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