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