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