From 964f0ab30405eac489c3781067a506ab585372a7 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 27 Jan 2019 09:39:33 -0600 Subject: [PATCH] aio_cancel need signal caller after the succeed and fix minor issue in the error handler --- fs/aio/aio_cancel.c | 36 ++++++++++++++++++++++++++---------- fs/aio/aio_fsync.c | 1 + fs/aio/aio_initialize.c | 1 + fs/aio/aio_queue.c | 3 +++ fs/aio/aio_read.c | 1 + fs/aio/aio_write.c | 18 +----------------- libs/libc/aio/lio_listio.c | 4 ++-- 7 files changed, 35 insertions(+), 29 deletions(-) diff --git a/fs/aio/aio_cancel.c b/fs/aio/aio_cancel.c index f9c263991e..65a86da10e 100644 --- a/fs/aio/aio_cancel.c +++ b/fs/aio/aio_cancel.c @@ -98,6 +98,7 @@ int aio_cancel(int fildes, FAR struct aiocb *aiocbp) { FAR struct aio_container_s *aioc; FAR struct aio_container_s *next; + pid_t pid; int status; int ret; @@ -140,17 +141,28 @@ int aio_cancel(int fildes, FAR struct aiocb *aiocbp) status = work_cancel(LPWORK, &aioc->aioc_work); if (status >= 0) { + /* Remove the container from the list of pending transfers */ + + pid = aioc->aioc_pid; + (void)aioc_decant(aioc); + aiocbp->aio_result = -ECANCELED; ret = AIO_CANCELED; + + /* Signal the client */ + + (void)aio_signal(pid, aiocbp); } else { ret = AIO_NOTCANCELED; } + } + else + { + /* Can't cancel, the operation is running */ - /* Remove the container from the list of pending transfers */ - - (void)aioc_decant(aioc); + ret = AIO_NOTCANCELED; } } } @@ -182,20 +194,24 @@ int aio_cancel(int fildes, FAR struct aiocb *aiocbp) */ status = work_cancel(LPWORK, &aioc->aioc_work); - - /* Remove the container from the list of pending transfers */ - - next = (FAR struct aio_container_s *)aioc->aioc_link.flink; - aiocbp = aioc_decant(aioc); - DEBUGASSERT(aiocbp); - if (status >= 0) { + /* Remove the container from the list of pending transfers */ + + next = (FAR struct aio_container_s *)aioc->aioc_link.flink; + pid = aioc->aioc_pid; + aiocbp = aioc_decant(aioc); + DEBUGASSERT(aiocbp); + aiocbp->aio_result = -ECANCELED; if (ret != AIO_NOTCANCELED) { ret = AIO_CANCELED; } + + /* Signal the client */ + + (void)aio_signal(pid, aiocbp); } else { diff --git a/fs/aio/aio_fsync.c b/fs/aio/aio_fsync.c index 9053172bb1..29c08f16f7 100644 --- a/fs/aio/aio_fsync.c +++ b/fs/aio/aio_fsync.c @@ -234,6 +234,7 @@ int aio_fsync(int op, FAR struct aiocb *aiocbp) { /* The result and the errno have already been set */ + aioc_decant(aioc); return ERROR; } diff --git a/fs/aio/aio_initialize.c b/fs/aio/aio_initialize.c index 2f7d342b3f..2872a15a98 100644 --- a/fs/aio/aio_initialize.c +++ b/fs/aio/aio_initialize.c @@ -109,6 +109,7 @@ void aio_initialize(void) /* Initialize counting semaphores */ (void)nxsem_init(&g_aioc_freesem, 0, CONFIG_FS_NAIOC); + (void)nxsem_setprotocol(&g_aioc_freesem, SEM_PRIO_NONE); (void)nxsem_init(&g_aio_exclsem, 0, 1); g_aio_holder = INVALID_PROCESS_ID; diff --git a/fs/aio/aio_queue.c b/fs/aio/aio_queue.c index d4c7cf76ea..dfae827e0d 100644 --- a/fs/aio/aio_queue.c +++ b/fs/aio/aio_queue.c @@ -94,6 +94,9 @@ int aio_queue(FAR struct aio_container_s *aioc, worker_t worker) FAR struct aiocb *aiocbp = aioc->aioc_aiocbp; DEBUGASSERT(aiocbp); +#ifdef CONFIG_PRIORITY_INHERITANCE + lpwork_restorepriority(aioc->aioc_prio); +#endif aiocbp->aio_result = ret; set_errno(-ret); ret = ERROR; diff --git a/fs/aio/aio_read.c b/fs/aio/aio_read.c index af41e14bf8..319e51f582 100644 --- a/fs/aio/aio_read.c +++ b/fs/aio/aio_read.c @@ -283,6 +283,7 @@ int aio_read(FAR struct aiocb *aiocbp) { /* The result and the errno have already been set */ + aioc_decant(aioc); return ERROR; } diff --git a/fs/aio/aio_write.c b/fs/aio/aio_write.c index 0eeef18e90..e92b4c3d2e 100644 --- a/fs/aio/aio_write.c +++ b/fs/aio/aio_write.c @@ -56,23 +56,6 @@ * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: file_fcntl - ****************************************************************************/ - -#ifdef AIO_HAVE_FILEP -static inline int file_fcntl(FAR struct file *filep, int cmd, ...) -{ - va_list ap; - int ret; - - va_start(ap, cmd); - ret = file_vfcntl(filep, cmd, ap); - va_end(ap); - return ret; -} -#endif - /**************************************************************************** * Name: aio_write_worker * @@ -333,6 +316,7 @@ int aio_write(FAR struct aiocb *aiocbp) { /* The result and the errno have already been set */ + aioc_decant(aioc); return ERROR; } diff --git a/libs/libc/aio/lio_listio.c b/libs/libc/aio/lio_listio.c index d6e42a76bb..79312f8519 100644 --- a/libs/libc/aio/lio_listio.c +++ b/libs/libc/aio/lio_listio.c @@ -59,7 +59,7 @@ struct lio_sighand_s { FAR struct aiocb * const *list; /* List of I/O operations */ - FAR struct sigevent *sig; /* Describes how to signal the caller */ + FAR struct sigevent sig; /* Describes how to signal the caller */ int nent; /* Number or elements in list[] */ pid_t pid; /* ID of client */ sigset_t oprocmask; /* sigprocmask to restore */ @@ -245,7 +245,7 @@ static int lio_sigsetup(FAR struct aiocb * const *list, int nent, /* Initialize the allocated structure */ sighand->list = list; - sighand->sig = sig; + sighand->sig = *sig; sighand->nent = nent; sighand->pid = getpid();