10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51885Sraf * Common Development and Distribution License (the "License"). 61885Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211885Sraf 220Sstevel@tonic-gate /* 238519SVamsi.Krishna@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _SYS_AIO_IMPL_H 280Sstevel@tonic-gate #define _SYS_AIO_IMPL_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #include <sys/aio_req.h> 310Sstevel@tonic-gate #include <sys/aio.h> 320Sstevel@tonic-gate #include <sys/aiocb.h> 330Sstevel@tonic-gate #include <sys/uio.h> 340Sstevel@tonic-gate #include <sys/dditypes.h> 350Sstevel@tonic-gate #include <sys/siginfo.h> 360Sstevel@tonic-gate #include <sys/port.h> 370Sstevel@tonic-gate #include <sys/port_kernel.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate #ifdef __cplusplus 400Sstevel@tonic-gate extern "C" { 410Sstevel@tonic-gate #endif 420Sstevel@tonic-gate 430Sstevel@tonic-gate #ifdef _KERNEL 440Sstevel@tonic-gate 450Sstevel@tonic-gate #define AIO_HASHSZ 8192L /* power of 2 */ 460Sstevel@tonic-gate #define AIO_HASH(cookie) (((uintptr_t)(cookie) >> 3) & (AIO_HASHSZ-1)) 470Sstevel@tonic-gate #define DUPLICATE 1 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * an aio_list_t is the head of a list. a group of requests are in 510Sstevel@tonic-gate * the same list if their aio_req_list field point to the same list 520Sstevel@tonic-gate * head. 530Sstevel@tonic-gate * 540Sstevel@tonic-gate * a list head is used for notification. a group of requests that 550Sstevel@tonic-gate * should only notify a process when they are done will have a 560Sstevel@tonic-gate * list head. notification is sent when the group of requests are 571885Sraf * done. 580Sstevel@tonic-gate */ 590Sstevel@tonic-gate typedef struct aio_lio { 600Sstevel@tonic-gate int lio_nent; /* number of requests in list */ 610Sstevel@tonic-gate int lio_refcnt; /* number of requests active */ 620Sstevel@tonic-gate struct aio_lio *lio_next; /* free list pointer */ 630Sstevel@tonic-gate kcondvar_t lio_notify; /* list notification */ 640Sstevel@tonic-gate sigqueue_t *lio_sigqp; /* sigqueue_t pointer */ 651885Sraf int lio_port; /* port number notification */ 661885Sraf port_kevent_t *lio_portkev; /* port event structure */ 670Sstevel@tonic-gate } aio_lio_t; 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* 700Sstevel@tonic-gate * async I/O request struct - one per I/O request. 710Sstevel@tonic-gate */ 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* 740Sstevel@tonic-gate * Clustering: The aio_req_t structure is used by the PXFS module 750Sstevel@tonic-gate * as a contract private interface. 760Sstevel@tonic-gate */ 770Sstevel@tonic-gate 780Sstevel@tonic-gate typedef struct aio_req_t { 790Sstevel@tonic-gate struct aio_req aio_req; 800Sstevel@tonic-gate int aio_req_fd; /* aio's file descriptor */ 810Sstevel@tonic-gate int aio_req_flags; /* flags */ 820Sstevel@tonic-gate aio_result_t *aio_req_resultp; /* pointer to user's results */ 830Sstevel@tonic-gate int (*aio_req_cancel)(); /* driver's cancel cb. */ 840Sstevel@tonic-gate struct aio_req_t *aio_req_next; /* doneq and pollq pointers */ 850Sstevel@tonic-gate struct aio_req_t *aio_req_prev; /* doubly linked list */ 860Sstevel@tonic-gate struct aio_req_t *aio_hash_next; /* next in a hash bucket */ 870Sstevel@tonic-gate aio_lio_t *aio_req_lio; /* head of list IO chain */ 880Sstevel@tonic-gate struct uio aio_req_uio; /* uio struct */ 890Sstevel@tonic-gate struct iovec aio_req_iov; /* iovec struct */ 900Sstevel@tonic-gate struct buf aio_req_buf; /* buf struct */ 910Sstevel@tonic-gate sigqueue_t *aio_req_sigqp; /* sigqueue_t pointer */ 920Sstevel@tonic-gate union { 930Sstevel@tonic-gate caddr_t iocb; /* ptr to aiocb: 32-32, 64-64 */ 940Sstevel@tonic-gate caddr32_t iocb32; /* ptr to aiocb: 32-64 */ 950Sstevel@tonic-gate } aio_req_iocb; 960Sstevel@tonic-gate port_kevent_t *aio_req_portkev; /* port event structure */ 970Sstevel@tonic-gate int aio_req_port; /* port id */ 980Sstevel@tonic-gate } aio_req_t; 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * Struct for asynchronous I/O (aio) information per process. 1020Sstevel@tonic-gate * Each proc stucture has a field pointing to this struct. 1030Sstevel@tonic-gate * The field will be null if no aio is used. 1040Sstevel@tonic-gate */ 1050Sstevel@tonic-gate typedef struct aio { 1060Sstevel@tonic-gate int aio_pending; /* # uncompleted requests */ 1070Sstevel@tonic-gate int aio_outstanding; /* total # of requests */ 1080Sstevel@tonic-gate int aio_ok; /* everything ok when set */ 1090Sstevel@tonic-gate int aio_flags; /* flags */ 110304Spraks int aio_rqclnup; /* cleanup request used by DR */ 1110Sstevel@tonic-gate int aio_portpendcnt; /* # pending req. per port */ 1120Sstevel@tonic-gate aio_req_t *aio_portq; /* port queue head */ 1130Sstevel@tonic-gate aio_req_t *aio_portcleanupq; /* port cleanup queue head */ 1140Sstevel@tonic-gate aio_req_t *aio_portpending; /* list of pending requests */ 1150Sstevel@tonic-gate aio_req_t *aio_free; /* freelist of aio requests */ 1160Sstevel@tonic-gate aio_lio_t *aio_lio_free; /* freelist of lio heads */ 1170Sstevel@tonic-gate aio_req_t *aio_doneq; /* done queue head */ 1180Sstevel@tonic-gate aio_req_t *aio_pollq; /* poll queue head */ 1190Sstevel@tonic-gate aio_req_t *aio_notifyq; /* notify queue head */ 1200Sstevel@tonic-gate aio_req_t *aio_cleanupq; /* cleanup queue head */ 1210Sstevel@tonic-gate kmutex_t aio_mutex; /* mutex for aio struct */ 1220Sstevel@tonic-gate kmutex_t aio_cleanupq_mutex; /* cleanupq processing */ 1230Sstevel@tonic-gate kcondvar_t aio_waitcv; /* cv for aiowait()'ers */ 1240Sstevel@tonic-gate kcondvar_t aio_cleanupcv; /* notify cleanup, aio_done */ 1250Sstevel@tonic-gate kcondvar_t aio_waitncv; /* cv for further aiowaitn() */ 1260Sstevel@tonic-gate kcondvar_t aio_portcv; /* cv for port events */ 1270Sstevel@tonic-gate aiocb_t **aio_iocb; /* list of 32 & 64 bit ptrs */ 1280Sstevel@tonic-gate size_t aio_iocbsz; /* reserved space for iocbs */ 1290Sstevel@tonic-gate uint_t aio_waitncnt; /* # requests for aiowaitn */ 1300Sstevel@tonic-gate int aio_notifycnt; /* # user-level notifications */ 1310Sstevel@tonic-gate kmutex_t aio_portq_mutex; /* mutex for aio_portq */ 1320Sstevel@tonic-gate aio_req_t *aio_hash[AIO_HASHSZ]; /* hash list of requests */ 1330Sstevel@tonic-gate } aio_t; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate /* 1360Sstevel@tonic-gate * aio_flags for an aio_t. 1370Sstevel@tonic-gate */ 138*10719SRoger.Faulkner@Sun.COM #define AIO_CLEANUP 0x0001 /* do aio cleanup processing */ 139*10719SRoger.Faulkner@Sun.COM #define AIO_WAITN 0x0002 /* aiowaitn in progress */ 140*10719SRoger.Faulkner@Sun.COM #define AIO_WAITN_PENDING 0x0004 /* aiowaitn requests pending */ 141*10719SRoger.Faulkner@Sun.COM #define AIO_REQ_BLOCK 0x0008 /* block new requests */ 142*10719SRoger.Faulkner@Sun.COM #define AIO_CLEANUP_PORT 0x0010 143*10719SRoger.Faulkner@Sun.COM #define AIO_DONE_ACTIVE 0x0020 /* aio_done call in progress */ 144*10719SRoger.Faulkner@Sun.COM #define AIO_SOLARIS_REQ 0x0040 /* an old solaris aio req was issued */ 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate /* 1470Sstevel@tonic-gate * aio_req_flags for an aio_req_t 1480Sstevel@tonic-gate */ 149*10719SRoger.Faulkner@Sun.COM #define AIO_POLL 0x0001 /* AIO_INPROGRESS is set */ 150*10719SRoger.Faulkner@Sun.COM #define AIO_PENDING 0x0002 /* aio is in progress */ 151*10719SRoger.Faulkner@Sun.COM #define AIO_PHYSIODONE 0x0004 /* unlocked phys pages */ 152*10719SRoger.Faulkner@Sun.COM #define AIO_COPYOUTDONE 0x0008 /* result copied to userland */ 153*10719SRoger.Faulkner@Sun.COM #define AIO_NOTIFYQ 0x0010 /* aio req is on the notifyq */ 154*10719SRoger.Faulkner@Sun.COM #define AIO_CLEANUPQ 0x0020 /* aio req is on the cleanupq */ 155*10719SRoger.Faulkner@Sun.COM #define AIO_POLLQ 0x0040 /* aio req is on the pollq */ 156*10719SRoger.Faulkner@Sun.COM #define AIO_DONEQ 0x0080 /* aio req is on the doneq */ 157*10719SRoger.Faulkner@Sun.COM #define AIO_ZEROLEN 0x0100 /* aio req is zero length */ 158*10719SRoger.Faulkner@Sun.COM #define AIO_PAGELOCKDONE 0x0200 /* aio called as_pagelock() */ 159*10719SRoger.Faulkner@Sun.COM #define AIO_CLOSE_PORT 0x0400 /* port is being closed */ 160*10719SRoger.Faulkner@Sun.COM #define AIO_SIGNALLED 0x0800 /* process signalled by this req */ 161*10719SRoger.Faulkner@Sun.COM #define AIO_SOLARIS 0x1000 /* this is an old solaris aio req */ 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* flag argument of aio_cleanup() */ 1640Sstevel@tonic-gate 165*10719SRoger.Faulkner@Sun.COM #define AIO_CLEANUP_POLL 0 /* check kaio poll queue */ 166*10719SRoger.Faulkner@Sun.COM #define AIO_CLEANUP_EXIT 1 /* aio_cleanup_exit() */ 167*10719SRoger.Faulkner@Sun.COM #define AIO_CLEANUP_THREAD 2 /* aio_cleanup_thread() */ 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate /* functions exported by common/os/aio_subr.c */ 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate extern int aphysio(int (*)(), int (*)(), dev_t, int, void (*)(), 1720Sstevel@tonic-gate struct aio_req *); 1730Sstevel@tonic-gate extern void aphysio_unlock(aio_req_t *); 1740Sstevel@tonic-gate extern void aio_cleanup(int); 1750Sstevel@tonic-gate extern void aio_cleanup_exit(void); 1760Sstevel@tonic-gate extern void aio_zerolen(aio_req_t *); 1770Sstevel@tonic-gate extern void aio_req_free(aio_t *, aio_req_t *); 1780Sstevel@tonic-gate extern void aio_cleanupq_concat(aio_t *, aio_req_t *, int); 1790Sstevel@tonic-gate extern void aio_copyout_result(aio_req_t *); 1800Sstevel@tonic-gate extern void aio_copyout_result_port(struct iovec *, struct buf *, void *); 1810Sstevel@tonic-gate extern void aio_req_remove_portq(aio_t *, aio_req_t *); 1821885Sraf extern void aio_enq(aio_req_t **, aio_req_t *, int); 1831885Sraf extern void aio_deq(aio_req_t **, aio_req_t *); 1840Sstevel@tonic-gate /* Clustering: PXFS module uses this interface */ 1850Sstevel@tonic-gate extern void aio_done(struct buf *); 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate #endif /* _KERNEL */ 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate #ifdef __cplusplus 1900Sstevel@tonic-gate } 1910Sstevel@tonic-gate #endif 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate #endif /* _SYS_AIO_IMPL_H */ 194