forked from Imagelibrary/rtems
cpukit/posix/aio*: added support for O_DSYNC
The aio_fsync function now supports the value O_DSYNC for op. Tests are added to improve coverage and test new features. Closes #5040.
This commit is contained in:
committed by
Amar Takhar
parent
dc123bb828
commit
adce380138
@@ -98,19 +98,6 @@ extern "C" {
|
|||||||
/** Request a write() */
|
/** Request a write() */
|
||||||
#define LIO_WRITE 2
|
#define LIO_WRITE 2
|
||||||
|
|
||||||
/** Needed by aio_fsync() */
|
|
||||||
#define LIO_SYNC 3
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Constants to track return status
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** The aio operation return value has been retrieved */
|
|
||||||
#define AIO_RETURNED 0
|
|
||||||
|
|
||||||
/** The aio operation return value has not been retrieved */
|
|
||||||
#define AIO_NOTRETURNED 1
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Asynchronous I/O Control Block
|
* @brief Asynchronous I/O Control Block
|
||||||
*
|
*
|
||||||
@@ -272,7 +259,7 @@ int aio_suspend(
|
|||||||
*
|
*
|
||||||
* 6.7.9 Asynchronous File Synchronization, P1003.1b-1993, p. 166
|
* 6.7.9 Asynchronous File Synchronization, P1003.1b-1993, p. 166
|
||||||
*
|
*
|
||||||
* @param[in] op O_SYNC
|
* @param[in] op O_SYNC or O_DSYNC
|
||||||
* @param[in,out] aiocbp is a pointer to the asynchronous I/O control block
|
* @param[in,out] aiocbp is a pointer to the asynchronous I/O control block
|
||||||
*
|
*
|
||||||
* @retval 0 The request was correctly enqueued.
|
* @retval 0 The request was correctly enqueued.
|
||||||
@@ -281,8 +268,7 @@ int aio_suspend(
|
|||||||
* due to temporary resource limitations.
|
* due to temporary resource limitations.
|
||||||
* - EBADF The aio_fildes member of the aiocb structure referenced
|
* - EBADF The aio_fildes member of the aiocb structure referenced
|
||||||
* by the aiocbp argument is not a valid file descriptor.
|
* by the aiocbp argument is not a valid file descriptor.
|
||||||
* - EINVAL A value of op other than O_SYNC was specified.
|
* - EINVAL A value of op other than O_SYNC or O_DSYNC was specified.
|
||||||
* The current implemetation only supports O_SYNC.
|
|
||||||
* - EINVAL aiocbp is a NULL pointer.
|
* - EINVAL aiocbp is a NULL pointer.
|
||||||
* - EINVAL aiocbp->sigevent is not valid.
|
* - EINVAL aiocbp->sigevent is not valid.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -57,6 +57,30 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** Constants to identify op type */
|
||||||
|
|
||||||
|
/** Needed by aio_fsync() */
|
||||||
|
#define AIO_OP_READ 0
|
||||||
|
|
||||||
|
/** Needed by aio_fsync() */
|
||||||
|
#define AIO_OP_WRITE 1
|
||||||
|
|
||||||
|
/** Needed by aio_fsync() */
|
||||||
|
#define AIO_OP_SYNC 2
|
||||||
|
|
||||||
|
/** Needed by aio_fsync() */
|
||||||
|
#define AIO_OP_DSYNC 3
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constants to track return status
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** The aio operation return value has been retrieved */
|
||||||
|
#define AIO_RETURNED 0
|
||||||
|
|
||||||
|
/** The aio operation return value has not been retrieved */
|
||||||
|
#define AIO_NOTRETURNED 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The request being processed
|
* @brief The request being processed
|
||||||
*/
|
*/
|
||||||
@@ -76,6 +100,10 @@ typedef struct
|
|||||||
|
|
||||||
/** @brief Aio control block */
|
/** @brief Aio control block */
|
||||||
struct aiocb *aiocbp;
|
struct aiocb *aiocbp;
|
||||||
|
|
||||||
|
/** @brief Operation type */
|
||||||
|
int op_type;
|
||||||
|
|
||||||
} rtems_aio_request;
|
} rtems_aio_request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include <aio.h>
|
#include <aio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <rtems/posix/aio_misc.h>
|
||||||
|
|
||||||
#include <rtems/seterr.h>
|
#include <rtems/seterr.h>
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ int aio_fsync(
|
|||||||
if ( aiocbp == NULL )
|
if ( aiocbp == NULL )
|
||||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||||
|
|
||||||
if ( op != O_SYNC )
|
if ( op != O_SYNC && op != O_DSYNC )
|
||||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||||
|
|
||||||
if ( rtems_aio_check_sigevent( &aiocbp->aio_sigevent ) == 0 )
|
if ( rtems_aio_check_sigevent( &aiocbp->aio_sigevent ) == 0 )
|
||||||
@@ -77,7 +77,11 @@ int aio_fsync(
|
|||||||
rtems_set_errno_and_return_minus_one( EAGAIN );
|
rtems_set_errno_and_return_minus_one( EAGAIN );
|
||||||
|
|
||||||
req->aiocbp = aiocbp;
|
req->aiocbp = aiocbp;
|
||||||
req->aiocbp->aio_lio_opcode = LIO_SYNC;
|
if ( op == O_SYNC ) {
|
||||||
|
req->op_type = AIO_OP_SYNC;
|
||||||
|
} else {
|
||||||
|
req->op_type = AIO_OP_DSYNC;
|
||||||
|
}
|
||||||
|
|
||||||
return rtems_aio_enqueue( req );
|
return rtems_aio_enqueue( req );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -613,8 +613,8 @@ static void rtems_aio_handle_helper( rtems_aio_request *req )
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
switch ( req->aiocbp->aio_lio_opcode ) {
|
switch ( req->op_type ) {
|
||||||
case LIO_READ:
|
case AIO_OP_READ:
|
||||||
AIO_printf( "read\n" );
|
AIO_printf( "read\n" );
|
||||||
result = pread(
|
result = pread(
|
||||||
req->aiocbp->aio_fildes,
|
req->aiocbp->aio_fildes,
|
||||||
@@ -623,7 +623,7 @@ static void rtems_aio_handle_helper( rtems_aio_request *req )
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIO_WRITE:
|
case AIO_OP_WRITE:
|
||||||
AIO_printf( "write\n" );
|
AIO_printf( "write\n" );
|
||||||
result = pwrite(
|
result = pwrite(
|
||||||
req->aiocbp->aio_fildes,
|
req->aiocbp->aio_fildes,
|
||||||
@@ -632,10 +632,15 @@ static void rtems_aio_handle_helper( rtems_aio_request *req )
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIO_SYNC:
|
case AIO_OP_SYNC:
|
||||||
AIO_printf( "sync\n" );
|
AIO_printf( "sync\n" );
|
||||||
result = fsync( req->aiocbp->aio_fildes );
|
result = fsync( req->aiocbp->aio_fildes );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case AIO_OP_DSYNC:
|
||||||
|
AIO_printf( "data sync\n" );
|
||||||
|
result = fdatasync( req->aiocbp->aio_fildes );
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result = -1;
|
result = -1;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ int aio_read( struct aiocb *aiocbp )
|
|||||||
rtems_set_errno_and_return_minus_one( EAGAIN );
|
rtems_set_errno_and_return_minus_one( EAGAIN );
|
||||||
|
|
||||||
req->aiocbp = aiocbp;
|
req->aiocbp = aiocbp;
|
||||||
req->aiocbp->aio_lio_opcode = LIO_READ;
|
req->op_type = AIO_OP_READ;
|
||||||
|
|
||||||
return rtems_aio_enqueue( req );
|
return rtems_aio_enqueue( req );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
#include <aio.h>
|
#include <aio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <rtems/seterr.h>
|
#include <rtems/seterr.h>
|
||||||
|
#include <rtems/posix/aio_misc.h>
|
||||||
|
|
||||||
ssize_t aio_return( struct aiocb *aiocbp )
|
ssize_t aio_return( struct aiocb *aiocbp )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ int aio_write( struct aiocb *aiocbp )
|
|||||||
rtems_set_errno_and_return_minus_one( EAGAIN );
|
rtems_set_errno_and_return_minus_one( EAGAIN );
|
||||||
|
|
||||||
req->aiocbp = aiocbp;
|
req->aiocbp = aiocbp;
|
||||||
req->aiocbp->aio_lio_opcode = LIO_WRITE;
|
req->op_type = AIO_OP_WRITE;
|
||||||
|
|
||||||
return rtems_aio_enqueue( req );
|
return rtems_aio_enqueue( req );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,41 @@ void *POSIX_Init( void *argument )
|
|||||||
|
|
||||||
TEST_BEGIN();
|
TEST_BEGIN();
|
||||||
|
|
||||||
|
/* NULL aiocbp */
|
||||||
|
|
||||||
|
result = aio_write( NULL );
|
||||||
|
status = errno;
|
||||||
|
rtems_test_assert( result == -1 );
|
||||||
|
rtems_test_assert( status == EINVAL );
|
||||||
|
|
||||||
|
/* NULL aiocbp */
|
||||||
|
|
||||||
|
result = aio_read( NULL );
|
||||||
|
status = errno;
|
||||||
|
rtems_test_assert( result == -1 );
|
||||||
|
rtems_test_assert( status == EINVAL );
|
||||||
|
|
||||||
|
/* NULL aiocbp */
|
||||||
|
|
||||||
|
result = aio_fsync( O_SYNC, NULL );
|
||||||
|
status = errno;
|
||||||
|
rtems_test_assert( result == -1 );
|
||||||
|
rtems_test_assert( status == EINVAL );
|
||||||
|
|
||||||
|
/* NULL aiocbp */
|
||||||
|
|
||||||
|
result = aio_return( NULL );
|
||||||
|
status = errno;
|
||||||
|
rtems_test_assert( result == -1 );
|
||||||
|
rtems_test_assert( status == ENOENT );
|
||||||
|
|
||||||
|
/* NULL aiocbp */
|
||||||
|
|
||||||
|
result = aio_error( NULL );
|
||||||
|
status = errno;
|
||||||
|
rtems_test_assert( result == -1 );
|
||||||
|
rtems_test_assert( status == EINVAL );
|
||||||
|
|
||||||
aiocbp = create_aiocb( WRONG_FD );
|
aiocbp = create_aiocb( WRONG_FD );
|
||||||
|
|
||||||
/* Bad file descriptor */
|
/* Bad file descriptor */
|
||||||
@@ -147,7 +182,7 @@ void *POSIX_Init( void *argument )
|
|||||||
rtems_test_assert( result == -1 );
|
rtems_test_assert( result == -1 );
|
||||||
rtems_test_assert( status == EINVAL );
|
rtems_test_assert( status == EINVAL );
|
||||||
|
|
||||||
/* Invalid request priority */
|
/* Invalid request priority */
|
||||||
|
|
||||||
result = aio_read( aiocbp );
|
result = aio_read( aiocbp );
|
||||||
status = errno;
|
status = errno;
|
||||||
@@ -168,6 +203,25 @@ void *POSIX_Init( void *argument )
|
|||||||
status = errno;
|
status = errno;
|
||||||
rtems_test_assert( result == -1 );
|
rtems_test_assert( result == -1 );
|
||||||
rtems_test_assert( status == EINVAL );
|
rtems_test_assert( status == EINVAL );
|
||||||
|
aiocbp->aio_fildes = fd;
|
||||||
|
|
||||||
|
/* Bad sigevent */
|
||||||
|
|
||||||
|
aiocbp->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
|
||||||
|
aiocbp->aio_sigevent.sigev_notify_function = NULL;
|
||||||
|
result = aio_fsync( O_SYNC, aiocbp );
|
||||||
|
status = errno;
|
||||||
|
rtems_test_assert( result == -1 );
|
||||||
|
rtems_test_assert( status == EINVAL );
|
||||||
|
|
||||||
|
/* Bad sigevent */
|
||||||
|
|
||||||
|
aiocbp->aio_sigevent.sigev_notify = SIGEV_THREAD;
|
||||||
|
aiocbp->aio_sigevent.sigev_signo = 0;
|
||||||
|
result = aio_fsync( O_SYNC, aiocbp );
|
||||||
|
status = errno;
|
||||||
|
rtems_test_assert( result == -1 );
|
||||||
|
rtems_test_assert( status == EINVAL );
|
||||||
|
|
||||||
free_aiocb( aiocbp );
|
free_aiocb( aiocbp );
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,10 @@ void *POSIX_Init( void *argument )
|
|||||||
status = aio_fsync( O_SYNC, aiocbp[9] );
|
status = aio_fsync( O_SYNC, aiocbp[9] );
|
||||||
rtems_test_assert( status != -1 );
|
rtems_test_assert( status != -1 );
|
||||||
|
|
||||||
|
aiocbp[9] = create_aiocb( fd[0] );
|
||||||
|
status = aio_fsync( O_DSYNC, aiocbp[9] );
|
||||||
|
rtems_test_assert( status != -1 );
|
||||||
|
|
||||||
status = aio_cancel( WRONG_FD, NULL );
|
status = aio_cancel( WRONG_FD, NULL );
|
||||||
rtems_test_assert( status == -1 );
|
rtems_test_assert( status == -1 );
|
||||||
|
|
||||||
@@ -170,6 +174,22 @@ void *POSIX_Init( void *argument )
|
|||||||
status = aio_cancel( fd[5], aiocbp[6] );
|
status = aio_cancel( fd[5], aiocbp[6] );
|
||||||
rtems_test_assert( status == AIO_CANCELED );
|
rtems_test_assert( status == AIO_CANCELED );
|
||||||
|
|
||||||
|
/* tests for aio error and aio test */
|
||||||
|
|
||||||
|
int result = aio_error( aiocbp[6] );
|
||||||
|
rtems_test_assert( result == ECANCELED );
|
||||||
|
|
||||||
|
result = aio_return( aiocbp[6] );
|
||||||
|
rtems_test_assert( result == -1 );
|
||||||
|
|
||||||
|
result = aio_return( aiocbp[6] );
|
||||||
|
rtems_test_assert( result == -1 );
|
||||||
|
|
||||||
|
rtems_test_assert( errno == EINVAL );
|
||||||
|
result = aio_error( aiocbp[6] );
|
||||||
|
rtems_test_assert( result == -1 );
|
||||||
|
rtems_test_assert( errno == EINVAL );
|
||||||
|
|
||||||
status = aio_cancel( fd[0], aiocbp[9] );
|
status = aio_cancel( fd[0], aiocbp[9] );
|
||||||
rtems_test_assert( status == AIO_CANCELED );
|
rtems_test_assert( status == AIO_CANCELED );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user