xref: /titanic_51/usr/src/uts/common/sys/aio_impl.h (revision e37d48e735b8e55f327dfa35a2d0006049ea5e58)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_AIO_IMPL_H
28 #define	_SYS_AIO_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/aio_req.h>
33 #include <sys/aio.h>
34 #include <sys/aiocb.h>
35 #include <sys/uio.h>
36 #include <sys/dditypes.h>
37 #include <sys/siginfo.h>
38 #include <sys/port.h>
39 #include <sys/port_kernel.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 #ifdef _KERNEL
46 
47 #define	AIO_HASHSZ		8192L		/* power of 2 */
48 #define	AIO_HASH(cookie)	(((uintptr_t)(cookie) >> 3) & (AIO_HASHSZ-1))
49 #define	DUPLICATE 1
50 #define	AIO_IOCB_MAX		32768L
51 
52 /*
53  * an aio_list_t is the head of a list. a group of requests are in
54  * the same list if their aio_req_list field point to the same list
55  * head.
56  *
57  * a list head is used for notification. a group of requests that
58  * should only notify a process when they are done will have a
59  * list head. notification is sent when the group of requests are
60  * done. individual requests do not send out any notification.
61  */
62 typedef struct aio_lio {
63 	int 		lio_nent;		/* number of requests in list */
64 	int 		lio_refcnt;		/* number of requests active */
65 	struct aio_lio	*lio_next;		/* free list pointer */
66 	kcondvar_t	lio_notify;		/* list notification */
67 	sigqueue_t	*lio_sigqp;		/* sigqueue_t pointer */
68 } aio_lio_t;
69 
70 /*
71  * async I/O request struct - one per I/O request.
72  */
73 
74 /*
75  * Clustering: The aio_req_t structure is used by the PXFS module
76  * as a contract private interface.
77  */
78 
79 typedef struct aio_req_t {
80 	struct aio_req	aio_req;
81 	int		aio_req_fd;		/* aio's file descriptor */
82 	int		aio_req_flags;		/* flags */
83 	aio_result_t	*aio_req_resultp;	/* pointer to user's results */
84 	int		(*aio_req_cancel)();	/* driver's cancel cb. */
85 	struct aio_req_t *aio_req_next;		/* doneq and pollq pointers */
86 	struct aio_req_t *aio_req_prev;		/* doubly linked list */
87 	struct aio_req_t *aio_hash_next;	/* next in a hash bucket */
88 	aio_lio_t 	*aio_req_lio;		/* head of list IO chain */
89 	struct uio	aio_req_uio;		/* uio struct */
90 	struct iovec	aio_req_iov;		/* iovec struct */
91 	struct buf	aio_req_buf;		/* buf struct */
92 	sigqueue_t	*aio_req_sigqp;		/* sigqueue_t pointer */
93 	union {
94 		caddr_t 	iocb;		/* ptr to aiocb: 32-32, 64-64 */
95 		caddr32_t	iocb32;		/* ptr to aiocb: 32-64 */
96 	} aio_req_iocb;
97 	port_kevent_t	*aio_req_portkev;	/* port event structure */
98 	int		aio_req_port;		/* port id */
99 } aio_req_t;
100 
101 /*
102  * Struct for asynchronous I/O (aio) information per process.
103  * Each proc stucture has a field pointing to this struct.
104  * The field will be null if no aio is used.
105  */
106 typedef struct aio {
107 	int		aio_pending;		/* # uncompleted requests */
108 	int		aio_outstanding;	/* total # of requests */
109 	int		aio_ok;			/* everything ok when set */
110 	int		aio_flags;		/* flags */
111 	int		aio_rqclnup;		/* cleanup request used by DR */
112 	int		aio_portpendcnt;	/* # pending req. per port */
113 	aio_req_t	*aio_portq;  		/* port queue head */
114 	aio_req_t	*aio_portcleanupq;	/* port cleanup queue head */
115 	aio_req_t	*aio_portpending;	/* list of pending requests */
116 	aio_req_t	*aio_free;  		/* freelist of aio requests */
117 	aio_lio_t	*aio_lio_free;		/* freelist of lio heads */
118 	aio_req_t	*aio_doneq;		/* done queue head */
119 	aio_req_t	*aio_pollq;		/* poll queue head */
120 	aio_req_t	*aio_notifyq;		/* notify queue head */
121 	aio_req_t	*aio_cleanupq;		/* cleanup queue head */
122 	kmutex_t    	aio_mutex;		/* mutex for aio struct */
123 	kmutex_t	aio_cleanupq_mutex;	/* cleanupq processing */
124 	kcondvar_t  	aio_waitcv;		/* cv for aiowait()'ers */
125 	kcondvar_t  	aio_cleanupcv;		/* notify cleanup, aio_done */
126 	kcondvar_t  	aio_waitncv;		/* cv for further aiowaitn() */
127 	kcondvar_t  	aio_portcv;		/* cv for port events */
128 	aiocb_t		**aio_iocb;		/* list of 32 & 64 bit ptrs */
129 	size_t		aio_iocbsz;		/* reserved space for iocbs */
130 	uint_t		aio_waitncnt;		/* # requests for aiowaitn */
131 	int 		aio_notifycnt;		/* # user-level notifications */
132 	kmutex_t	aio_portq_mutex;	/* mutex for aio_portq */
133 	aio_req_t 	*aio_hash[AIO_HASHSZ];	/* hash list of requests */
134 } aio_t;
135 
136 /*
137  * aio_flags for an aio_t.
138  */
139 #define	AIO_CLEANUP		0x1		/* do aio cleanup processing */
140 #define	AIO_WAITN		0x2		/* aiowaitn in progress */
141 #define	AIO_WAITN_PENDING	0x4		/* aiowaitn requests pending */
142 #define	AIO_REQ_BLOCK		0x8		/* block new requests */
143 #define	AIO_CLEANUP_PORT	0x10
144 #define	AIO_DONE_ACTIVE		0x20		/* aio_done call in progress */
145 
146 /*
147  * aio_req_flags for an aio_req_t
148  */
149 #define	AIO_POLL	0x1			/* AIO_INPROGRESS is set */
150 #define	AIO_PENDING	0x2			/* aio is in progress */
151 #define	AIO_PHYSIODONE	0x4			/* unlocked phys pages */
152 #define	AIO_COPYOUTDONE	0x8			/* result copied to userland */
153 #define	AIO_NOTIFYQ	0x10			/* aio req is on the notifyq */
154 #define	AIO_CLEANUPQ	0x20			/* aio req is on the cleanupq */
155 #define	AIO_POLLQ	0x40			/* aio req is on the pollq */
156 #define	AIO_DONEQ	0x80			/* aio req is on the doneq */
157 #define	AIO_ZEROLEN	0x100			/* aio req is zero length */
158 #define	AIO_PAGELOCKDONE	0x200		/* aio called as_pagelock() */
159 #define	AIO_CLOSE_PORT		0x400		/* port is being closed */
160 
161 #ifdef DEBUG
162 #define	AIO_REQ_PEND	0x1000			/* req in pending queue */
163 #define	AIO_REQ_CLEAN	0x2000			/* req in cleanup queue */
164 #define	AIO_REQ_PORTQ	0x4000			/* req in port done queue */
165 #define	AIO_REQ_FREE	0x8000			/* req in free queue */
166 #endif
167 
168 /* flag argument of aio_cleanup() */
169 
170 #define	AIO_CLEANUP_POLL	0		/* check kaio poll queue */
171 #define	AIO_CLEANUP_EXIT	1		/* aio_cleanup_exit() */
172 #define	AIO_CLEANUP_THREAD	2		/* aio_cleanup_thread() */
173 
174 /* functions exported by common/os/aio_subr.c */
175 
176 extern int aphysio(int (*)(), int (*)(), dev_t, int, void (*)(),
177 		struct aio_req *);
178 extern void aphysio_unlock(aio_req_t *);
179 extern void aio_cleanup(int);
180 extern void aio_cleanup_exit(void);
181 extern void aio_zerolen(aio_req_t *);
182 extern void aio_req_free(aio_t *, aio_req_t *);
183 extern void aio_cleanupq_concat(aio_t *, aio_req_t *, int);
184 extern void aio_copyout_result(aio_req_t *);
185 extern void aio_copyout_result_port(struct iovec *, struct buf *, void *);
186 extern void aio_enq_port_pending(aio_t *, aio_req_t *);
187 extern void aio_req_remove_portq(aio_t *, aio_req_t *);
188 /* Clustering: PXFS module uses this interface */
189 extern void aio_done(struct buf *);
190 
191 #endif /* _KERNEL */
192 
193 #ifdef	__cplusplus
194 }
195 #endif
196 
197 #endif /* _SYS_AIO_IMPL_H */
198