xref: /titanic_41/usr/src/uts/common/sys/lvm/mdio.h (revision bf85a12b7c81d0745d5a8aff65baeff50006cde9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS__MDIO_H
28 #define	_SYS__MDIO_H
29 
30 #include <sys/debug.h>
31 #include <sys/ioctl.h>
32 #include <sys/types.h>
33 #include <sys/int_types.h>
34 #include <sys/dditypes.h>
35 #ifdef _KERNEL
36 #include <sys/lvm/md_mdiox.h>
37 #else /* !_KERNEL */
38 #include <mdiox.h>
39 #endif
40 #include <sys/ddipropdefs.h>
41 #include <sys/hwconf.h>
42 
43 #ifdef	__cplusplus
44 extern "C" {
45 #endif
46 
47 /*
48  * driver version number
49  */
50 #define	MD_DVERSION	0x00040003	/* major.minor */
51 #define	MD_SET_SHIFT	(NBITSMINOR32 - MD_BITSSET)
52 #define	MD_MAXUNITS	(1 << MD_SET_SHIFT)
53 #define	MD_UNIT_MASK	(MD_MAXUNITS - 1)
54 
55 #define	MD_MIN2UNIT(m)	((m) & MD_UNIT_MASK)
56 #define	MD_MIN2SET(m)	((m) >> MD_SET_SHIFT)
57 #define	MD_SID(u)	((u)->c.un_self_id)
58 #define	MD_RECID(u)	((u)->c.un_record_id)
59 #define	MD_STATUS(u)	((u)->c.un_status)
60 #define	MD_PARENT(u)	((u)->c.un_parent)
61 #define	MD_CAPAB(u)	((u)->c.un_capabilities)
62 #define	MD_UN2SET(u)	MD_MIN2SET(MD_SID(u))
63 #define	MD_UL2SET(l)	MD_MIN2SET(MAXMIN32 & ((l)->un_dev))
64 
65 #define	MD_MKMIN(s, u)	((((s) & MD_SETMASK) << MD_SET_SHIFT) | \
66 			((u) & MD_UNIT_MASK))
67 
68 #define	HSP_BITSID	31
69 #define	HSP_SET_SHIFT	(HSP_BITSID - MD_BITSSET)
70 #define	HSP_SET_MASK	(MD_SETMASK << HSP_SET_SHIFT)
71 #define	HSP_SET(hspid)	(((hspid) & HSP_SET_MASK) >> HSP_SET_SHIFT)
72 #define	HSP_ID(hspid)	((hspid) & ~HSP_SET_MASK)
73 #define	MAKE_HSP_ID(setno, id)  (((setno) << HSP_SET_SHIFT) | (id))
74 
75 /*
76  * The following macros were added to support friendly names for hot spare
77  * pools.  Before the addition of friendly names the hsp_self_id was merely
78  * the conbination of the set number and the hot spare pool number.  With
79  * friendly names a NM record is created to hold the hot spare pool name.
80  * The hsp_self_id now becomes the set number shifted left plus the NM
81  * record key plus 1000.  The number 1000 is used to collision between
82  * traditional hsp_self_ids and friendly name self ids.  In traditional hot
83  * spare pool the hot spare pool number could never be grater than 999.
84  *
85  * HSP_ID_IS_FN(hspid)	returns TRUE if the hot spare pool ID is the ID of
86  * 			a friendly named hsp.  Will return FALSE otherwise.
87  * 			hspid may contain the set bits, since HSP_ID_IS_FN
88  * 			will call HSP_ID as part of doing its work.
89  *
90  * KEY_TO_HSP_ID(setno, reckey)	constructs a hot spare pool ID (hsp_t) from
91  * 			a set number and a NM record key.  The result is
92  * 			suitable for storing in the hsp_self_id member of a
93  * 			hot_spare_pool struct.
94  *
95  * HSP_ID_TO_KEY(hspid)	returns the NM key that is encoded in the hot spare
96  * 			pool ID.  MD_KEYBAD will be returned if hspid does
97  * 			not represent a friendly named hsp.  hspid may
98  * 			contain the set bits, since HSP_ID_TO_KEY will call
99  * 			HSP_ID as part of doing its work.
100  *
101  * HSP_KEY_OK(reckey)	Insures that the NM record key is not so large as
102  * 			to interfere with the set number bits in a hot
103  * 			spare pool self id.  This macro will probably only
104  * 			be used in meta_hs_add.
105  */
106 #define	HSP_FN_BASE	(1000)
107 #define	HSP_ID_IS_FN(hspid) (HSP_ID(hspid) > HSP_FN_BASE)
108 #define	KEY_TO_HSP_ID(setno, key) ((setno << HSP_SET_SHIFT) | \
109 					(key + HSP_FN_BASE))
110 #define	HSP_ID_TO_KEY(hspid) ((HSP_ID_IS_FN(hspid)) ? \
111 				(HSP_ID(hspid) - HSP_FN_BASE) : MD_KEYBAD)
112 #define	HSP_KEY_OK(key)	(((key + HSP_FN_BASE) & HSP_SET_MASK) == 0)
113 
114 /*
115  * for did stat ioctl
116  */
117 #define	MD_FIND_INVDID	0x01
118 #define	MD_GET_INVDID	0x02
119 
120 /*
121  * for setting the un_revision, hsp_revision and hs_revision
122  */
123 #define	MD_64BIT_META_DEV	0x01
124 #define	MD_FN_META_DEV		0x02	/* Friendly named metadevice */
125 
126 /*
127  * for trans EOF error messages
128  */
129 #define	MD_EOF_TRANS_MSG	"Trans logging has been replaced by UFS" \
130 	" Logging.\nSee mount_ufs(1M). Operation failed.\n"
131 
132 #define	MD_SHORT_EOF_TRANS_MSG	"#Trans logging has been replaced by UFS" \
133 	" Logging.\n#See mount_ufs(1M). Operation failed.\n"
134 
135 #define	MD_EOF_TRANS_WARNING	"Existing Trans devices are not logging; they" \
136 	"\npass data directly to the underlying device.\n"
137 
138 #define	MD_SHORT_EOF_TRANS_WARNING	"#Existing Trans devices are not " \
139 	"logging; they\n#pass data directly to the underlying device.\n"
140 
141 /*
142  * for importing of disksets (IMP_LOAD)
143  */
144 #define	MD_IMP_STALE_SET	1
145 
146 /*
147  * miscname stuff
148  */
149 
150 #define	MD_DRIVERNAMELEN	16
151 #define	MD_SETDRIVERNAME(to, from, setno) \
152 	if ((from) != NULL) \
153 		(void) strcpy((to)->md_driver.md_drivername, (from)); \
154 	(to)->md_driver.md_setno = (setno);
155 
156 
157 #define	MD_GETDRIVERNAME(to, from) \
158 	(void) strcpy((to), (from)->md_driver.md_drivername);
159 
160 #define	MD_PNTDRIVERNAME(from) \
161 	((from)->md_driver.md_drivername)
162 
163 /*
164  * ioctl parameter structures
165  */
166 
167 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
168 #pragma pack(4)
169 #endif
170 typedef struct md_i_driverinfo {
171 	MD_DRIVER
172 	md_error_t	mde;
173 	minor_t		mnum;
174 } md_i_driverinfo_t;
175 
176 typedef struct md_i_getnext {
177 	MD_DRIVER
178 	md_error_t	mde;
179 	minor_or_hsp_t	id;
180 } md_i_getnext_t;
181 
182 typedef struct md_i_getnum {
183 	MD_DRIVER
184 	md_error_t	mde;
185 	int		start;
186 	int		size;
187 	uint64_t	minors;	/* Pointer to minor #'s */
188 } md_i_getnum_t;
189 
190 typedef struct md_i_get {
191 	MD_DRIVER
192 	md_error_t	mde;
193 	minor_or_hsp_t	id;
194 	int		size;
195 	uint64_t	mdp;	/* Contains pointer */
196 } md_i_get_t;
197 
198 typedef struct md_i_reset {
199 	MD_DRIVER
200 	md_error_t	mde;
201 	minor_t		mnum;		/* Unit to clear */
202 	int		force;
203 } md_i_reset_t;
204 
205 /* soft partition reset parameters */
206 typedef struct md_sp_reset {
207 	MD_DRIVER
208 	md_error_t	mde;		/* Error return */
209 	minor_t		mnum;		/* Unit to clear */
210 	int		force;		/* Force reset */
211 	md_parent_t	new_parent;	/* New parent for child component */
212 } md_sp_reset_t;
213 
214 /* soft partition status change parameters */
215 typedef struct md_sp_statusset {
216 	MD_DRIVER
217 	md_error_t	mde;		/* Error return */
218 	int		num_units;	/* Number of units */
219 	int		new_status;	/* New status */
220 	int		size;		/* Array size */
221 	uint64_t	minors;		/* Pointer to array of minor numbers */
222 } md_sp_statusset_t;
223 
224 typedef struct md_sp_update_wm {
225 	MD_DRIVER
226 	md_error_t	mde;		/* Error return */
227 	minor_t		mnum;		/* Unit to update */
228 	uint_t		count;		/* Number of watermarks */
229 	uint64_t	wmp;		/* Pointer to array of watermarks */
230 	uint64_t	osp;		/* Pointer to array of offsets */
231 } md_sp_update_wm_t;
232 
233 typedef struct md_sp_read_wm {
234 	MD_DRIVER
235 	md_error_t	mde;		/* Error return */
236 	md_dev64_t	rdev;		/* Device from which to read */
237 	uint64_t	wmp;		/* Pointer to wm buffer */
238 	xsp_offset_t	offset;		/* Offset of wm */
239 } md_sp_read_wm_t;
240 
241 typedef struct md_set_userflags {
242 	MD_DRIVER
243 	md_error_t	mde;
244 	minor_t		mnum;
245 	uint_t		userflags;
246 } md_set_userflags_t;
247 
248 typedef struct md_stripe_params {
249 	MD_DRIVER
250 	md_error_t	mde;		/* Error return */
251 	minor_t		mnum;
252 	ms_params_t	params;
253 } md_stripe_params_t;
254 
255 typedef struct md_raid_params {
256 	MD_DRIVER
257 	md_error_t	mde;		/* Error return */
258 	minor_t		mnum;
259 	mr_params_t	params;
260 } md_raid_params_t;
261 
262 typedef struct md_mirror_params {
263 	MD_DRIVER
264 	md_error_t	mde;		/* Error return */
265 	minor_t		mnum;
266 	mm_params_t	params;
267 } md_mirror_params_t;
268 
269 typedef struct md_grow_params {
270 	MD_DRIVER
271 	md_error_t	mde;	/* Error return */
272 	minor_t		mnum;	/* Unit to grow */
273 	int		options; /* create a 64 or 32 bit device */
274 	uint64_t	mdp;	/* Optional - pointer to new unit struct */
275 	int		size;	/* Optional - size of new unit struct */
276 	int		nrows;	/* Optional - original number of rows */
277 	int		npar;	/* Optional - number of parents to lock */
278 	uint64_t	par;	/* Optional - pointer to parent units */
279 } md_grow_params_t;
280 
281 /* if the didstat struct changes you will need to change the following macro */
282 typedef struct md_i_didstat {
283 	md_error_t	mde;	/* Error return */
284 	set_t		setno;	/* which set to use */
285 	side_t		side;	/* which side to use */
286 	int		mode;	/* find or get ? */
287 	int		cnt;	/* return number of invalid devid's found */
288 	int		maxsz;	/* return max size of invalid device id */
289 	uint64_t	ctdp;	/* pointer to structure to fill with ctds */
290 } md_i_didstat_t;
291 
292 typedef struct mdnm_params {
293 	md_error_t	mde;		/* Error return */
294 	char		drvnm[MD_MAXDRVNM];  /* drvnm for get/set/rem nm */
295 	major_t		major;		/* major #, (alternative) for get nm */
296 	minor_t		mnum;		/* minor #, for get/set/rem nm */
297 	uint_t		devname_len;	/* Length of device name, for set nm */
298 	uint64_t	devname;	/* Address of device name for set/get */
299 	set_t		setno;		/* Which namespace set to use */
300 	side_t		side;		/* -1 == current side, >0 specified */
301 	mdkey_t		key;		/* 0 == alloc one, else use this key */
302 	mdkey_t		retkey;		/* return key here! */
303 	ushort_t	devid_size;	/* 0 == ret size, else use this one */
304 	uint64_t	devid;		/* pointer to devid, supplied by user */
305 	uint_t		pathname_len;	/* length of pathname */
306 	uint64_t	pathname;	/* address of pathname for update */
307 	md_dev64_t	devt;		/* devt for updating namespace */
308 	ushort_t	minorname_len;	/* length of minor name */
309 	uint64_t	minorname;	/* address of minor name */
310 	uint_t		ref_count;	/* returned n_count */
311 	int		imp_flag;	/* used by metaimport */
312 } mdnm_params_t;
313 
314 typedef struct mdhspnm_params {
315 	md_error_t	mde;		/* Error return */
316 	char		drvnm[MD_MAXDRVNM];  /* drvnm for get/set/rem nm */
317 	uint_t		hspname_len;	/* Length of device name, for set nm */
318 	uint64_t	hspname;	/* Address of device name for set/get */
319 	set_t		setno;		/* Which namespace set to use */
320 	side_t		side;		/* -1 == current side, >0 specified */
321 	hsp_t		hspid;		/* 0 == alloc one, else use this key */
322 	hsp_t		ret_hspid;	/* return key here! */
323 	uint_t		ref_count;	/* returned n_count */
324 } mdhspnm_params_t;
325 
326 typedef struct md_getdevs_params {
327 	MD_DRIVER
328 	md_error_t	mde;
329 	minor_t		mnum;
330 	int		cnt;
331 	uint64_t	devs;	/* Pointer to devs */
332 } md_getdevs_params_t;
333 
334 
335 typedef struct md_i_get_tstate {
336 	minor_or_hsp_t	id;
337 	uint_t		tstate;		/* Transient state */
338 	md_error_t	mde;
339 } md_i_get_tstate_t;
340 
341 typedef struct md_set_state_params {
342 	MD_DRIVER
343 	md_error_t	mde;
344 	minor_t		mnum;
345 	uint_t		sm;
346 	uint_t		comp;
347 	uint_t		state;
348 	mddb_recid_t	hs_id;
349 } md_set_state_params_t;
350 
351 typedef struct md_alloc_hotsp_params {
352 	MD_DRIVER
353 	md_error_t	mde;
354 	minor_t		mnum;
355 	uint_t		sm;
356 	uint_t		comp;
357 	mddb_recid_t	hs_id;
358 } md_alloc_hotsp_params_t;
359 
360 typedef struct md_suspend_wr_params {
361 	MD_DRIVER
362 	md_error_t	mde;
363 	minor_t		mnum;
364 } md_suspend_wr_params_t;
365 
366 typedef struct md_mn_req_owner {
367 	minor_t		mnum;		/* Mirror metadevice */
368 	uint_t		flags;		/* Flags (see below) */
369 	md_mn_nodeid_t	owner;		/* New owner of Mirror  */
370 } md_mn_req_owner_t;
371 
372 #define	MD_MN_MM_PREVENT_CHANGE	0x0001	/* Disallow further ownership change */
373 #define	MD_MN_MM_ALLOW_CHANGE	0x0002	/* Allow ownership change */
374 #define	MD_MN_MM_SPAWN_THREAD	0x0004
375 #define	MD_MN_MM_CHOOSE_OWNER	0x0008	/* Choose a resync owner */
376 
377 #define	MD_MN_MM_RESULT		0x80000000	/* Result contained in LSB */
378 #define	MD_MN_MM_RESULT_MASK	0xFFFF		/* Mask for result code	   */
379 #define	MD_MN_MM_RES_OK		0		/* Success */
380 #define	MD_MN_MM_RES_FAIL	1		/* Failure */
381 
382 typedef struct md_set_mmown_params {
383 	MD_DRIVER
384 	md_error_t		mde;
385 	md_mn_req_owner_t	d;	/* New owner */
386 } md_set_mmown_params_t;
387 
388 typedef struct md_mn_own_status {
389 	MD_DRIVER
390 	md_error_t		mde;
391 	minor_t			mnum;
392 	uint_t			flags;	/* See above *_MM_RESULT flags */
393 } md_mn_own_status_t;
394 
395 typedef struct md_mn_poke_hotspares {
396 	MD_DRIVER
397 	md_error_t		mde;
398 } md_mn_poke_hotspares_t;
399 
400 typedef struct md_mn_rs_params {
401 	MD_DRIVER
402 	md_error_t	mde;
403 	int		msg_type;	/* Type of message */
404 	minor_t		mnum;		/* Mirror metadevice */
405 	uint_t		rs_type;	/* Type of resync */
406 	diskaddr_t	rs_start;	/* 1st block of resync range */
407 	diskaddr_t	rs_size;	/* size of resync range */
408 	diskaddr_t	rs_done;	/* amount of resync done so far */
409 	diskaddr_t	rs_2_do;	/* amount still to be done */
410 	md_mn_nodeid_t	rs_originator;	/* Originator of resync message */
411 	char		rs_flags;	/* flags */
412 	char		rs_first_time;	/* set if first resync-next message */
413 	sm_state_t	rs_sm_state[NMIRROR];	/* Submirror state */
414 	sm_flags_t	rs_sm_flags[NMIRROR];	/* Submirror flags */
415 } md_mn_rs_params_t;
416 
417 /* flag values for rs_flags */
418 #define	MD_MN_RS_ERR			0x01 /* Resync err */
419 #define	MD_MN_RS_CLEAR_OPT_NOT_DONE	0x02 /* Optimized resync done */
420 #define	MD_MN_RS_FIRST_RESYNC_NEXT	0x04 /* First RESYNC_NEXT message */
421 
422 typedef struct md_mn_setcap_params {
423 	MD_DRIVER
424 	md_error_t	mde;
425 	minor_t		mnum;
426 	uint_t		sc_set;		/* Capability settings */
427 } md_mn_setcap_params_t;
428 
429 typedef struct md_mkdev_params {
430 	MD_DRIVER
431 	md_error_t	mde;		/* Error return */
432 	unit_t		un;
433 } md_mkdev_params_t;
434 
435 #define	MDMN_RR_CLEAN_PARAMS_DATA(x)	((unsigned char *)(x) + \
436 	    sizeof (md_mn_rr_clean_params_t))
437 #define	MDMN_RR_CLEAN_PARAMS_SIZE(x)	(sizeof (md_mn_rr_clean_params_t) + \
438 	    MDMN_RR_CLEAN_PARAMS_DATA_BYTES(x))
439 #define	MDMN_RR_CLEAN_PARAMS_START_BIT(x)	((x)->rr_start_size >> 16)
440 #define	MDMN_RR_CLEAN_PARAMS_DATA_BYTES(x)	((x)->rr_start_size & 0xffff)
441 
442 typedef struct md_mn_rr_clean_params {
443 	MD_DRIVER
444 	md_error_t	mde;
445 	md_mn_nodeid_t	rr_nodeid;
446 	minor_t		rr_mnum;
447 	unsigned int	rr_start_size;	/* start_bit (16b) | data_bytes (16b) */
448 	/* actual data goes here */
449 } md_mn_rr_clean_params_t;
450 
451 typedef struct md_mn_rr_dirty_params {
452 	MD_DRIVER
453 	md_error_t	mde;
454 	minor_t		rr_mnum;
455 	md_mn_nodeid_t	rr_nodeid;
456 	ushort_t	rr_start;	/* First RR region to mark */
457 	ushort_t	rr_end;		/* Last RR region to mark */
458 } md_mn_rr_dirty_params_t;
459 
460 /*
461  * Flags to coordinate sending device id between kernel and user space.
462  * To get devid from kernel:
463  *   User calls ioctl with l_devid_flags set to GETSZ flag to get size of
464  *   devid which is returned in the l_devid_sz field if the SZ flag is set.
465  *   Then user allocs that size and sends same ioctl with SPACE flag set
466  *   and l_devid_sz set to alloc'd size.  Kernel either sets the NOSPACE
467  *   flag (if alloc'd space is not big enough) or sets the VALID flag and
468  *   fills in the devid.
469  *
470  * To send devid to kernel:
471  *   User alloc's space for devid, fills in devid, sets (SPACE|VALID|SZ) flags
472  *   and sets size of devid into l_devid_sz field.
473  *
474  * If MDDB_DEVID_SPACE is set, MDDB_DEVID_GETSZ is ignored.
475  * If no flags are set, devid information is ignored.
476  */
477 #define	MDDB_DEVID_SPACE	0x0001	/* l_devid_sz bytes of space alloc'd */
478 #define	MDDB_DEVID_VALID	0x0002	/* kernel has filled in devid */
479 #define	MDDB_DEVID_NOSPACE	0x0004	/* not enough alloc'd space for devid */
480 #define	MDDB_DEVID_GETSZ	0x0008	/* fill in l_devid_sz with devid size */
481 #define	MDDB_DEVID_SZ		0x0010	/* l_devid_sz filled in with devid sz */
482 
483 
484 
485 /*
486  * Maximum number of replicas (or number of locator blocks) in set.
487  */
488 #define	MDDB_NLB		50
489 
490 /*
491  * maximum size of allowable bootlist property string - only used to
492  * read in and write out boolist property strings to conf files.
493  */
494 #define	MDDB_BOOTLIST_MAX_LEN	MAX_HWC_LINESIZE
495 
496 /*
497  * Percentage of free space left in replica during conversion of non-devid
498  * style replica to devid style replica.
499  */
500 #define	MDDB_DEVID_CONV_PERC	5
501 
502 typedef struct mddb_cfg_loc {
503 	dev32_t		l_dev;
504 	daddr32_t	l_blkno;
505 	int		l_flags;
506 	char		l_driver[MD_MAXDRVNM];
507 	minor_t		l_mnum;
508 	int		l_devid_flags;
509 	uint64_t	l_devid;	/* pointer to devid */
510 	int		l_devid_sz;
511 	uint64_t	l_old_devid;
512 	int		l_old_devid_sz;
513 	char		l_minor_name[MDDB_MINOR_NAME_MAX];
514 	char		l_devname[MAXPATHLEN];	/* device name */
515 } mddb_cfg_loc_t;
516 
517 typedef struct mddb_dtag {
518 	md_timeval32_t	dt_tv;
519 	int		dt_id;
520 	set_t		dt_setno;
521 	char		dt_sn[MDDB_SN_LEN];
522 	char		dt_hn[MD_MAX_NODENAME_PLUS_1];
523 } mddb_dtag_t;
524 
525 typedef struct mddb_dtag_lst {
526 	struct mddb_dtag_lst	*dtl_nx;
527 	mddb_dtag_t		dtl_dt;
528 } mddb_dtag_lst_t;
529 
530 typedef struct mddb_dtag_get_parm {
531 	set_t		dtgp_setno;
532 	mddb_dtag_t	dtgp_dt;
533 	md_error_t	dtgp_mde;
534 } mddb_dtag_get_parm_t;
535 
536 typedef struct mddb_dtag_use_parm {
537 	int		dtup_id;
538 	set_t		dtup_setno;
539 	md_error_t	dtup_mde;
540 } mddb_dtag_use_parm_t;
541 
542 typedef struct mddb_accept_parm {
543 	set_t		accp_setno;
544 	md_error_t	accp_mde;
545 } mddb_accept_parm_t;
546 
547 typedef struct mddb_med_parm {
548 	set_t		med_setno;
549 	md_hi_arr_t	med;
550 	md_error_t	med_mde;		/* error return */
551 } mddb_med_parm_t;
552 
553 typedef struct mddb_med_upd_parm {
554 	set_t		med_setno;
555 	md_error_t	med_mde;		/* error return */
556 } mddb_med_upd_parm_t;
557 
558 #define	MED_TE_NM_LEN	64
559 
560 typedef struct mddb_med_t_ent {
561 	char		med_te_nm[MED_TE_NM_LEN];
562 	md_dev64_t	med_te_dev;		/* fixed size dev_t */
563 } mddb_med_t_ent_t;
564 
565 typedef struct mddb_med_t_parm {
566 	md_error_t		med_tp_mde;		/* error return */
567 	int			med_tp_nents;		/* number of entries */
568 	int			med_tp_setup;		/* setup flag */
569 	mddb_med_t_ent_t	med_tp_ents[1];		/* Var. sized array */
570 } mddb_med_t_parm_t;
571 
572 #define	MDDB_SETMASTER_MAGIC	0x53544d41	/* Ascii for STMA */
573 typedef struct mddb_setmaster_config {
574 	md_error_t	c_mde;
575 	set_t		c_setno;
576 	int		c_magic;		/* used to verify ioctl */
577 	int		c_current_host_master;
578 } mddb_setmaster_config_t;
579 
580 /*
581  * Structure used to set/reset/get flags in set structure.
582  */
583 #define	MDDB_SETFLAGS_MAGIC	0x5354464c	/* ascii for STFL */
584 typedef struct mddb_setflags_config {
585 	md_error_t	sf_mde;
586 	set_t		sf_setno;
587 	int		sf_magic;	/* used to verify ioctl */
588 	int		sf_flags;	/* Control flags set/reset/get */
589 	int		sf_setflags;	/* Flag values */
590 } mddb_setflags_config_t;
591 
592 typedef struct mddb_set_node_params {
593 	md_error_t	sn_mde;
594 	set_t		sn_setno;
595 	md_mn_nodeid_t	sn_nodeid;
596 } mddb_set_node_params_t;
597 
598 typedef struct mddb_block_parm {
599 	md_error_t	c_mde;
600 	set_t		c_setno;
601 	int		c_blk_flags;
602 } mddb_block_parm_t;
603 
604 typedef struct mddb_parse_parm {
605 	md_error_t	c_mde;
606 	set_t		c_setno;
607 	int		c_parse_flags;
608 	int		c_lb_flags[MDDB_NLB];
609 } mddb_parse_parm_t;
610 
611 typedef struct mddb_optrec_parm {
612 	md_error_t		c_mde;
613 	set_t			c_setno;
614 	md_replica_recerr_t	c_recerr[2];
615 } mddb_optrec_parm_t;
616 
617 typedef struct mddb_config {
618 	md_error_t	c_mde;			/* error return */
619 	int		c_id;			/* used with getnext locator */
620 	md_splitname	c_devname;		/* contains name or keys */
621 	int		c_dbcnt;		/* number of dbs */
622 	int		c_dbmax;		/* maximum number of dbs */
623 	int		c_flags;
624 	int		c_dbend;		/* size of database */
625 	set_t		c_setno;		/* set number of replica */
626 	int		c_multi_node;		/* set if multi_node set */
627 	side_t		c_sideno;		/* side number of replica */
628 	md_timeval32_t	c_timestamp;		/* creation of set */
629 						/* setname */
630 	char		c_setname[MD_MAX_SETNAME_PLUS_1];
631 	md_hi_arr_t	c_med;			/* Mediator host information */
632 	int		c_spare[14];		/* unused must be zero */
633 	md_dev64_t	c_devt;			/* devt to get/set */
634 	mddb_cfg_loc_t	c_locator;		/* device specific info */
635 } mddb_config_t;
636 
637 #define	c_subcmd	c_spare[0]
638 /*
639  * Subcommands.
640  */
641 #define	MDDB_CONFIG_ABS	1		/* treat c_id as abs index */
642 
643 typedef	struct mddb_optloc {
644 	int	recid;	/* really mddb_recid_t */
645 	int	li[2];
646 } mddb_optloc_t;
647 
648 typedef struct md_gs_stat_parm {
649 	set_t		gs_setno;
650 	uint_t		gs_status;
651 	md_error_t	gs_mde;
652 } md_gs_stat_parm_t;
653 
654 typedef struct {
655 	int	setno;
656 	int	owns_set;
657 } mddb_ownset_t;
658 
659 typedef enum md_rename_operation_t {
660 	MDRNOP_UNK = 0, MDRNOP_RENAME, MDRNOP_EXCHANGE
661 } md_renop_t;
662 
663 typedef struct md_rename {
664 	md_error_t	mde;
665 	md_renop_t	op;
666 	int		revision;
667 	uint_t		flags;
668 	struct {
669 		minor_t	mnum;
670 		key_t	key;
671 	} from, to;
672 } md_rename_t;
673 
674 typedef struct md_regen_param {
675 	MD_DRIVER
676 	md_error_t	mde;
677 	minor_t		mnum;   /* Unit to regenerate parity for */
678 } md_regen_param_t;
679 
680 /* Base ioctl's defined here */
681 #define	MDIOC		('V' << 8)
682 #define	ISMDIOC(c)	(((c) >> 8) == 'V')
683 
684 #define	MD_IOCSET	(MDIOC|0)	/* set config    (metainit) */
685 #define	MD_IOCRESET	(MDIOC|1)	/* reset config  (metaclear) */
686 #define	MD_IOCGET	(MDIOC|2)	/* get config    (metastat) */
687 #define	MD_IOCGROW	(MDIOC|3)	/* grow config   (dyn concat) */
688 #define	MD_IOCCHANGE	(MDIOC|4)	/* change config (metaparam) */
689 #define	MD_IOCSET_NM	(MDIOC|5)	/* set device name */
690 #define	MD_IOCGET_NM	(MDIOC|6)	/* get device name */
691 #define	MD_IOCREM_NM	(MDIOC|7)	/* remove device name */
692 #define	MD_IOCGET_DRVNM	(MDIOC|8)	/* get driver name */
693 #define	MD_IOCGET_NEXT	(MDIOC|9)	/* get next unit id */
694 #define	MD_IOCGET_DEVS	(MDIOC|10)	/* get device list */
695 #define	MD_DB_NEWDEV	(MDIOC|11)	/* add a db replica */
696 #define	MD_DB_USEDEV	(MDIOC|12)	/* patch in a db location */
697 #define	MD_DB_GETDEV	(MDIOC|13)	/* get a db replica */
698 #define	MD_DB_DELDEV	(MDIOC|14)	/* remove a db replica */
699 #define	MD_DB_ENDDEV	(MDIOC|15)	/* get db replica and size */
700 #define	MD_DB_GETDRVNM	(MDIOC|16)	/* get db replica driver name */
701 #define	MD_HALT		(MDIOC|17)	/* halt driver   (metahalt) */
702 #define	MD_GRAB_SET	(MDIOC|18)
703 #define	MD_RELEASE_SET	(MDIOC|20)	/* release a set */
704 #define	MD_IOCSETSYNC	(MDIOC|21)
705 #define	MD_IOCGETSYNC	(MDIOC|22)
706 #define	MD_IOCOFFLINE	(MDIOC|23)
707 #define	MD_IOCONLINE	(MDIOC|24)
708 #define	MD_IOCATTACH	(MDIOC|25)
709 #define	MD_IOCDETACH	(MDIOC|26)
710 #define	MD_IOCREPLACE	(MDIOC|27)
711 #define	MD_DB_USERREQ	(MDIOC|28)
712 #define	MD_DB_GETOPTLOC	(MDIOC|29)	/* get locators for opt resync rec. */
713 #define	MD_DB_OWNSET	(MDIOC|30)	/* Does caller own the set */
714 #define	MD_IOCGETNSET	(MDIOC|31)	/* Get the config'd number sets */
715 #define	MD_IOCNXTKEY_NM	(MDIOC|32)	/* get next key from namespace */
716 #define	MD_DB_NEWSIDE	(MDIOC|33)	/* add another side to the db replica */
717 #define	MD_DB_DELSIDE	(MDIOC|34)	/* delete a side from the db replica */
718 #define	MD_IOCGVERSION	(MDIOC|35)	/* get the driver version */
719 #define	MD_IOCSET_FLAGS	(MDIOC|36)	/* set the userflags of a metadevice */
720 #define	MD_IOCGETNUNITS	(MDIOC|37)	/* Get the config'd number units */
721 #define	MD_IOCNOTIFY	(MDIOC|38)	/* notification */
722 #define	MD_IOCRENAME	(MDIOC|39)	/* (Ex)Change/Rename unit identities */
723 #define	MD_IOCISOPEN	(MDIOC|40)	/* Is metadevice open? */
724 #define	MD_IOCSETREGEN	(MDIOC|41)	/* regen ioctl for raid */
725 #define	MD_MED_GET_LST	(MDIOC|42)	/* Get the mediator list */
726 #define	MD_MED_SET_LST	(MDIOC|43)	/* Set the mediator list */
727 #define	MD_MED_UPD_MED	(MDIOC|44)	/* Have the kernel push mediator data */
728 #define	MD_MED_GET_NMED	(MDIOC|45)	/* Get the max number of mediators */
729 #define	MD_MED_GET_TLEN	(MDIOC|46)	/* Get the mediator transport tbl len */
730 #define	MD_MED_GET_T	(MDIOC|47)	/* Get the mediator transport tbl */
731 #define	MD_MED_SET_T	(MDIOC|48)	/* Set the mediator transport tbl */
732 #define	MD_MED_GET_TAG	(MDIOC|49)	/* Get the list of data tags */
733 #define	MD_MED_USE_TAG	(MDIOC|50)	/* Use one of the data tags */
734 #define	MD_MED_ACCEPT	(MDIOC|51)	/* Accept 1/2 n 1/2 */
735 #define	MD_GET_SETSTAT	(MDIOC|52)	/* Get the s_status for a set */
736 #define	MD_SET_SETSTAT	(MDIOC|53)	/* Set the s_status for a set */
737 #define	MD_IOCPROBE_DEV (MDIOC|54)	/* Force pseudo opens for metadevices */
738 #define	MD_IOCGET_DID	(MDIOC|55)	/* Get device id */
739 #define	MD_IOCUPD_NM	(MDIOC|56)	/* Update namespace */
740 #define	MD_DB_SETDID	(MDIOC|57)	/* Set device id for a locator block */
741 #define	MD_IOCUPD_LOCNM	(MDIOC|58)	/* update locator namespace */
742 #define	MD_SETNMDID	(MDIOC|59)	/* update namespace devid */
743 #define	MD_IOCDID_STAT	(MDIOC|60)	/* get invalid device id's */
744 #define	MD_UPGRADE_STAT	(MDIOC|61)	/* get upgrade status information */
745 #define	MD_IOCGET_NUM	(MDIOC|62)	/* get number of devs and devs */
746 #define	MD_IOCGET_TSTATE (MDIOC|63)	/* get ui_tstate for metastat */
747 #define	MD_SETMASTER	(MDIOC|64)
748 #define	MD_MN_SET_DOORH		(MDIOC|65) /* MN: set the doorhandle */
749 #define	MD_MN_OPEN_TEST		(MDIOC|66) /* MN: check / (un)lock a md */
750 #define	MD_MN_SET_MM_OWNER	(MDIOC|67) /* Set mirror owner */
751 #define	MD_MN_SET_NODEID	(MDIOC|68) /* Set this node's id */
752 #define	MD_MN_SET_STATE		(MDIOC|69) /* Set mirror state */
753 #define	MD_MN_SUSPEND_WRITES	(MDIOC|70) /* Blocks writes */
754 #define	MD_MN_GET_MM_OWNER	(MDIOC|71) /* Get mirror owner */
755 #define	MD_IOCGUNIQMSGID	(MDIOC|72) /* create a unique message ID */
756 #define	MD_MN_MM_OWNER_STATUS 	(MDIOC|73) /* Return status of SET_MM_OWNER */
757 #define	MD_MN_ALLOCATE_HOTSPARE (MDIOC|74) /* Allocate hotspare */
758 #define	MD_MN_SUBMIRROR_STATE 	(MDIOC|75) /* Submirror state change */
759 #define	MD_MN_RESYNC		(MDIOC|76) /* Resync ioctl */
760 #define	MD_MN_SUSPEND_SET	(MDIOC|77) /* suspend IO's for a MN diskset */
761 #define	MD_MN_RESUME_SET	(MDIOC|78) /* resume IO's for a MN diskset */
762 #define	MD_MN_MDDB_PARSE	(MDIOC|79) /* Re-parse portion of MNset mddb */
763 #define	MD_MN_MDDB_BLOCK	(MDIOC|80) /* Block parse or record changes */
764 #define	MD_MN_MDDB_OPTRECFIX	(MDIOC|81) /* Fix optimized record failure */
765 #define	MD_MN_SET_CAP		(MDIOC|82) /* set capability, eg ABR, DMR */
766 #define	MD_MN_CHK_WRT_MDDB	(MDIOC|83) /* New master checks/writes mddb */
767 #define	MD_MN_SET_SETFLAGS	(MDIOC|84) /* Set/reset set flags */
768 #define	MD_MN_GET_SETFLAGS	(MDIOC|85) /* Gets set flags */
769 #define	MD_IOCGET_DIDMIN	(MDIOC|94) /* get the minor name for a devid */
770 #define	MD_IOCIMP_LOAD		(MDIOC|95) /* load the import replicas */
771 #define	MD_IOCSET_DID		(MDIOC|96) /* set the devid of a disk */
772 #define	MD_MN_GET_MIRROR_STATE	(MDIOC|97) /* Get the mirror state MN only */
773 #define	MD_MN_DB_USERREQ	(MDIOC|98) /* MN MT-version of USERREQ */
774 #define	MD_IOCMAKE_DEV		(MDIOC|99) /* create device node for unit */
775 #define	MD_MN_SET_COMMD_RUNNING	(MDIOC|100) /* Commd running or exiting */
776 #define	MD_MN_COMMD_ERR		(MDIOC|101) /* get a message out */
777 #define	MD_MN_SETSYNC		(MDIOC|102) /* multi-threaded MD_IOCSETSYNC */
778 #define	MD_MN_POKE_HOTSPARES	(MDIOC|103) /* poke hotspares */
779 #define	MD_DB_LBINITTIME	(MDIOC|104) /* get the lb_inittime */
780 #define	MD_IOCGET_HSP_NM	(MDIOC|105) /* get hsp entry from namespace */
781 #define	MD_IOCREM_DEV		(MDIOC|106) /* remove device node for unit */
782 #define	MD_IOCUPDATE_NM_RR_DID	(MDIOC|107) /* update remotely repl did in NM */
783 #define	MD_MN_RR_DIRTY		(MDIOC|108) /* Mark RR range as dirty */
784 #define	MD_MN_RR_CLEAN		(MDIOC|109) /* Clean RR bits from bitmap */
785 
786 #define	MDIOC_MISC	(MDIOC|128)	/* misc module base */
787 /* Used in DEBUG_TEST code */
788 #define	MD_MN_CHECK_DOOR1 (MDIOC|126)	/* MN: test door to master */
789 #define	MD_MN_CHECK_DOOR2 (MDIOC|127)	/* MN: test door master-broadcast */
790 
791 #define	NODBNEEDED(c)	((c) == MD_IOCNOTIFY)
792 
793 typedef struct md_resync_ioctl {
794 	MD_DRIVER
795 	md_error_t	mde;
796 	minor_t		ri_mnum;	    /* mirror to sync */
797 	diskaddr_t	ri_copysize;	    /* The size of the copy buffer */
798 	int		ri_zerofill;	    /* Zerofill on lec read error */
799 	int		ri_percent_done;    /* percent done current phase */
800 	int		ri_percent_dirty;
801 	md_riflags_t	ri_flags;
802 } md_resync_ioctl_t;
803 
804 typedef struct md_rrsize {
805 	MD_DRIVER
806 	md_error_t	mde;		/* error return */
807 	minor_t		mnum;		/* unit # to get */
808 	ulong_t		rr_num;		/* Number of resync regions */
809 	ulong_t		rr_blksize;	/* Blocksize of regions */
810 } md_rrsize_t;
811 
812 typedef	enum replace_cmd {
813 	REPLACE_COMP, ENABLE_COMP, FORCE_REPLACE_COMP, FORCE_ENABLE_COMP
814 } replace_cmd_t;
815 
816 typedef struct replace_params {
817 	MD_DRIVER
818 	md_error_t	mde;
819 	replace_cmd_t	cmd;		/* what to do */
820 	minor_t		mnum;		/* mirror to act upon */
821 	md_dev64_t	old_dev;	/* enable/replace use this */
822 	md_dev64_t	new_dev;	/* replace only uses this */
823 	mdkey_t		new_key;	/* replace only uses this */
824 	diskaddr_t	start_blk;	/* start block of new device */
825 	int		has_label;	/* has label flag of new device */
826 	diskaddr_t	number_blks;	/* # of blocks of new device */
827 	uint_t		options;	/* misc options, see MDIOCTL_* below */
828 } replace_params_t;
829 
830 typedef struct md_i_off_on {
831 	MD_DRIVER
832 	md_error_t	mde;
833 	minor_t		mnum;
834 	md_dev64_t	submirror;
835 	int		force_offline;
836 } md_i_off_on_t;
837 
838 typedef struct md_att_struct {
839 	MD_DRIVER
840 	md_error_t	mde;		/* Normal error */
841 	minor_t		mnum;
842 	mdkey_t		key;		/* namespace key of sm */
843 	md_dev64_t	submirror;	/* The device  to attach */
844 	uint_t		options;	/* passed in from the command */
845 } md_att_struct_t;
846 
847 /* possible values for options above */
848 #define	MDIOCTL_DRYRUN		0x0001	/* Only check if operation possible */
849 #define	MDIOCTL_NO_RESYNC_RAID	0x0002	/* if cluster replace we don't */
850 					/*    want to resync */
851 
852 typedef struct md_detach_params {
853 	MD_DRIVER
854 	md_error_t	mde;
855 	minor_t		mnum;		/* mirror to act upon */
856 	md_dev64_t	submirror;
857 	int		force_detach;
858 } md_detach_params_t;
859 
860 /*
861  * Structure for accessing the DB from user land.
862  */
863 typedef struct mddb_userreq {
864 	md_error_t		ur_mde;
865 	mddb_usercmd_t		ur_cmd;
866 	set_t			ur_setno;
867 	mddb_type_t		ur_type;
868 	uint_t			ur_type2;
869 	mddb_recid_t		ur_recid;
870 	mddb_recstatus_t	ur_recstat;
871 	int			ur_size;
872 	uint64_t		ur_data;	/* Pointer to user data */
873 } mddb_userreq_t;
874 
875 /*
876  * Ioctl structure for MD_IOCISOPEN
877  */
878 typedef struct md_isopen {
879 	md_error_t	mde;
880 	md_dev64_t	dev;
881 	int		isopen;
882 } md_isopen_t;
883 
884 /*
885  * Ioctl structure for MD_MN_OPEN_TEST
886  * md_clu_open stands for md check/lock/unlock
887  * Can't use MD_IOCISOPEN, because it's a contracted inteface.
888  */
889 typedef struct md_clu_open {
890 	md_error_t	clu_mde;
891 	md_dev64_t	clu_dev;
892 	enum {	MD_MN_LCU_CHECK = 0,
893 		MD_MN_LCU_LOCK,
894 		MD_MN_LCU_UNLOCK } clu_cmd;
895 	int		clu_isopen;
896 } md_clu_open_t;
897 
898 /*
899  * Structure to push the message out from commd
900  * MAXPATHLEN macro is being overloaded to represent
901  * the line size of 1024 characters. i.e. no path
902  * is being passed.
903  */
904 typedef struct md_mn_commd_err {
905 	int size;
906 	uint64_t md_message; /* pointer to array of chars */
907 } md_mn_commd_err_t;
908 
909 /*
910  * Ioctl structure for MD_IOCPROBE_DEV
911  */
912 
913 #define	TESTNAME_LEN 32
914 
915 #define	PROBE_SEMA(p)	p->probe_sema
916 #define	PROBE_MX(p)	p->probe_mx
917 
918 /*
919  * To categorize user/kernel structures md_probedev is split into two,
920  * one used by user and the other by kernel, thereby hiding the semaphore
921  * /mutex pointer members from user, which should be the appropriate one.
922  */
923 
924 typedef struct md_probedev {
925 	MD_DRIVER
926 	md_error_t	mde;		/* return error status */
927 	int		nmdevs;		/* number of metadevices */
928 	char		test_name[TESTNAME_LEN];
929 	uint64_t	mnum_list;	/* pointer to array of minor numbers */
930 } md_probedev_t;
931 
932 typedef struct md_probedev_impl {
933 	ksema_t		*probe_sema;
934 	kmutex_t	*probe_mx;
935 	md_probedev_t	probe;
936 } md_probedev_impl_t;
937 
938 /*
939  * Ioctl structure for MD_MN_GET_MIRROR_STATE
940  */
941 typedef struct md_mn_get_mir_state {
942 	MD_DRIVER
943 	minor_t		mnum;		/* Unit to obtain submirror info from */
944 } md_mn_get_mir_state_t;
945 
946 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
947 #pragma pack()
948 #endif
949 /*
950  * Per set flags, stored in md_set[n].s_status
951  */
952 #define	MD_SET_HALTED		0x00000001  /* Set is shut down */
953 #define	MD_SET_SNARFED		0x00000002  /* incores built for set db recs */
954 #define	MD_SET_SNARFING		0x00000004  /* incores being built for set */
955 #define	MD_SET_STALE		0x00000008  /* set database not correct */
956 #define	MD_SET_NM_LOADED	0x00000010  /* set namespace is loaded */
957 #define	MD_SET_TAGDATA		0x00000020  /* tagged data detected */
958 #define	MD_SET_ACCOK		0x00000040  /* Accept data is possible */
959 #define	MD_SET_TOOFEW		0x00000080  /* not enough replicas */
960 #define	MD_SET_USETAG		0x00000100  /* A tag is selected, use it */
961 #define	MD_SET_ACCEPT		0x00000200  /* User chose accept 50/50 mode */
962 #define	MD_SET_OWNERSHIP	0x00000400  /* Set is owned */
963 #define	MD_SET_BADTAG		0x00000800  /* DT is not valid */
964 #define	MD_SET_CLRTAG		0x00001000  /* Clear the tags */
965 #define	MD_SET_KEEPTAG		0x00002000  /* Keep the tag */
966 #define	MD_SET_PUSHLB		0x00004000  /* Indicate a LB push is needed */
967 #define	MD_SET_MNSET		0x00008000  /* Set is a multinode diskset */
968 #define	MD_SET_DIDCLUP		0x00010000  /* Set has cleaned up devids */
969 #define	MD_SET_MNPARSE_BLK	0x00020000  /* Do not send parse msgs */
970 #define	MD_SET_MN_NEWMAS_RC	0x00040000  /* Is new master during reconfig */
971 #define	MD_SET_MN_START_RC	0x00080000  /* Start step executed for set */
972 #define	MD_SET_IMPORT		0x00100000  /* Indicate set is importing */
973 #define	MD_SET_MN_MIR_STATE_RC	0x00200000  /* Mirror state gotten for set */
974 #define	MD_SET_HOLD		0x00400000  /* Hold set during release */
975 #define	MD_SET_REPLICATED_IMPORT	0x00800000  /* Set importing RC disk */
976 
977 #define	MD_MNSET_SETNO(setno)	(md_set[setno].s_status & MD_SET_MNSET)
978 
979 /*
980  * See meta_prbits() in SUNWmd/lib/libmeta/meta_print.c for a description of
981  * the way this is used
982  */
983 #define	MD_SET_STAT_BITS "\020\001HALTED\002SNARFED\003SNARFING\004STALE" \
984 			    "\005NM_LOADED\006TAGDATA\007ACCOK\010TOOFEW" \
985 			    "\011USETAG\012ACCEPT\013OWNERSHIP\014BADTAG" \
986 			    "\015CLRTAG\016KEEPTAG\017PUSHLB\020MNSET" \
987 			    "\021DIDCLUP\022MNPARSE_BLK\023MN_NEWMAS_RC" \
988 			    "\024MN_START_RC\025IMPORT\026MIR_STATE_RC" \
989 			    "\027HOLD\030REPLICATED_IMPORT"
990 
991 
992 #ifdef	__cplusplus
993 }
994 #endif
995 
996 #endif	/* _SYS__MDIO_H */
997