fs/aio: unify socket into fs operate

Change-Id: I3aa88a47d88feaa7fd156caea9e0425b20554eee
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2021-03-08 14:49:18 +08:00 committed by Xiang Xiao
parent 2f29521dd1
commit cf61df9c5f
5 changed files with 50 additions and 131 deletions

View File

@ -49,12 +49,6 @@
# define CONFIG_FS_NAIOC 8
#endif
#undef AIO_HAVE_PSOCK
#ifdef CONFIG_NET_TCP
# define AIO_HAVE_PSOCK
#endif
/****************************************************************************
* Public Types
****************************************************************************/
@ -69,14 +63,7 @@ struct aio_container_s
{
dq_entry_t aioc_link; /* Supports a doubly linked list */
FAR struct aiocb *aioc_aiocbp; /* The contained AIO control block */
union
{
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;
FAR struct file *aioc_filep; /* File structure to use with the I/O */
struct work_s aioc_work; /* Used to defer I/O to the work thread */
pid_t aioc_pid; /* ID of the waiting task */
#ifdef CONFIG_PRIORITY_INHERITANCE

View File

@ -79,9 +79,9 @@ static void aio_fsync_worker(FAR void *arg)
#endif
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)
{
ferr("ERROR: file_fsync failed: %d\n", ret);

View File

@ -79,35 +79,16 @@ static void aio_read_worker(FAR void *arg)
#endif
aiocbp = aioc_decant(aioc);
#ifdef AIO_HAVE_PSOCK
if (aiocbp->aio_fildes < CONFIG_NFILE_DESCRIPTORS)
#endif
{
/* Perform the file read using:
*
* u.aioc_filep - File structure pointer
* aio_buf - Location of buffer
* aio_nbytes - Length of transfer
* aio_offset - File offset
*/
/* Perform the file read using:
*
* 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,
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
nread = file_pread(aioc->aioc_filep, (FAR void *)aiocbp->aio_buf,
aiocbp->aio_nbytes, aiocbp->aio_offset);
/* Set the result of the read operation. */

View File

@ -80,61 +80,41 @@ static void aio_write_worker(FAR void *arg)
#endif
aiocbp = aioc_decant(aioc);
#ifdef AIO_HAVE_PSOCK
if (aiocbp->aio_fildes < CONFIG_NFILE_DESCRIPTORS)
#endif
/* Call fcntl(F_GETFL) to get the file open mode. */
oflags = file_fcntl(aioc->aioc_filep, F_GETFL);
if (oflags < 0)
{
/* Call file_fcntl(F_GETFL) to get the file open mode. */
oflags = file_fcntl(aioc->u.aioc_filep, F_GETFL);
if (oflags < 0)
{
ferr("ERROR: file_fcntl failed: %d\n", oflags);
aiocbp->aio_result = oflags;
goto errout;
}
/* Perform the write using:
*
* u.aioc_filep - File structure pointer
* aio_buf - Location of buffer
* aio_nbytes - Length of transfer
* aio_offset - File offset
*/
/* Check if O_APPEND is set in the file open flags */
if ((oflags & O_APPEND) != 0)
{
/* 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);
}
ferr("ERROR: file_fcntl failed: %d\n", oflags);
aiocbp->aio_result = oflags;
goto errout;
}
/* Perform the write using:
*
* aioc_filep - File structure pointer
* aio_buf - Location of buffer
* aio_nbytes - Length of transfer
* aio_offset - File offset
*/
/* Check if O_APPEND is set in the file open flags */
if ((oflags & O_APPEND) != 0)
{
/* Append to the current file position */
nwritten = file_write(aioc->aioc_filep,
(FAR const void *)aiocbp->aio_buf,
aiocbp->aio_nbytes);
}
#ifdef AIO_HAVE_PSOCK
else
{
/* Perform the send using:
*
* u.aioc_psock - Socket structure pointer
* aio_buf - Location of buffer
* aio_nbytes - Length of transfer
*/
nwritten = psock_send(aioc->u.aioc_psock,
(FAR const void *)aiocbp->aio_buf,
aiocbp->aio_nbytes, 0);
nwritten = file_pwrite(aioc->aioc_filep,
(FAR const void *)aiocbp->aio_buf,
aiocbp->aio_nbytes,
aiocbp->aio_offset);
}
#endif
if (nwritten < 0)
{

View File

@ -59,51 +59,22 @@
FAR struct aio_container_s *aio_contain(FAR struct aiocb *aiocbp)
{
FAR struct aio_container_s *aioc;
union
{
FAR struct file *filep;
#ifdef AIO_HAVE_PSOCK
FAR struct socket *psock;
#endif
FAR void *ptr;
} u;
FAR struct file *filep;
#ifdef CONFIG_PRIORITY_INHERITANCE
struct sched_param param;
#endif
int ret;
#ifdef AIO_HAVE_PSOCK
if (aiocbp->aio_fildes < CONFIG_NFILE_DESCRIPTORS)
#endif
/* Get the file structure corresponding to the file descriptor. */
ret = fs_getfilep(aiocbp->aio_fildes, &filep);
if (ret < 0)
{
/* Get the file structure corresponding to the file descriptor. */
ret = fs_getfilep(aiocbp->aio_fildes, &u.filep);
if (ret < 0)
{
goto errout;
}
DEBUGASSERT(u.filep != NULL);
goto errout;
}
#ifdef AIO_HAVE_PSOCK
else
{
/* Get the socket structure corresponding to the socket descriptor */
u.psock = sockfd_socket(aiocbp->aio_fildes);
if (u.psock == NULL)
{
/* Does not return error information. EBADF is the most likely
* explanation.
*/
ret = -EBADF;
goto errout;
}
}
#endif
DEBUGASSERT(filep != NULL);
/* Allocate the AIO control block container, waiting for one to become
* 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));
aioc->aioc_aiocbp = aiocbp;
aioc->u.ptr = u.ptr;
aioc->aioc_filep = filep;
aioc->aioc_pid = getpid();
#ifdef CONFIG_PRIORITY_INHERITANCE