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.
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.
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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2011, 2020 by Delphix. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
26 * Copyright 2013 Saso Kiselkov. All rights reserved.
27 * Copyright (c) 2014 Integros [integros.com]
28 * Copyright 2017 Joyent, Inc.
29 * Copyright (c) 2017, 2019, Datto Inc. All rights reserved.
30 * Copyright (c) 2017, Intel Corporation.
31 * Copyright (c) 2019, Allan Jude
32 * Copyright (c) 2019, Klara Inc.
39 #include <sys/zfs_context.h>
40 #include <sys/kstat.h>
41 #include <sys/nvpair.h>
42 #include <sys/sysmacros.h>
43 #include <sys/types.h>
44 #include <sys/fs/zfs.h>
45 #include <sys/spa_checksum.h>
47 #include <sys/space_map.h>
48 #include <sys/bitops.h>
55 * Forward references that lots of things need.
57 typedef struct spa spa_t
;
58 typedef struct vdev vdev_t
;
59 typedef struct metaslab metaslab_t
;
60 typedef struct metaslab_group metaslab_group_t
;
61 typedef struct metaslab_class metaslab_class_t
;
62 typedef struct zio zio_t
;
63 typedef struct zilog zilog_t
;
64 typedef struct spa_aux_vdev spa_aux_vdev_t
;
65 typedef struct ddt ddt_t
;
66 typedef struct ddt_entry ddt_entry_t
;
67 typedef struct zbookmark_phys zbookmark_phys_t
;
73 struct dsl_crypto_params
;
76 * We currently support block sizes from 512 bytes to 16MB.
77 * The benefits of larger blocks, and thus larger IO, need to be weighed
78 * against the cost of COWing a giant block to modify one byte, and the
79 * large latency of reading or writing a large block.
81 * Note that although blocks up to 16MB are supported, the recordsize
82 * property can not be set larger than zfs_max_recordsize (default 1MB).
83 * See the comment near zfs_max_recordsize in dsl_dataset.c for details.
85 * Note that although the LSIZE field of the blkptr_t can store sizes up
86 * to 32MB, the dnode's dn_datablkszsec can only store sizes up to
87 * 32MB - 512 bytes. Therefore, we limit SPA_MAXBLOCKSIZE to 16MB.
89 #define SPA_MINBLOCKSHIFT 9
90 #define SPA_OLD_MAXBLOCKSHIFT 17
91 #define SPA_MAXBLOCKSHIFT 24
92 #define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT)
93 #define SPA_OLD_MAXBLOCKSIZE (1ULL << SPA_OLD_MAXBLOCKSHIFT)
94 #define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT)
97 * Alignment Shift (ashift) is an immutable, internal top-level vdev property
98 * which can only be set at vdev creation time. Physical writes are always done
99 * according to it, which makes 2^ashift the smallest possible IO on a vdev.
101 * We currently allow values ranging from 512 bytes (2^9 = 512) to 64 KiB
105 #define ASHIFT_MAX 16
108 * Size of block to hold the configuration data (a packed nvlist)
110 #define SPA_CONFIG_BLOCKSIZE (1ULL << 14)
113 * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
114 * The ASIZE encoding should be at least 64 times larger (6 more bits)
115 * to support up to 4-way RAID-Z mirror mode with worst-case gang block
116 * overhead, three DVAs per bp, plus one more bit in case we do anything
117 * else that expands the ASIZE.
119 #define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */
120 #define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */
121 #define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */
123 #define SPA_COMPRESSBITS 7
124 #define SPA_VDEVBITS 24
125 #define SPA_COMPRESSMASK ((1U << SPA_COMPRESSBITS) - 1)
128 * All SPA data is represented by 128-bit data virtual addresses (DVAs).
129 * The members of the dva_t should be considered opaque outside the SPA.
132 uint64_t dva_word
[2];
137 * Some checksums/hashes need a 256-bit initialization salt. This salt is kept
138 * secret and is suitable for use in MAC algorithms as the key.
140 typedef struct zio_cksum_salt
{
141 uint8_t zcs_bytes
[32];
145 * Each block is described by its DVAs, time of birth, checksum, etc.
146 * The word-by-word, bit-by-bit layout of the blkptr is as follows:
148 * 64 56 48 40 32 24 16 8 0
149 * +-------+-------+-------+-------+-------+-------+-------+-------+
150 * 0 | pad | vdev1 | GRID | ASIZE |
151 * +-------+-------+-------+-------+-------+-------+-------+-------+
153 * +-------+-------+-------+-------+-------+-------+-------+-------+
154 * 2 | pad | vdev2 | GRID | ASIZE |
155 * +-------+-------+-------+-------+-------+-------+-------+-------+
157 * +-------+-------+-------+-------+-------+-------+-------+-------+
158 * 4 | pad | vdev3 | GRID | ASIZE |
159 * +-------+-------+-------+-------+-------+-------+-------+-------+
161 * +-------+-------+-------+-------+-------+-------+-------+-------+
162 * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE |
163 * +-------+-------+-------+-------+-------+-------+-------+-------+
165 * +-------+-------+-------+-------+-------+-------+-------+-------+
167 * +-------+-------+-------+-------+-------+-------+-------+-------+
168 * 9 | physical birth txg |
169 * +-------+-------+-------+-------+-------+-------+-------+-------+
170 * a | logical birth txg |
171 * +-------+-------+-------+-------+-------+-------+-------+-------+
173 * +-------+-------+-------+-------+-------+-------+-------+-------+
175 * +-------+-------+-------+-------+-------+-------+-------+-------+
177 * +-------+-------+-------+-------+-------+-------+-------+-------+
179 * +-------+-------+-------+-------+-------+-------+-------+-------+
181 * +-------+-------+-------+-------+-------+-------+-------+-------+
185 * vdev virtual device ID
186 * offset offset into virtual device
188 * PSIZE physical size (after compression)
189 * ASIZE allocated size (including RAID-Z parity and gang block headers)
190 * GRID RAID-Z layout information (reserved for future use)
191 * cksum checksum function
192 * comp compression function
193 * G gang block indicator
194 * B byteorder (endianness)
197 * E blkptr_t contains embedded data (see below)
198 * lvl level of indirection
199 * type DMU object type
200 * phys birth txg when dva[0] was written; zero if same as logical birth txg
201 * note that typically all the dva's would be written in this
202 * txg, but they could be different if they were moved by
204 * log. birth transaction group in which the block was logically born
205 * fill count number of non-zero blocks under this bp
206 * checksum[4] 256-bit checksum of the data this bp describes
210 * The blkptr_t's of encrypted blocks also need to store the encryption
211 * parameters so that the block can be decrypted. This layout is as follows:
213 * 64 56 48 40 32 24 16 8 0
214 * +-------+-------+-------+-------+-------+-------+-------+-------+
215 * 0 | vdev1 | GRID | ASIZE |
216 * +-------+-------+-------+-------+-------+-------+-------+-------+
218 * +-------+-------+-------+-------+-------+-------+-------+-------+
219 * 2 | vdev2 | GRID | ASIZE |
220 * +-------+-------+-------+-------+-------+-------+-------+-------+
222 * +-------+-------+-------+-------+-------+-------+-------+-------+
224 * +-------+-------+-------+-------+-------+-------+-------+-------+
226 * +-------+-------+-------+-------+-------+-------+-------+-------+
227 * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE |
228 * +-------+-------+-------+-------+-------+-------+-------+-------+
230 * +-------+-------+-------+-------+-------+-------+-------+-------+
232 * +-------+-------+-------+-------+-------+-------+-------+-------+
233 * 9 | physical birth txg |
234 * +-------+-------+-------+-------+-------+-------+-------+-------+
235 * a | logical birth txg |
236 * +-------+-------+-------+-------+-------+-------+-------+-------+
237 * b | IV2 | fill count |
238 * +-------+-------+-------+-------+-------+-------+-------+-------+
240 * +-------+-------+-------+-------+-------+-------+-------+-------+
242 * +-------+-------+-------+-------+-------+-------+-------+-------+
244 * +-------+-------+-------+-------+-------+-------+-------+-------+
246 * +-------+-------+-------+-------+-------+-------+-------+-------+
250 * salt Salt for generating encryption keys
251 * IV1 First 64 bits of encryption IV
252 * X Block requires encryption handling (set to 1)
253 * E blkptr_t contains embedded data (set to 0, see below)
254 * fill count number of non-zero blocks under this bp (truncated to 32 bits)
255 * IV2 Last 32 bits of encryption IV
256 * checksum[2] 128-bit checksum of the data this bp describes
257 * MAC[2] 128-bit message authentication code for this data
259 * The X bit being set indicates that this block is one of 3 types. If this is
260 * a level 0 block with an encrypted object type, the block is encrypted
261 * (see BP_IS_ENCRYPTED()). If this is a level 0 block with an unencrypted
262 * object type, this block is authenticated with an HMAC (see
263 * BP_IS_AUTHENTICATED()). Otherwise (if level > 0), this bp will use the MAC
264 * words to store a checksum-of-MACs from the level below (see
265 * BP_HAS_INDIRECT_MAC_CKSUM()). For convenience in the code, BP_IS_PROTECTED()
266 * refers to both encrypted and authenticated blocks and BP_USES_CRYPT()
267 * refers to any of these 3 kinds of blocks.
269 * The additional encryption parameters are the salt, IV, and MAC which are
270 * explained in greater detail in the block comment at the top of zio_crypt.c.
271 * The MAC occupies half of the checksum space since it serves a very similar
272 * purpose: to prevent data corruption on disk. The only functional difference
273 * is that the checksum is used to detect on-disk corruption whether or not the
274 * encryption key is loaded and the MAC provides additional protection against
275 * malicious disk tampering. We use the 3rd DVA to store the salt and first
276 * 64 bits of the IV. As a result encrypted blocks can only have 2 copies
277 * maximum instead of the normal 3. The last 32 bits of the IV are stored in
278 * the upper bits of what is usually the fill count. Note that only blocks at
279 * level 0 or -2 are ever encrypted, which allows us to guarantee that these
280 * 32 bits are not trampled over by other code (see zio_crypt.c for details).
281 * The salt and IV are not used for authenticated bps or bps with an indirect
282 * MAC checksum, so these blocks can utilize all 3 DVAs and the full 64 bits
283 * for the fill count.
287 * "Embedded" blkptr_t's don't actually point to a block, instead they
288 * have a data payload embedded in the blkptr_t itself. See the comment
289 * in blkptr.c for more details.
291 * The blkptr_t is laid out as follows:
293 * 64 56 48 40 32 24 16 8 0
294 * +-------+-------+-------+-------+-------+-------+-------+-------+
301 * +-------+-------+-------+-------+-------+-------+-------+-------+
302 * 6 |BDX|lvl| type | etype |E| comp| PSIZE| LSIZE |
303 * +-------+-------+-------+-------+-------+-------+-------+-------+
307 * +-------+-------+-------+-------+-------+-------+-------+-------+
308 * a | logical birth txg |
309 * +-------+-------+-------+-------+-------+-------+-------+-------+
315 * +-------+-------+-------+-------+-------+-------+-------+-------+
319 * payload contains the embedded data
320 * B (byteorder) byteorder (endianness)
321 * D (dedup) padding (set to zero)
322 * X encryption (set to zero)
323 * E (embedded) set to one
324 * lvl indirection level
325 * type DMU object type
326 * etype how to interpret embedded data (BP_EMBEDDED_TYPE_*)
327 * comp compression function of payload
328 * PSIZE size of payload after compression, in bytes
329 * LSIZE logical size of payload, in bytes
330 * note that 25 bits is enough to store the largest
331 * "normal" BP's LSIZE (2^16 * 2^9) in bytes
332 * log. birth transaction group in which the block was logically born
334 * Note that LSIZE and PSIZE are stored in bytes, whereas for non-embedded
335 * bp's they are stored in units of SPA_MINBLOCKSHIFT.
336 * Generally, the generic BP_GET_*() macros can be used on embedded BP's.
337 * The B, D, X, lvl, type, and comp fields are stored the same as with normal
338 * BP's so the BP_SET_* macros can be used with them. etype, PSIZE, LSIZE must
339 * be set with the BPE_SET_* macros. BP_SET_EMBEDDED() should be called before
340 * other macros, as they assert that they are only used on BP's of the correct
341 * "embedded-ness". Encrypted blkptr_t's cannot be embedded because they use
342 * the payload space for encryption parameters (see the comment above on
343 * how encryption parameters are stored).
346 #define BPE_GET_ETYPE(bp) \
347 (ASSERT(BP_IS_EMBEDDED(bp)), \
348 BF64_GET((bp)->blk_prop, 40, 8))
349 #define BPE_SET_ETYPE(bp, t) do { \
350 ASSERT(BP_IS_EMBEDDED(bp)); \
351 BF64_SET((bp)->blk_prop, 40, 8, t); \
352 _NOTE(CONSTCOND) } while (0)
354 #define BPE_GET_LSIZE(bp) \
355 (ASSERT(BP_IS_EMBEDDED(bp)), \
356 BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1))
357 #define BPE_SET_LSIZE(bp, x) do { \
358 ASSERT(BP_IS_EMBEDDED(bp)); \
359 BF64_SET_SB((bp)->blk_prop, 0, 25, 0, 1, x); \
360 _NOTE(CONSTCOND) } while (0)
362 #define BPE_GET_PSIZE(bp) \
363 (ASSERT(BP_IS_EMBEDDED(bp)), \
364 BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1))
365 #define BPE_SET_PSIZE(bp, x) do { \
366 ASSERT(BP_IS_EMBEDDED(bp)); \
367 BF64_SET_SB((bp)->blk_prop, 25, 7, 0, 1, x); \
368 _NOTE(CONSTCOND) } while (0)
370 typedef enum bp_embedded_type
{
371 BP_EMBEDDED_TYPE_DATA
,
372 BP_EMBEDDED_TYPE_RESERVED
, /* Reserved for Delphix byteswap feature. */
373 BP_EMBEDDED_TYPE_REDACTED
,
374 NUM_BP_EMBEDDED_TYPES
375 } bp_embedded_type_t
;
377 #define BPE_NUM_WORDS 14
378 #define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t))
379 #define BPE_IS_PAYLOADWORD(bp, wp) \
380 ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth)
382 #define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */
383 #define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */
384 #define SPA_SYNC_MIN_VDEVS 3 /* min vdevs to update during sync */
387 * A block is a hole when it has either 1) never been written to, or
388 * 2) is zero-filled. In both cases, ZFS can return all zeroes for all reads
389 * without physically allocating disk space. Holes are represented in the
390 * blkptr_t structure by zeroed blk_dva. Correct checking for holes is
391 * done through the BP_IS_HOLE macro. For holes, the logical size, level,
392 * DMU object type, and birth times are all also stored for holes that
393 * were written to at some point (i.e. were punched after having been filled).
395 typedef struct blkptr
{
396 dva_t blk_dva
[SPA_DVAS_PER_BP
]; /* Data Virtual Addresses */
397 uint64_t blk_prop
; /* size, compression, type, etc */
398 uint64_t blk_pad
[2]; /* Extra space for the future */
399 uint64_t blk_phys_birth
; /* txg when block was allocated */
400 uint64_t blk_birth
; /* transaction group at birth */
401 uint64_t blk_fill
; /* fill count */
402 zio_cksum_t blk_cksum
; /* 256-bit checksum */
406 * Macros to get and set fields in a bp or DVA.
408 #define DVA_GET_ASIZE(dva) \
409 BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0)
410 #define DVA_SET_ASIZE(dva, x) \
411 BF64_SET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, \
412 SPA_MINBLOCKSHIFT, 0, x)
414 #define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8)
415 #define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x)
417 #define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, SPA_VDEVBITS)
418 #define DVA_SET_VDEV(dva, x) \
419 BF64_SET((dva)->dva_word[0], 32, SPA_VDEVBITS, x)
421 #define DVA_GET_OFFSET(dva) \
422 BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0)
423 #define DVA_SET_OFFSET(dva, x) \
424 BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x)
426 #define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1)
427 #define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x)
429 #define BP_GET_LSIZE(bp) \
430 (BP_IS_EMBEDDED(bp) ? \
431 (BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA ? BPE_GET_LSIZE(bp) : 0): \
432 BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1))
433 #define BP_SET_LSIZE(bp, x) do { \
434 ASSERT(!BP_IS_EMBEDDED(bp)); \
435 BF64_SET_SB((bp)->blk_prop, \
436 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \
437 _NOTE(CONSTCOND) } while (0)
439 #define BP_GET_PSIZE(bp) \
440 (BP_IS_EMBEDDED(bp) ? 0 : \
441 BF64_GET_SB((bp)->blk_prop, 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1))
442 #define BP_SET_PSIZE(bp, x) do { \
443 ASSERT(!BP_IS_EMBEDDED(bp)); \
444 BF64_SET_SB((bp)->blk_prop, \
445 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \
446 _NOTE(CONSTCOND) } while (0)
448 #define BP_GET_COMPRESS(bp) \
449 BF64_GET((bp)->blk_prop, 32, SPA_COMPRESSBITS)
450 #define BP_SET_COMPRESS(bp, x) \
451 BF64_SET((bp)->blk_prop, 32, SPA_COMPRESSBITS, x)
453 #define BP_IS_EMBEDDED(bp) BF64_GET((bp)->blk_prop, 39, 1)
454 #define BP_SET_EMBEDDED(bp, x) BF64_SET((bp)->blk_prop, 39, 1, x)
456 #define BP_GET_CHECKSUM(bp) \
457 (BP_IS_EMBEDDED(bp) ? ZIO_CHECKSUM_OFF : \
458 BF64_GET((bp)->blk_prop, 40, 8))
459 #define BP_SET_CHECKSUM(bp, x) do { \
460 ASSERT(!BP_IS_EMBEDDED(bp)); \
461 BF64_SET((bp)->blk_prop, 40, 8, x); \
462 _NOTE(CONSTCOND) } while (0)
464 #define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8)
465 #define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x)
467 #define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5)
468 #define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x)
470 /* encrypted, authenticated, and MAC cksum bps use the same bit */
471 #define BP_USES_CRYPT(bp) BF64_GET((bp)->blk_prop, 61, 1)
472 #define BP_SET_CRYPT(bp, x) BF64_SET((bp)->blk_prop, 61, 1, x)
474 #define BP_IS_ENCRYPTED(bp) \
475 (BP_USES_CRYPT(bp) && \
476 BP_GET_LEVEL(bp) <= 0 && \
477 DMU_OT_IS_ENCRYPTED(BP_GET_TYPE(bp)))
479 #define BP_IS_AUTHENTICATED(bp) \
480 (BP_USES_CRYPT(bp) && \
481 BP_GET_LEVEL(bp) <= 0 && \
482 !DMU_OT_IS_ENCRYPTED(BP_GET_TYPE(bp)))
484 #define BP_HAS_INDIRECT_MAC_CKSUM(bp) \
485 (BP_USES_CRYPT(bp) && BP_GET_LEVEL(bp) > 0)
487 #define BP_IS_PROTECTED(bp) \
488 (BP_IS_ENCRYPTED(bp) || BP_IS_AUTHENTICATED(bp))
490 #define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1)
491 #define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x)
493 #define BP_GET_BYTEORDER(bp) BF64_GET((bp)->blk_prop, 63, 1)
494 #define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x)
496 #define BP_GET_FREE(bp) BF64_GET((bp)->blk_fill, 0, 1)
497 #define BP_SET_FREE(bp, x) BF64_SET((bp)->blk_fill, 0, 1, x)
499 #define BP_PHYSICAL_BIRTH(bp) \
500 (BP_IS_EMBEDDED(bp) ? 0 : \
501 (bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)
503 #define BP_SET_BIRTH(bp, logical, physical) \
505 ASSERT(!BP_IS_EMBEDDED(bp)); \
506 (bp)->blk_birth = (logical); \
507 (bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \
510 #define BP_GET_FILL(bp) \
511 ((BP_IS_ENCRYPTED(bp)) ? BF64_GET((bp)->blk_fill, 0, 32) : \
512 ((BP_IS_EMBEDDED(bp)) ? 1 : (bp)->blk_fill))
514 #define BP_SET_FILL(bp, fill) \
516 if (BP_IS_ENCRYPTED(bp)) \
517 BF64_SET((bp)->blk_fill, 0, 32, fill); \
519 (bp)->blk_fill = fill; \
522 #define BP_GET_IV2(bp) \
523 (ASSERT(BP_IS_ENCRYPTED(bp)), \
524 BF64_GET((bp)->blk_fill, 32, 32))
525 #define BP_SET_IV2(bp, iv2) \
527 ASSERT(BP_IS_ENCRYPTED(bp)); \
528 BF64_SET((bp)->blk_fill, 32, 32, iv2); \
531 #define BP_IS_METADATA(bp) \
532 (BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp)))
534 #define BP_GET_ASIZE(bp) \
535 (BP_IS_EMBEDDED(bp) ? 0 : \
536 DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
537 DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
538 (DVA_GET_ASIZE(&(bp)->blk_dva[2]) * !BP_IS_ENCRYPTED(bp)))
540 #define BP_GET_UCSIZE(bp) \
541 (BP_IS_METADATA(bp) ? BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp))
543 #define BP_GET_NDVAS(bp) \
544 (BP_IS_EMBEDDED(bp) ? 0 : \
545 !!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
546 !!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
547 (!!DVA_GET_ASIZE(&(bp)->blk_dva[2]) * !BP_IS_ENCRYPTED(bp)))
549 #define BP_COUNT_GANG(bp) \
550 (BP_IS_EMBEDDED(bp) ? 0 : \
551 (DVA_GET_GANG(&(bp)->blk_dva[0]) + \
552 DVA_GET_GANG(&(bp)->blk_dva[1]) + \
553 (DVA_GET_GANG(&(bp)->blk_dva[2]) * !BP_IS_ENCRYPTED(bp))))
555 #define DVA_EQUAL(dva1, dva2) \
556 ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
557 (dva1)->dva_word[0] == (dva2)->dva_word[0])
559 #define BP_EQUAL(bp1, bp2) \
560 (BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) && \
561 (bp1)->blk_birth == (bp2)->blk_birth && \
562 DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) && \
563 DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) && \
564 DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2]))
567 #define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0)
569 #define BP_IDENTITY(bp) (ASSERT(!BP_IS_EMBEDDED(bp)), &(bp)->blk_dva[0])
570 #define BP_IS_GANG(bp) \
571 (BP_IS_EMBEDDED(bp) ? B_FALSE : DVA_GET_GANG(BP_IDENTITY(bp)))
572 #define DVA_IS_EMPTY(dva) ((dva)->dva_word[0] == 0ULL && \
573 (dva)->dva_word[1] == 0ULL)
574 #define BP_IS_HOLE(bp) \
575 (!BP_IS_EMBEDDED(bp) && DVA_IS_EMPTY(BP_IDENTITY(bp)))
577 #define BP_SET_REDACTED(bp) \
579 BP_SET_EMBEDDED(bp, B_TRUE); \
580 BPE_SET_ETYPE(bp, BP_EMBEDDED_TYPE_REDACTED); \
582 #define BP_IS_REDACTED(bp) \
583 (BP_IS_EMBEDDED(bp) && BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_REDACTED)
585 /* BP_IS_RAIDZ(bp) assumes no block compression */
586 #define BP_IS_RAIDZ(bp) (DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \
589 #define BP_ZERO(bp) \
591 (bp)->blk_dva[0].dva_word[0] = 0; \
592 (bp)->blk_dva[0].dva_word[1] = 0; \
593 (bp)->blk_dva[1].dva_word[0] = 0; \
594 (bp)->blk_dva[1].dva_word[1] = 0; \
595 (bp)->blk_dva[2].dva_word[0] = 0; \
596 (bp)->blk_dva[2].dva_word[1] = 0; \
597 (bp)->blk_prop = 0; \
598 (bp)->blk_pad[0] = 0; \
599 (bp)->blk_pad[1] = 0; \
600 (bp)->blk_phys_birth = 0; \
601 (bp)->blk_birth = 0; \
602 (bp)->blk_fill = 0; \
603 ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \
606 #ifdef _ZFS_BIG_ENDIAN
607 #define ZFS_HOST_BYTEORDER (0ULL)
609 #define ZFS_HOST_BYTEORDER (1ULL)
612 #define BP_SHOULD_BYTESWAP(bp) (BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER)
614 #define BP_SPRINTF_LEN 400
617 * This macro allows code sharing between zfs, libzpool, and mdb.
618 * 'func' is either snprintf() or mdb_snprintf().
619 * 'ws' (whitespace) can be ' ' for single-line format, '\n' for multi-line.
622 #define SNPRINTF_BLKPTR(func, ws, buf, size, bp, type, checksum, compress) \
624 static const char *copyname[] = \
625 { "zero", "single", "double", "triple" }; \
628 const char *crypt_type; \
630 if (BP_IS_ENCRYPTED(bp)) { \
631 crypt_type = "encrypted"; \
632 /* LINTED E_SUSPICIOUS_COMPARISON */ \
633 } else if (BP_IS_AUTHENTICATED(bp)) { \
634 crypt_type = "authenticated"; \
635 } else if (BP_HAS_INDIRECT_MAC_CKSUM(bp)) { \
636 crypt_type = "indirect-MAC"; \
638 crypt_type = "unencrypted"; \
642 len += func(buf + len, size - len, "<NULL>"); \
643 } else if (BP_IS_HOLE(bp)) { \
644 len += func(buf + len, size - len, \
646 "size=%llxL birth=%lluL", \
647 (u_longlong_t)BP_GET_LEVEL(bp), \
649 (u_longlong_t)BP_GET_LSIZE(bp), \
650 (u_longlong_t)bp->blk_birth); \
651 } else if (BP_IS_EMBEDDED(bp)) { \
652 len = func(buf + len, size - len, \
653 "EMBEDDED [L%llu %s] et=%u %s " \
654 "size=%llxL/%llxP birth=%lluL", \
655 (u_longlong_t)BP_GET_LEVEL(bp), \
657 (int)BPE_GET_ETYPE(bp), \
659 (u_longlong_t)BPE_GET_LSIZE(bp), \
660 (u_longlong_t)BPE_GET_PSIZE(bp), \
661 (u_longlong_t)bp->blk_birth); \
662 } else if (BP_IS_REDACTED(bp)) { \
663 len += func(buf + len, size - len, \
664 "REDACTED [L%llu %s] size=%llxL birth=%lluL", \
665 (u_longlong_t)BP_GET_LEVEL(bp), \
667 (u_longlong_t)BP_GET_LSIZE(bp), \
668 (u_longlong_t)bp->blk_birth); \
670 for (int d = 0; d < BP_GET_NDVAS(bp); d++) { \
671 const dva_t *dva = &bp->blk_dva[d]; \
672 if (DVA_IS_VALID(dva)) \
674 len += func(buf + len, size - len, \
675 "DVA[%d]=<%llu:%llx:%llx>%c", d, \
676 (u_longlong_t)DVA_GET_VDEV(dva), \
677 (u_longlong_t)DVA_GET_OFFSET(dva), \
678 (u_longlong_t)DVA_GET_ASIZE(dva), \
681 if (BP_IS_ENCRYPTED(bp)) { \
682 len += func(buf + len, size - len, \
683 "salt=%llx iv=%llx:%llx%c", \
684 (u_longlong_t)bp->blk_dva[2].dva_word[0], \
685 (u_longlong_t)bp->blk_dva[2].dva_word[1], \
686 (u_longlong_t)BP_GET_IV2(bp), \
689 if (BP_IS_GANG(bp) && \
690 DVA_GET_ASIZE(&bp->blk_dva[2]) <= \
691 DVA_GET_ASIZE(&bp->blk_dva[1]) / 2) \
693 len += func(buf + len, size - len, \
694 "[L%llu %s] %s %s %s %s %s %s %s%c" \
695 "size=%llxL/%llxP birth=%lluL/%lluP fill=%llu%c" \
696 "cksum=%llx:%llx:%llx:%llx", \
697 (u_longlong_t)BP_GET_LEVEL(bp), \
702 BP_GET_BYTEORDER(bp) == 0 ? "BE" : "LE", \
703 BP_IS_GANG(bp) ? "gang" : "contiguous", \
704 BP_GET_DEDUP(bp) ? "dedup" : "unique", \
707 (u_longlong_t)BP_GET_LSIZE(bp), \
708 (u_longlong_t)BP_GET_PSIZE(bp), \
709 (u_longlong_t)bp->blk_birth, \
710 (u_longlong_t)BP_PHYSICAL_BIRTH(bp), \
711 (u_longlong_t)BP_GET_FILL(bp), \
713 (u_longlong_t)bp->blk_cksum.zc_word[0], \
714 (u_longlong_t)bp->blk_cksum.zc_word[1], \
715 (u_longlong_t)bp->blk_cksum.zc_word[2], \
716 (u_longlong_t)bp->blk_cksum.zc_word[3]); \
718 ASSERT(len < size); \
721 #define BP_GET_BUFC_TYPE(bp) \
722 (BP_IS_METADATA(bp) ? ARC_BUFC_METADATA : ARC_BUFC_DATA)
724 typedef enum spa_import_type
{
729 typedef enum spa_mode
{
736 * Send TRIM commands in-line during normal pool operation while deleting.
739 * NB: IN_FREEBSD_BASE is defined within the FreeBSD sources.
742 SPA_AUTOTRIM_OFF
= 0, /* default */
744 #ifdef IN_FREEBSD_BASE
745 SPA_AUTOTRIM_DEFAULT
= SPA_AUTOTRIM_ON
,
747 SPA_AUTOTRIM_DEFAULT
= SPA_AUTOTRIM_OFF
,
752 * Reason TRIM command was issued, used internally for accounting purposes.
754 typedef enum trim_type
{
755 TRIM_TYPE_MANUAL
= 0,
760 /* state manipulation functions */
761 extern int spa_open(const char *pool
, spa_t
**, void *tag
);
762 extern int spa_open_rewind(const char *pool
, spa_t
**, void *tag
,
763 nvlist_t
*policy
, nvlist_t
**config
);
764 extern int spa_get_stats(const char *pool
, nvlist_t
**config
, char *altroot
,
766 extern int spa_create(const char *pool
, nvlist_t
*nvroot
, nvlist_t
*props
,
767 nvlist_t
*zplprops
, struct dsl_crypto_params
*dcp
);
768 extern int spa_import(char *pool
, nvlist_t
*config
, nvlist_t
*props
,
770 extern nvlist_t
*spa_tryimport(nvlist_t
*tryconfig
);
771 extern int spa_destroy(const char *pool
);
772 extern int spa_checkpoint(const char *pool
);
773 extern int spa_checkpoint_discard(const char *pool
);
774 extern int spa_export(const char *pool
, nvlist_t
**oldconfig
, boolean_t force
,
775 boolean_t hardforce
);
776 extern int spa_reset(const char *pool
);
777 extern void spa_async_request(spa_t
*spa
, int flag
);
778 extern void spa_async_unrequest(spa_t
*spa
, int flag
);
779 extern void spa_async_suspend(spa_t
*spa
);
780 extern void spa_async_resume(spa_t
*spa
);
781 extern int spa_async_tasks(spa_t
*spa
);
782 extern spa_t
*spa_inject_addref(char *pool
);
783 extern void spa_inject_delref(spa_t
*spa
);
784 extern void spa_scan_stat_init(spa_t
*spa
);
785 extern int spa_scan_get_stats(spa_t
*spa
, pool_scan_stat_t
*ps
);
786 extern int bpobj_enqueue_alloc_cb(void *arg
, const blkptr_t
*bp
, dmu_tx_t
*tx
);
787 extern int bpobj_enqueue_free_cb(void *arg
, const blkptr_t
*bp
, dmu_tx_t
*tx
);
789 #define SPA_ASYNC_CONFIG_UPDATE 0x01
790 #define SPA_ASYNC_REMOVE 0x02
791 #define SPA_ASYNC_PROBE 0x04
792 #define SPA_ASYNC_RESILVER_DONE 0x08
793 #define SPA_ASYNC_RESILVER 0x10
794 #define SPA_ASYNC_AUTOEXPAND 0x20
795 #define SPA_ASYNC_REMOVE_DONE 0x40
796 #define SPA_ASYNC_REMOVE_STOP 0x80
797 #define SPA_ASYNC_INITIALIZE_RESTART 0x100
798 #define SPA_ASYNC_TRIM_RESTART 0x200
799 #define SPA_ASYNC_AUTOTRIM_RESTART 0x400
800 #define SPA_ASYNC_L2CACHE_REBUILD 0x800
801 #define SPA_ASYNC_L2CACHE_TRIM 0x1000
802 #define SPA_ASYNC_REBUILD_DONE 0x2000
804 /* device manipulation */
805 extern int spa_vdev_add(spa_t
*spa
, nvlist_t
*nvroot
);
806 extern int spa_vdev_attach(spa_t
*spa
, uint64_t guid
, nvlist_t
*nvroot
,
807 int replacing
, int rebuild
);
808 extern int spa_vdev_detach(spa_t
*spa
, uint64_t guid
, uint64_t pguid
,
810 extern int spa_vdev_remove(spa_t
*spa
, uint64_t guid
, boolean_t unspare
);
811 extern boolean_t
spa_vdev_remove_active(spa_t
*spa
);
812 extern int spa_vdev_initialize(spa_t
*spa
, nvlist_t
*nv
, uint64_t cmd_type
,
813 nvlist_t
*vdev_errlist
);
814 extern int spa_vdev_trim(spa_t
*spa
, nvlist_t
*nv
, uint64_t cmd_type
,
815 uint64_t rate
, boolean_t partial
, boolean_t secure
, nvlist_t
*vdev_errlist
);
816 extern int spa_vdev_setpath(spa_t
*spa
, uint64_t guid
, const char *newpath
);
817 extern int spa_vdev_setfru(spa_t
*spa
, uint64_t guid
, const char *newfru
);
818 extern int spa_vdev_split_mirror(spa_t
*spa
, char *newname
, nvlist_t
*config
,
819 nvlist_t
*props
, boolean_t exp
);
821 /* spare state (which is global across all pools) */
822 extern void spa_spare_add(vdev_t
*vd
);
823 extern void spa_spare_remove(vdev_t
*vd
);
824 extern boolean_t
spa_spare_exists(uint64_t guid
, uint64_t *pool
, int *refcnt
);
825 extern void spa_spare_activate(vdev_t
*vd
);
827 /* L2ARC state (which is global across all pools) */
828 extern void spa_l2cache_add(vdev_t
*vd
);
829 extern void spa_l2cache_remove(vdev_t
*vd
);
830 extern boolean_t
spa_l2cache_exists(uint64_t guid
, uint64_t *pool
);
831 extern void spa_l2cache_activate(vdev_t
*vd
);
832 extern void spa_l2cache_drop(spa_t
*spa
);
835 extern int spa_scan(spa_t
*spa
, pool_scan_func_t func
);
836 extern int spa_scan_stop(spa_t
*spa
);
837 extern int spa_scrub_pause_resume(spa_t
*spa
, pool_scrub_cmd_t flag
);
840 extern void spa_sync(spa_t
*spa
, uint64_t txg
); /* only for DMU use */
841 extern void spa_sync_allpools(void);
843 extern int zfs_sync_pass_deferred_free
;
845 /* spa namespace global mutex */
846 extern kmutex_t spa_namespace_lock
;
849 * SPA configuration functions in spa_config.c
852 #define SPA_CONFIG_UPDATE_POOL 0
853 #define SPA_CONFIG_UPDATE_VDEVS 1
855 extern void spa_write_cachefile(spa_t
*, boolean_t
, boolean_t
);
856 extern void spa_config_load(void);
857 extern nvlist_t
*spa_all_configs(uint64_t *);
858 extern void spa_config_set(spa_t
*spa
, nvlist_t
*config
);
859 extern nvlist_t
*spa_config_generate(spa_t
*spa
, vdev_t
*vd
, uint64_t txg
,
861 extern void spa_config_update(spa_t
*spa
, int what
);
862 extern int spa_config_parse(spa_t
*spa
, vdev_t
**vdp
, nvlist_t
*nv
,
863 vdev_t
*parent
, uint_t id
, int atype
);
867 * Miscellaneous SPA routines in spa_misc.c
870 /* Namespace manipulation */
871 extern spa_t
*spa_lookup(const char *name
);
872 extern spa_t
*spa_add(const char *name
, nvlist_t
*config
, const char *altroot
);
873 extern void spa_remove(spa_t
*spa
);
874 extern spa_t
*spa_next(spa_t
*prev
);
876 /* Refcount functions */
877 extern void spa_open_ref(spa_t
*spa
, void *tag
);
878 extern void spa_close(spa_t
*spa
, void *tag
);
879 extern void spa_async_close(spa_t
*spa
, void *tag
);
880 extern boolean_t
spa_refcount_zero(spa_t
*spa
);
882 #define SCL_NONE 0x00
883 #define SCL_CONFIG 0x01
884 #define SCL_STATE 0x02
885 #define SCL_L2ARC 0x04 /* hack until L2ARC 2.0 */
886 #define SCL_ALLOC 0x08
888 #define SCL_FREE 0x20
889 #define SCL_VDEV 0x40
891 #define SCL_ALL ((1 << SCL_LOCKS) - 1)
892 #define SCL_STATE_ALL (SCL_STATE | SCL_L2ARC | SCL_ZIO)
894 /* Historical pool statistics */
895 typedef struct spa_history_kstat
{
902 } spa_history_kstat_t
;
904 typedef struct spa_history_list
{
906 procfs_list_t procfs_list
;
907 } spa_history_list_t
;
909 typedef struct spa_stats
{
910 spa_history_list_t read_history
;
911 spa_history_list_t txg_history
;
912 spa_history_kstat_t tx_assign_histogram
;
913 spa_history_kstat_t io_history
;
914 spa_history_list_t mmp_history
;
915 spa_history_kstat_t state
; /* pool state */
916 spa_history_kstat_t iostats
;
919 typedef enum txg_state
{
922 TXG_STATE_QUIESCED
= 2,
923 TXG_STATE_WAIT_FOR_SYNC
= 3,
924 TXG_STATE_SYNCED
= 4,
925 TXG_STATE_COMMITTED
= 5,
928 typedef struct txg_stat
{
935 /* Assorted pool IO kstats */
936 typedef struct spa_iostats
{
937 kstat_named_t trim_extents_written
;
938 kstat_named_t trim_bytes_written
;
939 kstat_named_t trim_extents_skipped
;
940 kstat_named_t trim_bytes_skipped
;
941 kstat_named_t trim_extents_failed
;
942 kstat_named_t trim_bytes_failed
;
943 kstat_named_t autotrim_extents_written
;
944 kstat_named_t autotrim_bytes_written
;
945 kstat_named_t autotrim_extents_skipped
;
946 kstat_named_t autotrim_bytes_skipped
;
947 kstat_named_t autotrim_extents_failed
;
948 kstat_named_t autotrim_bytes_failed
;
949 kstat_named_t simple_trim_extents_written
;
950 kstat_named_t simple_trim_bytes_written
;
951 kstat_named_t simple_trim_extents_skipped
;
952 kstat_named_t simple_trim_bytes_skipped
;
953 kstat_named_t simple_trim_extents_failed
;
954 kstat_named_t simple_trim_bytes_failed
;
957 extern void spa_stats_init(spa_t
*spa
);
958 extern void spa_stats_destroy(spa_t
*spa
);
959 extern void spa_read_history_add(spa_t
*spa
, const zbookmark_phys_t
*zb
,
961 extern void spa_txg_history_add(spa_t
*spa
, uint64_t txg
, hrtime_t birth_time
);
962 extern int spa_txg_history_set(spa_t
*spa
, uint64_t txg
,
963 txg_state_t completed_state
, hrtime_t completed_time
);
964 extern txg_stat_t
*spa_txg_history_init_io(spa_t
*, uint64_t,
966 extern void spa_txg_history_fini_io(spa_t
*, txg_stat_t
*);
967 extern void spa_tx_assign_add_nsecs(spa_t
*spa
, uint64_t nsecs
);
968 extern int spa_mmp_history_set_skip(spa_t
*spa
, uint64_t mmp_kstat_id
);
969 extern int spa_mmp_history_set(spa_t
*spa
, uint64_t mmp_kstat_id
, int io_error
,
971 extern void spa_mmp_history_add(spa_t
*spa
, uint64_t txg
, uint64_t timestamp
,
972 uint64_t mmp_delay
, vdev_t
*vd
, int label
, uint64_t mmp_kstat_id
,
974 extern void spa_iostats_trim_add(spa_t
*spa
, trim_type_t type
,
975 uint64_t extents_written
, uint64_t bytes_written
,
976 uint64_t extents_skipped
, uint64_t bytes_skipped
,
977 uint64_t extents_failed
, uint64_t bytes_failed
);
978 extern void spa_import_progress_add(spa_t
*spa
);
979 extern void spa_import_progress_remove(uint64_t spa_guid
);
980 extern int spa_import_progress_set_mmp_check(uint64_t pool_guid
,
981 uint64_t mmp_sec_remaining
);
982 extern int spa_import_progress_set_max_txg(uint64_t pool_guid
,
984 extern int spa_import_progress_set_state(uint64_t pool_guid
,
985 spa_load_state_t spa_load_state
);
987 /* Pool configuration locks */
988 extern int spa_config_tryenter(spa_t
*spa
, int locks
, void *tag
, krw_t rw
);
989 extern void spa_config_enter(spa_t
*spa
, int locks
, const void *tag
, krw_t rw
);
990 extern void spa_config_exit(spa_t
*spa
, int locks
, const void *tag
);
991 extern int spa_config_held(spa_t
*spa
, int locks
, krw_t rw
);
993 /* Pool vdev add/remove lock */
994 extern uint64_t spa_vdev_enter(spa_t
*spa
);
995 extern uint64_t spa_vdev_detach_enter(spa_t
*spa
, uint64_t guid
);
996 extern uint64_t spa_vdev_config_enter(spa_t
*spa
);
997 extern void spa_vdev_config_exit(spa_t
*spa
, vdev_t
*vd
, uint64_t txg
,
998 int error
, char *tag
);
999 extern int spa_vdev_exit(spa_t
*spa
, vdev_t
*vd
, uint64_t txg
, int error
);
1001 /* Pool vdev state change lock */
1002 extern void spa_vdev_state_enter(spa_t
*spa
, int oplock
);
1003 extern int spa_vdev_state_exit(spa_t
*spa
, vdev_t
*vd
, int error
);
1006 typedef enum spa_log_state
{
1007 SPA_LOG_UNKNOWN
= 0, /* unknown log state */
1008 SPA_LOG_MISSING
, /* missing log(s) */
1009 SPA_LOG_CLEAR
, /* clear the log(s) */
1010 SPA_LOG_GOOD
, /* log(s) are good */
1013 extern spa_log_state_t
spa_get_log_state(spa_t
*spa
);
1014 extern void spa_set_log_state(spa_t
*spa
, spa_log_state_t state
);
1015 extern int spa_reset_logs(spa_t
*spa
);
1017 /* Log claim callback */
1018 extern void spa_claim_notify(zio_t
*zio
);
1019 extern void spa_deadman(void *);
1021 /* Accessor functions */
1022 extern boolean_t
spa_shutting_down(spa_t
*spa
);
1023 extern struct dsl_pool
*spa_get_dsl(spa_t
*spa
);
1024 extern boolean_t
spa_is_initializing(spa_t
*spa
);
1025 extern boolean_t
spa_indirect_vdevs_loaded(spa_t
*spa
);
1026 extern blkptr_t
*spa_get_rootblkptr(spa_t
*spa
);
1027 extern void spa_set_rootblkptr(spa_t
*spa
, const blkptr_t
*bp
);
1028 extern void spa_altroot(spa_t
*, char *, size_t);
1029 extern int spa_sync_pass(spa_t
*spa
);
1030 extern char *spa_name(spa_t
*spa
);
1031 extern uint64_t spa_guid(spa_t
*spa
);
1032 extern uint64_t spa_load_guid(spa_t
*spa
);
1033 extern uint64_t spa_last_synced_txg(spa_t
*spa
);
1034 extern uint64_t spa_first_txg(spa_t
*spa
);
1035 extern uint64_t spa_syncing_txg(spa_t
*spa
);
1036 extern uint64_t spa_final_dirty_txg(spa_t
*spa
);
1037 extern uint64_t spa_version(spa_t
*spa
);
1038 extern pool_state_t
spa_state(spa_t
*spa
);
1039 extern spa_load_state_t
spa_load_state(spa_t
*spa
);
1040 extern uint64_t spa_freeze_txg(spa_t
*spa
);
1041 extern uint64_t spa_get_worst_case_asize(spa_t
*spa
, uint64_t lsize
);
1042 extern uint64_t spa_get_dspace(spa_t
*spa
);
1043 extern uint64_t spa_get_checkpoint_space(spa_t
*spa
);
1044 extern uint64_t spa_get_slop_space(spa_t
*spa
);
1045 extern void spa_update_dspace(spa_t
*spa
);
1046 extern uint64_t spa_version(spa_t
*spa
);
1047 extern boolean_t
spa_deflate(spa_t
*spa
);
1048 extern metaslab_class_t
*spa_normal_class(spa_t
*spa
);
1049 extern metaslab_class_t
*spa_log_class(spa_t
*spa
);
1050 extern metaslab_class_t
*spa_special_class(spa_t
*spa
);
1051 extern metaslab_class_t
*spa_dedup_class(spa_t
*spa
);
1052 extern metaslab_class_t
*spa_preferred_class(spa_t
*spa
, uint64_t size
,
1053 dmu_object_type_t objtype
, uint_t level
, uint_t special_smallblk
);
1055 extern void spa_evicting_os_register(spa_t
*, objset_t
*os
);
1056 extern void spa_evicting_os_deregister(spa_t
*, objset_t
*os
);
1057 extern void spa_evicting_os_wait(spa_t
*spa
);
1058 extern int spa_max_replication(spa_t
*spa
);
1059 extern int spa_prev_software_version(spa_t
*spa
);
1060 extern uint64_t spa_get_failmode(spa_t
*spa
);
1061 extern uint64_t spa_get_deadman_failmode(spa_t
*spa
);
1062 extern void spa_set_deadman_failmode(spa_t
*spa
, const char *failmode
);
1063 extern boolean_t
spa_suspended(spa_t
*spa
);
1064 extern uint64_t spa_bootfs(spa_t
*spa
);
1065 extern uint64_t spa_delegation(spa_t
*spa
);
1066 extern objset_t
*spa_meta_objset(spa_t
*spa
);
1067 extern space_map_t
*spa_syncing_log_sm(spa_t
*spa
);
1068 extern uint64_t spa_deadman_synctime(spa_t
*spa
);
1069 extern uint64_t spa_deadman_ziotime(spa_t
*spa
);
1070 extern uint64_t spa_dirty_data(spa_t
*spa
);
1071 extern spa_autotrim_t
spa_get_autotrim(spa_t
*spa
);
1073 /* Miscellaneous support routines */
1074 extern void spa_load_failed(spa_t
*spa
, const char *fmt
, ...);
1075 extern void spa_load_note(spa_t
*spa
, const char *fmt
, ...);
1076 extern void spa_activate_mos_feature(spa_t
*spa
, const char *feature
,
1078 extern void spa_deactivate_mos_feature(spa_t
*spa
, const char *feature
);
1079 extern spa_t
*spa_by_guid(uint64_t pool_guid
, uint64_t device_guid
);
1080 extern boolean_t
spa_guid_exists(uint64_t pool_guid
, uint64_t device_guid
);
1081 extern char *spa_strdup(const char *);
1082 extern void spa_strfree(char *);
1083 extern uint64_t spa_get_random(uint64_t range
);
1084 extern uint64_t spa_generate_guid(spa_t
*spa
);
1085 extern void snprintf_blkptr(char *buf
, size_t buflen
, const blkptr_t
*bp
);
1086 extern void spa_freeze(spa_t
*spa
);
1087 extern int spa_change_guid(spa_t
*spa
);
1088 extern void spa_upgrade(spa_t
*spa
, uint64_t version
);
1089 extern void spa_evict_all(void);
1090 extern vdev_t
*spa_lookup_by_guid(spa_t
*spa
, uint64_t guid
,
1092 extern boolean_t
spa_has_spare(spa_t
*, uint64_t guid
);
1093 extern uint64_t dva_get_dsize_sync(spa_t
*spa
, const dva_t
*dva
);
1094 extern uint64_t bp_get_dsize_sync(spa_t
*spa
, const blkptr_t
*bp
);
1095 extern uint64_t bp_get_dsize(spa_t
*spa
, const blkptr_t
*bp
);
1096 extern boolean_t
spa_has_slogs(spa_t
*spa
);
1097 extern boolean_t
spa_is_root(spa_t
*spa
);
1098 extern boolean_t
spa_writeable(spa_t
*spa
);
1099 extern boolean_t
spa_has_pending_synctask(spa_t
*spa
);
1100 extern int spa_maxblocksize(spa_t
*spa
);
1101 extern int spa_maxdnodesize(spa_t
*spa
);
1102 extern boolean_t
spa_has_checkpoint(spa_t
*spa
);
1103 extern boolean_t
spa_importing_readonly_checkpoint(spa_t
*spa
);
1104 extern boolean_t
spa_suspend_async_destroy(spa_t
*spa
);
1105 extern uint64_t spa_min_claim_txg(spa_t
*spa
);
1106 extern boolean_t
zfs_dva_valid(spa_t
*spa
, const dva_t
*dva
,
1107 const blkptr_t
*bp
);
1108 typedef void (*spa_remap_cb_t
)(uint64_t vdev
, uint64_t offset
, uint64_t size
,
1110 extern boolean_t
spa_remap_blkptr(spa_t
*spa
, blkptr_t
*bp
,
1111 spa_remap_cb_t callback
, void *arg
);
1112 extern uint64_t spa_get_last_removal_txg(spa_t
*spa
);
1113 extern boolean_t
spa_trust_config(spa_t
*spa
);
1114 extern uint64_t spa_missing_tvds_allowed(spa_t
*spa
);
1115 extern void spa_set_missing_tvds(spa_t
*spa
, uint64_t missing
);
1116 extern boolean_t
spa_top_vdevs_spacemap_addressable(spa_t
*spa
);
1117 extern uint64_t spa_total_metaslabs(spa_t
*spa
);
1118 extern boolean_t
spa_multihost(spa_t
*spa
);
1119 extern uint32_t spa_get_hostid(spa_t
*spa
);
1120 extern void spa_activate_allocation_classes(spa_t
*, dmu_tx_t
*);
1121 extern boolean_t
spa_livelist_delete_check(spa_t
*spa
);
1123 extern spa_mode_t
spa_mode(spa_t
*spa
);
1124 extern uint64_t zfs_strtonum(const char *str
, char **nptr
);
1126 extern char *spa_his_ievent_table
[];
1128 extern void spa_history_create_obj(spa_t
*spa
, dmu_tx_t
*tx
);
1129 extern int spa_history_get(spa_t
*spa
, uint64_t *offset
, uint64_t *len_read
,
1131 extern int spa_history_log(spa_t
*spa
, const char *his_buf
);
1132 extern int spa_history_log_nvl(spa_t
*spa
, nvlist_t
*nvl
);
1133 extern void spa_history_log_version(spa_t
*spa
, const char *operation
,
1135 extern void spa_history_log_internal(spa_t
*spa
, const char *operation
,
1136 dmu_tx_t
*tx
, const char *fmt
, ...) __printflike(4, 5);
1137 extern void spa_history_log_internal_ds(struct dsl_dataset
*ds
, const char *op
,
1138 dmu_tx_t
*tx
, const char *fmt
, ...) __printflike(4, 5);
1139 extern void spa_history_log_internal_dd(dsl_dir_t
*dd
, const char *operation
,
1140 dmu_tx_t
*tx
, const char *fmt
, ...) __printflike(4, 5);
1142 extern const char *spa_state_to_name(spa_t
*spa
);
1144 /* error handling */
1145 struct zbookmark_phys
;
1146 extern void spa_log_error(spa_t
*spa
, const zbookmark_phys_t
*zb
);
1147 extern int zfs_ereport_post(const char *clazz
, spa_t
*spa
, vdev_t
*vd
,
1148 const zbookmark_phys_t
*zb
, zio_t
*zio
, uint64_t state
);
1149 extern boolean_t
zfs_ereport_is_valid(const char *clazz
, spa_t
*spa
, vdev_t
*vd
,
1151 extern void zfs_ereport_taskq_fini(void);
1152 extern nvlist_t
*zfs_event_create(spa_t
*spa
, vdev_t
*vd
, const char *type
,
1153 const char *name
, nvlist_t
*aux
);
1154 extern void zfs_post_remove(spa_t
*spa
, vdev_t
*vd
);
1155 extern void zfs_post_state_change(spa_t
*spa
, vdev_t
*vd
, uint64_t laststate
);
1156 extern void zfs_post_autoreplace(spa_t
*spa
, vdev_t
*vd
);
1157 extern uint64_t spa_get_errlog_size(spa_t
*spa
);
1158 extern int spa_get_errlog(spa_t
*spa
, void *uaddr
, size_t *count
);
1159 extern void spa_errlog_rotate(spa_t
*spa
);
1160 extern void spa_errlog_drain(spa_t
*spa
);
1161 extern void spa_errlog_sync(spa_t
*spa
, uint64_t txg
);
1162 extern void spa_get_errlists(spa_t
*spa
, avl_tree_t
*last
, avl_tree_t
*scrub
);
1165 extern void vdev_cache_stat_init(void);
1166 extern void vdev_cache_stat_fini(void);
1169 extern void vdev_mirror_stat_init(void);
1170 extern void vdev_mirror_stat_fini(void);
1172 /* Initialization and termination */
1173 extern void spa_init(spa_mode_t mode
);
1174 extern void spa_fini(void);
1175 extern void spa_boot_init(void);
1178 extern int spa_prop_set(spa_t
*spa
, nvlist_t
*nvp
);
1179 extern int spa_prop_get(spa_t
*spa
, nvlist_t
**nvp
);
1180 extern void spa_prop_clear_bootfs(spa_t
*spa
, uint64_t obj
, dmu_tx_t
*tx
);
1181 extern void spa_configfile_set(spa_t
*, nvlist_t
*, boolean_t
);
1183 /* asynchronous event notification */
1184 extern void spa_event_notify(spa_t
*spa
, vdev_t
*vdev
, nvlist_t
*hist_nvl
,
1187 /* waiting for pool activities to complete */
1188 extern int spa_wait(const char *pool
, zpool_wait_activity_t activity
,
1190 extern int spa_wait_tag(const char *name
, zpool_wait_activity_t activity
,
1191 uint64_t tag
, boolean_t
*waited
);
1192 extern void spa_notify_waiters(spa_t
*spa
);
1193 extern void spa_wake_waiters(spa_t
*spa
);
1195 /* module param call functions */
1196 int param_set_deadman_ziotime(ZFS_MODULE_PARAM_ARGS
);
1197 int param_set_deadman_synctime(ZFS_MODULE_PARAM_ARGS
);
1198 int param_set_slop_shift(ZFS_MODULE_PARAM_ARGS
);
1199 int param_set_deadman_failmode(ZFS_MODULE_PARAM_ARGS
);
1202 #define dprintf_bp(bp, fmt, ...) do { \
1203 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
1204 char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP); \
1205 snprintf_blkptr(__blkbuf, BP_SPRINTF_LEN, (bp)); \
1206 dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf); \
1207 kmem_free(__blkbuf, BP_SPRINTF_LEN); \
1209 _NOTE(CONSTCOND) } while (0)
1211 #define dprintf_bp(bp, fmt, ...)
1214 extern spa_mode_t spa_mode_global
;
1215 extern int zfs_deadman_enabled
;
1216 extern unsigned long zfs_deadman_synctime_ms
;
1217 extern unsigned long zfs_deadman_ziotime_ms
;
1218 extern unsigned long zfs_deadman_checktime_ms
;
1224 #endif /* _SYS_SPA_H */