summaryrefslogtreecommitdiffstats
path: root/sys/geom/vinum/geom_vinum_var.h
blob: 124944fda2b61e4a23bcd0cdd18f629a0887266f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/*-
 * Copyright (c) 2004, 2007 Lukas Ertl
 * Copyright (c) 1997, 1998, 1999
 *      Nan Yang Computer Services Limited.  All rights reserved.
 *
 * Parts copyright (c) 1997, 1998 Cybernet Corporation, NetMAX project.
 * Parts written by Greg Lehey.
 *
 *  This software is distributed under the so-called ``Berkeley
 *  License'':                                                                   *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by Nan Yang Computer
 *      Services Limited.
 * 4. Neither the name of the Company nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *  
 * This software is provided ``as is'', and any express or implied
 * warranties, including, but not limited to, the implied warranties of
 * merchantability and fitness for a particular purpose are disclaimed.
 * In no event shall the company or contributors be liable for any               * direct, indirect, incidental, special, exemplary, or consequential
 * damages (including, but not limited to, procurement of substitute
 * goods or services; loss of use, data, or profits; or business
 * interruption) however caused and on any theory of liability, whether
 * in contract, strict liability, or tort (including negligence or
 * otherwise) arising in any way out of the use of this software, even if
 * advised of the possibility of such damage.
 *  
 * $FreeBSD$
 */

#ifndef	_GEOM_VINUM_VAR_H_
#define	_GEOM_VINUM_VAR_H_

/*
 * Slice header
 *
 * Vinum drives start with this structure:
 *
 *\                                            Sector
 * |--------------------------------------|
 * |   PDP-11 memorial boot block         |      0
 * |--------------------------------------|
 * |   Disk label, maybe                  |      1
 * |--------------------------------------|
 * |   Slice definition  (vinum_hdr)      |      8
 * |--------------------------------------|
 * |                                      |
 * |   Configuration info, first copy     |      9
 * |                                      |
 * |--------------------------------------|
 * |                                      |
 * |   Configuration info, second copy    |      9 + size of config
 * |                                      |
 * |--------------------------------------|
 */

/* Sizes and offsets of our information. */
#define	GV_HDR_OFFSET	4096	/* Offset of vinum header. */
#define	GV_HDR_LEN	512	/* Size of vinum header. */
#define	GV_CFG_OFFSET	4608	/* Offset of first config copy. */
#define	GV_CFG_LEN	65536	/* Size of config copy. */

/* This is where the actual data starts. */
#define	GV_DATA_START	(GV_CFG_LEN * 2 + GV_CFG_OFFSET)
/* #define GV_DATA_START	(GV_CFG_LEN * 2 + GV_HDR_LEN) */

#define	GV_MAXDRIVENAME	32	/* Maximum length of a device name. */
#define	GV_MAXSDNAME	64	/* Maximum length of a subdisk name. */
#define	GV_MAXPLEXNAME	64	/* Maximum length of a plex name. */
#define	GV_MAXVOLNAME	64	/* Maximum length of a volume name. */

/* Command line flags. */
#define	GV_FLAG_R	0x01
#define	GV_FLAG_S	0x02
#define	GV_FLAG_V	0x04
#define	GV_FLAG_VV	0x08
#define	GV_FLAG_F	0x10

/* Object types. */
#define	GV_TYPE_VOL	1
#define	GV_TYPE_PLEX	2
#define	GV_TYPE_SD	3
#define	GV_TYPE_DRIVE	4

/* State changing flags. */
#define	GV_SETSTATE_FORCE	0x1
#define	GV_SETSTATE_CONFIG	0x2

/* Subdisk state bitmaps for plexes. */
#define	GV_SD_DOWNSTATE		0x01	/* Subdisk is down. */
#define	GV_SD_STALESTATE	0x02	/* Subdisk is stale. */
#define	GV_SD_INITSTATE		0x04	/* Subdisk is initializing. */
#define	GV_SD_UPSTATE		0x08	/* Subdisk is up. */

/* Synchronization/initialization request sizes. */
#define	GV_MIN_SYNCSIZE		512
#define	GV_MAX_SYNCSIZE		MAXPHYS
#define	GV_DFLT_SYNCSIZE	65536

/* Flags for BIOs, as they are processed within vinum. */
#define	GV_BIO_DONE	0x01
#define	GV_BIO_MALLOC	0x02
#define	GV_BIO_ONHOLD	0x04
#define	GV_BIO_SYNCREQ	0x08
#define	GV_BIO_INIT	0x10
#define	GV_BIO_REBUILD	0x20
#define	GV_BIO_CHECK	0x40
#define	GV_BIO_PARITY	0x80
#define	GV_BIO_RETRY	0x100
#define GV_BIO_INTERNAL \
    (GV_BIO_SYNCREQ | GV_BIO_INIT | GV_BIO_REBUILD |GV_BIO_CHECK)

/* Error codes to be used within gvinum. */
#define	GV_ERR_SETSTATE		(-1)	/* Error setting state. */
#define	GV_ERR_BADSIZE		(-2)	/* Object has wrong size. */
#define	GV_ERR_INVTYPE		(-3)    /* Invalid object type. */
#define	GV_ERR_CREATE		(-4)	/* Error creating gvinum object. */
#define	GV_ERR_ISBUSY		(-5)	/* Object is busy. */
#define	GV_ERR_ISATTACHED	(-6)	/* Object is attached to another. */
#define	GV_ERR_INVFLAG		(-7)	/* Invalid flag passed. */
#define	GV_ERR_INVSTATE		(-8)	/* Invalid state. */
#define	GV_ERR_NOTFOUND		(-9)	/* Object not found. */
#define	GV_ERR_NAMETAKEN	(-10)	/* Object name is taken. */
#define	GV_ERR_NOSPACE		(-11)	/* No space left on drive/subdisk. */
#define	GV_ERR_BADOFFSET	(-12)	/* Invalid offset specified. */
#define	GV_ERR_INVNAME		(-13)	/* Invalid object name. */
#define	GV_ERR_PLEXORG		(-14)	/* Invalid plex organization. */

/*
 * hostname is 256 bytes long, but we don't need to shlep multiple copies in
 * vinum.  We use the host name just to identify this system, and 32 bytes
 * should be ample for that purpose.
 */

#define	GV_HOSTNAME_LEN	32
struct gv_label {
	char	sysname[GV_HOSTNAME_LEN]; /* System name at creation time. */
	char	name[GV_MAXDRIVENAME];	/* Our name of the drive. */
	struct timeval	date_of_birth;	/* The time it was created ... */
	struct timeval	last_update;	/* ... and the time of last update. */
	off_t		drive_size;	/* Total size incl. headers. */
};

/* The 'header' of each valid vinum drive. */
struct gv_hdr {
	uint64_t	magic;
#define GV_OLD_MAGIC	0x494E2056494E4F00LL
#define GV_OLD_NOMAGIC	0x4E4F2056494E4F00LL
#define GV_MAGIC	0x56494E554D2D3100LL
#define GV_NOMAGIC	0x56494E554D2D2D00LL

	uint64_t	config_length;
	struct gv_label	label;
};

/* A single freelist entry of a drive. */
struct gv_freelist {
	off_t size;				/* Size of this free slot. */
	off_t offset;				/* Offset on the drive. */
	LIST_ENTRY(gv_freelist) freelist;
};

/*
 * Since we share structures between userland and kernel, we need this helper
 * struct instead of struct bio_queue_head and friends.  Maybe I find a proper
 * solution some day.
 */
struct gv_bioq {
	struct bio *bp;
	TAILQ_ENTRY(gv_bioq)	queue;
};

#define	GV_EVENT_DRIVE_TASTED		1
#define	GV_EVENT_DRIVE_LOST		2
#define	GV_EVENT_THREAD_EXIT		3
#define	GV_EVENT_CREATE_DRIVE		4
#define	GV_EVENT_CREATE_VOLUME		5
#define	GV_EVENT_CREATE_PLEX		6
#define	GV_EVENT_CREATE_SD		7
#define	GV_EVENT_SAVE_CONFIG		8
#define	GV_EVENT_RM_VOLUME		9
#define	GV_EVENT_RM_PLEX		10
#define	GV_EVENT_RM_SD			11
#define	GV_EVENT_RM_DRIVE		12
#define	GV_EVENT_SET_SD_STATE		13
#define	GV_EVENT_SET_DRIVE_STATE	14
#define	GV_EVENT_SET_VOL_STATE		15
#define	GV_EVENT_SET_PLEX_STATE		16
#define	GV_EVENT_RESET_CONFIG		17
#define	GV_EVENT_PARITY_REBUILD		18
#define	GV_EVENT_PARITY_CHECK		19
#define	GV_EVENT_START_PLEX		20
#define	GV_EVENT_START_VOLUME		21
#define	GV_EVENT_ATTACH_PLEX		22
#define	GV_EVENT_ATTACH_SD		23
#define	GV_EVENT_DETACH_PLEX		24
#define	GV_EVENT_DETACH_SD		25
#define	GV_EVENT_RENAME_VOL		26
#define	GV_EVENT_RENAME_PLEX		27
#define	GV_EVENT_RENAME_SD		28
#define	GV_EVENT_RENAME_DRIVE		29
#define	GV_EVENT_MOVE_SD		30
#define	GV_EVENT_SETUP_OBJECTS		31

#ifdef _KERNEL
struct gv_event {
	int	type;
	void	*arg1;
	void	*arg2;
	intmax_t arg3;
	intmax_t arg4;
	TAILQ_ENTRY(gv_event)	events;
};
#endif

/* This struct contains the main vinum config. */
struct gv_softc {
	/* Linked lists of all objects in our setup. */
	LIST_HEAD(,gv_drive)	drives;		/* All drives. */
	LIST_HEAD(,gv_plex)	plexes;		/* All plexes. */
	LIST_HEAD(,gv_sd)	subdisks;	/* All subdisks. */
	LIST_HEAD(,gv_volume)	volumes;	/* All volumes. */

	TAILQ_HEAD(,gv_event)	equeue;		/* Event queue. */
	struct mtx		queue_mtx;	/* Queue lock. */
	struct mtx		config_mtx;	/* Configuration lock. */
#ifdef	_KERNEL
	struct bio_queue_head	*bqueue;	/* BIO queue. */
#else
	char			*padding;
#endif
	struct g_geom		*geom;		/* Pointer to our VINUM geom. */
};

/* softc for a drive. */
struct gv_drive {
	char	name[GV_MAXDRIVENAME];		/* The name of this drive. */
	char	device[GV_MAXDRIVENAME];	/* Associated device. */
	int	state;				/* The state of this drive. */
#define	GV_DRIVE_DOWN	0
#define	GV_DRIVE_UP	1

	off_t	size;				/* Size of this drive. */
	off_t	avail;				/* Available space. */
	int	sdcount;			/* Number of subdisks. */

	int	flags;
#define	GV_DRIVE_REFERENCED	0x01	/* The drive isn't really existing,
					   but was referenced by a subdisk
					   during taste. */

	struct gv_hdr	*hdr;		/* The drive header. */

	struct g_consumer *consumer;	/* Consumer attached to this drive. */

	int freelist_entries;			/* Count of freelist entries. */
	LIST_HEAD(,gv_freelist)	freelist;	/* List of freelist entries. */
	LIST_HEAD(,gv_sd)	subdisks;	/* Subdisks on this drive. */
	LIST_ENTRY(gv_drive)	drive;		/* Entry in the vinum config. */

	struct gv_softc	*vinumconf;		/* Pointer to the vinum conf. */
};

/* softc for a subdisk. */
struct gv_sd {
	char	name[GV_MAXSDNAME];	/* The name of this subdisk. */
	off_t	size;			/* The size of this subdisk. */
	off_t	drive_offset;		/* Offset in the underlying drive. */
	off_t	plex_offset;		/* Offset in the associated plex. */
	int	state;			/* The state of this subdisk. */
#define	GV_SD_DOWN		0
#define	GV_SD_STALE		1
#define	GV_SD_INITIALIZING	2
#define	GV_SD_REVIVING		3
#define	GV_SD_UP		4

	off_t	initialized;		/* Count of initialized bytes. */

	int	init_size;		/* Initialization read/write size. */
	int	init_error;		/* Flag error on initialization. */

	int	flags;
#define	GV_SD_NEWBORN		0x01	/* Subdisk is created by user. */
#define	GV_SD_TASTED		0x02	/* Subdisk is created during taste. */
#define	GV_SD_CANGOUP		0x04	/* Subdisk can go up immediately. */
#define GV_SD_GROW		0x08	/* Subdisk is added to striped plex. */

	char drive[GV_MAXDRIVENAME];	/* Name of underlying drive. */
	char plex[GV_MAXPLEXNAME];	/* Name of associated plex. */

	struct gv_drive	*drive_sc;	/* Pointer to underlying drive. */
	struct gv_plex	*plex_sc;	/* Pointer to associated plex. */

	LIST_ENTRY(gv_sd) from_drive;	/* Subdisk list of underlying drive. */
	LIST_ENTRY(gv_sd) in_plex;	/* Subdisk list of associated plex. */
	LIST_ENTRY(gv_sd) sd;		/* Entry in the vinum config. */

	struct gv_softc	*vinumconf;	/* Pointer to the vinum config. */
};

/* softc for a plex. */
struct gv_plex {
	char	name[GV_MAXPLEXNAME];	/* The name of the plex. */
	off_t	size;			/* The size of the plex. */
	int	state;			/* The plex state. */
#define	GV_PLEX_DOWN		0
#define	GV_PLEX_INITIALIZING	1
#define	GV_PLEX_DEGRADED	2
#define GV_PLEX_GROWABLE	3
#define	GV_PLEX_UP		4

	int	org;			/* The plex organisation. */
#define	GV_PLEX_DISORG	0
#define	GV_PLEX_CONCAT	1
#define	GV_PLEX_STRIPED	2
#define	GV_PLEX_RAID5	4

	int	stripesize;		/* The stripe size of the plex. */

	char	volume[GV_MAXVOLNAME];	/* Name of associated volume. */
	struct gv_volume *vol_sc;	/* Pointer to associated volume. */

	int	sddetached;		/* Number of detached subdisks. */
	int	sdcount;		/* Number of subdisks in this plex. */
	int	sddown;			/* Number of subdisks that are down. */
	int	flags;
#define	GV_PLEX_ADDED		0x01	/* Added to an existing volume. */
#define	GV_PLEX_SYNCING		0x02	/* Plex is syncing from another plex. */
#define	GV_PLEX_THREAD_ACTIVE	0x04	/* Plex has an active RAID5 thread. */
#define	GV_PLEX_THREAD_DIE	0x08	/* Signal the RAID5 thread to die. */
#define	GV_PLEX_THREAD_DEAD	0x10	/* The RAID5 thread has died. */
#define	GV_PLEX_NEWBORN		0x20	/* The plex was just created. */
#define GV_PLEX_REBUILDING	0x40	/* The plex is rebuilding. */
#define GV_PLEX_GROWING		0x80	/* The plex is growing. */

	off_t	synced;			/* Count of synced bytes. */

	TAILQ_HEAD(,gv_raid5_packet)	packets; /* RAID5 sub-requests. */

	LIST_HEAD(,gv_sd)   subdisks;	/* List of attached subdisks. */
	LIST_ENTRY(gv_plex) in_volume;	/* Plex list of associated volume. */
	LIST_ENTRY(gv_plex) plex;	/* Entry in the vinum config. */

#ifdef	_KERNEL
	struct bio_queue_head	*bqueue;	/* BIO queue. */
	struct bio_queue_head	*wqueue;	/* Waiting BIO queue. */
	struct bio_queue_head	*rqueue;	/* Rebuild waiting BIO queue. */
#else
	char			*bpad, *wpad, *rpad; /* Padding for userland. */
#endif

	struct gv_softc	*vinumconf;	/* Pointer to the vinum config. */
};

/* softc for a volume. */
struct gv_volume {
	char	name[GV_MAXVOLNAME];	/* The name of the volume. */
	off_t	size;			/* The size of the volume. */
	int	plexcount;		/* Number of plexes. */
	int	state;			/* The state of the volume. */
#define	GV_VOL_DOWN	0
#define	GV_VOL_UP	1

	int	flags;
#define	GV_VOL_THREAD_ACTIVE	0x01	/* Volume has an active thread. */
#define	GV_VOL_THREAD_DIE	0x02	/* Signal the thread to die. */
#define	GV_VOL_THREAD_DEAD	0x04	/* The thread has died. */
#define GV_VOL_NEWBORN		0x08	/* The volume was just created. */

	LIST_HEAD(,gv_plex)	plexes;		/* List of attached plexes. */
	LIST_ENTRY(gv_volume)	volume;		/* Entry in vinum config. */

	struct g_provider	*provider;	/* Provider of this volume. */

#ifdef	_KERNEL
	struct bio_queue_head	*wqueue;	/* BIO delayed request queue. */
#else
	char			*wpad; /* Padding for userland. */
#endif

	struct gv_plex	*last_read_plex;
	struct gv_softc	*vinumconf;	/* Pointer to the vinum config. */
};

#endif /* !_GEOM_VINUM_VAR_H */
OpenPOWER on IntegriCloud