2 * Copyright (c) 2004 Lukas Ertl
3 * Copyright (c) 1997, 1998, 1999
4 * Nan Yang Computer Services Limited. All rights reserved.
6 * Parts copyright (c) 1997, 1998 Cybernet Corporation, NetMAX project.
7 * Parts written by Greg Lehey.
9 * This software is distributed under the so-called ``Berkeley
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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
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.
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.
41 #ifndef _GEOM_VINUM_VAR_H_
42 #define _GEOM_VINUM_VAR_H_
47 * Vinum drives start with this structure:
50 * |--------------------------------------|
51 * | PDP-11 memorial boot block | 0
52 * |--------------------------------------|
53 * | Disk label, maybe | 1
54 * |--------------------------------------|
55 * | Slice definition (vinum_hdr) | 8
56 * |--------------------------------------|
58 * | Configuration info, first copy | 9
60 * |--------------------------------------|
62 * | Configuration info, second copy | 9 + size of config
64 * |--------------------------------------|
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. */
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) */
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. */
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
91 #define GV_TYPE_PLEX 2
93 #define GV_TYPE_DRIVE 4
95 /* State changing flags. */
96 #define GV_SETSTATE_FORCE 0x1
97 #define GV_SETSTATE_CONFIG 0x2
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. */
105 /* Synchronization/initialization request sizes. */
106 #define GV_MIN_SYNCSIZE 512
107 #define GV_MAX_SYNCSIZE MAXPHYS
108 #define GV_DFLT_SYNCSIZE 65536
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
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.
127 #define GV_HOSTNAME_LEN 32
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. */
136 /* The 'header' of each valid vinum drive. */
139 #define GV_MAGIC 22322600044678729LL
140 #define GV_NOMAGIC 22322600044678990LL
143 struct gv_label label;
146 /* A single freelist entry of a drive. */
148 off_t size; /* Size of this free slot. */
149 off_t offset; /* Offset on the drive. */
150 LIST_ENTRY(gv_freelist) freelist;
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
160 TAILQ_ENTRY(gv_bioq) queue;
163 /* This struct contains the main vinum config. */
165 /*struct mtx config_mtx; XXX not yet */
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. */
173 struct g_geom *geom; /* Pointer to our VINUM geom. */
176 /* softc for a 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
184 off_t size; /* Size of this drive. */
185 off_t avail; /* Available space. */
186 int sdcount; /* Number of subdisks. */
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. */
194 struct gv_hdr *hdr; /* The drive header. */
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. */
202 struct bio_queue_head *bqueue; /* BIO queue of this drive. */
206 struct mtx bqueue_mtx; /* Mtx. to protect the queue. */
208 struct g_geom *geom; /* The geom of this drive. */
209 struct gv_softc *vinumconf; /* Pointer to the vinum conf. */
212 /* softc for a subdisk. */
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. */
220 #define GV_SD_STALE 1
221 #define GV_SD_INITIALIZING 2
222 #define GV_SD_REVIVING 3
225 off_t initialized; /* Count of initialized bytes. */
227 int init_size; /* Initialization read/write size. */
228 int init_error; /* Flag error on initialization. */
231 #define GV_SD_NEWBORN 0x01 /* Subdisk was just created. */
232 #define GV_SD_INITCANCEL 0x02 /* Cancel initialization process. */
234 char drive[GV_MAXDRIVENAME]; /* Name of underlying drive. */
235 char plex[GV_MAXPLEXNAME]; /* Name of associated plex. */
237 struct gv_drive *drive_sc; /* Pointer to underlying drive. */
238 struct gv_plex *plex_sc; /* Pointer to associated plex. */
240 struct g_provider *provider; /* The provider this sd represents. */
241 struct g_consumer *consumer; /* Consumer attached to our provider. */
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. */
247 struct gv_softc *vinumconf; /* Pointer to the vinum config. */
250 /* softc for a 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
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
266 int stripesize; /* The stripe size of the plex. */
268 char volume[GV_MAXVOLNAME]; /* Name of associated volume. */
269 struct gv_volume *vol_sc; /* Pointer to associated volume. */
271 int sdcount; /* Number of subdisks in this plex. */
272 int sddown; /* Number of subdisks that are down. */
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. */
281 off_t synced; /* Count of synced bytes. */
283 struct mtx bqueue_mtx; /* Lock for the BIO queue. */
285 struct bio_queue_head *bqueue; /* BIO queue. */
286 struct bio_queue_head *wqueue; /* Waiting BIO queue. */
290 TAILQ_HEAD(,gv_raid5_packet) packets; /* RAID5 sub-requests. */
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. */
296 struct g_provider *provider; /* The provider this plex represents. */
297 struct g_consumer *consumer; /* Consumer attached to our provider. */
299 struct g_geom *geom; /* The geom of this plex. */
300 struct gv_softc *vinumconf; /* Pointer to the vinum config. */
303 /* softc for a 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
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. */
317 struct mtx bqueue_mtx; /* Lock for the BIO queue. */
319 struct bio_queue_head *bqueue; /* BIO queue. */
324 LIST_HEAD(,gv_plex) plexes; /* List of attached plexes. */
325 LIST_ENTRY(gv_volume) volume; /* Entry in vinum config. */
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. */
332 #endif /* !_GEOM_VINUM_VAR_H */