xref: /minix/sys/sys/aio.h (revision 6c8f7fc3)
1*6c8f7fc3SBen Gras /*	$NetBSD: aio.h,v 1.12 2012/01/07 19:48:19 christos Exp $	*/
2*6c8f7fc3SBen Gras 
3*6c8f7fc3SBen Gras /*
4*6c8f7fc3SBen Gras  * Copyright (c) 2007, Mindaugas Rasiukevicius <rmind at NetBSD org>
5*6c8f7fc3SBen Gras  * All rights reserved.
6*6c8f7fc3SBen Gras  *
7*6c8f7fc3SBen Gras  * Redistribution and use in source and binary forms, with or without
8*6c8f7fc3SBen Gras  * modification, are permitted provided that the following conditions
9*6c8f7fc3SBen Gras  * are met:
10*6c8f7fc3SBen Gras  * 1. Redistributions of source code must retain the above copyright
11*6c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer.
12*6c8f7fc3SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
13*6c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer in the
14*6c8f7fc3SBen Gras  *    documentation and/or other materials provided with the distribution.
15*6c8f7fc3SBen Gras  *
16*6c8f7fc3SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*6c8f7fc3SBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*6c8f7fc3SBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*6c8f7fc3SBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*6c8f7fc3SBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*6c8f7fc3SBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*6c8f7fc3SBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*6c8f7fc3SBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*6c8f7fc3SBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*6c8f7fc3SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*6c8f7fc3SBen Gras  * SUCH DAMAGE.
27*6c8f7fc3SBen Gras  */
28*6c8f7fc3SBen Gras 
29*6c8f7fc3SBen Gras #ifndef _SYS_AIO_H_
30*6c8f7fc3SBen Gras #define _SYS_AIO_H_
31*6c8f7fc3SBen Gras 
32*6c8f7fc3SBen Gras #include <sys/types.h>
33*6c8f7fc3SBen Gras #include <sys/signal.h>
34*6c8f7fc3SBen Gras 
35*6c8f7fc3SBen Gras /* Returned by aio_cancel() */
36*6c8f7fc3SBen Gras #define AIO_CANCELED		0x1
37*6c8f7fc3SBen Gras #define AIO_NOTCANCELED		0x2
38*6c8f7fc3SBen Gras #define AIO_ALLDONE		0x3
39*6c8f7fc3SBen Gras 
40*6c8f7fc3SBen Gras /* LIO opcodes */
41*6c8f7fc3SBen Gras #define LIO_NOP			0x0
42*6c8f7fc3SBen Gras #define LIO_WRITE		0x1
43*6c8f7fc3SBen Gras #define LIO_READ		0x2
44*6c8f7fc3SBen Gras 
45*6c8f7fc3SBen Gras /* LIO modes */
46*6c8f7fc3SBen Gras #define LIO_NOWAIT		0x0
47*6c8f7fc3SBen Gras #define LIO_WAIT		0x1
48*6c8f7fc3SBen Gras 
49*6c8f7fc3SBen Gras /*
50*6c8f7fc3SBen Gras  * Asynchronous I/O structure.
51*6c8f7fc3SBen Gras  * Defined in the Base Definitions volume of IEEE Std 1003.1-2001 .
52*6c8f7fc3SBen Gras  */
53*6c8f7fc3SBen Gras struct aiocb {
54*6c8f7fc3SBen Gras 	off_t aio_offset;		/* File offset */
55*6c8f7fc3SBen Gras 	volatile void *aio_buf;		/* I/O buffer in process space */
56*6c8f7fc3SBen Gras 	size_t aio_nbytes;		/* Length of transfer */
57*6c8f7fc3SBen Gras 	int aio_fildes;			/* File descriptor */
58*6c8f7fc3SBen Gras 	int aio_lio_opcode;		/* LIO opcode */
59*6c8f7fc3SBen Gras 	int aio_reqprio;		/* Request priority offset */
60*6c8f7fc3SBen Gras 	struct sigevent aio_sigevent;	/* Signal to deliver */
61*6c8f7fc3SBen Gras 
62*6c8f7fc3SBen Gras 	/* Internal kernel variables */
63*6c8f7fc3SBen Gras 	int _state;			/* State of the job */
64*6c8f7fc3SBen Gras 	int _errno;			/* Error value */
65*6c8f7fc3SBen Gras 	ssize_t _retval;		/* Return value */
66*6c8f7fc3SBen Gras };
67*6c8f7fc3SBen Gras 
68*6c8f7fc3SBen Gras /* Internal kernel data */
69*6c8f7fc3SBen Gras #ifdef _KERNEL
70*6c8f7fc3SBen Gras 
71*6c8f7fc3SBen Gras /* Default limits of allowed AIO operations */
72*6c8f7fc3SBen Gras #define AIO_LISTIO_MAX		512
73*6c8f7fc3SBen Gras #define AIO_MAX			AIO_LISTIO_MAX * 16
74*6c8f7fc3SBen Gras 
75*6c8f7fc3SBen Gras #include <sys/condvar.h>
76*6c8f7fc3SBen Gras #include <sys/lwp.h>
77*6c8f7fc3SBen Gras #include <sys/mutex.h>
78*6c8f7fc3SBen Gras #include <sys/pool.h>
79*6c8f7fc3SBen Gras #include <sys/queue.h>
80*6c8f7fc3SBen Gras 
81*6c8f7fc3SBen Gras /* Operations (as flags) */
82*6c8f7fc3SBen Gras #define AIO_LIO			0x00
83*6c8f7fc3SBen Gras #define AIO_READ		0x01
84*6c8f7fc3SBen Gras #define AIO_WRITE		0x02
85*6c8f7fc3SBen Gras #define AIO_SYNC		0x04
86*6c8f7fc3SBen Gras #define AIO_DSYNC		0x08
87*6c8f7fc3SBen Gras 
88*6c8f7fc3SBen Gras /* Job states */
89*6c8f7fc3SBen Gras #define JOB_NONE		0x0
90*6c8f7fc3SBen Gras #define JOB_WIP			0x1
91*6c8f7fc3SBen Gras #define JOB_DONE		0x2
92*6c8f7fc3SBen Gras 
93*6c8f7fc3SBen Gras /* Structure of AIO job */
94*6c8f7fc3SBen Gras struct aio_job {
95*6c8f7fc3SBen Gras 	int aio_op;		/* Operation code */
96*6c8f7fc3SBen Gras 	struct aiocb aiocbp;	/* AIO data structure */
97*6c8f7fc3SBen Gras 	void *aiocb_uptr;	/* User-space pointer for identification of job */
98*6c8f7fc3SBen Gras 	TAILQ_ENTRY(aio_job) list;
99*6c8f7fc3SBen Gras 	struct lio_req *lio;
100*6c8f7fc3SBen Gras };
101*6c8f7fc3SBen Gras 
102*6c8f7fc3SBen Gras /* LIO structure */
103*6c8f7fc3SBen Gras struct lio_req {
104*6c8f7fc3SBen Gras 	u_int refcnt;		/* Reference counter */
105*6c8f7fc3SBen Gras 	struct sigevent sig;	/* Signal of lio_listio() calls */
106*6c8f7fc3SBen Gras };
107*6c8f7fc3SBen Gras 
108*6c8f7fc3SBen Gras /* Structure of AIO data for process */
109*6c8f7fc3SBen Gras struct aioproc {
110*6c8f7fc3SBen Gras 	kmutex_t aio_mtx;		/* Protects the entire structure */
111*6c8f7fc3SBen Gras 	kcondvar_t aio_worker_cv;	/* Signals on a new job */
112*6c8f7fc3SBen Gras 	kcondvar_t done_cv;		/* Signals when the job is done */
113*6c8f7fc3SBen Gras 	struct aio_job *curjob;		/* Currently processing AIO job */
114*6c8f7fc3SBen Gras 	unsigned int jobs_count;	/* Count of the jobs */
115*6c8f7fc3SBen Gras 	TAILQ_HEAD(, aio_job) jobs_queue;/* Queue of the AIO jobs */
116*6c8f7fc3SBen Gras 	struct lwp *aio_worker;		/* AIO worker thread */
117*6c8f7fc3SBen Gras };
118*6c8f7fc3SBen Gras 
119*6c8f7fc3SBen Gras extern u_int aio_listio_max;
120*6c8f7fc3SBen Gras /* Prototypes */
121*6c8f7fc3SBen Gras void	aio_print_jobs(void (*)(const char *, ...) __printflike(1, 2));
122*6c8f7fc3SBen Gras int	aio_suspend1(struct lwp *, struct aiocb **, int, struct timespec *);
123*6c8f7fc3SBen Gras 
124*6c8f7fc3SBen Gras #endif /* _KERNEL */
125*6c8f7fc3SBen Gras 
126*6c8f7fc3SBen Gras #endif /* _SYS_AIO_H_ */
127