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