xref: /onnv-gate/usr/src/uts/common/avs/ns/rdc/rdc_io.h (revision 10715:b905b416f22e)
17836SJohn.Forte@Sun.COM /*
27836SJohn.Forte@Sun.COM  * CDDL HEADER START
37836SJohn.Forte@Sun.COM  *
47836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
57836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
67836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
77836SJohn.Forte@Sun.COM  *
87836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
107836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
117836SJohn.Forte@Sun.COM  * and limitations under the License.
127836SJohn.Forte@Sun.COM  *
137836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
147836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
167836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
177836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
187836SJohn.Forte@Sun.COM  *
197836SJohn.Forte@Sun.COM  * CDDL HEADER END
207836SJohn.Forte@Sun.COM  */
217836SJohn.Forte@Sun.COM /*
22*10715SThomas.Atkins@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237836SJohn.Forte@Sun.COM  * Use is subject to license terms.
247836SJohn.Forte@Sun.COM  */
257836SJohn.Forte@Sun.COM 
267836SJohn.Forte@Sun.COM #ifndef _RDC_IO_H
277836SJohn.Forte@Sun.COM #define	_RDC_IO_H
287836SJohn.Forte@Sun.COM 
297836SJohn.Forte@Sun.COM #ifdef	__cplusplus
307836SJohn.Forte@Sun.COM extern "C" {
317836SJohn.Forte@Sun.COM #endif
327836SJohn.Forte@Sun.COM 
337836SJohn.Forte@Sun.COM 
347836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s.h>
357836SJohn.Forte@Sun.COM #ifdef DS_DDICT
367836SJohn.Forte@Sun.COM #define	bool_t	int
377836SJohn.Forte@Sun.COM #endif
387836SJohn.Forte@Sun.COM #include  <sys/nsctl/rdc_prot.h>
397836SJohn.Forte@Sun.COM #include <sys/nsctl/nsctl.h>
407836SJohn.Forte@Sun.COM #include <sys/nsctl/rdc_ioctl.h>
417836SJohn.Forte@Sun.COM 
427836SJohn.Forte@Sun.COM /*
437836SJohn.Forte@Sun.COM  * Definitions for kstats
447836SJohn.Forte@Sun.COM  */
457836SJohn.Forte@Sun.COM #define	RDC_MKSTAT_MAXSETS		"maxsets"
467836SJohn.Forte@Sun.COM #define	RDC_MKSTAT_MAXFBAS		"maxfbas"
477836SJohn.Forte@Sun.COM #define	RDC_MKSTAT_RPC_TIMEOUT		"rpc_timeout"
487836SJohn.Forte@Sun.COM #define	RDC_MKSTAT_HEALTH_THRES		"health_thres"
497836SJohn.Forte@Sun.COM #define	RDC_MKSTAT_BITMAP_WRITES	"bitmap_writes"
507836SJohn.Forte@Sun.COM #define	RDC_MKSTAT_CLNT_COTS_CALLS	"clnt_cots_calls"
517836SJohn.Forte@Sun.COM #define	RDC_MKSTAT_CLNT_CLTS_CALLS	"clnt_clts_calls"
527836SJohn.Forte@Sun.COM #define	RDC_MKSTAT_SVC_COTS_CALLS	"svc_cots_calls"
537836SJohn.Forte@Sun.COM #define	RDC_MKSTAT_SVC_CLTS_CALLS	"svc_clts_calls"
547836SJohn.Forte@Sun.COM #define	RDC_MKSTAT_BITMAP_REF_DELAY	"bitmap_ref_delay"
557836SJohn.Forte@Sun.COM 
567836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_FLAGS		"flags"
577836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_SYNCFLAGS		"syncflags"
587836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_BMPFLAGS		"bmpflags"
597836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_SYNCPOS		"syncpos"
607836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_VOLSIZE		"volsize"
617836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_BITSSET		"bitsset"
627836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_AUTOSYNC		"autosync"
637836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_MAXQFBAS		"maxqfbas"
647836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_MAXQITEMS		"maxqitems"
657836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_FILE			"primary_vol"
667836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_SECFILE		"secondary_vol"
677836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_BITMAP		"bitmap"
687836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_PRIMARY_HOST		"primary_host"
697836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_SECONDARY_HOST	"secondary_host"
707836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_TYPE_FLAG		"type_flag"
717836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_BMP_SIZE		"bmp_size"
727836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_DISK_STATUS		"disk_status"
737836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_IF_DOWN		"if_down"
747836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_IF_RPC_VERSION	"if_rpc_version"
757836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_ASYNC_THROTTLE_DELAY	"async_throttle_delay"
767836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_ASYNC_BLOCK_HWM	"async_block_hwm"
777836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_ASYNC_ITEM_HWM	"async_item_hwm"
787836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_QUEUE_TYPE		"async_queue_type"
797836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_ASYNC_ITEMS		"async_queue_items"
807836SJohn.Forte@Sun.COM #define	RDC_IKSTAT_ASYNC_BLOCKS		"async_queue_blocks"
817836SJohn.Forte@Sun.COM 
827836SJohn.Forte@Sun.COM /*
837836SJohn.Forte@Sun.COM  * Queue types
847836SJohn.Forte@Sun.COM  */
857836SJohn.Forte@Sun.COM #define	RDC_DISKQUE	0X01
867836SJohn.Forte@Sun.COM #define	RDC_MEMQUE	0x02
877836SJohn.Forte@Sun.COM #define	RDC_NOQUE	-1
887836SJohn.Forte@Sun.COM 
897836SJohn.Forte@Sun.COM #define	RDC_ACTIVE	0x1
907836SJohn.Forte@Sun.COM #define	RDC_INACTIVE	0x2
917836SJohn.Forte@Sun.COM 
927836SJohn.Forte@Sun.COM #ifdef _KERNEL
937836SJohn.Forte@Sun.COM 
947836SJohn.Forte@Sun.COM extern nstset_t *_rdc_ioset;
957836SJohn.Forte@Sun.COM extern nstset_t *_rdc_flset;
967836SJohn.Forte@Sun.COM 
977836SJohn.Forte@Sun.COM #ifdef DEBUG
987836SJohn.Forte@Sun.COM extern int RDC_MAX_SYNC_THREADS;
997836SJohn.Forte@Sun.COM extern int rdc_maxthreads_last;
1007836SJohn.Forte@Sun.COM int num_sync_threads;
1017836SJohn.Forte@Sun.COM #else
1027836SJohn.Forte@Sun.COM #define	RDC_MAX_SYNC_THREADS	8
1037836SJohn.Forte@Sun.COM #endif
1047836SJohn.Forte@Sun.COM #ifdef DEBUG
1057836SJohn.Forte@Sun.COM #define	RDC_AVAIL_THR_TUNE(n)	\
1067836SJohn.Forte@Sun.COM 	do { \
1077836SJohn.Forte@Sun.COM 		if (rdc_maxthreads_last < RDC_MAX_SYNC_THREADS) { \
1087836SJohn.Forte@Sun.COM 			(void) nst_add_thread(n.rdc_syncset, \
1097836SJohn.Forte@Sun.COM 		    RDC_MAX_SYNC_THREADS - rdc_maxthreads_last);\
1107836SJohn.Forte@Sun.COM 		} \
1117836SJohn.Forte@Sun.COM 		if (rdc_maxthreads_last > RDC_MAX_SYNC_THREADS) { \
1127836SJohn.Forte@Sun.COM 			(void) nst_del_thread(n.rdc_syncset, \
1137836SJohn.Forte@Sun.COM 			    rdc_maxthreads_last - RDC_MAX_SYNC_THREADS); \
1147836SJohn.Forte@Sun.COM 		} \
1157836SJohn.Forte@Sun.COM 		n.avail_thr = RDC_MAX_SYNC_THREADS - n.active_thr; \
1167836SJohn.Forte@Sun.COM 		if (n.avail_thr < 0) { \
1177836SJohn.Forte@Sun.COM 			n.avail_thr = 0; \
1187836SJohn.Forte@Sun.COM 		} \
1197836SJohn.Forte@Sun.COM 		rdc_maxthreads_last = RDC_MAX_SYNC_THREADS; \
1207836SJohn.Forte@Sun.COM 		num_sync_threads = nst_nthread(n.rdc_syncset); \
1217836SJohn.Forte@Sun.COM 	} while (0);
1227836SJohn.Forte@Sun.COM #else
1237836SJohn.Forte@Sun.COM #define	RDC_AVAIL_THR_TUNE(n)	\
1247836SJohn.Forte@Sun.COM 	do { \
1257836SJohn.Forte@Sun.COM 		n.avail_thr = RDC_MAX_SYNC_THREADS - n.active_thr; \
1267836SJohn.Forte@Sun.COM 		if (n.avail_thr < 0) \
1277836SJohn.Forte@Sun.COM 			n.avail_thr = 0; \
1287836SJohn.Forte@Sun.COM 	} while (0);
1297836SJohn.Forte@Sun.COM 
1307836SJohn.Forte@Sun.COM #endif
1317836SJohn.Forte@Sun.COM 
1327836SJohn.Forte@Sun.COM typedef struct syncloop_info {
1337836SJohn.Forte@Sun.COM 	int		active_thr;
1347836SJohn.Forte@Sun.COM 	int		avail_thr; /* should be MAX_RDC_SYNC_THREADS - active */
1357836SJohn.Forte@Sun.COM 	kmutex_t	lock;
1367836SJohn.Forte@Sun.COM 	nstset_t	*rdc_syncset;
1377836SJohn.Forte@Sun.COM } sync_info_t;
1387836SJohn.Forte@Sun.COM 
1397836SJohn.Forte@Sun.COM sync_info_t sync_info;
1407836SJohn.Forte@Sun.COM 
1417836SJohn.Forte@Sun.COM /*
1427836SJohn.Forte@Sun.COM  * Static server information
1437836SJohn.Forte@Sun.COM  */
1447836SJohn.Forte@Sun.COM typedef struct servinfo {
1457836SJohn.Forte@Sun.COM 	struct knetconfig	*ri_knconf;	/* bound TLI fd */
1467836SJohn.Forte@Sun.COM 	struct netbuf		ri_addr;	/* server's address */
1477836SJohn.Forte@Sun.COM 	struct sec_data		*ri_secdata;	/* sec data for rpcsec module */
1487836SJohn.Forte@Sun.COM 	char			*ri_hostname;	/* server's hostname */
1497836SJohn.Forte@Sun.COM 	int			ri_hostnamelen; /* server's hostname length */
1507836SJohn.Forte@Sun.COM } rdc_srv_t;
1517836SJohn.Forte@Sun.COM 
1527836SJohn.Forte@Sun.COM /*
1537836SJohn.Forte@Sun.COM  * Interface structure, including health monitoring.
1547836SJohn.Forte@Sun.COM  */
1557836SJohn.Forte@Sun.COM typedef struct rdc_if_s {
1567836SJohn.Forte@Sun.COM 	struct rdc_if_s *next;		/* chain pointer */
1577836SJohn.Forte@Sun.COM 	struct netbuf ifaddr;
1587836SJohn.Forte@Sun.COM 	struct netbuf r_ifaddr;
1597836SJohn.Forte@Sun.COM 	rdc_srv_t *srv;			/* servinfo of server end */
1607836SJohn.Forte@Sun.COM 	int	if_down;		/* i/f is down (set on primary) */
1617836SJohn.Forte@Sun.COM 	int	isprimary;		/* this end is a primary */
1627836SJohn.Forte@Sun.COM 	int	issecondary;		/* this end is a secondary */
1637836SJohn.Forte@Sun.COM 	rpcvers_t rpc_version;		/* RPC protocol version in use */
1647836SJohn.Forte@Sun.COM 	int	no_ping;		/* set on secondary to hold off RPCs */
1657836SJohn.Forte@Sun.COM 	int	old_pulse;		/* previous (current) pulse value */
1667836SJohn.Forte@Sun.COM 	int	new_pulse;		/* new (incoming) pulse value */
1677836SJohn.Forte@Sun.COM 	int	deadness;		/* how close to death are we? */
1687836SJohn.Forte@Sun.COM 	volatile int exiting;		/* daemon exit flag */
1697836SJohn.Forte@Sun.COM 	time_t	last;			/* time of last ping */
1707836SJohn.Forte@Sun.COM } rdc_if_t;
1717836SJohn.Forte@Sun.COM 
1727836SJohn.Forte@Sun.COM 
1737836SJohn.Forte@Sun.COM typedef struct rdc_aio_s {
1747836SJohn.Forte@Sun.COM 	struct rdc_aio_s *next;
1757836SJohn.Forte@Sun.COM 	nsc_buf_t *handle;
1767836SJohn.Forte@Sun.COM 	nsc_buf_t *qhandle;
1777836SJohn.Forte@Sun.COM 	nsc_off_t pos;
1787836SJohn.Forte@Sun.COM 	nsc_off_t qpos;
1797836SJohn.Forte@Sun.COM 	nsc_size_t len;
1807836SJohn.Forte@Sun.COM 	nsc_size_t orig_len;
1817836SJohn.Forte@Sun.COM 	int	flag;
1827836SJohn.Forte@Sun.COM 	int	iostatus;
1837836SJohn.Forte@Sun.COM 	int	index;
1847836SJohn.Forte@Sun.COM 	uint_t	seq;		/* sequence on async Q */
1857836SJohn.Forte@Sun.COM } rdc_aio_t;
1867836SJohn.Forte@Sun.COM 
1877836SJohn.Forte@Sun.COM /* values for (rdc_aio_t *)->iostatus */
1887836SJohn.Forte@Sun.COM enum {
1897836SJohn.Forte@Sun.COM 	RDC_IO_NONE = 0,	/* not used */
1907836SJohn.Forte@Sun.COM 	RDC_IO_INIT,		/* io started */
1917836SJohn.Forte@Sun.COM 	RDC_IO_DONE,		/* io done successfully */
1927836SJohn.Forte@Sun.COM 	RDC_IO_FAILED,		/* io failed */
1937836SJohn.Forte@Sun.COM 	RDC_IO_DISCARDED,	/* io discarded */
1947836SJohn.Forte@Sun.COM 	RDC_IO_CANCELLED	/* group_log in progress */
1957836SJohn.Forte@Sun.COM };
1967836SJohn.Forte@Sun.COM 
1977836SJohn.Forte@Sun.COM 
1987836SJohn.Forte@Sun.COM #define	RDC_MAX_QBLOCKS	16384	/* 8MB temporary q for diskq to flush to */
1997836SJohn.Forte@Sun.COM #define	RDC_LOW_QBLOCKS 13927	/* roughly 85% of queue full */
2007836SJohn.Forte@Sun.COM #define	RDC_HALF_MQUEUE 8192	/* half of the memory queue */
2017836SJohn.Forte@Sun.COM 
2027836SJohn.Forte@Sun.COM typedef struct netqueue {
2037836SJohn.Forte@Sun.COM 	rdc_aio_t *net_qhead;
2047836SJohn.Forte@Sun.COM 	rdc_aio_t *net_qtail;
2057836SJohn.Forte@Sun.COM 	kmutex_t net_qlock;
2067836SJohn.Forte@Sun.COM 	int hwmhit;			/* queue full hit? reset after hwm */
2077836SJohn.Forte@Sun.COM 	int qfill_sleeping;		/* waiting for work? */
2087836SJohn.Forte@Sun.COM 	int qfflags;			/* diskq/memq flusher flags */
2097836SJohn.Forte@Sun.COM 	kcondvar_t qfcv;		/* for timed waits */
2107836SJohn.Forte@Sun.COM 	volatile nsc_size_t blocks;	/* number of FBAs in q */
2117836SJohn.Forte@Sun.COM 	volatile uint64_t nitems;	/* number of items in q */
2127836SJohn.Forte@Sun.COM 	volatile int  inflbls;		/* number of inflight blocks */
2137836SJohn.Forte@Sun.COM 	volatile int  inflitems;	/* number of inflight items */
2147836SJohn.Forte@Sun.COM 	uint64_t  nitems_hwm;		/* highest items on queue */
2157836SJohn.Forte@Sun.COM 	nsc_size_t  blocks_hwm;		/* highest blocks on queue */
2167836SJohn.Forte@Sun.COM 	long throttle_delay;		/* Number of times we delayed x 2 */
2177836SJohn.Forte@Sun.COM } net_queue;
2187836SJohn.Forte@Sun.COM 
2197836SJohn.Forte@Sun.COM 
2207836SJohn.Forte@Sun.COM /*
2217836SJohn.Forte@Sun.COM  * Bitmap header structures.
2227836SJohn.Forte@Sun.COM  * These must be fixed size in all data models.
2237836SJohn.Forte@Sun.COM  * If we ever support little-endian machines (eg. Intel) we will need
2247836SJohn.Forte@Sun.COM  * to add byte-swapping logic.
2257836SJohn.Forte@Sun.COM  */
2267836SJohn.Forte@Sun.COM 
2277836SJohn.Forte@Sun.COM typedef struct {
2287836SJohn.Forte@Sun.COM 	int32_t magic;
2297836SJohn.Forte@Sun.COM 	int32_t serial_mode;
2307836SJohn.Forte@Sun.COM 	int32_t use_mirror;
2317836SJohn.Forte@Sun.COM 	int32_t mirror_down;
2327836SJohn.Forte@Sun.COM 	int32_t sync_needed;
2337836SJohn.Forte@Sun.COM 	char bitmapname[NSC_MAXPATH];
2347836SJohn.Forte@Sun.COM 	char filename[NSC_MAXPATH];
2357836SJohn.Forte@Sun.COM 	int32_t volume_failed;
2367836SJohn.Forte@Sun.COM } rdc_headerv2_t;
2377836SJohn.Forte@Sun.COM #define	RDC_HDR_V2	0x52444302	/* RDC2 */
2387836SJohn.Forte@Sun.COM 
2397836SJohn.Forte@Sun.COM #define	RDC_SYNC	0x1
2407836SJohn.Forte@Sun.COM #define	RDC_REV_SYNC	0x2
2417836SJohn.Forte@Sun.COM #define	RDC_FULL_SYNC	0x3
2427836SJohn.Forte@Sun.COM 
2437836SJohn.Forte@Sun.COM #define	RDC_FAILED	0x1
2447836SJohn.Forte@Sun.COM #define	RDC_COMPLETED	0x2
2457836SJohn.Forte@Sun.COM 
2467836SJohn.Forte@Sun.COM typedef struct {
2477836SJohn.Forte@Sun.COM 	char	file[NSC_MAXPATH];
2487836SJohn.Forte@Sun.COM 	char	bitmap[NSC_MAXPATH];
2497836SJohn.Forte@Sun.COM } rdc_hdr_addr_t;
2507836SJohn.Forte@Sun.COM 
2517836SJohn.Forte@Sun.COM typedef struct {
2527836SJohn.Forte@Sun.COM 	int32_t		magic;
2537836SJohn.Forte@Sun.COM 	rdc_hdr_addr_t	primary;
2547836SJohn.Forte@Sun.COM 	rdc_hdr_addr_t	secondary;
2557836SJohn.Forte@Sun.COM 	int32_t		flags;
2567836SJohn.Forte@Sun.COM 	int32_t		autosync;
2577836SJohn.Forte@Sun.COM 	int32_t		maxqfbas;
2587836SJohn.Forte@Sun.COM 	int32_t		maxqitems;
2597836SJohn.Forte@Sun.COM 	int32_t		syshostid;	/* for cluster bitmaps */
2607836SJohn.Forte@Sun.COM } rdc_headerv3_t;
2617836SJohn.Forte@Sun.COM #define	RDC_HDR_V3	0x52444303	/* RDC3 */
2627836SJohn.Forte@Sun.COM 
2637836SJohn.Forte@Sun.COM typedef struct {
2647836SJohn.Forte@Sun.COM 	int32_t		magic;
2657836SJohn.Forte@Sun.COM 	rdc_hdr_addr_t	primary;
2667836SJohn.Forte@Sun.COM 	rdc_hdr_addr_t	secondary;
2677836SJohn.Forte@Sun.COM 	int32_t		flags;
2687836SJohn.Forte@Sun.COM 	int32_t		autosync;
2697836SJohn.Forte@Sun.COM 	int32_t		maxqfbas;
2707836SJohn.Forte@Sun.COM 	int32_t		maxqitems;
2717836SJohn.Forte@Sun.COM 	int32_t		syshostid;	/* for cluster bitmaps */
2727836SJohn.Forte@Sun.COM 	int32_t		asyncthr;
2737836SJohn.Forte@Sun.COM } rdc_headerv4_t;
2747836SJohn.Forte@Sun.COM #define	RDC_HDR_V4	0x52444304	/* RDC4 */
2757836SJohn.Forte@Sun.COM 
2767836SJohn.Forte@Sun.COM typedef struct {
2777836SJohn.Forte@Sun.COM 	int32_t		magic;
2787836SJohn.Forte@Sun.COM 	rdc_hdr_addr_t	primary;
2797836SJohn.Forte@Sun.COM 	rdc_hdr_addr_t	secondary;
2807836SJohn.Forte@Sun.COM 	int32_t		flags;
2817836SJohn.Forte@Sun.COM 	int32_t		autosync;
2827836SJohn.Forte@Sun.COM 	int64_t		maxqfbas;
2837836SJohn.Forte@Sun.COM 	int64_t		maxqitems;
2847836SJohn.Forte@Sun.COM 	int32_t		syshostid;	/* for cluster bitmaps */
2857836SJohn.Forte@Sun.COM 	int32_t		asyncthr;
2867836SJohn.Forte@Sun.COM 	int32_t		refcntsize;	/* size in bytes of each refcount */
2877836SJohn.Forte@Sun.COM } rdc_headerv5_t;
2887836SJohn.Forte@Sun.COM #define	RDC_HDR_V5	0x52444305	/* RDC5 */
2897836SJohn.Forte@Sun.COM 
2907836SJohn.Forte@Sun.COM typedef rdc_headerv5_t	rdc_header_t;	/* Current header type */
2917836SJohn.Forte@Sun.COM #define	RDC_HDR_MAGIC	RDC_HDR_V5	/* Current header magic number */
2927836SJohn.Forte@Sun.COM 
2937836SJohn.Forte@Sun.COM #endif	/* _KERNEL */
2947836SJohn.Forte@Sun.COM 
2957836SJohn.Forte@Sun.COM #define	RDC_BITMAP_FBA	1		/* Offset at which the bitmap starts */
2967836SJohn.Forte@Sun.COM #define	RDC_BITREF_FBA(krdc) (RDC_BITMAP_FBA + FBA_LEN(krdc->bitmap_size))
2977836SJohn.Forte@Sun.COM 
2987836SJohn.Forte@Sun.COM #ifdef _KERNEL
2997836SJohn.Forte@Sun.COM 
3007836SJohn.Forte@Sun.COM #define	RDC_FUTILE_ATTEMPTS	50
3017836SJohn.Forte@Sun.COM typedef struct aio_buf_s {
3027836SJohn.Forte@Sun.COM 	struct aio_buf_s	*next;		/* next aio_buf */
3037836SJohn.Forte@Sun.COM 	nsc_buf_t		*rdc_abufp;	/* actual anon buf */
3047836SJohn.Forte@Sun.COM 	int			kindex;		/* index we are attached to */
3057836SJohn.Forte@Sun.COM } aio_buf_t;
3067836SJohn.Forte@Sun.COM 
3077836SJohn.Forte@Sun.COM typedef struct rdc_thrsync {
3087836SJohn.Forte@Sun.COM 	kmutex_t	lock;
3097836SJohn.Forte@Sun.COM 	int		threads;
3107836SJohn.Forte@Sun.COM 	int		complete;
3117836SJohn.Forte@Sun.COM 	kcondvar_t	cv;
3127836SJohn.Forte@Sun.COM } rdc_thrsync_t;
3137836SJohn.Forte@Sun.COM 
3147836SJohn.Forte@Sun.COM typedef struct sync_status_s {
3157836SJohn.Forte@Sun.COM 	int	offset;
3167836SJohn.Forte@Sun.COM 	struct sync_status_s *next;
3177836SJohn.Forte@Sun.COM } sync_status_t;
3187836SJohn.Forte@Sun.COM 
3197836SJohn.Forte@Sun.COM typedef struct rdc_syncthr {
3207836SJohn.Forte@Sun.COM 	nsc_off_t		offset;
3217836SJohn.Forte@Sun.COM 	nsc_size_t		len;
3227836SJohn.Forte@Sun.COM 	struct rdc_k_info	*krdc;
3237836SJohn.Forte@Sun.COM 	sync_status_t		*status;
3247836SJohn.Forte@Sun.COM } rdc_syncthr_t;
3257836SJohn.Forte@Sun.COM 
3267836SJohn.Forte@Sun.COM /*
3277836SJohn.Forte@Sun.COM  * RDC buffer header
3287836SJohn.Forte@Sun.COM  */
3297836SJohn.Forte@Sun.COM 
3307836SJohn.Forte@Sun.COM typedef struct rdc_buf_s {
3317836SJohn.Forte@Sun.COM 	nsc_buf_t	rdc_bufh;	/* exported buffer header */
3327836SJohn.Forte@Sun.COM 	nsc_buf_t	*rdc_bufp;	/* underlying buffer */
3337836SJohn.Forte@Sun.COM 	aio_buf_t	*rdc_anon;	/* ANON async buffer */
3347836SJohn.Forte@Sun.COM 	struct rdc_fd_s	*rdc_fd;	/* back link */
3357836SJohn.Forte@Sun.COM 	size_t		rdc_vsize;	/* size of allocated nsc_vec_t */
3367836SJohn.Forte@Sun.COM 	int		rdc_flags;	/* flags */
3377836SJohn.Forte@Sun.COM 	kmutex_t	aio_lock;	/* lock for rdc_anon */
3387836SJohn.Forte@Sun.COM 	rdc_thrsync_t	rdc_sync;	/* for thread syncronization */
3397836SJohn.Forte@Sun.COM } rdc_buf_t;
3407836SJohn.Forte@Sun.COM 
3417836SJohn.Forte@Sun.COM #define	RDC_VEC_ALLOC	0x1		/* local kmem vector for remote io */
3427836SJohn.Forte@Sun.COM #define	RDC_ALLOC	0x2		/* rdc_bufp is nsc_buf_alloc'd */
3437836SJohn.Forte@Sun.COM #define	RDC_ASYNC_VEC	0x4		/* Keep tmp handle for async flusher */
3447836SJohn.Forte@Sun.COM #define	RDC_REMOTE_BUF	0x8		/* buffer alloc'd for remote io only */
3457836SJohn.Forte@Sun.COM #define	RDC_NULL_BUF	0x10		/* tell diskq to only store io_hdr */
3467836SJohn.Forte@Sun.COM #define	RDC_ASYNC_BUF	0x20		/* this buf is to an async vol */
3477836SJohn.Forte@Sun.COM #define	RDC_NULLBUFREAD	0x0f000000	/* read because RDC_NULL_BUF detected */
3487836SJohn.Forte@Sun.COM 
3497836SJohn.Forte@Sun.COM #define	BUF_IS_ASYNC(h)	(((h) != NULL) && (h)->rdc_flags & RDC_ASYNC_BUF)
3507836SJohn.Forte@Sun.COM #define	RDC_REMOTE(h)	(((h) != NULL) && ((h)->rdc_flags & RDC_REMOTE_BUF) && \
3517836SJohn.Forte@Sun.COM 			(((h)->rdc_flags & RDC_ASYNC_VEC) == 0))
3527836SJohn.Forte@Sun.COM 
3537836SJohn.Forte@Sun.COM /* check a handle against a supplied pos/len pair */
3547836SJohn.Forte@Sun.COM 
3557836SJohn.Forte@Sun.COM #define	RDC_HANDLE_LIMITS(h, p, l) \
3567836SJohn.Forte@Sun.COM 		(((h)->sb_user & RDC_DISKQUE) || \
3577836SJohn.Forte@Sun.COM 		((p) >= (h)->sb_pos) && \
3587836SJohn.Forte@Sun.COM 		(((p) + (l)) <= ((h)->sb_pos + (h)->sb_len)))
3597836SJohn.Forte@Sun.COM 
3607836SJohn.Forte@Sun.COM /* check a dset against a supplied pos/len pair */
3617836SJohn.Forte@Sun.COM 
3627836SJohn.Forte@Sun.COM #define	RDC_DSET_LIMITS(d, p, l) \
3637836SJohn.Forte@Sun.COM 		(((p) >= (d)->pos) && \
3647836SJohn.Forte@Sun.COM 		(((p) + (l)) <= ((d)->pos + (d)->fbalen)))
3657836SJohn.Forte@Sun.COM 
3667836SJohn.Forte@Sun.COM /*
3677836SJohn.Forte@Sun.COM  * RDC device info structures
3687836SJohn.Forte@Sun.COM  */
3697836SJohn.Forte@Sun.COM 
3707836SJohn.Forte@Sun.COM typedef struct _rdc_info_dev_s {
3717836SJohn.Forte@Sun.COM 	nsc_fd_t	*bi_fd;		/* file descriptor */
3727836SJohn.Forte@Sun.COM 	nsc_iodev_t	*bi_iodev;	/* I/O device structure */
3737836SJohn.Forte@Sun.COM 	struct rdc_k_info *bi_krdc;	/* back link */
3747836SJohn.Forte@Sun.COM 	int		bi_rsrv;	/* Count of reserves held */
3757836SJohn.Forte@Sun.COM 	int		bi_orsrv;	/* Reserves for other io provider */
3767836SJohn.Forte@Sun.COM 	int		bi_failed;	/* Count of failed (faked) reserves */
3777836SJohn.Forte@Sun.COM 	int		bi_ofailed;	/* Other io provider failed reserves */
3787836SJohn.Forte@Sun.COM 	int		bi_flag;	/* Reserve flags */
3797836SJohn.Forte@Sun.COM } _rdc_info_dev_t;
3807836SJohn.Forte@Sun.COM 
3817836SJohn.Forte@Sun.COM 
3827836SJohn.Forte@Sun.COM typedef struct rdc_info_dev_s {
3837836SJohn.Forte@Sun.COM 	struct rdc_info_dev_s	*id_next;	/* forward link */
3847836SJohn.Forte@Sun.COM 	_rdc_info_dev_t		id_cache_dev;	/* cached device info */
3857836SJohn.Forte@Sun.COM 	_rdc_info_dev_t		id_raw_dev;	/* raw device info */
3867836SJohn.Forte@Sun.COM 	kmutex_t		id_rlock;	/* reserve/release lock */
3877836SJohn.Forte@Sun.COM 	kcondvar_t		id_rcv;		/* nsc_release pending cv */
3887836SJohn.Forte@Sun.COM 	int			id_sets;	/* # of sets referencing */
3897836SJohn.Forte@Sun.COM 	int			id_release;	/* # of pending nsc_releases */
3907836SJohn.Forte@Sun.COM 	int			id_flag;	/* flags */
3917836SJohn.Forte@Sun.COM } rdc_info_dev_t;
3927836SJohn.Forte@Sun.COM 
3937836SJohn.Forte@Sun.COM 
3947836SJohn.Forte@Sun.COM typedef struct rdc_path_s {
3957836SJohn.Forte@Sun.COM 	nsc_path_t		*rp_tok;	/* nsc_register_path token */
3967836SJohn.Forte@Sun.COM 	int			rp_ref;		/* # of rdc_fd_t's */
3977836SJohn.Forte@Sun.COM } rdc_path_t;
3987836SJohn.Forte@Sun.COM 
3997836SJohn.Forte@Sun.COM 
4007836SJohn.Forte@Sun.COM /*
4017836SJohn.Forte@Sun.COM  * Values for id_flag
4027836SJohn.Forte@Sun.COM  */
4037836SJohn.Forte@Sun.COM #define	RDC_ID_CLOSING		0x1		/* device is closing */
4047836SJohn.Forte@Sun.COM 
4057836SJohn.Forte@Sun.COM #include <sys/nsctl/rdc_diskq.h>
4067836SJohn.Forte@Sun.COM 
4077836SJohn.Forte@Sun.COM /*
4087836SJohn.Forte@Sun.COM  * value for diskio.seq.
4097836SJohn.Forte@Sun.COM  */
4107836SJohn.Forte@Sun.COM #define	RDC_NOSEQ		(0)		/* ignore sequence */
4117836SJohn.Forte@Sun.COM #define	RDC_NEWSEQ		(1)		/* start of sequence */
4127836SJohn.Forte@Sun.COM 
4137836SJohn.Forte@Sun.COM typedef struct rdc_sleepq {
4147836SJohn.Forte@Sun.COM 	struct rdc_sleepq	*next;
4157836SJohn.Forte@Sun.COM 	uint_t			seq;		/* sequence in queue */
4167836SJohn.Forte@Sun.COM 	int			idx;		/* idx number of request */
4177836SJohn.Forte@Sun.COM 	int			pindex;		/* primary host set index */
4187836SJohn.Forte@Sun.COM 	int			sindex;		/* secondary host set index */
4197836SJohn.Forte@Sun.COM 	uint64_t		qpos;		/* offset on primary's queue */
4207836SJohn.Forte@Sun.COM 	int			nocache;	/* cache flag to alloc_buf */
4217836SJohn.Forte@Sun.COM } rdc_sleepq_t;
4227836SJohn.Forte@Sun.COM 
4237836SJohn.Forte@Sun.COM /*
4247836SJohn.Forte@Sun.COM  * RDC group structure
4257836SJohn.Forte@Sun.COM  */
4267836SJohn.Forte@Sun.COM typedef struct rdc_group {
4277836SJohn.Forte@Sun.COM 	int		count;
4287836SJohn.Forte@Sun.COM 	int		rdc_writer;
4297836SJohn.Forte@Sun.COM 	int		unregistering;
4307836SJohn.Forte@Sun.COM 	kmutex_t	lock;
4317836SJohn.Forte@Sun.COM 	net_queue	ra_queue;	/* io todo async queues */
4327836SJohn.Forte@Sun.COM 	kcondvar_t	iowaitcv;	/* wait for flusher */
4337836SJohn.Forte@Sun.COM 	kcondvar_t	unregistercv;	/* wait for unregister */
4347836SJohn.Forte@Sun.COM 	int		rdc_thrnum;	/* number of threads */
4357836SJohn.Forte@Sun.COM 	int		rdc_addthrnum;	/* number threads added to thr set */
4367836SJohn.Forte@Sun.COM 	kmutex_t	addthrnumlk;	/* lock for above */
4377836SJohn.Forte@Sun.COM 	rdc_sleepq_t	*sleepq;	/* head of waiting tasks */
4387836SJohn.Forte@Sun.COM 	/*
4397836SJohn.Forte@Sun.COM 	 * Dual use, the outgoing sequence number on the client.
4407836SJohn.Forte@Sun.COM 	 * The next expected sequence number on the server.
4417836SJohn.Forte@Sun.COM 	 * Protected by the ra_queue lock.
4427836SJohn.Forte@Sun.COM 	 */
4437836SJohn.Forte@Sun.COM 	uint_t		seq;
4447836SJohn.Forte@Sun.COM 	/*
4457836SJohn.Forte@Sun.COM 	 * Dual use, the last acknowledged sequence number.
4467836SJohn.Forte@Sun.COM 	 * Used to ensure that the queue doesn't overflow on server
4477836SJohn.Forte@Sun.COM 	 * and to stall transmissions on the client.
4487836SJohn.Forte@Sun.COM 	 * Protected by the ra_queue lock.
4497836SJohn.Forte@Sun.COM 	 */
4507836SJohn.Forte@Sun.COM 	uint_t		seqack;
4517836SJohn.Forte@Sun.COM 	int		asyncstall;	/* count of asleep threads */
4527836SJohn.Forte@Sun.COM 	int		asyncdis;	/* discard stalled output */
4537836SJohn.Forte@Sun.COM 	kcondvar_t	asyncqcv;	/* output stall here */
4547836SJohn.Forte@Sun.COM 	int		flags;		/* memory or disk. status etc */
4557836SJohn.Forte@Sun.COM 	disk_queue	diskq;		/* disk queue */
4567836SJohn.Forte@Sun.COM 	nsc_fd_t	*diskqfd;	/* diskq handle */
4577836SJohn.Forte@Sun.COM 	nsc_path_t	*q_tok;		/* q registration */
4587836SJohn.Forte@Sun.COM 	int		diskqrsrv;	/* reserve count */
4597836SJohn.Forte@Sun.COM 	kmutex_t	diskqmutex;	/* enables/disables/reserves */
4607836SJohn.Forte@Sun.COM 	uint_t		synccount;	/* number of group members syncing */
4617836SJohn.Forte@Sun.COM } rdc_group_t;
4627836SJohn.Forte@Sun.COM 
4637836SJohn.Forte@Sun.COM /* group state */
4647836SJohn.Forte@Sun.COM #define	RDC_DISKQ_KILL		0x01	/* a force kill of diskq pending */
4657836SJohn.Forte@Sun.COM 
4667836SJohn.Forte@Sun.COM #define	RDC_IS_DISKQ(grp)	(grp->flags & RDC_DISKQUE)
4677836SJohn.Forte@Sun.COM #define	RDC_IS_MEMQ(grp)	(grp->flags & RDC_MEMQUE)
4687836SJohn.Forte@Sun.COM 
4697836SJohn.Forte@Sun.COM /*
4707836SJohn.Forte@Sun.COM  * These flags are used in the
4717836SJohn.Forte@Sun.COM  * aux_state field, and are used to track:
4727836SJohn.Forte@Sun.COM  * AUXSYNCIP: When the code has a sync thread running, used instead
4737836SJohn.Forte@Sun.COM  * of the RC_SYNCING flag which gets cleared before the sync thread
4747836SJohn.Forte@Sun.COM  * terminates.
4757836SJohn.Forte@Sun.COM  * AUXWRITE: Set when rdc_sync_write_thr is running, so the rdc_unintercept
4767836SJohn.Forte@Sun.COM  * code can wait until a one-to-many write has actually terminated.
4777836SJohn.Forte@Sun.COM  */
4787836SJohn.Forte@Sun.COM #define	RDC_AUXSYNCIP	0x01		/* a sync is in progress */
4797836SJohn.Forte@Sun.COM #define	RDC_AUXWRITE	0x02		/* I've got a write in progress */
4807836SJohn.Forte@Sun.COM 
4817836SJohn.Forte@Sun.COM 
4827836SJohn.Forte@Sun.COM /*
4837836SJohn.Forte@Sun.COM  * RDC kernel-private information
4847836SJohn.Forte@Sun.COM  */
4857836SJohn.Forte@Sun.COM typedef struct rdc_k_info {
4867836SJohn.Forte@Sun.COM 	int			index;		/* Index into array */
4877836SJohn.Forte@Sun.COM 	int			remote_index;	/* -1 means unknown */
4887836SJohn.Forte@Sun.COM 	int			type_flag;
4897836SJohn.Forte@Sun.COM 	int			rpc_version;	/* RPC version this set supps */
4907836SJohn.Forte@Sun.COM 	int			spare1;
4917836SJohn.Forte@Sun.COM 	nsc_off_t		syncbitpos;
4927836SJohn.Forte@Sun.COM 	kmutex_t		syncbitmutex;	/* lock for syncbitpos */
4937836SJohn.Forte@Sun.COM 	volatile int		busy_count;	/* ioctls in progress */
4947836SJohn.Forte@Sun.COM 	volatile int		sync_done;
4957836SJohn.Forte@Sun.COM 	int			aux_state; /* syncing ,don't disable */
4967836SJohn.Forte@Sun.COM 	rdc_thrsync_t		syncs;		/* _rdc_sync thread tracking */
4977836SJohn.Forte@Sun.COM 	rdc_info_dev_t		*devices;
4987836SJohn.Forte@Sun.COM 	nsc_iodev_t		*iodev;		/* I/O device structure */
4997836SJohn.Forte@Sun.COM 	rdc_path_t		cache_path;
5007836SJohn.Forte@Sun.COM 	rdc_path_t		raw_path;
5017836SJohn.Forte@Sun.COM 	rdc_if_t		*intf;
5027836SJohn.Forte@Sun.COM 	rdc_srv_t		*lsrv;		/* list of servinfo */
5037836SJohn.Forte@Sun.COM 	nsc_size_t		maxfbas;	/* returned from nsc_maxfbas */
5047836SJohn.Forte@Sun.COM 	unsigned char		*dcio_bitmap;
5057836SJohn.Forte@Sun.COM 	void			*bitmap_ref;	/* Incore bitmap bit ref */
5067836SJohn.Forte@Sun.COM 	struct rdc_group	*group;
5077836SJohn.Forte@Sun.COM 	nsc_size_t		bitmap_size;
5087836SJohn.Forte@Sun.COM 	int			bmaprsrv;	/* bitmap reserve count */
5097836SJohn.Forte@Sun.COM 	int			bitmap_write;
5107836SJohn.Forte@Sun.COM 	nsc_fd_t		*bitmapfd;
5117836SJohn.Forte@Sun.COM 	nsc_fd_t		*remote_fd;	/* FCAL direct io */
5127836SJohn.Forte@Sun.COM 	volatile int		disk_status;	/* set to halt sync */
5137836SJohn.Forte@Sun.COM 	int			closing;
5147836SJohn.Forte@Sun.COM 	nsc_path_t		*b_tok;		/* Bitmap registration */
5157836SJohn.Forte@Sun.COM 	int			b_ref;
5167836SJohn.Forte@Sun.COM 	kmutex_t		dc_sleep;
5177836SJohn.Forte@Sun.COM 	kmutex_t		bmapmutex;	/* mutex for bitmap ops */
5187836SJohn.Forte@Sun.COM 	kcondvar_t		busycv;		/* wait for ioctl to complete */
5197836SJohn.Forte@Sun.COM 	kcondvar_t		closingcv;	/* unregister_path/close */
5207836SJohn.Forte@Sun.COM 	kcondvar_t		haltcv;		/* wait for sync to halt */
5217836SJohn.Forte@Sun.COM 	kcondvar_t		synccv;		/* wait for sync to halt */
5227836SJohn.Forte@Sun.COM 	struct rdc_net_dataset  *net_dataset;	/* replaces hnds */
5237836SJohn.Forte@Sun.COM 	int64_t			io_time;	/* moved from cd_info */
5247836SJohn.Forte@Sun.COM 	struct rdc_k_info	*many_next;	/* 1-to-many circular list */
5257836SJohn.Forte@Sun.COM 	struct rdc_k_info	*multi_next;	/* to multihop krdc */
5267836SJohn.Forte@Sun.COM 	struct rdc_k_info	*group_next;	/* group circular list */
5277836SJohn.Forte@Sun.COM 	kstat_t			*io_kstats;	/* io kstat */
5287836SJohn.Forte@Sun.COM 	kstat_t			*bmp_kstats;	/* bitmap io kstat */
5297836SJohn.Forte@Sun.COM 	kstat_t			*set_kstats;	/* set kstat */
5307836SJohn.Forte@Sun.COM 	kmutex_t		kstat_mutex;	/* mutex for kstats */
5317836SJohn.Forte@Sun.COM 	kmutex_t		bmp_kstat_mutex;	/* mutex for kstats */
5327836SJohn.Forte@Sun.COM 	struct bm_ref_ops	*bm_refs;
5337836SJohn.Forte@Sun.COM } rdc_k_info_t;
5347836SJohn.Forte@Sun.COM 
5357836SJohn.Forte@Sun.COM #define	c_fd		devices->id_cache_dev.bi_fd
5367836SJohn.Forte@Sun.COM #define	c_rsrv		devices->id_cache_dev.bi_rsrv
5377836SJohn.Forte@Sun.COM #define	c_failed	devices->id_cache_dev.bi_failed
5387836SJohn.Forte@Sun.COM #define	c_flag		devices->id_cache_dev.bi_flag
5397836SJohn.Forte@Sun.COM 
5407836SJohn.Forte@Sun.COM #define	c_tok		cache_path.rp_tok
5417836SJohn.Forte@Sun.COM #define	c_ref		cache_path.rp_ref
5427836SJohn.Forte@Sun.COM 
5437836SJohn.Forte@Sun.COM #define	r_fd		devices->id_raw_dev.bi_fd
5447836SJohn.Forte@Sun.COM #define	r_rsrv		devices->id_raw_dev.bi_rsrv
5457836SJohn.Forte@Sun.COM #define	r_failed	devices->id_raw_dev.bi_failed
5467836SJohn.Forte@Sun.COM #define	r_flag		devices->id_raw_dev.bi_flag
5477836SJohn.Forte@Sun.COM 
5487836SJohn.Forte@Sun.COM #define	r_tok		raw_path.rp_tok
5497836SJohn.Forte@Sun.COM #define	r_ref		raw_path.rp_ref
5507836SJohn.Forte@Sun.COM 
5517836SJohn.Forte@Sun.COM /*
5527836SJohn.Forte@Sun.COM  * flags for _rdc_rsrv_devs()
5537836SJohn.Forte@Sun.COM  */
5547836SJohn.Forte@Sun.COM 
5557836SJohn.Forte@Sun.COM /*
5567836SJohn.Forte@Sun.COM  * which device(s) to reserve - integer bitmap.
5577836SJohn.Forte@Sun.COM  */
5587836SJohn.Forte@Sun.COM 
5597836SJohn.Forte@Sun.COM #define	RDC_CACHE	0x1	/* data device in cache mode */
5607836SJohn.Forte@Sun.COM #define	RDC_RAW		0x2	/* data device in raw mode */
5617836SJohn.Forte@Sun.COM #define	RDC_BMP		0x4	/* bitmap device */
5627836SJohn.Forte@Sun.COM #define	RDC_QUE		0x8	/* diskq device */
5637836SJohn.Forte@Sun.COM 
5647836SJohn.Forte@Sun.COM /*
5657836SJohn.Forte@Sun.COM  * device usage after reserve - integer flag.
5667836SJohn.Forte@Sun.COM  */
5677836SJohn.Forte@Sun.COM 
5687836SJohn.Forte@Sun.COM #define	RDC_INTERNAL	0x1	/* reserve for rdc internal purposes */
5697836SJohn.Forte@Sun.COM #define	RDC_EXTERNAL	0x2	/* reserve in response to io provider Attach */
5707836SJohn.Forte@Sun.COM 
5717836SJohn.Forte@Sun.COM /*
5727836SJohn.Forte@Sun.COM  * Utility macro for nsc_*() io function returns.
5737836SJohn.Forte@Sun.COM  */
5747836SJohn.Forte@Sun.COM 
5757836SJohn.Forte@Sun.COM #define	RDC_SUCCESS(rc)	(((rc) == NSC_DONE) || ((rc) == NSC_HIT))
5767836SJohn.Forte@Sun.COM 
5777836SJohn.Forte@Sun.COM /*
5787836SJohn.Forte@Sun.COM  * RDC file descriptor structure
5797836SJohn.Forte@Sun.COM  */
5807836SJohn.Forte@Sun.COM 
5817836SJohn.Forte@Sun.COM typedef struct rdc_fd_s {
5827836SJohn.Forte@Sun.COM 	rdc_k_info_t	*rdc_info;	/* devices info structure */
5837836SJohn.Forte@Sun.COM 	int		rdc_type;	/* open type, diskq or bitmap */
5847836SJohn.Forte@Sun.COM 	int		rdc_oflags;	/* raw or cached open type */
5857836SJohn.Forte@Sun.COM } rdc_fd_t;
5867836SJohn.Forte@Sun.COM 
5877836SJohn.Forte@Sun.COM /*
5887836SJohn.Forte@Sun.COM  * fd and rsrv macros
5897836SJohn.Forte@Sun.COM  */
5907836SJohn.Forte@Sun.COM 
5917836SJohn.Forte@Sun.COM #define	RSRV(bi)	(((bi)->bi_rsrv > 0) || ((bi)->bi_failed > 0))
5927836SJohn.Forte@Sun.COM #define	ORSRV(bi)	(((bi)->bi_orsrv > 0) || ((bi)->bi_ofailed > 0))
5937836SJohn.Forte@Sun.COM #define	RFAILED(bi)	(((bi)->bi_failed > 0) || ((bi)->bi_ofailed > 0))
5947836SJohn.Forte@Sun.COM 
5957836SJohn.Forte@Sun.COM #define	IS_RSRV(bi)	(RSRV(bi) || ORSRV(bi))
5967836SJohn.Forte@Sun.COM 
5977836SJohn.Forte@Sun.COM #define	IS_CRSRV(gcd)	(IS_RSRV(&(gcd)->devices->id_cache_dev))
5987836SJohn.Forte@Sun.COM #define	IS_RRSRV(gcd)	(IS_RSRV(&(gcd)->devices->id_raw_dev))
5997836SJohn.Forte@Sun.COM 
6007836SJohn.Forte@Sun.COM #define	IS_RFAILED(gcd)	\
6017836SJohn.Forte@Sun.COM 		(RFAILED(&(gcd)->devices->id_cache_dev) || \
6027836SJohn.Forte@Sun.COM 		RFAILED(&(gcd)->devices->id_raw_dev))
6037836SJohn.Forte@Sun.COM 
6047836SJohn.Forte@Sun.COM #define	RDC_IS_BMP(rdc)	((rdc)->rdc_type == RDC_BMP)
6057836SJohn.Forte@Sun.COM #define	RDC_IS_QUE(rdc) ((rdc)->rdc_type == RDC_QUE)
6067836SJohn.Forte@Sun.COM #define	RDC_IS_RAW(rdc)	(((rdc)->rdc_oflags & NSC_CACHE) == 0)
6077836SJohn.Forte@Sun.COM #define	RDC_U_FD(gcd)	(IS_CRSRV(gcd) ? (gcd)->c_fd : (gcd)->r_fd)
6087836SJohn.Forte@Sun.COM #define	RDC_FD(rdc)	(RDC_U_FD(rdc->rdc_info))
6097836SJohn.Forte@Sun.COM 
6107836SJohn.Forte@Sun.COM 
6117836SJohn.Forte@Sun.COM typedef struct rdc_host_u {
6127836SJohn.Forte@Sun.COM 	char *nodename;
6137836SJohn.Forte@Sun.COM 	int netaddr;
6147836SJohn.Forte@Sun.COM 	struct netbuf *naddr;
6157836SJohn.Forte@Sun.COM } rdc_host_t;
6167836SJohn.Forte@Sun.COM 
6177836SJohn.Forte@Sun.COM /*
6187836SJohn.Forte@Sun.COM  * Reply from remote read
6197836SJohn.Forte@Sun.COM  * - convenience defines for the client side code.
6207836SJohn.Forte@Sun.COM  * - keep this in sync with the readres structure in rdc_prot.h/.x
6217836SJohn.Forte@Sun.COM  */
6227836SJohn.Forte@Sun.COM #define	rdcrdresult	readres
6237836SJohn.Forte@Sun.COM #define	rr_status	status
6247836SJohn.Forte@Sun.COM #define	rr_ok		readres_u.reply
6257836SJohn.Forte@Sun.COM #define	rr_bufsize	rr_ok.data.data_len
6267836SJohn.Forte@Sun.COM #define	rr_data		rr_ok.data.data_val
6277836SJohn.Forte@Sun.COM 
6287836SJohn.Forte@Sun.COM /*
6297836SJohn.Forte@Sun.COM  * Flags for remote read rpc
6307836SJohn.Forte@Sun.COM  *
6317836SJohn.Forte@Sun.COM  * _START must be a unique rpc, _DATA and _END may be OR-d together.
6327836SJohn.Forte@Sun.COM  */
6337836SJohn.Forte@Sun.COM #define	RDC_RREAD_DATA	0x1	/* Intermediate rpc with data payload */
6347836SJohn.Forte@Sun.COM #define	RDC_RREAD_START	0x2	/* Setup rpc */
6357836SJohn.Forte@Sun.COM #define	RDC_RREAD_END	0x4	/* End rpc */
6367836SJohn.Forte@Sun.COM #define	RDC_RREAD_FAIL	0x8	/* Primary is failed */
6377836SJohn.Forte@Sun.COM 
6387836SJohn.Forte@Sun.COM /*
6397836SJohn.Forte@Sun.COM  * Flags for remote write rpc
6407836SJohn.Forte@Sun.COM  */
6417836SJohn.Forte@Sun.COM #define	RDC_RWRITE_FAIL	0x8	/* Primary is failed */
6427836SJohn.Forte@Sun.COM 
6437836SJohn.Forte@Sun.COM /*
6447836SJohn.Forte@Sun.COM  * macro used to determine if the incomming sq, with sequence
6457836SJohn.Forte@Sun.COM  * value x, should be placed before the sq with sequence value y.
646*10715SThomas.Atkins@Sun.COM  * This has to account for integer wrap. We account for integer
647*10715SThomas.Atkins@Sun.COM  * wrap by checking if the difference between x and y is within
648*10715SThomas.Atkins@Sun.COM  * half of the maximum integer value (RDC_MAXINT) or not.
6497836SJohn.Forte@Sun.COM  */
650*10715SThomas.Atkins@Sun.COM 
651*10715SThomas.Atkins@Sun.COM #define	RDC_BITSPERBYTE 8
652*10715SThomas.Atkins@Sun.COM #define	RDC_BITS(type)	(RDC_BITSPERBYTE * (long)sizeof (type))
653*10715SThomas.Atkins@Sun.COM #define	RDC_HIBITI	((unsigned)1 << (RDC_BITS(int) - 1))
654*10715SThomas.Atkins@Sun.COM #define	RDC_MAXINT	((int)(~RDC_HIBITI))
655*10715SThomas.Atkins@Sun.COM #define	RDC_RANGE	((RDC_MAXINT / 2) -1)
656*10715SThomas.Atkins@Sun.COM 
657*10715SThomas.Atkins@Sun.COM #define	RDC_INFRONT(x, y) (((x < y) && ((y - x) < RDC_RANGE)) ? 1 : \
658*10715SThomas.Atkins@Sun.COM 	((x > y) && ((x - y) > RDC_RANGE)) ? 1 : 0)
6597836SJohn.Forte@Sun.COM 
6607836SJohn.Forte@Sun.COM 
6617836SJohn.Forte@Sun.COM 
6627836SJohn.Forte@Sun.COM 
6637836SJohn.Forte@Sun.COM #endif /* _KERNEL */
6647836SJohn.Forte@Sun.COM 
6657836SJohn.Forte@Sun.COM /*
6667836SJohn.Forte@Sun.COM  * RDC user-visible information
6677836SJohn.Forte@Sun.COM  */
6687836SJohn.Forte@Sun.COM typedef rdc_set_t rdc_u_info_t;
6697836SJohn.Forte@Sun.COM 
6707836SJohn.Forte@Sun.COM 
6717836SJohn.Forte@Sun.COM /*
6727836SJohn.Forte@Sun.COM  * RDC flags for set state / set cd RPC.
6737836SJohn.Forte@Sun.COM  * Must remain compatible with rdc RPC protocol version v3.
6747836SJohn.Forte@Sun.COM  */
6757836SJohn.Forte@Sun.COM #define	CCIO_NONE		0x0000
6767836SJohn.Forte@Sun.COM #define	CCIO_ENABLE		0x0008
6777836SJohn.Forte@Sun.COM #define	CCIO_SLAVE		0x0010
6787836SJohn.Forte@Sun.COM #define	CCIO_DONE		0x0020
6797836SJohn.Forte@Sun.COM #define	CCIO_ENABLELOG		0x0100
6807836SJohn.Forte@Sun.COM #define	CCIO_RSYNC		0x0400
6817836SJohn.Forte@Sun.COM #define	CCIO_REMOTE		0x2000
6827836SJohn.Forte@Sun.COM 
6837836SJohn.Forte@Sun.COM 
6847836SJohn.Forte@Sun.COM /*
6857836SJohn.Forte@Sun.COM  * In kernel type flags (krdc->type_flag).
6867836SJohn.Forte@Sun.COM  */
6877836SJohn.Forte@Sun.COM #define	RDC_CONFIGURED		0x1
6887836SJohn.Forte@Sun.COM #define	RDC_DISABLEPEND		0x2	/* Suspend/Disable is in progress */
6897836SJohn.Forte@Sun.COM #define	RDC_ASYNCMODE		0x4
6907836SJohn.Forte@Sun.COM #define	RDC_RESUMEPEND		0x8
6917836SJohn.Forte@Sun.COM #define	RDC_RESPONSIBLE		0x10
6927836SJohn.Forte@Sun.COM #define	RDC_BUSYWAIT		0x20
6937836SJohn.Forte@Sun.COM #define	RDC_UNREGISTER		0x40	/* Unregister is in progress */
6947836SJohn.Forte@Sun.COM #define	RDC_QDISABLEPEND	0x100	/* Q Suspend/Disable is in progress */
6957836SJohn.Forte@Sun.COM 
6967836SJohn.Forte@Sun.COM #define	IS_ENABLED(urdc)	((IS_CONFIGURED(&rdc_k_info[(urdc)->index]) && \
6977836SJohn.Forte@Sun.COM 	(rdc_get_vflags(urdc) & RDC_ENABLED)))
6987836SJohn.Forte@Sun.COM #define	IS_CONFIGURED(krdc)	((krdc)->type_flag & RDC_CONFIGURED)
6997836SJohn.Forte@Sun.COM #define	IS_MANY(krdc)		((krdc)->many_next != (krdc))
7007836SJohn.Forte@Sun.COM #define	IS_MULTI(krdc)		((krdc)->multi_next != NULL)
7017836SJohn.Forte@Sun.COM 
7027836SJohn.Forte@Sun.COM #define	IS_VALID_INDEX(index)	((index) >= 0 && (index) < rdc_max_sets && \
7037836SJohn.Forte@Sun.COM 					IS_CONFIGURED(&rdc_k_info[(index)]))
7047836SJohn.Forte@Sun.COM 
7057836SJohn.Forte@Sun.COM #define	RDC_NOFLUSH	0	/* Do not do a flush when starting logging */
7067836SJohn.Forte@Sun.COM #define	RDC_NOREMOTE	0	/* Do no remote logging notifications */
7077836SJohn.Forte@Sun.COM #define	RDC_FLUSH	1	/* Do a flush when starting logging */
7087836SJohn.Forte@Sun.COM #define	RDC_ALLREMOTE	2	/* Notify all remote group members */
7097836SJohn.Forte@Sun.COM #define	RDC_OTHERREMOTE	4	/* Notify all remote group members except */
7107836SJohn.Forte@Sun.COM 				/* the one corresponding to the current set, */
7117836SJohn.Forte@Sun.COM 				/* to prevent recursion in the case where */
7127836SJohn.Forte@Sun.COM 				/* the request was initiated from the remote */
7137836SJohn.Forte@Sun.COM 				/* node. */
7147836SJohn.Forte@Sun.COM #define	RDC_FORCE_GROUP 8	/* set all group memebers logging regardless */
7157836SJohn.Forte@Sun.COM 
7167836SJohn.Forte@Sun.COM #ifdef _KERNEL
7177836SJohn.Forte@Sun.COM 
7187836SJohn.Forte@Sun.COM /*
7197836SJohn.Forte@Sun.COM  * Functions, vars
7207836SJohn.Forte@Sun.COM  */
7217836SJohn.Forte@Sun.COM 
7227836SJohn.Forte@Sun.COM #define	RDC_SYNC_EVENT_TIMEOUT	(60 * HZ)
7237836SJohn.Forte@Sun.COM typedef struct {
7247836SJohn.Forte@Sun.COM 	clock_t lbolt;
7257836SJohn.Forte@Sun.COM 	int event;
7267836SJohn.Forte@Sun.COM 	int ack;
7277836SJohn.Forte@Sun.COM 	int daemon_waiting;		/* Daemon waiting in ioctl */
7287836SJohn.Forte@Sun.COM 	int kernel_waiting;		/* Kernel waiting for daemon to reply */
7297836SJohn.Forte@Sun.COM 	char master[NSC_MAXPATH];
7307836SJohn.Forte@Sun.COM 	char group[NSC_MAXPATH];
7317836SJohn.Forte@Sun.COM 	kmutex_t mutex;
7327836SJohn.Forte@Sun.COM 	kcondvar_t cv;
7337836SJohn.Forte@Sun.COM 	kcondvar_t done_cv;
7347836SJohn.Forte@Sun.COM } rdc_sync_event_t;
7357836SJohn.Forte@Sun.COM extern rdc_sync_event_t rdc_sync_event;
7367836SJohn.Forte@Sun.COM extern clock_t rdc_sync_event_timeout;
7377836SJohn.Forte@Sun.COM extern kmutex_t rdc_sync_mutex;
7387836SJohn.Forte@Sun.COM 
7397836SJohn.Forte@Sun.COM extern rdc_u_info_t *rdc_u_info;
7407836SJohn.Forte@Sun.COM extern rdc_k_info_t *rdc_k_info;
7417836SJohn.Forte@Sun.COM 
7427836SJohn.Forte@Sun.COM extern int rdc_max_sets;
7437836SJohn.Forte@Sun.COM 
7447836SJohn.Forte@Sun.COM extern unsigned long rdc_async_timeout;
7457836SJohn.Forte@Sun.COM 
7467836SJohn.Forte@Sun.COM extern int rdc_self_host();
7477836SJohn.Forte@Sun.COM extern uint64_t mirror_getsize(int index);
7487836SJohn.Forte@Sun.COM extern void rdc_sleepqdiscard(rdc_group_t *);
7497836SJohn.Forte@Sun.COM 
7507836SJohn.Forte@Sun.COM 
7517836SJohn.Forte@Sun.COM #ifdef	DEBUG
7527836SJohn.Forte@Sun.COM extern void rdc_stallzero(int);
7537836SJohn.Forte@Sun.COM #endif
7547836SJohn.Forte@Sun.COM 
7557836SJohn.Forte@Sun.COM struct rdc_net_dataitem {
7567836SJohn.Forte@Sun.COM 	void *dptr;
7577836SJohn.Forte@Sun.COM 	int   len;	/* byte count */
7587836SJohn.Forte@Sun.COM 	int   mlen;	/* actual malloced size */
7597836SJohn.Forte@Sun.COM 	struct rdc_net_dataitem *next;
7607836SJohn.Forte@Sun.COM };
7617836SJohn.Forte@Sun.COM typedef struct rdc_net_dataitem rdc_net_dataitem_t;
7627836SJohn.Forte@Sun.COM 
7637836SJohn.Forte@Sun.COM struct rdc_net_dataset {
7647836SJohn.Forte@Sun.COM 	int id;
7657836SJohn.Forte@Sun.COM 	int inuse;
7667836SJohn.Forte@Sun.COM 	int delpend;
7677836SJohn.Forte@Sun.COM 	int nitems;
7687836SJohn.Forte@Sun.COM 	nsc_off_t pos;
7697836SJohn.Forte@Sun.COM 	nsc_size_t fbalen;
7707836SJohn.Forte@Sun.COM 	rdc_net_dataitem_t *head;
7717836SJohn.Forte@Sun.COM 	rdc_net_dataitem_t *tail;
7727836SJohn.Forte@Sun.COM 	struct rdc_net_dataset *next;
7737836SJohn.Forte@Sun.COM };
7747836SJohn.Forte@Sun.COM typedef struct rdc_net_dataset rdc_net_dataset_t;
7757836SJohn.Forte@Sun.COM 
7767836SJohn.Forte@Sun.COM 
7777836SJohn.Forte@Sun.COM #endif /* _KERNEL */
7787836SJohn.Forte@Sun.COM 
7797836SJohn.Forte@Sun.COM 
7807836SJohn.Forte@Sun.COM #define	RDC_TCP_DEV		"/dev/tcp"
7817836SJohn.Forte@Sun.COM 
7827836SJohn.Forte@Sun.COM #define	RDC_VERS_MIN	RDC_VERSION5
7837836SJohn.Forte@Sun.COM #define	RDC_VERS_MAX	RDC_VERSION7
7847836SJohn.Forte@Sun.COM 
7857836SJohn.Forte@Sun.COM #define	RDC_HEALTH_THRESHOLD	20
7867836SJohn.Forte@Sun.COM #define	RDC_MIN_HEALTH_THRES	5
7877836SJohn.Forte@Sun.COM #define	SNDR_MAXTHREADS		16
7887836SJohn.Forte@Sun.COM /*
7897836SJohn.Forte@Sun.COM  * These next two defines are the default value of the async queue size
7907836SJohn.Forte@Sun.COM  * They have been calculated to be 8MB of data with an average of
7917836SJohn.Forte@Sun.COM  * 2K IO size
7927836SJohn.Forte@Sun.COM  */
7937836SJohn.Forte@Sun.COM #define	RDC_MAXTHRES_QUEUE 	16384	/* max # of fbas on async q */
7947836SJohn.Forte@Sun.COM #define	RDC_MAX_QITEMS		4096	/* max # of items on async q */
7957836SJohn.Forte@Sun.COM #define	RDC_ASYNCTHR		2	/* number of async threads */
7967836SJohn.Forte@Sun.COM 
7977836SJohn.Forte@Sun.COM #define	RDC_RPC_MAX		(RDC_MAXDATA + sizeof (net_data5) +\
7987836SJohn.Forte@Sun.COM 					(RPC_MAXDATASIZE - 8192))
7997836SJohn.Forte@Sun.COM #define	ATM_NONE 0
8007836SJohn.Forte@Sun.COM #define	ATM_INIT 1
8017836SJohn.Forte@Sun.COM #define	ATM_EXIT 2
8027836SJohn.Forte@Sun.COM 
8037836SJohn.Forte@Sun.COM #define	RDC_CLNT_TMOUT		16
8047836SJohn.Forte@Sun.COM 
8057836SJohn.Forte@Sun.COM #define	BMAP_BLKSIZE 1024
8067836SJohn.Forte@Sun.COM #define	BMAP_BLKSIZEV7 RDC_MAXDATA
8077836SJohn.Forte@Sun.COM 
8087836SJohn.Forte@Sun.COM /* right now we can only trace 1m or less writes to the bitmap (32 bits wide) */
8097836SJohn.Forte@Sun.COM #define	RDC_MAX_MAXFBAS	2048
8107836SJohn.Forte@Sun.COM 
8117836SJohn.Forte@Sun.COM #if defined(_KERNEL)
8127836SJohn.Forte@Sun.COM /* kstat interface */
8137836SJohn.Forte@Sun.COM 
8147836SJohn.Forte@Sun.COM /*
8157836SJohn.Forte@Sun.COM  * Per module kstats
8167836SJohn.Forte@Sun.COM  * only one instance
8177836SJohn.Forte@Sun.COM  */
8187836SJohn.Forte@Sun.COM typedef struct {
8197836SJohn.Forte@Sun.COM 	kstat_named_t	m_maxsets;		/* Max # of sndr sets */
8207836SJohn.Forte@Sun.COM 	kstat_named_t	m_maxfbas;		/* Max # of FBAS from nsctl */
8217836SJohn.Forte@Sun.COM 	kstat_named_t	m_rpc_timeout;		/* global RPC timeout */
8227836SJohn.Forte@Sun.COM 	kstat_named_t	m_health_thres;		/* Health thread timeout */
8237836SJohn.Forte@Sun.COM 	kstat_named_t	m_bitmap_writes;	/* True for bitmap writes */
8247836SJohn.Forte@Sun.COM 	kstat_named_t	m_clnt_cots_calls;	/* # of clnt COTS calls */
8257836SJohn.Forte@Sun.COM 	kstat_named_t	m_clnt_clts_calls;	/* # of clnt CLTS calls */
8267836SJohn.Forte@Sun.COM 	kstat_named_t	m_svc_cots_calls;	/* # of server COTS calls */
8277836SJohn.Forte@Sun.COM 	kstat_named_t	m_svc_clts_calls;	/* # of server CLTS calls */
8287836SJohn.Forte@Sun.COM 	kstat_named_t	m_bitmap_ref_delay;	/* # of bitmap ref overflows */
8297836SJohn.Forte@Sun.COM } sndr_m_stats_t;
8307836SJohn.Forte@Sun.COM 
8317836SJohn.Forte@Sun.COM /*
8327836SJohn.Forte@Sun.COM  * Per set kstats
8337836SJohn.Forte@Sun.COM  * one instance per configured set
8347836SJohn.Forte@Sun.COM  */
8357836SJohn.Forte@Sun.COM typedef struct {
8367836SJohn.Forte@Sun.COM 	kstat_named_t	s_flags;	/* from rdc_set_t */
8377836SJohn.Forte@Sun.COM 	kstat_named_t	s_syncflags;	/* from rdc_set_t */
8387836SJohn.Forte@Sun.COM 	kstat_named_t	s_bmpflags;	/* from rdc_set_t */
8397836SJohn.Forte@Sun.COM 	kstat_named_t	s_syncpos;	/* from rdc_set_t */
8407836SJohn.Forte@Sun.COM 	kstat_named_t	s_volsize;	/* from rdc_set_t */
8417836SJohn.Forte@Sun.COM 	kstat_named_t	s_bits_set;	/* from rdc_set_t */
8427836SJohn.Forte@Sun.COM 	kstat_named_t	s_autosync;	/* from rdc_set_t */
8437836SJohn.Forte@Sun.COM 	kstat_named_t	s_maxqfbas;	/* from rdc_set_t */
8447836SJohn.Forte@Sun.COM 	kstat_named_t	s_maxqitems;	/* from rdc_set_t */
8457836SJohn.Forte@Sun.COM 	kstat_named_t	s_primary_vol;	/* from rdc_set_t */
8467836SJohn.Forte@Sun.COM 	kstat_named_t	s_secondary_vol;	/* from rdc_set_t */
8477836SJohn.Forte@Sun.COM 	kstat_named_t	s_bitmap;	/* from rdc_set_t */
8487836SJohn.Forte@Sun.COM 	kstat_named_t	s_primary_intf;	/* from rdc_set_t */
8497836SJohn.Forte@Sun.COM 	kstat_named_t	s_secondary_intf;	/* from rdc_set_t */
8507836SJohn.Forte@Sun.COM 	kstat_named_t	s_type_flag;	/* from rdc_k_info_t */
8517836SJohn.Forte@Sun.COM 	kstat_named_t	s_bitmap_size;	/* from rdc_k_info_t */
8527836SJohn.Forte@Sun.COM 	kstat_named_t	s_disk_status;	/* from rdc_k_info_t */
8537836SJohn.Forte@Sun.COM 	kstat_named_t	s_if_if_down;	/* from rdc_if_t */
8547836SJohn.Forte@Sun.COM 	kstat_named_t	s_if_rpc_version;	/* from rdc_if_t */
8557836SJohn.Forte@Sun.COM 	kstat_named_t	s_aqueue_blk_hwm;	/* from rdc_k_info_t */
8567836SJohn.Forte@Sun.COM 	kstat_named_t	s_aqueue_itm_hwm;	/* from rdc_k_info_t */
8577836SJohn.Forte@Sun.COM 	kstat_named_t	s_aqueue_throttle;	/* from rdc_k_info_t */
8587836SJohn.Forte@Sun.COM 	kstat_named_t	s_aqueue_items;
8597836SJohn.Forte@Sun.COM 	kstat_named_t	s_aqueue_blocks;
8607836SJohn.Forte@Sun.COM 	kstat_named_t	s_aqueue_type;
8617836SJohn.Forte@Sun.COM } rdc_info_stats_t;
8627836SJohn.Forte@Sun.COM #endif /* _KERNEL */
8637836SJohn.Forte@Sun.COM 
8647836SJohn.Forte@Sun.COM #ifndef _SunOS_5_6 	/* i.e. 2.7+ */
8657836SJohn.Forte@Sun.COM typedef int xdr_t;
8667836SJohn.Forte@Sun.COM #else	/* i.e. 2.6- */
8677836SJohn.Forte@Sun.COM typedef unsigned long rpcprog_t;
8687836SJohn.Forte@Sun.COM typedef unsigned long rpcvers_t;
8697836SJohn.Forte@Sun.COM typedef unsigned long rpcproc_t;
8707836SJohn.Forte@Sun.COM typedef unsigned long rpcprot_t;
8717836SJohn.Forte@Sun.COM typedef unsigned long rpcport_t;
8727836SJohn.Forte@Sun.COM #endif /* _SunOS_5_6 */
8737836SJohn.Forte@Sun.COM 
8747836SJohn.Forte@Sun.COM 
8757836SJohn.Forte@Sun.COM #ifdef _KERNEL
8767836SJohn.Forte@Sun.COM 
8777836SJohn.Forte@Sun.COM extern nsc_size_t MAX_RDC_FBAS;
8787836SJohn.Forte@Sun.COM extern volatile int net_exit;
8797836SJohn.Forte@Sun.COM extern nsc_size_t rdc_maxthres_queue;	/* max # of fbas on async q */
8807836SJohn.Forte@Sun.COM extern int rdc_max_qitems;		/* max # of items on async q */
8817836SJohn.Forte@Sun.COM extern int rdc_asyncthr;	/* # of async threads */
8827836SJohn.Forte@Sun.COM 
8837836SJohn.Forte@Sun.COM #ifdef DEBUG
8847836SJohn.Forte@Sun.COM extern kmutex_t rdc_cntlock;
8857836SJohn.Forte@Sun.COM extern int rdc_datasetcnt;
8867836SJohn.Forte@Sun.COM #endif
8877836SJohn.Forte@Sun.COM 
8887836SJohn.Forte@Sun.COM /*
8897836SJohn.Forte@Sun.COM  * Macro to keep tabs on dataset memory usage.
8907836SJohn.Forte@Sun.COM  */
8917836SJohn.Forte@Sun.COM #ifdef DEBUG
8927836SJohn.Forte@Sun.COM #define	RDC_DSMEMUSE(x) \
8937836SJohn.Forte@Sun.COM 	mutex_enter(&rdc_cntlock);\
8947836SJohn.Forte@Sun.COM 	rdc_datasetcnt += (x);\
8957836SJohn.Forte@Sun.COM 	mutex_exit(&rdc_cntlock);
8967836SJohn.Forte@Sun.COM #else
8977836SJohn.Forte@Sun.COM #define	RDC_DSMEMUSE(x)
8987836SJohn.Forte@Sun.COM #endif
8997836SJohn.Forte@Sun.COM 
9007836SJohn.Forte@Sun.COM 
9017836SJohn.Forte@Sun.COM 
9027836SJohn.Forte@Sun.COM 
9037836SJohn.Forte@Sun.COM 
9047836SJohn.Forte@Sun.COM extern kmutex_t rdc_ping_lock;
9057836SJohn.Forte@Sun.COM extern rdc_if_t *rdc_if_top;
9067836SJohn.Forte@Sun.COM 
9077836SJohn.Forte@Sun.COM extern int _rdc_enqueue_write(rdc_k_info_t *, nsc_off_t, nsc_size_t, int,
9087836SJohn.Forte@Sun.COM     nsc_buf_t *);
9097836SJohn.Forte@Sun.COM extern int rdc_net_state(int, int);
9107836SJohn.Forte@Sun.COM extern int rdc_net_getbmap(int, int);
9117836SJohn.Forte@Sun.COM extern int rdc_net_getsize(int, uint64_t *);
9127836SJohn.Forte@Sun.COM extern int rdc_net_write(int, int, nsc_buf_t *, nsc_off_t, nsc_size_t, uint_t,
9137836SJohn.Forte@Sun.COM     int, netwriteres *);
9147836SJohn.Forte@Sun.COM extern int rdc_net_read(int, int, nsc_buf_t *, nsc_off_t, nsc_size_t);
9157836SJohn.Forte@Sun.COM extern int _rdc_remote_read(rdc_k_info_t *, nsc_buf_t *, nsc_off_t, nsc_size_t,
9167836SJohn.Forte@Sun.COM     int);
9177836SJohn.Forte@Sun.COM extern int _rdc_multi_write(nsc_buf_t *, nsc_off_t, nsc_size_t, int,
9187836SJohn.Forte@Sun.COM     rdc_k_info_t *);
9197836SJohn.Forte@Sun.COM extern int rdc_start_server(struct rdc_svc_args *, int);
9207836SJohn.Forte@Sun.COM extern aio_buf_t *rdc_aio_buf_get(rdc_buf_t *, int);
9217836SJohn.Forte@Sun.COM extern void rdc_aio_buf_del(rdc_buf_t *, rdc_k_info_t *);
9227836SJohn.Forte@Sun.COM extern aio_buf_t *rdc_aio_buf_add(int, rdc_buf_t *);
9237836SJohn.Forte@Sun.COM extern int rdc_net_getstate(rdc_k_info_t *, int *, int *, int *, int);
9247836SJohn.Forte@Sun.COM extern kmutex_t rdc_conf_lock;
9257836SJohn.Forte@Sun.COM extern kmutex_t rdc_many_lock;
9267836SJohn.Forte@Sun.COM extern int rdc_drain_queue(int);
9277836SJohn.Forte@Sun.COM extern int flush_group_queue(int);
9287836SJohn.Forte@Sun.COM extern void rdc_dev_close(rdc_k_info_t *);
9297836SJohn.Forte@Sun.COM extern int rdc_dev_open(rdc_set_t *, int);
9307836SJohn.Forte@Sun.COM extern void rdc_get_details(rdc_k_info_t *);
9317836SJohn.Forte@Sun.COM extern int rdc_lookup_bitmap(char *);
9327836SJohn.Forte@Sun.COM extern int rdc_lookup_enabled(char *, int);
9337836SJohn.Forte@Sun.COM extern int rdc_lookup_byaddr(rdc_set_t *);
9347836SJohn.Forte@Sun.COM extern int rdc_lookup_byname(rdc_set_t *);
9357836SJohn.Forte@Sun.COM extern int rdc_intercept(rdc_k_info_t *);
9367836SJohn.Forte@Sun.COM extern int rdc_unintercept(rdc_k_info_t *);
9377836SJohn.Forte@Sun.COM extern int _rdc_rsrv_devs(rdc_k_info_t *, int, int);
9387836SJohn.Forte@Sun.COM extern void _rdc_rlse_devs(rdc_k_info_t *, int);
9397836SJohn.Forte@Sun.COM extern void _rdc_unload(void);
9407836SJohn.Forte@Sun.COM extern int _rdc_load(void);
9417836SJohn.Forte@Sun.COM extern int _rdc_configure(void);
9427836SJohn.Forte@Sun.COM extern void _rdc_deconfigure(void);
9437836SJohn.Forte@Sun.COM extern void _rdc_async_throttle(rdc_k_info_t *, long);
9447836SJohn.Forte@Sun.COM extern int rdc_writer(int);
9457836SJohn.Forte@Sun.COM extern int rdc_dump_alloc_bufs_cd(int);
9467836SJohn.Forte@Sun.COM extern void rdc_dump_alloc_bufs(rdc_if_t *);
9477836SJohn.Forte@Sun.COM extern int rdc_check_secondary(rdc_if_t *, int);
9487836SJohn.Forte@Sun.COM extern void rdc_dump_queue(int);
9497836SJohn.Forte@Sun.COM extern int rdc_isactive_if(struct netbuf *, struct netbuf *);
9507836SJohn.Forte@Sun.COM extern rdc_if_t *rdc_add_to_if(rdc_srv_t *, struct netbuf *, struct netbuf *,
9517836SJohn.Forte@Sun.COM     int);
9527836SJohn.Forte@Sun.COM extern void rdc_remove_from_if(rdc_if_t *);
9537836SJohn.Forte@Sun.COM extern void rdc_set_if_vers(rdc_u_info_t *, rpcvers_t);
9547836SJohn.Forte@Sun.COM 
9557836SJohn.Forte@Sun.COM extern void rdc_print_svinfo(rdc_srv_t *, char *);
9567836SJohn.Forte@Sun.COM extern rdc_srv_t *rdc_create_svinfo(char *, struct netbuf *,
9577836SJohn.Forte@Sun.COM 			struct knetconfig *);
9587836SJohn.Forte@Sun.COM extern void rdc_destroy_svinfo(rdc_srv_t *);
9597836SJohn.Forte@Sun.COM 
9607836SJohn.Forte@Sun.COM extern void init_rdc_netbuf(struct netbuf *);
9617836SJohn.Forte@Sun.COM extern void free_rdc_netbuf(struct netbuf *);
9627836SJohn.Forte@Sun.COM extern void dup_rdc_netbuf(const struct netbuf *, struct netbuf *);
9637836SJohn.Forte@Sun.COM extern int rdc_netbuf_toint(struct netbuf *);
9647836SJohn.Forte@Sun.COM extern struct netbuf *rdc_int_tonetbuf(int);
9657836SJohn.Forte@Sun.COM extern void rdc_lor(const uchar_t *, uchar_t *, int);
9667836SJohn.Forte@Sun.COM extern int rdc_resume2(rdc_k_info_t *);
9677836SJohn.Forte@Sun.COM extern void rdc_set_flags(rdc_u_info_t *, int);
9687836SJohn.Forte@Sun.COM extern void rdc_clr_flags(rdc_u_info_t *, int);
9697836SJohn.Forte@Sun.COM extern int rdc_get_vflags(rdc_u_info_t *);
9707836SJohn.Forte@Sun.COM extern void rdc_set_mflags(rdc_u_info_t *, int);
9717836SJohn.Forte@Sun.COM extern void rdc_clr_mflags(rdc_u_info_t *, int);
9727836SJohn.Forte@Sun.COM extern int rdc_get_mflags(rdc_u_info_t *);
9737836SJohn.Forte@Sun.COM extern void rdc_set_flags_log(rdc_u_info_t *, int, char *);
9747836SJohn.Forte@Sun.COM extern void rdc_group_log(rdc_k_info_t *krdc, int flush, char *why);
9757836SJohn.Forte@Sun.COM extern int _rdc_config(void *, int, spcs_s_info_t, int *);
9767836SJohn.Forte@Sun.COM extern void rdc_many_enter(rdc_k_info_t *);
9777836SJohn.Forte@Sun.COM extern void rdc_many_exit(rdc_k_info_t *);
9787836SJohn.Forte@Sun.COM extern void rdc_group_enter(rdc_k_info_t *);
9797836SJohn.Forte@Sun.COM extern void rdc_group_exit(rdc_k_info_t *);
9807836SJohn.Forte@Sun.COM extern int _rdc_sync_event_wait(void *, void *, int, spcs_s_info_t, int *);
9817836SJohn.Forte@Sun.COM extern int _rdc_sync_event_notify(int, char *, char *);
9827836SJohn.Forte@Sun.COM extern int _rdc_link_down(void *, int, spcs_s_info_t, int *);
9837836SJohn.Forte@Sun.COM extern void rdc_delgroup(rdc_group_t *);
9847836SJohn.Forte@Sun.COM extern int rdc_write_bitmap_fba(rdc_k_info_t *, nsc_off_t);
9857836SJohn.Forte@Sun.COM extern int rdc_bitmapset(int, char *, char *, void *, int, nsc_off_t, int);
9867836SJohn.Forte@Sun.COM extern rdc_net_dataset_t *rdc_net_add_set(int);
9877836SJohn.Forte@Sun.COM extern rdc_net_dataset_t *rdc_net_get_set(int, int);
9887836SJohn.Forte@Sun.COM extern void rdc_net_put_set(int, rdc_net_dataset_t *);
9897836SJohn.Forte@Sun.COM extern void rdc_net_del_set(int, rdc_net_dataset_t *);
9907836SJohn.Forte@Sun.COM extern void rdc_net_free_set(rdc_k_info_t *, rdc_net_dataset_t *);
9917836SJohn.Forte@Sun.COM extern int rdc_lookup_byhostdev(char *intf, char *file);
9927836SJohn.Forte@Sun.COM extern int rdc_lookup_configured(char *path);
9937836SJohn.Forte@Sun.COM extern void rdc_dump_dsets(int);
9947836SJohn.Forte@Sun.COM extern void set_busy(rdc_k_info_t *);
9957836SJohn.Forte@Sun.COM extern void wakeup_busy(rdc_k_info_t *);
9967836SJohn.Forte@Sun.COM 
9977836SJohn.Forte@Sun.COM 
9987836SJohn.Forte@Sun.COM #ifdef	DEBUG
9997836SJohn.Forte@Sun.COM extern int rdc_async6(void *, int mode, int *);
10007836SJohn.Forte@Sun.COM extern int rdc_readgen(void *, int, int *);
10017836SJohn.Forte@Sun.COM #endif
10027836SJohn.Forte@Sun.COM 
10037836SJohn.Forte@Sun.COM #endif /* _KERNEL */
10047836SJohn.Forte@Sun.COM 
10057836SJohn.Forte@Sun.COM #ifdef	__cplusplus
10067836SJohn.Forte@Sun.COM }
10077836SJohn.Forte@Sun.COM #endif
10087836SJohn.Forte@Sun.COM 
10097836SJohn.Forte@Sun.COM #endif /* _RDC_IO_H */
1010