mirror of
https://github.com/apache/nuttx.git
synced 2026-05-29 04:19:37 +08:00
fs/aio: unify socket into fs operate
Change-Id: I3aa88a47d88feaa7fd156caea9e0425b20554eee Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
+1
-14
@@ -49,12 +49,6 @@
|
|||||||
# define CONFIG_FS_NAIOC 8
|
# define CONFIG_FS_NAIOC 8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef AIO_HAVE_PSOCK
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_TCP
|
|
||||||
# define AIO_HAVE_PSOCK
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -69,14 +63,7 @@ struct aio_container_s
|
|||||||
{
|
{
|
||||||
dq_entry_t aioc_link; /* Supports a doubly linked list */
|
dq_entry_t aioc_link; /* Supports a doubly linked list */
|
||||||
FAR struct aiocb *aioc_aiocbp; /* The contained AIO control block */
|
FAR struct aiocb *aioc_aiocbp; /* The contained AIO control block */
|
||||||
union
|
FAR struct file *aioc_filep; /* File structure to use with the I/O */
|
||||||
{
|
|
||||||
FAR struct file *aioc_filep; /* File structure to use with the I/O */
|
|
||||||
#ifdef AIO_HAVE_PSOCK
|
|
||||||
FAR struct socket *aioc_psock; /* Socket structure to use with the I/O */
|
|
||||||
#endif
|
|
||||||
FAR void *ptr; /* Generic pointer to FAR data */
|
|
||||||
} u;
|
|
||||||
struct work_s aioc_work; /* Used to defer I/O to the work thread */
|
struct work_s aioc_work; /* Used to defer I/O to the work thread */
|
||||||
pid_t aioc_pid; /* ID of the waiting task */
|
pid_t aioc_pid; /* ID of the waiting task */
|
||||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
||||||
|
|||||||
+2
-2
@@ -79,9 +79,9 @@ static void aio_fsync_worker(FAR void *arg)
|
|||||||
#endif
|
#endif
|
||||||
aiocbp = aioc_decant(aioc);
|
aiocbp = aioc_decant(aioc);
|
||||||
|
|
||||||
/* Perform the fsync using u.aioc_filep */
|
/* Perform the fsync using aioc_filep */
|
||||||
|
|
||||||
ret = file_fsync(aioc->u.aioc_filep);
|
ret = file_fsync(aioc->aioc_filep);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
ferr("ERROR: file_fsync failed: %d\n", ret);
|
ferr("ERROR: file_fsync failed: %d\n", ret);
|
||||||
|
|||||||
+9
-28
@@ -79,35 +79,16 @@ static void aio_read_worker(FAR void *arg)
|
|||||||
#endif
|
#endif
|
||||||
aiocbp = aioc_decant(aioc);
|
aiocbp = aioc_decant(aioc);
|
||||||
|
|
||||||
#ifdef AIO_HAVE_PSOCK
|
/* Perform the file read using:
|
||||||
if (aiocbp->aio_fildes < CONFIG_NFILE_DESCRIPTORS)
|
*
|
||||||
#endif
|
* aioc_filep - File structure pointer
|
||||||
{
|
* aio_buf - Location of buffer
|
||||||
/* Perform the file read using:
|
* aio_nbytes - Length of transfer
|
||||||
*
|
* aio_offset - File offset
|
||||||
* u.aioc_filep - File structure pointer
|
*/
|
||||||
* aio_buf - Location of buffer
|
|
||||||
* aio_nbytes - Length of transfer
|
|
||||||
* aio_offset - File offset
|
|
||||||
*/
|
|
||||||
|
|
||||||
nread = file_pread(aioc->u.aioc_filep, (FAR void *)aiocbp->aio_buf,
|
nread = file_pread(aioc->aioc_filep, (FAR void *)aiocbp->aio_buf,
|
||||||
aiocbp->aio_nbytes, aiocbp->aio_offset);
|
aiocbp->aio_nbytes, aiocbp->aio_offset);
|
||||||
}
|
|
||||||
#ifdef AIO_HAVE_PSOCK
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Perform the socket receive using:
|
|
||||||
*
|
|
||||||
* u.aioc_psock - Socket structure pointer
|
|
||||||
* aio_buf - Location of buffer
|
|
||||||
* aio_nbytes - Length of transfer
|
|
||||||
*/
|
|
||||||
|
|
||||||
nread = psock_recv(aioc->u.aioc_psock, (FAR void *)aiocbp->aio_buf,
|
|
||||||
aiocbp->aio_nbytes, 0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set the result of the read operation. */
|
/* Set the result of the read operation. */
|
||||||
|
|
||||||
|
|||||||
+30
-50
@@ -80,61 +80,41 @@ static void aio_write_worker(FAR void *arg)
|
|||||||
#endif
|
#endif
|
||||||
aiocbp = aioc_decant(aioc);
|
aiocbp = aioc_decant(aioc);
|
||||||
|
|
||||||
#ifdef AIO_HAVE_PSOCK
|
/* Call fcntl(F_GETFL) to get the file open mode. */
|
||||||
if (aiocbp->aio_fildes < CONFIG_NFILE_DESCRIPTORS)
|
|
||||||
#endif
|
oflags = file_fcntl(aioc->aioc_filep, F_GETFL);
|
||||||
|
if (oflags < 0)
|
||||||
{
|
{
|
||||||
/* Call file_fcntl(F_GETFL) to get the file open mode. */
|
ferr("ERROR: file_fcntl failed: %d\n", oflags);
|
||||||
|
aiocbp->aio_result = oflags;
|
||||||
oflags = file_fcntl(aioc->u.aioc_filep, F_GETFL);
|
goto errout;
|
||||||
if (oflags < 0)
|
}
|
||||||
{
|
|
||||||
ferr("ERROR: file_fcntl failed: %d\n", oflags);
|
/* Perform the write using:
|
||||||
aiocbp->aio_result = oflags;
|
*
|
||||||
goto errout;
|
* aioc_filep - File structure pointer
|
||||||
}
|
* aio_buf - Location of buffer
|
||||||
|
* aio_nbytes - Length of transfer
|
||||||
/* Perform the write using:
|
* aio_offset - File offset
|
||||||
*
|
*/
|
||||||
* u.aioc_filep - File structure pointer
|
|
||||||
* aio_buf - Location of buffer
|
/* Check if O_APPEND is set in the file open flags */
|
||||||
* aio_nbytes - Length of transfer
|
|
||||||
* aio_offset - File offset
|
if ((oflags & O_APPEND) != 0)
|
||||||
*/
|
{
|
||||||
|
/* Append to the current file position */
|
||||||
/* Check if O_APPEND is set in the file open flags */
|
|
||||||
|
nwritten = file_write(aioc->aioc_filep,
|
||||||
if ((oflags & O_APPEND) != 0)
|
(FAR const void *)aiocbp->aio_buf,
|
||||||
{
|
aiocbp->aio_nbytes);
|
||||||
/* Append to the current file position */
|
|
||||||
|
|
||||||
nwritten = file_write(aioc->u.aioc_filep,
|
|
||||||
(FAR const void *)aiocbp->aio_buf,
|
|
||||||
aiocbp->aio_nbytes);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nwritten = file_pwrite(aioc->u.aioc_filep,
|
|
||||||
(FAR const void *)aiocbp->aio_buf,
|
|
||||||
aiocbp->aio_nbytes,
|
|
||||||
aiocbp->aio_offset);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#ifdef AIO_HAVE_PSOCK
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Perform the send using:
|
nwritten = file_pwrite(aioc->aioc_filep,
|
||||||
*
|
(FAR const void *)aiocbp->aio_buf,
|
||||||
* u.aioc_psock - Socket structure pointer
|
aiocbp->aio_nbytes,
|
||||||
* aio_buf - Location of buffer
|
aiocbp->aio_offset);
|
||||||
* aio_nbytes - Length of transfer
|
|
||||||
*/
|
|
||||||
|
|
||||||
nwritten = psock_send(aioc->u.aioc_psock,
|
|
||||||
(FAR const void *)aiocbp->aio_buf,
|
|
||||||
aiocbp->aio_nbytes, 0);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (nwritten < 0)
|
if (nwritten < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
+8
-37
@@ -59,51 +59,22 @@
|
|||||||
FAR struct aio_container_s *aio_contain(FAR struct aiocb *aiocbp)
|
FAR struct aio_container_s *aio_contain(FAR struct aiocb *aiocbp)
|
||||||
{
|
{
|
||||||
FAR struct aio_container_s *aioc;
|
FAR struct aio_container_s *aioc;
|
||||||
union
|
FAR struct file *filep;
|
||||||
{
|
|
||||||
FAR struct file *filep;
|
|
||||||
#ifdef AIO_HAVE_PSOCK
|
|
||||||
FAR struct socket *psock;
|
|
||||||
#endif
|
|
||||||
FAR void *ptr;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
||||||
struct sched_param param;
|
struct sched_param param;
|
||||||
#endif
|
#endif
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef AIO_HAVE_PSOCK
|
/* Get the file structure corresponding to the file descriptor. */
|
||||||
if (aiocbp->aio_fildes < CONFIG_NFILE_DESCRIPTORS)
|
|
||||||
#endif
|
ret = fs_getfilep(aiocbp->aio_fildes, &filep);
|
||||||
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
/* Get the file structure corresponding to the file descriptor. */
|
goto errout;
|
||||||
|
|
||||||
ret = fs_getfilep(aiocbp->aio_fildes, &u.filep);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUGASSERT(u.filep != NULL);
|
|
||||||
}
|
}
|
||||||
#ifdef AIO_HAVE_PSOCK
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Get the socket structure corresponding to the socket descriptor */
|
|
||||||
|
|
||||||
u.psock = sockfd_socket(aiocbp->aio_fildes);
|
DEBUGASSERT(filep != NULL);
|
||||||
if (u.psock == NULL)
|
|
||||||
{
|
|
||||||
/* Does not return error information. EBADF is the most likely
|
|
||||||
* explanation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = -EBADF;
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Allocate the AIO control block container, waiting for one to become
|
/* Allocate the AIO control block container, waiting for one to become
|
||||||
* available if necessary. This should not fail except for in the case
|
* available if necessary. This should not fail except for in the case
|
||||||
@@ -117,7 +88,7 @@ FAR struct aio_container_s *aio_contain(FAR struct aiocb *aiocbp)
|
|||||||
|
|
||||||
memset(aioc, 0, sizeof(struct aio_container_s));
|
memset(aioc, 0, sizeof(struct aio_container_s));
|
||||||
aioc->aioc_aiocbp = aiocbp;
|
aioc->aioc_aiocbp = aiocbp;
|
||||||
aioc->u.ptr = u.ptr;
|
aioc->aioc_filep = filep;
|
||||||
aioc->aioc_pid = getpid();
|
aioc->aioc_pid = getpid();
|
||||||
|
|
||||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
||||||
|
|||||||
Reference in New Issue
Block a user