xref: /titanic_41/usr/src/uts/common/sys/lvm/md_sp.h (revision 6185db853e024a486ff8837e6784dd290d866112)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS__MD_SP_H
28 #define	_SYS__MD_SP_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/lvm/mdvar.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #define	META_SP_DEBUG ("META_SP_DEBUG")
39 
40 /* on-disk structures */
41 #define	MD_SP_MAGIC			(0x20000127)
42 /* number of sectors to reserve at the beginning of the volume */
43 #define	MD_SP_START			(0)
44 /* current watermark version number */
45 #define	MD_SP_VERSION			(1)
46 /* size of a watermark in sectors */
47 #define	MD_SP_WMSIZE			(1)
48 /* free watermark name */
49 #define	MD_SP_FREEWMNAME		"free"
50 /* local set name */
51 #define	MD_SP_LOCALSETNAME		""
52 /* maximum length of a soft partition metadevice name. eg. dXXXX\0 */
53 #define	MD_SP_MAX_DEVNAME_PLUS_1	(6)
54 
55 /*
56  * The size of this structure is forced to be 512 bytes (ie a sector) by
57  * using a union. Note the MD_MAX_SETNAME_PLUS_1 is set in meta_basic.h
58  */
59 
60 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
61 #pragma pack(4)
62 #endif
63 typedef union mp_watermark {
64 	struct {
65 		uint32_t	wm_magic;	/* magic number */
66 		uint32_t	wm_version;	/* version number */
67 		uint32_t	wm_checksum;	/* structure checksum */
68 		uint32_t	wm_seq;		/* sequence number */
69 		uint32_t	wm_type;	/* extent type */
70 		uint64_t	wm_length;	/* length of extent */
71 		char		wm_mdname[MD_MAX_SETNAME_PLUS_1 +
72 				    MD_SP_MAX_DEVNAME_PLUS_1];	/* SP name */
73 		char		wm_setname[MD_MAX_SETNAME_PLUS_1]; /* setname */
74 	} wm;
75 	uchar_t			wm_pad[MD_SP_WMSIZE * DEV_BSIZE];
76 } mp_watermark_t;
77 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
78 #pragma pack()
79 #endif
80 
81 #define	wm_magic	wm.wm_magic
82 #define	wm_version	wm.wm_version
83 #define	wm_checksum	wm.wm_checksum
84 #define	wm_seq		wm.wm_seq
85 #define	wm_type		wm.wm_type
86 #define	wm_length	wm.wm_length
87 #define	wm_mdname	wm.wm_mdname
88 #define	wm_setname	wm.wm_setname
89 
90 /* Watermark types */
91 typedef enum sp_ext_type {
92 	EXTTYP_ALLOC	= 0x1,	/* this extent is in use by a soft partition */
93 	EXTTYP_FREE	= 0x2,	/* extent is not in use */
94 	EXTTYP_END	= 0x3,	/* last descriptor on the volume */
95 	EXTTYP_RESERVED	= 0x4	/* extent will not be used or updated */
96 } sp_ext_type_t;
97 
98 /* ioctls */
99 #define	MD_IOC_SPSTATUS		(MDIOC_MISC|0)
100 #define	MD_IOC_SPUPDATEWM	(MDIOC_MISC|1)
101 #define	MD_IOC_SPREADWM		(MDIOC_MISC|2)
102 
103 #ifdef _KERNEL
104 
105 /*
106  * parent and child save areas provide the mechanism for tracking
107  * I/O operations in the metadevice stack.
108  */
109 
110 /* soft partitioning parent save area */
111 typedef struct md_spps {		/* soft partition parent save */
112 	DAEMON_QUEUE
113 	mp_unit_t	*ps_un;		/* sp unit structure */
114 	mdi_unit_t	*ps_ui;		/* incore unit struct */
115 	buf_t		*ps_bp;		/* parent buffer */
116 	caddr_t		 ps_addr;
117 	int		 ps_frags;
118 	int		 ps_flags;
119 	/*
120 	 * New structure members should be added here; fields added
121 	 * after ps_mx will not be zeroed during initialization.
122 	 */
123 	kmutex_t	 ps_mx;
124 } md_spps_t;
125 
126 /* parent save flags. */
127 #define	MD_SPPS_ERROR		0x0001
128 #define	MD_SPPS_DONTFREE	0x0002
129 #define	MD_SPPS_DONE		0x0004
130 
131 /* soft partitioning child save area */
132 typedef struct md_spcs {
133 	DAEMON_QUEUE
134 	minor_t		 cs_mdunit;	/* child minor number */
135 	md_spps_t	*cs_ps;		/* parent save pointer */
136 	/* Add new structure members HERE!! */
137 	buf_t		 cs_buf;	/* child buffer */
138 	/*  DO NOT add struture members here; cs_buf is dynamically sized */
139 } md_spcs_t;
140 
141 #define	SPPS_FREE(kc, ps)			\
142 {						\
143 	if ((ps)->ps_flags & MD_SPPS_DONTFREE)	\
144 		(ps)->ps_flags |= MD_SPPS_DONE;	\
145 	else					\
146 		kmem_cache_free((kc), (ps));	\
147 }
148 
149 /* externals from sp.c */
150 extern int	sp_build_incore(void *, int);
151 extern void	reset_sp(mp_unit_t *, minor_t, int);
152 extern int	sp_directed_read(minor_t, vol_directed_rd_t *, int);
153 
154 /* externals from sp_ioctl.c */
155 extern int	md_sp_ioctl(dev_t dev, int cmd, void *data,
156 	int mode, IOLOCK *lockp);
157 
158 #endif	/* _KERNEL */
159 
160 #ifdef	__cplusplus
161 }
162 #endif
163 
164 #endif	/* _SYS__MD_SP_H */
165