You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/03/17 13:46:50 UTC
[incubator-nuttx] 01/03: fs/aio: unify socket into fs operate
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit cf61df9c5f3d6d4624e5bb6a0e9121ca6795a7ba
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Mon Mar 8 14:49:18 2021 +0800
fs/aio: unify socket into fs operate
Change-Id: I3aa88a47d88feaa7fd156caea9e0425b20554eee
Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
fs/aio/aio.h | 15 +---------
fs/aio/aio_fsync.c | 4 +--
fs/aio/aio_read.c | 39 +++++++------------------
fs/aio/aio_write.c | 80 +++++++++++++++++++--------------------------------
fs/aio/aioc_contain.c | 45 ++++++-----------------------
5 files changed, 51 insertions(+), 132 deletions(-)
diff --git a/fs/aio/aio.h b/fs/aio/aio.h
index 111afa7..509d11a 100644
--- a/fs/aio/aio.h
+++ b/fs/aio/aio.h
@@ -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
diff --git a/fs/aio/aio_fsync.c b/fs/aio/aio_fsync.c
index 78f88e8..932656b 100644
--- a/fs/aio/aio_fsync.c
+++ b/fs/aio/aio_fsync.c
@@ -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);
diff --git a/fs/aio/aio_read.c b/fs/aio/aio_read.c
index 385dc32..0f5fd8a 100644
--- a/fs/aio/aio_read.c
+++ b/fs/aio/aio_read.c
@@ -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
- */
-
- 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
+ /* 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->aioc_filep, (FAR void *)aiocbp->aio_buf,
+ aiocbp->aio_nbytes, aiocbp->aio_offset);
/* Set the result of the read operation. */
diff --git a/fs/aio/aio_write.c b/fs/aio/aio_write.c
index 40c26f5..4352754 100644
--- a/fs/aio/aio_write.c
+++ b/fs/aio/aio_write.c
@@ -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;
}
-#ifdef AIO_HAVE_PSOCK
- else
+
+ /* 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)
{
- /* 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,
+ /* Append to the current file position */
+
+ nwritten = file_write(aioc->aioc_filep,
(FAR const void *)aiocbp->aio_buf,
- aiocbp->aio_nbytes, 0);
+ aiocbp->aio_nbytes);
+ }
+ else
+ {
+ nwritten = file_pwrite(aioc->aioc_filep,
+ (FAR const void *)aiocbp->aio_buf,
+ aiocbp->aio_nbytes,
+ aiocbp->aio_offset);
}
-#endif
if (nwritten < 0)
{
diff --git a/fs/aio/aioc_contain.c b/fs/aio/aioc_contain.c
index 49992c4..a95d414 100644
--- a/fs/aio/aioc_contain.c
+++ b/fs/aio/aioc_contain.c
@@ -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, &u.filep);
- if (ret < 0)
- {
- goto errout;
- }
+ /* Get the file structure corresponding to the file descriptor. */
- DEBUGASSERT(u.filep != NULL);
- }
-#ifdef AIO_HAVE_PSOCK
- else
+ ret = fs_getfilep(aiocbp->aio_fildes, &filep);
+ if (ret < 0)
{
- /* 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;
- }
+ 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