xref: /freebsd/sys/geom/vinum/geom_vinum_var.h (revision 39beb93c3f8bdbf72a61fda42300b5ebed7390c8)
1 /*-
2  * Copyright (c) 2004 Lukas Ertl
3  * Copyright (c) 1997, 1998, 1999
4  *      Nan Yang Computer Services Limited.  All rights reserved.
5  *
6  * Parts copyright (c) 1997, 1998 Cybernet Corporation, NetMAX project.
7  * Parts written by Greg Lehey.
8  *
9  *  This software is distributed under the so-called ``Berkeley
10  *  License'':                                                                   *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *      This product includes software developed by Nan Yang Computer
22  *      Services Limited.
23  * 4. Neither the name of the Company nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * This software is provided ``as is'', and any express or implied
28  * warranties, including, but not limited to, the implied warranties of
29  * merchantability and fitness for a particular purpose are disclaimed.
30  * In no event shall the company or contributors be liable for any               * direct, indirect, incidental, special, exemplary, or consequential
31  * damages (including, but not limited to, procurement of substitute
32  * goods or services; loss of use, data, or profits; or business
33  * interruption) however caused and on any theory of liability, whether
34  * in contract, strict liability, or tort (including negligence or
35  * otherwise) arising in any way out of the use of this software, even if
36  * advised of the possibility of such damage.
37  *
38  * $FreeBSD$
39  */
40 
41 #ifndef	_GEOM_VINUM_VAR_H_
42 #define	_GEOM_VINUM_VAR_H_
43 
44 /*
45  * Slice header
46  *
47  * Vinum drives start with this structure:
48  *
49  *\                                            Sector
50  * |--------------------------------------|
51  * |   PDP-11 memorial boot block         |      0
52  * |--------------------------------------|
53  * |   Disk label, maybe                  |      1
54  * |--------------------------------------|
55  * |   Slice definition  (vinum_hdr)      |      8
56  * |--------------------------------------|
57  * |                                      |
58  * |   Configuration info, first copy     |      9
59  * |                                      |
60  * |--------------------------------------|
61  * |                                      |
62  * |   Configuration info, second copy    |      9 + size of config
63  * |                                      |
64  * |--------------------------------------|
65  */
66 
67 /* Sizes and offsets of our information. */
68 #define	GV_HDR_OFFSET	4096	/* Offset of vinum header. */
69 #define	GV_HDR_LEN	512	/* Size of vinum header. */
70 #define	GV_CFG_OFFSET	4608	/* Offset of first config copy. */
71 #define	GV_CFG_LEN	65536	/* Size of config copy. */
72 
73 /* This is where the actual data starts. */
74 #define	GV_DATA_START	(GV_CFG_LEN * 2 + GV_CFG_OFFSET)
75 /* #define GV_DATA_START	(GV_CFG_LEN * 2 + GV_HDR_LEN) */
76 
77 #define	GV_MAXDRIVENAME	32	/* Maximum length of a device name. */
78 #define	GV_MAXSDNAME	64	/* Maximum length of a subdisk name. */
79 #define	GV_MAXPLEXNAME	64	/* Maximum length of a plex name. */
80 #define	GV_MAXVOLNAME	64	/* Maximum length of a volume name. */
81 
82 /* Command line flags. */
83 #define	GV_FLAG_R	0x01
84 #define	GV_FLAG_S	0x02
85 #define	GV_FLAG_V	0x04
86 #define	GV_FLAG_VV	0x08
87 #define	GV_FLAG_F	0x10
88 
89 /* Object types. */
90 #define	GV_TYPE_VOL	1
91 #define	GV_TYPE_PLEX	2
92 #define	GV_TYPE_SD	3
93 #define	GV_TYPE_DRIVE	4
94 
95 /* State changing flags. */
96 #define	GV_SETSTATE_FORCE	0x1
97 #define	GV_SETSTATE_CONFIG	0x2
98 
99 /* Subdisk state bitmaps for plexes. */
100 #define	GV_SD_DOWNSTATE		0x01	/* Subdisk is down. */
101 #define	GV_SD_STALESTATE	0x02	/* Subdisk is stale. */
102 #define	GV_SD_INITSTATE		0x04	/* Subdisk is initializing. */
103 #define	GV_SD_UPSTATE		0x08	/* Subdisk is up. */
104 
105 /* Synchronization/initialization request sizes. */
106 #define	GV_MIN_SYNCSIZE		512
107 #define	GV_MAX_SYNCSIZE		MAXPHYS
108 #define	GV_DFLT_SYNCSIZE	65536
109 
110 /* Flags for BIOs, as they are processed within vinum. */
111 #define	GV_BIO_DONE	0x01
112 #define	GV_BIO_MALLOC	0x02
113 #define	GV_BIO_ONHOLD	0x04
114 #define	GV_BIO_SYNCREQ	0x08
115 #define	GV_BIO_SUCCEED	0x10
116 #define	GV_BIO_REBUILD	0x20
117 #define	GV_BIO_CHECK	0x40
118 #define	GV_BIO_PARITY	0x80
119 #define	GV_BIO_RETRY	0x100
120 
121 /*
122  * hostname is 256 bytes long, but we don't need to shlep multiple copies in
123  * vinum.  We use the host name just to identify this system, and 32 bytes
124  * should be ample for that purpose.
125  */
126 
127 #define	GV_HOSTNAME_LEN	32
128 struct gv_label {
129 	char	sysname[GV_HOSTNAME_LEN]; /* System name at creation time. */
130 	char	name[GV_MAXDRIVENAME];	/* Our name of the drive. */
131 	struct timeval	date_of_birth;	/* The time it was created ... */
132 	struct timeval	last_update;	/* ... and the time of last update. */
133 	off_t		drive_size;	/* Total size incl. headers. */
134 };
135 
136 /* The 'header' of each valid vinum drive. */
137 struct gv_hdr {
138 	uint64_t	magic;
139 #define GV_OLD_MAGIC	0x494E2056494E4F00LL
140 #define GV_OLD_NOMAGIC	0x4E4F2056494E4F00LL
141 #define GV_MAGIC	0x56494E554D2D3100LL
142 #define GV_NOMAGIC	0x56494E554D2D2D00LL
143 
144 	uint64_t	config_length;
145 	struct gv_label	label;
146 };
147 
148 /* A single freelist entry of a drive. */
149 struct gv_freelist {
150 	off_t size;				/* Size of this free slot. */
151 	off_t offset;				/* Offset on the drive. */
152 	LIST_ENTRY(gv_freelist) freelist;
153 };
154 
155 /*
156  * Since we share structures between userland and kernel, we need this helper
157  * struct instead of struct bio_queue_head and friends.  Maybe I find a proper
158  * solution some day.
159  */
160 struct gv_bioq {
161 	struct bio *bp;
162 	TAILQ_ENTRY(gv_bioq)	queue;
163 };
164 
165 /* This struct contains the main vinum config. */
166 struct gv_softc {
167 	/*struct mtx config_mtx; XXX not yet */
168 
169 	/* Linked lists of all objects in our setup. */
170 	LIST_HEAD(,gv_drive)	drives;		/* All drives. */
171 	LIST_HEAD(,gv_plex)	plexes;		/* All plexes. */
172 	LIST_HEAD(,gv_sd)	subdisks;	/* All subdisks. */
173 	LIST_HEAD(,gv_volume)	volumes;	/* All volumes. */
174 
175 	struct g_geom		*geom;		/* Pointer to our VINUM geom. */
176 };
177 
178 /* softc for a drive. */
179 struct gv_drive {
180 	char	name[GV_MAXDRIVENAME];		/* The name of this drive. */
181 	char	device[GV_MAXDRIVENAME];	/* Associated device. */
182 	int	state;				/* The state of this drive. */
183 #define	GV_DRIVE_DOWN	0
184 #define	GV_DRIVE_UP	1
185 
186 	off_t	size;				/* Size of this drive. */
187 	off_t	avail;				/* Available space. */
188 	int	sdcount;			/* Number of subdisks. */
189 
190 	int	flags;
191 #define	GV_DRIVE_THREAD_ACTIVE	0x01	/* Drive has an active worker thread. */
192 #define	GV_DRIVE_THREAD_DIE	0x02	/* Signal the worker thread to die. */
193 #define	GV_DRIVE_THREAD_DEAD	0x04	/* The worker thread has died. */
194 #define	GV_DRIVE_NEWBORN	0x08	/* The drive was just created. */
195 
196 	struct gv_hdr	*hdr;			/* The drive header. */
197 
198 	int freelist_entries;			/* Count of freelist entries. */
199 	LIST_HEAD(,gv_freelist)	freelist;	/* List of freelist entries. */
200 	LIST_HEAD(,gv_sd)	subdisks;	/* Subdisks on this drive. */
201 	LIST_ENTRY(gv_drive)	drive;		/* Entry in the vinum config. */
202 
203 #ifdef _KERNEL
204 	struct bio_queue_head	*bqueue;	/* BIO queue of this drive. */
205 #else
206 	char			*padding;
207 #endif
208 	struct mtx		bqueue_mtx;	/* Mtx. to protect the queue. */
209 
210 	struct g_geom	*geom;			/* The geom of this drive. */
211 	struct gv_softc	*vinumconf;		/* Pointer to the vinum conf. */
212 };
213 
214 /* softc for a subdisk. */
215 struct gv_sd {
216 	char	name[GV_MAXSDNAME];	/* The name of this subdisk. */
217 	off_t	size;			/* The size of this subdisk. */
218 	off_t	drive_offset;		/* Offset in the underlying drive. */
219 	off_t	plex_offset;		/* Offset in the associated plex. */
220 	int	state;			/* The state of this subdisk. */
221 #define	GV_SD_DOWN		0
222 #define	GV_SD_STALE		1
223 #define	GV_SD_INITIALIZING	2
224 #define	GV_SD_REVIVING		3
225 #define	GV_SD_UP		4
226 
227 	off_t	initialized;		/* Count of initialized bytes. */
228 
229 	int	init_size;		/* Initialization read/write size. */
230 	int	init_error;		/* Flag error on initialization. */
231 
232 	int	flags;
233 #define	GV_SD_NEWBORN		0x01	/* Subdisk was just created. */
234 #define	GV_SD_INITCANCEL	0x02	/* Cancel initialization process. */
235 
236 	char drive[GV_MAXDRIVENAME];	/* Name of underlying drive. */
237 	char plex[GV_MAXPLEXNAME];	/* Name of associated plex. */
238 
239 	struct gv_drive	*drive_sc;	/* Pointer to underlying drive. */
240 	struct gv_plex	*plex_sc;	/* Pointer to associated plex. */
241 
242 	struct g_provider *provider;	/* The provider this sd represents. */
243 	struct g_consumer *consumer;	/* Consumer attached to our provider. */
244 
245 	LIST_ENTRY(gv_sd) from_drive;	/* Subdisk list of underlying drive. */
246 	LIST_ENTRY(gv_sd) in_plex;	/* Subdisk list of associated plex. */
247 	LIST_ENTRY(gv_sd) sd;		/* Entry in the vinum config. */
248 
249 	struct gv_softc	*vinumconf;	/* Pointer to the vinum config. */
250 };
251 
252 /* softc for a plex. */
253 struct gv_plex {
254 	char	name[GV_MAXPLEXNAME];	/* The name of the plex. */
255 	off_t	size;			/* The size of the plex. */
256 	int	state;			/* The plex state. */
257 #define	GV_PLEX_DOWN		0
258 #define	GV_PLEX_INITIALIZING	1
259 #define	GV_PLEX_DEGRADED	2
260 #define	GV_PLEX_UP		3
261 
262 	int	org;			/* The plex organisation. */
263 #define	GV_PLEX_DISORG	0
264 #define	GV_PLEX_CONCAT	1
265 #define	GV_PLEX_STRIPED	2
266 #define	GV_PLEX_RAID5	4
267 
268 	int	stripesize;		/* The stripe size of the plex. */
269 
270 	char	volume[GV_MAXVOLNAME];	/* Name of associated volume. */
271 	struct gv_volume *vol_sc;	/* Pointer to associated volume. */
272 
273 	int	sdcount;		/* Number of subdisks in this plex. */
274 	int	sddown;			/* Number of subdisks that are down. */
275 	int	flags;
276 #define	GV_PLEX_ADDED		0x01	/* Added to an existing volume. */
277 #define	GV_PLEX_SYNCING		0x02	/* Plex is syncing from another plex. */
278 #define	GV_PLEX_THREAD_ACTIVE	0x04	/* Plex has an active RAID5 thread. */
279 #define	GV_PLEX_THREAD_DIE	0x08	/* Signal the RAID5 thread to die. */
280 #define	GV_PLEX_THREAD_DEAD	0x10	/* The RAID5 thread has died. */
281 #define	GV_PLEX_NEWBORN		0x20	/* The plex was just created. */
282 
283 	off_t	synced;			/* Count of synced bytes. */
284 
285 	struct mtx		bqueue_mtx; /* Lock for the BIO queue. */
286 #ifdef _KERNEL
287 	struct bio_queue_head	*bqueue; /* BIO queue. */
288 	struct bio_queue_head	*wqueue; /* Waiting BIO queue. */
289 #else
290 	char			*bpad, *wpad;
291 #endif
292 	TAILQ_HEAD(,gv_raid5_packet)	packets; /* RAID5 sub-requests. */
293 
294 	LIST_HEAD(,gv_sd)   subdisks;	/* List of attached subdisks. */
295 	LIST_ENTRY(gv_plex) in_volume;	/* Plex list of associated volume. */
296 	LIST_ENTRY(gv_plex) plex;	/* Entry in the vinum config. */
297 
298 	struct g_provider *provider;	/* The provider this plex represents. */
299 	struct g_consumer *consumer;	/* Consumer attached to our provider. */
300 
301 	struct g_geom	*geom;		/* The geom of this plex. */
302 	struct gv_softc	*vinumconf;	/* Pointer to the vinum config. */
303 };
304 
305 /* softc for a volume. */
306 struct gv_volume {
307 	char	name[GV_MAXVOLNAME];	/* The name of the volume. */
308 	off_t	size;			/* The size of the volume. */
309 	int	plexcount;		/* Number of plexes. */
310 	int	state;			/* The state of the volume. */
311 #define	GV_VOL_DOWN	0
312 #define	GV_VOL_UP	1
313 
314 	int	flags;
315 #define	GV_VOL_THREAD_ACTIVE	0x01	/* Volume has an active thread. */
316 #define	GV_VOL_THREAD_DIE	0x02	/* Signal the thread to die. */
317 #define	GV_VOL_THREAD_DEAD	0x04	/* The thread has died. */
318 
319 	struct mtx		bqueue_mtx; /* Lock for the BIO queue. */
320 #ifdef _KERNEL
321 	struct bio_queue_head	*bqueue; /* BIO queue. */
322 #else
323 	char			*padding;
324 #endif
325 
326 	LIST_HEAD(,gv_plex)   plexes;	/* List of attached plexes. */
327 	LIST_ENTRY(gv_volume) volume;	/* Entry in vinum config. */
328 
329 	struct gv_plex	*last_read_plex;
330 	struct g_geom	*geom;		/* The geom of this volume. */
331 	struct gv_softc	*vinumconf;	/* Pointer to the vinum config. */
332 };
333 
334 #endif /* !_GEOM_VINUM_VAR_H */
335