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