libsysve  3.1.0
VE AIO

VE AIO is a asynchronous I/O feature for VE programs. More...

Functions

struct ve_aio_ctx * ve_aio_init (void)
 This function returns a new ve_aio_ctx managing a read/write request. More...
 
int ve_aio_fini (struct ve_aio_ctx *ctx)
 This function releases context managing a read/write request. More...
 
int ve_aio_read (struct ve_aio_ctx *ctx, int fd, ssize_t count, void *buf, off_t offset)
 This function starts asynchronous read. More...
 
int ve_aio_write (struct ve_aio_ctx *ctx, int fd, ssize_t count, void *buf, off_t offset)
 This function starts asynchronous write. More...
 
int ve_aio_query (struct ve_aio_ctx *ctx, ssize_t *retval, int *errnoval)
 This function gets state of read/write operation for the context. More...
 
int ve_aio_wait (struct ve_aio_ctx *ctx, ssize_t *retval, int *errnoval)
 This function waits read/write request for the context. More...
 

Detailed Description

VE AIO is a asynchronous I/O feature for VE programs.

VE programs can do their own tasks while data transfer between VE and VH and actual I/O are done asynchronously.

Please include "veaio.h". Please specify "-lveio -pthread" option to the compiler driver to link libveio.

Note
VE AIO expects an ordinary file opened without O_DIRECT flag. Socket, pipe or fifo can't be used.
Calling fork() or vfork() when read/write operation status is in progress, invoking AIO API results in undefined behavior. Check read/write operation status by using ve_aio_query() or synchronize read/write operation by using ve_aio_wait().
Pseudo process(ve_exec) creates IO worker threads on VH and each thread allocates IO buffer and opens two files to communicate with VEOS. IO request is divided and processed non-atomically under multithreading by default. Following environment variables can be set to change from default.
  • VE_ASYNC_IO_THREAD To specify the number of VEAIO worker threads per VE process. This is valid only when VE_ASYNC_IO_ATOMIC is 0. Default is 4.
  • VE_ASYNC_IO_BUFSIZE To specify IO buffer size(Byte) per worker thread. This is valid only when VE_ASYNC_IO_ATOMIC is 0. Default is 8MB.
  • VE_ASYNC_IO_ATOMIC Set this to 1 and VEAIO worker threads process IO operation atomically. Default is 0. The number of bytes read or written at once is restricted to 2147479552Byte(2GB - 4KB) same as pread64/pwrite64.
If VE thread which has submitted read/write request terminates before completion of read/write operation, then VE process gets abnormal termination.

Function Documentation

struct ve_aio_ctx* ve_aio_init ( void  )

This function returns a new ve_aio_ctx managing a read/write request.

Note
User must initialize a ve_aio_ctx for AIO operation
User must invoke this function as many as multiplicity of read/write requests
For example, initialize two contexts to submit two read/write requests at a time
Context can be reused after completion of previous request
Return values
ve_aio_ctxon success
NULLon failure.
int ve_aio_fini ( struct ve_aio_ctx *  ctx)

This function releases context managing a read/write request.

Parameters
[in]ctxContext to be released
Return values
0on success
-1on failure and following errno is set
  • EINVAL Context in arguments is invalid
  • EBUSY Request for this context is in progress
int ve_aio_read ( struct ve_aio_ctx *  ctx,
int  fd,
ssize_t  count,
void *  buf,
off_t  offset 
)

This function starts asynchronous read.

Note
This function internally invokes pread() system call at VH side
Context can be reused after completion of previous request
Parameters
[in]ctxContext managing this request
[in]fdFile descriptor which refer to a file this function reads to
[in]countNumber of bytes read
[out]bufBuffer this function reads from
[in]offsetFile offset
Return values
0on success
-1on failure and following errno is set
  • EINVAL Context in arguments is invalid
  • EBUSY Not complete the previous read request for this context
  • EAGAIN No resource to accept this request
  • ENOMEM No memory to accept this request on host
int ve_aio_write ( struct ve_aio_ctx *  ctx,
int  fd,
ssize_t  count,
void *  buf,
off_t  offset 
)

This function starts asynchronous write.

Note
This function internally invokes pwrite() system call at VH side
Context can be reused after completion of previous request
Parameters
[in]ctxContext managing this request
[in]fdFile descriptor which refer to a file function writes to
[in]countNumber of bytes written
[in]bufBuffer this function writes from
[in]offsetFile offset
Return values
0on success
-1on failure and following errno is set
  • EINVAL Context in arguments is invalid
  • EBUSY Not complete the previous read request for this context
  • EAGAIN No resource to accept this request
  • ENOMEM No memory to accept this request on host
int ve_aio_query ( struct ve_aio_ctx *  ctx,
ssize_t *  retval,
int *  errnoval 
)

This function gets state of read/write operation for the context.

Note
If argument *retval or *errnoval below is NULL, status of read/write can be got but return value or error number can not be got
Parameters
[in]ctxContext which this function gets some information from
[out]retvalPointer to get return value of pread()/pwrite()
[out]errnovalPointer to get error number of pread()/pwrite()
Return values
0on completion of read/write and set retval and errnoval
1on incompletion read/write
-1on failure of query and following errno is set
  • EINVAL Context in arguments is invalid
int ve_aio_wait ( struct ve_aio_ctx *  ctx,
ssize_t *  retval,
int *  errnoval 
)

This function waits read/write request for the context.

Note
When read or write is failure (actually, pread or pwrite is used internally), its error number is set
This function blocks VE process so VEOS finds other process to schedule
After context was reused, this function gets result of latest request for ve_aio_ctx
When this function fails, retval and errnoval are not set
Parameters
[in]ctxContext managing read/write request
[out]retvalPointer to get return value of pread()/pwrite()
[out]errnovalPointer to get error number of pread()/pwrite()
Return values
0on completion of read/write and set retval and errnoval
-1on failure of wait and following errno is set
  • EINVAL Context in arguments is invalid
  • EBUSY Context in arguments has already managed new read/write request and failure to get result of previous request