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