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:
alessandronardin
2024-07-03 12:29:42 +02:00
committed by Amar Takhar
parent dc123bb828
commit adce380138
10 changed files with 124 additions and 25 deletions

View File

@@ -98,19 +98,6 @@ extern "C" {
/** Request a write() */
#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
*
@@ -272,7 +259,7 @@ int aio_suspend(
*
* 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
*
* @retval 0 The request was correctly enqueued.
@@ -281,8 +268,7 @@ int aio_suspend(
* due to temporary resource limitations.
* - EBADF The aio_fildes member of the aiocb structure referenced
* by the aiocbp argument is not a valid file descriptor.
* - EINVAL A value of op other than O_SYNC was specified.
* The current implemetation only supports O_SYNC.
* - EINVAL A value of op other than O_SYNC or O_DSYNC was specified.
* - EINVAL aiocbp is a NULL pointer.
* - EINVAL aiocbp->sigevent is not valid.
*/

View File

@@ -57,6 +57,30 @@
extern "C" {
#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
*/
@@ -76,6 +100,10 @@ typedef struct
/** @brief Aio control block */
struct aiocb *aiocbp;
/** @brief Operation type */
int op_type;
} rtems_aio_request;
/**

View File

@@ -42,6 +42,7 @@
#include <aio.h>
#include <errno.h>
#include <rtems/posix/aio_misc.h>
#include <rtems/seterr.h>

View File

@@ -57,7 +57,7 @@ int aio_fsync(
if ( aiocbp == NULL )
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 );
if ( rtems_aio_check_sigevent( &aiocbp->aio_sigevent ) == 0 )
@@ -77,7 +77,11 @@ int aio_fsync(
rtems_set_errno_and_return_minus_one( EAGAIN );
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 );
}

View File

@@ -613,8 +613,8 @@ static void rtems_aio_handle_helper( rtems_aio_request *req )
{
int result;
switch ( req->aiocbp->aio_lio_opcode ) {
case LIO_READ:
switch ( req->op_type ) {
case AIO_OP_READ:
AIO_printf( "read\n" );
result = pread(
req->aiocbp->aio_fildes,
@@ -623,7 +623,7 @@ static void rtems_aio_handle_helper( rtems_aio_request *req )
);
break;
case LIO_WRITE:
case AIO_OP_WRITE:
AIO_printf( "write\n" );
result = pwrite(
req->aiocbp->aio_fildes,
@@ -632,11 +632,16 @@ static void rtems_aio_handle_helper( rtems_aio_request *req )
);
break;
case LIO_SYNC:
case AIO_OP_SYNC:
AIO_printf( "sync\n" );
result = fsync( req->aiocbp->aio_fildes );
break;
case AIO_OP_DSYNC:
AIO_printf( "data sync\n" );
result = fdatasync( req->aiocbp->aio_fildes );
break;
default:
result = -1;
}

View File

@@ -79,7 +79,7 @@ int aio_read( struct aiocb *aiocbp )
rtems_set_errno_and_return_minus_one( EAGAIN );
req->aiocbp = aiocbp;
req->aiocbp->aio_lio_opcode = LIO_READ;
req->op_type = AIO_OP_READ;
return rtems_aio_enqueue( req );
}

View File

@@ -43,6 +43,7 @@
#include <aio.h>
#include <errno.h>
#include <rtems/seterr.h>
#include <rtems/posix/aio_misc.h>
ssize_t aio_return( struct aiocb *aiocbp )
{

View File

@@ -76,7 +76,7 @@ int aio_write( struct aiocb *aiocbp )
rtems_set_errno_and_return_minus_one( EAGAIN );
req->aiocbp = aiocbp;
req->aiocbp->aio_lio_opcode = LIO_WRITE;
req->op_type = AIO_OP_WRITE;
return rtems_aio_enqueue( req );
}

View File

@@ -86,6 +86,41 @@ void *POSIX_Init( void *argument )
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 );
/* Bad file descriptor */
@@ -168,6 +203,25 @@ void *POSIX_Init( void *argument )
status = errno;
rtems_test_assert( result == -1 );
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 );

View File

@@ -148,6 +148,10 @@ void *POSIX_Init( void *argument )
status = aio_fsync( O_SYNC, aiocbp[9] );
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 );
rtems_test_assert( status == -1 );
@@ -170,6 +174,22 @@ void *POSIX_Init( void *argument )
status = aio_cancel( fd[5], aiocbp[6] );
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] );
rtems_test_assert( status == AIO_CANCELED );