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