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