mqueue: add file_mq_xx for kernel use

Change-Id: Ida12f5938388cca2f233a4cde90277a218033645
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd
2020-12-24 20:53:17 +08:00
committed by Xiang Xiao
parent 3bc33572e3
commit f63db66382
37 changed files with 1158 additions and 484 deletions
+28
View File
@@ -40,6 +40,34 @@
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: file_mq_close
*
* Description:
* This is an internal OS interface. It is functionally equivalent to
* mq_close() except that:
*
* - It is not a cancellation point, and
* - It does not modify the errno value.
*
* See comments with mq_close() for a more complete description of the
* behavior of this function
*
* Input Parameters:
* mq - Message queue descriptor.
*
* Returned Value:
* This is an internal OS interface and should not be used by applications.
* It follows the NuttX internal error return policy: Zero (OK) is
* returned on success. A negated errno value is returned on failure.
*
****************************************************************************/
int file_mq_close(FAR struct file *mq)
{
return file_close(mq);
}
/****************************************************************************
* Name: nxmq_close
*
+162 -75
View File
@@ -84,61 +84,37 @@ static int nxmq_file_close(FAR struct file *filep)
return 0;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxmq_open
*
* Description:
* This function establish a connection between a named message queue and
* the calling task. This is an internal OS interface. It is functionally
* equivalent to mq_open() except that:
*
* - It is not a cancellation point, and
* - It does not modify the errno value.
*
* See comments with mq_open() for a more complete description of the
* behavior of this function
*
* Input Parameters:
* mq_name - Name of the queue to open
* oflags - open flags
* Optional parameters. When the O_CREAT flag is specified, two optional
* parameters are expected:
*
* 1. mode_t mode (ignored), and
* 2. struct mq_attr *attr. The mq_maxmsg attribute
* is used at the time that the message queue is
* created to determine the maximum number of
* messages that may be placed in the message queue.
*
* Returned Value:
* This is an internal OS interface and should not be used by applications.
* It follows the NuttX internal error return policy: Zero (OK) is
* returned on success, mqdes point to the new message queue descriptor.
* A negated errno value is returned on failure.
*
****************************************************************************/
int nxmq_open(FAR const char *mq_name, int oflags, mode_t mode,
FAR struct mq_attr *attr, FAR mqd_t *mqdes)
static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name,
int oflags, va_list ap, int *created)
{
FAR struct inode *inode;
FAR struct mqueue_inode_s *msgq;
FAR struct mq_attr *attr = NULL;
struct inode_search_s desc;
char fullpath[MAX_MQUEUE_PATH];
mode_t mode = 0;
int ret;
/* Make sure that a non-NULL name is supplied */
if (mq_name == NULL || *mq_name == '\0')
if (!mq || !mq_name || *mq_name == '\0')
{
ret = -EINVAL;
goto errout;
}
/* Were we asked to create it? */
if ((oflags & O_CREAT) != 0)
{
/* We have to extract the additional
* parameters from the variable argument list.
*/
mode = va_arg(ap, mode_t);
attr = va_arg(ap, FAR struct mq_attr *);
}
/* Skip over any leading '/'. All message queue paths are relative to
* CONFIG_FS_MQUEUE_MPATH.
*/
@@ -195,11 +171,14 @@ int nxmq_open(FAR const char *mq_name, int oflags, mode_t mode,
/* Associate the inode with a file structure */
*mqdes = files_allocate(inode, oflags, 0, 0);
if (*mqdes < 0)
mq->f_oflags = oflags;
mq->f_pos = 0;
mq->f_inode = inode;
mq->f_priv = NULL;
if (created)
{
ret = *mqdes;
goto errout_with_msgq;
*created = 1;
}
}
else
@@ -243,12 +222,10 @@ int nxmq_open(FAR const char *mq_name, int oflags, mode_t mode,
/* Associate the inode with a file structure */
*mqdes = files_allocate(inode, oflags, 0, 0);
if (*mqdes < 0)
{
ret = *mqdes;
goto errout_with_msgq;
}
mq->f_oflags = oflags;
mq->f_pos = 0;
mq->f_inode = inode;
mq->f_priv = NULL;
INODE_SET_MQUEUE(inode);
inode->u.i_ops = &g_nxmq_fileops;
@@ -258,15 +235,17 @@ int nxmq_open(FAR const char *mq_name, int oflags, mode_t mode,
/* Set the initial reference count on this inode to one */
inode->i_crefs = 1;
if (created)
{
*created = 0;
}
}
RELEASE_SEARCH(&desc);
sched_unlock();
return OK;
errout_with_msgq:
nxmq_free_msgq(msgq);
errout_with_inode:
inode_release(inode);
@@ -278,6 +257,129 @@ errout:
return ret;
}
static mqd_t nxmq_vopen(FAR const char *mq_name, int oflags, va_list ap)
{
struct file mq;
int created;
int ret;
ret = file_mq_vopen(&mq, mq_name, oflags, ap, &created);
if (ret < 0)
{
return ret;
}
ret = files_allocate(mq.f_inode, mq.f_oflags, mq.f_pos, 0);
if (ret < 0)
{
file_mq_close(&mq);
if (created)
{
file_mq_unlink(mq_name);
}
}
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: file_mq_open
*
* Description:
* This function establish a connection between a named message queue and
* the calling task. This is an internal OS interface. It is functionally
* equivalent to mq_open() except that:
*
* - It is not a cancellation point, and
* - It does not modify the errno value.
*
* See comments with mq_open() for a more complete description of the
* behavior of this function
*
* Input Parameters:
* mq_name - Name of the queue to open
* oflags - open flags
* Optional parameters. When the O_CREAT flag is specified, two optional
* parameters are expected:
*
* 1. mode_t mode (ignored), and
* 2. struct mq_attr *attr. The mq_maxmsg attribute
* is used at the time that the message queue is
* created to determine the maximum number of
* messages that may be placed in the message queue.
*
* Returned Value:
* This is an internal OS interface and should not be used by applications.
* It follows the NuttX internal error return policy: Zero (OK) is
* returned on success, mqdes point to the new message queue descriptor.
* A negated errno value is returned on failure.
*
****************************************************************************/
int file_mq_open(FAR struct file *mq,
FAR const char *mq_name, int oflags, ...)
{
va_list ap;
int ret;
va_start(ap, oflags);
ret = file_mq_vopen(mq, mq_name, oflags, ap, NULL);
va_end(ap);
return ret;
}
/****************************************************************************
* Name: nxmq_open
*
* Description:
* This function establish a connection between a named message queue and
* the calling task. This is an internal OS interface. It is functionally
* equivalent to mq_open() except that:
*
* - It is not a cancellation point, and
* - It does not modify the errno value.
*
* See comments with mq_open() for a more complete description of the
* behavior of this function
*
* Input Parameters:
* mq_name - Name of the queue to open
* oflags - open flags
* Optional parameters. When the O_CREAT flag is specified, two optional
* parameters are expected:
*
* 1. mode_t mode (ignored), and
* 2. struct mq_attr *attr. The mq_maxmsg attribute
* is used at the time that the message queue is
* created to determine the maximum number of
* messages that may be placed in the message queue.
*
* Returned Value:
* This is an internal OS interface and should not be used by applications.
* It follows the NuttX internal error return policy: Zero (OK) is
* returned on success, mqdes point to the new message queue descriptor.
* A negated errno value is returned on failure.
*
****************************************************************************/
mqd_t nxmq_open(FAR const char *mq_name, int oflags, ...)
{
va_list ap;
mqd_t ret;
va_start(ap, oflags);
ret = nxmq_vopen(mq_name, oflags, ap);
va_end(ap);
return ret;
}
/****************************************************************************
* Name: mq_open
*
@@ -309,32 +411,17 @@ errout:
mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
{
FAR struct mq_attr *attr = NULL;
mode_t mode = 0;
mqd_t mqdes;
va_list ap;
int ret;
mqd_t ret;
/* Were we asked to create it? */
if ((oflags & O_CREAT) != 0)
{
/* We have to extract the additional
* parameters from the variable argument list.
*/
va_start(ap, oflags);
mode = va_arg(ap, mode_t);
attr = va_arg(ap, FAR struct mq_attr *);
va_end(ap);
}
ret = nxmq_open(mq_name, oflags, mode, attr, &mqdes);
va_start(ap, oflags);
ret = nxmq_vopen(mq_name, oflags, ap);
va_end(ap);
if (ret < 0)
{
set_errno(-ret);
mqdes = (mqd_t)ERROR;
return ERROR;
}
return mqdes;
return ret;
}
+30 -2
View File
@@ -72,7 +72,7 @@ static void mq_inode_release(FAR struct inode *inode)
****************************************************************************/
/****************************************************************************
* Name: nxmq_unlink
* Name: file_mq_unlink
*
* Description:
* This is an internal OS interface. It is functionally equivalent to
@@ -94,7 +94,7 @@ static void mq_inode_release(FAR struct inode *inode)
*
****************************************************************************/
int nxmq_unlink(FAR const char *mq_name)
int file_mq_unlink(FAR const char *mq_name)
{
FAR struct inode *inode;
struct inode_search_s desc;
@@ -187,6 +187,34 @@ errout_with_search:
return ret;
}
/****************************************************************************
* Name: nxmq_unlink
*
* Description:
* This is an internal OS interface. It is functionally equivalent to
* mq_unlink() except that:
*
* - It is not a cancellation point, and
* - It does not modify the errno value.
*
* See comments with mq_unlink() for a more complete description of the
* behavior of this function
*
* Input Parameters:
* mq_name - Name of the message queue
*
* Returned Value:
* This is an internal OS interface and should not be used by applications.
* It follows the NuttX internal error return policy: Zero (OK) is
* returned on success. A negated errno value is returned on failure.
*
****************************************************************************/
int nxmq_unlink(FAR const char *mq_name)
{
return file_mq_unlink(mq_name);
}
/****************************************************************************
* Name: mq_unlink
*