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