xref: /freebsd/sys/geom/vinum/geom_vinum_var.h (revision 9336e0699bda8a301cd2bfa37106b6ec5e32012e)
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_MAGIC	22322600044678729LL
140 #define	GV_NOMAGIC	22322600044678990LL
141 
142 	int		config_length;
143 	struct gv_label	label;
144 };
145 
146 /* A single freelist entry of a drive. */
147 struct gv_freelist {
148 	off_t size;				/* Size of this free slot. */
149 	off_t offset;				/* Offset on the drive. */
150 	LIST_ENTRY(gv_freelist) freelist;
151 };
152 
153 /*
154  * Since we share structures between userland and kernel, we need this helper
155  * struct instead of struct bio_queue_head and friends.  Maybe I find a proper
156  * solution some day.
157  */
158 struct gv_bioq {
159 	struct bio *bp;
160 	TAILQ_ENTRY(gv_bioq)	queue;
161 };
162 
163 /* This struct contains the main vinum config. */
164 struct gv_softc {
165 	/*struct mtx config_mtx; XXX not yet */
166 
167 	/* Linked lists of all objects in our setup. */
168 	LIST_HEAD(,gv_drive)	drives;		/* All drives. */
169 	LIST_HEAD(,gv_plex)	plexes;		/* All plexes. */
170 	LIST_HEAD(,gv_sd)	subdisks;	/* All subdisks. */
171 	LIST_HEAD(,gv_volume)	volumes;	/* All volumes. */
172 
173 	struct g_geom		*geom;		/* Pointer to our VINUM geom. */
174 };
175 
176 /* softc for a drive. */
177 struct gv_drive {
178 	char	name[GV_MAXDRIVENAME];		/* The name of this drive. */
179 	char	device[GV_MAXDRIVENAME];	/* Associated device. */
180 	int	state;				/* The state of this drive. */
181 #define	GV_DRIVE_DOWN	0
182 #define	GV_DRIVE_UP	1
183 
184 	off_t	size;				/* Size of this drive. */
185 	off_t	avail;				/* Available space. */
186 	int	sdcount;			/* Number of subdisks. */
187 
188 	int	flags;
189 #define	GV_DRIVE_THREAD_ACTIVE	0x01	/* Drive has an active worker thread. */
190 #define	GV_DRIVE_THREAD_DIE	0x02	/* Signal the worker thread to die. */
191 #define	GV_DRIVE_THREAD_DEAD	0x04	/* The worker thread has died. */
192 #define	GV_DRIVE_NEWBORN	0x08	/* The drive was just created. */
193 
194 	struct gv_hdr	*hdr;			/* The drive header. */
195 
196 	int freelist_entries;			/* Count of freelist entries. */
197 	LIST_HEAD(,gv_freelist)	freelist;	/* List of freelist entries. */
198 	LIST_HEAD(,gv_sd)	subdisks;	/* Subdisks on this drive. */
199 	LIST_ENTRY(gv_drive)	drive;		/* Entry in the vinum config. */
200 
201 #ifdef _KERNEL
202 	struct bio_queue_head	*bqueue;	/* BIO queue of this drive. */
203 #else
204 	char			*padding;
205 #endif
206 	struct mtx		bqueue_mtx;	/* Mtx. to protect the queue. */
207 
208 	struct g_geom	*geom;			/* The geom of this drive. */
209 	struct gv_softc	*vinumconf;		/* Pointer to the vinum conf. */
210 };
211 
212 /* softc for a subdisk. */
213 struct gv_sd {
214 	char	name[GV_MAXSDNAME];	/* The name of this subdisk. */
215 	off_t	size;			/* The size of this subdisk. */
216 	off_t	drive_offset;		/* Offset in the underlying drive. */
217 	off_t	plex_offset;		/* Offset in the associated plex. */
218 	int	state;			/* The state of this subdisk. */
219 #define	GV_SD_DOWN		0
220 #define	GV_SD_STALE		1
221 #define	GV_SD_INITIALIZING	2
222 #define	GV_SD_REVIVING		3
223 #define	GV_SD_UP		4
224 
225 	off_t	initialized;		/* Count of initialized bytes. */
226 
227 	int	init_size;		/* Initialization read/write size. */
228 	int	init_error;		/* Flag error on initialization. */
229 
230 	int	flags;
231 #define	GV_SD_NEWBORN		0x01	/* Subdisk was just created. */
232 #define	GV_SD_INITCANCEL	0x02	/* Cancel initialization process. */
233 
234 	char drive[GV_MAXDRIVENAME];	/* Name of underlying drive. */
235 	char plex[GV_MAXPLEXNAME];	/* Name of associated plex. */
236 
237 	struct gv_drive	*drive_sc;	/* Pointer to underlying drive. */
238 	struct gv_plex	*plex_sc;	/* Pointer to associated plex. */
239 
240 	struct g_provider *provider;	/* The provider this sd represents. */
241 	struct g_consumer *consumer;	/* Consumer attached to our provider. */
242 
243 	LIST_ENTRY(gv_sd) from_drive;	/* Subdisk list of underlying drive. */
244 	LIST_ENTRY(gv_sd) in_plex;	/* Subdisk list of associated plex. */
245 	LIST_ENTRY(gv_sd) sd;		/* Entry in the vinum config. */
246 
247 	struct gv_softc	*vinumconf;	/* Pointer to the vinum config. */
248 };
249 
250 /* softc for a plex. */
251 struct gv_plex {
252 	char	name[GV_MAXPLEXNAME];	/* The name of the plex. */
253 	off_t	size;			/* The size of the plex. */
254 	int	state;			/* The plex state. */
255 #define	GV_PLEX_DOWN		0
256 #define	GV_PLEX_INITIALIZING	1
257 #define	GV_PLEX_DEGRADED	2
258 #define	GV_PLEX_UP		3
259 
260 	int	org;			/* The plex organisation. */
261 #define	GV_PLEX_DISORG	0
262 #define	GV_PLEX_CONCAT	1
263 #define	GV_PLEX_STRIPED	2
264 #define	GV_PLEX_RAID5	4
265 
266 	int	stripesize;		/* The stripe size of the plex. */
267 
268 	char	volume[GV_MAXVOLNAME];	/* Name of associated volume. */
269 	struct gv_volume *vol_sc;	/* Pointer to associated volume. */
270 
271 	int	sdcount;		/* Number of subdisks in this plex. */
272 	int	sddown;			/* Number of subdisks that are down. */
273 	int	flags;
274 #define	GV_PLEX_ADDED		0x01	/* Added to an existing volume. */
275 #define	GV_PLEX_SYNCING		0x02	/* Plex is syncing from another plex. */
276 #define	GV_PLEX_THREAD_ACTIVE	0x04	/* Plex has an active RAID5 thread. */
277 #define	GV_PLEX_THREAD_DIE	0x08	/* Signal the RAID5 thread to die. */
278 #define	GV_PLEX_THREAD_DEAD	0x10	/* The RAID5 thread has died. */
279 #define	GV_PLEX_NEWBORN		0x20	/* The plex was just created. */
280 
281 	off_t	synced;			/* Count of synced bytes. */
282 
283 	struct mtx		bqueue_mtx; /* Lock for the BIO queue. */
284 #ifdef _KERNEL
285 	struct bio_queue_head	*bqueue; /* BIO queue. */
286 	struct bio_queue_head	*wqueue; /* Waiting BIO queue. */
287 #else
288 	char			*bpad, *wpad;
289 #endif
290 	TAILQ_HEAD(,gv_raid5_packet)	packets; /* RAID5 sub-requests. */
291 
292 	LIST_HEAD(,gv_sd)   subdisks;	/* List of attached subdisks. */
293 	LIST_ENTRY(gv_plex) in_volume;	/* Plex list of associated volume. */
294 	LIST_ENTRY(gv_plex) plex;	/* Entry in the vinum config. */
295 
296 	struct g_provider *provider;	/* The provider this plex represents. */
297 	struct g_consumer *consumer;	/* Consumer attached to our provider. */
298 
299 	struct g_geom	*geom;		/* The geom of this plex. */
300 	struct gv_softc	*vinumconf;	/* Pointer to the vinum config. */
301 };
302 
303 /* softc for a volume. */
304 struct gv_volume {
305 	char	name[GV_MAXVOLNAME];	/* The name of the volume. */
306 	off_t	size;			/* The size of the volume. */
307 	int	plexcount;		/* Number of plexes. */
308 	int	state;			/* The state of the volume. */
309 #define	GV_VOL_DOWN	0
310 #define	GV_VOL_UP	1
311 
312 	int	flags;
313 #define	GV_VOL_THREAD_ACTIVE	0x01	/* Volume has an active thread. */
314 #define	GV_VOL_THREAD_DIE	0x02	/* Signal the thread to die. */
315 #define	GV_VOL_THREAD_DEAD	0x04	/* The thread has died. */
316 
317 	struct mtx		bqueue_mtx; /* Lock for the BIO queue. */
318 #ifdef _KERNEL
319 	struct bio_queue_head	*bqueue; /* BIO queue. */
320 #else
321 	char			*padding;
322 #endif
323 
324 	LIST_HEAD(,gv_plex)   plexes;	/* List of attached plexes. */
325 	LIST_ENTRY(gv_volume) volume;	/* Entry in vinum config. */
326 
327 	struct gv_plex	*last_read_plex;
328 	struct g_geom	*geom;		/* The geom of this volume. */
329 	struct gv_softc	*vinumconf;	/* Pointer to the vinum config. */
330 };
331 
332 #endif /* !_GEOM_VINUM_VAR_H */
333