1*563e4487Sriastradh /* $NetBSD: aio.h,v 1.13 2016/04/09 19:55:33 riastradh Exp $ */ 267d703cfSrmind 367d703cfSrmind /* 467d703cfSrmind * Copyright (c) 2007, Mindaugas Rasiukevicius <rmind at NetBSD org> 5c75dc327Srmind * All rights reserved. 667d703cfSrmind * 767d703cfSrmind * Redistribution and use in source and binary forms, with or without 867d703cfSrmind * modification, are permitted provided that the following conditions 967d703cfSrmind * are met: 1067d703cfSrmind * 1. Redistributions of source code must retain the above copyright 1167d703cfSrmind * notice, this list of conditions and the following disclaimer. 1267d703cfSrmind * 2. Redistributions in binary form must reproduce the above copyright 1367d703cfSrmind * notice, this list of conditions and the following disclaimer in the 1467d703cfSrmind * documentation and/or other materials provided with the distribution. 1567d703cfSrmind * 1606171502Srmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1706171502Srmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1806171502Srmind * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1906171502Srmind * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2006171502Srmind * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2106171502Srmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2206171502Srmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2306171502Srmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2406171502Srmind * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2506171502Srmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2606171502Srmind * SUCH DAMAGE. 2767d703cfSrmind */ 2867d703cfSrmind 2967d703cfSrmind #ifndef _SYS_AIO_H_ 3067d703cfSrmind #define _SYS_AIO_H_ 3167d703cfSrmind 32fbaf57ceSchristos #include <sys/types.h> 33fbaf57ceSchristos #include <sys/signal.h> 34fbaf57ceSchristos 3567d703cfSrmind /* Returned by aio_cancel() */ 3667d703cfSrmind #define AIO_CANCELED 0x1 3767d703cfSrmind #define AIO_NOTCANCELED 0x2 3867d703cfSrmind #define AIO_ALLDONE 0x3 3967d703cfSrmind 4067d703cfSrmind /* LIO opcodes */ 4167d703cfSrmind #define LIO_NOP 0x0 4267d703cfSrmind #define LIO_WRITE 0x1 4367d703cfSrmind #define LIO_READ 0x2 4467d703cfSrmind 4567d703cfSrmind /* LIO modes */ 4667d703cfSrmind #define LIO_NOWAIT 0x0 4767d703cfSrmind #define LIO_WAIT 0x1 4867d703cfSrmind 4967d703cfSrmind /* 5067d703cfSrmind * Asynchronous I/O structure. 5167d703cfSrmind * Defined in the Base Definitions volume of IEEE Std 1003.1-2001 . 5267d703cfSrmind */ 5367d703cfSrmind struct aiocb { 5467d703cfSrmind off_t aio_offset; /* File offset */ 5567d703cfSrmind volatile void *aio_buf; /* I/O buffer in process space */ 5667d703cfSrmind size_t aio_nbytes; /* Length of transfer */ 57e8256921Srmind int aio_fildes; /* File descriptor */ 58e8256921Srmind int aio_lio_opcode; /* LIO opcode */ 5967d703cfSrmind int aio_reqprio; /* Request priority offset */ 6067d703cfSrmind struct sigevent aio_sigevent; /* Signal to deliver */ 6167d703cfSrmind 6267d703cfSrmind /* Internal kernel variables */ 63e8256921Srmind int _state; /* State of the job */ 6467d703cfSrmind int _errno; /* Error value */ 6567d703cfSrmind ssize_t _retval; /* Return value */ 6667d703cfSrmind }; 6767d703cfSrmind 6867d703cfSrmind /* Internal kernel data */ 6967d703cfSrmind #ifdef _KERNEL 7067d703cfSrmind 7129cb26a6Srmind /* Default limits of allowed AIO operations */ 7267d703cfSrmind #define AIO_LISTIO_MAX 512 73*563e4487Sriastradh #define AIO_MAX (AIO_LISTIO_MAX * 16) 7467d703cfSrmind 7567d703cfSrmind #include <sys/condvar.h> 7667d703cfSrmind #include <sys/lwp.h> 7767d703cfSrmind #include <sys/mutex.h> 7867d703cfSrmind #include <sys/pool.h> 7967d703cfSrmind #include <sys/queue.h> 8067d703cfSrmind 8167d703cfSrmind /* Operations (as flags) */ 8267d703cfSrmind #define AIO_LIO 0x00 8367d703cfSrmind #define AIO_READ 0x01 8467d703cfSrmind #define AIO_WRITE 0x02 8567d703cfSrmind #define AIO_SYNC 0x04 8667d703cfSrmind #define AIO_DSYNC 0x08 8767d703cfSrmind 8867d703cfSrmind /* Job states */ 8967d703cfSrmind #define JOB_NONE 0x0 9067d703cfSrmind #define JOB_WIP 0x1 9167d703cfSrmind #define JOB_DONE 0x2 9267d703cfSrmind 9367d703cfSrmind /* Structure of AIO job */ 9467d703cfSrmind struct aio_job { 9567d703cfSrmind int aio_op; /* Operation code */ 9667d703cfSrmind struct aiocb aiocbp; /* AIO data structure */ 9767d703cfSrmind void *aiocb_uptr; /* User-space pointer for identification of job */ 9867d703cfSrmind TAILQ_ENTRY(aio_job) list; 9967d703cfSrmind struct lio_req *lio; 10067d703cfSrmind }; 10167d703cfSrmind 10267d703cfSrmind /* LIO structure */ 10367d703cfSrmind struct lio_req { 10467d703cfSrmind u_int refcnt; /* Reference counter */ 10567d703cfSrmind struct sigevent sig; /* Signal of lio_listio() calls */ 10667d703cfSrmind }; 10767d703cfSrmind 10867d703cfSrmind /* Structure of AIO data for process */ 10967d703cfSrmind struct aioproc { 11067d703cfSrmind kmutex_t aio_mtx; /* Protects the entire structure */ 11167d703cfSrmind kcondvar_t aio_worker_cv; /* Signals on a new job */ 11267d703cfSrmind kcondvar_t done_cv; /* Signals when the job is done */ 11367d703cfSrmind struct aio_job *curjob; /* Currently processing AIO job */ 11467d703cfSrmind unsigned int jobs_count; /* Count of the jobs */ 11567d703cfSrmind TAILQ_HEAD(, aio_job) jobs_queue;/* Queue of the AIO jobs */ 11667d703cfSrmind struct lwp *aio_worker; /* AIO worker thread */ 11767d703cfSrmind }; 11867d703cfSrmind 119461a86f9Schristos extern u_int aio_listio_max; 12067d703cfSrmind /* Prototypes */ 12164afb694Schristos void aio_print_jobs(void (*)(const char *, ...) __printflike(1, 2)); 122461a86f9Schristos int aio_suspend1(struct lwp *, struct aiocb **, int, struct timespec *); 12367d703cfSrmind 12467d703cfSrmind #endif /* _KERNEL */ 12567d703cfSrmind 12667d703cfSrmind #endif /* _SYS_AIO_H_ */ 127