xref: /titanic_41/usr/src/uts/common/avs/ns/dsw/dsw_dev.h (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_DSW_DEV_H
27 #define	_DSW_DEV_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * Definitions for kstats
35  */
36 #define	DSW_SKSTAT_SIZE			"size"
37 #define	DSW_SKSTAT_MTIME		"latest modified time"
38 #define	DSW_SKSTAT_FLAGS		"flags"
39 #define	DSW_SKSTAT_THROTTLE_UNIT	"ii_throttle_unit"
40 #define	DSW_SKSTAT_THROTTLE_DELAY	"ii_throttle_delay"
41 #define	DSW_SKSTAT_SHDCHKS		"shdchks"
42 #define	DSW_SKSTAT_SHDCHKUSED		"shdchkused"
43 #define	DSW_SKSTAT_SHDBITS		"shdbits"
44 #define	DSW_SKSTAT_COPYBITS		"copybits"
45 #define	DSW_SKSTAT_MSTA			"mst-a"
46 #define	DSW_SKSTAT_MSTB			"mst-b"
47 #define	DSW_SKSTAT_MSTC			"mst-c"
48 #define	DSW_SKSTAT_MSTD			"mst-d"
49 #define	DSW_SKSTAT_SETA			"set-a"
50 #define	DSW_SKSTAT_SETB			"set-b"
51 #define	DSW_SKSTAT_SETC			"set-c"
52 #define	DSW_SKSTAT_SETD			"set-d"
53 #define	DSW_SKSTAT_BMPA			"bmp-a"
54 #define	DSW_SKSTAT_BMPB			"bmp-b"
55 #define	DSW_SKSTAT_BMPC			"bmp-c"
56 #define	DSW_SKSTAT_BMPD			"bmp-d"
57 #define	DSW_SKSTAT_OVRA			"ovr-a"
58 #define	DSW_SKSTAT_OVRB			"ovr-b"
59 #define	DSW_SKSTAT_OVRC			"ovr-c"
60 #define	DSW_SKSTAT_OVRD			"ovr-d"
61 #define	DSW_SKSTAT_MSTIO		"mst-io"
62 #define	DSW_SKSTAT_SHDIO		"shd-io"
63 #define	DSW_SKSTAT_BMPIO		"bmp-io"
64 #define	DSW_SKSTAT_OVRIO		"ovr-io"
65 
66 /*
67  * Bitmap macros
68  */
69 
70 #define	DSW_BIT_CLR(bmap, bit)		(bmap &= (char)~(1 << bit))
71 #define	DSW_BIT_SET(bmap, bit)		(bmap |= (char)(1 << bit))
72 #define	DSW_BIT_ISSET(bmap, bit)	((bmap & (1 << bit)) != 0)
73 
74 #define	DSW_CBLK_FBA		16		/* cache blocks in fba's */
75 #define	DSW_SHD_BM_OFFSET	DSW_CBLK_FBA	/* offset to allow for header */
76 #define	DSW_COPY_BM_OFFSET	(DSW_SHD_BM_OFFSET + \
77 					DSW_BM_FBA_LEN(ip->bi_size))
78 #define	DSW_BM_FBA_LEN(mst_size)  ((mst_size) / FBA_SIZE(DSW_SIZE*DSW_BITS) + \
79 					DSW_CBLK_FBA)
80 
81 #define	DSW_BM_SIZE_CHUNKS(ip)	((ip->bi_size + DSW_SIZE - 1) / DSW_SIZE)
82 #define	DSW_BM_SIZE_BYTES(ip)	((DSW_BM_SIZE_CHUNKS(ip) + DSW_BITS - 1) /  \
83 					DSW_BITS)
84 
85 #define	DSW_CHK2FBA(chunk)		(((nsc_off_t)(chunk)) * DSW_SIZE)
86 
87 #if defined(_KERNEL) || defined(_KMEMUSER)
88 
89 /*
90  * Shadow types.
91  */
92 
93 #define	DSW_GOLDEN_TYPE	0x1000
94 #define	DSW_QUICK_TYPE	0x2000
95 
96 /*
97  * Miscellaneous defines
98  */
99 
100 #define	II_INTERNAL	0x1
101 #define	II_EXTERNAL	0x2
102 
103 #define	II_EXISTING	0x01	/* Internal dsw_ioctl()/dsw_config() flags */
104 #define	II_IMPORT	0x02
105 
106 /*
107  * defines for _ii_nsc_io and _ii_write, used by kstats
108  */
109 
110 #define	KS_NA	0
111 #define	KS_MST	1
112 #define	KS_SHD	2
113 #define	KS_BMP	3
114 #define	KS_OVR	4
115 
116 /*
117  * global kstats
118  */
119 
120 typedef struct _iigkstat_s {
121 	/* static */
122 	kstat_named_t ii_debug;
123 	kstat_named_t ii_bitmap;
124 	kstat_named_t ii_throttle_unit;
125 	kstat_named_t ii_throttle_delay;
126 	kstat_named_t ii_copy_direct;
127 
128 	/* dynamic */
129 	kstat_named_t num_sets;
130 	kstat_named_t assoc_over;
131 	kstat_named_t spilled_over;
132 } iigkstat_t;
133 
134 extern iigkstat_t iigkstat;
135 
136 /*
137  * set-specific kstats
138  */
139 typedef struct _ii_kstat_set_s {
140 	kstat_named_t size;		/* from _ii_stat() */
141 	kstat_named_t mtime;		/* from _ii_stat() */
142 	kstat_named_t flags;		/* from _ii_stat() */
143 	kstat_named_t unit;		/* ii_throttle_unit */
144 	kstat_named_t delay;		/* ii_throttle_delay */
145 	kstat_named_t shdchks;		/* from _ii_stat() */
146 	kstat_named_t shdchkused;	/* from _ii_stat() */
147 	kstat_named_t shdbits;		/* # bits set shadow bitmap */
148 	kstat_named_t copybits;		/* # bits set copy bitmap */
149 	kstat_named_t mst_a;		/* name		*/
150 	kstat_named_t mst_b;		/* .. of	*/
151 	kstat_named_t mst_c;		/* .. master	*/
152 	kstat_named_t mst_d;		/* .. volume	*/
153 	kstat_named_t set_a;		/* name		*/
154 	kstat_named_t set_b;		/* .. of	*/
155 	kstat_named_t set_c;		/* .. the	*/
156 	kstat_named_t set_d;		/* .. set	*/
157 	kstat_named_t bmp_a;		/* name		*/
158 	kstat_named_t bmp_b;		/* .. of	*/
159 	kstat_named_t bmp_c;		/* .. bitmap	*/
160 	kstat_named_t bmp_d;		/* .. volume	*/
161 	kstat_named_t ovr_a;		/* name		*/
162 	kstat_named_t ovr_b;		/* .. of	*/
163 	kstat_named_t ovr_c;		/* .. overflow	*/
164 	kstat_named_t ovr_d;		/* .. volume	*/
165 	kstat_named_t mst_io;		/* kstat_io of master */
166 	kstat_named_t shd_io;		/* kstat_io of shadow */
167 	kstat_named_t bmp_io;		/* kstat_io of bitmap */
168 	kstat_named_t ovr_io;		/* kstat_io of overflow */
169 } ii_kstat_set_t;
170 
171 extern ii_kstat_set_t ii_kstat_set;
172 #define	IOSTAT_NAME_LEN 10
173 
174 /* Basic types */
175 #ifdef II_MULTIMULTI_TERABYTE
176 typedef	int64_t	chunkid_t;
177 typedef	int32_t	chunkid32_t;
178 #else
179 typedef	int32_t	chunkid_t;
180 #endif
181 
182 /*
183  * OV_HEADER_VERSION
184  *      0 = original OV header version
185  *      1 = flags support
186  */
187 #define	OV_HEADER_VERSION	1
188 
189 /* Overflow disk volume header */
190 typedef	struct	_ii_doverflow_s {
191 	char	ii_dvolname[DSW_NAMELEN];	/* this volumes name */
192 	uint32_t	ii_dhmagic;		/* sanity check */
193 	uint32_t	ii_dhversion;		/* volume format */
194 	int32_t		ii_ddrefcnt;		/* total number of users */
195 	int32_t		ii_dflags;		/* status flags */
196 	int64_t		ii_dfreehead;		/* chain of freed chunks */
197 	int64_t		ii_dnchunks;		/* total number of chunks */
198 	int64_t		ii_dunused;		/* number of chunks available */
199 	int64_t		ii_dused;		/* number of chunks allocated */
200 	int32_t		ii_urefcnt;		/* # shadows needing update */
201 	int32_t		ii_dcrefcnt;		/* current number of users */
202 } _ii_doverflow_t;
203 
204 /* Overflow volume in core structure */
205 typedef	struct	_ii_overflow_s {
206 	_ii_doverflow_t	ii_do;
207 	kmutex_t		ii_mutex;	/* Mutex */
208 	kmutex_t		ii_kstat_mutex;	/* Mutex for overflow kstat */
209 	int	ii_detachcnt;			/* users detaching on disable */
210 	struct	_ii_overflow_s *ii_next;	/* chain of incore structs */
211 	struct	_ii_info_dev_s *ii_dev;		/* pointer to device details */
212 	kstat_t		*ii_overflow;		/* kstats data for this vol */
213 	char	ii_ioname[KSTAT_DATA_CHAR_LEN];	/* name for iostat -x */
214 } _ii_overflow_t;
215 
216 #define	ii_volname	ii_do.ii_dvolname
217 #define	ii_hmagic	ii_do.ii_dhmagic
218 #define	ii_drefcnt	ii_do.ii_ddrefcnt
219 #define	ii_freehead	ii_do.ii_dfreehead
220 #define	ii_nchunks	ii_do.ii_dnchunks
221 #define	ii_unused	ii_do.ii_dunused
222 #define	ii_used		ii_do.ii_dused
223 #define	ii_hversion	ii_do.ii_dhversion
224 #define	ii_flags	ii_do.ii_dflags
225 #define	ii_urefcnt	ii_do.ii_urefcnt
226 #define	ii_crefcnt	ii_do.ii_dcrefcnt
227 
228 #define	II_OHEADER_FBA	0			/* overflow header location */
229 /*
230  * logging of kstat_io
231  */
232 #ifdef DISABLE_KSTATS
233 #define	II_READ_START(ip, type)
234 #define	II_READ_END(ip, type, rc, blocks)
235 #define	II_WRITE_START(ip, type)
236 #define	II_WRITE_END(ip, type, rc, blocks)
237 #else
238 
239 #define	II_KS(ip, x) KSTAT_IO_PTR(ip->bi_kstat_io.x)
240 #define	II_MUTEX(ip, x) ip->bi_kstat_io.x->ks_lock
241 #define	II_BLKSIZE 512
242 
243 #define	II_READ_START(ip, type)						\
244 	if (ip->bi_kstat_io.type) {					\
245 		mutex_enter(II_MUTEX(ip, type));			\
246 		kstat_runq_enter(II_KS(ip, type));			\
247 		mutex_exit(II_MUTEX(ip, type));				\
248 	}
249 #define	II_READ_END(ip, type, rc, blocks)				\
250 	if (ip->bi_kstat_io.type) {					\
251 		mutex_enter(II_MUTEX(ip, type));			\
252 		if (II_SUCCESS(rc)) {					\
253 			II_KS(ip, type)->reads++;			\
254 			II_KS(ip, type)->nread += II_BLKSIZE * (blocks);\
255 		}							\
256 		kstat_runq_exit(II_KS(ip, type));			\
257 		mutex_exit(II_MUTEX(ip, type));				\
258 	}
259 
260 #define	II_WRITE_START(ip, type)					\
261 	if (ip->bi_kstat_io.type) {					\
262 		mutex_enter(II_MUTEX(ip, type));			\
263 		kstat_runq_enter(II_KS(ip, type));			\
264 		mutex_exit(II_MUTEX(ip, type));				\
265 	}
266 #define	II_WRITE_END(ip, type, rc, blocks)				\
267 	if (ip->bi_kstat_io.type) {					\
268 		mutex_enter(II_MUTEX(ip, type));			\
269 		if (II_SUCCESS(rc)) {					\
270 			II_KS(ip, type)->writes++;			\
271 			II_KS(ip, type)->nwritten += II_BLKSIZE * (blocks);\
272 		}							\
273 		kstat_runq_exit(II_KS(ip, type));			\
274 		mutex_exit(II_MUTEX(ip, type));				\
275 	}
276 #endif
277 
278 #define	II_NSC_READ(ip, type, rc, buf, pos, len, flag)			\
279 		II_READ_START(ip, type);				\
280 		rc = nsc_read(buf, pos, len, flag);			\
281 		II_READ_END(ip, type, rc, len);
282 
283 #define	II_NSC_WRITE(ip, type, rc, buf, pos, len, flag)			\
284 		II_WRITE_START(ip, type);				\
285 		rc = nsc_write(buf, pos, len, flag);			\
286 		II_WRITE_END(ip, type, rc, len);
287 
288 #define	II_NSC_COPY_DIRECT(ip, t1, t2, rc, buf1, buf2, pos1, pos2, len)	\
289 		II_WRITE_START(ip, t2);					\
290 		rc = nsc_copy_direct(buf1, buf2, pos1, pos2, len);	\
291 		II_WRITE_END(ip, t2, rc, len);
292 
293 #define	II_ALLOC_BUF(ip, type, rc, fd, pos, len, flag, tmp)		\
294 	if (flag & NSC_READ) {						\
295 		II_READ_START(ip, type);				\
296 	}								\
297 	rc = nsc_alloc_buf(fd, pos, len, flag, tmp);			\
298 	if (flag & NSC_READ) {						\
299 		II_READ_END(ip, type, rc, len);				\
300 	}
301 
302 /*
303  * All kstat_io associated with a set.  NOTE: only one mutex for all
304  * of the kstats for a given set; all master/shadow/bmp/overflow mutexes
305  * point back to the statmutex
306  */
307 
308 typedef struct _ii_kstat_info_s {
309 	kstat_t		*master;
310 	kstat_t		*shadow;
311 	kstat_t		*bitmap;
312 	kstat_t		*overflow;
313 	kmutex_t	statmutex;
314 	char	mstio[KSTAT_DATA_CHAR_LEN];	/* name of mst in iostat -x */
315 	char	shdio[KSTAT_DATA_CHAR_LEN];	/* name of shd in iostat -x */
316 	char	bmpio[KSTAT_DATA_CHAR_LEN];	/* name of bmp in iostat -x */
317 	char	ovrio[KSTAT_DATA_CHAR_LEN];	/* name of ovr in iostat -x */
318 } ii_kstat_info_t;
319 
320 /*
321  * II device info structure
322  */
323 
324 typedef struct _ii_info_dev_s {
325 	nsc_fd_t		*bi_fd;		/* Bitmap file descriptor */
326 	nsc_iodev_t		*bi_iodev;	/* I/O device structure */
327 	nsc_path_t		*bi_tok;	/* Register path token */
328 	int			bi_ref;		/* Count of fd's referencing */
329 	int			bi_rsrv;	/* Count of reserves held */
330 	int			bi_orsrv;	/* Reserves for other io prov */
331 	int			bi_flag;	/* Internal/External reserve */
332 } _ii_info_dev_t;
333 
334 typedef struct _ii_info_s {
335 	struct _ii_info_s	*bi_next;	/* Chain of all groups */
336 	struct _ii_info_s	*bi_head;	/* head of sibling chain */
337 	struct _ii_info_s	*bi_sibling;	/* Chain of groups with same */
338 							/* master */
339 	struct _ii_info_s	*bi_master;	/* location of master */
340 	struct _ii_info_s	*bi_nextmst;	/* next multimaster */
341 	kmutex_t		bi_mutex;	/* Mutex */
342 	_ii_info_dev_t		*bi_mstdev;
343 	_ii_info_dev_t		*bi_mstrdev;
344 	_ii_info_dev_t		bi_shddev;
345 	_ii_info_dev_t		bi_shdrdev;
346 	_ii_info_dev_t		bi_bmpdev;
347 	char			bi_keyname[DSW_NAMELEN];
348 	unsigned char		*bi_bitmap;	/* Master device bitmap */
349 	char			*bi_cluster;	/* cluster name */
350 	char			*bi_group;	/* group name */
351 	char			*bi_busy;	/* Busy bitmap */
352 	nsc_off_t		bi_shdfba;	/* location of shadow bitmap */
353 	nsc_size_t		bi_shdbits;	/* shadow bitmap counter */
354 	nsc_off_t		bi_copyfba;	/* location of copy bitmap */
355 	nsc_size_t		bi_copybits;	/* copy bitmap counter */
356 	nsc_size_t		bi_size;	/* Size of mst device */
357 	uint_t			bi_flags;	/* Flags */
358 	uint_t			bi_state;	/* State flags */
359 	int			bi_disabled;	/* Disable has started */
360 	int			bi_ioctl;	/* Number of active ioctls */
361 	int			bi_release;	/* Do a release in copyvol */
362 	int			bi_rsrvcnt;	/* reserve count */
363 	kcondvar_t		bi_copydonecv;	/* Copy operation condvar */
364 	kcondvar_t		bi_reservecv;	/* Reserve condvar */
365 	kcondvar_t		bi_releasecv;	/* Release condvar */
366 	kcondvar_t		bi_closingcv;	/* Shadow closing condvar */
367 	kcondvar_t		bi_ioctlcv;	/* Ioctls complete condvar */
368 	kcondvar_t		bi_busycv;	/* Busy bitmap condvar */
369 	krwlock_t		bi_busyrw;	/* Busy bitmap rwlock */
370 	struct _ii_bmp_ops_s	*bi_bitmap_ops;	/* Functions for bitmap ops */
371 	kmutex_t		bi_rsrvmutex;	/* Reserve operation mutex */
372 	kmutex_t		bi_rlsemutex;	/* Release operation mutex */
373 	kmutex_t		bi_bmpmutex;	/* mutex for bi_bitmap_ops */
374 	chunkid_t		bi_mstchks;
375 	chunkid_t		bi_shdchks;	/* # of chunks on shadow vol */
376 	chunkid_t		bi_shdchkused;	/* # of allocated */
377 	chunkid_t		bi_shdfchk;	/* start of shd chunk flst */
378 	_ii_overflow_t		*bi_overflow;
379 	struct ii_fd_s		*bi_iifd;	/* fd holding master's ip */
380 	int32_t			bi_throttle_unit;
381 	int32_t			bi_throttle_delay;
382 	krwlock_t		bi_linkrw;	/* altering linkage rwlock */
383 	kmutex_t		bi_chksmutex;	/* Mutex for bi_???chks */
384 	pid_t			bi_locked_pid;	/* lock pid for update/copy */
385 	kstat_t			*bi_kstat;	/* kstat data for set */
386 	ii_kstat_info_t		bi_kstat_io;	/* kstat I/O data for set */
387 	time_t			bi_mtime;
388 } _ii_info_t;
389 
390 #define	bi_bmpfd	bi_bmpdev.bi_fd
391 #define	bi_mstfd	bi_mstdev->bi_fd
392 #define	bi_mstrfd	bi_mstrdev->bi_fd
393 #define	bi_shdfd	bi_shddev.bi_fd
394 #define	bi_shdrfd	bi_shdrdev.bi_fd
395 #define	bi_mst_iodev	bi_mstdev->bi_iodev
396 #define	bi_mstr_iodev	bi_mstrdev->bi_iodev
397 #define	bi_shd_iodev	bi_shddev.bi_iodev
398 #define	bi_shdr_iodev	bi_shdrdev.bi_iodev
399 #define	bi_bmp_iodev	bi_bmpdev.bi_iodev
400 #define	bi_mst_tok	bi_mstdev->bi_tok
401 #define	bi_mstr_tok	bi_mstrdev->bi_tok
402 #define	bi_shd_tok	bi_shddev.bi_tok
403 #define	bi_shdr_tok	bi_shdrdev.bi_tok
404 #define	bi_bmp_tok	bi_bmpdev.bi_tok
405 #define	bi_mstref	bi_mstdev->bi_ref
406 #define	bi_mstrref	bi_mstrdev->bi_ref
407 #define	bi_shdref	bi_shddev.bi_ref
408 #define	bi_shdrref	bi_shdrdev.bi_ref
409 #define	bi_bmpref	bi_bmpdev.bi_ref
410 #define	bi_mstrsrv	bi_mstdev->bi_rsrv
411 #define	bi_mstrrsrv	bi_mstrdev->bi_rsrv
412 #define	bi_shdrsrv	bi_shddev.bi_rsrv
413 #define	bi_shdrrsrv	bi_shdrdev.bi_rsrv
414 #define	bi_bmprsrv	bi_bmpdev.bi_rsrv
415 #define	bi_mstrflag	bi_mstrdev->bi_flag
416 #define	bi_shdrflag	bi_shdrdev.bi_flag
417 /*
418  * Cluster and group linked lists
419  */
420 typedef struct _ii_lstinfo_s {
421 	_ii_info_t		*lst_ip;	/* ptr to info_t */
422 	struct _ii_lstinfo_s	*lst_next;	/* ptr to next in chain */
423 } _ii_lstinfo_t;
424 
425 typedef struct _ii_lsthead_s {
426 	uint64_t	lst_hash;		/* from nsc_strhash */
427 	char		lst_name[DSW_NAMELEN];	/* resource group */
428 	_ii_lstinfo_t	*lst_start;		/* start of set list */
429 	struct _ii_lsthead_s *lst_next;		/* next list head */
430 } _ii_lsthead_t;
431 
432 /*
433  * Flag set and clear macros and function.
434  */
435 
436 void _ii_flag_op(int and, int or, _ii_info_t *ip, int update);
437 
438 #define	II_FLAG_SET(f, ip)		_ii_flag_op(~0, (f), ip, TRUE)
439 #define	II_FLAG_CLR(f, ip)		_ii_flag_op(~(f), 0, ip, TRUE)
440 
441 #define	II_FLAG_SETX(f, ip)		_ii_flag_op(~0, (f), ip, FALSE)
442 #define	II_FLAG_CLRX(f, ip)		_ii_flag_op(~(f), 0, ip, FALSE)
443 #define	II_FLAG_ASSIGN(f, ip)		_ii_flag_op(0, (f), ip, FALSE);
444 #define	LOG_EVENT(msg, level)		\
445 		nsc_do_sysevent("ii", msg, level, level, component, ii_dip);
446 
447 /* Reserve and release macros */
448 
449 	/* also used by ii_volume() volume identification, hence NONE & OVR */
450 #define	NONE	0x0000			/* no volume type */
451 #define	MST	0x0001			/* master reserve/release flag */
452 #define	MSTR	0x0010			/* raw master reserve/release flag */
453 #define	SHD	0x0002			/* shadow reserve/release flag */
454 #define	SHDR	0x0020			/* raw shadow reserve/release flag */
455 #define	BMP	0x0100			/* bitmap reserve/release flag */
456 #define	OVR	0x0400			/* overflow volume */
457 
458 #define	RSRV(ip)	((ip)->bi_rsrv > 0 || (ip)->bi_orsrv > 0)
459 
460 #define	MSTRSRV(ip)	(RSRV(((ip)->bi_mstdev)))
461 #define	SHDRSRV(ip)	(RSRV(&((ip)->bi_shddev)))
462 
463 #define	MSTFD(ip)	(MSTRSRV(ip) ? (ip)->bi_mstfd : (ip)->bi_mstrfd)
464 #define	SHDFD(ip)	(SHDRSRV(ip) ? (ip)->bi_shdfd : (ip)->bi_shdrfd)
465 #define	OVRFD(ip)	(ip->bi_overflow->ii_dev->bi_fd)
466 
467 #define	II_RAW(ii)	(((ii)->ii_oflags&NSC_DEVICE) != 0)
468 #define	II_FD(ii)	((ii)->ii_shd ? SHDFD((ii)->ii_info) : \
469 					MSTFD((ii)->ii_info))
470 
471 			/* are there multiple shadows of ip's master volume? */
472 #define	NSHADOWS(ip)	((ip)->bi_head != (ip) || (ip)->bi_sibling)
473 
474 typedef	struct _ii_bmp_ops_s {
475 	int	(*co_bmp)(_ii_info_t *, nsc_off_t, unsigned char *, int);
476 	int	(*ci_bmp)(_ii_info_t *, nsc_off_t, unsigned char *, int);
477 	int	(*zerobm)(_ii_info_t *);
478 	int	(*copybm)(_ii_info_t *);
479 	int	(*orbm)(_ii_info_t *);
480 	int	(*tst_shd_bit)(_ii_info_t *, chunkid_t);
481 	int	(*set_shd_bit)(_ii_info_t *, chunkid_t);
482 	int	(*tst_copy_bit)(_ii_info_t *, chunkid_t);
483 	int	(*set_copy_bit)(_ii_info_t *, chunkid_t);
484 	int	(*clr_copy_bits)(_ii_info_t *, chunkid_t, int);
485 	chunkid_t	(*next_copy_bit)(_ii_info_t *, chunkid_t, chunkid_t,
486 						int, int *);
487 	int	(*fill_copy_bmp)(_ii_info_t *);
488 	int	(*load_bmp)(_ii_info_t *, int);
489 	int	(*save_bmp)(_ii_info_t *, int);
490 	int	(*change_bmp)(_ii_info_t *, unsigned char *);
491 	int	(*cnt_bits)(_ii_info_t *, nsc_off_t, nsc_size_t *, int);
492 	int	(*join_bmp)(_ii_info_t *, _ii_info_t *);
493 } _ii_bmp_ops_t;
494 
495 #define	II_CO_BMP(ip, a, b, c)	(*(ip)->bi_bitmap_ops->co_bmp)(ip, a, b, c)
496 #define	II_CI_BMP(ip, a, b, c)	(*(ip)->bi_bitmap_ops->ci_bmp)(ip, a, b, c)
497 #define	II_ZEROBM(ip)		(*(ip)->bi_bitmap_ops->zerobm)(ip)
498 #define	II_COPYBM(ip)		(*(ip)->bi_bitmap_ops->copybm)(ip)
499 #define	II_ORBM(ip)		(*(ip)->bi_bitmap_ops->orbm)(ip)
500 #define	II_TST_SHD_BIT(ip, c)	(*(ip)->bi_bitmap_ops->tst_shd_bit)(ip, c)
501 #define	II_SET_SHD_BIT(ip, c)	(*(ip)->bi_bitmap_ops->set_shd_bit)(ip, c)
502 #define	II_TST_COPY_BIT(ip, c)	(*(ip)->bi_bitmap_ops->tst_copy_bit)(ip, c)
503 #define	II_SET_COPY_BIT(ip, c)	(*(ip)->bi_bitmap_ops->set_copy_bit)(ip, c)
504 #define	II_CLR_COPY_BITS(ip, c, n)	(*(ip)->bi_bitmap_ops->clr_copy_bits) \
505 						(ip, c, n)
506 #define	II_CLR_COPY_BIT(ip, c)	(*(ip)->bi_bitmap_ops->clr_copy_bits)(ip, c, 1)
507 #define	II_NEXT_COPY_BIT(ip, c, m, w, g)	\
508 			(*(ip)->bi_bitmap_ops->next_copy_bit)(ip, c, m, w, g)
509 #define	II_FILL_COPY_BMP(ip)	(*(ip)->bi_bitmap_ops->fill_copy_bmp)(ip)
510 #define	II_LOAD_BMP(ip, f)	(*(ip)->bi_bitmap_ops->load_bmp)(ip, f)
511 #define	II_SAVE_BMP(ip, f)	(*(ip)->bi_bitmap_ops->save_bmp)(ip, f)
512 #define	II_CHANGE_BMP(ip, p)	(*(ip)->bi_bitmap_ops->change_bmp)(ip, p)
513 #define	II_CNT_BITS(ip, a, b, c) (*(ip)->bi_bitmap_ops->cnt_bits)(ip, a, b, c)
514 #define	II_JOIN_BMP(dip, sip) (*(ip)->bi_bitmap_ops->join_bmp)(dip, sip)
515 
516 /*
517  * State flags
518  */
519 #define	DSW_IOCTL	0x0001		/* Waiting for ioctl to complete */
520 #define	DSW_CLOSING	0x0002		/* Waiting for shadow to close */
521 #define	DSW_MSTTARGET	0x0004		/* Master is target of update */
522 #define	DSW_MULTIMST	0x0008		/* disabled set is multi master */
523 #define	DSW_CNTSHDBITS	0x0010		/* need to count # of shd bits set */
524 #define	DSW_CNTCPYBITS	0x0020		/* need to count # of copy bits set */
525 
526 /*
527  * DSW file descriptor structure
528  */
529 
530 typedef struct ii_fd_s {
531 	_ii_info_t	*ii_info;	/* Info structure */
532 	int		ii_bmp;		/* This fd is for the bmp device */
533 	int		ii_shd;		/* This fd is for the shadow device */
534 	int		ii_ovr;		/* This fd is for the overflow device */
535 	_ii_overflow_t	*ii_optr;	/* pointer to overflow structure */
536 	int		ii_oflags;	/* raw or cached open type */
537 } ii_fd_t;
538 
539 
540 /*
541  * II buffer header
542  */
543 
544 typedef struct ii_buf_s {
545 	nsc_buf_t	ii_bufh;	/* exported buffer header */
546 	nsc_buf_t	*ii_bufp;	/* main underlying buffer */
547 	nsc_buf_t	*ii_bufp2;	/* second underlying buffer */
548 	nsc_buf_t	*ii_abufp;	/* anonymous underlying buffer */
549 	ii_fd_t		*ii_fd;		/* back link */
550 	int		ii_rsrv;	/* fd to release in free_buf */
551 } ii_buf_t;
552 #endif	/* _KERNEL || _KMEMUSER */
553 
554 
555 /*
556  * Valid magic numbers in the bitmap volume header
557  */
558 
559 #define	DSW_DIRTY	0x44495254
560 #define	DSW_CLEAN	0x434C4541
561 #define	DSW_INVALID	0x00000000
562 
563 /*
564  * II_HEADER_VERSION
565  *	1 = original II header version
566  *	2 = Compact Dependent Shadows (DSW_TREEMAP)
567  *	3 = Persistance of throttle parameters
568  *	4 = add cluster & group information
569  *	5 = add time string to hold last modify time
570  */
571 #define	II_HEADER_VERSION	5
572 
573 /*
574  * DSW bitmap volume header structure
575  */
576 
577 typedef struct ii_header_s {
578 	int32_t	ii_magic;	/* magic number */
579 	int32_t	ii_type;	/* bitmap or independent copy */
580 	int32_t	ii_state;	/* State of the master/shadow/bitmap tuple */
581 	int32_t	ii_version;	/* version or format of bitmap volume */
582 	int32_t	ii_shdfba;	/* location of shadow bitmap */
583 	int32_t	ii_copyfba;	/* location of copy bitmap */
584 	char	master_vol[DSW_NAMELEN];
585 	char	shadow_vol[DSW_NAMELEN];
586 	char	bitmap_vol[DSW_NAMELEN];
587 	/* II_HEADER_VERSION 2 */
588 	char	overflow_vol[DSW_NAMELEN];
589 	int64_t	ii_mstchks;	/* # of chunks in master volume */
590 	int64_t	ii_shdchks;	/* # of chunks in shadow volume */
591 	int64_t	ii_shdchkused;	/* # of shd chunks allocated or on free list */
592 	int64_t	ii_shdfchk;	/* list of free shadow chunks */
593 	/* II_HEADER_VERSION 3 */
594 	int32_t	ii_throttle_unit;  /* Last setting of throttle unit */
595 	int32_t ii_throttle_delay; /* Last setting of throttle delay */
596 	/* II_HEADER_VERSION 4 */
597 	char	clstr_name[DSW_NAMELEN];
598 	char	group_name[DSW_NAMELEN];
599 	/* II_HEADER_VERSION 5 */
600 	time_t ii_mtime;
601 } ii_header_t;
602 
603 #define	II_SUCCESS(rc)	(((rc) == NSC_DONE) || ((rc) == NSC_HIT))
604 
605 /*
606  * Overflow volume defines.
607  */
608 
609 #define	II_OMAGIC		0x476F6C64		/* "Gold" */
610 #define	II_ISOVERFLOW(n)	((n) < 0 && (n) != II_NULLCHUNK)
611 #define	II_2OVERFLOW(n)		(-(n))
612 				/* -tive node id's are in overflow volume */
613 
614 #ifdef	_SunOS_5_6
615 #define	II_NULLNODE		(INT_MIN)
616 #define	II_NULLCHUNK		(INT_MIN)
617 #else
618 #ifdef II_MULTIMULTI_TERABYTE
619 #define	II_NULLNODE		(INT64_MIN)
620 #define	II_NULLCHUNK		(INT64_MIN)
621 #define	II_NULL32NODE		(INT32_MIN)
622 #define	II_NULL32CHUNK		(INT32_MIN)
623 #else
624 #define	II_NULLNODE		(INT32_MIN)
625 #define	II_NULLCHUNK		(INT32_MIN)
626 #endif /* II_MULTIMULTI_TERABYTE */
627 #endif
628 
629 #ifdef __cplusplus
630 }
631 #endif
632 
633 #endif	/* _DSW_DEV_H */
634