]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
7 | * | |
8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 | * or http://www.opensolaris.org/os/licensing. | |
10 | * See the License for the specific language governing permissions | |
11 | * and limitations under the License. | |
12 | * | |
13 | * When distributing Covered Code, include this CDDL HEADER in each | |
14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 | * If applicable, add the following below this CDDL HEADER, with the | |
16 | * fields enclosed by brackets "[]" replaced with your own identifying | |
17 | * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
21 | /* | |
428870ff | 22 | * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
cc99f275 | 23 | * Copyright (c) 2011, 2018 by Delphix. All rights reserved. |
3541dc6d | 24 | * Copyright 2011 Nexenta Systems, Inc. All rights reserved. |
0c66c32d | 25 | * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved. |
3c67d83a | 26 | * Copyright 2013 Saso Kiselkov. All rights reserved. |
12fa0466 DE |
27 | * Copyright (c) 2014 Integros [integros.com] |
28 | * Copyright 2017 Joyent, Inc. | |
0ea05c64 | 29 | * Copyright (c) 2017 Datto Inc. |
cc99f275 | 30 | * Copyright (c) 2017, Intel Corporation. |
34dc7c2f BB |
31 | */ |
32 | ||
33 | #ifndef _SYS_SPA_H | |
34 | #define _SYS_SPA_H | |
35 | ||
34dc7c2f BB |
36 | #include <sys/avl.h> |
37 | #include <sys/zfs_context.h> | |
efcd79a8 | 38 | #include <sys/kstat.h> |
34dc7c2f BB |
39 | #include <sys/nvpair.h> |
40 | #include <sys/sysmacros.h> | |
41 | #include <sys/types.h> | |
42 | #include <sys/fs/zfs.h> | |
1eeb4562 | 43 | #include <sys/spa_checksum.h> |
c4434877 | 44 | #include <sys/dmu.h> |
34dc7c2f BB |
45 | |
46 | #ifdef __cplusplus | |
47 | extern "C" { | |
48 | #endif | |
49 | ||
50 | /* | |
51 | * Forward references that lots of things need. | |
52 | */ | |
53 | typedef struct spa spa_t; | |
54 | typedef struct vdev vdev_t; | |
55 | typedef struct metaslab metaslab_t; | |
428870ff BB |
56 | typedef struct metaslab_group metaslab_group_t; |
57 | typedef struct metaslab_class metaslab_class_t; | |
58 | typedef struct zio zio_t; | |
34dc7c2f | 59 | typedef struct zilog zilog_t; |
34dc7c2f | 60 | typedef struct spa_aux_vdev spa_aux_vdev_t; |
428870ff BB |
61 | typedef struct ddt ddt_t; |
62 | typedef struct ddt_entry ddt_entry_t; | |
5dbd68a3 | 63 | typedef struct zbookmark_phys zbookmark_phys_t; |
1421c891 | 64 | |
34dc7c2f | 65 | struct dsl_pool; |
6f1ffb06 | 66 | struct dsl_dataset; |
b5256303 | 67 | struct dsl_crypto_params; |
34dc7c2f BB |
68 | |
69 | /* | |
70 | * General-purpose 32-bit and 64-bit bitfield encodings. | |
71 | */ | |
72 | #define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len)) | |
73 | #define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len)) | |
74 | #define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low)) | |
75 | #define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low)) | |
76 | ||
77 | #define BF32_GET(x, low, len) BF32_DECODE(x, low, len) | |
78 | #define BF64_GET(x, low, len) BF64_DECODE(x, low, len) | |
79 | ||
b0bc7a84 MG |
80 | #define BF32_SET(x, low, len, val) do { \ |
81 | ASSERT3U(val, <, 1U << (len)); \ | |
82 | ASSERT3U(low + len, <=, 32); \ | |
83 | (x) ^= BF32_ENCODE((x >> low) ^ (val), low, len); \ | |
84 | _NOTE(CONSTCOND) } while (0) | |
85 | ||
86 | #define BF64_SET(x, low, len, val) do { \ | |
87 | ASSERT3U(val, <, 1ULL << (len)); \ | |
88 | ASSERT3U(low + len, <=, 64); \ | |
89 | ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len)); \ | |
90 | _NOTE(CONSTCOND) } while (0) | |
34dc7c2f BB |
91 | |
92 | #define BF32_GET_SB(x, low, len, shift, bias) \ | |
93 | ((BF32_GET(x, low, len) + (bias)) << (shift)) | |
94 | #define BF64_GET_SB(x, low, len, shift, bias) \ | |
95 | ((BF64_GET(x, low, len) + (bias)) << (shift)) | |
96 | ||
b0bc7a84 MG |
97 | #define BF32_SET_SB(x, low, len, shift, bias, val) do { \ |
98 | ASSERT(IS_P2ALIGNED(val, 1U << shift)); \ | |
99 | ASSERT3S((val) >> (shift), >=, bias); \ | |
100 | BF32_SET(x, low, len, ((val) >> (shift)) - (bias)); \ | |
101 | _NOTE(CONSTCOND) } while (0) | |
102 | #define BF64_SET_SB(x, low, len, shift, bias, val) do { \ | |
103 | ASSERT(IS_P2ALIGNED(val, 1ULL << shift)); \ | |
104 | ASSERT3S((val) >> (shift), >=, bias); \ | |
105 | BF64_SET(x, low, len, ((val) >> (shift)) - (bias)); \ | |
106 | _NOTE(CONSTCOND) } while (0) | |
34dc7c2f BB |
107 | |
108 | /* | |
f1512ee6 MA |
109 | * We currently support block sizes from 512 bytes to 16MB. |
110 | * The benefits of larger blocks, and thus larger IO, need to be weighed | |
111 | * against the cost of COWing a giant block to modify one byte, and the | |
112 | * large latency of reading or writing a large block. | |
113 | * | |
114 | * Note that although blocks up to 16MB are supported, the recordsize | |
115 | * property can not be set larger than zfs_max_recordsize (default 1MB). | |
116 | * See the comment near zfs_max_recordsize in dsl_dataset.c for details. | |
117 | * | |
118 | * Note that although the LSIZE field of the blkptr_t can store sizes up | |
119 | * to 32MB, the dnode's dn_datablkszsec can only store sizes up to | |
120 | * 32MB - 512 bytes. Therefore, we limit SPA_MAXBLOCKSIZE to 16MB. | |
34dc7c2f BB |
121 | */ |
122 | #define SPA_MINBLOCKSHIFT 9 | |
f1512ee6 MA |
123 | #define SPA_OLD_MAXBLOCKSHIFT 17 |
124 | #define SPA_MAXBLOCKSHIFT 24 | |
34dc7c2f | 125 | #define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT) |
f1512ee6 | 126 | #define SPA_OLD_MAXBLOCKSIZE (1ULL << SPA_OLD_MAXBLOCKSHIFT) |
34dc7c2f BB |
127 | #define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT) |
128 | ||
ff61d1a4 | 129 | /* |
130 | * Alignment Shift (ashift) is an immutable, internal top-level vdev property | |
131 | * which can only be set at vdev creation time. Physical writes are always done | |
132 | * according to it, which makes 2^ashift the smallest possible IO on a vdev. | |
133 | * | |
dddef7d6 | 134 | * We currently allow values ranging from 512 bytes (2^9 = 512) to 64 KiB |
135 | * (2^16 = 65,536). | |
ff61d1a4 | 136 | */ |
137 | #define ASHIFT_MIN 9 | |
dddef7d6 | 138 | #define ASHIFT_MAX 16 |
ff61d1a4 | 139 | |
b128c09f BB |
140 | /* |
141 | * Size of block to hold the configuration data (a packed nvlist) | |
142 | */ | |
9ae529ec | 143 | #define SPA_CONFIG_BLOCKSIZE (1ULL << 14) |
b128c09f | 144 | |
34dc7c2f BB |
145 | /* |
146 | * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB. | |
147 | * The ASIZE encoding should be at least 64 times larger (6 more bits) | |
148 | * to support up to 4-way RAID-Z mirror mode with worst-case gang block | |
149 | * overhead, three DVAs per bp, plus one more bit in case we do anything | |
150 | * else that expands the ASIZE. | |
151 | */ | |
152 | #define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */ | |
153 | #define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */ | |
154 | #define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */ | |
155 | ||
d3c2ae1c | 156 | #define SPA_COMPRESSBITS 7 |
4d044c4c | 157 | #define SPA_VDEVBITS 24 |
d3c2ae1c | 158 | |
34dc7c2f BB |
159 | /* |
160 | * All SPA data is represented by 128-bit data virtual addresses (DVAs). | |
161 | * The members of the dva_t should be considered opaque outside the SPA. | |
162 | */ | |
163 | typedef struct dva { | |
164 | uint64_t dva_word[2]; | |
165 | } dva_t; | |
166 | ||
34dc7c2f | 167 | |
3c67d83a TH |
168 | /* |
169 | * Some checksums/hashes need a 256-bit initialization salt. This salt is kept | |
170 | * secret and is suitable for use in MAC algorithms as the key. | |
171 | */ | |
172 | typedef struct zio_cksum_salt { | |
173 | uint8_t zcs_bytes[32]; | |
174 | } zio_cksum_salt_t; | |
175 | ||
34dc7c2f BB |
176 | /* |
177 | * Each block is described by its DVAs, time of birth, checksum, etc. | |
178 | * The word-by-word, bit-by-bit layout of the blkptr is as follows: | |
179 | * | |
180 | * 64 56 48 40 32 24 16 8 0 | |
181 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
4d044c4c | 182 | * 0 | pad | vdev1 | GRID | ASIZE | |
34dc7c2f BB |
183 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
184 | * 1 |G| offset1 | | |
185 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
4d044c4c | 186 | * 2 | pad | vdev2 | GRID | ASIZE | |
34dc7c2f BB |
187 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
188 | * 3 |G| offset2 | | |
189 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
4d044c4c | 190 | * 4 | pad | vdev3 | GRID | ASIZE | |
34dc7c2f BB |
191 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
192 | * 5 |G| offset3 | | |
193 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
9b67f605 | 194 | * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE | |
34dc7c2f BB |
195 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
196 | * 7 | padding | | |
197 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
198 | * 8 | padding | | |
199 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
428870ff | 200 | * 9 | physical birth txg | |
34dc7c2f | 201 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
428870ff | 202 | * a | logical birth txg | |
34dc7c2f BB |
203 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
204 | * b | fill count | | |
205 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
206 | * c | checksum[0] | | |
207 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
208 | * d | checksum[1] | | |
209 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
210 | * e | checksum[2] | | |
211 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
212 | * f | checksum[3] | | |
213 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
214 | * | |
215 | * Legend: | |
216 | * | |
217 | * vdev virtual device ID | |
218 | * offset offset into virtual device | |
219 | * LSIZE logical size | |
220 | * PSIZE physical size (after compression) | |
221 | * ASIZE allocated size (including RAID-Z parity and gang block headers) | |
222 | * GRID RAID-Z layout information (reserved for future use) | |
223 | * cksum checksum function | |
224 | * comp compression function | |
225 | * G gang block indicator | |
428870ff BB |
226 | * B byteorder (endianness) |
227 | * D dedup | |
b5256303 | 228 | * X encryption |
9b67f605 | 229 | * E blkptr_t contains embedded data (see below) |
34dc7c2f | 230 | * lvl level of indirection |
428870ff | 231 | * type DMU object type |
a1d477c2 MA |
232 | * phys birth txg when dva[0] was written; zero if same as logical birth txg |
233 | * note that typically all the dva's would be written in this | |
234 | * txg, but they could be different if they were moved by | |
235 | * device removal. | |
428870ff | 236 | * log. birth transaction group in which the block was logically born |
34dc7c2f BB |
237 | * fill count number of non-zero blocks under this bp |
238 | * checksum[4] 256-bit checksum of the data this bp describes | |
239 | */ | |
9b67f605 | 240 | |
b5256303 TC |
241 | /* |
242 | * The blkptr_t's of encrypted blocks also need to store the encryption | |
243 | * parameters so that the block can be decrypted. This layout is as follows: | |
244 | * | |
245 | * 64 56 48 40 32 24 16 8 0 | |
246 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
247 | * 0 | vdev1 | GRID | ASIZE | | |
248 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
249 | * 1 |G| offset1 | | |
250 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
251 | * 2 | vdev2 | GRID | ASIZE | | |
252 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
253 | * 3 |G| offset2 | | |
254 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
255 | * 4 | salt | | |
256 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
257 | * 5 | IV1 | | |
258 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
259 | * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE | | |
260 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
261 | * 7 | padding | | |
262 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
263 | * 8 | padding | | |
264 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
265 | * 9 | physical birth txg | | |
266 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
267 | * a | logical birth txg | | |
268 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
269 | * b | IV2 | fill count | | |
270 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
271 | * c | checksum[0] | | |
272 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
273 | * d | checksum[1] | | |
274 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
275 | * e | MAC[0] | | |
276 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
277 | * f | MAC[1] | | |
278 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
279 | * | |
280 | * Legend: | |
281 | * | |
282 | * salt Salt for generating encryption keys | |
283 | * IV1 First 64 bits of encryption IV | |
284 | * X Block requires encryption handling (set to 1) | |
285 | * E blkptr_t contains embedded data (set to 0, see below) | |
286 | * fill count number of non-zero blocks under this bp (truncated to 32 bits) | |
287 | * IV2 Last 32 bits of encryption IV | |
288 | * checksum[2] 128-bit checksum of the data this bp describes | |
289 | * MAC[2] 128-bit message authentication code for this data | |
290 | * | |
291 | * The X bit being set indicates that this block is one of 3 types. If this is | |
292 | * a level 0 block with an encrypted object type, the block is encrypted | |
293 | * (see BP_IS_ENCRYPTED()). If this is a level 0 block with an unencrypted | |
294 | * object type, this block is authenticated with an HMAC (see | |
295 | * BP_IS_AUTHENTICATED()). Otherwise (if level > 0), this bp will use the MAC | |
296 | * words to store a checksum-of-MACs from the level below (see | |
297 | * BP_HAS_INDIRECT_MAC_CKSUM()). For convenience in the code, BP_IS_PROTECTED() | |
298 | * refers to both encrypted and authenticated blocks and BP_USES_CRYPT() | |
299 | * refers to any of these 3 kinds of blocks. | |
300 | * | |
301 | * The additional encryption parameters are the salt, IV, and MAC which are | |
302 | * explained in greater detail in the block comment at the top of zio_crypt.c. | |
303 | * The MAC occupies half of the checksum space since it serves a very similar | |
304 | * purpose: to prevent data corruption on disk. The only functional difference | |
305 | * is that the checksum is used to detect on-disk corruption whether or not the | |
306 | * encryption key is loaded and the MAC provides additional protection against | |
307 | * malicious disk tampering. We use the 3rd DVA to store the salt and first | |
308 | * 64 bits of the IV. As a result encrypted blocks can only have 2 copies | |
309 | * maximum instead of the normal 3. The last 32 bits of the IV are stored in | |
310 | * the upper bits of what is usually the fill count. Note that only blocks at | |
311 | * level 0 or -2 are ever encrypted, which allows us to guarantee that these | |
312 | * 32 bits are not trampled over by other code (see zio_crypt.c for details). | |
313 | * The salt and IV are not used for authenticated bps or bps with an indirect | |
314 | * MAC checksum, so these blocks can utilize all 3 DVAs and the full 64 bits | |
315 | * for the fill count. | |
316 | */ | |
317 | ||
9b67f605 MA |
318 | /* |
319 | * "Embedded" blkptr_t's don't actually point to a block, instead they | |
320 | * have a data payload embedded in the blkptr_t itself. See the comment | |
321 | * in blkptr.c for more details. | |
322 | * | |
323 | * The blkptr_t is laid out as follows: | |
324 | * | |
325 | * 64 56 48 40 32 24 16 8 0 | |
326 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
327 | * 0 | payload | | |
328 | * 1 | payload | | |
329 | * 2 | payload | | |
330 | * 3 | payload | | |
331 | * 4 | payload | | |
332 | * 5 | payload | | |
333 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
334 | * 6 |BDX|lvl| type | etype |E| comp| PSIZE| LSIZE | | |
335 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
336 | * 7 | payload | | |
337 | * 8 | payload | | |
338 | * 9 | payload | | |
339 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
340 | * a | logical birth txg | | |
341 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
342 | * b | payload | | |
343 | * c | payload | | |
344 | * d | payload | | |
345 | * e | payload | | |
346 | * f | payload | | |
347 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | |
348 | * | |
349 | * Legend: | |
350 | * | |
351 | * payload contains the embedded data | |
352 | * B (byteorder) byteorder (endianness) | |
353 | * D (dedup) padding (set to zero) | |
b5256303 | 354 | * X encryption (set to zero) |
9b67f605 MA |
355 | * E (embedded) set to one |
356 | * lvl indirection level | |
357 | * type DMU object type | |
358 | * etype how to interpret embedded data (BP_EMBEDDED_TYPE_*) | |
359 | * comp compression function of payload | |
360 | * PSIZE size of payload after compression, in bytes | |
361 | * LSIZE logical size of payload, in bytes | |
362 | * note that 25 bits is enough to store the largest | |
363 | * "normal" BP's LSIZE (2^16 * 2^9) in bytes | |
364 | * log. birth transaction group in which the block was logically born | |
365 | * | |
366 | * Note that LSIZE and PSIZE are stored in bytes, whereas for non-embedded | |
367 | * bp's they are stored in units of SPA_MINBLOCKSHIFT. | |
368 | * Generally, the generic BP_GET_*() macros can be used on embedded BP's. | |
369 | * The B, D, X, lvl, type, and comp fields are stored the same as with normal | |
370 | * BP's so the BP_SET_* macros can be used with them. etype, PSIZE, LSIZE must | |
371 | * be set with the BPE_SET_* macros. BP_SET_EMBEDDED() should be called before | |
372 | * other macros, as they assert that they are only used on BP's of the correct | |
b5256303 TC |
373 | * "embedded-ness". Encrypted blkptr_t's cannot be embedded because they use |
374 | * the payload space for encryption parameters (see the comment above on | |
375 | * how encryption parameters are stored). | |
9b67f605 MA |
376 | */ |
377 | ||
378 | #define BPE_GET_ETYPE(bp) \ | |
379 | (ASSERT(BP_IS_EMBEDDED(bp)), \ | |
380 | BF64_GET((bp)->blk_prop, 40, 8)) | |
381 | #define BPE_SET_ETYPE(bp, t) do { \ | |
382 | ASSERT(BP_IS_EMBEDDED(bp)); \ | |
383 | BF64_SET((bp)->blk_prop, 40, 8, t); \ | |
384 | _NOTE(CONSTCOND) } while (0) | |
385 | ||
386 | #define BPE_GET_LSIZE(bp) \ | |
387 | (ASSERT(BP_IS_EMBEDDED(bp)), \ | |
388 | BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1)) | |
389 | #define BPE_SET_LSIZE(bp, x) do { \ | |
390 | ASSERT(BP_IS_EMBEDDED(bp)); \ | |
391 | BF64_SET_SB((bp)->blk_prop, 0, 25, 0, 1, x); \ | |
392 | _NOTE(CONSTCOND) } while (0) | |
393 | ||
394 | #define BPE_GET_PSIZE(bp) \ | |
395 | (ASSERT(BP_IS_EMBEDDED(bp)), \ | |
396 | BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1)) | |
397 | #define BPE_SET_PSIZE(bp, x) do { \ | |
398 | ASSERT(BP_IS_EMBEDDED(bp)); \ | |
399 | BF64_SET_SB((bp)->blk_prop, 25, 7, 0, 1, x); \ | |
400 | _NOTE(CONSTCOND) } while (0) | |
401 | ||
402 | typedef enum bp_embedded_type { | |
403 | BP_EMBEDDED_TYPE_DATA, | |
404 | BP_EMBEDDED_TYPE_RESERVED, /* Reserved for an unintegrated feature. */ | |
405 | NUM_BP_EMBEDDED_TYPES = BP_EMBEDDED_TYPE_RESERVED | |
406 | } bp_embedded_type_t; | |
407 | ||
408 | #define BPE_NUM_WORDS 14 | |
409 | #define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t)) | |
410 | #define BPE_IS_PAYLOADWORD(bp, wp) \ | |
411 | ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth) | |
412 | ||
34dc7c2f BB |
413 | #define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */ |
414 | #define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */ | |
6cb8e530 | 415 | #define SPA_SYNC_MIN_VDEVS 3 /* min vdevs to update during sync */ |
34dc7c2f | 416 | |
b0bc7a84 MG |
417 | /* |
418 | * A block is a hole when it has either 1) never been written to, or | |
419 | * 2) is zero-filled. In both cases, ZFS can return all zeroes for all reads | |
420 | * without physically allocating disk space. Holes are represented in the | |
421 | * blkptr_t structure by zeroed blk_dva. Correct checking for holes is | |
422 | * done through the BP_IS_HOLE macro. For holes, the logical size, level, | |
423 | * DMU object type, and birth times are all also stored for holes that | |
424 | * were written to at some point (i.e. were punched after having been filled). | |
425 | */ | |
428870ff BB |
426 | typedef struct blkptr { |
427 | dva_t blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */ | |
428 | uint64_t blk_prop; /* size, compression, type, etc */ | |
429 | uint64_t blk_pad[2]; /* Extra space for the future */ | |
430 | uint64_t blk_phys_birth; /* txg when block was allocated */ | |
431 | uint64_t blk_birth; /* transaction group at birth */ | |
432 | uint64_t blk_fill; /* fill count */ | |
433 | zio_cksum_t blk_cksum; /* 256-bit checksum */ | |
434 | } blkptr_t; | |
435 | ||
34dc7c2f BB |
436 | /* |
437 | * Macros to get and set fields in a bp or DVA. | |
438 | */ | |
439 | #define DVA_GET_ASIZE(dva) \ | |
b0bc7a84 | 440 | BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0) |
34dc7c2f | 441 | #define DVA_SET_ASIZE(dva, x) \ |
b0bc7a84 MG |
442 | BF64_SET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, \ |
443 | SPA_MINBLOCKSHIFT, 0, x) | |
34dc7c2f BB |
444 | |
445 | #define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8) | |
446 | #define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x) | |
447 | ||
4d044c4c SD |
448 | #define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, SPA_VDEVBITS) |
449 | #define DVA_SET_VDEV(dva, x) \ | |
450 | BF64_SET((dva)->dva_word[0], 32, SPA_VDEVBITS, x) | |
34dc7c2f BB |
451 | |
452 | #define DVA_GET_OFFSET(dva) \ | |
453 | BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0) | |
454 | #define DVA_SET_OFFSET(dva, x) \ | |
455 | BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x) | |
456 | ||
457 | #define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1) | |
458 | #define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x) | |
459 | ||
460 | #define BP_GET_LSIZE(bp) \ | |
9b67f605 MA |
461 | (BP_IS_EMBEDDED(bp) ? \ |
462 | (BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA ? BPE_GET_LSIZE(bp) : 0): \ | |
463 | BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1)) | |
464 | #define BP_SET_LSIZE(bp, x) do { \ | |
465 | ASSERT(!BP_IS_EMBEDDED(bp)); \ | |
466 | BF64_SET_SB((bp)->blk_prop, \ | |
467 | 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \ | |
468 | _NOTE(CONSTCOND) } while (0) | |
34dc7c2f BB |
469 | |
470 | #define BP_GET_PSIZE(bp) \ | |
9b67f605 MA |
471 | (BP_IS_EMBEDDED(bp) ? 0 : \ |
472 | BF64_GET_SB((bp)->blk_prop, 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1)) | |
473 | #define BP_SET_PSIZE(bp, x) do { \ | |
474 | ASSERT(!BP_IS_EMBEDDED(bp)); \ | |
475 | BF64_SET_SB((bp)->blk_prop, \ | |
476 | 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \ | |
477 | _NOTE(CONSTCOND) } while (0) | |
478 | ||
d3c2ae1c GW |
479 | #define BP_GET_COMPRESS(bp) \ |
480 | BF64_GET((bp)->blk_prop, 32, SPA_COMPRESSBITS) | |
481 | #define BP_SET_COMPRESS(bp, x) \ | |
482 | BF64_SET((bp)->blk_prop, 32, SPA_COMPRESSBITS, x) | |
34dc7c2f | 483 | |
9b67f605 MA |
484 | #define BP_IS_EMBEDDED(bp) BF64_GET((bp)->blk_prop, 39, 1) |
485 | #define BP_SET_EMBEDDED(bp, x) BF64_SET((bp)->blk_prop, 39, 1, x) | |
428870ff | 486 | |
9b67f605 MA |
487 | #define BP_GET_CHECKSUM(bp) \ |
488 | (BP_IS_EMBEDDED(bp) ? ZIO_CHECKSUM_OFF : \ | |
489 | BF64_GET((bp)->blk_prop, 40, 8)) | |
490 | #define BP_SET_CHECKSUM(bp, x) do { \ | |
491 | ASSERT(!BP_IS_EMBEDDED(bp)); \ | |
492 | BF64_SET((bp)->blk_prop, 40, 8, x); \ | |
493 | _NOTE(CONSTCOND) } while (0) | |
34dc7c2f | 494 | |
428870ff BB |
495 | #define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8) |
496 | #define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x) | |
34dc7c2f | 497 | |
428870ff BB |
498 | #define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5) |
499 | #define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x) | |
34dc7c2f | 500 | |
b5256303 TC |
501 | /* encrypted, authenticated, and MAC cksum bps use the same bit */ |
502 | #define BP_USES_CRYPT(bp) BF64_GET((bp)->blk_prop, 61, 1) | |
503 | #define BP_SET_CRYPT(bp, x) BF64_SET((bp)->blk_prop, 61, 1, x) | |
504 | ||
505 | #define BP_IS_ENCRYPTED(bp) \ | |
506 | (BP_USES_CRYPT(bp) && \ | |
507 | BP_GET_LEVEL(bp) <= 0 && \ | |
508 | DMU_OT_IS_ENCRYPTED(BP_GET_TYPE(bp))) | |
509 | ||
510 | #define BP_IS_AUTHENTICATED(bp) \ | |
511 | (BP_USES_CRYPT(bp) && \ | |
512 | BP_GET_LEVEL(bp) <= 0 && \ | |
513 | !DMU_OT_IS_ENCRYPTED(BP_GET_TYPE(bp))) | |
514 | ||
515 | #define BP_HAS_INDIRECT_MAC_CKSUM(bp) \ | |
516 | (BP_USES_CRYPT(bp) && BP_GET_LEVEL(bp) > 0) | |
517 | ||
518 | #define BP_IS_PROTECTED(bp) \ | |
519 | (BP_IS_ENCRYPTED(bp) || BP_IS_AUTHENTICATED(bp)) | |
520 | ||
428870ff BB |
521 | #define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1) |
522 | #define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x) | |
523 | ||
b0bc7a84 | 524 | #define BP_GET_BYTEORDER(bp) BF64_GET((bp)->blk_prop, 63, 1) |
428870ff BB |
525 | #define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x) |
526 | ||
527 | #define BP_PHYSICAL_BIRTH(bp) \ | |
9b67f605 MA |
528 | (BP_IS_EMBEDDED(bp) ? 0 : \ |
529 | (bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth) | |
428870ff BB |
530 | |
531 | #define BP_SET_BIRTH(bp, logical, physical) \ | |
532 | { \ | |
9b67f605 | 533 | ASSERT(!BP_IS_EMBEDDED(bp)); \ |
428870ff BB |
534 | (bp)->blk_birth = (logical); \ |
535 | (bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \ | |
536 | } | |
34dc7c2f | 537 | |
b5256303 TC |
538 | #define BP_GET_FILL(bp) \ |
539 | ((BP_IS_ENCRYPTED(bp)) ? BF64_GET((bp)->blk_fill, 0, 32) : \ | |
540 | ((BP_IS_EMBEDDED(bp)) ? 1 : (bp)->blk_fill)) | |
541 | ||
542 | #define BP_SET_FILL(bp, fill) \ | |
543 | { \ | |
544 | if (BP_IS_ENCRYPTED(bp)) \ | |
545 | BF64_SET((bp)->blk_fill, 0, 32, fill); \ | |
546 | else \ | |
547 | (bp)->blk_fill = fill; \ | |
548 | } | |
549 | ||
550 | #define BP_GET_IV2(bp) \ | |
551 | (ASSERT(BP_IS_ENCRYPTED(bp)), \ | |
552 | BF64_GET((bp)->blk_fill, 32, 32)) | |
553 | #define BP_SET_IV2(bp, iv2) \ | |
554 | { \ | |
555 | ASSERT(BP_IS_ENCRYPTED(bp)); \ | |
556 | BF64_SET((bp)->blk_fill, 32, 32, iv2); \ | |
557 | } | |
9b67f605 | 558 | |
a6255b7f DQ |
559 | #define BP_IS_METADATA(bp) \ |
560 | (BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp))) | |
561 | ||
34dc7c2f | 562 | #define BP_GET_ASIZE(bp) \ |
9b67f605 MA |
563 | (BP_IS_EMBEDDED(bp) ? 0 : \ |
564 | DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \ | |
565 | DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ | |
b5256303 | 566 | (DVA_GET_ASIZE(&(bp)->blk_dva[2]) * !BP_IS_ENCRYPTED(bp))) |
34dc7c2f | 567 | |
a6255b7f DQ |
568 | #define BP_GET_UCSIZE(bp) \ |
569 | (BP_IS_METADATA(bp) ? BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp)) | |
34dc7c2f BB |
570 | |
571 | #define BP_GET_NDVAS(bp) \ | |
9b67f605 MA |
572 | (BP_IS_EMBEDDED(bp) ? 0 : \ |
573 | !!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \ | |
34dc7c2f | 574 | !!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ |
b5256303 | 575 | (!!DVA_GET_ASIZE(&(bp)->blk_dva[2]) * !BP_IS_ENCRYPTED(bp))) |
34dc7c2f BB |
576 | |
577 | #define BP_COUNT_GANG(bp) \ | |
9b67f605 | 578 | (BP_IS_EMBEDDED(bp) ? 0 : \ |
34dc7c2f BB |
579 | (DVA_GET_GANG(&(bp)->blk_dva[0]) + \ |
580 | DVA_GET_GANG(&(bp)->blk_dva[1]) + \ | |
b5256303 | 581 | (DVA_GET_GANG(&(bp)->blk_dva[2]) * !BP_IS_ENCRYPTED(bp)))) |
34dc7c2f BB |
582 | |
583 | #define DVA_EQUAL(dva1, dva2) \ | |
584 | ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \ | |
585 | (dva1)->dva_word[0] == (dva2)->dva_word[0]) | |
586 | ||
428870ff BB |
587 | #define BP_EQUAL(bp1, bp2) \ |
588 | (BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) && \ | |
9b67f605 | 589 | (bp1)->blk_birth == (bp2)->blk_birth && \ |
428870ff BB |
590 | DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) && \ |
591 | DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) && \ | |
592 | DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2])) | |
593 | ||
37f8a883 | 594 | |
34dc7c2f BB |
595 | #define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0) |
596 | ||
9b67f605 MA |
597 | #define BP_IDENTITY(bp) (ASSERT(!BP_IS_EMBEDDED(bp)), &(bp)->blk_dva[0]) |
598 | #define BP_IS_GANG(bp) \ | |
599 | (BP_IS_EMBEDDED(bp) ? B_FALSE : DVA_GET_GANG(BP_IDENTITY(bp))) | |
b0bc7a84 MG |
600 | #define DVA_IS_EMPTY(dva) ((dva)->dva_word[0] == 0ULL && \ |
601 | (dva)->dva_word[1] == 0ULL) | |
9b67f605 MA |
602 | #define BP_IS_HOLE(bp) \ |
603 | (!BP_IS_EMBEDDED(bp) && DVA_IS_EMPTY(BP_IDENTITY(bp))) | |
428870ff BB |
604 | |
605 | /* BP_IS_RAIDZ(bp) assumes no block compression */ | |
606 | #define BP_IS_RAIDZ(bp) (DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \ | |
607 | BP_GET_PSIZE(bp)) | |
34dc7c2f | 608 | |
b128c09f | 609 | #define BP_ZERO(bp) \ |
34dc7c2f BB |
610 | { \ |
611 | (bp)->blk_dva[0].dva_word[0] = 0; \ | |
612 | (bp)->blk_dva[0].dva_word[1] = 0; \ | |
613 | (bp)->blk_dva[1].dva_word[0] = 0; \ | |
614 | (bp)->blk_dva[1].dva_word[1] = 0; \ | |
615 | (bp)->blk_dva[2].dva_word[0] = 0; \ | |
616 | (bp)->blk_dva[2].dva_word[1] = 0; \ | |
34dc7c2f BB |
617 | (bp)->blk_prop = 0; \ |
618 | (bp)->blk_pad[0] = 0; \ | |
619 | (bp)->blk_pad[1] = 0; \ | |
428870ff | 620 | (bp)->blk_phys_birth = 0; \ |
b128c09f | 621 | (bp)->blk_birth = 0; \ |
34dc7c2f BB |
622 | (bp)->blk_fill = 0; \ |
623 | ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \ | |
624 | } | |
625 | ||
34dc7c2f BB |
626 | #ifdef _BIG_ENDIAN |
627 | #define ZFS_HOST_BYTEORDER (0ULL) | |
628 | #else | |
b0bc7a84 | 629 | #define ZFS_HOST_BYTEORDER (1ULL) |
34dc7c2f BB |
630 | #endif |
631 | ||
632 | #define BP_SHOULD_BYTESWAP(bp) (BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER) | |
633 | ||
b5256303 | 634 | #define BP_SPRINTF_LEN 400 |
34dc7c2f | 635 | |
428870ff BB |
636 | /* |
637 | * This macro allows code sharing between zfs, libzpool, and mdb. | |
638 | * 'func' is either snprintf() or mdb_snprintf(). | |
639 | * 'ws' (whitespace) can be ' ' for single-line format, '\n' for multi-line. | |
640 | */ | |
5c27ec10 | 641 | #define SNPRINTF_BLKPTR(func, ws, buf, size, bp, type, checksum, compress) \ |
428870ff BB |
642 | { \ |
643 | static const char *copyname[] = \ | |
644 | { "zero", "single", "double", "triple" }; \ | |
428870ff BB |
645 | int len = 0; \ |
646 | int copies = 0; \ | |
5c27ec10 MA |
647 | const char *crypt_type; \ |
648 | if (bp != NULL) { \ | |
649 | if (BP_IS_ENCRYPTED(bp)) { \ | |
650 | crypt_type = "encrypted"; \ | |
651 | /* LINTED E_SUSPICIOUS_COMPARISON */ \ | |
652 | } else if (BP_IS_AUTHENTICATED(bp)) { \ | |
653 | crypt_type = "authenticated"; \ | |
654 | } else if (BP_HAS_INDIRECT_MAC_CKSUM(bp)) { \ | |
655 | crypt_type = "indirect-MAC"; \ | |
656 | } else { \ | |
657 | crypt_type = "unencrypted"; \ | |
658 | } \ | |
659 | } \ | |
428870ff | 660 | if (bp == NULL) { \ |
b0bc7a84 | 661 | len += func(buf + len, size - len, "<NULL>"); \ |
428870ff | 662 | } else if (BP_IS_HOLE(bp)) { \ |
a4069eef PS |
663 | len += func(buf + len, size - len, \ |
664 | "HOLE [L%llu %s] " \ | |
665 | "size=%llxL birth=%lluL", \ | |
666 | (u_longlong_t)BP_GET_LEVEL(bp), \ | |
667 | type, \ | |
668 | (u_longlong_t)BP_GET_LSIZE(bp), \ | |
669 | (u_longlong_t)bp->blk_birth); \ | |
9b67f605 MA |
670 | } else if (BP_IS_EMBEDDED(bp)) { \ |
671 | len = func(buf + len, size - len, \ | |
672 | "EMBEDDED [L%llu %s] et=%u %s " \ | |
673 | "size=%llxL/%llxP birth=%lluL", \ | |
674 | (u_longlong_t)BP_GET_LEVEL(bp), \ | |
675 | type, \ | |
676 | (int)BPE_GET_ETYPE(bp), \ | |
677 | compress, \ | |
678 | (u_longlong_t)BPE_GET_LSIZE(bp), \ | |
679 | (u_longlong_t)BPE_GET_PSIZE(bp), \ | |
680 | (u_longlong_t)bp->blk_birth); \ | |
428870ff | 681 | } else { \ |
1c27024e | 682 | for (int d = 0; d < BP_GET_NDVAS(bp); d++) { \ |
428870ff BB |
683 | const dva_t *dva = &bp->blk_dva[d]; \ |
684 | if (DVA_IS_VALID(dva)) \ | |
685 | copies++; \ | |
686 | len += func(buf + len, size - len, \ | |
687 | "DVA[%d]=<%llu:%llx:%llx>%c", d, \ | |
688 | (u_longlong_t)DVA_GET_VDEV(dva), \ | |
689 | (u_longlong_t)DVA_GET_OFFSET(dva), \ | |
690 | (u_longlong_t)DVA_GET_ASIZE(dva), \ | |
691 | ws); \ | |
692 | } \ | |
b5256303 TC |
693 | if (BP_IS_ENCRYPTED(bp)) { \ |
694 | len += func(buf + len, size - len, \ | |
695 | "salt=%llx iv=%llx:%llx%c", \ | |
696 | (u_longlong_t)bp->blk_dva[2].dva_word[0], \ | |
697 | (u_longlong_t)bp->blk_dva[2].dva_word[1], \ | |
698 | (u_longlong_t)BP_GET_IV2(bp), \ | |
699 | ws); \ | |
700 | } \ | |
428870ff BB |
701 | if (BP_IS_GANG(bp) && \ |
702 | DVA_GET_ASIZE(&bp->blk_dva[2]) <= \ | |
703 | DVA_GET_ASIZE(&bp->blk_dva[1]) / 2) \ | |
704 | copies--; \ | |
705 | len += func(buf + len, size - len, \ | |
b5256303 | 706 | "[L%llu %s] %s %s %s %s %s %s %s%c" \ |
428870ff BB |
707 | "size=%llxL/%llxP birth=%lluL/%lluP fill=%llu%c" \ |
708 | "cksum=%llx:%llx:%llx:%llx", \ | |
709 | (u_longlong_t)BP_GET_LEVEL(bp), \ | |
710 | type, \ | |
711 | checksum, \ | |
712 | compress, \ | |
b5256303 | 713 | crypt_type, \ |
428870ff BB |
714 | BP_GET_BYTEORDER(bp) == 0 ? "BE" : "LE", \ |
715 | BP_IS_GANG(bp) ? "gang" : "contiguous", \ | |
716 | BP_GET_DEDUP(bp) ? "dedup" : "unique", \ | |
717 | copyname[copies], \ | |
718 | ws, \ | |
719 | (u_longlong_t)BP_GET_LSIZE(bp), \ | |
720 | (u_longlong_t)BP_GET_PSIZE(bp), \ | |
721 | (u_longlong_t)bp->blk_birth, \ | |
722 | (u_longlong_t)BP_PHYSICAL_BIRTH(bp), \ | |
9b67f605 | 723 | (u_longlong_t)BP_GET_FILL(bp), \ |
428870ff BB |
724 | ws, \ |
725 | (u_longlong_t)bp->blk_cksum.zc_word[0], \ | |
726 | (u_longlong_t)bp->blk_cksum.zc_word[1], \ | |
727 | (u_longlong_t)bp->blk_cksum.zc_word[2], \ | |
728 | (u_longlong_t)bp->blk_cksum.zc_word[3]); \ | |
729 | } \ | |
730 | ASSERT(len < size); \ | |
731 | } | |
732 | ||
34dc7c2f | 733 | #define BP_GET_BUFC_TYPE(bp) \ |
a6255b7f | 734 | (BP_IS_METADATA(bp) ? ARC_BUFC_METADATA : ARC_BUFC_DATA) |
428870ff BB |
735 | |
736 | typedef enum spa_import_type { | |
737 | SPA_IMPORT_EXISTING, | |
738 | SPA_IMPORT_ASSEMBLE | |
739 | } spa_import_type_t; | |
34dc7c2f BB |
740 | |
741 | /* state manipulation functions */ | |
742 | extern int spa_open(const char *pool, spa_t **, void *tag); | |
428870ff BB |
743 | extern int spa_open_rewind(const char *pool, spa_t **, void *tag, |
744 | nvlist_t *policy, nvlist_t **config); | |
9ae529ec CS |
745 | extern int spa_get_stats(const char *pool, nvlist_t **config, char *altroot, |
746 | size_t buflen); | |
b5256303 TC |
747 | extern int spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props, |
748 | nvlist_t *zplprops, struct dsl_crypto_params *dcp); | |
13fe0198 | 749 | extern int spa_import(char *pool, nvlist_t *config, nvlist_t *props, |
572e2857 | 750 | uint64_t flags); |
34dc7c2f BB |
751 | extern nvlist_t *spa_tryimport(nvlist_t *tryconfig); |
752 | extern int spa_destroy(char *pool); | |
d2734cce SD |
753 | extern int spa_checkpoint(const char *pool); |
754 | extern int spa_checkpoint_discard(const char *pool); | |
fb5f0bc8 BB |
755 | extern int spa_export(char *pool, nvlist_t **oldconfig, boolean_t force, |
756 | boolean_t hardforce); | |
34dc7c2f BB |
757 | extern int spa_reset(char *pool); |
758 | extern void spa_async_request(spa_t *spa, int flag); | |
b128c09f | 759 | extern void spa_async_unrequest(spa_t *spa, int flag); |
34dc7c2f BB |
760 | extern void spa_async_suspend(spa_t *spa); |
761 | extern void spa_async_resume(spa_t *spa); | |
762 | extern spa_t *spa_inject_addref(char *pool); | |
763 | extern void spa_inject_delref(spa_t *spa); | |
428870ff BB |
764 | extern void spa_scan_stat_init(spa_t *spa); |
765 | extern int spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps); | |
34dc7c2f | 766 | |
b128c09f BB |
767 | #define SPA_ASYNC_CONFIG_UPDATE 0x01 |
768 | #define SPA_ASYNC_REMOVE 0x02 | |
769 | #define SPA_ASYNC_PROBE 0x04 | |
770 | #define SPA_ASYNC_RESILVER_DONE 0x08 | |
771 | #define SPA_ASYNC_RESILVER 0x10 | |
9babb374 | 772 | #define SPA_ASYNC_AUTOEXPAND 0x20 |
428870ff BB |
773 | #define SPA_ASYNC_REMOVE_DONE 0x40 |
774 | #define SPA_ASYNC_REMOVE_STOP 0x80 | |
775 | ||
776 | /* | |
777 | * Controls the behavior of spa_vdev_remove(). | |
778 | */ | |
779 | #define SPA_REMOVE_UNSPARE 0x01 | |
780 | #define SPA_REMOVE_DONE 0x02 | |
34dc7c2f BB |
781 | |
782 | /* device manipulation */ | |
783 | extern int spa_vdev_add(spa_t *spa, nvlist_t *nvroot); | |
784 | extern int spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot, | |
785 | int replacing); | |
fb5f0bc8 BB |
786 | extern int spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, |
787 | int replace_done); | |
34dc7c2f | 788 | extern int spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare); |
428870ff | 789 | extern boolean_t spa_vdev_remove_active(spa_t *spa); |
34dc7c2f | 790 | extern int spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath); |
9babb374 | 791 | extern int spa_vdev_setfru(spa_t *spa, uint64_t guid, const char *newfru); |
428870ff BB |
792 | extern int spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config, |
793 | nvlist_t *props, boolean_t exp); | |
34dc7c2f BB |
794 | |
795 | /* spare state (which is global across all pools) */ | |
796 | extern void spa_spare_add(vdev_t *vd); | |
797 | extern void spa_spare_remove(vdev_t *vd); | |
b128c09f | 798 | extern boolean_t spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt); |
34dc7c2f BB |
799 | extern void spa_spare_activate(vdev_t *vd); |
800 | ||
801 | /* L2ARC state (which is global across all pools) */ | |
802 | extern void spa_l2cache_add(vdev_t *vd); | |
803 | extern void spa_l2cache_remove(vdev_t *vd); | |
804 | extern boolean_t spa_l2cache_exists(uint64_t guid, uint64_t *pool); | |
805 | extern void spa_l2cache_activate(vdev_t *vd); | |
806 | extern void spa_l2cache_drop(spa_t *spa); | |
34dc7c2f | 807 | |
428870ff BB |
808 | /* scanning */ |
809 | extern int spa_scan(spa_t *spa, pool_scan_func_t func); | |
810 | extern int spa_scan_stop(spa_t *spa); | |
0ea05c64 | 811 | extern int spa_scrub_pause_resume(spa_t *spa, pool_scrub_cmd_t flag); |
34dc7c2f BB |
812 | |
813 | /* spa syncing */ | |
814 | extern void spa_sync(spa_t *spa, uint64_t txg); /* only for DMU use */ | |
815 | extern void spa_sync_allpools(void); | |
816 | ||
55d85d5a | 817 | extern int zfs_sync_pass_deferred_free; |
428870ff | 818 | |
b128c09f BB |
819 | /* spa namespace global mutex */ |
820 | extern kmutex_t spa_namespace_lock; | |
821 | ||
34dc7c2f BB |
822 | /* |
823 | * SPA configuration functions in spa_config.c | |
824 | */ | |
825 | ||
826 | #define SPA_CONFIG_UPDATE_POOL 0 | |
827 | #define SPA_CONFIG_UPDATE_VDEVS 1 | |
828 | ||
a1d477c2 | 829 | extern void spa_write_cachefile(spa_t *, boolean_t, boolean_t); |
34dc7c2f BB |
830 | extern void spa_config_load(void); |
831 | extern nvlist_t *spa_all_configs(uint64_t *); | |
832 | extern void spa_config_set(spa_t *spa, nvlist_t *config); | |
833 | extern nvlist_t *spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, | |
834 | int getstats); | |
835 | extern void spa_config_update(spa_t *spa, int what); | |
34dc7c2f BB |
836 | |
837 | /* | |
838 | * Miscellaneous SPA routines in spa_misc.c | |
839 | */ | |
840 | ||
841 | /* Namespace manipulation */ | |
842 | extern spa_t *spa_lookup(const char *name); | |
428870ff | 843 | extern spa_t *spa_add(const char *name, nvlist_t *config, const char *altroot); |
34dc7c2f BB |
844 | extern void spa_remove(spa_t *spa); |
845 | extern spa_t *spa_next(spa_t *prev); | |
846 | ||
847 | /* Refcount functions */ | |
848 | extern void spa_open_ref(spa_t *spa, void *tag); | |
849 | extern void spa_close(spa_t *spa, void *tag); | |
0c66c32d | 850 | extern void spa_async_close(spa_t *spa, void *tag); |
34dc7c2f BB |
851 | extern boolean_t spa_refcount_zero(spa_t *spa); |
852 | ||
428870ff | 853 | #define SCL_NONE 0x00 |
b128c09f BB |
854 | #define SCL_CONFIG 0x01 |
855 | #define SCL_STATE 0x02 | |
856 | #define SCL_L2ARC 0x04 /* hack until L2ARC 2.0 */ | |
857 | #define SCL_ALLOC 0x08 | |
858 | #define SCL_ZIO 0x10 | |
859 | #define SCL_FREE 0x20 | |
860 | #define SCL_VDEV 0x40 | |
861 | #define SCL_LOCKS 7 | |
862 | #define SCL_ALL ((1 << SCL_LOCKS) - 1) | |
863 | #define SCL_STATE_ALL (SCL_STATE | SCL_L2ARC | SCL_ZIO) | |
864 | ||
1421c891 | 865 | /* Historical pool statistics */ |
d1261452 | 866 | typedef struct spa_history_kstat { |
1421c891 PS |
867 | kmutex_t lock; |
868 | uint64_t count; | |
869 | uint64_t size; | |
870 | kstat_t *kstat; | |
871 | void *private; | |
872 | list_t list; | |
d1261452 JG |
873 | } spa_history_kstat_t; |
874 | ||
875 | typedef struct spa_history_list { | |
876 | uint64_t size; | |
877 | procfs_list_t procfs_list; | |
878 | } spa_history_list_t; | |
1421c891 PS |
879 | |
880 | typedef struct spa_stats { | |
d1261452 JG |
881 | spa_history_list_t read_history; |
882 | spa_history_list_t txg_history; | |
883 | spa_history_kstat_t tx_assign_histogram; | |
884 | spa_history_kstat_t io_history; | |
885 | spa_history_list_t mmp_history; | |
886 | spa_history_kstat_t state; /* pool state */ | |
1421c891 PS |
887 | } spa_stats_t; |
888 | ||
0b1401ee BB |
889 | typedef enum txg_state { |
890 | TXG_STATE_BIRTH = 0, | |
891 | TXG_STATE_OPEN = 1, | |
892 | TXG_STATE_QUIESCED = 2, | |
478d64fd IL |
893 | TXG_STATE_WAIT_FOR_SYNC = 3, |
894 | TXG_STATE_SYNCED = 4, | |
895 | TXG_STATE_COMMITTED = 5, | |
0b1401ee BB |
896 | } txg_state_t; |
897 | ||
baf67d15 BB |
898 | typedef struct txg_stat { |
899 | vdev_stat_t vs1; | |
900 | vdev_stat_t vs2; | |
901 | uint64_t txg; | |
902 | uint64_t ndirty; | |
903 | } txg_stat_t; | |
904 | ||
1421c891 PS |
905 | extern void spa_stats_init(spa_t *spa); |
906 | extern void spa_stats_destroy(spa_t *spa); | |
5dbd68a3 | 907 | extern void spa_read_history_add(spa_t *spa, const zbookmark_phys_t *zb, |
1421c891 | 908 | uint32_t aflags); |
01b738f4 | 909 | extern void spa_txg_history_add(spa_t *spa, uint64_t txg, hrtime_t birth_time); |
0b1401ee BB |
910 | extern int spa_txg_history_set(spa_t *spa, uint64_t txg, |
911 | txg_state_t completed_state, hrtime_t completed_time); | |
baf67d15 BB |
912 | extern txg_stat_t *spa_txg_history_init_io(spa_t *, uint64_t, |
913 | struct dsl_pool *); | |
914 | extern void spa_txg_history_fini_io(spa_t *, txg_stat_t *); | |
2d37239a | 915 | extern void spa_tx_assign_add_nsecs(spa_t *spa, uint64_t nsecs); |
d2160d05 | 916 | extern int spa_mmp_history_set_skip(spa_t *spa, uint64_t mmp_kstat_id); |
7088545d OF |
917 | extern int spa_mmp_history_set(spa_t *spa, uint64_t mmp_kstat_id, int io_error, |
918 | hrtime_t duration); | |
d1261452 | 919 | extern void spa_mmp_history_add(spa_t *spa, uint64_t txg, uint64_t timestamp, |
d2160d05 OF |
920 | uint64_t mmp_delay, vdev_t *vd, int label, uint64_t mmp_kstat_id, |
921 | int error); | |
1421c891 | 922 | |
b128c09f BB |
923 | /* Pool configuration locks */ |
924 | extern int spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw); | |
925 | extern void spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw); | |
926 | extern void spa_config_exit(spa_t *spa, int locks, void *tag); | |
927 | extern int spa_config_held(spa_t *spa, int locks, krw_t rw); | |
34dc7c2f BB |
928 | |
929 | /* Pool vdev add/remove lock */ | |
930 | extern uint64_t spa_vdev_enter(spa_t *spa); | |
428870ff BB |
931 | extern uint64_t spa_vdev_config_enter(spa_t *spa); |
932 | extern void spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg, | |
933 | int error, char *tag); | |
34dc7c2f BB |
934 | extern int spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error); |
935 | ||
b128c09f | 936 | /* Pool vdev state change lock */ |
428870ff | 937 | extern void spa_vdev_state_enter(spa_t *spa, int oplock); |
b128c09f BB |
938 | extern int spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error); |
939 | ||
428870ff BB |
940 | /* Log state */ |
941 | typedef enum spa_log_state { | |
942 | SPA_LOG_UNKNOWN = 0, /* unknown log state */ | |
943 | SPA_LOG_MISSING, /* missing log(s) */ | |
944 | SPA_LOG_CLEAR, /* clear the log(s) */ | |
945 | SPA_LOG_GOOD, /* log(s) are good */ | |
946 | } spa_log_state_t; | |
947 | ||
948 | extern spa_log_state_t spa_get_log_state(spa_t *spa); | |
949 | extern void spa_set_log_state(spa_t *spa, spa_log_state_t state); | |
a1d477c2 | 950 | extern int spa_reset_logs(spa_t *spa); |
428870ff BB |
951 | |
952 | /* Log claim callback */ | |
953 | extern void spa_claim_notify(zio_t *zio); | |
cc92e9d0 | 954 | extern void spa_deadman(void *); |
428870ff | 955 | |
34dc7c2f | 956 | /* Accessor functions */ |
b128c09f | 957 | extern boolean_t spa_shutting_down(spa_t *spa); |
34dc7c2f | 958 | extern struct dsl_pool *spa_get_dsl(spa_t *spa); |
9ae529ec | 959 | extern boolean_t spa_is_initializing(spa_t *spa); |
a1d477c2 | 960 | extern boolean_t spa_indirect_vdevs_loaded(spa_t *spa); |
34dc7c2f BB |
961 | extern blkptr_t *spa_get_rootblkptr(spa_t *spa); |
962 | extern void spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp); | |
963 | extern void spa_altroot(spa_t *, char *, size_t); | |
964 | extern int spa_sync_pass(spa_t *spa); | |
965 | extern char *spa_name(spa_t *spa); | |
966 | extern uint64_t spa_guid(spa_t *spa); | |
3541dc6d | 967 | extern uint64_t spa_load_guid(spa_t *spa); |
34dc7c2f BB |
968 | extern uint64_t spa_last_synced_txg(spa_t *spa); |
969 | extern uint64_t spa_first_txg(spa_t *spa); | |
428870ff | 970 | extern uint64_t spa_syncing_txg(spa_t *spa); |
3b7f360c | 971 | extern uint64_t spa_final_dirty_txg(spa_t *spa); |
34dc7c2f | 972 | extern uint64_t spa_version(spa_t *spa); |
b128c09f | 973 | extern pool_state_t spa_state(spa_t *spa); |
428870ff | 974 | extern spa_load_state_t spa_load_state(spa_t *spa); |
34dc7c2f | 975 | extern uint64_t spa_freeze_txg(spa_t *spa); |
3ec3bc21 | 976 | extern uint64_t spa_get_worst_case_asize(spa_t *spa, uint64_t lsize); |
428870ff | 977 | extern uint64_t spa_get_dspace(spa_t *spa); |
d2734cce | 978 | extern uint64_t spa_get_checkpoint_space(spa_t *spa); |
0c60cc32 | 979 | extern uint64_t spa_get_slop_space(spa_t *spa); |
428870ff | 980 | extern void spa_update_dspace(spa_t *spa); |
34dc7c2f | 981 | extern uint64_t spa_version(spa_t *spa); |
428870ff BB |
982 | extern boolean_t spa_deflate(spa_t *spa); |
983 | extern metaslab_class_t *spa_normal_class(spa_t *spa); | |
984 | extern metaslab_class_t *spa_log_class(spa_t *spa); | |
cc99f275 DB |
985 | extern metaslab_class_t *spa_special_class(spa_t *spa); |
986 | extern metaslab_class_t *spa_dedup_class(spa_t *spa); | |
987 | extern metaslab_class_t *spa_preferred_class(spa_t *spa, uint64_t size, | |
988 | dmu_object_type_t objtype, uint_t level, uint_t special_smallblk); | |
989 | ||
0c66c32d JG |
990 | extern void spa_evicting_os_register(spa_t *, objset_t *os); |
991 | extern void spa_evicting_os_deregister(spa_t *, objset_t *os); | |
992 | extern void spa_evicting_os_wait(spa_t *spa); | |
34dc7c2f | 993 | extern int spa_max_replication(spa_t *spa); |
428870ff | 994 | extern int spa_prev_software_version(spa_t *spa); |
8fb1ede1 BB |
995 | extern uint64_t spa_get_failmode(spa_t *spa); |
996 | extern uint64_t spa_get_deadman_failmode(spa_t *spa); | |
997 | extern void spa_set_deadman_failmode(spa_t *spa, const char *failmode); | |
b128c09f | 998 | extern boolean_t spa_suspended(spa_t *spa); |
428870ff BB |
999 | extern uint64_t spa_bootfs(spa_t *spa); |
1000 | extern uint64_t spa_delegation(spa_t *spa); | |
1001 | extern objset_t *spa_meta_objset(spa_t *spa); | |
cc92e9d0 | 1002 | extern uint64_t spa_deadman_synctime(spa_t *spa); |
8fb1ede1 | 1003 | extern uint64_t spa_deadman_ziotime(spa_t *spa); |
dae3e9ea | 1004 | extern uint64_t spa_dirty_data(spa_t *spa); |
34dc7c2f BB |
1005 | |
1006 | /* Miscellaneous support routines */ | |
4a0ee12a PZ |
1007 | extern void spa_load_failed(spa_t *spa, const char *fmt, ...); |
1008 | extern void spa_load_note(spa_t *spa, const char *fmt, ...); | |
b0bc7a84 MG |
1009 | extern void spa_activate_mos_feature(spa_t *spa, const char *feature, |
1010 | dmu_tx_t *tx); | |
9ae529ec | 1011 | extern void spa_deactivate_mos_feature(spa_t *spa, const char *feature); |
34dc7c2f | 1012 | extern int spa_rename(const char *oldname, const char *newname); |
572e2857 | 1013 | extern spa_t *spa_by_guid(uint64_t pool_guid, uint64_t device_guid); |
34dc7c2f BB |
1014 | extern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid); |
1015 | extern char *spa_strdup(const char *); | |
1016 | extern void spa_strfree(char *); | |
1017 | extern uint64_t spa_get_random(uint64_t range); | |
428870ff | 1018 | extern uint64_t spa_generate_guid(spa_t *spa); |
b0bc7a84 | 1019 | extern void snprintf_blkptr(char *buf, size_t buflen, const blkptr_t *bp); |
34dc7c2f | 1020 | extern void spa_freeze(spa_t *spa); |
3541dc6d | 1021 | extern int spa_change_guid(spa_t *spa); |
34dc7c2f BB |
1022 | extern void spa_upgrade(spa_t *spa, uint64_t version); |
1023 | extern void spa_evict_all(void); | |
b128c09f BB |
1024 | extern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid, |
1025 | boolean_t l2cache); | |
34dc7c2f | 1026 | extern boolean_t spa_has_spare(spa_t *, uint64_t guid); |
428870ff BB |
1027 | extern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva); |
1028 | extern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp); | |
1029 | extern uint64_t bp_get_dsize(spa_t *spa, const blkptr_t *bp); | |
34dc7c2f | 1030 | extern boolean_t spa_has_slogs(spa_t *spa); |
b128c09f | 1031 | extern boolean_t spa_is_root(spa_t *spa); |
fb5f0bc8 | 1032 | extern boolean_t spa_writeable(spa_t *spa); |
acbad6ff | 1033 | extern boolean_t spa_has_pending_synctask(spa_t *spa); |
f1512ee6 | 1034 | extern int spa_maxblocksize(spa_t *spa); |
50c957f7 | 1035 | extern int spa_maxdnodesize(spa_t *spa); |
d2734cce SD |
1036 | extern boolean_t spa_has_checkpoint(spa_t *spa); |
1037 | extern boolean_t spa_importing_readonly_checkpoint(spa_t *spa); | |
1038 | extern boolean_t spa_suspend_async_destroy(spa_t *spa); | |
1039 | extern uint64_t spa_min_claim_txg(spa_t *spa); | |
63e3a861 | 1040 | extern void zfs_blkptr_verify(spa_t *spa, const blkptr_t *bp); |
6cb8e530 PZ |
1041 | extern boolean_t zfs_dva_valid(spa_t *spa, const dva_t *dva, |
1042 | const blkptr_t *bp); | |
a1d477c2 MA |
1043 | typedef void (*spa_remap_cb_t)(uint64_t vdev, uint64_t offset, uint64_t size, |
1044 | void *arg); | |
1045 | extern boolean_t spa_remap_blkptr(spa_t *spa, blkptr_t *bp, | |
1046 | spa_remap_cb_t callback, void *arg); | |
1047 | extern uint64_t spa_get_last_removal_txg(spa_t *spa); | |
6cb8e530 PZ |
1048 | extern boolean_t spa_trust_config(spa_t *spa); |
1049 | extern uint64_t spa_missing_tvds_allowed(spa_t *spa); | |
1050 | extern void spa_set_missing_tvds(spa_t *spa, uint64_t missing); | |
d2734cce | 1051 | extern boolean_t spa_top_vdevs_spacemap_addressable(spa_t *spa); |
379ca9cf OF |
1052 | extern boolean_t spa_multihost(spa_t *spa); |
1053 | extern unsigned long spa_get_hostid(void); | |
cc99f275 | 1054 | extern void spa_activate_allocation_classes(spa_t *, dmu_tx_t *); |
428870ff | 1055 | |
fb5f0bc8 | 1056 | extern int spa_mode(spa_t *spa); |
e19572e4 | 1057 | extern uint64_t zfs_strtonum(const char *str, char **nptr); |
34dc7c2f | 1058 | |
34dc7c2f BB |
1059 | extern char *spa_his_ievent_table[]; |
1060 | ||
1061 | extern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx); | |
1062 | extern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read, | |
1063 | char *his_buf); | |
6f1ffb06 MA |
1064 | extern int spa_history_log(spa_t *spa, const char *his_buf); |
1065 | extern int spa_history_log_nvl(spa_t *spa, nvlist_t *nvl); | |
d5e024cb BB |
1066 | extern void spa_history_log_version(spa_t *spa, const char *operation, |
1067 | dmu_tx_t *tx); | |
6f1ffb06 MA |
1068 | extern void spa_history_log_internal(spa_t *spa, const char *operation, |
1069 | dmu_tx_t *tx, const char *fmt, ...); | |
1070 | extern void spa_history_log_internal_ds(struct dsl_dataset *ds, const char *op, | |
1071 | dmu_tx_t *tx, const char *fmt, ...); | |
1072 | extern void spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation, | |
1073 | dmu_tx_t *tx, const char *fmt, ...); | |
34dc7c2f | 1074 | |
f0ed6c74 TH |
1075 | extern const char *spa_state_to_name(spa_t *spa); |
1076 | ||
34dc7c2f | 1077 | /* error handling */ |
5dbd68a3 | 1078 | struct zbookmark_phys; |
b5256303 | 1079 | extern void spa_log_error(spa_t *spa, const zbookmark_phys_t *zb); |
34dc7c2f | 1080 | extern void zfs_ereport_post(const char *class, spa_t *spa, vdev_t *vd, |
a2c2ed1b TC |
1081 | const zbookmark_phys_t *zb, zio_t *zio, uint64_t stateoroffset, |
1082 | uint64_t length); | |
12fa0466 DE |
1083 | extern nvlist_t *zfs_event_create(spa_t *spa, vdev_t *vd, const char *type, |
1084 | const char *name, nvlist_t *aux); | |
34dc7c2f | 1085 | extern void zfs_post_remove(spa_t *spa, vdev_t *vd); |
d02ca379 | 1086 | extern void zfs_post_state_change(spa_t *spa, vdev_t *vd, uint64_t laststate); |
34dc7c2f BB |
1087 | extern void zfs_post_autoreplace(spa_t *spa, vdev_t *vd); |
1088 | extern uint64_t spa_get_errlog_size(spa_t *spa); | |
1089 | extern int spa_get_errlog(spa_t *spa, void *uaddr, size_t *count); | |
1090 | extern void spa_errlog_rotate(spa_t *spa); | |
1091 | extern void spa_errlog_drain(spa_t *spa); | |
1092 | extern void spa_errlog_sync(spa_t *spa, uint64_t txg); | |
1093 | extern void spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub); | |
1094 | ||
1095 | /* vdev cache */ | |
1096 | extern void vdev_cache_stat_init(void); | |
1097 | extern void vdev_cache_stat_fini(void); | |
1098 | ||
551905dd GN |
1099 | /* vdev mirror */ |
1100 | extern void vdev_mirror_stat_init(void); | |
1101 | extern void vdev_mirror_stat_fini(void); | |
1102 | ||
34dc7c2f BB |
1103 | /* Initialization and termination */ |
1104 | extern void spa_init(int flags); | |
1105 | extern void spa_fini(void); | |
0bc8fd78 | 1106 | extern void spa_boot_init(void); |
34dc7c2f BB |
1107 | |
1108 | /* properties */ | |
1109 | extern int spa_prop_set(spa_t *spa, nvlist_t *nvp); | |
1110 | extern int spa_prop_get(spa_t *spa, nvlist_t **nvp); | |
1111 | extern void spa_prop_clear_bootfs(spa_t *spa, uint64_t obj, dmu_tx_t *tx); | |
d164b209 | 1112 | extern void spa_configfile_set(spa_t *, nvlist_t *, boolean_t); |
34dc7c2f BB |
1113 | |
1114 | /* asynchronous event notification */ | |
12fa0466 DE |
1115 | extern void spa_event_notify(spa_t *spa, vdev_t *vdev, nvlist_t *hist_nvl, |
1116 | const char *name); | |
34dc7c2f BB |
1117 | |
1118 | #ifdef ZFS_DEBUG | |
79c76d5b BB |
1119 | #define dprintf_bp(bp, fmt, ...) do { \ |
1120 | if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ | |
1121 | char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP); \ | |
1122 | snprintf_blkptr(__blkbuf, BP_SPRINTF_LEN, (bp)); \ | |
1123 | dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf); \ | |
1124 | kmem_free(__blkbuf, BP_SPRINTF_LEN); \ | |
34dc7c2f BB |
1125 | } \ |
1126 | _NOTE(CONSTCOND) } while (0) | |
1127 | #else | |
1128 | #define dprintf_bp(bp, fmt, ...) | |
1129 | #endif | |
1130 | ||
fb5f0bc8 | 1131 | extern int spa_mode_global; /* mode, e.g. FREAD | FWRITE */ |
8fb1ede1 BB |
1132 | extern int zfs_deadman_enabled; |
1133 | extern unsigned long zfs_deadman_synctime_ms; | |
1134 | extern unsigned long zfs_deadman_ziotime_ms; | |
1135 | extern unsigned long zfs_deadman_checktime_ms; | |
34dc7c2f BB |
1136 | |
1137 | #ifdef __cplusplus | |
1138 | } | |
1139 | #endif | |
1140 | ||
1141 | #endif /* _SYS_SPA_H */ |