Move all file operations from libc/aio to fs/aio. These will need to be kernel routines in order to handler issues with using file descriptors on worker thread

This commit is contained in:
Gregory Nutt 2014-10-05 15:33:31 -06:00
parent f34127823a
commit f73a18ae39
13 changed files with 161 additions and 73 deletions

View File

@ -48,6 +48,7 @@ config FS_WRITABLE
bool
default n
source fs/aio/Kconfig
source fs/semaphore/Kconfig
source fs/mqueue/Kconfig
source fs/shm/Kconfig

View File

@ -47,6 +47,7 @@ include inode/Make.defs
include vfs/Make.defs
include driver/Make.defs
include dirent/Make.defs
include aio/Make.defs
include mmap/Make.defs
# OS resources

46
fs/aio/Make.defs Normal file
View File

@ -0,0 +1,46 @@
############################################################################
# fs/aio/Make.defs
#
# Copyright (C) 2014 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
ifeq ($(CONFIG_LIBC_AIO),y)
# Add the asynchronous I/O C files to the build
CSRCS += aio_cancel.c aio_fsync.c aio_read.c aio_signal.c aio_write.c
# Add the asynchronous I/O directory to the build
DEPPATH += --dep-path aio
VPATH += :aio
endif

91
fs/aio/aio.h Normal file
View File

@ -0,0 +1,91 @@
/****************************************************************************
* fs/aio/aio.h
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __FS_AIO_AIO_H
#define __FS_AIO_AIO_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <aio.h>
#include <nuttx/wqueue.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Variables
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: aio_signal
*
* Description:
* Signal the client that an I/O has completed.
*
* Input Parameters:
* aiocbp - Pointer to the asynchronous I/O state structure that includes
* information about how to signal the client
*
* Returned Value:
* Zero (OK) if the client was successfully signalled. Otherwise, a
* negated errno value is returned.
*
****************************************************************************/
int aio_signal(FAR struct aiocb *aiocbp);
#endif /* __FS_AIO_AIO_H */

View File

@ -1,5 +1,5 @@
/****************************************************************************
* libc/aio/aio_cancel.c
* fs/aio/aio_cancel.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@ -150,7 +150,7 @@ int aio_cancel(int fildes, FAR struct aiocb *aiocbp)
* -ENOENT in the first case.
*/
status = work_cancel(AIO_QUEUE, &aiocbp->aio_work);
status = work_cancel(LPWORK, &aiocbp->aio_work);
ret = status >= 0 ? AIO_CANCELED : AIO_NOTCANCELED;
}
else

View File

@ -1,5 +1,5 @@
/****************************************************************************
* libc/aio/aio_fsync.c
* fs/aio/aio_fsync.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@ -43,10 +43,10 @@
#include <aio.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/wqueue.h>
#include "lib_internal.h"
#include "aio/aio.h"
#ifdef CONFIG_LIBC_AIO
@ -214,7 +214,7 @@ int aio_fsync(int op, FAR struct aiocb *aiocbp)
/* Defer the work to the worker thread */
ret = work_queue(AIO_QUEUE, &aiocbp->aio_work, aio_fsync_worker, aiocbp, 0);
ret = work_queue(LPWORK, &aiocbp->aio_work, aio_fsync_worker, aiocbp, 0);
if (ret < 0)
{
aiocbp->aio_result = ret;

View File

@ -1,5 +1,5 @@
/****************************************************************************
* libc/aio/aio_read.c
* fs/aio/aio_read.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@ -44,10 +44,10 @@
#include <aio.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/wqueue.h>
#include "lib_internal.h"
#include "aio/aio.h"
#ifdef CONFIG_LIBC_AIO
@ -262,7 +262,7 @@ int aio_read(FAR struct aiocb *aiocbp)
/* Defer the work to the worker thread */
ret = work_queue(AIO_QUEUE, &aiocbp->aio_work, aio_read_worker, aiocbp, 0);
ret = work_queue(LPWORK, &aiocbp->aio_work, aio_read_worker, aiocbp, 0);
if (ret < 0)
{
aiocbp->aio_result = ret;

View File

@ -1,5 +1,5 @@
/****************************************************************************
* libc/aio/aio_signal.c
* fs/aio/aio_signal.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>

View File

@ -1,5 +1,5 @@
/****************************************************************************
* libc/aio/aio_write.c
* fs/aio/aio_write.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@ -45,10 +45,10 @@
#include <aio.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/wqueue.h>
#include "lib_internal.h"
#include "aio/aio.h"
#ifdef CONFIG_LIBC_AIO
@ -97,13 +97,7 @@ static void aio_write_worker(FAR void *arg)
ssize_t nwritten;
int oflags;
/* Call fcntl(F_GETFL) to get the file open mode.
*
* REVISIT: Consider moving aio_write into the kernel. Notice that in a
* system using system calls, up to three system calls may be required:
* (1) fcntl, (2) write or pwrite, and possibly (3) sigueue(). If aio_write
* were a system call, then only one would be required.
*/
/* Call fcntl(F_GETFL) to get the file open mode. */
oflags = fcntl(aiocbp->aio_fildes, F_GETFL);
if (oflags < 0)
@ -299,7 +293,7 @@ int aio_write(FAR struct aiocb *aiocbp)
/* Defer the work to the worker thread */
ret = work_queue(AIO_QUEUE, &aiocbp->aio_work, aio_write_worker, aiocbp, 0);
ret = work_queue(LPWORK, &aiocbp->aio_work, aio_write_worker, aiocbp, 0);
if (ret < 0)
{
aiocbp->aio_result = ret;

View File

@ -58,28 +58,20 @@
# undef CONFIG_LIBC_AIO
#endif
/* Work queue support is required. In the flat, embedded build the low-
* priority work queue is required so that the asynchronous I/O does not
* interfere with high priority driver operations. In the protected and
* kernel mode builds, user-space work queue support is required. If these
* pre-requisites are met, then asynchronous I/O support can be enabled with
* CONFIG_LIBC_AIO
/* Work queue support is required. The low-priority work queue is required
* so that the asynchronous I/O does not interfere with high priority driver
* operations. If this pre-requisite is met, then asynchronous I/O support
* can be enabled with CONFIG_LIBC_AIO
*/
#ifdef CONFIG_LIBC_AIO
#ifndef CONFIG_SCHED_WORKQUEUE
# error Asynchronous I/O requires CONFIG_SCHED_WORKQUEUE
#else
# if defined (CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)
# ifndef CONFIG_SCHED_USRWORK
# error User-space asynchronous I/O requires CONFIG_SCHED_USRWORK
# endif
# else
# ifndef CONFIG_SCHED_LPWORK
# error Flat-build asynchronous I/O requires CONFIG_SCHED_LPWORK
# endif
# endif
#endif
#ifndef CONFIG_SCHED_LPWORK
# error Asynchronous I/O requires CONFIG_SCHED_LPWORK
#endif
/* Standard Definitions *****************************************************/

View File

@ -79,14 +79,6 @@ config EOL_IS_EITHER_CRLF
endchoice
config LIBC_AIO
bool "Asynchronous I/O support"
default n
depends on ((BUILD_PROTECTED || BUILD_KERNEL) && SCHED_USRWORK) || (BUILD_FLAT && SCHED_LPWORK)
---help---
Enable support for aynchronous I/O. This selection enabled the
interface declared in include/aio.h.
config LIBC_EXECFUNCS
bool "Enable exec[l|v] / posix_spawn() Support"
default n

View File

@ -37,8 +37,7 @@ ifeq ($(CONFIG_LIBC_AIO),y)
# Add the asynchronous I/O C files to the build
CSRCS += aio_cancel.c aio_error.c aio_fsync.c aio_read.c aio_return.c
CSRCS += aio_signal.c aio_suspend.c aio_write.c lio_listio.c
CSRCS += aio_error.c aio_return.c aio_suspend.c lio_listio.c
# Add the asynchronous I/O directory to the build

View File

@ -42,19 +42,9 @@
#include <nuttx/config.h>
#include <aio.h>
#include <nuttx/wqueue.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Select the appropriate work queue */
#if defined (CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)
# define AIO_QUEUE LPWORK
#else
# define AIO_QUEUE USRWORK
#endif
/****************************************************************************
* Public Types
@ -77,22 +67,4 @@ extern "C"
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: aio_signal
*
* Description:
* Signal the client that an I/O has completed.
*
* Input Parameters:
* aiocbp - Pointer to the asynchronous I/O state structure that includes
* information about how to signal the client
*
* Returned Value:
* Zero (OK) if the client was successfully signalled. Otherwise, a
* negated errno value is returned.
*
****************************************************************************/
int aio_signal(FAR struct aiocb *aiocbp);
#endif /* __LIBC_AIO_AIO_H */