libaio.h revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _LIBAIO_H
#define _LIBAIO_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <thread.h>
#include <asynch.h>
#include <setjmp.h>
#include <signal.h>
#include <siginfo.h>
#include <aio.h>
#include <limits.h>
#include <ucontext.h>
#ifndef _REENTRANT
#define _REENTRANT
#endif
#ifdef DEBUG
extern int assfail(char *, char *, int);
#else
#endif
typedef struct aio_args {
int fd;
} aio_args_t;
/*
* list head for UFS list I/O
*/
typedef struct aio_lio {
char lio_mode; /* LIO_WAIT/LIO_NOWAIT */
int lio_nent; /* Number of list I/O's */
int lio_refcnt; /* outstanding I/O's */
int lio_signo; /* Signal for LIO_NOWAIT */
char lio_canned; /* lio was canceled */
} aio_lio_t;
/*
* size of aio_req should be power of 2. this helps to improve the
* effectiveness of the hashing function.
*/
typedef struct aio_req {
/*
* fields protected by _aio_mutex lock.
*/
/*
* when req is on the doneq, then req_next is protected by
* the _aio_mutex lock. when the req is on a work q, then
* req_next is protected by a worker's work_qlock1 lock.
*/
/*
* condition variable that waits for a request to be
* canceled.
*/
char req_canned; /* set when canceled */
/*
* fields protected by a worker's work_qlock1 lock.
*/
int req_state; /* AIO_REQ_QUEUED, ... */
/*
* fields require no locking.
*/
int req_type; /* AIO_POSIX_REQ ? */
int req_op; /* read or write */
int req_retval; /* resultp's retval */
int req_errno; /* resultp's errno */
char req_canwait; /* waiting for req to be canceled */
struct sigevent aio_sigevent;
int lio_signo; /* Signal for LIO_NOWAIT */
} aio_req_t;
/* special request type for handling sigevent notification */
/* special lio type that destroys itself when lio refcnt becomes zero */
/* lio flags */
#define LIO_FSYNC_CANCELED 0x1
/* values for aios_state */
#define AIO_REQ_QUEUED 1
#define AIO_REQ_INPROGRESS 2
#define AIO_REQ_CANCELED 3
#define AIO_REQ_DONE 4
#define AIO_REQ_FREE 5
#define AIO_LIO_DONE 6
#define AIO_REQ_DONEQ 7
/* use KAIO in _aio_rw() */
#define AIO_NO_KAIO 0x0
#define AIO_KAIO 0x1
#define AIO_NO_DUPS 0x2
#define AIO_POSIX_REQ 0x1
#define CHECK 1
#define NOCHECK 2
#define CHECKED 3
#define USERAIO 4
#define USERAIO_DONE 5
/* values for _aio_flags */
/*
* if set, _aiodone() notifies aio_waitn about done requests
* from the threads
*/
#define AIO_WAIT_INPROGRESS 0x1
/*
*/
#define AIO_IO_WAITING 0x2
/*
* Before a kaio() system call, the fd will be checked
* to ensure that kernel async. I/O is supported for this file.
* The only way to find out is if a kaio() call returns ENOTSUP,
* so the default will always be to try the kaio() call. Only in
* the specific instance of a kaio() call returning ENOTSUP
* will we stop submitting kaio() calls for that fd.
* If the fd is outside the array bounds, we will allow the kaio()
* call.
*
* The only way that an fd entry can go from ENOTSUP to supported
* is if that fd is freed up by a close(), and close will clear
* the entry for that fd.
*
* Each fd gets a bit in the array _kaio_supported[].
*
* uint32_t _kaio_supported[MAX_KAIO_FDARRAY_SIZE];
*
* Array is MAX_KAIO_ARRAY_SIZE of 32-bit elements, for 4kb.
* If more than (MAX_KAIO_FDARRAY_SIZE * KAIO_FDARRAY_ELEM_SIZE )
* files are open, this can be expanded.
*/
#define MAX_KAIO_FDARRAY_SIZE 1024
#define KAIO_SUPPORTED(fdes) \
#define SET_KAIO_NOT_SUPPORTED(fdes) \
#define CLEAR_KAIO_SUPPORTED(fdes) \
typedef struct aio_worker {
/*
* fields protected by _aio_mutex lock
*/
/*
* fields require no locking.
*/
int work_cnt1; /* length of work queue one */
int work_done1; /* number of requests done */
int work_minload1; /* min length of queue */
int work_idleflg; /* when set, worker is idle */
char work_cancel_flg; /* flag set when at cancellation pt */
} aio_worker_t;
extern void _kaio_init(void);
struct sigevent *);
extern int __aio_fsync(int, aiocb_t *);
#if defined(_LARGEFILE64_SOURCE) && !defined(_LP64)
struct sigevent *);
extern int __aio_fsync64(int, aiocb64_t *);
#endif
extern int aiocancel_all(int);
extern int _aio_create_worker(aio_req_t *, int);
extern void *_aio_send_sigev(void *);
extern void _aio_cancel_on(aio_worker_t *);
extern void _aio_cancel_off(aio_worker_t *);
extern void _aio_forkinit(void);
extern void _aiopanic(char *);
extern void _aio_lock(void);
extern void _aio_unlock(void);
extern void _aio_req_free(aio_req_t *);
extern int _fill_aiocache(int);
extern aio_worker_t *_aio_alloc_worker(void);
extern void _aio_free_worker(void *);
extern void _aio_idle(struct aio_worker *);
extern void __aiosendsig(void);
extern void *_aio_do_request(void *);
extern void _aio_remove(aio_req_t *);
extern void _lio_remove(aio_lio_t *);
extern int _close(int);
extern void aiosigcancelhndlr(int, siginfo_t *, void *);
extern int __rd_workerscnt; /* number of rd workers */
extern int __wr_workerscnt; /* number of wr workers */
extern int __si_workerscnt; /* number of si workers */
extern int __aiostksz; /* stack size for workers */
extern int _max_workers; /* max number of workers permitted */
extern int _min_workers; /* min number of workers */
extern int _aio_worker_cnt; /* number of AIO workers */
extern int _sigio_enabled; /* when set, send SIGIO signal */
extern int __sigio_pending; /* count of pending SIGIO signals */
extern int __sigio_masked; /* when set, SIGIO is masked */
extern int __sigio_maskedcnt; /* count number times bit mask is set */
extern int _kaio_ok; /* indicates if kaio is initialized */
extern int _pagesize;
/*
* Array for determining whether or not a file supports kaio
*
*/
extern uint32_t _kaio_supported[];
#ifdef __cplusplus
}
#endif
#endif /* _LIBAIO_H */