1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23 * Copyright (c) 2011, 2018 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 Datto Inc. 30 * Copyright (c) 2017, Intel Corporation. 31 */ 32 33 #ifndef _SYS_SPA_H 34 #define _SYS_SPA_H 35 36 #include <sys/avl.h> 37 #include <sys/zfs_context.h> 38 #include <sys/nvpair.h> 39 #include <sys/sysevent.h> 40 #include <sys/sysmacros.h> 41 #include <sys/types.h> 42 #include <sys/fs/zfs.h> 43 #include <sys/dmu.h> 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 /* 50 * Forward references that lots of things need. 51 */ 52 typedef struct spa spa_t; 53 typedef struct vdev vdev_t; 54 typedef struct metaslab metaslab_t; 55 typedef struct metaslab_group metaslab_group_t; 56 typedef struct metaslab_class metaslab_class_t; 57 typedef struct zio zio_t; 58 typedef struct zilog zilog_t; 59 typedef struct spa_aux_vdev spa_aux_vdev_t; 60 typedef struct ddt ddt_t; 61 typedef struct ddt_entry ddt_entry_t; 62 struct dsl_pool; 63 struct dsl_dataset; 64 65 /* 66 * General-purpose 32-bit and 64-bit bitfield encodings. 67 */ 68 #define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len)) 69 #define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len)) 70 #define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low)) 71 #define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low)) 72 73 #define BF32_GET(x, low, len) BF32_DECODE(x, low, len) 74 #define BF64_GET(x, low, len) BF64_DECODE(x, low, len) 75 76 #define BF32_SET(x, low, len, val) do { \ 77 ASSERT3U(val, <, 1U << (len)); \ 78 ASSERT3U(low + len, <=, 32); \ 79 (x) ^= BF32_ENCODE((x >> low) ^ (val), low, len); \ 80 _NOTE(CONSTCOND) } while (0) 81 82 #define BF64_SET(x, low, len, val) do { \ 83 ASSERT3U(val, <, 1ULL << (len)); \ 84 ASSERT3U(low + len, <=, 64); \ 85 ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len)); \ 86 _NOTE(CONSTCOND) } while (0) 87 88 #define BF32_GET_SB(x, low, len, shift, bias) \ 89 ((BF32_GET(x, low, len) + (bias)) << (shift)) 90 #define BF64_GET_SB(x, low, len, shift, bias) \ 91 ((BF64_GET(x, low, len) + (bias)) << (shift)) 92 93 #define BF32_SET_SB(x, low, len, shift, bias, val) do { \ 94 ASSERT(IS_P2ALIGNED(val, 1U << shift)); \ 95 ASSERT3S((val) >> (shift), >=, bias); \ 96 BF32_SET(x, low, len, ((val) >> (shift)) - (bias)); \ 97 _NOTE(CONSTCOND) } while (0) 98 #define BF64_SET_SB(x, low, len, shift, bias, val) do { \ 99 ASSERT(IS_P2ALIGNED(val, 1ULL << shift)); \ 100 ASSERT3S((val) >> (shift), >=, bias); \ 101 BF64_SET(x, low, len, ((val) >> (shift)) - (bias)); \ 102 _NOTE(CONSTCOND) } while (0) 103 104 /* 105 * We currently support block sizes from 512 bytes to 16MB. 106 * The benefits of larger blocks, and thus larger IO, need to be weighed 107 * against the cost of COWing a giant block to modify one byte, and the 108 * large latency of reading or writing a large block. 109 * 110 * Note that although blocks up to 16MB are supported, the recordsize 111 * property can not be set larger than zfs_max_recordsize (default 1MB). 112 * See the comment near zfs_max_recordsize in dsl_dataset.c for details. 113 * 114 * Note that although the LSIZE field of the blkptr_t can store sizes up 115 * to 32MB, the dnode's dn_datablkszsec can only store sizes up to 116 * 32MB - 512 bytes. Therefore, we limit SPA_MAXBLOCKSIZE to 16MB. 117 */ 118 #define SPA_MINBLOCKSHIFT 9 119 #define SPA_OLD_MAXBLOCKSHIFT 17 120 #define SPA_MAXBLOCKSHIFT 24 121 #define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT) 122 #define SPA_OLD_MAXBLOCKSIZE (1ULL << SPA_OLD_MAXBLOCKSHIFT) 123 #define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT) 124 125 /* 126 * Size of block to hold the configuration data (a packed nvlist) 127 */ 128 #define SPA_CONFIG_BLOCKSIZE (1ULL << 14) 129 130 /* 131 * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB. 132 * The ASIZE encoding should be at least 64 times larger (6 more bits) 133 * to support up to 4-way RAID-Z mirror mode with worst-case gang block 134 * overhead, three DVAs per bp, plus one more bit in case we do anything 135 * else that expands the ASIZE. 136 */ 137 #define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */ 138 #define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */ 139 #define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */ 140 141 #define SPA_COMPRESSBITS 7 142 #define SPA_VDEVBITS 24 143 144 /* 145 * All SPA data is represented by 128-bit data virtual addresses (DVAs). 146 * The members of the dva_t should be considered opaque outside the SPA. 147 */ 148 typedef struct dva { 149 uint64_t dva_word[2]; 150 } dva_t; 151 152 /* 153 * Each block has a 256-bit checksum -- strong enough for cryptographic hashes. 154 */ 155 typedef struct zio_cksum { 156 uint64_t zc_word[4]; 157 } zio_cksum_t; 158 159 /* 160 * Some checksums/hashes need a 256-bit initialization salt. This salt is kept 161 * secret and is suitable for use in MAC algorithms as the key. 162 */ 163 typedef struct zio_cksum_salt { 164 uint8_t zcs_bytes[32]; 165 } zio_cksum_salt_t; 166 167 /* 168 * Each block is described by its DVAs, time of birth, checksum, etc. 169 * The word-by-word, bit-by-bit layout of the blkptr is as follows: 170 * 171 * 64 56 48 40 32 24 16 8 0 172 * +-------+-------+-------+-------+-------+-------+-------+-------+ 173 * 0 | pad | vdev1 | GRID | ASIZE | 174 * +-------+-------+-------+-------+-------+-------+-------+-------+ 175 * 1 |G| offset1 | 176 * +-------+-------+-------+-------+-------+-------+-------+-------+ 177 * 2 | pad | vdev2 | GRID | ASIZE | 178 * +-------+-------+-------+-------+-------+-------+-------+-------+ 179 * 3 |G| offset2 | 180 * +-------+-------+-------+-------+-------+-------+-------+-------+ 181 * 4 | pad | vdev3 | GRID | ASIZE | 182 * +-------+-------+-------+-------+-------+-------+-------+-------+ 183 * 5 |G| offset3 | 184 * +-------+-------+-------+-------+-------+-------+-------+-------+ 185 * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE | 186 * +-------+-------+-------+-------+-------+-------+-------+-------+ 187 * 7 | padding | 188 * +-------+-------+-------+-------+-------+-------+-------+-------+ 189 * 8 | padding | 190 * +-------+-------+-------+-------+-------+-------+-------+-------+ 191 * 9 | physical birth txg | 192 * +-------+-------+-------+-------+-------+-------+-------+-------+ 193 * a | logical birth txg | 194 * +-------+-------+-------+-------+-------+-------+-------+-------+ 195 * b | fill count | 196 * +-------+-------+-------+-------+-------+-------+-------+-------+ 197 * c | checksum[0] | 198 * +-------+-------+-------+-------+-------+-------+-------+-------+ 199 * d | checksum[1] | 200 * +-------+-------+-------+-------+-------+-------+-------+-------+ 201 * e | checksum[2] | 202 * +-------+-------+-------+-------+-------+-------+-------+-------+ 203 * f | checksum[3] | 204 * +-------+-------+-------+-------+-------+-------+-------+-------+ 205 * 206 * Legend: 207 * 208 * vdev virtual device ID 209 * offset offset into virtual device 210 * LSIZE logical size 211 * PSIZE physical size (after compression) 212 * ASIZE allocated size (including RAID-Z parity and gang block headers) 213 * GRID RAID-Z layout information (reserved for future use) 214 * cksum checksum function 215 * comp compression function 216 * G gang block indicator 217 * B byteorder (endianness) 218 * D dedup 219 * X encryption (on version 30, which is not supported) 220 * E blkptr_t contains embedded data (see below) 221 * lvl level of indirection 222 * type DMU object type 223 * phys birth txg when dva[0] was written; zero if same as logical birth txg 224 * note that typically all the dva's would be written in this 225 * txg, but they could be different if they were moved by 226 * device removal. 227 * log. birth transaction group in which the block was logically born 228 * fill count number of non-zero blocks under this bp 229 * checksum[4] 256-bit checksum of the data this bp describes 230 */ 231 232 /* 233 * "Embedded" blkptr_t's don't actually point to a block, instead they 234 * have a data payload embedded in the blkptr_t itself. See the comment 235 * in blkptr.c for more details. 236 * 237 * The blkptr_t is laid out as follows: 238 * 239 * 64 56 48 40 32 24 16 8 0 240 * +-------+-------+-------+-------+-------+-------+-------+-------+ 241 * 0 | payload | 242 * 1 | payload | 243 * 2 | payload | 244 * 3 | payload | 245 * 4 | payload | 246 * 5 | payload | 247 * +-------+-------+-------+-------+-------+-------+-------+-------+ 248 * 6 |BDX|lvl| type | etype |E| comp| PSIZE| LSIZE | 249 * +-------+-------+-------+-------+-------+-------+-------+-------+ 250 * 7 | payload | 251 * 8 | payload | 252 * 9 | payload | 253 * +-------+-------+-------+-------+-------+-------+-------+-------+ 254 * a | logical birth txg | 255 * +-------+-------+-------+-------+-------+-------+-------+-------+ 256 * b | payload | 257 * c | payload | 258 * d | payload | 259 * e | payload | 260 * f | payload | 261 * +-------+-------+-------+-------+-------+-------+-------+-------+ 262 * 263 * Legend: 264 * 265 * payload contains the embedded data 266 * B (byteorder) byteorder (endianness) 267 * D (dedup) padding (set to zero) 268 * X encryption (set to zero; see above) 269 * E (embedded) set to one 270 * lvl indirection level 271 * type DMU object type 272 * etype how to interpret embedded data (BP_EMBEDDED_TYPE_*) 273 * comp compression function of payload 274 * PSIZE size of payload after compression, in bytes 275 * LSIZE logical size of payload, in bytes 276 * note that 25 bits is enough to store the largest 277 * "normal" BP's LSIZE (2^16 * 2^9) in bytes 278 * log. birth transaction group in which the block was logically born 279 * 280 * Note that LSIZE and PSIZE are stored in bytes, whereas for non-embedded 281 * bp's they are stored in units of SPA_MINBLOCKSHIFT. 282 * Generally, the generic BP_GET_*() macros can be used on embedded BP's. 283 * The B, D, X, lvl, type, and comp fields are stored the same as with normal 284 * BP's so the BP_SET_* macros can be used with them. etype, PSIZE, LSIZE must 285 * be set with the BPE_SET_* macros. BP_SET_EMBEDDED() should be called before 286 * other macros, as they assert that they are only used on BP's of the correct 287 * "embedded-ness". 288 */ 289 290 #define BPE_GET_ETYPE(bp) \ 291 (ASSERT(BP_IS_EMBEDDED(bp)), \ 292 BF64_GET((bp)->blk_prop, 40, 8)) 293 #define BPE_SET_ETYPE(bp, t) do { \ 294 ASSERT(BP_IS_EMBEDDED(bp)); \ 295 BF64_SET((bp)->blk_prop, 40, 8, t); \ 296 _NOTE(CONSTCOND) } while (0) 297 298 #define BPE_GET_LSIZE(bp) \ 299 (ASSERT(BP_IS_EMBEDDED(bp)), \ 300 BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1)) 301 #define BPE_SET_LSIZE(bp, x) do { \ 302 ASSERT(BP_IS_EMBEDDED(bp)); \ 303 BF64_SET_SB((bp)->blk_prop, 0, 25, 0, 1, x); \ 304 _NOTE(CONSTCOND) } while (0) 305 306 #define BPE_GET_PSIZE(bp) \ 307 (ASSERT(BP_IS_EMBEDDED(bp)), \ 308 BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1)) 309 #define BPE_SET_PSIZE(bp, x) do { \ 310 ASSERT(BP_IS_EMBEDDED(bp)); \ 311 BF64_SET_SB((bp)->blk_prop, 25, 7, 0, 1, x); \ 312 _NOTE(CONSTCOND) } while (0) 313 314 typedef enum bp_embedded_type { 315 BP_EMBEDDED_TYPE_DATA, 316 BP_EMBEDDED_TYPE_RESERVED, /* Reserved for an unintegrated feature. */ 317 NUM_BP_EMBEDDED_TYPES = BP_EMBEDDED_TYPE_RESERVED 318 } bp_embedded_type_t; 319 320 #define BPE_NUM_WORDS 14 321 #define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t)) 322 #define BPE_IS_PAYLOADWORD(bp, wp) \ 323 ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth) 324 325 #define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */ 326 #define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */ 327 #define SPA_SYNC_MIN_VDEVS 3 /* min vdevs to update during sync */ 328 329 /* 330 * A block is a hole when it has either 1) never been written to, or 331 * 2) is zero-filled. In both cases, ZFS can return all zeroes for all reads 332 * without physically allocating disk space. Holes are represented in the 333 * blkptr_t structure by zeroed blk_dva. Correct checking for holes is 334 * done through the BP_IS_HOLE macro. For holes, the logical size, level, 335 * DMU object type, and birth times are all also stored for holes that 336 * were written to at some point (i.e. were punched after having been filled). 337 */ 338 typedef struct blkptr { 339 dva_t blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */ 340 uint64_t blk_prop; /* size, compression, type, etc */ 341 uint64_t blk_pad[2]; /* Extra space for the future */ 342 uint64_t blk_phys_birth; /* txg when block was allocated */ 343 uint64_t blk_birth; /* transaction group at birth */ 344 uint64_t blk_fill; /* fill count */ 345 zio_cksum_t blk_cksum; /* 256-bit checksum */ 346 } blkptr_t; 347 348 /* 349 * Macros to get and set fields in a bp or DVA. 350 */ 351 #define DVA_GET_ASIZE(dva) \ 352 BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0) 353 #define DVA_SET_ASIZE(dva, x) \ 354 BF64_SET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, \ 355 SPA_MINBLOCKSHIFT, 0, x) 356 357 #define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8) 358 #define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x) 359 360 #define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, SPA_VDEVBITS) 361 #define DVA_SET_VDEV(dva, x) \ 362 BF64_SET((dva)->dva_word[0], 32, SPA_VDEVBITS, x) 363 364 #define DVA_GET_OFFSET(dva) \ 365 BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0) 366 #define DVA_SET_OFFSET(dva, x) \ 367 BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x) 368 369 #define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1) 370 #define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x) 371 372 #define BP_GET_LSIZE(bp) \ 373 (BP_IS_EMBEDDED(bp) ? \ 374 (BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA ? BPE_GET_LSIZE(bp) : 0): \ 375 BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1)) 376 #define BP_SET_LSIZE(bp, x) do { \ 377 ASSERT(!BP_IS_EMBEDDED(bp)); \ 378 BF64_SET_SB((bp)->blk_prop, \ 379 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \ 380 _NOTE(CONSTCOND) } while (0) 381 382 #define BP_GET_PSIZE(bp) \ 383 (BP_IS_EMBEDDED(bp) ? 0 : \ 384 BF64_GET_SB((bp)->blk_prop, 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1)) 385 #define BP_SET_PSIZE(bp, x) do { \ 386 ASSERT(!BP_IS_EMBEDDED(bp)); \ 387 BF64_SET_SB((bp)->blk_prop, \ 388 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \ 389 _NOTE(CONSTCOND) } while (0) 390 391 #define BP_GET_COMPRESS(bp) \ 392 BF64_GET((bp)->blk_prop, 32, SPA_COMPRESSBITS) 393 #define BP_SET_COMPRESS(bp, x) \ 394 BF64_SET((bp)->blk_prop, 32, SPA_COMPRESSBITS, x) 395 396 #define BP_IS_EMBEDDED(bp) BF64_GET((bp)->blk_prop, 39, 1) 397 #define BP_SET_EMBEDDED(bp, x) BF64_SET((bp)->blk_prop, 39, 1, x) 398 399 #define BP_GET_CHECKSUM(bp) \ 400 (BP_IS_EMBEDDED(bp) ? ZIO_CHECKSUM_OFF : \ 401 BF64_GET((bp)->blk_prop, 40, 8)) 402 #define BP_SET_CHECKSUM(bp, x) do { \ 403 ASSERT(!BP_IS_EMBEDDED(bp)); \ 404 BF64_SET((bp)->blk_prop, 40, 8, x); \ 405 _NOTE(CONSTCOND) } while (0) 406 407 #define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8) 408 #define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x) 409 410 #define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5) 411 #define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x) 412 413 #define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1) 414 #define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x) 415 416 #define BP_GET_BYTEORDER(bp) BF64_GET((bp)->blk_prop, 63, 1) 417 #define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x) 418 419 #define BP_PHYSICAL_BIRTH(bp) \ 420 (BP_IS_EMBEDDED(bp) ? 0 : \ 421 (bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth) 422 423 #define BP_SET_BIRTH(bp, logical, physical) \ 424 { \ 425 ASSERT(!BP_IS_EMBEDDED(bp)); \ 426 (bp)->blk_birth = (logical); \ 427 (bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \ 428 } 429 430 #define BP_GET_FILL(bp) (BP_IS_EMBEDDED(bp) ? 1 : (bp)->blk_fill) 431 432 #define BP_IS_METADATA(bp) \ 433 (BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp))) 434 435 #define BP_GET_ASIZE(bp) \ 436 (BP_IS_EMBEDDED(bp) ? 0 : \ 437 DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \ 438 DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ 439 DVA_GET_ASIZE(&(bp)->blk_dva[2])) 440 441 #define BP_GET_UCSIZE(bp) \ 442 (BP_IS_METADATA(bp) ? BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp)) 443 444 #define BP_GET_NDVAS(bp) \ 445 (BP_IS_EMBEDDED(bp) ? 0 : \ 446 !!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \ 447 !!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ 448 !!DVA_GET_ASIZE(&(bp)->blk_dva[2])) 449 450 #define BP_COUNT_GANG(bp) \ 451 (BP_IS_EMBEDDED(bp) ? 0 : \ 452 (DVA_GET_GANG(&(bp)->blk_dva[0]) + \ 453 DVA_GET_GANG(&(bp)->blk_dva[1]) + \ 454 DVA_GET_GANG(&(bp)->blk_dva[2]))) 455 456 #define DVA_EQUAL(dva1, dva2) \ 457 ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \ 458 (dva1)->dva_word[0] == (dva2)->dva_word[0]) 459 460 #define BP_EQUAL(bp1, bp2) \ 461 (BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) && \ 462 (bp1)->blk_birth == (bp2)->blk_birth && \ 463 DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) && \ 464 DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) && \ 465 DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2])) 466 467 #define ZIO_CHECKSUM_EQUAL(zc1, zc2) \ 468 (0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \ 469 ((zc1).zc_word[1] - (zc2).zc_word[1]) | \ 470 ((zc1).zc_word[2] - (zc2).zc_word[2]) | \ 471 ((zc1).zc_word[3] - (zc2).zc_word[3]))) 472 473 #define ZIO_CHECKSUM_IS_ZERO(zc) \ 474 (0 == ((zc)->zc_word[0] | (zc)->zc_word[1] | \ 475 (zc)->zc_word[2] | (zc)->zc_word[3])) 476 477 #define ZIO_CHECKSUM_BSWAP(zcp) \ 478 { \ 479 (zcp)->zc_word[0] = BSWAP_64((zcp)->zc_word[0]); \ 480 (zcp)->zc_word[1] = BSWAP_64((zcp)->zc_word[1]); \ 481 (zcp)->zc_word[2] = BSWAP_64((zcp)->zc_word[2]); \ 482 (zcp)->zc_word[3] = BSWAP_64((zcp)->zc_word[3]); \ 483 } 484 485 486 #define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0) 487 488 #define ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3) \ 489 { \ 490 (zcp)->zc_word[0] = w0; \ 491 (zcp)->zc_word[1] = w1; \ 492 (zcp)->zc_word[2] = w2; \ 493 (zcp)->zc_word[3] = w3; \ 494 } 495 496 #define BP_IDENTITY(bp) (ASSERT(!BP_IS_EMBEDDED(bp)), &(bp)->blk_dva[0]) 497 #define BP_IS_GANG(bp) \ 498 (BP_IS_EMBEDDED(bp) ? B_FALSE : DVA_GET_GANG(BP_IDENTITY(bp))) 499 #define DVA_IS_EMPTY(dva) ((dva)->dva_word[0] == 0ULL && \ 500 (dva)->dva_word[1] == 0ULL) 501 #define BP_IS_HOLE(bp) \ 502 (!BP_IS_EMBEDDED(bp) && DVA_IS_EMPTY(BP_IDENTITY(bp))) 503 504 /* BP_IS_RAIDZ(bp) assumes no block compression */ 505 #define BP_IS_RAIDZ(bp) (DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \ 506 BP_GET_PSIZE(bp)) 507 508 #define BP_ZERO(bp) \ 509 { \ 510 (bp)->blk_dva[0].dva_word[0] = 0; \ 511 (bp)->blk_dva[0].dva_word[1] = 0; \ 512 (bp)->blk_dva[1].dva_word[0] = 0; \ 513 (bp)->blk_dva[1].dva_word[1] = 0; \ 514 (bp)->blk_dva[2].dva_word[0] = 0; \ 515 (bp)->blk_dva[2].dva_word[1] = 0; \ 516 (bp)->blk_prop = 0; \ 517 (bp)->blk_pad[0] = 0; \ 518 (bp)->blk_pad[1] = 0; \ 519 (bp)->blk_phys_birth = 0; \ 520 (bp)->blk_birth = 0; \ 521 (bp)->blk_fill = 0; \ 522 ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \ 523 } 524 525 #ifdef _BIG_ENDIAN 526 #define ZFS_HOST_BYTEORDER (0ULL) 527 #else 528 #define ZFS_HOST_BYTEORDER (1ULL) 529 #endif 530 531 #define BP_SHOULD_BYTESWAP(bp) (BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER) 532 533 #define BP_SPRINTF_LEN 320 534 535 /* 536 * This macro allows code sharing between zfs, libzpool, and mdb. 537 * 'func' is either snprintf() or mdb_snprintf(). 538 * 'ws' (whitespace) can be ' ' for single-line format, '\n' for multi-line. 539 */ 540 #define SNPRINTF_BLKPTR(func, ws, buf, size, bp, type, checksum, compress) \ 541 { \ 542 static const char *copyname[] = \ 543 { "zero", "single", "double", "triple" }; \ 544 int len = 0; \ 545 int copies = 0; \ 546 \ 547 if (bp == NULL) { \ 548 len += func(buf + len, size - len, "<NULL>"); \ 549 } else if (BP_IS_HOLE(bp)) { \ 550 len += func(buf + len, size - len, \ 551 "HOLE [L%llu %s] " \ 552 "size=%llxL birth=%lluL", \ 553 (u_longlong_t)BP_GET_LEVEL(bp), \ 554 type, \ 555 (u_longlong_t)BP_GET_LSIZE(bp), \ 556 (u_longlong_t)bp->blk_birth); \ 557 } else if (BP_IS_EMBEDDED(bp)) { \ 558 len = func(buf + len, size - len, \ 559 "EMBEDDED [L%llu %s] et=%u %s " \ 560 "size=%llxL/%llxP birth=%lluL", \ 561 (u_longlong_t)BP_GET_LEVEL(bp), \ 562 type, \ 563 (int)BPE_GET_ETYPE(bp), \ 564 compress, \ 565 (u_longlong_t)BPE_GET_LSIZE(bp), \ 566 (u_longlong_t)BPE_GET_PSIZE(bp), \ 567 (u_longlong_t)bp->blk_birth); \ 568 } else { \ 569 for (int d = 0; d < BP_GET_NDVAS(bp); d++) { \ 570 const dva_t *dva = &bp->blk_dva[d]; \ 571 if (DVA_IS_VALID(dva)) \ 572 copies++; \ 573 len += func(buf + len, size - len, \ 574 "DVA[%d]=<%llu:%llx:%llx>%c", d, \ 575 (u_longlong_t)DVA_GET_VDEV(dva), \ 576 (u_longlong_t)DVA_GET_OFFSET(dva), \ 577 (u_longlong_t)DVA_GET_ASIZE(dva), \ 578 ws); \ 579 } \ 580 if (BP_IS_GANG(bp) && \ 581 DVA_GET_ASIZE(&bp->blk_dva[2]) <= \ 582 DVA_GET_ASIZE(&bp->blk_dva[1]) / 2) \ 583 copies--; \ 584 len += func(buf + len, size - len, \ 585 "[L%llu %s] %s %s %s %s %s %s%c" \ 586 "size=%llxL/%llxP birth=%lluL/%lluP fill=%llu%c" \ 587 "cksum=%llx:%llx:%llx:%llx", \ 588 (u_longlong_t)BP_GET_LEVEL(bp), \ 589 type, \ 590 checksum, \ 591 compress, \ 592 BP_GET_BYTEORDER(bp) == 0 ? "BE" : "LE", \ 593 BP_IS_GANG(bp) ? "gang" : "contiguous", \ 594 BP_GET_DEDUP(bp) ? "dedup" : "unique", \ 595 copyname[copies], \ 596 ws, \ 597 (u_longlong_t)BP_GET_LSIZE(bp), \ 598 (u_longlong_t)BP_GET_PSIZE(bp), \ 599 (u_longlong_t)bp->blk_birth, \ 600 (u_longlong_t)BP_PHYSICAL_BIRTH(bp), \ 601 (u_longlong_t)BP_GET_FILL(bp), \ 602 ws, \ 603 (u_longlong_t)bp->blk_cksum.zc_word[0], \ 604 (u_longlong_t)bp->blk_cksum.zc_word[1], \ 605 (u_longlong_t)bp->blk_cksum.zc_word[2], \ 606 (u_longlong_t)bp->blk_cksum.zc_word[3]); \ 607 } \ 608 ASSERT(len < size); \ 609 } 610 611 #define BP_GET_BUFC_TYPE(bp) \ 612 (BP_IS_METADATA(bp) ? ARC_BUFC_METADATA : ARC_BUFC_DATA) 613 614 typedef enum spa_import_type { 615 SPA_IMPORT_EXISTING, 616 SPA_IMPORT_ASSEMBLE 617 } spa_import_type_t; 618 619 /* state manipulation functions */ 620 extern int spa_open(const char *pool, spa_t **, void *tag); 621 extern int spa_open_rewind(const char *pool, spa_t **, void *tag, 622 nvlist_t *policy, nvlist_t **config); 623 extern int spa_get_stats(const char *pool, nvlist_t **config, char *altroot, 624 size_t buflen); 625 extern int spa_create(const char *pool, nvlist_t *config, nvlist_t *props, 626 nvlist_t *zplprops); 627 extern int spa_import_rootpool(char *devpath, char *devid); 628 extern int spa_import(const char *pool, nvlist_t *config, nvlist_t *props, 629 uint64_t flags); 630 extern nvlist_t *spa_tryimport(nvlist_t *tryconfig); 631 extern int spa_destroy(char *pool); 632 extern int spa_checkpoint(const char *pool); 633 extern int spa_checkpoint_discard(const char *pool); 634 extern int spa_export(char *pool, nvlist_t **oldconfig, boolean_t force, 635 boolean_t hardforce); 636 extern int spa_reset(char *pool); 637 extern void spa_async_request(spa_t *spa, int flag); 638 extern void spa_async_unrequest(spa_t *spa, int flag); 639 extern void spa_async_suspend(spa_t *spa); 640 extern void spa_async_resume(spa_t *spa); 641 extern spa_t *spa_inject_addref(char *pool); 642 extern void spa_inject_delref(spa_t *spa); 643 extern void spa_scan_stat_init(spa_t *spa); 644 extern int spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps); 645 646 #define SPA_ASYNC_CONFIG_UPDATE 0x01 647 #define SPA_ASYNC_REMOVE 0x02 648 #define SPA_ASYNC_PROBE 0x04 649 #define SPA_ASYNC_RESILVER_DONE 0x08 650 #define SPA_ASYNC_RESILVER 0x10 651 #define SPA_ASYNC_AUTOEXPAND 0x20 652 #define SPA_ASYNC_REMOVE_DONE 0x40 653 #define SPA_ASYNC_REMOVE_STOP 0x80 654 #define SPA_ASYNC_INITIALIZE_RESTART 0x100 655 656 /* 657 * Controls the behavior of spa_vdev_remove(). 658 */ 659 #define SPA_REMOVE_UNSPARE 0x01 660 #define SPA_REMOVE_DONE 0x02 661 662 /* device manipulation */ 663 extern int spa_vdev_add(spa_t *spa, nvlist_t *nvroot); 664 extern int spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot, 665 int replacing); 666 extern int spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, 667 int replace_done); 668 extern int spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare); 669 extern boolean_t spa_vdev_remove_active(spa_t *spa); 670 extern int spa_vdev_initialize(spa_t *spa, uint64_t guid, uint64_t cmd_type); 671 extern int spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath); 672 extern int spa_vdev_setfru(spa_t *spa, uint64_t guid, const char *newfru); 673 extern int spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config, 674 nvlist_t *props, boolean_t exp); 675 676 /* spare state (which is global across all pools) */ 677 extern void spa_spare_add(vdev_t *vd); 678 extern void spa_spare_remove(vdev_t *vd); 679 extern boolean_t spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt); 680 extern void spa_spare_activate(vdev_t *vd); 681 682 /* L2ARC state (which is global across all pools) */ 683 extern void spa_l2cache_add(vdev_t *vd); 684 extern void spa_l2cache_remove(vdev_t *vd); 685 extern boolean_t spa_l2cache_exists(uint64_t guid, uint64_t *pool); 686 extern void spa_l2cache_activate(vdev_t *vd); 687 extern void spa_l2cache_drop(spa_t *spa); 688 689 /* scanning */ 690 extern int spa_scan(spa_t *spa, pool_scan_func_t func); 691 extern int spa_scan_stop(spa_t *spa); 692 extern int spa_scrub_pause_resume(spa_t *spa, pool_scrub_cmd_t flag); 693 694 /* spa syncing */ 695 extern void spa_sync(spa_t *spa, uint64_t txg); /* only for DMU use */ 696 extern void spa_sync_allpools(void); 697 698 /* spa namespace global mutex */ 699 extern kmutex_t spa_namespace_lock; 700 701 /* 702 * SPA configuration functions in spa_config.c 703 */ 704 705 #define SPA_CONFIG_UPDATE_POOL 0 706 #define SPA_CONFIG_UPDATE_VDEVS 1 707 708 extern void spa_write_cachefile(spa_t *, boolean_t, boolean_t); 709 extern void spa_config_load(void); 710 extern nvlist_t *spa_all_configs(uint64_t *); 711 extern void spa_config_set(spa_t *spa, nvlist_t *config); 712 extern nvlist_t *spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, 713 int getstats); 714 extern void spa_config_update(spa_t *spa, int what); 715 716 /* 717 * Miscellaneous SPA routines in spa_misc.c 718 */ 719 720 /* Namespace manipulation */ 721 extern spa_t *spa_lookup(const char *name); 722 extern spa_t *spa_add(const char *name, nvlist_t *config, const char *altroot); 723 extern void spa_remove(spa_t *spa); 724 extern spa_t *spa_next(spa_t *prev); 725 726 /* Refcount functions */ 727 extern void spa_open_ref(spa_t *spa, void *tag); 728 extern void spa_close(spa_t *spa, void *tag); 729 extern void spa_async_close(spa_t *spa, void *tag); 730 extern boolean_t spa_refcount_zero(spa_t *spa); 731 732 #define SCL_NONE 0x00 733 #define SCL_CONFIG 0x01 734 #define SCL_STATE 0x02 735 #define SCL_L2ARC 0x04 /* hack until L2ARC 2.0 */ 736 #define SCL_ALLOC 0x08 737 #define SCL_ZIO 0x10 738 #define SCL_FREE 0x20 739 #define SCL_VDEV 0x40 740 #define SCL_LOCKS 7 741 #define SCL_ALL ((1 << SCL_LOCKS) - 1) 742 #define SCL_STATE_ALL (SCL_STATE | SCL_L2ARC | SCL_ZIO) 743 744 /* Pool configuration locks */ 745 extern int spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw); 746 extern void spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw); 747 extern void spa_config_exit(spa_t *spa, int locks, void *tag); 748 extern int spa_config_held(spa_t *spa, int locks, krw_t rw); 749 750 /* Pool vdev add/remove lock */ 751 extern uint64_t spa_vdev_enter(spa_t *spa); 752 extern uint64_t spa_vdev_config_enter(spa_t *spa); 753 extern void spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg, 754 int error, char *tag); 755 extern int spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error); 756 757 /* Pool vdev state change lock */ 758 extern void spa_vdev_state_enter(spa_t *spa, int oplock); 759 extern int spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error); 760 761 /* Log state */ 762 typedef enum spa_log_state { 763 SPA_LOG_UNKNOWN = 0, /* unknown log state */ 764 SPA_LOG_MISSING, /* missing log(s) */ 765 SPA_LOG_CLEAR, /* clear the log(s) */ 766 SPA_LOG_GOOD, /* log(s) are good */ 767 } spa_log_state_t; 768 769 extern spa_log_state_t spa_get_log_state(spa_t *spa); 770 extern void spa_set_log_state(spa_t *spa, spa_log_state_t state); 771 extern int spa_reset_logs(spa_t *spa); 772 773 /* Log claim callback */ 774 extern void spa_claim_notify(zio_t *zio); 775 776 /* Accessor functions */ 777 extern boolean_t spa_shutting_down(spa_t *spa); 778 extern struct dsl_pool *spa_get_dsl(spa_t *spa); 779 extern boolean_t spa_is_initializing(spa_t *spa); 780 extern boolean_t spa_indirect_vdevs_loaded(spa_t *spa); 781 extern blkptr_t *spa_get_rootblkptr(spa_t *spa); 782 extern void spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp); 783 extern void spa_altroot(spa_t *, char *, size_t); 784 extern int spa_sync_pass(spa_t *spa); 785 extern char *spa_name(spa_t *spa); 786 extern uint64_t spa_guid(spa_t *spa); 787 extern uint64_t spa_load_guid(spa_t *spa); 788 extern uint64_t spa_last_synced_txg(spa_t *spa); 789 extern uint64_t spa_first_txg(spa_t *spa); 790 extern uint64_t spa_syncing_txg(spa_t *spa); 791 extern uint64_t spa_final_dirty_txg(spa_t *spa); 792 extern uint64_t spa_version(spa_t *spa); 793 extern pool_state_t spa_state(spa_t *spa); 794 extern spa_load_state_t spa_load_state(spa_t *spa); 795 extern uint64_t spa_freeze_txg(spa_t *spa); 796 extern uint64_t spa_get_worst_case_asize(spa_t *spa, uint64_t lsize); 797 extern uint64_t spa_get_dspace(spa_t *spa); 798 extern uint64_t spa_get_checkpoint_space(spa_t *spa); 799 extern uint64_t spa_get_slop_space(spa_t *spa); 800 extern void spa_update_dspace(spa_t *spa); 801 extern uint64_t spa_version(spa_t *spa); 802 extern boolean_t spa_deflate(spa_t *spa); 803 extern metaslab_class_t *spa_normal_class(spa_t *spa); 804 extern metaslab_class_t *spa_log_class(spa_t *spa); 805 extern metaslab_class_t *spa_special_class(spa_t *spa); 806 extern metaslab_class_t *spa_dedup_class(spa_t *spa); 807 extern metaslab_class_t *spa_preferred_class(spa_t *spa, uint64_t size, 808 dmu_object_type_t objtype, uint_t level, uint_t special_smallblk); 809 810 extern void spa_evicting_os_register(spa_t *, objset_t *os); 811 extern void spa_evicting_os_deregister(spa_t *, objset_t *os); 812 extern void spa_evicting_os_wait(spa_t *spa); 813 extern int spa_max_replication(spa_t *spa); 814 extern int spa_prev_software_version(spa_t *spa); 815 extern int spa_busy(void); 816 extern uint8_t spa_get_failmode(spa_t *spa); 817 extern boolean_t spa_suspended(spa_t *spa); 818 extern uint64_t spa_bootfs(spa_t *spa); 819 extern uint64_t spa_delegation(spa_t *spa); 820 extern objset_t *spa_meta_objset(spa_t *spa); 821 extern uint64_t spa_deadman_synctime(spa_t *spa); 822 extern uint64_t spa_dirty_data(spa_t *spa); 823 824 /* Miscellaneous support routines */ 825 extern void spa_load_failed(spa_t *spa, const char *fmt, ...); 826 extern void spa_load_note(spa_t *spa, const char *fmt, ...); 827 extern void spa_activate_mos_feature(spa_t *spa, const char *feature, 828 dmu_tx_t *tx); 829 extern void spa_deactivate_mos_feature(spa_t *spa, const char *feature); 830 extern spa_t *spa_by_guid(uint64_t pool_guid, uint64_t device_guid); 831 extern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid); 832 extern char *spa_strdup(const char *); 833 extern void spa_strfree(char *); 834 extern uint64_t spa_get_random(uint64_t range); 835 extern uint64_t spa_generate_guid(spa_t *spa); 836 extern void snprintf_blkptr(char *buf, size_t buflen, const blkptr_t *bp); 837 extern void spa_freeze(spa_t *spa); 838 extern int spa_change_guid(spa_t *spa); 839 extern void spa_upgrade(spa_t *spa, uint64_t version); 840 extern void spa_evict_all(void); 841 extern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid, 842 boolean_t l2cache); 843 extern boolean_t spa_has_spare(spa_t *, uint64_t guid); 844 extern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva); 845 extern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp); 846 extern uint64_t bp_get_dsize(spa_t *spa, const blkptr_t *bp); 847 extern boolean_t spa_has_slogs(spa_t *spa); 848 extern boolean_t spa_is_root(spa_t *spa); 849 extern boolean_t spa_writeable(spa_t *spa); 850 extern boolean_t spa_has_pending_synctask(spa_t *spa); 851 extern int spa_maxblocksize(spa_t *spa); 852 extern int spa_maxdnodesize(spa_t *spa); 853 extern boolean_t spa_multihost(spa_t *spa); 854 extern unsigned long spa_get_hostid(void); 855 extern boolean_t spa_has_checkpoint(spa_t *spa); 856 extern boolean_t spa_importing_readonly_checkpoint(spa_t *spa); 857 extern boolean_t spa_suspend_async_destroy(spa_t *spa); 858 extern uint64_t spa_min_claim_txg(spa_t *spa); 859 extern void zfs_blkptr_verify(spa_t *spa, const blkptr_t *bp); 860 extern boolean_t zfs_dva_valid(spa_t *spa, const dva_t *dva, 861 const blkptr_t *bp); 862 typedef void (*spa_remap_cb_t)(uint64_t vdev, uint64_t offset, uint64_t size, 863 void *arg); 864 extern boolean_t spa_remap_blkptr(spa_t *spa, blkptr_t *bp, 865 spa_remap_cb_t callback, void *arg); 866 extern uint64_t spa_get_last_removal_txg(spa_t *spa); 867 extern boolean_t spa_trust_config(spa_t *spa); 868 extern uint64_t spa_missing_tvds_allowed(spa_t *spa); 869 extern void spa_set_missing_tvds(spa_t *spa, uint64_t missing); 870 extern boolean_t spa_top_vdevs_spacemap_addressable(spa_t *spa); 871 extern void spa_activate_allocation_classes(spa_t *, dmu_tx_t *); 872 873 extern int spa_mode(spa_t *spa); 874 extern uint64_t zfs_strtonum(const char *str, char **nptr); 875 876 extern char *spa_his_ievent_table[]; 877 878 extern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx); 879 extern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read, 880 char *his_buf); 881 extern int spa_history_log(spa_t *spa, const char *his_buf); 882 extern int spa_history_log_nvl(spa_t *spa, nvlist_t *nvl); 883 extern void spa_history_log_version(spa_t *spa, const char *operation); 884 extern void spa_history_log_internal(spa_t *spa, const char *operation, 885 dmu_tx_t *tx, const char *fmt, ...); 886 extern void spa_history_log_internal_ds(struct dsl_dataset *ds, const char *op, 887 dmu_tx_t *tx, const char *fmt, ...); 888 extern void spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation, 889 dmu_tx_t *tx, const char *fmt, ...); 890 891 /* error handling */ 892 struct zbookmark_phys; 893 extern void spa_log_error(spa_t *spa, zio_t *zio); 894 extern void zfs_ereport_post(const char *class, spa_t *spa, vdev_t *vd, 895 zio_t *zio, uint64_t stateoroffset, uint64_t length); 896 extern void zfs_post_remove(spa_t *spa, vdev_t *vd); 897 extern void zfs_post_state_change(spa_t *spa, vdev_t *vd); 898 extern void zfs_post_autoreplace(spa_t *spa, vdev_t *vd); 899 extern uint64_t spa_get_errlog_size(spa_t *spa); 900 extern int spa_get_errlog(spa_t *spa, void *uaddr, size_t *count); 901 extern void spa_errlog_rotate(spa_t *spa); 902 extern void spa_errlog_drain(spa_t *spa); 903 extern void spa_errlog_sync(spa_t *spa, uint64_t txg); 904 extern void spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub); 905 906 /* vdev cache */ 907 extern void vdev_cache_stat_init(void); 908 extern void vdev_cache_stat_fini(void); 909 910 /* vdev mirror */ 911 extern void vdev_mirror_stat_init(void); 912 extern void vdev_mirror_stat_fini(void); 913 914 /* Initialization and termination */ 915 extern void spa_init(int flags); 916 extern void spa_fini(void); 917 extern void spa_boot_init(void); 918 919 /* properties */ 920 extern int spa_prop_set(spa_t *spa, nvlist_t *nvp); 921 extern int spa_prop_get(spa_t *spa, nvlist_t **nvp); 922 extern void spa_prop_clear_bootfs(spa_t *spa, uint64_t obj, dmu_tx_t *tx); 923 extern void spa_configfile_set(spa_t *, nvlist_t *, boolean_t); 924 925 /* asynchronous event notification */ 926 extern void spa_event_notify(spa_t *spa, vdev_t *vdev, nvlist_t *hist_nvl, 927 const char *name); 928 extern sysevent_t *spa_event_create(spa_t *spa, vdev_t *vd, nvlist_t *hist_nvl, 929 const char *name); 930 extern void spa_event_post(sysevent_t *ev); 931 extern void spa_event_discard(sysevent_t *ev); 932 933 #ifdef ZFS_DEBUG 934 #define dprintf_bp(bp, fmt, ...) do { \ 935 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ 936 char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP); \ 937 snprintf_blkptr(__blkbuf, BP_SPRINTF_LEN, (bp)); \ 938 dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf); \ 939 kmem_free(__blkbuf, BP_SPRINTF_LEN); \ 940 } \ 941 _NOTE(CONSTCOND) } while (0) 942 #else 943 #define dprintf_bp(bp, fmt, ...) 944 #endif 945 946 extern int spa_mode_global; /* mode, e.g. FREAD | FWRITE */ 947 948 #ifdef __cplusplus 949 } 950 #endif 951 952 #endif /* _SYS_SPA_H */ 953