xref: /titanic_41/usr/src/uts/common/sys/lvm/mdvar.h (revision 70025d765b044c6d8594bb965a2247a61e991a99)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_MDVAR_H
28 #define	_SYS_MDVAR_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/kmem.h>
34 #include <sys/mkdev.h>
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/t_lock.h>
38 #include <sys/open.h>
39 #include <sys/devops.h>
40 #include <sys/modctl.h>
41 #ifdef	DEBUG
42 #include <sys/thread.h>
43 #endif
44 #include <sys/kstat.h>
45 #include <sys/efi_partition.h>
46 #include <sys/byteorder.h>
47 #include <sys/door.h>
48 
49 #include <sys/lvm/mdmn_commd.h>
50 #include <sys/lvm/mdio.h>
51 #include <sys/lvm/md_mdiox.h>
52 #include <sys/lvm/md_mddb.h>
53 #include <sys/lvm/md_notify.h>
54 
55 #ifdef	__cplusplus
56 extern "C" {
57 #endif
58 
59 /*
60  * defaults
61  */
62 #define	NMD_DEFAULT		128	/* number of metadevices */
63 #define	MD_NOPS			25	/* number of misc modules */
64 #define	MAXBOOTLIST		64
65 
66 /*
67  * Needed for backwards-compatibility with metadevices created under
68  * 2.6 or earlier.  Back then, a krwlock_t was twelve bytes.  More
69  * recently, it's four bytes.  Since these get included in structures
70  * written out to disk, we have to make sure we're using the largest
71  * size.  Things will get interesting if krwlock_t ever gets bigger
72  * than twelve bytes.
73  */
74 
75 typedef union _md_krwlock {
76 	krwlock_t	lock;
77 	struct {
78 		void	*_opaque[3];
79 	} xx;
80 } md_krwlock_t;
81 
82 typedef struct {
83 	kmutex_t	md_io_mx;		/* counter mutex */
84 	kcondvar_t	md_io_cv;		/* ioctl wait on if draining */
85 	long		io_cnt;			/* number of I/Os */
86 	long		io_state;		/* !0 if waiting on zero */
87 } md_set_io_t;
88 
89 typedef enum set_iostate {
90 	MD_SET_ACTIVE = 1,
91 	MD_SET_RELEASE = 2
92 }set_iostate_t;
93 
94 /*
95  * for md_dev64_t translation
96  */
97 struct md_xlate_table {
98 	dev32_t		mini_devt;
99 	dev32_t		targ_devt;
100 };
101 
102 extern struct md_xlate_table	*md_tuple_table;
103 
104 /*
105  * for major number translation
106  */
107 
108 struct md_xlate_major_table {
109 	char		*drv_name;
110 	major_t		targ_maj;
111 };
112 
113 extern struct md_xlate_major_table *md_major_tuple_table;
114 
115 extern int	md_tuple_length;
116 extern uint_t	md_majortab_len;
117 extern int	md_in_upgrade;
118 
119 extern md_mn_nodeid_t	md_mn_mynode_id;
120 
121 #define	MD_UPGRADE (md_in_upgrade == 1)
122 
123 /*
124  * Flags used during upgrade:
125  *
126  * md_keep_repl_state flag means that mddb should be kept in the format
127  *   that was found on disk (non-device id format vs. device id format).
128  *   This is used during the upgrade process when install is probing
129  *   for root disks so that the user can choose the one to be upgraded.
130  *
131  * md_devid_destroy flag is used to destroy device ids stored in the
132  *   metadevice state database (mddb).
133  *
134  *   The md_devid_destroy flag is to be used only in a catastrophic failure
135  *   case. An example of this would be if a user upgrades firmware on all
136  *   disks where this causes the disks to now have different device id's.
137  *   The user would not be able to boot a mirror'd root filesystem since the
138  *   system would recognize none of the device id's stored in the mddb.
139  *   This flag would destroy all device id information stored in the mddb and
140  *   if the md_keep_repl_state flag was not set, the mddb would be reconverted
141  *   to device id format on SLVM startup and all of the device id
142  *   information would be regenerated.
143  *
144  *   If the md_devid_destroy flag is set and the md_keep_repl_state flag is
145  *   set, the mddb's would have their device id information destroyed and
146  *   would be left in non-devid format since the device id information would
147  *   not be regenerated.
148  *
149  *   This flag is not documented anywhere and is only to be used as a last
150  *   resort as in the described case or if a device driver has a bug where
151  *   device id's are found to not be unique.  If device id's aren't unique,
152  *   the user could run without device id's until a patch is released for
153  *   that driver.
154  */
155 extern int	md_keep_repl_state;
156 extern int	md_devid_destroy;
157 extern int	mdmn_door_did;
158 #ifdef _KERNEL
159 extern door_handle_t	mdmn_door_handle;
160 #endif /* _KERNEL */
161 
162 /*
163  * An io_lock mechanism for raid, the MD_UL_XXXX bits are used for
164  * convenience.
165  */
166 typedef struct md_io_lock {
167 	ulong_t		io_readercnt;	/* number of unit readers */
168 	ulong_t		io_wanabecnt;	/* # pending on becoming unit writer */
169 	ulong_t		io_lock;
170 	void		*io_list_front;
171 	void		*io_list_back;
172 	kmutex_t	io_mx;
173 	kcondvar_t	io_cv;
174 	kmutex_t	io_list_mutex;	/* list of waiting io */
175 	kthread_id_t	io_owner;	/* writer thread */
176 } md_io_lock_t;
177 
178 /*
179  * The following flags are in un_flag field of mdc_unit struct.
180  */
181 #define	MD_LABELED	0x1	/* First sector of the metadevice is a label */
182 #define	MD_EFILABEL	0x2	/* This md has an EFI label and no vtoc */
183 
184 /*
185  * This is the number of bytes a DKIOCGETEFI ioctl returns
186  * For now it's one time the header and once the size for a partition info
187  */
188 #define	MD_EFI_LABEL_SIZE (sizeof (efi_gpt_t) + sizeof (efi_gpe_t))
189 
190 /* This is the number of bytes consumed by efi_gpe_PartitionName */
191 #define	MD_EFI_PARTNAME_BYTES (EFI_PART_NAME_LEN * sizeof (ushort_t))
192 
193 typedef enum hs_cmds {
194 	HS_GET, HS_FREE, HS_BAD, HSP_INCREF, HSP_DECREF, HS_MKDEV
195 } hs_cmds_t;
196 
197 typedef struct md_link {
198 	struct md_link	*ln_next;
199 	set_t		ln_setno;
200 	uint_t		ln_id;
201 } md_link_t;
202 
203 typedef struct mdi_unit {
204 	md_link_t	ui_link;
205 	ulong_t		ui_readercnt;	/* number of unit readers */
206 	ulong_t		ui_wanabecnt;	/* # pending on becoming unit writer */
207 	ulong_t		ui_lock;
208 	kmutex_t	ui_mx;
209 	kcondvar_t	ui_cv;
210 	int		ui_opsindex;
211 	uint_t		ui_ocnt[OTYPCNT]; /* open counts */
212 	md_io_lock_t	*ui_io_lock;	/* pointer to io lock */
213 	kstat_t		*ui_kstat;	/* kernel statistics */
214 	kthread_id_t	ui_owner;	/* writer thread */
215 	uint_t		ui_tstate;	/* transient state bits */
216 	uint_t		ui_capab;	/* Capability bits supported */
217 } mdi_unit_t;
218 
219 /*
220  * Following are used with ui_lock
221  * which is in the unit incore structure.
222  */
223 #define	MD_UL_WRITER		0x0001 /* Stall all new strategy calls */
224 #define	MD_UL_WANABEWRITER	0x0002
225 #define	MD_UL_OPENORCLOSE	0x0004
226 
227 #define	MD_UL_OPEN		0x0008	/* unit is open */
228 #define	MD_UL_EXCL		0x0010	/* unit is open exclusively */
229 
230 /*
231  * The softpart open code may do an I/O to validate the watermarks
232  * and should hold no open locks during this I/O.  So, mark the unit
233  * as OPENINPROGRESS and drop the locks.  This will keep any other
234  * softpart open's waiting until the validate has completed.
235  */
236 #define	MD_UL_OPENINPROGRESS	0x0020	/* Open in Progress */
237 
238 /*
239  * Following are used with ui_tstate to specify any transient states which
240  * occur during metadevice operation. These are not written to the metadb as
241  * they do not represent a failure of the underlying metadevice.
242  * Transient errors are stored in the lower 16 bits and other transient
243  * state is stored in the upper 16 bits.
244  * MD_NOTOPENABLE should contain all the states that are set prior to an
245  * open (by snarf) and that indicate that a metadevice cannot be opened.
246  */
247 #define	MD_DEV_ERRORED		0x0000ffff /* ui_tstate error bits */
248 #define	MD_EOF_METADEVICE	0x00000001 /* EOF'd metadevice */
249 #define	MD_64MD_ON_32KERNEL	0x00000002 /* 64bit metadev on 32bit kernel */
250 #define	MD_INACCESSIBLE		0x00000004 /* metadevice unavailable */
251 #define	MD_RETRYING		0x00010000 /* retrying errored failfast I/O */
252 #define	MD_OPENLOCKED		0x00020000 /* MN: open locked before removing */
253 #define	MD_ERR_PENDING		0x00040000 /* MN: error pending */
254 #define	MD_ABR_CAP		0x00080000 /* MN: Application Based Recovery */
255 #define	MD_DMR_CAP		0x00100000 /* MN: Directed Mirror Read */
256 #define	MD_RELEASE_IOERR_DONE	0x00200000 /* ioerr console message done */
257 #define	MD_RESYNC_NOT_DONE	0x00400000 /* resync not done yet */
258 
259 /* A metadevice cannot be opened when these states are set */
260 #define	MD_NOTOPENABLE		(MD_EOF_METADEVICE|MD_64MD_ON_32KERNEL)
261 
262 typedef struct md_ioctl_lock {
263 	int		l_flags;	/* locks held */
264 	mdi_unit_t	*l_ui;		/* unit for which lock is held */
265 } md_ioctl_lock_t;
266 
267 #define	MD_MASTER_DROPPED	0x0001
268 #define	MD_READER_HELD		0x0002
269 #define	MD_WRITER_HELD		0x0004
270 #define	MD_IO_HELD		0x0008
271 #define	MD_ARRAY_READER		0x0010
272 #define	MD_ARRAY_WRITER		0x0020
273 #define	STALE_OK		0x0100
274 #define	NO_OLD			0x0200
275 #define	NO_LOCK			0x0400
276 #define	MD_MT_IOCTL		0x80000 /* MD_GBL_IOCTL_LOCK not set */
277 #define	IOLOCK	md_ioctl_lock_t
278 
279 #define	WR_LOCK			MD_WRITER_HELD
280 #define	RD_LOCK			MD_READER_HELD | STALE_OK
281 #define	ARRAY_WRITER		MD_ARRAY_WRITER
282 #define	ARRAY_READER		MD_ARRAY_READER
283 #define	WRITERS			MD_WRITER_HELD | MD_IO_HELD | MD_ARRAY_WRITER
284 #define	READERS			RD_LOCK | MD_ARRAY_READER
285 
286 #define	IOLOCK_RETURN_IOCTLEND(code, lock) \
287 	md_ioctl_lock_exit((code), (lock)->l_flags, (lock)->l_ui, TRUE)
288 
289 #define	IOLOCK_RETURN(code, lock) \
290 	md_ioctl_lock_exit((code), (lock)->l_flags, (lock)->l_ui, FALSE)
291 
292 #define	IOLOCK_RETURN_RELEASE(code, lock) \
293 	md_ioctl_releaselocks((code), (lock)->l_flags, (lock)->l_ui)
294 
295 #define	IOLOCK_RETURN_REACQUIRE(lock) \
296 	md_ioctl_reacquirelocks((lock)->l_flags, (lock)->l_ui)
297 
298 #define	IOLOCK_INIT(lock)	bzero((caddr_t)(lock), sizeof (*(lock)))
299 /*
300  * checks to be sure locks are held
301  */
302 #define	UNIT_WRITER_HELD(un) \
303 	(MDI_UNIT(MD_SID(un))->ui_lock & MD_UL_WRITER)
304 #define	UNIT_READER_HELD(un) \
305 	(MDI_UNIT(MD_SID(un))->ui_readercnt != 0)
306 #define	IO_WRITER_HELD(un) \
307 	(MDI_UNIT(MD_SID(un))->ui_io_lock->io_lock & MD_UL_WRITER)
308 #define	IO_READER_HELD(un) \
309 	(MDI_UNIT(MD_SID(un))->ui_io_lock->io_readercnt != 0)
310 
311 #ifdef  DEBUG
312 #define	STAT_INC(statvar)		\
313 	statvar++
314 #define	STAT_DEC(statvar)		\
315 	statvar--
316 #define	STAT_ZERO(statvar)		\
317 	statvar = 0;
318 #define	STAT_MAX(statmax, statvar)	\
319 	{				\
320 	statvar++;			\
321 	if (statvar > statmax)		\
322 		statmax = statvar;	\
323 	}
324 #define	STAT_CHECK(statvar, value)	\
325 	{				\
326 	if (value)			\
327 		statvar++;		\
328 	}
329 #else
330 #define	STAT_INC(statvar)
331 #define	STAT_DEC(statvar)
332 #define	STAT_ZERO(statvar)
333 #define	STAT_MAX(statmax, statvar)
334 #define	STAT_CHECK(statvar, value)
335 #endif
336 /*
337  * bit map related macros
338  */
339 #define	setbit(a, i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))
340 #define	clrbit(a, i)	((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
341 #define	isset(a, i)	((a)[(i)/NBBY] & (1<<((i)%NBBY)))
342 #define	isclr(a, i)	(((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
343 
344 typedef struct daemon_queue {
345 	int	maxq_len;
346 	int	qlen;
347 	int	treqs;		/* total number of requests */
348 	struct daemon_queue	*dq_next;
349 	struct daemon_queue	*dq_prev;
350 	void			(*dq_call)();
351 } daemon_queue_t;
352 
353 #define	DAEMON_QUEUE daemon_queue_t	dq;
354 
355 #ifdef _KERNEL
356 #include	<sys/buf.h>
357 #include	<sys/dkio.h>
358 #include	<sys/vtoc.h>
359 
360 #define	MD_DEV2SET(d)	(MD_MIN2SET(md_getminor(d)))
361 
362 #define	MD_UNIT(m)	(md_set[MD_MIN2SET(m)].s_un[MD_MIN2UNIT(m)])
363 #define	MDI_UNIT(m)	((mdi_unit_t *) \
364 			    md_set[MD_MIN2SET(m)].s_ui[MD_MIN2UNIT(m)])
365 #define	MD_VOIDUNIT(m)	(md_set[MD_MIN2SET(m)].s_un[MD_MIN2UNIT(m)])
366 #define	MDI_VOIDUNIT(m)	(md_set[MD_MIN2SET(m)].s_ui[MD_MIN2UNIT(m)])
367 
368 /*
369  * This is the current maximum number of real disks per Virtual Disk.
370  */
371 extern	uint_t	md_mdelay;	/* md_mirror timeout delay */
372 
373 #define	MD_ADM_MINOR		L_MAXMIN32 /* the minor number for md_admin */
374 #define	MD_MDELAY		(md_mdelay)
375 #define	NUM_USEC_IN_SEC		1000000 /* 1 million usec in a second */
376 
377 #define	ANY_SERVICE		-1	/* md_get_named_service() wild card */
378 
379 /*
380  * daemon threads are used in multiple places in md. The following set of
381  * structures and routines allow a common way to create and initialize them.
382  *
383  * md_requestq_entry_t - entry of creating request queues.
384  * struct mdq_anchor - request queue header
385  *
386  * Functions associated with request queues:
387  *
388  * int init_requestq_entry -
389  * void daemon_request - put a request on the queue.
390  */
391 
392 typedef struct md_requestq_entry {
393 	struct mdq_anchor	*dispq_headp;
394 	int		*num_threadsp; /* threads servicing the queue */
395 } md_requestq_entry_t;
396 
397 #define	NULL_REQUESTQ_ENTRY(rqp)\
398 		((rqp)->dispq_headp == NULL || (rqp)->num_threadsp == NULL)
399 
400 /* this typedef is used to differentiate between the two call styles */
401 typedef enum callstyle {
402 	REQ_OLD,
403 	REQ_NEW
404 } callstyle_t;
405 
406 
407 #define	daemon_request_new daemon_request
408 
409 typedef struct mdq_anchor {
410 	DAEMON_QUEUE
411 	kcondvar_t	 a_cv;		/* Request has been put on queue */
412 	kmutex_t	 a_mx;
413 } mdq_anchor_t;
414 
415 typedef struct daemon_request {
416 	DAEMON_QUEUE
417 	kmutex_t	dr_mx;
418 	int		dr_pending;
419 	timeout_id_t	dr_timeout_id;
420 } daemon_request_t;
421 
422 typedef struct sv_dev {
423 	set_t	setno;
424 	side_t	side;
425 	mdkey_t	key;
426 } sv_dev_t;
427 
428 /*
429  * Types of device probes
430  */
431 
432 
433 typedef struct probe_req {
434 	DAEMON_QUEUE
435 	minor_t mnum;			/* mnum of the metadevice to probe */
436 	void   *private_handle;		/* private handle */
437 	intptr_t (*probe_fcn)();	/* type of probeing to be done */
438 } probe_req_t;
439 
440 /* Global flags */
441 #define	MD_NO_GBL_LOCKS_HELD	0x0000	/* currently holding no global locks */
442 #define	MD_GBL_DAEMONS_LIVE	0x0001	/* master daemon has been started. */
443 #define	MD_GBL_DAEMONS_DIE	0x0002
444 #define	MD_GBL_HALTED		0x0004	/* driver is shut down */
445 
446 /* Available bit was GBL_STALE	0x0008	*/
447 
448 #define	MD_GBL_IOCTL_LOCK	0x0010	/* single-threads ioctls */
449 #define	MD_GBL_HS_LOCK		0x0020	/* single-threads hotspares */
450 #define	MD_GBL_OPEN		0x0040	/* admin is open */
451 #define	MD_GBL_EXCL		0x0080	/* admin is open exclusively */
452 
453 #define	MD_OFLG_NULL		0x0000	/* Null flag */
454 #define	MD_OFLG_CONT_ERRS	0x0001	/* Continue on open errors */
455 #define	MD_OFLG_PROBEDEV	0x0002  /* force a simulated open */
456 #define	MD_OFLG_ISINIT		0x0004  /* raid initialization */
457 #define	MD_OFLG_FROMIOCTL	0x0008  /* Called from an ioctl handler */
458 
459 
460 typedef struct md_named_services {
461 
462 	intptr_t	(*md_service)();
463 	char		*md_name;
464 } md_named_services_t;
465 
466 typedef enum md_snarfcmd {MD_SNARF_CLEANUP, MD_SNARF_DOIT} md_snarfcmd_t;
467 
468 typedef struct md_ops {
469 	int	(*md_open)(
470 		    dev_t		*devp,
471 		    int			flag,
472 		    int			otyp,
473 		    cred_t		*credp,
474 		    int			md_oflags);
475 	int	(*md_close)(
476 		    dev_t		dev,
477 		    int			flag,
478 		    int			otyp,
479 		    cred_t		*credp,
480 		    int			md_oflags);
481 	void	(*md_strategy)(
482 		    buf_t		*bufp,
483 		    int			flag,
484 		    void		*private);
485 	int	(*md_print)();		/* unused now */
486 	int	(*md_dump)(
487 		    dev_t		dev,
488 		    caddr_t		addr,
489 		    daddr_t		blkno,
490 		    int			nblk);
491 	int	(*md_read)(
492 		    dev_t		dev,
493 		    struct uio		*uiop,
494 		    cred_t		*credp);
495 	int	(*md_write)(
496 		    dev_t		dev,
497 		    struct uio		*uiop,
498 		    cred_t		*credp);
499 	int	(*md_ioctl)(
500 		    dev_t		dev,
501 		    int			cmd,
502 		    void		*data,
503 		    int			mode,
504 		    IOLOCK		*lockp);
505 	int	(*md_snarf)(
506 		    md_snarfcmd_t	cmd,
507 		    set_t		setno);
508 	int	(*md_halt)();
509 	int	(*md_aread)(
510 		    dev_t		dev,
511 		    struct aio_req	*aiop,
512 		    cred_t		*credp);
513 	int	(*md_awrite)(
514 		    dev_t		dev,
515 		    struct aio_req	*aiop,
516 		    cred_t		*credp);
517 	int	(*md_imp_set)(
518 		    set_t		setno);
519 	md_named_services_t	*md_services;
520 	md_krwlock_t		md_link_rw;
521 	md_link_t		*md_head;
522 	/*
523 	 * NOTE: when TSlvm s10/onnv compatibility is not an issue:
524 	 *	o md_modid and md_locked should be deleted.
525 	 *	o md_mod should be added
526 	 *		ddi_modhandle_t		md_mod;
527 	 *	  and used instead of the md_mods array (md_mods should
528 	 *	  be deleted).
529 	 */
530 	int			md_modid;
531 	int			md_locked;
532 	int			md_selfindex;
533 	struct md_ops		*md_next;
534 	md_driver_t		md_driver;
535 	/* NOTE: TSlvm depends on offsets in and sizeof this structure */
536 } md_ops_t;
537 
538 /* macro to generate linkage for a md misc plugin module */
539 #define	md_noop
540 #define	MD_PLUGIN_MISC_MODULE(desc, init_init, fini_uninit)		\
541 	static struct modlmisc		modlmisc = {			\
542 		&mod_miscops, "Solaris Volume Manager " desc		\
543 	};								\
544 	static struct modlinkage	modlinkage = {			\
545 		MODREV_1, (void *)&modlmisc, NULL			\
546 	};								\
547 	int								\
548 	_init(void)							\
549 	{								\
550 		int	i;						\
551 		init_init;						\
552 		if ((i = mod_install(&modlinkage)) != 0) {		\
553 			fini_uninit;					\
554 		}							\
555 		return (i);						\
556 	}								\
557 	int								\
558 	_fini()								\
559 	{								\
560 		int	i;                                              \
561 		if ((i = mod_remove(&modlinkage)) == 0) {		\
562 			fini_uninit;					\
563 		}							\
564 		return (i);						\
565 	}								\
566 	int								\
567 	_info(struct modinfo *modinfop)					\
568 	{								\
569 		return (mod_info(&modlinkage, modinfop));		\
570 	}
571 
572 typedef enum md_haltcmd {MD_HALT_ALL, MD_HALT_CHECK, MD_HALT_DOIT,
573 			MD_HALT_CLOSE, MD_HALT_OPEN, MD_HALT_UNLOAD
574 } md_haltcmd_t;
575 
576 /*
577  * To support cpr (Energy Star) we need to know when the resync threads are
578  * running to not allow suspention.
579  */
580 typedef struct md_resync_thds_cnt {
581 	int md_raid_resync;	/* count of active raid resync threads */
582 	int md_mirror_resync;	/* count of active mirror resync threads */
583 	kmutex_t md_resync_mutex;	/* protects both resync counts */
584 } md_resync_t;
585 
586 /*
587  * flags used with call to individual strategy routines
588  */
589 #define	MD_STR_PASSEDON 0x0000ffff
590 #define	MD_STR_NOTTOP	0x00000001
591 #define	MD_STR_MAPPED	0x00000002	/* set when buf_t is mapped in	*/
592 #define	MD_STR_ABR	0x00000004	/* use ABR to handle any recovery */
593 #define	MD_STR_WMUPDATE	0x00000008	/* set if updating watermarks for sp */
594 #define	MD_IO_COUNTED	0x00000400	/* io has been counted */
595 #define	MD_NOBLOCK	0x00000800	/* do not block io durring release */
596 
597 #define	MD_STR_WAR	0x00010000	/* this write is write after read */
598 #define	MD_STR_WOW	0x00020000	/* handling a write-on-write */
599 #define	MD_STR_DMR	0x00040000	/* Directed Read request */
600 #define	MD_STR_DIRTY_RD	0x00080000	/* Read of a dirty block */
601 #define	MD_STR_FLAG_ERR	0x00100000	/* Flag any write error on this i/o */
602 
603 /*
604  * Bits for return value of md_getdevnum
605  */
606 #define	MD_TRUST_DEVT	1
607 #define	MD_NOTRUST_DEVT	0
608 
609 /* Flag for drivers to pass to kmem_cache_alloc() */
610 #define	MD_ALLOCFLAGS   (KM_PUSHPAGE | KM_SLEEP)
611 
612 /* Named services */
613 #define	MD_CHECK_OFFLINE	"check_offline"
614 #define	MD_INC_ABR_COUNT	"inc abr count"
615 #define	MD_DEC_ABR_COUNT	"dec abr count"
616 
617 /* Externals from md.c */
618 extern int	md_snarf_db_set(set_t setno, md_error_t *ep);
619 extern void	get_info(struct dk_cinfo *, minor_t);
620 extern void	get_minfo(struct dk_minfo *, minor_t);
621 extern int	mdstrategy(buf_t *);
622 extern int	md_create_minor_node(set_t, minor_t);
623 
624 
625 /* External from md_subr.c */
626 extern int	md_inc_iocount(set_t);
627 extern void	md_inc_iocount_noblock(set_t);
628 extern void	md_dec_iocount(set_t);
629 extern int	md_isblock_setio(set_t);
630 extern int	md_block_setio(set_t);
631 extern void	md_clearblock_setio(set_t);
632 extern void	md_unblock_setio(set_t);
633 extern int	md_tas_block_setio(set_t);
634 extern void	md_biodone(struct buf *);
635 extern void	md_bioreset(struct buf *);
636 extern md_dev64_t md_xlate_targ_2_mini(md_dev64_t);
637 extern md_dev64_t md_xlate_mini_2_targ(md_dev64_t);
638 extern void	md_xlate_free(int);
639 extern major_t	md_targ_name_to_major(char *);
640 extern char	*md_targ_major_to_name(major_t);
641 extern void	md_majortab_free();
642 extern void	md_set_status(int);
643 extern void	md_clr_status(int);
644 extern int	md_get_status(void);
645 extern void	md_set_setstatus(set_t, int);
646 extern void	md_clr_setstatus(set_t, int);
647 extern uint_t	md_get_setstatus(set_t);
648 extern void	*md_unit_readerlock(mdi_unit_t *);
649 extern void	*md_unit_writerlock(mdi_unit_t *);
650 extern void	md_unit_readerexit(mdi_unit_t *);
651 extern void	md_unit_writerexit(mdi_unit_t *);
652 extern void	md_ioctl_releaselocks(int, int, mdi_unit_t *);
653 extern void	md_ioctl_reacquirelocks(int, mdi_unit_t *);
654 extern int	md_ioctl_lock_exit(int, int, mdi_unit_t *, int);
655 extern int	md_ioctl_lock_enter(void);
656 extern void	*md_ioctl_readerlock(IOLOCK *, mdi_unit_t *);
657 extern void	md_ioctl_readerexit(IOLOCK *);
658 extern void	*md_ioctl_writerlock(IOLOCK *, mdi_unit_t *);
659 extern void	md_ioctl_writerexit(IOLOCK *);
660 extern void	md_ioctl_io_exit(IOLOCK *);
661 extern void	*md_ioctl_io_lock(IOLOCK *, mdi_unit_t *);
662 extern void	md_ioctl_droplocks(IOLOCK *);
663 extern void	md_array_writer(IOLOCK *);
664 extern void	md_array_reader(IOLOCK *);
665 extern void	*md_ioctl_openclose_enter(IOLOCK *, mdi_unit_t *);
666 extern void	md_ioctl_openclose_exit(IOLOCK *);
667 extern void	md_ioctl_openclose_exit_lh(IOLOCK *);
668 extern void	*md_unit_openclose_enter(mdi_unit_t *);
669 extern void	md_unit_openclose_exit(mdi_unit_t *);
670 extern void	md_unit_openclose_exit_lh(mdi_unit_t *);
671 extern int	md_unit_isopen(mdi_unit_t *ui);
672 extern int	md_unit_incopen(minor_t mnum, int flag, int otyp);
673 extern int	md_unit_decopen(minor_t mnum, int otyp);
674 extern void	*md_io_readerlock(mdi_unit_t *);
675 extern void	*md_io_writerlock(mdi_unit_t *);
676 extern void	md_io_readerexit(mdi_unit_t *);
677 extern void	md_io_writerexit(mdi_unit_t *);
678 extern intptr_t	(*md_get_named_service())();
679 extern int	init_requestq(md_requestq_entry_t *, void (*)(),
680 						caddr_t, int, int);
681 extern void	daemon_request(mdq_anchor_t *, void(*)(),
682 				daemon_queue_t *, callstyle_t);
683 extern void	md_daemon(int, mdq_anchor_t *);
684 extern void	mddb_commitrec_wrapper(mddb_recid_t);
685 extern void	mddb_commitrecs_wrapper(mddb_recid_t *);
686 extern void	mddb_deleterec_wrapper(mddb_recid_t);
687 extern void	md_holdset_enter(set_t setno);
688 extern void	md_holdset_exit(set_t setno);
689 extern int	md_holdset_testandenter(set_t setno);
690 extern void	md_haltsnarf_enter(set_t setno);
691 extern void	md_haltsnarf_exit(set_t setno);
692 extern void	md_haltsnarf_wait(set_t setno);
693 extern int	md_halt_set(set_t setno, enum md_haltcmd cmd);
694 extern int	md_halt(int global_lock_flag);
695 extern int	md_layered_open(minor_t, md_dev64_t *, int);
696 extern void	md_layered_close(md_dev64_t, int);
697 extern char	*md_get_device_name(md_dev64_t);
698 extern int	errdone(mdi_unit_t *, struct buf *, int);
699 extern int	md_checkbuf(mdi_unit_t *, md_unit_t *, buf_t *);
700 extern int	md_start_daemons(int init_queues);
701 extern int	md_loadsubmod(set_t, char *, int);
702 extern int	md_getmodindex(md_driver_t *, int, int);
703 extern void	md_call_strategy(buf_t *, int, void *);
704 extern int	md_call_ioctl(md_dev64_t, int, void *, int, IOLOCK *);
705 extern void	md_rem_link(set_t, int, krwlock_t *, md_link_t **);
706 extern int	md_dev_exists(md_dev64_t);
707 extern md_parent_t md_get_parent(md_dev64_t);
708 extern void	md_set_parent(md_dev64_t, md_parent_t);
709 extern void	md_reset_parent(md_dev64_t);
710 extern int	md_hot_spare_ifc(hs_cmds_t, mddb_recid_t, u_longlong_t, int,
711 		    mddb_recid_t *, mdkey_t *, md_dev64_t *, diskaddr_t *);
712 extern int	md_notify_interface(md_event_cmds_t cmd, md_tags_t type,
713 		set_t set, md_dev64_t dev, md_event_type_t event);
714 extern void	svm_gen_sysevent(char *se_class, char *se_subclass,
715 		    uint32_t tag, set_t setno, md_dev64_t devid);
716 extern void	md_create_unit_incore(minor_t, md_ops_t *, int);
717 extern void	md_destroy_unit_incore(minor_t, md_ops_t *);
718 extern void	md_rem_names(sv_dev_t *, int);
719 struct uio;
720 extern int	md_chk_uio(struct uio *);
721 extern char	*md_shortname(minor_t mnum);
722 extern char	*md_devname(set_t setno, md_dev64_t dev, char *buf,
723 		size_t size);
724 extern void	md_minphys(buf_t *);
725 extern void	md_kstat_init(minor_t mnum);
726 extern void	md_kstat_init_ui(minor_t mnum, mdi_unit_t *ui);
727 extern void	md_kstat_destroy(minor_t mnum);
728 extern void	md_kstat_destroy_ui(mdi_unit_t *ui);
729 extern void	md_kstat_waitq_enter(mdi_unit_t *ui);
730 extern void	md_kstat_waitq_to_runq(mdi_unit_t *ui);
731 extern void	md_kstat_waitq_exit(mdi_unit_t *ui);
732 extern void	md_kstat_runq_enter(mdi_unit_t *ui);
733 extern void	md_kstat_runq_exit(mdi_unit_t *ui);
734 extern void	md_kstat_done(mdi_unit_t *ui, buf_t *bp, int war);
735 extern pid_t	md_getpid(void);
736 extern proc_t	*md_getproc(void);
737 extern int	md_checkpid(pid_t pid, proc_t *proc);
738 extern char	*md_strdup(char *cp);
739 extern void	freestr(char *cp);
740 extern int	md_check_ioctl_against_efi(int, ushort_t);
741 extern mddb_recid_t md_vtoc_to_efi_record(mddb_recid_t, set_t);
742 
743 extern int	mdmn_ksend_message(set_t, md_mn_msgtype_t, uint_t, char *, int,
744 		    md_mn_kresult_t *);
745 extern void	mdmn_ksend_show_error(int, md_mn_kresult_t *, const char *);
746 extern int	mdmn_send_capability_message(minor_t, volcap_t, IOLOCK *);
747 extern void	mdmn_clear_all_capabilities(minor_t);
748 extern int	md_init_probereq(struct md_probedev_impl *p,
749 		    daemon_queue_t **hdrpp);
750 extern boolean_t callb_md_mrs_cpr(void *, int);
751 
752 /* Externals from md_ioctl.c */
753 extern int	md_mn_is_commd_present(void);
754 extern void	md_mn_clear_commd_present(void);
755 extern int	md_admin_ioctl(md_dev64_t, int, caddr_t, int, IOLOCK *lockp);
756 extern void	md_get_geom(md_unit_t *, struct dk_geom *);
757 extern void	md_get_vtoc(md_unit_t *, struct vtoc *);
758 extern int	md_set_vtoc(md_unit_t *, struct vtoc *);
759 extern void	md_get_cgapart(md_unit_t *, struct dk_map *);
760 extern void	md_get_efi(md_unit_t *, char *);
761 extern int	md_set_efi(md_unit_t *, char *);
762 extern int	md_dkiocgetefi(minor_t, void *, int);
763 extern int	md_dkiocsetefi(minor_t, void *, int);
764 extern int	md_dkiocpartition(minor_t, void *, int);
765 
766 
767 /* Externals from md_names.c */
768 extern mdkey_t	md_setdevname(set_t, side_t, mdkey_t, char *, minor_t, char *,
769 			set_t);
770 extern int	md_getdevname(set_t, side_t, mdkey_t, md_dev64_t, char *,
771 		    size_t);
772 extern int	md_getkeyfromdev(set_t, side_t, md_dev64_t, mdkey_t *, int *);
773 extern int	md_devid_found(set_t, side_t, mdkey_t);
774 extern int	md_getnment(set_t, side_t, mdkey_t, md_dev64_t,
775 		    char *, uint_t, major_t *, minor_t *, mdkey_t *);
776 extern md_dev64_t md_getdevnum(set_t, side_t, mdkey_t, int);
777 extern mdkey_t	md_getnextkey(set_t, side_t, mdkey_t, uint_t *);
778 extern int	md_remdevname(set_t, side_t, mdkey_t);
779 extern mdkey_t	md_setshared_name(set_t, char *, int);
780 extern char	*md_getshared_name(set_t, mdkey_t);
781 extern int	md_remshared_name(set_t, mdkey_t);
782 extern mdkey_t	md_getshared_key(set_t, char *);
783 extern int	md_setshared_data(set_t, uint_t, caddr_t);
784 extern caddr_t	md_getshared_data(set_t, uint_t);
785 extern int	md_load_namespace(set_t, md_error_t *ep, int);
786 extern void	md_unload_namespace(set_t, int);
787 extern int	md_nm_did_chkspace(set_t);
788 extern void	md_bioinit();
789 extern buf_t	*md_bioclone(buf_t *, off_t, size_t, dev_t, diskaddr_t,
790 		    int (*)(buf_t *), buf_t *, int);
791 extern int	md_getdevid(set_t setno, side_t side, mdkey_t key,
792 		    ddi_devid_t devid, ushort_t *did_size);
793 extern int	md_getdevidminor(set_t setno, side_t side, mdkey_t key,
794 		    char *minorname, size_t minorname_len);
795 extern int	md_update_namespace(set_t setno, side_t side, mdkey_t key,
796 		    caddr_t devname, caddr_t pathname, minor_t mnum);
797 extern int	md_update_locator_namespace(set_t setno, side_t side,
798 		    caddr_t devname, caddr_t pathname, md_dev64_t devt);
799 extern int	md_update_namespace_did(set_t setno, side_t side, mdkey_t key,
800 		    md_error_t *ep);
801 extern int	md_validate_devid(set_t setno, side_t side, int *maxsz);
802 extern int	md_get_invdid(set_t setno, side_t side, int cnt, int maxsz,
803 		    void *didptr);
804 extern md_dev64_t md_resolve_bydevid(minor_t, md_dev64_t, mdkey_t key);
805 extern md_dev64_t md_expldev(md_dev64_t);
806 extern dev32_t	md_cmpldev(md_dev64_t);
807 extern dev_t	md_dev64_to_dev(md_dev64_t);
808 extern md_dev64_t md_makedevice(major_t, minor_t);
809 extern major_t	md_getmajor(md_dev64_t);
810 extern minor_t	md_getminor(md_dev64_t);
811 extern void	md_timeval(md_timeval32_t *);
812 extern int	md_imp_snarf_set(set_t *, int);
813 
814 /* externals from md_mddb.c */
815 extern int	mddb_reread_rr(set_t, mddb_recid_t);
816 extern int	mddb_setowner(mddb_recid_t id, md_mn_nodeid_t owner);
817 extern int	mddb_parse(mddb_parse_parm_t *mpp);
818 extern int	mddb_block(mddb_block_parm_t *mpp);
819 extern int	mddb_optrecfix(mddb_optrec_parm_t *mop);
820 extern int	mddb_check_write_ioctl(mddb_config_t *info);
821 extern int	mddb_setflags_ioctl(mddb_setflags_config_t *info);
822 extern struct nm_next_hdr	*get_first_record(set_t, int, int);
823 extern void	*lookup_entry(struct nm_next_hdr *, set_t,
824 			side_t, mdkey_t, md_dev64_t, int);
825 extern void	*lookup_shared_entry(struct nm_next_hdr *,
826 		    mdkey_t key, char *, mddb_recid_t *, int);
827 extern int	remove_shared_entry(struct nm_next_hdr *, mdkey_t key,
828 		    char *, int);
829 extern void	*alloc_entry(struct nm_next_hdr *, mddb_recid_t, size_t, int,
830 		    mddb_recid_t *);
831 extern void	*getshared_name(set_t, mdkey_t, int);
832 
833 #endif	/* _KERNEL */
834 
835 
836 /* externals from md_revchk.c */
837 extern int	revchk(uint_t my_rev, uint_t data);
838 
839 
840 #ifdef	__cplusplus
841 }
842 #endif
843 
844 #endif	/* _SYS_MDVAR_H */
845