xref: /titanic_41/usr/src/head/meta.h (revision 6185db853e024a486ff8837e6784dd290d866112)
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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_META_H
27 #define	_META_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <limits.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <fcntl.h>
35 #include <errno.h>
36 #include <string.h>
37 #include <unistd.h>
38 #include <libgen.h>
39 #include <locale.h>
40 #include <time.h>
41 #include <assert.h>
42 #include <stdarg.h>
43 #include <signal.h>
44 #include <devid.h>
45 #include <sys/types.h>
46 #include <sys/stat.h>
47 #include <sys/sysmacros.h>
48 #include <sys/mkdev.h>
49 #include <sys/time.h>
50 #include <sys/dkio.h>
51 #include <sys/vtoc.h>
52 #include <sys/efi_partition.h>
53 #include <meta_basic.h>
54 #include <mdiox.h>
55 #include <metamed.h>
56 #include <sys/lvm/mdio.h>
57 #include <sys/lvm/md_mddb.h>
58 #include <sys/lvm/md_sp.h>
59 #include <sys/lvm/mdmn_commd.h>
60 
61 #ifdef	__cplusplus
62 extern "C" {
63 #endif
64 
65 /* debug malloc include */
66 #ifdef	DEBUG_MALLOC
67 #ifdef	_REENTRANT
68 die right now
69 #endif
70 #include <../lib/malloclib/malloc.h>
71 #endif
72 
73 /*
74  * useful macros
75  */
76 #ifndef	min
77 #define	min(x, y)	(((x) < (y)) ? (x) : (y))
78 #endif
79 #ifndef	max
80 #define	max(x, y)	(((x) > (y)) ? (x) : (y))
81 #endif
82 #ifndef	rounddown
83 #define	rounddown(x, y)	(((x) / (y)) * (y))
84 #endif
85 
86 /*
87  * external names
88  */
89 
90 #define	METATAB			"/etc/lvm/md.tab"
91 #define	METACONF		"/etc/lvm/md.cf"
92 #define	METACONFTMP		"/etc/lvm/md.cf.new"
93 #define	META_DBCONF		"/etc/lvm/mddb.cf"
94 #define	META_DBCONFTMP		"/etc/lvm/mddb.cf.new"
95 #define	META_MNSET_NODELIST	"/var/run/nodelist"
96 #define	METALOG			"/etc/lvm/md.log"
97 #define	METALOCK		"/etc/lvm/lock"
98 #define	METADEVPATH		"/etc/lvm/devpath"
99 #define	METALOGENV		"MD_LOG"
100 #define	METAPKGROOT		"/usr"
101 #define	ADMSPECIAL		"/dev/md/admin"
102 
103 #define	MDB_STR			"metadevice state database"
104 
105 /* default database size (4MB) */
106 #define	MD_DBSIZE	(8192)
107 
108 /* default Multinode database size (16MB) */
109 #define	MD_MN_DBSIZE	(32768)
110 
111 /* disk label size */
112 #define	VTOC_SIZE	(16)
113 
114 /* maximum ctd name size (in # of digits) for printing out */
115 #define	CTD_FORMAT_LEN	6
116 
117 /* Recommend timeout in seconds for RPC client creation. */
118 #define	MD_CLNT_CREATE_TOUT	(60)
119 
120 /*
121  * If event needs to be checked during wait of MD_CLNT_CREATE_TOUT,
122  * spin checking for event and then waiting for MD_CLNT_CREATE_SUBTIMEOUT
123  * seconds until MD_CLNT_CREATE_TOUT seconds are used.
124  */
125 #define	MD_CLNT_CREATE_SUBTIMEOUT	(5)
126 
127 /*
128  * metaclust verbosity levels and what they are for. Messages upto MC_LOG2
129  * will also be logged in syslog.
130  */
131 #define	MC_LOG0		0	/* special class. log messages regardless of */
132 				/* debug level */
133 #define	MC_LOG1		1	/* log standard error messages */
134 #define	MC_LOG2		2	/* log metaclust step level timing messages */
135 #define	MC_LOG3		3	/* log per set level timing messages */
136 				/* intended for use in loops walking mn sets */
137 #define	MC_LOG4		4	/* log per device level timing messages */
138 				/* intended for use in loops walking devices */
139 #define	MC_LOG5		5	/* typically for use in deep nested loops */
140 				/* or in libmeta routines */
141 
142 /*
143  * for meta_print* options
144  */
145 typedef	uint_t	mdprtopts_t;
146 #define	PRINT_SHORT		0x00000001
147 #define	PRINT_SUBDEVS		0x00000002
148 #define	PRINT_HEADER		0x00000004
149 #define	PRINT_DEBUG		0x00000008
150 #define	PRINT_TIMES		0x00000010
151 #define	PRINT_SETSTAT		0x00000020
152 #define	PRINT_SETSTAT_ONLY	0x00000040
153 #define	PRINT_FAST		0x00000080
154 #define	PRINT_DEVID		0x00000100
155 #define	PRINT_LARGEDEVICES	0x00000200
156 #define	PRINT_FN		0x00000400
157 
158 /*
159  * for meta_devadm options
160  */
161 typedef	uint_t  mddevopts_t;
162 #define	DEV_VERBOSE		0x00000001
163 #define	DEV_NOACTION		0x00000002
164 #define	DEV_LOG			0x00000004
165 #define	DEV_RELOAD		0x00000008
166 #define	DEV_UPDATE		0x00000010
167 #define	DEV_LOCAL_SET		0x00000020	/* update only MD_LOCAL_SET */
168 
169 /*
170  * return values for meta_devadm operations
171  */
172 #define	METADEVADM_SUCCESS	0
173 #define	METADEVADM_ERR		1
174 #define	METADEVADM_DEVIDINVALID	2
175 #define	METADEVADM_DSKNAME_ERR	3
176 #define	METADEVADM_DISKMOVE	4
177 
178 /*
179  * meta_check* options
180  */
181 typedef	uint_t	mdchkopts_t;
182 #define	MDCHK_ALLOW_MDDB	0x01	/* allows repliica in md's (metainit) */
183 #define	MDCHK_ALLOW_HS		0x02	/* allows hs in multiple hsp's (hs) */
184 #define	MDCHK_ALLOW_LOG		0x04	/* allows sharing of logs (trans) */
185 #define	MDCHK_ALLOW_REPSLICE	0x08	/* allow replica slice to be used */
186 #define	MDCHK_ALLOW_NODBS	0x10	/* no db replicas allowed (metadb) */
187 #define	MDCHK_DRVINSET		0x20	/* drive is in set (metaset) */
188 #define	MDCHK_SET_LOCKED	0x40	/* The set is locked */
189 #define	MDCHK_SET_FORCE		0x80	/* This is a forced operation */
190 
191 /*
192  * meta_check_inuse options
193  */
194 typedef uint_t	mdinuseopts_t;
195 #define	MDCHK_SWAP	0x01		/* check swap & overlap w/swap */
196 #define	MDCHK_DUMP	0x02		/* check dump & overlap w/dump */
197 #define	MDCHK_MOUNTED	0x04		/* check mounted & overlap w/mounted */
198 #define	MDCHK_INUSE	0xff		/* check all */
199 
200 /*
201  * meta* force options
202  */
203 typedef	uint_t	mdforceopts_t;
204 #define	MDFORCE_NONE		0x01	/* no extra force used */
205 #define	MDFORCE_LOCAL		0x02	/* force from metadb command line */
206 #define	MDFORCE_DS		0x04	/* force from metaset library */
207 #define	MDFORCE_SET_LOCKED	0x10	/* The set is locked */
208 
209 
210 /*
211  * meta* options
212  */
213 typedef	uint_t	mdcmdopts_t;
214 #define	MDCMD_DOIT		0x0001	/* really do operation */
215 #define	MDCMD_FORCE		0x0002	/* force operation */
216 #define	MDCMD_PRINT		0x0004	/* print success messages to stdout */
217 #define	MDCMD_RECURSE		0x0008	/* recursive operation */
218 #define	MDCMD_INIT		0x0010	/* init operation */
219 #define	MDCMD_UPDATE		0x0020	/* update sizes used w/o DOIT mostly */
220 #define	MDCMD_NOLOCK		0x0040	/* lock already held, DONT acquire */
221 #define	MDCMD_VERBOSE		0x0100	/* be verbose */
222 #define	MDCMD_USE_WHOLE_DISK	0x0200	/* repartition disk */
223 #define	MDCMD_DIRECT		0x0400	/* extents specified directly */
224 #define	MDCMD_ALLOPTION		0x0800	/* the all option is being used */
225 #define	MDCMD_MN_OPEN_CHECK	0x1000	/* Perform open check on all nodes */
226 
227 /*
228  * meta_tab* definitions
229  */
230 #define	TAB_ARG_ALLOC	5
231 #define	TAB_LINE_ALLOC	10
232 
233 typedef uint_t mdinittypes_t;
234 #define	TAB_UNKNOWN		0x0000
235 #define	TAB_MDDB		0x0001
236 #define	TAB_HSP			0x0002
237 #define	TAB_STRIPE		0x0004
238 #define	TAB_MIRROR		0x0008
239 #define	TAB_RAID		0x0010
240 #define	TAB_TRANS		0x0020
241 #define	TAB_SP			0x0040
242 #define	TAB_MD			(TAB_STRIPE | TAB_MIRROR | TAB_RAID |\
243 					TAB_TRANS | TAB_SP)
244 #define	TAB_MD_HSP		(TAB_MD | TAB_HSP)
245 
246 typedef	struct {
247 	mdinittypes_t	type;
248 	char		*context;
249 	char		*cname;
250 	int		argc;
251 	char		**argv;
252 	size_t		alloc;
253 	uint_t		flags;	/* for application use */
254 } md_tab_line_t;
255 
256 typedef	struct {
257 	char		*filename;
258 	char		*data;
259 	size_t		total;
260 	size_t		nlines;
261 	md_tab_line_t	*lines;
262 	size_t		alloc;
263 } md_tab_t;
264 
265 /*
266  * disk status definitions
267  */
268 typedef struct md_disk_status_list {
269 	struct md_disk_status_list	*next;
270 	mddrivename_t			*drivenamep;
271 	md_error_t			status;
272 } md_disk_status_list_t;
273 
274 /*
275  * module name list used by meta_patch_root & meta_systemfile
276  */
277 struct modname {
278 	char		*name;
279 	struct modname	*next;
280 };
281 
282 /*
283  * list to be used for printing Device Relocation Information
284  */
285 typedef struct mddevid_t {
286 	struct mddevid_t *next;
287 	char *ctdname;
288 	mdkey_t key;
289 } mddevid_t;
290 
291 /*
292  * Multi-Node Diskset List
293  *
294  * we either store the IP address of the private interconnect or its name
295  * in the msl_node_addr member
296  */
297 typedef struct mndiskset_membershiplist {
298 	uint_t				msl_node_id;
299 	md_mnnode_nm_t			msl_node_name;
300 	md_mnnode_nm_t			msl_node_addr;
301 	struct mndiskset_membershiplist	*next;
302 } mndiskset_membershiplist_t;
303 
304 /*
305  * client pool for rpc calls to mdcommd
306  */
307 typedef struct md_mn_client_list {
308 	CLIENT *mcl_clnt;
309 	struct md_mn_client_list *mcl_next;
310 } md_mn_client_list_t;
311 
312 /*
313  * Resync thread manipulation commands.
314  *
315  * The resync thread can now be started, blocked, unblocked or killed.
316  * This typedef specifies the action to be taken by meta_resync.c
317  * routines.
318  */
319 typedef enum {
320 	MD_RESYNC_START = 1,
321 	MD_RESYNC_BLOCK,
322 	MD_RESYNC_UNBLOCK,
323 	MD_RESYNC_KILL,
324 	MD_RESYNC_KILL_NO_WAIT,
325 	MD_RESYNC_FORCE_MNSTART
326 } md_resync_cmd_t;
327 
328 
329 /*
330  * rpc.metad macro definitions.
331  */
332 #define	METAD_SETUP_DR(cmd, id)	\
333 	{				\
334 	req.ur_cmd = cmd;		\
335 	req.ur_setno = MD_LOCAL_SET;	\
336 	req.ur_type = MDDB_USER;	\
337 	req.ur_type2 = MDDB_UR_DR;	\
338 	req.ur_recid = id;		\
339 	}
340 
341 #define	METAD_SETUP_NR(cmd, id)	\
342 	{				\
343 	req.ur_cmd = cmd;		\
344 	req.ur_setno = MD_LOCAL_SET;	\
345 	req.ur_type = MDDB_USER;	\
346 	req.ur_type2 = MDDB_UR_NR;	\
347 	req.ur_recid = id;		\
348 	}
349 
350 #define	METAD_SETUP_SR(cmd, id)	\
351 	{				\
352 	req.ur_cmd = cmd;		\
353 	req.ur_setno = MD_LOCAL_SET;	\
354 	req.ur_type = MDDB_USER;	\
355 	req.ur_type2 = MDDB_UR_SR;	\
356 	req.ur_recid = id;		\
357 	}
358 
359 #define	METAD_SETUP_UR(cmd, type2, id)	\
360 	{				\
361 	req.ur_cmd = cmd;		\
362 	req.ur_setno = MD_LOCAL_SET;	\
363 	req.ur_type = MDDB_USER;	\
364 	req.ur_type2 = type2;		\
365 	req.ur_recid = id;		\
366 	}
367 
368 #define	METAD_SETUP_LR(cmd, setno, id)	\
369 	{				\
370 	req.ur_cmd = cmd;		\
371 	req.ur_setno = setno;	\
372 	req.ur_type = MDDB_USER;	\
373 	req.ur_type2 = MDDB_UR_LR;	\
374 	req.ur_recid = id;		\
375 	}
376 
377 /*
378  * This typedef specifies the signature of a function that
379  * meta_client_create_retry can use to establish an rpc connection.
380  * private is used to pass data from the caller of meta_client_create_retry
381  * to clnt_create_func.
382  */
383 typedef CLIENT *(*clnt_create_func_t)(char *hostname,
384 	void *private,
385 	struct timeval *time_out);
386 
387 /* definition of the table for the different message types */
388 typedef struct md_mn_msg_tbl_entry {
389 	md_mn_msgclass_t	mte_class;
390 	void (*mte_handler)
391 	    (md_mn_msg_t *msg, uint_t flags, md_mn_result_t *res);
392 	int (*mte_smgen)
393 	    (md_mn_msg_t *msg, md_mn_msg_t **msglist);
394 	time_t		mte_timeout; /* seconds before msg times out */
395 	uint_t		mte_retry1; /* nretries in case of class busy */
396 	uint_t		mte_ticks1; /* sleep nticks before retry */
397 	uint_t		mte_retry2; /* nretries in case of comm fail */
398 	uint_t		mte_ticks2; /* sleep nticks before retry */
399 } md_mn_msg_tbl_entry_t;
400 
401 /*
402  * Flags for the take command
403  */
404 #define	TAKE_FORCE	0x0001
405 #define	TAKE_USETAG	0x0002
406 #define	TAKE_USEIT	0x0004
407 #define	TAKE_IMP	0x0008
408 #define	TAKE_RETAKE	0x0010
409 
410 /*
411  * ignore gettext for lint so we check printf args
412  */
413 #ifdef __lint
414 #define	dgettext(d, s)	s
415 #define	gettext(s)	s
416 #endif
417 
418 /*
419  * Defines for enabling/disabling SVM services in SMF.
420  */
421 #define	META_SMF_CORE		0x01
422 #define	META_SMF_DISKSET	0x02
423 #define	META_SMF_MN_DISKSET	0x04
424 #define	META_SMF_ALL		0xFF
425 
426 /*
427  * Defines to send/not_send addition of mddb sidenames to
428  * rpc.mdcommd for MN disksets.
429  */
430 #define	DB_ADDSIDENMS_NO_BCAST	0
431 #define	DB_ADDSIDENMS_BCAST	1
432 
433 /*
434  * Defines and structures to support rpc.mdcommd.
435  * RPC routines in rpc.metad will be used to suspend, resume
436  * and reinitialize the rpc.mdcommd running on that node.
437  * These actions are needed when the nodelist is changing.
438  */
439 #define	COMMDCTL_SUSPEND	1
440 #define	COMMDCTL_RESUME		2
441 #define	COMMDCTL_REINIT		3
442 
443 /*
444  * Defines used when joining a node to a MN diskset.
445  * A MN diskset is stale if < 50% mddbs are available when the first node
446  * joins the set.  A MN diskset is stale when 50% mddbs are available when
447  * the first node joins the set if the mediator is unable to provide an
448  * extra vote.
449  * Once a MN set is marked stale, it stays in the stale state (even if > 50%
450  * mddbs are available) until all nodes are withdrawn from the diskset.
451  * Any new nodes joining a stale MN diskset are marked stale regardless of
452  * the availability of mddbs in order to keep the diskset consistent across
453  * all nodes.
454  *
455  * If a reconfig cycle is underway, set the reconfig flag so that rpc.metad
456  * clnt_locks are not enforced.  Since the reconfig cycle has locked out the
457  * meta* commands, this is safe to do.
458  */
459 #define	MNSET_IS_STALE		1	/* Is MN set stale? */
460 #define	MNSET_IN_RECONFIG	2	/* Is MN set in reconfig? */
461 
462 /*
463  * Structure used during reconfig step2 to aid in sychronization
464  * of the drives in a diskset.
465  */
466 typedef struct md_mnsr_node {
467 	md_mnset_record		*mmn_mnsr;
468 	md_mnnode_nm_t		mmn_nodename;
469 	int			mmn_numdrives;
470 	md_drive_desc		*mmn_dd;
471 	struct md_mnsr_node	*mmn_next;
472 } md_mnsr_node_t;
473 
474 
475 /*
476  * meta events definitions ("meta_notify.h")
477  */
478 
479 /*
480  * event flags
481  * meta_notify_createq(),	(EXISTERR, PERMANENT)
482  * meta_notify_getev(),		(WAIT)
483  * meta_notify_getevlist()	(WAIT)
484  */
485 #define	EVFLG_WAIT	0x00000001	/* block until events are pending */
486 #define	EVFLG_EXISTERR	0x00000002	/* if q exists, return an error */
487 #define	EVFLG_PERMANENT	0x00000004	/* queue persists after process exit */
488 
489 /*
490  * events are always associated with an underlying object
491  * This object is of one of the following types.
492  */
493 typedef enum md_ev_objtype_t {
494 	EVO_EMPTY	= 0,
495 	EVO_METADEV,
496 	EVO_MIRROR,
497 	EVO_STRIPE,
498 	EVO_RAID5,
499 	EVO_TRANS,
500 	EVO_REPLICA,
501 	EVO_HSP,
502 	EVO_HS,
503 	EVO_SET,
504 	EVO_DRIVE,
505 	EVO_HOST,
506 	EVO_MEDIATOR,
507 	EVO_UNSPECIFIED,
508 	EVO_LAST
509 } ev_obj_t;
510 
511 /*
512  * Specific events are sent upon state changes
513  * in the underlying devices or when sent by
514  * user applications. These events have a unique
515  * type. These types map to kernel event types (sys/md_notify.h)
516  *
517  * When updating these UPDATE THE TABLE in lib/config/config.c
518  */
519 typedef enum md_ev_id_t {
520 	EV_UNK = 0,
521 	EV_EMPTY,
522 	EV_CREATE,
523 	EV_DELETE,
524 	EV_ADD,
525 	EV_REMOVE,
526 	EV_REPLACE,
527 	EV_GROW,
528 	EV_RENAME_SRC,
529 	EV_RENAME_DST,
530 	EV_MEDIATOR_ADD,
531 	EV_MEDIATOR_DELETE,
532 	EV_HOST_ADD,
533 	EV_HOST_DELETE,
534 	EV_DRIVE_ADD,
535 	EV_DRIVE_DELETE,
536 	EV_INIT_START,
537 	EV_INIT_FAILED,
538 	EV_INIT_FATAL,
539 	EV_INIT_SUCCESS,
540 	EV_IOERR,
541 	EV_ERRED,
542 	EV_LASTERRED,
543 	EV_OK,
544 	EV_ENABLE,
545 	EV_RESYNC_START,
546 	EV_RESYNC_FAILED,
547 	EV_RESYNC_SUCCESS,
548 	EV_RESYNC_DONE,
549 	EV_HOTSPARED,
550 	EV_HS_FREED,
551 	EV_HS_CHANGED,
552 	EV_TAKEOVER,
553 	EV_RELEASE,
554 	EV_OPEN_FAIL,
555 	EV_OFFLINE,
556 	EV_ONLINE,
557 	EV_GROW_PENDING,
558 	EV_DETACH,
559 	EV_DETACHING,
560 	EV_ATTACH,
561 	EV_ATTACHING,
562 	EV_CHANGE,
563 	EV_EXCHANGE,
564 	EV_REGEN_START,
565 	EV_REGEN_DONE,
566 	EV_REGEN_FAILED,
567 	EV_USER,
568 	EV_NOTIFY_LOST,
569 	EV_LAST
570 } evid_t;
571 
572 #define	EV_ALLOBJS	(~0ULL)
573 #define	EV_ALLSETS	((set_t)(~0))
574 
575 #if !defined(_KERNEL)
576 
577 #define	NOTIFY_MD(tag, set, dev, ev)					\
578 	(void) meta_notify_sendev((tag), (set), (dev), (ev))
579 
580 #define	SE_NOTIFY(se_class, se_subclass, tag, set, dev)			\
581 	meta_svm_sysevent((se_class), (se_subclass), (tag), (set), (dev))
582 
583 #endif /* _KERNEL */
584 
585 typedef struct md_ev {
586 	ev_obj_t	obj_type;
587 	set_t		setno;
588 	evid_t		ev;
589 	u_longlong_t	obj;	/* usually md_dev64_t or hsp id */
590 	u_longlong_t	uev;	/* for (EV_USER) user-defined events */
591 } md_ev_t;
592 
593 typedef struct md_evlist {
594 	struct md_evlist	*next;
595 	md_ev_t			*evp;
596 } md_evlist_t;
597 
598 /* end of meta event definitions ("meta_notify.h") */
599 
600 typedef struct md_im_names {
601 	int	min_count;
602 	char	**min_names;
603 } md_im_names_t;
604 
605 /* Values for replica info status */
606 #define	MD_IM_REPLICA_SCANNED	(0x01)
607 #define	MD_IM_REPLICA_VALID	(0x02)
608 
609 typedef struct md_im_replica_info {
610 	struct md_im_replica_info	*mir_next;
611 	int				mir_status;
612 	int				mir_flags;
613 	daddr32_t			mir_offset;
614 	daddr32_t			mir_length;
615 	md_timeval32_t			mir_timestamp;
616 } md_im_replica_info_t;
617 
618 typedef struct md_im_drive_info {
619 	struct md_im_drive_info		*mid_next; /* next drive in this set */
620 	mddrivename_t			*mid_dnp;
621 	void 				*mid_devid;
622 	void				*mid_o_devid;
623 	int				mid_devid_sz;
624 	int				mid_o_devid_sz;
625 	char				mid_minor_name[MDDB_MINOR_NAME_MAX];
626 	minor_t				mid_mnum;
627 	int				mid_available;
628 	md_timeval32_t			mid_setcreatetimestamp;
629 	char				*mid_driver_name;
630 	char				*mid_devname;
631 	md_im_replica_info_t		*mid_replicas;
632 	int				overlapped_disk;
633 	struct md_im_drive_info		*overlap; /* chain of overlap disks */
634 } md_im_drive_info_t;
635 
636 /* Values for mid_available */
637 #define	MD_IM_DISK_AVAILABLE		0x00
638 #define	MD_IM_DISK_NOT_AVAILABLE	0x01
639 
640 /* Values for set descriptor flags */
641 #define	MD_IM_SET_INVALID	0x10
642 #define	MD_IM_SET_REPLICATED	0x20
643 
644 /* Values for mis_partial */
645 #define	MD_IM_COMPLETE_DISKSET	0x04
646 #define	MD_IM_PARTIAL_DISKSET	0x08
647 
648 typedef struct md_im_set_desc {
649 	struct md_im_set_desc		*mis_next;
650 	int				mis_flags;
651 	int				mis_oldsetno;
652 	md_im_drive_info_t		*mis_drives;
653 	int				mis_active_replicas;
654 	int				mis_partial;
655 } md_im_set_desc_t;
656 
657 /* meta_admin.c */
658 extern	int		open_admin(md_error_t *ep);
659 extern	int		close_admin(md_error_t *ep);
660 extern	int		meta_dev_ismeta(md_dev64_t dev);
661 extern	int		meta_get_nunits(md_error_t *ep);
662 extern	md_dev64_t	metamakedev(minor_t mnum);
663 
664 /* meta_attach.c */
665 extern	int		meta_concat_generic(mdsetname_t *sp, mdname_t *namep,
666 			    u_longlong_t big_or_little, md_error_t *ep);
667 extern	int		meta_concat_parent(mdsetname_t *sp, mdname_t *childnp,
668 			    md_error_t *ep);
669 
670 /* meta_check.c */
671 extern	int		meta_check_inuse(mdsetname_t *sp, mdname_t *np,
672 			    mdinuseopts_t inuse_flag, md_error_t *ep);
673 extern	int		meta_check_driveinset(mdsetname_t *sp,
674 			    mddrivename_t *dnp, md_error_t *ep);
675 extern	int		meta_check_drivemounted(mdsetname_t *sp,
676 			    mddrivename_t *dnp, md_error_t *ep);
677 extern	int		meta_check_driveswapped(mdsetname_t *sp,
678 			    mddrivename_t *dnp, md_error_t *ep);
679 extern	int		meta_check_samedrive(mdname_t *np1, mdname_t *np2,
680 			    md_error_t *ep);
681 extern	int		meta_check_overlap(char *uname, mdname_t *np1,
682 			    diskaddr_t slblk1, diskaddr_t nblks1, mdname_t *np2,
683 			    diskaddr_t slblk2, diskaddr_t nblks2,
684 			    md_error_t *ep);
685 extern	int		meta_check_inmeta(mdsetname_t *sp, mdname_t *np,
686 			    mdchkopts_t options, diskaddr_t slblk,
687 			    diskaddr_t nblks,
688 			    md_error_t *ep);
689 extern	int		meta_check_inset(mdsetname_t *sp, mdname_t *np,
690 			    md_error_t *ep);
691 extern  int		meta_check_root(md_error_t *ep);
692 
693 
694 /* meta_db.c */
695 extern	char		*meta_devid_encode_str(ddi_devid_t devid,
696 			    char *minor_name);
697 extern	void		meta_devid_encode_str_free(char *devidstr);
698 extern	int		meta_devid_decode_str(char *devidstr,
699 			    ddi_devid_t *devidp, char **minor_namep);
700 extern	int		meta_check_inreplica(mdsetname_t *sp, mdname_t *np,
701 			    diskaddr_t slblk, diskaddr_t nblks, md_error_t *ep);
702 extern	int		meta_check_replica(mdsetname_t *sp, mdname_t *np,
703 			    mdchkopts_t options, diskaddr_t slblk,
704 			    diskaddr_t nblks, md_error_t *ep);
705 extern	int		meta_db_addsidenms(mdsetname_t *sp, mdname_t *np,
706 			    daddr_t blkno, int bcast, md_error_t *ep);
707 extern	int		meta_db_delsidenm(mdsetname_t *sp, side_t sideno,
708 			    mdname_t *np, daddr_t blkno, md_error_t *ep);
709 extern	int		meta_db_patch(char *sname, char *cname, int patch,
710 			    md_error_t *ep);
711 extern	int		meta_db_attach(mdsetname_t *sp, mdnamelist_t *db_nlp,
712 			    mdchkopts_t options, md_timeval32_t *timeval,
713 			    int dbcnt, int dbsize, char *sysfilename,
714 			    md_error_t *ep);
715 extern	int		meta_db_detach(mdsetname_t *sp, mdnamelist_t *db_nlp,
716 			    mdforceopts_t force, char *sysfilename,
717 			    md_error_t *ep);
718 extern	void		metafreereplicalist(md_replicalist_t *rlp);
719 extern	int		metareplicalist(mdsetname_t *sp, int flags,
720 			    md_replicalist_t **rlpp, md_error_t *ep);
721 extern	void		meta_sync_db_locations(mdsetname_t *sp,
722 			    md_error_t *ep);
723 extern	int		meta_setup_db_locations(md_error_t *ep);
724 extern	daddr_t		meta_db_minreplica(mdsetname_t *sp, md_error_t *ep);
725 extern	int		meta_get_replica_names(mdsetname_t *,
726 			    mdnamelist_t **, int options, md_error_t *);
727 extern	void		meta_mkdummymaster(mdsetname_t *sp, int fd,
728 			    daddr_t firstblk);
729 extern md_timeval32_t	meta_get_lb_inittime(mdsetname_t *sp, md_error_t *ep);
730 
731 /* meta_db_balance.c */
732 extern	int		meta_db_balance(mdsetname_t *sp, md_drive_desc *opdd,
733 			    md_drive_desc *curdd, daddr_t dbsize,
734 			    md_error_t *ep);
735 
736 /* metadevstamp.c */
737 extern 	int		getdevstamp(mddrivename_t *dnp, time_t *stamp,
738 			    md_error_t *ep);
739 extern 	int		setdevstamp(mddrivename_t *dnp, time_t *stamp,
740 			    md_error_t *ep);
741 
742 /* meta_error.c */
743 extern	int		metaioctl(int cmd, void *data, md_error_t *ep,
744 			    char *name);
745 extern	void		md_logpfx(FILE *fp);
746 /* PRINTFLIKE2 */
747 extern	char		*mde_sperror(md_error_t *mdep, const char *fmt, ...);
748 /* PRINTFLIKE2 */
749 extern	void		mde_perror(md_error_t *mdep, const char *fmt, ...);
750 /* PRINTFLIKE1 */
751 extern	void		md_perror(const char *fmt, ...);
752 /* PRINTFLIKE1 */
753 extern	void		md_eprintf(const char *fmt, ...);
754 extern	void		meta_mc_log(int level, const char *fmt, ...);
755 
756 /* meta_getdevs.c */
757 extern	minor_t		meta_getminor(md_dev64_t dev64);
758 extern	major_t		meta_getmajor(md_dev64_t dev64);
759 extern	md_dev64_t	meta_expldev(md_dev64_t dev);
760 extern	dev32_t		meta_cmpldev(md_dev64_t dev64);
761 
762 extern	int		meta_getdevs(mdsetname_t *sp, mdname_t *namep,
763 			    mdnamelist_t **nlpp, md_error_t *ep);
764 extern	int		meta_getalldevs(mdsetname_t *sp, mdnamelist_t **nlpp,
765 			    int check_db, md_error_t *ep);
766 extern	int		meta_getvtoc(int fd, char *devname,
767 			    struct vtoc *vtocbufp, int *partno,
768 			    md_error_t *ep);
769 extern	int		meta_setvtoc(int fd, char *devname,
770 			    struct vtoc *vtocbufp, md_error_t *ep);
771 extern	int		meta_setmdvtoc(int fd, char *devname,
772 			    mdvtoc_t *mdvtocbufp, md_error_t *ep);
773 extern	int		meta_get_names(char *drivername, mdsetname_t *sp,
774 			    mdnamelist_t **nlpp, mdprtopts_t options,
775 			    md_error_t *ep);
776 extern	int		meta_deviceid_to_nmlist(char *search_path,
777 			    ddi_devid_t devid, char *minor_name,
778 			    devid_nmlist_t **retlist);
779 
780 /* meta_hotspares.c */
781 extern	int		meta_get_hsp_names(mdsetname_t *sp,
782 			    mdhspnamelist_t **hspnlpp, int options,
783 			    md_error_t *ep);
784 extern	void		meta_free_hsp(md_hsp_t *hspp);
785 extern	void		meta_invalidate_hsp(mdhspname_t *hspnp);
786 extern	md_hsp_t	*meta_get_hsp(mdsetname_t *sp, mdhspname_t *hspnp,
787 			    md_error_t *ep);
788 extern	md_hsp_t	*meta_get_hsp_common(mdsetname_t *sp,
789 			    mdhspname_t *hspnp, int fast, md_error_t *ep);
790 extern	int		meta_check_inhsp(mdsetname_t *sp, mdname_t *np,
791 			    diskaddr_t slblk, diskaddr_t nblks, md_error_t *ep);
792 extern	int		meta_check_hotspare(mdsetname_t *sp, mdname_t *np,
793 			    md_error_t *ep);
794 extern	char		*hs_state_to_name(md_hs_t *hsp,
795 			    md_timeval32_t *tvp);
796 extern	int		meta_hsp_print(mdsetname_t *sp, mdhspname_t *hspnp,
797 			    mdnamelist_t **nlpp, char *fname, FILE *fp,
798 			    mdprtopts_t options, md_error_t *ep);
799 extern	int		metachkhsp(mdsetname_t *sp, mdhspname_t *hspnp,
800 			    md_error_t *ep);
801 extern	int		meta_hs_add(mdsetname_t *sp, mdhspname_t *hspnp,
802 			    mdnamelist_t *nlp, mdcmdopts_t options,
803 			    md_error_t *ep);
804 extern	int		meta_hs_delete(mdsetname_t *sp, mdhspname_t *hspnp,
805 			    mdnamelist_t *nlp, mdcmdopts_t options,
806 			    md_error_t *ep);
807 extern	int		meta_hs_replace(mdsetname_t *sp, mdhspname_t *hspnp,
808 			    mdname_t *oldnp, mdname_t *newnp,
809 			    mdcmdopts_t options, md_error_t *ep);
810 extern	int		meta_hs_enable(mdsetname_t *sp, mdnamelist_t *nlp,
811 			    mdcmdopts_t options, md_error_t *ep);
812 extern	int		meta_check_hsp(mdsetname_t *sp, md_hsp_t *hspp,
813 			    mdcmdopts_t options, md_error_t *ep);
814 extern	int		meta_create_hsp(mdsetname_t *sp, md_hsp_t *hspp,
815 			    mdcmdopts_t options, md_error_t *ep);
816 extern	int		meta_init_hsp(mdsetname_t **spp,
817 			    int argc, char *argv[], mdcmdopts_t options,
818 			    md_error_t *ep);
819 extern	int		meta_hsp_reset(mdsetname_t *sp, mdhspname_t *hspnp,
820 			    mdcmdopts_t options, md_error_t *ep);
821 
822 /* meta_init.c */
823 extern	int		parse_interlace(char *uname, char *name,
824 			    diskaddr_t *interlacep, md_error_t *ep);
825 extern	int		meta_cook_syntax(md_error_t *ep,
826 			    md_void_errno_t errcode, char *uname,
827 			    int argc, char *argv[]);
828 extern	int		meta_setup_geom(md_unit_t *md, mdname_t *np,
829 			    mdgeom_t *geomp, uint_t write_reinstruct,
830 			    uint_t read_reinstruct, uint_t round_cyl,
831 			    md_error_t *ep);
832 extern	int		meta_adjust_geom(md_unit_t *md, mdname_t *np,
833 			    uint_t write_reinstruct, uint_t read_reinstruct,
834 			    uint_t round_cyl, md_error_t *ep);
835 extern	int		meta_init_name(mdsetname_t **spp, int argc,
836 			    char *argv[], char *cname, mdcmdopts_t options,
837 			    md_error_t *ep);
838 extern	int		meta_check_devicesize(diskaddr_t total_blocks);
839 extern	int		meta_init_make_device(mdsetname_t **spp, char *uname,
840 			    md_error_t *ep);
841 extern mdinittypes_t	meta_get_init_type(int argc, char *argv[]);
842 
843 /* meta_mdcf.c */
844 extern	int		meta_update_md_cf(mdsetname_t *sp, md_error_t *ep);
845 
846 /* meta_med.c */
847 extern	int		meddstealerror(md_error_t *ep, med_err_t *medep);
848 extern	int		clnt_med_null(char *hostname, md_error_t *ep);
849 extern	int		clnt_med_upd_data(md_h_t *mdhp, mdsetname_t *sp,
850 			    med_data_t *meddp, md_error_t *ep);
851 extern	int		clnt_med_get_data(md_h_t *mdhp, mdsetname_t *sp,
852 			    med_data_t *meddp, md_error_t *ep);
853 extern	int		clnt_med_get_rec(md_h_t *mdhp, mdsetname_t *sp,
854 			    med_rec_t *medrp, md_error_t *ep);
855 extern	int		clnt_med_upd_rec(md_h_t *mdhp, mdsetname_t *sp,
856 			    med_rec_t *medrp, md_error_t *ep);
857 extern	int		clnt_med_hostname(char *hostname, char **ret_hostname,
858 			    md_error_t *ep);
859 
860 extern	int		meta_med_hnm2ip(md_hi_arr_t *mp, md_error_t *ep);
861 extern	int		meta_h2hi(md_h_arr_t *mdhp, md_hi_arr_t *mdhip,
862 			    md_error_t *ep);
863 extern	int		meta_hi2h(md_hi_arr_t *mdhip, md_h_arr_t *mdhp,
864 			    md_error_t *ep);
865 extern	int		setup_med_cfg(mdsetname_t *sp, mddb_config_t *cp,
866 			    int force, md_error_t *ep);
867 
868 /* meta_mem.c */
869 #ifdef	_DEBUG_MALLOC_INC
870 extern	void		*_Malloc(char *file, int line, size_t s);
871 extern	void		*_Zalloc(char *file, int line, size_t s);
872 extern	void		*_Realloc(char *file, int line, void *p, size_t s);
873 extern	void		*_Calloc(char *file, int line, size_t n, size_t s);
874 extern	char		*_Strdup(char *file, int line, char *p);
875 extern	void		_Free(char *file, int line, void *p);
876 #define	Malloc(s)	_Malloc(__FILE__, __LINE__, (s))
877 #define	Zalloc(s)	_Zalloc(__FILE__, __LINE__, (s))
878 #define	Realloc(p, s)	_Realloc(__FILE__, __LINE__, (p), (s))
879 #define	Calloc(n, s)	_Calloc(__FILE__, __LINE__, (n), (s))
880 #define	Strdup(p)	_Strdup(__FILE__, __LINE__, (p))
881 #define	Free(p)		_Free(__FILE__, __LINE__, (p))
882 #else	/* ! _DEBUG_MALLOC_INC */
883 extern	void		*Malloc(size_t s);
884 extern	void		*Zalloc(size_t s);
885 extern	void		*Realloc(void *p, size_t s);
886 extern	void		*Calloc(size_t n, size_t s);
887 extern	char		*Strdup(char *p);
888 extern	void		Free(void *p);
889 #endif	/* ! _DEBUG_MALLOC_INC */
890 
891 /* meta_metad.c */
892 extern	int		clnt_adddrvs(char *hostname, mdsetname_t *sp,
893 			    md_drive_desc *dd, md_timeval32_t timestamp,
894 			    ulong_t genid, md_error_t *ep);
895 extern	int		clnt_addhosts(char *hostname, mdsetname_t *sp,
896 			    int node_c, char **node_v, md_error_t *ep);
897 extern	int		clnt_update_namespace(char *hostname, mdsetname_t *sp,
898 			    side_t side, mddrivename_t *dnp, char *newname,
899 			    md_error_t *ep);
900 extern	int		clnt_add_drv_sidenms(char *hostname, char *this_host,
901 			    mdsetname_t *sp, md_set_desc *sd, int node_c,
902 			    char **node_v, md_error_t *ep);
903 extern	int		clnt_createset(char *hostname, mdsetname_t *sp,
904 			    md_node_nm_arr_t nodes, md_timeval32_t timestamp,
905 			    ulong_t genid, md_error_t *ep);
906 extern	int		clnt_mncreateset(char *hostname, mdsetname_t *sp,
907 			    md_mnnode_desc *nodelist, md_timeval32_t timestamp,
908 			    ulong_t genid, md_node_nm_t master_nodenm,
909 			    int master_nodeid, md_error_t *ep);
910 extern	int		clnt_joinset(char *hostname, mdsetname_t *sp,
911 			    int flags, md_error_t *ep);
912 extern	int		clnt_withdrawset(char *hostname, mdsetname_t *sp,
913 			    md_error_t *ep);
914 extern	int		clnt_deldrvs_by_devid(char *hostname, mdsetname_t *sp,
915 			    md_drive_desc *dd, md_error_t *ep);
916 extern	int		clnt_deldrvs(char *hostname, mdsetname_t *sp,
917 			    md_drive_desc *dd, md_error_t *ep);
918 extern	int		clnt_delhosts(char *hostname, mdsetname_t *sp,
919 			    int node_c, char **node_v, md_error_t *ep);
920 extern	int		clnt_delset(char *hostname, mdsetname_t *sp,
921 			    md_error_t *ep);
922 extern	int		clnt_del_drv_sidenms(char *hostname, mdsetname_t *sp,
923 			    md_error_t *ep);
924 extern	int		clnt_devinfo(char *hostname, mdsetname_t *sp,
925 			    mddrivename_t *dp, md_dev64_t *ret_dev,
926 			    time_t *ret_timestamp, md_error_t *ep);
927 extern	int		clnt_devid(char *hostname, mdsetname_t *sp,
928 			    mddrivename_t *dp, char **ret_encdevid,
929 			    md_error_t *ep);
930 extern	int		clnt_devinfo_by_devid(char *hostname, mdsetname_t *sp,
931 			    char *devidstr, md_dev64_t *retdev,
932 			    char *orig_devname, char **ret_devname,
933 			    char **ret_driver, md_error_t *ep);
934 extern	int		clnt_drvused(char *hostname, mdsetname_t *sp,
935 			    mddrivename_t *dp, md_error_t *ep);
936 extern	void		free_sr(md_set_record *sr);
937 extern	int		clnt_getset(char *hostname, char *setname, set_t setno,
938 			    md_set_record **sr, md_error_t *ep);
939 extern	int		clnt_mngetset(char *hostname, char *setname,
940 			    set_t setno, md_mnset_record **mnsr,
941 			    md_error_t *ep);
942 extern	int		clnt_hostname(char *hostname, char **ret_hostname,
943 			    md_error_t *ep);
944 extern	int		clnt_nullproc(char *hostname, md_error_t *ep);
945 extern	int		clnt_ownset(char *hostname, mdsetname_t *sp,
946 			    int *ret_bool, md_error_t *ep);
947 extern	int		clnt_setnameok(char *hostname, mdsetname_t *sp,
948 			    int *ret_bool, md_error_t *ep);
949 extern	int		clnt_setnumbusy(char *hostname, set_t setno,
950 			    int *ret_bool, md_error_t *ep);
951 extern	int		clnt_upd_dr_dbinfo(char *hostname, mdsetname_t *sp,
952 			    md_drive_desc *dd, md_error_t *ep);
953 extern	int		clnt_stimeout(char *hostname, mdsetname_t *sp,
954 			    mhd_mhiargs_t *mhiargsp, md_error_t *ep);
955 extern	int		clnt_gtimeout(char *hostname, mdsetname_t *sp,
956 			    mhd_mhiargs_t *ret_mhiargs, md_error_t *ep);
957 extern	int		clnt_upd_dr_flags(char *hostname, mdsetname_t *sp,
958 			    md_drive_desc *dd, uint_t new_flags,
959 			    md_error_t *ep);
960 extern	int		clnt_enable_sr_flags(char *hostname, mdsetname_t *sp,
961 			    uint_t new_flags, md_error_t *ep);
962 extern	int		clnt_disable_sr_flags(char *hostname, mdsetname_t *sp,
963 			    uint_t new_flags, md_error_t *ep);
964 extern	int		clnt_upd_sr_flags(char *hostname, mdsetname_t *sp,
965 			    uint_t new_flags, md_error_t *ep);
966 extern	int		clnt_upd_nr_flags(char *hostname, mdsetname_t *sp,
967 			    md_mnnode_desc *nd, uint_t flag_action,
968 			    uint_t flags, md_error_t *ep);
969 extern	int		clnt_unlock_set(char *hostname, md_setkey_t *cl_sk,
970 			    md_error_t *ep);
971 extern	int		clnt_lock_set(char *hostname, mdsetname_t *sp,
972 			    md_error_t *ep);
973 extern	int		clnt_updmeds(char *hostname, mdsetname_t *sp,
974 			    md_h_arr_t *meddp, md_error_t *ep);
975 extern  int		clnt_resnarf_set(char *hostname, set_t setno,
976 			    md_error_t *ep);
977 extern	md_setkey_t	*cl_get_setkey(set_t setno, char *setname);
978 extern	void		cl_set_setkey(md_setkey_t *cl_sk);
979 extern	void		meta_conv_drvname_new2old(o_mddrivename_t *,
980 			    mddrivename_t *);
981 extern	void		meta_conv_drvname_old2new(o_mddrivename_t *,
982 			    mddrivename_t *);
983 extern	void		meta_conv_drvdesc_new2old(o_md_drive_desc *,
984 			    md_drive_desc *);
985 extern	void		meta_conv_drvdesc_old2new(o_md_drive_desc *,
986 			    md_drive_desc *);
987 extern  void 		alloc_olddrvdesc(o_md_drive_desc **, md_drive_desc *);
988 extern  void 		alloc_newdrvdesc(o_md_drive_desc *, md_drive_desc **);
989 extern  void		free_olddrvdesc(o_md_drive_desc *);
990 extern  void		free_newdrvdesc(md_drive_desc *);
991 extern	char		*meta_get_devid(char *);
992 extern	int		clnt_mnsetmaster(char *hostname, mdsetname_t *sp,
993 			    md_node_nm_t master_nodenm, int master_nodeid,
994 			    md_error_t *ep);
995 extern	int		clnt_clr_mnsetlock(char *hostname, md_error_t *ep);
996 extern	int		clnt_mdcommdctl(char *hostname, int flag_action,
997 			    mdsetname_t *sp, md_mn_msgclass_t class,
998 			    uint_t flags, md_error_t *ep);
999 extern	int		clnt_mn_is_stale(char *hostname, mdsetname_t *sp,
1000 			    int *ret_bool, md_error_t *ep);
1001 extern	int		clnt_getdrivedesc(char *hostname, mdsetname_t *sp,
1002 			    md_drive_desc **dd, md_error_t *ep);
1003 extern	void		free_rem_dd(md_drive_desc *dd);
1004 extern	int		clnt_upd_dr_reconfig(char *hostname, mdsetname_t *sp,
1005 			    md_drive_desc *dd, md_error_t *ep);
1006 extern	int		clnt_reset_mirror_owner(char *hostname, mdsetname_t *sp,
1007 			    int node_c, int *node_id, md_error_t *ep);
1008 extern	int		clnt_mn_susp_res_io(char *hostname, set_t setno,
1009 			    int flag, md_error_t *ep);
1010 extern	int		clnt_mn_mirror_resync_all(char *hostname, set_t setno,
1011 			    md_error_t *ep);
1012 extern	int		clnt_mn_sp_update_abr(char *hostname, set_t setno,
1013 			    md_error_t *ep);
1014 
1015 /* meta_metad_subr.c */
1016 extern	mddb_userreq_t	*get_db_rec(md_ur_get_cmd_t cmd, set_t setno,
1017 			    mddb_type_t type, uint_t type2, mddb_recid_t *idp,
1018 			    md_error_t *ep);
1019 extern	void		*get_ur_rec(set_t setno, md_ur_get_cmd_t cmd,
1020 			    uint_t type2, mddb_recid_t *idp, md_error_t *ep);
1021 extern	void		sr_validate(void);
1022 extern	void		sr_del_drv(md_set_record *sr, mddb_recid_t recid);
1023 extern	int		set_snarf(md_error_t *ep);
1024 extern	void		sr_cache_add(md_set_record *sr);
1025 extern	void		sr_cache_del(mddb_recid_t recid);
1026 extern	void		dr_cache_add(md_set_record *sr, md_drive_record *dr);
1027 extern	void		dr_cache_del(md_set_record *sr, mddb_recid_t recid);
1028 extern	void		mnnr_cache_add(md_mnset_record *sr,
1029 			    md_mnnode_record *nr);
1030 extern	void		mnnr_cache_del(md_mnset_record *sr, mddb_recid_t recid);
1031 extern	int		metad_isautotakebyname(char *setname);
1032 extern	int		metad_isautotakebynum(set_t setno);
1033 extern	md_set_record	*metad_getsetbyname(char *setname, md_error_t *ep);
1034 extern	md_set_record	*metad_getsetbynum(set_t setno, md_error_t *ep);
1035 extern	void		commitset(md_set_record *sr, int inc_genid,
1036 			    md_error_t *ep);
1037 extern	md_set_record	*setdup(md_set_record *sr);
1038 extern	md_mnset_record	*mnsetdup(md_mnset_record *mnsr);
1039 extern	md_drive_record	*drdup(md_drive_record *dr);
1040 extern	md_mnnode_record *nrdup(md_mnnode_record *nr);
1041 extern	md_drive_desc	*dd_list_dup(md_drive_desc *dd);
1042 extern	void		sr_cache_flush(int flushnames);
1043 extern	void		sr_cache_flush_setno(set_t setno);
1044 extern	void		s_delset(char *setname, md_error_t *ep);
1045 extern	void		s_delrec(mddb_recid_t recid, md_error_t *ep);
1046 extern	int		s_ownset(set_t setno, md_error_t *ep);
1047 extern	int		resnarf_set(set_t setno, md_error_t *ep);
1048 
1049 /* meta_mh.c */
1050 extern	mhd_mhiargs_t	defmhiargs;
1051 extern	int		meta_take_own(char *sname, mddrivenamelist_t *dnlp,
1052 			    mhd_mhiargs_t *mhiargsp, int partial_set,
1053 			    md_error_t *ep);
1054 extern	int		tk_own_bydd(mdsetname_t *sp, md_drive_desc *dd,
1055 			    mhd_mhiargs_t *mhiargsp, int partial_set,
1056 			    md_error_t *ep);
1057 extern	int		meta_rel_own(char *sname, mddrivenamelist_t *dnlp,
1058 			    int partial_set, md_error_t *ep);
1059 extern	int		rel_own_bydd(mdsetname_t *sp, md_drive_desc *dd,
1060 			    int partial_set, md_error_t *ep);
1061 extern	int		meta_status_own(char *sname,
1062 			    md_disk_status_list_t *dslp, int partial_set,
1063 			    md_error_t *ep);
1064 extern	md_disk_status_list_t *meta_drive_to_disk_status_list(
1065 			    mddrivenamelist_t *dnlp);
1066 extern	void		meta_free_disk_status_list(md_disk_status_list_t *dslp);
1067 extern	void		meta_free_drive_info_list(mhd_drive_info_list_t *listp);
1068 extern	int		meta_list_drives(char *hostname, char *path,
1069 			    mhd_did_flags_t flags,
1070 			    mhd_drive_info_list_t *listp, md_error_t *ep);
1071 extern	int		meta_get_drive_names(mdsetname_t *sp,
1072 			    mddrivenamelist_t **dnlpp, int options,
1073 			    md_error_t *ep);
1074 
1075 /* meta_mirror.c */
1076 extern	int		meta_get_mirror_names(mdsetname_t *sp,
1077 			    mdnamelist_t **nlpp, int options, md_error_t *ep);
1078 extern	void		meta_free_mirror(md_mirror_t *mirrorp);
1079 extern	md_mirror_t	*meta_get_mirror(mdsetname_t *sp, mdname_t *mirnp,
1080 			    md_error_t *ep);
1081 extern	int		meta_check_inmirror(mdsetname_t *sp, mdname_t *np,
1082 			    diskaddr_t slblk, diskaddr_t nblks, md_error_t *ep);
1083 extern	int		meta_check_submirror(mdsetname_t *sp, mdname_t *np,
1084 			    mdname_t *mirnp, int force, md_error_t *ep);
1085 extern	char		*rd_opt_to_name(mm_rd_opt_t opt);
1086 extern	int		name_to_rd_opt(char *uname, char *name,
1087 			    mm_rd_opt_t *optp, md_error_t *ep);
1088 extern	char		*wr_opt_to_name(mm_wr_opt_t opt);
1089 extern	int		name_to_wr_opt(char *uname, char *name,
1090 			    mm_wr_opt_t *optp, md_error_t *ep);
1091 extern	int		name_to_pass_num(char *uname, char *name,
1092 			    mm_pass_num_t *passp, md_error_t *ep);
1093 extern	char		*sm_state_to_name(md_submirror_t *mdsp,
1094 			    md_status_t mirror_status, md_timeval32_t *tvp,
1095 			    uint_t tstate);
1096 extern	int		sm_state_to_action(mdsetname_t *sp,
1097 			    md_submirror_t *mdsp, md_status_t mirror_status,
1098 			    md_mirror_t *mirrorp, char **actionp,
1099 			    md_error_t *ep);
1100 extern	int		meta_print_mirror_options(mm_rd_opt_t read_options,
1101 			    mm_wr_opt_t write_option, mm_pass_num_t pass_num,
1102 			    uint_t tstate, char *fname,
1103 			    mdsetname_t *sp, FILE *fp, md_error_t *ep);
1104 extern	int		meta_mirror_print(mdsetname_t *sp, mdname_t *mirnp,
1105 			    mdnamelist_t **nlpp, char *fname, FILE *fp,
1106 			    mdprtopts_t options, md_error_t *ep);
1107 extern	int		meta_mirror_online(mdsetname_t *sp, mdname_t *mirnp,
1108 			    mdname_t *submirnp, mdcmdopts_t options,
1109 			    md_error_t *ep);
1110 extern	int		meta_mirror_offline(mdsetname_t *sp, mdname_t *mirnp,
1111 			    mdname_t *submirnp, mdcmdopts_t options,
1112 			    md_error_t *ep);
1113 extern	int		meta_mirror_attach(mdsetname_t *sp, mdname_t *mirnp,
1114 			    mdname_t *submirnp, mdcmdopts_t options,
1115 			    md_error_t *ep);
1116 extern	int		meta_mirror_detach(mdsetname_t *sp, mdname_t *mirnp,
1117 			    mdname_t *submirnp, mdcmdopts_t options,
1118 			    md_error_t *ep);
1119 extern	int		meta_mirror_get_params(mdsetname_t *sp,
1120 			    mdname_t *mirnp, mm_params_t *paramsp,
1121 			    md_error_t *ep);
1122 extern	int		meta_mirror_set_params(mdsetname_t *sp,
1123 			    mdname_t *mirnp, mm_params_t *paramsp,
1124 			    md_error_t *ep);
1125 extern	int		meta_mirror_replace(mdsetname_t *sp, mdname_t *mirnp,
1126 			    mdname_t *oldnp, mdname_t *newnp,
1127 			    mdcmdopts_t options, md_error_t *ep);
1128 extern	int		meta_mirror_enable(mdsetname_t *sp, mdname_t *mirnp,
1129 			    mdname_t *compnp, mdcmdopts_t options,
1130 			    md_error_t *ep);
1131 extern	int		meta_check_mirror(mdsetname_t *sp,
1132 			    md_mirror_t *mirrorp, mdcmdopts_t options,
1133 			    md_error_t *ep);
1134 extern	int		meta_create_mirror(mdsetname_t *sp,
1135 			    md_mirror_t *mirrorp, mdcmdopts_t options,
1136 			    md_error_t *ep);
1137 extern	int		meta_init_mirror(mdsetname_t **spp,
1138 			    int argc, char *argv[], mdcmdopts_t options,
1139 			    md_error_t *ep);
1140 extern	int		meta_mirror_reset(mdsetname_t *sp, mdname_t *mirnp,
1141 			    mdcmdopts_t options, md_error_t *ep);
1142 extern	int		meta_mirror_anycomp_is_err(mdsetname_t *,
1143 			    mdnamelist_t *);
1144 
1145 /* meta_mirror_resync.c */
1146 extern	int		meta_mirror_resync(mdsetname_t *sp, mdname_t *mirnp,
1147 			    daddr_t size, md_error_t *ep, md_resync_cmd_t cmd);
1148 extern	int		meta_mirror_resync_all(mdsetname_t *sp, daddr_t size,
1149 			    md_error_t *ep);
1150 extern	void		*meta_mn_mirror_resync_all(void *arg);
1151 extern	void		meta_mirror_resync_kill_all(void);
1152 extern	void		meta_mirror_resync_block_all(void);
1153 extern	void		meta_mirror_resync_unblock_all(void);
1154 extern	void		meta_mirror_resync_unblock(mdsetname_t *sp);
1155 extern	void		meta_mirror_resync_kill(mdsetname_t *sp);
1156 
1157 /* meta_mount.c */
1158 extern	char		*meta_get_mountp(mdsetname_t *, mdname_t *,
1159 			    md_error_t *);
1160 
1161 /* meta_name.c */
1162 extern  char		*meta_name_getname(mdsetname_t **spp, char *uname,
1163 			    meta_device_type_t uname_type, md_error_t *ep);
1164 extern	char		*meta_canonicalize(mdsetname_t *sp, char *uname);
1165 extern	char		*meta_canonicalize_check_set(mdsetname_t **sp,
1166 			    char *uname, md_error_t *ep);
1167 extern	int		meta_is_all(char *uname);
1168 extern	int		is_existing_metadevice(mdsetname_t *sp, char *uname);
1169 extern	int		is_existing_hsp(mdsetname_t *sp, char *uname);
1170 extern	int		is_existing_meta_hsp(mdsetname_t *sp, char *uname);
1171 extern	int		is_metaname(char *uname);
1172 extern	int		meta_is_none(char *uname);
1173 extern	int		is_hspname(char *uname);
1174 extern	int		parse_ctd(char *uname, uint_t *slice);
1175 extern	md_set_desc	*sr2setdesc(md_set_record *sr);
1176 extern	mdsetname_t	*metasetname(char *sname, md_error_t *ep);
1177 extern	mdsetname_t	*metasetnosetname(set_t setno, md_error_t *ep);
1178 extern	mdsetname_t	*metafakesetname(set_t setno, char *sname);
1179 extern	md_set_desc	*metaget_setdesc(mdsetname_t *sp, md_error_t *ep);
1180 extern	void		metaflushsetname(mdsetname_t *sp);
1181 extern	void		metaflushdrivenames(void);
1182 extern	int		metaislocalset(mdsetname_t *sp);
1183 extern	int		metaissameset(mdsetname_t *sp1, mdsetname_t *sp2);
1184 extern	void		metaflushsidenames(mddrivename_t *dnp);
1185 extern	char		*metadiskname(char *name);
1186 extern	mddrivename_t	*metadrivename(mdsetname_t **spp, char *uname,
1187 			    md_error_t *ep);
1188 extern	mddrivename_t	*metadrivenamebydevid(mdsetname_t **spp, char *devid,
1189 			    char *uname, md_error_t *ep);
1190 extern	mdname_t	*metaslicename(mddrivename_t *dnp, uint_t sliceno,
1191 			    md_error_t *ep);
1192 extern	void		metafreedrivename(mddrivename_t *dnp);
1193 extern	void		metafreedrivenamelist(mddrivenamelist_t *dnlp);
1194 extern	int		metadrivenamelist(mdsetname_t **spp,
1195 			    mddrivenamelist_t **dnlpp,
1196 			    int argc, char *argv[], md_error_t *ep);
1197 extern	mddrivename_t	*metadrivenamelist_append(mddrivenamelist_t **dnlpp,
1198 			    mddrivename_t *dnp);
1199 extern  mddrivenamelist_t	**meta_drivenamelist_append_wrapper(
1200 				    mddrivenamelist_t **dnlpp,
1201 				    mddrivename_t *dnp);
1202 extern	int		meta_getdev(mdsetname_t *sp, mdname_t *np,
1203 			    md_error_t *ep);
1204 extern	mdname_t	*metaname_fast(mdsetname_t **spp, char *uname,
1205 			    meta_device_type_t uname_type, md_error_t *ep);
1206 extern	mdname_t	*metaname(mdsetname_t **spp, char *uname,
1207 			    meta_device_type_t uname_type, md_error_t *ep);
1208 extern	mdname_t	*metamnumname(mdsetname_t **spp, minor_t mnum,
1209 			    int fast, md_error_t *ep);
1210 extern	char		*get_mdname(mdsetname_t *sp, minor_t mnum);
1211 extern	int		metaismeta(mdname_t *np);
1212 extern	int		metachkmeta(mdname_t *np, md_error_t *ep);
1213 extern	int		metachkdisk(mdname_t *np, md_error_t *ep);
1214 extern	int		metachkcomp(mdname_t *np, md_error_t *ep);
1215 extern	void		metafreenamelist(mdnamelist_t *nlp);
1216 extern	int		metanamelist(mdsetname_t **spp, mdnamelist_t **nlpp,
1217 			    int argc, char *argv[], meta_device_type_t type,
1218 			    md_error_t *ep);
1219 extern	mdname_t	*metanamelist_append(mdnamelist_t **nlpp,
1220 			    mdname_t *np);
1221 extern  mdnamelist_t	**meta_namelist_append_wrapper(mdnamelist_t **nlpp,
1222 			    mdname_t *np);
1223 extern	mdhspname_t	*metahspname(mdsetname_t **spp,
1224 			    char *uname, md_error_t *ep);
1225 extern	mdhspname_t	*metahsphspname(mdsetname_t **spp,
1226 			    hsp_t hsp, md_error_t *ep);
1227 extern	char		*get_hspname(mdsetname_t *sp, hsp_t mnum);
1228 extern	void		metafreehspnamelist(mdhspnamelist_t *hspnlp);
1229 extern	int		metahspnamelist(mdsetname_t **spp,
1230 			    mdhspnamelist_t **hspnlpp,
1231 			    int argc, char *argv[], md_error_t *ep);
1232 extern	mdhspname_t	*metahspnamelist_append(mdhspnamelist_t **hspnlp,
1233 			    mdhspname_t *hspnp);
1234 extern	mdname_t	*metadevname(mdsetname_t **spp,
1235 			    md_dev64_t dev, md_error_t *ep);
1236 extern	char		*get_devname(set_t setno, md_dev64_t dev);
1237 extern	mdname_t	*metakeyname(mdsetname_t **spp,
1238 			    mdkey_t key, int fast, md_error_t *ep);
1239 extern	void		metaflushmetanames(void);
1240 extern	void		metaflushnames(int flush_sr_cache);
1241 extern	int		meta_get_hotspare_names(mdsetname_t *sp,
1242 			    mdnamelist_t **nlpp, int options, md_error_t *ep);
1243 extern	void		meta_create_non_dup_list(mdname_t *mdnp,
1244 			    mddevid_t **ldevidpp);
1245 extern	mddrivename_t	*meta_getdnp_bydevid(mdsetname_t *sp, side_t sideno,
1246 			    ddi_devid_t devidp, mdkey_t key, md_error_t *ep);
1247 
1248 
1249 /* meta_nameinfo.c */
1250 extern	mdsetname_t	*metagetset(mdname_t *np, int bypass_daemon,
1251 			    md_error_t *ep);
1252 extern	void		metafreevtoc(mdvtoc_t *vtocp);
1253 extern	int		meta_match_enclosure(mdname_t *, mdcinfo_t *,
1254 			    md_error_t *);
1255 extern	mdvtoc_t	*metagetvtoc(mdname_t *np, int nocache, uint_t *partnop,
1256 			    md_error_t *ep);
1257 extern	int		metasetvtoc(mdname_t *np, md_error_t *ep);
1258 extern	void		metaflushctlrcache(void);
1259 extern	mdgeom_t	*metagetgeom(mdname_t *np, md_error_t *ep);
1260 extern	mdcinfo_t	*metagetcinfo(mdname_t *np, md_error_t *ep);
1261 extern	int		metagetpartno(mdname_t *np, md_error_t *ep);
1262 extern	diskaddr_t	metagetsize(mdname_t *np, md_error_t *ep);
1263 extern	diskaddr_t	metagetlabel(mdname_t *np, md_error_t *ep);
1264 extern	diskaddr_t	metagetstart(mdsetname_t *sp, mdname_t *np,
1265 			    md_error_t *ep);
1266 extern	int		metahasmddb(mdsetname_t *sp, mdname_t *np,
1267 			    md_error_t *ep);
1268 extern	char		*metagetdevicesname(mdname_t *np, md_error_t *ep);
1269 extern	char		*metagetmiscname(mdname_t *np, md_error_t *ep);
1270 extern	md_unit_t	*meta_get_mdunit(mdsetname_t *sp, mdname_t *np,
1271 			    md_error_t *ep);
1272 extern	void		meta_free_unit(mddrivename_t *dnp);
1273 extern	void		meta_invalidate_name(mdname_t *np);
1274 extern	md_common_t	*meta_get_unit(mdsetname_t *sp, mdname_t *np,
1275 			    md_error_t *ep);
1276 extern	int		meta_isopen(mdsetname_t *sp, mdname_t *np,
1277 			    md_error_t *ep, mdcmdopts_t options);
1278 
1279 /* meta_namespace.c */
1280 extern	char		*meta_getnmbykey(set_t setno, side_t sideno,
1281 			    mdkey_t key, md_error_t *ep);
1282 extern	char		*meta_getnmentbykey(set_t setno, side_t sideno,
1283 			    mdkey_t key, char **drvnm, minor_t *mnum,
1284 			    md_dev64_t *dev, md_error_t *ep);
1285 extern	char		*meta_getnmentbydev(set_t setno, side_t sideno,
1286 			    md_dev64_t dev, char **drvnm, minor_t *mnum,
1287 			    mdkey_t *key, md_error_t *ep);
1288 extern	char		*meta_gethspnmentbyid(set_t setno, side_t sideno,
1289 			    hsp_t hspid, md_error_t *ep);
1290 extern	hsp_t		meta_gethspnmentbyname(set_t setno, side_t sideno,
1291 			    char *hspname, md_error_t *ep);
1292 extern	char		*meta_getdidminorbykey(set_t setno, side_t sideno,
1293 			    mdkey_t key, md_error_t *ep);
1294 extern	ddi_devid_t	meta_getdidbykey(set_t setno, side_t sideno,
1295 			    mdkey_t key, md_error_t *ep);
1296 extern	int		meta_setdid(set_t setno, side_t sideno, mdkey_t key,
1297 			    md_error_t *ep);
1298 extern	int		add_name(mdsetname_t *sp, side_t sideno, mdkey_t key,
1299 			    char *dname, minor_t mnum, char *bname,
1300 			    char *minorname, ddi_devid_t devid, md_error_t *ep);
1301 extern	int		del_name(mdsetname_t *sp, side_t sideno, mdkey_t key,
1302 			    md_error_t *ep);
1303 extern	int		add_key_name(mdsetname_t *sp, mdname_t *np,
1304 			    mdnamelist_t **nlpp, md_error_t *ep);
1305 extern	int		del_key_name(mdsetname_t *sp, mdname_t *np,
1306 			    md_error_t *ep);
1307 extern	int		del_key_names(mdsetname_t *sp, mdnamelist_t *nlp,
1308 			    md_error_t *ep);
1309 extern	mdkey_t		add_self_name(mdsetname_t *, char *,
1310 			    md_mkdev_params_t *, md_error_t *);
1311 extern	int		del_self_name(mdsetname_t *, mdkey_t,
1312 			    md_error_t *);
1313 
1314 /* meta_patch.c */
1315 extern	int		meta_patch_vfstab(char *cmpname, mdname_t *fsnp,
1316 			    char *vname, char *old_bdevname, int doit,
1317 			    int verbose, char **tname, md_error_t *ep);
1318 extern	int		meta_patch_fsdev(char *fsname, mdname_t *fsnp,
1319 			    char *vname, md_error_t *ep);
1320 extern	int		meta_patch_swapdev(mdname_t *fsnp,
1321 			    char *vname, char *old_bdevname, md_error_t *ep);
1322 extern	int		meta_patch_mddb(char *sname, char *cname, int patch,
1323 			    md_error_t *ep);
1324 
1325 /* meta_patch_root.c */
1326 extern	int		meta_patch_rootdev(mdname_t *np, char *sname,
1327 			    char *vname, char *cname, char *dbname, int doit,
1328 			    int verbose, md_error_t *ep);
1329 
1330 /* meta_print.c */
1331 extern	int		meta_print_name(mdsetname_t *sp, mdname_t *namep,
1332 			    mdnamelist_t **nlpp, char *fname, FILE *fp,
1333 			    mdprtopts_t options, mdnamelist_t **lognlpp,
1334 			    md_error_t *ep);
1335 extern	int		meta_print_all(mdsetname_t *sp, char *fname,
1336 			    mdnamelist_t **nlpp, FILE *fp,
1337 			    mdprtopts_t options, int *meta_print_trans_msgp,
1338 			    md_error_t *ep);
1339 extern	char		*meta_print_time(md_timeval32_t *timep);
1340 extern	char		*meta_print_hrtime(hrtime_t secs);
1341 extern	int		meta_prbits(FILE *fp, const char *fmt, ...);
1342 extern	char 		*meta_number_to_string(diskaddr_t number,
1343 			    u_longlong_t blk_sz);
1344 extern	int		meta_get_tstate(md_dev64_t dev64, uint_t *tstatep,
1345 			    md_error_t *ep);
1346 extern	int		meta_print_devid(mdsetname_t *sp, FILE *fp,
1347 			    mddevid_t *mddevidp, md_error_t *ep);
1348 
1349 /* meta_raid.c */
1350 extern	int		meta_get_raid_names(mdsetname_t *sp,
1351 			    mdnamelist_t **nlpp, int options, md_error_t *ep);
1352 extern	void		meta_free_raid(md_raid_t *raidp);
1353 extern	md_raid_t	*meta_get_raid_common(mdsetname_t *sp, mdname_t *raidnp,
1354 			    int fast, md_error_t *ep);
1355 extern	md_raid_t	*meta_get_raid(mdsetname_t *sp, mdname_t *raidnp,
1356 			    md_error_t *ep);
1357 extern	int		meta_check_inraid(mdsetname_t *sp, mdname_t *np,
1358 			    diskaddr_t slblk, diskaddr_t nblks, md_error_t *ep);
1359 extern	int		meta_check_column(mdsetname_t *sp, mdname_t *np,
1360 			    md_error_t *ep);
1361 extern	char		*raid_state_to_name(md_raid_t *raidp,
1362 			    md_timeval32_t *tvp, uint_t tstate);
1363 extern	char		*raid_state_to_action(md_raid_t *raidp);
1364 extern	char		*raid_col_state_to_name(md_raidcol_t *colp,
1365 			    md_timeval32_t *tvp, uint_t tstate);
1366 extern	int		meta_print_raid_options(mdhspname_t *hspnamep,
1367 			    char *fname, FILE *fp, md_error_t *ep);
1368 extern	int		meta_raid_print(mdsetname_t *sp, mdname_t *raidnp,
1369 			    mdnamelist_t **nlpp, char *fname, FILE *fp,
1370 			    mdprtopts_t options, md_error_t *ep);
1371 extern	int		meta_raid_attach(mdsetname_t *sp, mdname_t *raidnp,
1372 			    mdnamelist_t *nlp, mdcmdopts_t options,
1373 			    md_error_t *ep);
1374 extern	int		meta_raid_get_params(mdsetname_t *sp, mdname_t *raidnp,
1375 			    mr_params_t *paramsp, md_error_t *ep);
1376 extern	int		meta_raid_set_params(mdsetname_t *sp, mdname_t *raidnp,
1377 			    mr_params_t *paramsp, md_error_t *ep);
1378 extern	int		meta_raid_replace(mdsetname_t *sp, mdname_t *raidnp,
1379 			    mdname_t *oldnp, mdname_t *newnp,
1380 			    mdcmdopts_t options, md_error_t *ep);
1381 extern	int		meta_raid_enable(mdsetname_t *sp, mdname_t *raidnp,
1382 			    mdname_t *compnp, mdcmdopts_t options,
1383 			    md_error_t *ep);
1384 extern	diskaddr_t		meta_default_raid_interlace(void);
1385 extern	int		meta_raid_check_interlace(diskaddr_t interlace,
1386 			    char *uname, md_error_t *ep);
1387 extern	int		meta_check_raid(mdsetname_t *sp, md_raid_t *raidp,
1388 			    mdcmdopts_t options, md_error_t *ep);
1389 extern	int		meta_create_raid(mdsetname_t *sp, md_raid_t *raidp,
1390 			    mdcmdopts_t options, md_error_t *ep);
1391 extern	int		meta_init_raid(mdsetname_t **spp,
1392 			    int argc, char *argv[], mdcmdopts_t options,
1393 			    md_error_t *ep);
1394 extern	int		meta_raid_reset(mdsetname_t *sp, mdname_t *np,
1395 			    mdcmdopts_t options, md_error_t *ep);
1396 extern	int		meta_raid_anycomp_is_err(mdsetname_t *, mdnamelist_t *);
1397 
1398 /* meta_raid_resync.c */
1399 extern	int		meta_raid_resync(mdsetname_t *sp, mdname_t *raidnp,
1400 			    daddr_t size, md_error_t *ep);
1401 extern	int		meta_raid_resync_all(mdsetname_t *sp, daddr_t size,
1402 			    md_error_t *ep);
1403 
1404 extern	int		meta_raid_regen_byname(mdsetname_t *sp,
1405 			    mdname_t *raidnp, diskaddr_t size, md_error_t *ep);
1406 
1407 /* meta_repartition.c */
1408 extern	int		meta_replicaslice(mddrivename_t *dnp,
1409 			    uint_t *slicep, md_error_t *ep);
1410 
1411 /* meta_replace.c */
1412 extern	int		meta_replace_byname(mdsetname_t *sp, mdname_t *namep,
1413 			    mdname_t *oldnp, mdname_t *newnp,
1414 			    mdcmdopts_t options, md_error_t *ep);
1415 extern	int		meta_enable_byname(mdsetname_t *sp, mdname_t *namep,
1416 			    mdname_t *compnp, mdcmdopts_t options,
1417 			    md_error_t *ep);
1418 
1419 /* meta_reset.c */
1420 extern	int		meta_reset(mdsetname_t *sp, mdname_t *np,
1421 			    mdcmdopts_t options, md_error_t *ep);
1422 extern	int		meta_reset_all(mdsetname_t *sp, mdcmdopts_t options,
1423 			    md_error_t *ep);
1424 extern	int		meta_reset_by_name(mdsetname_t *sp, mdname_t *np,
1425 			    mdcmdopts_t options, md_error_t *ep);
1426 
1427 /* meta_resync.c */
1428 extern	int		meta_resync_byname(mdsetname_t *sp, mdname_t *np,
1429 			    daddr_t size, md_error_t *ep, md_resync_cmd_t cmd);
1430 extern	int		meta_resync_all(mdsetname_t *sp, daddr_t size,
1431 			    md_error_t *ep);
1432 
1433 /* meta_set.c */
1434 extern	set_t		get_max_sets(md_error_t *ep);
1435 extern	int		get_max_meds(md_error_t *ep);
1436 extern	side_t		getmyside(mdsetname_t *sp, md_error_t *ep);
1437 extern	md_set_record	*getsetbyname(char *setname, md_error_t *ep);
1438 extern	md_set_record	*getsetbynum(set_t setno, md_error_t *ep);
1439 extern	int		meta_check_drive_inuse(mdsetname_t *sp,
1440 			    mddrivename_t *dnp, int check_db, md_error_t *ep);
1441 extern	int		meta_check_ownership(mdsetname_t *sp, md_error_t *ep);
1442 extern	int		meta_check_ownership_on_host(mdsetname_t *sp,
1443 			    char *hostname, md_error_t *ep);
1444 extern	int		meta_is_member(char *node_name, md_mn_nodeid_t node_id,
1445 			    mndiskset_membershiplist_t *nl);
1446 extern	int		meta_getnextside_devinfo(mdsetname_t *sp, char *bname,
1447 			    side_t *sideno, char **ret_bname, char **ret_dname,
1448 			    minor_t *ret_mnum, md_error_t *ep);
1449 extern	int		meta_getside_devinfo(mdsetname_t *sp, char *bname,
1450 			    side_t sideno, char **ret_bname, char **ret_dname,
1451 			    minor_t *ret_mnum, md_error_t *ep);
1452 extern	int		meta_is_drive_in_anyset(mddrivename_t *dnp,
1453 			    mdsetname_t **spp, int bypass_daemon,
1454 			    md_error_t *ep);
1455 extern	int		meta_is_drive_in_thisset(mdsetname_t *sp,
1456 			    mddrivename_t *dnp, int bypass_daemon,
1457 			    md_error_t *ep);
1458 extern	int		meta_is_devid_in_anyset(void *devid,
1459 			    mdsetname_t **spp, md_error_t *ep);
1460 extern	int		meta_is_devid_in_thisset(mdsetname_t *sp,
1461 			    void *devid, md_error_t *ep);
1462 extern	int		meta_set_balance(mdsetname_t *sp, md_error_t *ep);
1463 extern	int		meta_set_destroy(mdsetname_t *sp, int lock_set,
1464 			    md_error_t *ep);
1465 extern	int		meta_set_purge(mdsetname_t *sp, int bypass_cluster,
1466 			    int forceflg, md_error_t *ep);
1467 extern	int		meta_set_query(mdsetname_t *sp, mddb_dtag_lst_t **dtlpp,
1468 			    md_error_t *ep);
1469 extern	mddrivename_t	*metadrivename_withdrkey(mdsetname_t *sp,
1470 			    side_t sideno, mdkey_t key, int flags,
1471 			    md_error_t *ep);
1472 extern	void		metafreedrivedesc(md_drive_desc **dd);
1473 extern	md_drive_desc	*metaget_drivedesc(mdsetname_t *sp, int flags,
1474 			    md_error_t *ep);
1475 extern	md_drive_desc	*metaget_drivedesc_fromnamelist(mdsetname_t *sp,
1476 			    mdnamelist_t *nlp, md_error_t *ep);
1477 extern	md_drive_desc	*metaget_drivedesc_sideno(mdsetname_t *sp,
1478 			    side_t sideno, int flags, md_error_t *ep);
1479 extern	int		metaget_setownership(mdsetname_t *sp, md_error_t *ep);
1480 extern	char		*mynode(void);
1481 extern	int		strinlst(char *str, int cnt, char **lst);
1482 extern	int		meta_get_reserved_names(mdsetname_t *sp,
1483 			    mdnamelist_t **nlpp, int options, md_error_t *ep);
1484 extern	int		meta_set_join(mdsetname_t *sp, md_error_t *ep);
1485 extern	int		meta_set_withdraw(mdsetname_t *sp, md_error_t *ep);
1486 extern	int		meta_reconfig_choose_master();
1487 extern	int		meta_mnsync_user_records(mdsetname_t *sp,
1488 			    md_error_t *ep);
1489 extern	int		meta_mnsync_diskset_mddbs(mdsetname_t *sp,
1490 			    md_error_t *ep);
1491 extern	int		meta_mnjoin_all(mdsetname_t *sp, md_error_t *ep);
1492 extern	int		meta_getandsetmaster(mdsetname_t *sp,
1493 			    md_mnset_record *mnsr, md_set_desc *sd,
1494 			    md_error_t *ep);
1495 extern	int		meta_devid_use(md_error_t *ep);
1496 
1497 /* meta_set_drv.c */
1498 extern	int		meta_make_sidenmlist(mdsetname_t *,
1499 			    mddrivename_t *, int imp_flag,
1500 			    md_im_drive_info_t *midp, md_error_t *);
1501 extern	int		meta_set_adddrives(mdsetname_t *sp,
1502 			    mddrivenamelist_t *dnlp, daddr_t dbsize,
1503 			    int force_label, md_error_t *ep);
1504 extern	int		meta_set_deletedrives(mdsetname_t *sp,
1505 			    mddrivenamelist_t *dnlp, int forceflg,
1506 			    md_error_t *ep);
1507 
1508 /* meta_set_hst.c */
1509 extern	int		meta_set_checkname(char *setname, md_error_t *ep);
1510 extern	int		meta_set_addhosts(mdsetname_t *sp, int multi_node,
1511 			    int node_c, char **node_v, int auto_take,
1512 			    md_error_t *ep);
1513 extern	int		meta_set_deletehosts(mdsetname_t *sp, int node_c,
1514 			    char **node_v, int forceflg, md_error_t *ep);
1515 extern	int		meta_set_auto_take(mdsetname_t *sp, int take_val,
1516 			    md_error_t *ep);
1517 
1518 /* meta_set_med.c */
1519 extern	int		meta_set_addmeds(mdsetname_t *sp, int node_c,
1520 			    char **node_v, md_error_t *ep);
1521 extern	int		meta_set_deletemeds(mdsetname_t *sp, int node_c,
1522 			    char **node_v, int forceflg, md_error_t *ep);
1523 
1524 /* meta_set_tkr.c */
1525 extern	int		meta_set_take(mdsetname_t *sp, mhd_mhiargs_t *mhiargsp,
1526 			    int flags, int usetag, md_error_t *ep);
1527 extern	int		meta_set_release(mdsetname_t *sp, md_error_t *ep);
1528 extern	int		meta_update_mb(mdsetname_t *sp, md_drive_desc *dd,
1529 			    md_error_t *ep);
1530 
1531 /* meta_setup.c */
1532 extern	char		*myname;
1533 extern	FILE		*metalogfp;
1534 extern	int		metasyslog;
1535 extern	uint_t		verbosity;
1536 extern	hrtime_t	start_time;
1537 extern	sigset_t	allsigs;
1538 #define	ANYSIG		allsigs
1539 extern	char		*meta_lock_name(set_t setno);
1540 extern	int		meta_unlock(mdsetname_t *sp, md_error_t *ep);
1541 extern	int		meta_lock(mdsetname_t *sp, int print_status,
1542 			    md_error_t *ep);
1543 extern	int		meta_lock_nowait(mdsetname_t *sp, md_error_t *ep);
1544 extern	int		meta_lock_status(mdsetname_t *sp, md_error_t *ep);
1545 extern	int		md_daemonize(mdsetname_t *sp, md_error_t *ep);
1546 extern	void		md_exit(mdsetname_t *sp, int eval);
1547 extern	void		md_post_sig(int sig);
1548 extern	int		md_got_sig(void);
1549 extern	int		md_which_sig(void);
1550 extern	void		md_rb_sig_handling_on(void);
1551 extern	void		md_rb_sig_handling_off(int sig_seen, int sig);
1552 extern	void		setup_mc_log(uint_t level);
1553 extern	int		md_init(int argc, char *argv[],
1554 			    int dosyslog, int doadmin, md_error_t *ep);
1555 extern	int		md_init_nosig(int argc, char *argv[],
1556 			    int dosyslog, int doadmin, md_error_t *ep);
1557 
1558 extern	int		md_init_daemon(char *name, md_error_t *ep);
1559 
1560 /* meta_smf.c */
1561 extern	int		meta_smf_enable(uint_t flags, md_error_t *ep);
1562 extern	int		meta_smf_disable(uint_t flags, md_error_t *ep);
1563 extern	int		meta_smf_isonline(uint_t flags, md_error_t *ep);
1564 extern	int		meta_smf_getmask();
1565 
1566 /* meta_sp.c */
1567 extern	int		meta_get_sp_names(mdsetname_t *sp, mdnamelist_t **nlpp,
1568 			    int options, md_error_t *ep);
1569 extern	int		meta_check_insp(mdsetname_t *sp, mdname_t *np,
1570 			    diskaddr_t slblk, diskaddr_t nblks, md_error_t *ep);
1571 extern	int		meta_sp_print(mdsetname_t *sp, mdname_t *np,
1572 			    mdnamelist_t **nlpp, char *fname, FILE *fp,
1573 			    mdprtopts_t options, md_error_t *ep);
1574 extern	md_sp_t		*meta_get_sp_common(mdsetname_t *sp, mdname_t *np,
1575 			    int fast, md_error_t *ep);
1576 extern	md_sp_t		*meta_get_sp(mdsetname_t *sp, mdname_t *np,
1577 			    md_error_t *ep);
1578 extern	int		meta_init_sp(mdsetname_t **spp, int argc, char *argv[],
1579 			    mdcmdopts_t options, md_error_t *ep);
1580 extern	void		meta_free_sp(md_sp_t *spp);
1581 extern	int		meta_sp_issp(mdsetname_t *sp, mdname_t *np,
1582 			    md_error_t *ep);
1583 extern	int		meta_sp_reset(mdsetname_t *sp, mdname_t *np,
1584 			    mdcmdopts_t options, md_error_t *ep);
1585 extern	int		meta_sp_reset_component(mdsetname_t *sp, char *name,
1586 			    mdcmdopts_t options, md_error_t *ep);
1587 extern	int		meta_sp_attach(mdsetname_t *sp, mdname_t *np,
1588 			    char *addsize, mdcmdopts_t options,
1589 			    sp_ext_length_t alignment, md_error_t *ep);
1590 extern	int		meta_recover_sp(mdsetname_t *sp, mdname_t *np, int argc,
1591 			    char *argv[], mdcmdopts_t options, md_error_t *ep);
1592 extern boolean_t	meta_sp_can_create_sps(mdsetname_t *mdsetnamep,
1593 				mdname_t *mdnamep, int number_of_sps,
1594 				blkcnt_t sp_size);
1595 extern boolean_t	meta_sp_can_create_sps_on_drive(mdsetname_t *mdsetnamep,
1596 				mddrivename_t *mddrivenamep, int number_of_sps,
1597 				blkcnt_t sp_size);
1598 extern blkcnt_t		meta_sp_get_free_space(mdsetname_t *mdsetnamep,
1599 				mdname_t *mdnamep);
1600 extern blkcnt_t		meta_sp_get_free_space_on_drive(mdsetname_t *mdsetnamep,
1601 				mddrivename_t *mddrivenamep);
1602 extern int 		meta_sp_get_number_of_possible_sps(
1603 				mdsetname_t *mdsetnamep, mdname_t *mdnamep,
1604 				blkcnt_t sp_size);
1605 extern int 		meta_sp_get_number_of_possible_sps_on_drive(
1606 				mdsetname_t *mdsetnamep,
1607 				mddrivename_t *mddrivenamep, blkcnt_t sp_size);
1608 extern blkcnt_t		meta_sp_get_possible_sp_size(mdsetname_t *mdsetnamep,
1609 				mdname_t *mdnamep, int number_of_sps);
1610 extern blkcnt_t		meta_sp_get_possible_sp_size_on_drive(
1611 				mdsetname_t *mdsetnamep,
1612 				mddrivename_t *mddrivenamep, int number_of_sps);
1613 extern int		meta_sp_setstatus(mdsetname_t *sp, minor_t *minors,
1614 			    int num_units, sp_status_t status, md_error_t *ep);
1615 extern int		meta_sp_parsesize(char *s, sp_ext_length_t *szp);
1616 extern int		meta_sp_update_abr(mdsetname_t *sp, md_error_t *ep);
1617 extern void		*meta_mn_sp_update_abr(void *arg);
1618 
1619 /* meta_stat.c */
1620 extern	int		meta_stat(const char *, struct stat *);
1621 extern	void		metaflushstatcache(void);
1622 
1623 /* meta_stripe.c */
1624 extern	int		meta_stripe_replace(mdsetname_t *sp, mdname_t *stripenp,
1625 			    mdname_t *oldnp, mdname_t *newnp,
1626 			    mdcmdopts_t options, md_error_t *ep);
1627 extern	int		meta_get_stripe_names(mdsetname_t *sp,
1628 			    mdnamelist_t **nlpp, int options, md_error_t *ep);
1629 extern	void		meta_free_stripe(md_stripe_t *stripep);
1630 extern	md_stripe_t	*meta_get_stripe_common(mdsetname_t *sp,
1631 			    mdname_t *stripenp, int fast, md_error_t *ep);
1632 extern	md_stripe_t	*meta_get_stripe(mdsetname_t *sp, mdname_t *stripenp,
1633 			    md_error_t *ep);
1634 extern	int		meta_check_instripe(mdsetname_t *sp, mdname_t *np,
1635 			    diskaddr_t slblk, diskaddr_t nblks, md_error_t *ep);
1636 extern	int		meta_check_component(mdsetname_t *sp, mdname_t *np,
1637 			    int force, md_error_t *ep);
1638 extern	char		*comp_state_to_name(md_comp_t *mdcp,
1639 			    md_timeval32_t *tvp, uint_t tstate);
1640 extern	int		meta_print_stripe_options(mdhspname_t *hspnamep,
1641 			    char *fname, FILE *fp, md_error_t *ep);
1642 extern	int		meta_stripe_print(mdsetname_t *sp, mdname_t *stripenp,
1643 			    mdnamelist_t **nlpp, char *fname, FILE *fp,
1644 			    mdprtopts_t options, md_error_t *ep);
1645 extern	int		meta_find_erred_comp(mdsetname_t *sp,
1646 			    mdname_t *stripenp, mdname_t **compnpp,
1647 			    comp_state_t *compstate, md_error_t *ep);
1648 extern	int		meta_stripe_attach(mdsetname_t *sp, mdname_t *stripenp,
1649 			    mdnamelist_t *nlp, diskaddr_t interlace,
1650 			    mdcmdopts_t options, md_error_t *ep);
1651 extern	int		meta_stripe_get_params(mdsetname_t *sp,
1652 			    mdname_t *stripenp, ms_params_t *paramsp,
1653 			    md_error_t *ep);
1654 extern	int		meta_stripe_set_params(mdsetname_t *sp,
1655 			    mdname_t *stripenp, ms_params_t *paramsp,
1656 			    md_error_t *ep);
1657 extern	diskaddr_t		meta_default_stripe_interlace(void);
1658 extern	int		meta_stripe_check_interlace(diskaddr_t interlace,
1659 				char *uname, md_error_t *ep);
1660 extern	int		meta_check_stripe(mdsetname_t *sp,
1661 			    md_stripe_t *stripep, mdcmdopts_t options,
1662 			    md_error_t *ep);
1663 extern	int		meta_create_stripe(mdsetname_t *sp,
1664 			    md_stripe_t *stripep, mdcmdopts_t options,
1665 			    md_error_t *ep);
1666 extern	int		meta_init_stripe(mdsetname_t **spp,
1667 			    int argc, char *argv[], mdcmdopts_t options,
1668 			    md_error_t *ep);
1669 extern	int		meta_stripe_reset(mdsetname_t *sp, mdname_t *stripenp,
1670 			    mdcmdopts_t options, md_error_t *ep);
1671 extern	int		meta_stripe_anycomp_is_err(mdsetname_t *,
1672 			    mdnamelist_t *);
1673 
1674 /* meta_systemfile.c */
1675 extern	int		meta_systemfile_copy(char *sname, int doroot,
1676 			    int domddb, int doit, int verbose, char **tname,
1677 			    FILE **tfp, md_error_t *ep);
1678 extern	int		meta_systemfile_append_mdroot(mdname_t *rootnp,
1679 			    char *sname, char *tname, FILE *tfp, int ismeta,
1680 			    int doit, int verbose, md_error_t *ep);
1681 extern	int		meta_systemfile_append_mddb(char *cname, char *sname,
1682 			    char *tname, FILE *tfp, int doit, int verbose,
1683 			    int check, md_error_t *ep);
1684 
1685 /* meta_tab.c */
1686 extern	void		meta_tab_dump(md_tab_t *tabp, FILE *fp);
1687 extern	void		meta_tab_free(md_tab_t *tabp);
1688 extern	md_tab_t	*meta_tab_parse(char *filename, md_error_t *ep);
1689 extern	md_tab_line_t	*meta_tab_find(mdsetname_t *sp, md_tab_t *tabp,
1690 			    char *name, mdinittypes_t type);
1691 
1692 /* meta_trans.c */
1693 extern	int		meta_trans_replace(mdsetname_t *sp, mdname_t *transnp,
1694 			    mdname_t *oldnp, mdname_t *newnp,
1695 			    mdcmdopts_t options, md_error_t *ep);
1696 extern	int		meta_get_trans_names(mdsetname_t *sp,
1697 			    mdnamelist_t **nlpp, int options, md_error_t *ep);
1698 extern	void		meta_free_trans(md_trans_t *transp);
1699 extern	md_trans_t	*meta_get_trans(mdsetname_t *sp, mdname_t *transnp,
1700 			    md_error_t *ep);
1701 extern	md_trans_t	*meta_get_trans_common(mdsetname_t *sp,
1702 			    mdname_t *transnp, int fast, md_error_t *ep);
1703 extern	int		meta_check_intrans(mdsetname_t *sp, mdname_t *np,
1704 			    mdchkopts_t options, diskaddr_t slblk,
1705 			    diskaddr_t nblks, md_error_t *ep);
1706 extern	int		meta_check_master(mdsetname_t *sp, mdname_t *np,
1707 			    int force, md_error_t *ep);
1708 extern	int		meta_check_log(mdsetname_t *sp, mdname_t *np,
1709 			    md_error_t *ep);
1710 extern	char		*mt_l_error_to_name(md_trans_t *transp,
1711 			    md_timeval32_t *tvp, uint_t tstate);
1712 extern	char		*mt_flags_to_name(md_trans_t *transp,
1713 			    md_timeval32_t *tvp, uint_t tstate);
1714 extern	char		*mt_flags_to_action(md_trans_t *transp);
1715 extern	char		*mt_l_error_to_action(
1716 				mdsetname_t	*sp,
1717 				mdnamelist_t	*transnlp,
1718 				mdname_t	*lognamep,
1719 				md_error_t	*ep);
1720 extern	int		meta_trans_print(mdsetname_t *sp, mdname_t *transnp,
1721 			    mdnamelist_t **nlistpp, char *fname, FILE *fp,
1722 			    mdprtopts_t options, int *meta_print_trans_msgp,
1723 			    mdnamelist_t **lognlpp, md_error_t *ep);
1724 extern	int		meta_logs_print(mdsetname_t *sp, mdnamelist_t *lognlp,
1725 			    mdnamelist_t **nlistpp, char *fname, FILE *fp,
1726 			    mdprtopts_t options, md_error_t *ep);
1727 extern	int		meta_trans_attach(mdsetname_t *sp, mdname_t *transnp,
1728 			    mdname_t *lognp, mdcmdopts_t options,
1729 			    md_error_t *ep);
1730 extern	int		meta_trans_detach(mdsetname_t *sp, mdname_t *transnp,
1731 			    mdcmdopts_t options, int *delayed, md_error_t *ep);
1732 extern	int		meta_check_trans(mdsetname_t *sp, md_trans_t *transp,
1733 			    mdcmdopts_t options, md_error_t *ep);
1734 extern	int		meta_create_trans(mdsetname_t *sp, md_trans_t *transp,
1735 			    mdcmdopts_t options, char *uname, md_error_t *ep);
1736 extern	int		meta_init_trans(mdsetname_t **spp,
1737 			    int argc, char *argv[], mdcmdopts_t options,
1738 			    md_error_t *ep);
1739 extern	int		meta_trans_reset(mdsetname_t *sp, mdname_t *transnp,
1740 			    mdcmdopts_t options, md_error_t *ep);
1741 
1742 /* meta_userflags.c */
1743 extern int		meta_getuserflags(mdsetname_t *sp, mdname_t *np,
1744 			    uint_t *userflags, md_error_t *ep);
1745 extern int		meta_setuserflags(mdsetname_t *sp, mdname_t *np,
1746 			    uint_t userflags, md_error_t *ep);
1747 
1748 /* metarpcopen.c */
1749 extern CLIENT		*meta_client_create_retry(char *hostname,
1750 				clnt_create_func_t func, void *data,
1751 				time_t tout, md_error_t *ep);
1752 extern	CLIENT		*meta_client_create(char *host, rpcprog_t prognum,
1753 				rpcvers_t version, char *nettype);
1754 extern	CLIENT		*metarpcopen(char *hostname, long time_out,
1755 			    md_error_t *ep);
1756 extern	void		metarpcclose(CLIENT *clntp);
1757 extern	void		metarpccloseall(void);
1758 
1759 /* metasplitname.c */
1760 extern	int		splitname(char *devname, md_splitname *splitname);
1761 extern	char		*splicename(md_splitname *splitname);
1762 
1763 /* meta_notify.c */
1764 extern	int		meta_notify_createq(char *qname, ulong_t flags,
1765 			    md_error_t *ep);
1766 extern	int		meta_notify_deleteq(char *qname, md_error_t *ep);
1767 extern	int		meta_notify_validq(char *qname, md_error_t *ep);
1768 extern	int		meta_notify_listq(char ***qnames, md_error_t *ep);
1769 extern	int		meta_notify_flushq(char *qname, md_error_t *ep);
1770 
1771 extern	int		meta_notify_getev(char *qname, ulong_t flags,
1772 			    md_ev_t *evp, md_error_t *ep);
1773 extern	int		meta_notify_getevlist(char *qname, ulong_t flags,
1774 			    md_evlist_t **evlpp, md_error_t *ep);
1775 extern	int		meta_notify_putev(md_ev_t *evp, md_error_t *ep);
1776 extern	int		meta_notify_putevlist(md_evlist_t *evlistp,
1777 			    md_error_t *ep);
1778 extern	void		meta_notify_freeevlist(md_evlist_t *evlp);
1779 
1780 extern	int		meta_notify_sendev(ev_obj_t tag, set_t set,
1781 			    md_dev64_t dev, evid_t event);
1782 
1783 extern	int		meta_exchange(mdsetname_t *, mdname_t *, mdname_t *,
1784 			    mdcmdopts_t, md_error_t *);
1785 extern	int		meta_rename(mdsetname_t *, mdname_t *, mdname_t *,
1786 			    mdcmdopts_t, md_error_t *);
1787 /* meta_se_notify.c */
1788 extern  void		meta_svm_sysevent(char *se_class, char *se_subclass,
1789 			    uint32_t tag, set_t setno, md_dev64_t devid);
1790 
1791 /* metgetroot.c */
1792 extern  void		*meta_get_current_root(md_error_t *ep);
1793 extern  mdname_t	*meta_get_current_root_dev(mdsetname_t *sp,
1794 			    md_error_t *ep);
1795 
1796 /* meta_time.c */
1797 extern  int		meta_gettimeofday(md_timeval32_t *tv);
1798 
1799 /* meta_devadm.c */
1800 extern	int		meta_fixdevid(mdsetname_t *sp, mddevopts_t options,
1801 			    char *diskname, md_error_t *ep);
1802 extern	int		meta_upd_ctdnames(mdsetname_t **sp, set_t setno,
1803 			    side_t sideno, mddrivename_t *dnp, char **newname,
1804 			    md_error_t *ep);
1805 extern  int		pathname_reload(mdsetname_t **sp, set_t setno,
1806 			    md_error_t *ep);
1807 extern	int		meta_update_devtree(minor_t mnum);
1808 
1809 /* meta_mn_comm.c */
1810 extern int		mdmn_send_message(set_t setno, md_mn_msgtype_t type,
1811 			    uint_t flags, char *data, int size,
1812 			    md_mn_result_t **resp, md_error_t *ep);
1813 extern int		mdmn_send_message_with_msgid(set_t setno,
1814 			    md_mn_msgtype_t type, uint_t flags, char *data,
1815 			    int size, md_mn_result_t **resp,
1816 			    md_mn_msgid_t *msgid, md_error_t *ep);
1817 extern int		mdmn_create_msgid(md_mn_msgid_t *id);
1818 extern int		mdmn_reinit_set(set_t setno);
1819 extern int		mdmn_resume(set_t setno, md_mn_msgclass_t class,
1820 			    uint_t flags);
1821 extern int		mdmn_suspend(set_t setno, md_mn_msgclass_t class);
1822 extern int		mdmn_msgtype_lock(md_mn_msgtype_t msgtype,
1823 			    uint_t locktype);
1824 extern void		mdmn_abort(void);
1825 extern md_mn_result_t	*copy_result(md_mn_result_t *res);
1826 extern void		free_result(md_mn_result_t *res);
1827 extern md_mn_msg_t	*copy_msg(md_mn_msg_t *src, md_mn_msg_t *dest);
1828 
1829 /* meta_import.c */
1830 extern	int		read_master_block(md_error_t *ep, int fd, void *bp,
1831 			    int bsize);
1832 extern	int		read_database_block(md_error_t *, int, mddb_mb_t *, int,
1833 			    void *, int);
1834 extern	daddr_t		getphysblk(mddb_block_t, mddb_mb_t *);
1835 
1836 extern	md_im_drive_info_t	*pick_good_disk(md_im_set_desc_t *misp);
1837 
1838 extern	void		meta_unrslv_replicated_mb(mdsetname_t *sp,
1839 			    md_drive_desc *dd, mddrivenamelist_t *dnlp,
1840 			    md_error_t *ep);
1841 extern	void		meta_unrslv_replicated_nm(mdsetname_t *sp,
1842 			    md_drive_desc *dd, mddrivenamelist_t *dnlp,
1843 			    md_error_t *ep);
1844 extern  void *		replicated_list_lookup(uint_t devid_len,
1845 			    void *old_devid);
1846 extern  int		build_replicated_disks_list(md_error_t *ep,
1847 			    mddrivenamelist_t *dnlp);
1848 
1849 /*
1850  * pnm_rec is used to store the mapping from keys in the NM namespace
1851  * to actual physical devices.  The current name of a physical device, used
1852  * by a set that can be imported, can be retrieved by matching the did_key
1853  * (deviceID entry) in the DID_SHR_NM namespace to the min_devid_key in the
1854  * DID_NM namespace(the did_key to the min_key).  Then matching the min_key
1855  * in the DID_NM namespace to the n_key in the NM namespace.
1856  *
1857  * n_name is defined to be an array, so that only one malloc is needed for the
1858  * entire datastructure.
1859  */
1860 typedef struct pnm_rec {
1861 	mdkey_t		n_key;  /* The n_key/min_key value */
1862 	struct pnm_rec	*next;
1863 	ushort_t	n_namlen;
1864 	char		n_name[1]; /* The name of the physical device */
1865 } pnm_rec_t;
1866 
1867 /* Indentation value for metaimport output */
1868 #define	META_INDENT			4
1869 
1870 /* Flags for metaimport reporting */
1871 #define	META_IMP_REPORT		0x0001
1872 #define	META_IMP_VERBOSE	0x0002
1873 #define	META_IMP_PASS1		0x1000
1874 
1875 extern	int			meta_list_disks(md_error_t *, md_im_names_t *);
1876 extern	mddrivenamelist_t	*meta_prune_cnames(md_error_t *,
1877 				    md_im_names_t *, int);
1878 extern	int			meta_get_and_report_set_info(
1879 				    mddrivenamelist_t *, md_im_set_desc_t **,
1880 				    int, uint_t, int *, int,
1881 				    md_im_drive_info_t *, md_error_t *);
1882 extern	void			free_pnm_rec_list(pnm_rec_t **);
1883 extern	int			meta_imp_set(md_im_set_desc_t *,
1884 				    char *, int, bool_t, md_error_t *);
1885 extern	int			meta_imp_drvused(mdsetname_t *sp,
1886 				    mddrivename_t *dnp, md_error_t *ep);
1887 extern	int			meta_replica_quorum(md_im_set_desc_t *misp);
1888 extern	int			meta_imp_set_adddrives(mdsetname_t *sp,
1889 				    mddrivenamelist_t *dnlp,
1890 				    md_im_set_desc_t *misp, md_error_t *ep);
1891 extern	void			meta_free_im_set_desc(md_im_set_desc_t *misp);
1892 extern	int			clnt_imp_adddrvs(char *hostname,
1893 				    mdsetname_t *sp, md_drive_desc *dd,
1894 				    md_timeval32_t timestamp,
1895 				    ulong_t genid, md_error_t *ep);
1896 
1897 /* Flags for direction in copy_msg_1 */
1898 #define	MD_MN_COPY_TO_ONDISK 0x0001
1899 #define	MD_MN_COPY_TO_INCORE 0x0002
1900 
1901 extern void		copy_msg_1(md_mn_msg_t *incorep,
1902 			    md_mn_msg_od_t *ondiskp, int direction);
1903 extern void		free_msg(md_mn_msg_t *msg);
1904 
1905 extern md_mn_msgclass_t	mdmn_get_message_class(md_mn_msgtype_t msgtype);
1906 extern void		(*mdmn_get_handler(md_mn_msgtype_t msgtype))
1907 			    (md_mn_msg_t *msg, uint_t flags,
1908 			    md_mn_result_t *res);
1909 extern int		(*mdmn_get_submessage_generator(md_mn_msgtype_t type))
1910 			    (md_mn_msg_t *msg, md_mn_msg_t **msglist);
1911 extern time_t		mdmn_get_timeout(md_mn_msgtype_t msgtype);
1912 
1913 extern	int		meta_read_nodelist(int *nodecnt,
1914 			    mndiskset_membershiplist_t **nl, md_error_t *ep);
1915 extern	int		meta_write_nodelist(int nodecnt, char **nids,
1916 			    md_error_t *ep);
1917 extern	void		meta_free_nodelist(mndiskset_membershiplist_t *nl);
1918 
1919 /* meta_mn_subr.c */
1920 /* defines for flags argument for meta_mn_send_command() */
1921 #define	MD_DISP_STDERR			0x0000
1922 #define	MD_IGNORE_STDERR		0x0001
1923 #define	MD_DRYRUN			0x0002
1924 #define	MD_RETRY_BUSY			0x0004
1925 #define	MD_NOLOG			0x0008
1926 #define	MD_PANIC_WHEN_INCONSISTENT	0x0010
1927 
1928 /* define for initall_context argument for meta_mn_send_command() */
1929 #define	NO_CONTEXT_STRING	NULL
1930 
1931 extern int		meta_is_mn_set(mdsetname_t *sp, md_error_t *ep);
1932 extern int		meta_is_mn_name(mdsetname_t **sp, char *name,
1933 			    md_error_t *ep);
1934 extern void		meta_ping_mnset(set_t setno);
1935 extern int		meta_mn_send_command(mdsetname_t *sp, int argc,
1936 			    char *argv[], int flags, char *initall_context,
1937 			    md_error_t *ep);
1938 extern int		meta_mn_send_suspend_writes(minor_t mnum,
1939 			    md_error_t *ep);
1940 extern int		meta_mn_send_setsync(mdsetname_t *sp,
1941 			    mdname_t *mirnp, daddr_t size, md_error_t *ep);
1942 extern int		meta_mn_send_metaclear_command(mdsetname_t *sp,
1943 			    char *name, mdcmdopts_t options, int pflag,
1944 			    md_error_t *ep);
1945 extern int		meta_mn_send_resync_starting(mdname_t *mirnp,
1946 			    md_error_t *ep);
1947 extern int		meta_mn_change_owner(md_set_mmown_params_t **opp,
1948 			    set_t setno, uint_t mnum, uint_t owner,
1949 			    uint_t flags);
1950 extern int		meta_mn_singlenode(void);
1951 extern int		meta_mn_send_get_tstate(md_dev64_t dev, uint_t *tstatep,
1952 			    md_error_t *ep);
1953 /* meta_set_prv.c */
1954 extern int		setup_db_bydd(mdsetname_t *sp, md_drive_desc *dd,
1955 			    int force, md_error_t *ep);
1956 extern int		snarf_set(mdsetname_t *sp, bool_t stale_bool,
1957 			    md_error_t *ep);
1958 extern int		halt_set(mdsetname_t *sp, md_error_t *ep);
1959 
1960 /* meta_statconcise.c */
1961 extern  void		print_concise_entry(int indent, char *name,
1962 			    diskaddr_t size, char mtype);
1963 extern	char		*meta_get_raid_col_state(rcs_state_t);
1964 extern	char		*meta_get_stripe_state(comp_state_t);
1965 extern	char		*meta_get_hs_state(hotspare_states_t);
1966 extern	int		report_metastat_info(mddb_mb_t *, mddb_lb_t *,
1967 			    mddb_rb_t *, pnm_rec_t **, mdname_t *, int,
1968 			    md_timeval32_t *, md_error_t *);
1969 
1970 #ifdef	__cplusplus
1971 }
1972 #endif
1973 
1974 #endif	/* _META_H */
1975