Print this page
3748 zfs headers should be C++ compatible
Submitted by: Justin Gibbs <justing@spectralogic.com>
Submitted by: Will Andrews <willa@spectralogic.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/sys/spa.h
+++ new/usr/src/uts/common/fs/zfs/sys/spa.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 25 */
26 26
27 27 #ifndef _SYS_SPA_H
28 28 #define _SYS_SPA_H
29 29
30 30 #include <sys/avl.h>
31 31 #include <sys/zfs_context.h>
32 32 #include <sys/nvpair.h>
33 33 #include <sys/sysmacros.h>
34 34 #include <sys/types.h>
35 35 #include <sys/fs/zfs.h>
36 36
37 37 #ifdef __cplusplus
38 38 extern "C" {
39 39 #endif
40 40
41 41 /*
42 42 * Forward references that lots of things need.
43 43 */
44 44 typedef struct spa spa_t;
45 45 typedef struct vdev vdev_t;
46 46 typedef struct metaslab metaslab_t;
47 47 typedef struct metaslab_group metaslab_group_t;
48 48 typedef struct metaslab_class metaslab_class_t;
49 49 typedef struct zio zio_t;
50 50 typedef struct zilog zilog_t;
51 51 typedef struct spa_aux_vdev spa_aux_vdev_t;
52 52 typedef struct ddt ddt_t;
53 53 typedef struct ddt_entry ddt_entry_t;
54 54 struct dsl_pool;
55 55 struct dsl_dataset;
56 56
57 57 /*
58 58 * General-purpose 32-bit and 64-bit bitfield encodings.
59 59 */
60 60 #define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len))
61 61 #define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len))
62 62 #define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low))
63 63 #define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low))
64 64
65 65 #define BF32_GET(x, low, len) BF32_DECODE(x, low, len)
66 66 #define BF64_GET(x, low, len) BF64_DECODE(x, low, len)
67 67
68 68 #define BF32_SET(x, low, len, val) \
69 69 ((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len))
70 70 #define BF64_SET(x, low, len, val) \
71 71 ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len))
72 72
73 73 #define BF32_GET_SB(x, low, len, shift, bias) \
74 74 ((BF32_GET(x, low, len) + (bias)) << (shift))
75 75 #define BF64_GET_SB(x, low, len, shift, bias) \
76 76 ((BF64_GET(x, low, len) + (bias)) << (shift))
77 77
78 78 #define BF32_SET_SB(x, low, len, shift, bias, val) \
79 79 BF32_SET(x, low, len, ((val) >> (shift)) - (bias))
80 80 #define BF64_SET_SB(x, low, len, shift, bias, val) \
81 81 BF64_SET(x, low, len, ((val) >> (shift)) - (bias))
82 82
83 83 /*
84 84 * We currently support nine block sizes, from 512 bytes to 128K.
85 85 * We could go higher, but the benefits are near-zero and the cost
86 86 * of COWing a giant block to modify one byte would become excessive.
87 87 */
88 88 #define SPA_MINBLOCKSHIFT 9
89 89 #define SPA_MAXBLOCKSHIFT 17
90 90 #define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT)
91 91 #define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT)
92 92
93 93 #define SPA_BLOCKSIZES (SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)
94 94
95 95 /*
96 96 * Size of block to hold the configuration data (a packed nvlist)
97 97 */
98 98 #define SPA_CONFIG_BLOCKSIZE (1ULL << 14)
99 99
100 100 /*
101 101 * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
102 102 * The ASIZE encoding should be at least 64 times larger (6 more bits)
103 103 * to support up to 4-way RAID-Z mirror mode with worst-case gang block
104 104 * overhead, three DVAs per bp, plus one more bit in case we do anything
105 105 * else that expands the ASIZE.
106 106 */
107 107 #define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */
108 108 #define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */
109 109 #define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */
110 110
111 111 /*
112 112 * All SPA data is represented by 128-bit data virtual addresses (DVAs).
113 113 * The members of the dva_t should be considered opaque outside the SPA.
114 114 */
115 115 typedef struct dva {
116 116 uint64_t dva_word[2];
117 117 } dva_t;
118 118
119 119 /*
120 120 * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
121 121 */
122 122 typedef struct zio_cksum {
123 123 uint64_t zc_word[4];
124 124 } zio_cksum_t;
125 125
126 126 /*
127 127 * Each block is described by its DVAs, time of birth, checksum, etc.
128 128 * The word-by-word, bit-by-bit layout of the blkptr is as follows:
129 129 *
130 130 * 64 56 48 40 32 24 16 8 0
131 131 * +-------+-------+-------+-------+-------+-------+-------+-------+
132 132 * 0 | vdev1 | GRID | ASIZE |
133 133 * +-------+-------+-------+-------+-------+-------+-------+-------+
134 134 * 1 |G| offset1 |
135 135 * +-------+-------+-------+-------+-------+-------+-------+-------+
136 136 * 2 | vdev2 | GRID | ASIZE |
137 137 * +-------+-------+-------+-------+-------+-------+-------+-------+
138 138 * 3 |G| offset2 |
139 139 * +-------+-------+-------+-------+-------+-------+-------+-------+
140 140 * 4 | vdev3 | GRID | ASIZE |
141 141 * +-------+-------+-------+-------+-------+-------+-------+-------+
142 142 * 5 |G| offset3 |
143 143 * +-------+-------+-------+-------+-------+-------+-------+-------+
144 144 * 6 |BDX|lvl| type | cksum | comp | PSIZE | LSIZE |
145 145 * +-------+-------+-------+-------+-------+-------+-------+-------+
146 146 * 7 | padding |
147 147 * +-------+-------+-------+-------+-------+-------+-------+-------+
148 148 * 8 | padding |
149 149 * +-------+-------+-------+-------+-------+-------+-------+-------+
150 150 * 9 | physical birth txg |
151 151 * +-------+-------+-------+-------+-------+-------+-------+-------+
152 152 * a | logical birth txg |
153 153 * +-------+-------+-------+-------+-------+-------+-------+-------+
154 154 * b | fill count |
155 155 * +-------+-------+-------+-------+-------+-------+-------+-------+
156 156 * c | checksum[0] |
157 157 * +-------+-------+-------+-------+-------+-------+-------+-------+
158 158 * d | checksum[1] |
159 159 * +-------+-------+-------+-------+-------+-------+-------+-------+
160 160 * e | checksum[2] |
161 161 * +-------+-------+-------+-------+-------+-------+-------+-------+
162 162 * f | checksum[3] |
163 163 * +-------+-------+-------+-------+-------+-------+-------+-------+
164 164 *
165 165 * Legend:
166 166 *
167 167 * vdev virtual device ID
168 168 * offset offset into virtual device
169 169 * LSIZE logical size
170 170 * PSIZE physical size (after compression)
171 171 * ASIZE allocated size (including RAID-Z parity and gang block headers)
172 172 * GRID RAID-Z layout information (reserved for future use)
173 173 * cksum checksum function
174 174 * comp compression function
175 175 * G gang block indicator
176 176 * B byteorder (endianness)
177 177 * D dedup
178 178 * X unused
179 179 * lvl level of indirection
180 180 * type DMU object type
181 181 * phys birth txg of block allocation; zero if same as logical birth txg
182 182 * log. birth transaction group in which the block was logically born
183 183 * fill count number of non-zero blocks under this bp
184 184 * checksum[4] 256-bit checksum of the data this bp describes
185 185 */
186 186 #define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */
187 187 #define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */
188 188
189 189 typedef struct blkptr {
190 190 dva_t blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */
191 191 uint64_t blk_prop; /* size, compression, type, etc */
192 192 uint64_t blk_pad[2]; /* Extra space for the future */
193 193 uint64_t blk_phys_birth; /* txg when block was allocated */
194 194 uint64_t blk_birth; /* transaction group at birth */
195 195 uint64_t blk_fill; /* fill count */
196 196 zio_cksum_t blk_cksum; /* 256-bit checksum */
197 197 } blkptr_t;
198 198
199 199 /*
200 200 * Macros to get and set fields in a bp or DVA.
201 201 */
202 202 #define DVA_GET_ASIZE(dva) \
203 203 BF64_GET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0)
204 204 #define DVA_SET_ASIZE(dva, x) \
205 205 BF64_SET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0, x)
206 206
207 207 #define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8)
208 208 #define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x)
209 209
210 210 #define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, 32)
211 211 #define DVA_SET_VDEV(dva, x) BF64_SET((dva)->dva_word[0], 32, 32, x)
212 212
213 213 #define DVA_GET_OFFSET(dva) \
214 214 BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0)
215 215 #define DVA_SET_OFFSET(dva, x) \
216 216 BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x)
217 217
218 218 #define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1)
219 219 #define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x)
220 220
221 221 #define BP_GET_LSIZE(bp) \
222 222 BF64_GET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1)
223 223 #define BP_SET_LSIZE(bp, x) \
224 224 BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
225 225
226 226 #define BP_GET_PSIZE(bp) \
227 227 BF64_GET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1)
228 228 #define BP_SET_PSIZE(bp, x) \
229 229 BF64_SET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1, x)
230 230
231 231 #define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 8)
232 232 #define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 8, x)
233 233
234 234 #define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8)
235 235 #define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x)
236 236
237 237 #define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8)
238 238 #define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x)
239 239
240 240 #define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5)
241 241 #define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x)
242 242
243 243 #define BP_GET_PROP_BIT_61(bp) BF64_GET((bp)->blk_prop, 61, 1)
244 244 #define BP_SET_PROP_BIT_61(bp, x) BF64_SET((bp)->blk_prop, 61, 1, x)
245 245
246 246 #define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1)
247 247 #define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x)
248 248
249 249 #define BP_GET_BYTEORDER(bp) (0 - BF64_GET((bp)->blk_prop, 63, 1))
250 250 #define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x)
251 251
252 252 #define BP_PHYSICAL_BIRTH(bp) \
253 253 ((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)
254 254
255 255 #define BP_SET_BIRTH(bp, logical, physical) \
256 256 { \
257 257 (bp)->blk_birth = (logical); \
258 258 (bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \
259 259 }
260 260
261 261 #define BP_GET_ASIZE(bp) \
262 262 (DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
263 263 DVA_GET_ASIZE(&(bp)->blk_dva[2]))
264 264
265 265 #define BP_GET_UCSIZE(bp) \
266 266 ((BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp))) ? \
267 267 BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp))
268 268
269 269 #define BP_GET_NDVAS(bp) \
270 270 (!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
271 271 !!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
272 272 !!DVA_GET_ASIZE(&(bp)->blk_dva[2]))
273 273
274 274 #define BP_COUNT_GANG(bp) \
275 275 (DVA_GET_GANG(&(bp)->blk_dva[0]) + \
276 276 DVA_GET_GANG(&(bp)->blk_dva[1]) + \
277 277 DVA_GET_GANG(&(bp)->blk_dva[2]))
278 278
279 279 #define DVA_EQUAL(dva1, dva2) \
280 280 ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
281 281 (dva1)->dva_word[0] == (dva2)->dva_word[0])
282 282
283 283 #define BP_EQUAL(bp1, bp2) \
284 284 (BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) && \
285 285 DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) && \
286 286 DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) && \
287 287 DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2]))
288 288
289 289 #define ZIO_CHECKSUM_EQUAL(zc1, zc2) \
290 290 (0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
291 291 ((zc1).zc_word[1] - (zc2).zc_word[1]) | \
292 292 ((zc1).zc_word[2] - (zc2).zc_word[2]) | \
293 293 ((zc1).zc_word[3] - (zc2).zc_word[3])))
294 294
295 295 #define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0)
296 296
297 297 #define ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3) \
298 298 { \
299 299 (zcp)->zc_word[0] = w0; \
300 300 (zcp)->zc_word[1] = w1; \
301 301 (zcp)->zc_word[2] = w2; \
302 302 (zcp)->zc_word[3] = w3; \
303 303 }
304 304
305 305 #define BP_IDENTITY(bp) (&(bp)->blk_dva[0])
306 306 #define BP_IS_GANG(bp) DVA_GET_GANG(BP_IDENTITY(bp))
307 307 #define BP_IS_HOLE(bp) ((bp)->blk_birth == 0)
308 308
309 309 /* BP_IS_RAIDZ(bp) assumes no block compression */
310 310 #define BP_IS_RAIDZ(bp) (DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \
311 311 BP_GET_PSIZE(bp))
312 312
313 313 #define BP_ZERO(bp) \
314 314 { \
315 315 (bp)->blk_dva[0].dva_word[0] = 0; \
316 316 (bp)->blk_dva[0].dva_word[1] = 0; \
317 317 (bp)->blk_dva[1].dva_word[0] = 0; \
318 318 (bp)->blk_dva[1].dva_word[1] = 0; \
319 319 (bp)->blk_dva[2].dva_word[0] = 0; \
320 320 (bp)->blk_dva[2].dva_word[1] = 0; \
321 321 (bp)->blk_prop = 0; \
322 322 (bp)->blk_pad[0] = 0; \
323 323 (bp)->blk_pad[1] = 0; \
324 324 (bp)->blk_phys_birth = 0; \
325 325 (bp)->blk_birth = 0; \
326 326 (bp)->blk_fill = 0; \
327 327 ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \
328 328 }
329 329
330 330 /*
331 331 * Note: the byteorder is either 0 or -1, both of which are palindromes.
332 332 * This simplifies the endianness handling a bit.
333 333 */
334 334 #ifdef _BIG_ENDIAN
335 335 #define ZFS_HOST_BYTEORDER (0ULL)
336 336 #else
337 337 #define ZFS_HOST_BYTEORDER (-1ULL)
338 338 #endif
339 339
340 340 #define BP_SHOULD_BYTESWAP(bp) (BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER)
341 341
342 342 #define BP_SPRINTF_LEN 320
343 343
344 344 /*
345 345 * This macro allows code sharing between zfs, libzpool, and mdb.
346 346 * 'func' is either snprintf() or mdb_snprintf().
347 347 * 'ws' (whitespace) can be ' ' for single-line format, '\n' for multi-line.
348 348 */
349 349 #define SPRINTF_BLKPTR(func, ws, buf, bp, type, checksum, compress) \
350 350 { \
351 351 static const char *copyname[] = \
352 352 { "zero", "single", "double", "triple" }; \
353 353 int size = BP_SPRINTF_LEN; \
354 354 int len = 0; \
355 355 int copies = 0; \
356 356 \
357 357 if (bp == NULL) { \
358 358 len = func(buf + len, size - len, "<NULL>"); \
359 359 } else if (BP_IS_HOLE(bp)) { \
360 360 len = func(buf + len, size - len, "<hole>"); \
361 361 } else { \
362 362 for (int d = 0; d < BP_GET_NDVAS(bp); d++) { \
363 363 const dva_t *dva = &bp->blk_dva[d]; \
364 364 if (DVA_IS_VALID(dva)) \
365 365 copies++; \
366 366 len += func(buf + len, size - len, \
367 367 "DVA[%d]=<%llu:%llx:%llx>%c", d, \
368 368 (u_longlong_t)DVA_GET_VDEV(dva), \
369 369 (u_longlong_t)DVA_GET_OFFSET(dva), \
370 370 (u_longlong_t)DVA_GET_ASIZE(dva), \
371 371 ws); \
372 372 } \
373 373 if (BP_IS_GANG(bp) && \
374 374 DVA_GET_ASIZE(&bp->blk_dva[2]) <= \
375 375 DVA_GET_ASIZE(&bp->blk_dva[1]) / 2) \
376 376 copies--; \
377 377 len += func(buf + len, size - len, \
378 378 "[L%llu %s] %s %s %s %s %s %s%c" \
379 379 "size=%llxL/%llxP birth=%lluL/%lluP fill=%llu%c" \
380 380 "cksum=%llx:%llx:%llx:%llx", \
381 381 (u_longlong_t)BP_GET_LEVEL(bp), \
382 382 type, \
383 383 checksum, \
384 384 compress, \
385 385 BP_GET_BYTEORDER(bp) == 0 ? "BE" : "LE", \
386 386 BP_IS_GANG(bp) ? "gang" : "contiguous", \
387 387 BP_GET_DEDUP(bp) ? "dedup" : "unique", \
388 388 copyname[copies], \
389 389 ws, \
390 390 (u_longlong_t)BP_GET_LSIZE(bp), \
391 391 (u_longlong_t)BP_GET_PSIZE(bp), \
392 392 (u_longlong_t)bp->blk_birth, \
393 393 (u_longlong_t)BP_PHYSICAL_BIRTH(bp), \
394 394 (u_longlong_t)bp->blk_fill, \
395 395 ws, \
396 396 (u_longlong_t)bp->blk_cksum.zc_word[0], \
397 397 (u_longlong_t)bp->blk_cksum.zc_word[1], \
398 398 (u_longlong_t)bp->blk_cksum.zc_word[2], \
399 399 (u_longlong_t)bp->blk_cksum.zc_word[3]); \
400 400 } \
401 401 ASSERT(len < size); \
402 402 }
403 403
404 404 #include <sys/dmu.h>
405 405
406 406 #define BP_GET_BUFC_TYPE(bp) \
407 407 (((BP_GET_LEVEL(bp) > 0) || (DMU_OT_IS_METADATA(BP_GET_TYPE(bp)))) ? \
408 408 ARC_BUFC_METADATA : ARC_BUFC_DATA)
409 409
410 410 typedef enum spa_import_type {
411 411 SPA_IMPORT_EXISTING,
412 412 SPA_IMPORT_ASSEMBLE
413 413 } spa_import_type_t;
414 414
415 415 /* state manipulation functions */
416 416 extern int spa_open(const char *pool, spa_t **, void *tag);
417 417 extern int spa_open_rewind(const char *pool, spa_t **, void *tag,
418 418 nvlist_t *policy, nvlist_t **config);
419 419 extern int spa_get_stats(const char *pool, nvlist_t **config, char *altroot,
420 420 size_t buflen);
421 421 extern int spa_create(const char *pool, nvlist_t *config, nvlist_t *props,
422 422 nvlist_t *zplprops);
423 423 extern int spa_import_rootpool(char *devpath, char *devid);
424 424 extern int spa_import(const char *pool, nvlist_t *config, nvlist_t *props,
425 425 uint64_t flags);
426 426 extern nvlist_t *spa_tryimport(nvlist_t *tryconfig);
427 427 extern int spa_destroy(char *pool);
428 428 extern int spa_export(char *pool, nvlist_t **oldconfig, boolean_t force,
429 429 boolean_t hardforce);
430 430 extern int spa_reset(char *pool);
431 431 extern void spa_async_request(spa_t *spa, int flag);
432 432 extern void spa_async_unrequest(spa_t *spa, int flag);
433 433 extern void spa_async_suspend(spa_t *spa);
434 434 extern void spa_async_resume(spa_t *spa);
435 435 extern spa_t *spa_inject_addref(char *pool);
436 436 extern void spa_inject_delref(spa_t *spa);
437 437 extern void spa_scan_stat_init(spa_t *spa);
438 438 extern int spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps);
439 439
440 440 #define SPA_ASYNC_CONFIG_UPDATE 0x01
441 441 #define SPA_ASYNC_REMOVE 0x02
442 442 #define SPA_ASYNC_PROBE 0x04
443 443 #define SPA_ASYNC_RESILVER_DONE 0x08
444 444 #define SPA_ASYNC_RESILVER 0x10
445 445 #define SPA_ASYNC_AUTOEXPAND 0x20
446 446 #define SPA_ASYNC_REMOVE_DONE 0x40
447 447 #define SPA_ASYNC_REMOVE_STOP 0x80
448 448
449 449 /*
450 450 * Controls the behavior of spa_vdev_remove().
451 451 */
452 452 #define SPA_REMOVE_UNSPARE 0x01
453 453 #define SPA_REMOVE_DONE 0x02
454 454
455 455 /* device manipulation */
456 456 extern int spa_vdev_add(spa_t *spa, nvlist_t *nvroot);
457 457 extern int spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot,
458 458 int replacing);
459 459 extern int spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid,
460 460 int replace_done);
461 461 extern int spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare);
462 462 extern boolean_t spa_vdev_remove_active(spa_t *spa);
463 463 extern int spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath);
464 464 extern int spa_vdev_setfru(spa_t *spa, uint64_t guid, const char *newfru);
465 465 extern int spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
466 466 nvlist_t *props, boolean_t exp);
467 467
468 468 /* spare state (which is global across all pools) */
469 469 extern void spa_spare_add(vdev_t *vd);
470 470 extern void spa_spare_remove(vdev_t *vd);
471 471 extern boolean_t spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt);
472 472 extern void spa_spare_activate(vdev_t *vd);
473 473
474 474 /* L2ARC state (which is global across all pools) */
475 475 extern void spa_l2cache_add(vdev_t *vd);
476 476 extern void spa_l2cache_remove(vdev_t *vd);
477 477 extern boolean_t spa_l2cache_exists(uint64_t guid, uint64_t *pool);
478 478 extern void spa_l2cache_activate(vdev_t *vd);
479 479 extern void spa_l2cache_drop(spa_t *spa);
480 480
481 481 /* scanning */
482 482 extern int spa_scan(spa_t *spa, pool_scan_func_t func);
483 483 extern int spa_scan_stop(spa_t *spa);
484 484
485 485 /* spa syncing */
486 486 extern void spa_sync(spa_t *spa, uint64_t txg); /* only for DMU use */
487 487 extern void spa_sync_allpools(void);
488 488
489 489 /* spa namespace global mutex */
490 490 extern kmutex_t spa_namespace_lock;
491 491
492 492 /*
493 493 * SPA configuration functions in spa_config.c
494 494 */
495 495
496 496 #define SPA_CONFIG_UPDATE_POOL 0
497 497 #define SPA_CONFIG_UPDATE_VDEVS 1
498 498
499 499 extern void spa_config_sync(spa_t *, boolean_t, boolean_t);
500 500 extern void spa_config_load(void);
501 501 extern nvlist_t *spa_all_configs(uint64_t *);
502 502 extern void spa_config_set(spa_t *spa, nvlist_t *config);
503 503 extern nvlist_t *spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg,
504 504 int getstats);
505 505 extern void spa_config_update(spa_t *spa, int what);
506 506
507 507 /*
508 508 * Miscellaneous SPA routines in spa_misc.c
509 509 */
510 510
511 511 /* Namespace manipulation */
512 512 extern spa_t *spa_lookup(const char *name);
513 513 extern spa_t *spa_add(const char *name, nvlist_t *config, const char *altroot);
514 514 extern void spa_remove(spa_t *spa);
515 515 extern spa_t *spa_next(spa_t *prev);
516 516
517 517 /* Refcount functions */
518 518 extern void spa_open_ref(spa_t *spa, void *tag);
519 519 extern void spa_close(spa_t *spa, void *tag);
520 520 extern boolean_t spa_refcount_zero(spa_t *spa);
521 521
522 522 #define SCL_NONE 0x00
523 523 #define SCL_CONFIG 0x01
524 524 #define SCL_STATE 0x02
525 525 #define SCL_L2ARC 0x04 /* hack until L2ARC 2.0 */
526 526 #define SCL_ALLOC 0x08
527 527 #define SCL_ZIO 0x10
528 528 #define SCL_FREE 0x20
529 529 #define SCL_VDEV 0x40
530 530 #define SCL_LOCKS 7
531 531 #define SCL_ALL ((1 << SCL_LOCKS) - 1)
532 532 #define SCL_STATE_ALL (SCL_STATE | SCL_L2ARC | SCL_ZIO)
533 533
534 534 /* Pool configuration locks */
535 535 extern int spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw);
536 536 extern void spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw);
537 537 extern void spa_config_exit(spa_t *spa, int locks, void *tag);
538 538 extern int spa_config_held(spa_t *spa, int locks, krw_t rw);
539 539
540 540 /* Pool vdev add/remove lock */
541 541 extern uint64_t spa_vdev_enter(spa_t *spa);
542 542 extern uint64_t spa_vdev_config_enter(spa_t *spa);
543 543 extern void spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg,
544 544 int error, char *tag);
545 545 extern int spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error);
546 546
547 547 /* Pool vdev state change lock */
548 548 extern void spa_vdev_state_enter(spa_t *spa, int oplock);
549 549 extern int spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error);
550 550
551 551 /* Log state */
552 552 typedef enum spa_log_state {
553 553 SPA_LOG_UNKNOWN = 0, /* unknown log state */
554 554 SPA_LOG_MISSING, /* missing log(s) */
555 555 SPA_LOG_CLEAR, /* clear the log(s) */
556 556 SPA_LOG_GOOD, /* log(s) are good */
557 557 } spa_log_state_t;
558 558
559 559 extern spa_log_state_t spa_get_log_state(spa_t *spa);
560 560 extern void spa_set_log_state(spa_t *spa, spa_log_state_t state);
561 561 extern int spa_offline_log(spa_t *spa);
562 562
563 563 /* Log claim callback */
564 564 extern void spa_claim_notify(zio_t *zio);
565 565
566 566 /* Accessor functions */
567 567 extern boolean_t spa_shutting_down(spa_t *spa);
568 568 extern struct dsl_pool *spa_get_dsl(spa_t *spa);
569 569 extern boolean_t spa_is_initializing(spa_t *spa);
570 570 extern blkptr_t *spa_get_rootblkptr(spa_t *spa);
571 571 extern void spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp);
572 572 extern void spa_altroot(spa_t *, char *, size_t);
573 573 extern int spa_sync_pass(spa_t *spa);
574 574 extern char *spa_name(spa_t *spa);
575 575 extern uint64_t spa_guid(spa_t *spa);
576 576 extern uint64_t spa_load_guid(spa_t *spa);
577 577 extern uint64_t spa_last_synced_txg(spa_t *spa);
578 578 extern uint64_t spa_first_txg(spa_t *spa);
579 579 extern uint64_t spa_syncing_txg(spa_t *spa);
580 580 extern uint64_t spa_version(spa_t *spa);
581 581 extern pool_state_t spa_state(spa_t *spa);
582 582 extern spa_load_state_t spa_load_state(spa_t *spa);
583 583 extern uint64_t spa_freeze_txg(spa_t *spa);
584 584 extern uint64_t spa_get_asize(spa_t *spa, uint64_t lsize);
585 585 extern uint64_t spa_get_dspace(spa_t *spa);
586 586 extern void spa_update_dspace(spa_t *spa);
587 587 extern uint64_t spa_version(spa_t *spa);
588 588 extern boolean_t spa_deflate(spa_t *spa);
589 589 extern metaslab_class_t *spa_normal_class(spa_t *spa);
590 590 extern metaslab_class_t *spa_log_class(spa_t *spa);
591 591 extern int spa_max_replication(spa_t *spa);
592 592 extern int spa_prev_software_version(spa_t *spa);
593 593 extern int spa_busy(void);
594 594 extern uint8_t spa_get_failmode(spa_t *spa);
595 595 extern boolean_t spa_suspended(spa_t *spa);
596 596 extern uint64_t spa_bootfs(spa_t *spa);
597 597 extern uint64_t spa_delegation(spa_t *spa);
598 598 extern objset_t *spa_meta_objset(spa_t *spa);
599 599 extern uint64_t spa_deadman_synctime(spa_t *spa);
600 600
601 601 /* Miscellaneous support routines */
602 602 extern void spa_activate_mos_feature(spa_t *spa, const char *feature);
603 603 extern void spa_deactivate_mos_feature(spa_t *spa, const char *feature);
604 604 extern int spa_rename(const char *oldname, const char *newname);
605 605 extern spa_t *spa_by_guid(uint64_t pool_guid, uint64_t device_guid);
606 606 extern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid);
607 607 extern char *spa_strdup(const char *);
608 608 extern void spa_strfree(char *);
609 609 extern uint64_t spa_get_random(uint64_t range);
610 610 extern uint64_t spa_generate_guid(spa_t *spa);
611 611 extern void sprintf_blkptr(char *buf, const blkptr_t *bp);
612 612 extern void spa_freeze(spa_t *spa);
613 613 extern int spa_change_guid(spa_t *spa);
614 614 extern void spa_upgrade(spa_t *spa, uint64_t version);
615 615 extern void spa_evict_all(void);
616 616 extern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid,
617 617 boolean_t l2cache);
618 618 extern boolean_t spa_has_spare(spa_t *, uint64_t guid);
619 619 extern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva);
620 620 extern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp);
621 621 extern uint64_t bp_get_dsize(spa_t *spa, const blkptr_t *bp);
622 622 extern boolean_t spa_has_slogs(spa_t *spa);
623 623 extern boolean_t spa_is_root(spa_t *spa);
624 624 extern boolean_t spa_writeable(spa_t *spa);
625 625
626 626 extern int spa_mode(spa_t *spa);
627 627 extern uint64_t strtonum(const char *str, char **nptr);
628 628
629 629 extern char *spa_his_ievent_table[];
630 630
631 631 extern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx);
632 632 extern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read,
633 633 char *his_buf);
634 634 extern int spa_history_log(spa_t *spa, const char *his_buf);
635 635 extern int spa_history_log_nvl(spa_t *spa, nvlist_t *nvl);
636 636 extern void spa_history_log_version(spa_t *spa, const char *operation);
↓ open down ↓ |
636 lines elided |
↑ open up ↑ |
637 637 extern void spa_history_log_internal(spa_t *spa, const char *operation,
638 638 dmu_tx_t *tx, const char *fmt, ...);
639 639 extern void spa_history_log_internal_ds(struct dsl_dataset *ds, const char *op,
640 640 dmu_tx_t *tx, const char *fmt, ...);
641 641 extern void spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation,
642 642 dmu_tx_t *tx, const char *fmt, ...);
643 643
644 644 /* error handling */
645 645 struct zbookmark;
646 646 extern void spa_log_error(spa_t *spa, zio_t *zio);
647 -extern void zfs_ereport_post(const char *class, spa_t *spa, vdev_t *vd,
647 +extern void zfs_ereport_post(const char *subclass, spa_t *spa, vdev_t *vd,
648 648 zio_t *zio, uint64_t stateoroffset, uint64_t length);
649 649 extern void zfs_post_remove(spa_t *spa, vdev_t *vd);
650 650 extern void zfs_post_state_change(spa_t *spa, vdev_t *vd);
651 651 extern void zfs_post_autoreplace(spa_t *spa, vdev_t *vd);
652 652 extern uint64_t spa_get_errlog_size(spa_t *spa);
653 653 extern int spa_get_errlog(spa_t *spa, void *uaddr, size_t *count);
654 654 extern void spa_errlog_rotate(spa_t *spa);
655 655 extern void spa_errlog_drain(spa_t *spa);
656 656 extern void spa_errlog_sync(spa_t *spa, uint64_t txg);
657 657 extern void spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub);
658 658
659 659 /* vdev cache */
660 660 extern void vdev_cache_stat_init(void);
661 661 extern void vdev_cache_stat_fini(void);
662 662
663 663 /* Initialization and termination */
664 664 extern void spa_init(int flags);
665 665 extern void spa_fini(void);
666 666 extern void spa_boot_init();
667 667
668 668 /* properties */
669 669 extern int spa_prop_set(spa_t *spa, nvlist_t *nvp);
670 670 extern int spa_prop_get(spa_t *spa, nvlist_t **nvp);
671 671 extern void spa_prop_clear_bootfs(spa_t *spa, uint64_t obj, dmu_tx_t *tx);
672 672 extern void spa_configfile_set(spa_t *, nvlist_t *, boolean_t);
673 673
674 674 /* asynchronous event notification */
675 675 extern void spa_event_notify(spa_t *spa, vdev_t *vdev, const char *name);
676 676
677 677 #ifdef ZFS_DEBUG
678 678 #define dprintf_bp(bp, fmt, ...) do { \
679 679 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
680 680 char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP); \
681 681 sprintf_blkptr(__blkbuf, (bp)); \
682 682 dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf); \
683 683 kmem_free(__blkbuf, BP_SPRINTF_LEN); \
684 684 } \
685 685 _NOTE(CONSTCOND) } while (0)
686 686 #else
687 687 #define dprintf_bp(bp, fmt, ...)
688 688 #endif
689 689
690 690 extern boolean_t spa_debug_enabled(spa_t *spa);
691 691 #define spa_dbgmsg(spa, ...) \
692 692 { \
693 693 if (spa_debug_enabled(spa)) \
694 694 zfs_dbgmsg(__VA_ARGS__); \
695 695 }
696 696
697 697 extern int spa_mode_global; /* mode, e.g. FREAD | FWRITE */
698 698
699 699 #ifdef __cplusplus
700 700 }
701 701 #endif
702 702
703 703 #endif /* _SYS_SPA_H */
↓ open down ↓ |
46 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX