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