11ba4a712SPawel Jakub Dawidek /*- 21ba4a712SPawel Jakub Dawidek * Copyright (c) 2002 McAfee, Inc. 31ba4a712SPawel Jakub Dawidek * All rights reserved. 41ba4a712SPawel Jakub Dawidek * 51ba4a712SPawel Jakub Dawidek * This software was developed for the FreeBSD Project by Marshall 61ba4a712SPawel Jakub Dawidek * Kirk McKusick and McAfee Research,, the Security Research Division of 71ba4a712SPawel Jakub Dawidek * McAfee, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as 81ba4a712SPawel Jakub Dawidek * part of the DARPA CHATS research program 91ba4a712SPawel Jakub Dawidek * 101ba4a712SPawel Jakub Dawidek * Redistribution and use in source and binary forms, with or without 111ba4a712SPawel Jakub Dawidek * modification, are permitted provided that the following conditions 121ba4a712SPawel Jakub Dawidek * are met: 131ba4a712SPawel Jakub Dawidek * 1. Redistributions of source code must retain the above copyright 141ba4a712SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer. 151ba4a712SPawel Jakub Dawidek * 2. Redistributions in binary form must reproduce the above copyright 161ba4a712SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer in the 171ba4a712SPawel Jakub Dawidek * documentation and/or other materials provided with the distribution. 181ba4a712SPawel Jakub Dawidek * 191ba4a712SPawel Jakub Dawidek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 201ba4a712SPawel Jakub Dawidek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 211ba4a712SPawel Jakub Dawidek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221ba4a712SPawel Jakub Dawidek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 231ba4a712SPawel Jakub Dawidek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241ba4a712SPawel Jakub Dawidek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251ba4a712SPawel Jakub Dawidek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 261ba4a712SPawel Jakub Dawidek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271ba4a712SPawel Jakub Dawidek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 281ba4a712SPawel Jakub Dawidek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 291ba4a712SPawel Jakub Dawidek * SUCH DAMAGE. 301ba4a712SPawel Jakub Dawidek */ 311ba4a712SPawel Jakub Dawidek /* 321ba4a712SPawel Jakub Dawidek * CDDL HEADER START 331ba4a712SPawel Jakub Dawidek * 341ba4a712SPawel Jakub Dawidek * The contents of this file are subject to the terms of the 351ba4a712SPawel Jakub Dawidek * Common Development and Distribution License (the "License"). 361ba4a712SPawel Jakub Dawidek * You may not use this file except in compliance with the License. 371ba4a712SPawel Jakub Dawidek * 381ba4a712SPawel Jakub Dawidek * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 391ba4a712SPawel Jakub Dawidek * or http://www.opensolaris.org/os/licensing. 401ba4a712SPawel Jakub Dawidek * See the License for the specific language governing permissions 411ba4a712SPawel Jakub Dawidek * and limitations under the License. 421ba4a712SPawel Jakub Dawidek * 431ba4a712SPawel Jakub Dawidek * When distributing Covered Code, include this CDDL HEADER in each 441ba4a712SPawel Jakub Dawidek * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 451ba4a712SPawel Jakub Dawidek * If applicable, add the following below this CDDL HEADER, with the 461ba4a712SPawel Jakub Dawidek * fields enclosed by brackets "[]" replaced with your own identifying 471ba4a712SPawel Jakub Dawidek * information: Portions Copyright [yyyy] [name of copyright owner] 481ba4a712SPawel Jakub Dawidek * 491ba4a712SPawel Jakub Dawidek * CDDL HEADER END 501ba4a712SPawel Jakub Dawidek */ 511ba4a712SPawel Jakub Dawidek /* 528fc25799SMartin Matuska * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 531ba4a712SPawel Jakub Dawidek * Use is subject to license terms. 541ba4a712SPawel Jakub Dawidek */ 55ef17620fSXin LI /* 56ef17620fSXin LI * Copyright 2013 by Saso Kiselkov. All rights reserved. 57ef17620fSXin LI */ 5829441ba3SXin LI /* 5929441ba3SXin LI * Copyright (c) 2013 by Delphix. All rights reserved. 6029441ba3SXin LI */ 611ba4a712SPawel Jakub Dawidek 622d9cf57eSMartin Matuska #define MAXNAMELEN 256 632d9cf57eSMartin Matuska 6429441ba3SXin LI #define _NOTE(s) 6529441ba3SXin LI 664deb8929SAllan Jude typedef enum { B_FALSE, B_TRUE } boolean_t; 674deb8929SAllan Jude 681ba4a712SPawel Jakub Dawidek /* CRC64 table */ 691ba4a712SPawel Jakub Dawidek #define ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */ 701ba4a712SPawel Jakub Dawidek 711ba4a712SPawel Jakub Dawidek /* 721ba4a712SPawel Jakub Dawidek * Macros for various sorts of alignment and rounding when the alignment 731ba4a712SPawel Jakub Dawidek * is known to be a power of 2. 741ba4a712SPawel Jakub Dawidek */ 751ba4a712SPawel Jakub Dawidek #define P2ALIGN(x, align) ((x) & -(align)) 761ba4a712SPawel Jakub Dawidek #define P2PHASE(x, align) ((x) & ((align) - 1)) 771ba4a712SPawel Jakub Dawidek #define P2NPHASE(x, align) (-(x) & ((align) - 1)) 781ba4a712SPawel Jakub Dawidek #define P2ROUNDUP(x, align) (-(-(x) & -(align))) 791ba4a712SPawel Jakub Dawidek #define P2END(x, align) (-(~(x) & -(align))) 801ba4a712SPawel Jakub Dawidek #define P2PHASEUP(x, align, phase) ((phase) - (((phase) - (x)) & -(align))) 81c43d127aSMartin Matuska #define P2BOUNDARY(off, len, align) (((off) ^ ((off) + (len) - 1)) > (align) - 1) 821ba4a712SPawel Jakub Dawidek 831ba4a712SPawel Jakub Dawidek /* 841ba4a712SPawel Jakub Dawidek * General-purpose 32-bit and 64-bit bitfield encodings. 851ba4a712SPawel Jakub Dawidek */ 861ba4a712SPawel Jakub Dawidek #define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len)) 871ba4a712SPawel Jakub Dawidek #define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len)) 881ba4a712SPawel Jakub Dawidek #define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low)) 891ba4a712SPawel Jakub Dawidek #define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low)) 901ba4a712SPawel Jakub Dawidek 911ba4a712SPawel Jakub Dawidek #define BF32_GET(x, low, len) BF32_DECODE(x, low, len) 921ba4a712SPawel Jakub Dawidek #define BF64_GET(x, low, len) BF64_DECODE(x, low, len) 931ba4a712SPawel Jakub Dawidek 941ba4a712SPawel Jakub Dawidek #define BF32_SET(x, low, len, val) \ 951ba4a712SPawel Jakub Dawidek ((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len)) 961ba4a712SPawel Jakub Dawidek #define BF64_SET(x, low, len, val) \ 971ba4a712SPawel Jakub Dawidek ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len)) 981ba4a712SPawel Jakub Dawidek 991ba4a712SPawel Jakub Dawidek #define BF32_GET_SB(x, low, len, shift, bias) \ 1001ba4a712SPawel Jakub Dawidek ((BF32_GET(x, low, len) + (bias)) << (shift)) 1011ba4a712SPawel Jakub Dawidek #define BF64_GET_SB(x, low, len, shift, bias) \ 1021ba4a712SPawel Jakub Dawidek ((BF64_GET(x, low, len) + (bias)) << (shift)) 1031ba4a712SPawel Jakub Dawidek 1041ba4a712SPawel Jakub Dawidek #define BF32_SET_SB(x, low, len, shift, bias, val) \ 1051ba4a712SPawel Jakub Dawidek BF32_SET(x, low, len, ((val) >> (shift)) - (bias)) 1061ba4a712SPawel Jakub Dawidek #define BF64_SET_SB(x, low, len, shift, bias, val) \ 1071ba4a712SPawel Jakub Dawidek BF64_SET(x, low, len, ((val) >> (shift)) - (bias)) 1081ba4a712SPawel Jakub Dawidek 1091ba4a712SPawel Jakub Dawidek /* 11010b9d77bSPawel Jakub Dawidek * Macros to reverse byte order 11110b9d77bSPawel Jakub Dawidek */ 11210b9d77bSPawel Jakub Dawidek #define BSWAP_8(x) ((x) & 0xff) 11310b9d77bSPawel Jakub Dawidek #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8)) 11410b9d77bSPawel Jakub Dawidek #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16)) 11510b9d77bSPawel Jakub Dawidek #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32)) 11610b9d77bSPawel Jakub Dawidek 1171ba4a712SPawel Jakub Dawidek #define SPA_MINBLOCKSHIFT 9 1182c55d090SToomas Soome #define SPA_OLDMAXBLOCKSHIFT 17 1192c55d090SToomas Soome #define SPA_MAXBLOCKSHIFT 24 1201ba4a712SPawel Jakub Dawidek #define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT) 1212c55d090SToomas Soome #define SPA_OLDMAXBLOCKSIZE (1ULL << SPA_OLDMAXBLOCKSHIFT) 1221ba4a712SPawel Jakub Dawidek #define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT) 1231ba4a712SPawel Jakub Dawidek 1241ba4a712SPawel Jakub Dawidek /* 1251ba4a712SPawel Jakub Dawidek * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB. 1261ba4a712SPawel Jakub Dawidek * The ASIZE encoding should be at least 64 times larger (6 more bits) 1271ba4a712SPawel Jakub Dawidek * to support up to 4-way RAID-Z mirror mode with worst-case gang block 1281ba4a712SPawel Jakub Dawidek * overhead, three DVAs per bp, plus one more bit in case we do anything 1291ba4a712SPawel Jakub Dawidek * else that expands the ASIZE. 1301ba4a712SPawel Jakub Dawidek */ 1311ba4a712SPawel Jakub Dawidek #define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */ 1321ba4a712SPawel Jakub Dawidek #define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */ 1331ba4a712SPawel Jakub Dawidek #define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */ 1341ba4a712SPawel Jakub Dawidek 1351ba4a712SPawel Jakub Dawidek /* 1361ba4a712SPawel Jakub Dawidek * All SPA data is represented by 128-bit data virtual addresses (DVAs). 1371ba4a712SPawel Jakub Dawidek * The members of the dva_t should be considered opaque outside the SPA. 1381ba4a712SPawel Jakub Dawidek */ 1391ba4a712SPawel Jakub Dawidek typedef struct dva { 1401ba4a712SPawel Jakub Dawidek uint64_t dva_word[2]; 1411ba4a712SPawel Jakub Dawidek } dva_t; 1421ba4a712SPawel Jakub Dawidek 1431ba4a712SPawel Jakub Dawidek /* 1441ba4a712SPawel Jakub Dawidek * Each block has a 256-bit checksum -- strong enough for cryptographic hashes. 1451ba4a712SPawel Jakub Dawidek */ 1461ba4a712SPawel Jakub Dawidek typedef struct zio_cksum { 1471ba4a712SPawel Jakub Dawidek uint64_t zc_word[4]; 1481ba4a712SPawel Jakub Dawidek } zio_cksum_t; 1491ba4a712SPawel Jakub Dawidek 1501ba4a712SPawel Jakub Dawidek /* 1512c55d090SToomas Soome * Some checksums/hashes need a 256-bit initialization salt. This salt is kept 1522c55d090SToomas Soome * secret and is suitable for use in MAC algorithms as the key. 1532c55d090SToomas Soome */ 1542c55d090SToomas Soome typedef struct zio_cksum_salt { 1552c55d090SToomas Soome uint8_t zcs_bytes[32]; 1562c55d090SToomas Soome } zio_cksum_salt_t; 1572c55d090SToomas Soome 1582c55d090SToomas Soome /* 1591ba4a712SPawel Jakub Dawidek * Each block is described by its DVAs, time of birth, checksum, etc. 1601ba4a712SPawel Jakub Dawidek * The word-by-word, bit-by-bit layout of the blkptr is as follows: 1611ba4a712SPawel Jakub Dawidek * 1621ba4a712SPawel Jakub Dawidek * 64 56 48 40 32 24 16 8 0 1631ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1641ba4a712SPawel Jakub Dawidek * 0 | vdev1 | GRID | ASIZE | 1651ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1661ba4a712SPawel Jakub Dawidek * 1 |G| offset1 | 1671ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1681ba4a712SPawel Jakub Dawidek * 2 | vdev2 | GRID | ASIZE | 1691ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1701ba4a712SPawel Jakub Dawidek * 3 |G| offset2 | 1711ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1721ba4a712SPawel Jakub Dawidek * 4 | vdev3 | GRID | ASIZE | 1731ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1741ba4a712SPawel Jakub Dawidek * 5 |G| offset3 | 1751ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 17629441ba3SXin LI * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE | 1771ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1781ba4a712SPawel Jakub Dawidek * 7 | padding | 1791ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1801ba4a712SPawel Jakub Dawidek * 8 | padding | 1811ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 18210b9d77bSPawel Jakub Dawidek * 9 | physical birth txg | 1831ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 18410b9d77bSPawel Jakub Dawidek * a | logical birth txg | 1851ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1861ba4a712SPawel Jakub Dawidek * b | fill count | 1871ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1881ba4a712SPawel Jakub Dawidek * c | checksum[0] | 1891ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1901ba4a712SPawel Jakub Dawidek * d | checksum[1] | 1911ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1921ba4a712SPawel Jakub Dawidek * e | checksum[2] | 1931ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1941ba4a712SPawel Jakub Dawidek * f | checksum[3] | 1951ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1961ba4a712SPawel Jakub Dawidek * 1971ba4a712SPawel Jakub Dawidek * Legend: 1981ba4a712SPawel Jakub Dawidek * 1991ba4a712SPawel Jakub Dawidek * vdev virtual device ID 2001ba4a712SPawel Jakub Dawidek * offset offset into virtual device 2011ba4a712SPawel Jakub Dawidek * LSIZE logical size 2021ba4a712SPawel Jakub Dawidek * PSIZE physical size (after compression) 2031ba4a712SPawel Jakub Dawidek * ASIZE allocated size (including RAID-Z parity and gang block headers) 2041ba4a712SPawel Jakub Dawidek * GRID RAID-Z layout information (reserved for future use) 2051ba4a712SPawel Jakub Dawidek * cksum checksum function 2061ba4a712SPawel Jakub Dawidek * comp compression function 2071ba4a712SPawel Jakub Dawidek * G gang block indicator 20810b9d77bSPawel Jakub Dawidek * B byteorder (endianness) 20910b9d77bSPawel Jakub Dawidek * D dedup 21029441ba3SXin LI * X encryption (on version 30, which is not supported) 21129441ba3SXin LI * E blkptr_t contains embedded data (see below) 2121ba4a712SPawel Jakub Dawidek * lvl level of indirection 21310b9d77bSPawel Jakub Dawidek * type DMU object type 21410b9d77bSPawel Jakub Dawidek * phys birth txg of block allocation; zero if same as logical birth txg 21510b9d77bSPawel Jakub Dawidek * log. birth transaction group in which the block was logically born 2161ba4a712SPawel Jakub Dawidek * fill count number of non-zero blocks under this bp 2171ba4a712SPawel Jakub Dawidek * checksum[4] 256-bit checksum of the data this bp describes 2181ba4a712SPawel Jakub Dawidek */ 21929441ba3SXin LI 22029441ba3SXin LI /* 22129441ba3SXin LI * "Embedded" blkptr_t's don't actually point to a block, instead they 22229441ba3SXin LI * have a data payload embedded in the blkptr_t itself. See the comment 22329441ba3SXin LI * in blkptr.c for more details. 22429441ba3SXin LI * 22529441ba3SXin LI * The blkptr_t is laid out as follows: 22629441ba3SXin LI * 22729441ba3SXin LI * 64 56 48 40 32 24 16 8 0 22829441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 22929441ba3SXin LI * 0 | payload | 23029441ba3SXin LI * 1 | payload | 23129441ba3SXin LI * 2 | payload | 23229441ba3SXin LI * 3 | payload | 23329441ba3SXin LI * 4 | payload | 23429441ba3SXin LI * 5 | payload | 23529441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 23629441ba3SXin LI * 6 |BDX|lvl| type | etype |E| comp| PSIZE| LSIZE | 23729441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 23829441ba3SXin LI * 7 | payload | 23929441ba3SXin LI * 8 | payload | 24029441ba3SXin LI * 9 | payload | 24129441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 24229441ba3SXin LI * a | logical birth txg | 24329441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 24429441ba3SXin LI * b | payload | 24529441ba3SXin LI * c | payload | 24629441ba3SXin LI * d | payload | 24729441ba3SXin LI * e | payload | 24829441ba3SXin LI * f | payload | 24929441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 25029441ba3SXin LI * 25129441ba3SXin LI * Legend: 25229441ba3SXin LI * 25329441ba3SXin LI * payload contains the embedded data 25429441ba3SXin LI * B (byteorder) byteorder (endianness) 25529441ba3SXin LI * D (dedup) padding (set to zero) 25629441ba3SXin LI * X encryption (set to zero; see above) 25729441ba3SXin LI * E (embedded) set to one 25829441ba3SXin LI * lvl indirection level 25929441ba3SXin LI * type DMU object type 26029441ba3SXin LI * etype how to interpret embedded data (BP_EMBEDDED_TYPE_*) 26129441ba3SXin LI * comp compression function of payload 26229441ba3SXin LI * PSIZE size of payload after compression, in bytes 26329441ba3SXin LI * LSIZE logical size of payload, in bytes 26429441ba3SXin LI * note that 25 bits is enough to store the largest 26529441ba3SXin LI * "normal" BP's LSIZE (2^16 * 2^9) in bytes 26629441ba3SXin LI * log. birth transaction group in which the block was logically born 26729441ba3SXin LI * 26829441ba3SXin LI * Note that LSIZE and PSIZE are stored in bytes, whereas for non-embedded 26929441ba3SXin LI * bp's they are stored in units of SPA_MINBLOCKSHIFT. 27029441ba3SXin LI * Generally, the generic BP_GET_*() macros can be used on embedded BP's. 27129441ba3SXin LI * The B, D, X, lvl, type, and comp fields are stored the same as with normal 27229441ba3SXin LI * BP's so the BP_SET_* macros can be used with them. etype, PSIZE, LSIZE must 27329441ba3SXin LI * be set with the BPE_SET_* macros. BP_SET_EMBEDDED() should be called before 27429441ba3SXin LI * other macros, as they assert that they are only used on BP's of the correct 27529441ba3SXin LI * "embedded-ness". 27629441ba3SXin LI */ 27729441ba3SXin LI 27829441ba3SXin LI #define BPE_GET_ETYPE(bp) \ 27929441ba3SXin LI (ASSERT(BP_IS_EMBEDDED(bp)), \ 28029441ba3SXin LI BF64_GET((bp)->blk_prop, 40, 8)) 28129441ba3SXin LI #define BPE_SET_ETYPE(bp, t) do { \ 28229441ba3SXin LI ASSERT(BP_IS_EMBEDDED(bp)); \ 28329441ba3SXin LI BF64_SET((bp)->blk_prop, 40, 8, t); \ 28429441ba3SXin LI _NOTE(CONSTCOND) } while (0) 28529441ba3SXin LI 28629441ba3SXin LI #define BPE_GET_LSIZE(bp) \ 28729441ba3SXin LI (ASSERT(BP_IS_EMBEDDED(bp)), \ 28829441ba3SXin LI BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1)) 28929441ba3SXin LI #define BPE_SET_LSIZE(bp, x) do { \ 29029441ba3SXin LI ASSERT(BP_IS_EMBEDDED(bp)); \ 29129441ba3SXin LI BF64_SET_SB((bp)->blk_prop, 0, 25, 0, 1, x); \ 29229441ba3SXin LI _NOTE(CONSTCOND) } while (0) 29329441ba3SXin LI 29429441ba3SXin LI #define BPE_GET_PSIZE(bp) \ 29529441ba3SXin LI (ASSERT(BP_IS_EMBEDDED(bp)), \ 29629441ba3SXin LI BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1)) 29729441ba3SXin LI #define BPE_SET_PSIZE(bp, x) do { \ 29829441ba3SXin LI ASSERT(BP_IS_EMBEDDED(bp)); \ 29929441ba3SXin LI BF64_SET_SB((bp)->blk_prop, 25, 7, 0, 1, x); \ 30029441ba3SXin LI _NOTE(CONSTCOND) } while (0) 30129441ba3SXin LI 30229441ba3SXin LI typedef enum bp_embedded_type { 30329441ba3SXin LI BP_EMBEDDED_TYPE_DATA, 30429441ba3SXin LI BP_EMBEDDED_TYPE_RESERVED, /* Reserved for an unintegrated feature. */ 30529441ba3SXin LI NUM_BP_EMBEDDED_TYPES = BP_EMBEDDED_TYPE_RESERVED 30629441ba3SXin LI } bp_embedded_type_t; 30729441ba3SXin LI 30829441ba3SXin LI #define BPE_NUM_WORDS 14 30929441ba3SXin LI #define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t)) 31029441ba3SXin LI #define BPE_IS_PAYLOADWORD(bp, wp) \ 31129441ba3SXin LI ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth) 31229441ba3SXin LI 31310b9d77bSPawel Jakub Dawidek #define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */ 31410b9d77bSPawel Jakub Dawidek #define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */ 31510b9d77bSPawel Jakub Dawidek 3161ba4a712SPawel Jakub Dawidek typedef struct blkptr { 31710b9d77bSPawel Jakub Dawidek dva_t blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */ 3181ba4a712SPawel Jakub Dawidek uint64_t blk_prop; /* size, compression, type, etc */ 31910b9d77bSPawel Jakub Dawidek uint64_t blk_pad[2]; /* Extra space for the future */ 32010b9d77bSPawel Jakub Dawidek uint64_t blk_phys_birth; /* txg when block was allocated */ 3211ba4a712SPawel Jakub Dawidek uint64_t blk_birth; /* transaction group at birth */ 3221ba4a712SPawel Jakub Dawidek uint64_t blk_fill; /* fill count */ 3231ba4a712SPawel Jakub Dawidek zio_cksum_t blk_cksum; /* 256-bit checksum */ 3241ba4a712SPawel Jakub Dawidek } blkptr_t; 3251ba4a712SPawel Jakub Dawidek 3261ba4a712SPawel Jakub Dawidek /* 3271ba4a712SPawel Jakub Dawidek * Macros to get and set fields in a bp or DVA. 3281ba4a712SPawel Jakub Dawidek */ 3291ba4a712SPawel Jakub Dawidek #define DVA_GET_ASIZE(dva) \ 330f4c8ba83SXin LI BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0) 3311ba4a712SPawel Jakub Dawidek #define DVA_SET_ASIZE(dva, x) \ 332f4c8ba83SXin LI BF64_SET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, \ 333f4c8ba83SXin LI SPA_MINBLOCKSHIFT, 0, x) 3341ba4a712SPawel Jakub Dawidek 3351ba4a712SPawel Jakub Dawidek #define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8) 3361ba4a712SPawel Jakub Dawidek #define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x) 3371ba4a712SPawel Jakub Dawidek 3381ba4a712SPawel Jakub Dawidek #define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, 32) 3391ba4a712SPawel Jakub Dawidek #define DVA_SET_VDEV(dva, x) BF64_SET((dva)->dva_word[0], 32, 32, x) 3401ba4a712SPawel Jakub Dawidek 3411ba4a712SPawel Jakub Dawidek #define DVA_GET_OFFSET(dva) \ 3421ba4a712SPawel Jakub Dawidek BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0) 3431ba4a712SPawel Jakub Dawidek #define DVA_SET_OFFSET(dva, x) \ 3441ba4a712SPawel Jakub Dawidek BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x) 3451ba4a712SPawel Jakub Dawidek 3461ba4a712SPawel Jakub Dawidek #define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1) 3471ba4a712SPawel Jakub Dawidek #define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x) 3481ba4a712SPawel Jakub Dawidek 3491ba4a712SPawel Jakub Dawidek #define BP_GET_LSIZE(bp) \ 35029441ba3SXin LI (BP_IS_EMBEDDED(bp) ? \ 35129441ba3SXin LI (BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA ? BPE_GET_LSIZE(bp) : 0): \ 352f4c8ba83SXin LI BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1)) 35329441ba3SXin LI #define BP_SET_LSIZE(bp, x) do { \ 35429441ba3SXin LI ASSERT(!BP_IS_EMBEDDED(bp)); \ 35529441ba3SXin LI BF64_SET_SB((bp)->blk_prop, \ 35629441ba3SXin LI 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \ 35729441ba3SXin LI _NOTE(CONSTCOND) } while (0) 3581ba4a712SPawel Jakub Dawidek 3591ba4a712SPawel Jakub Dawidek #define BP_GET_PSIZE(bp) \ 360f4c8ba83SXin LI BF64_GET_SB((bp)->blk_prop, 16, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1) 3611ba4a712SPawel Jakub Dawidek #define BP_SET_PSIZE(bp, x) \ 362f4c8ba83SXin LI BF64_SET_SB((bp)->blk_prop, 16, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x) 3631ba4a712SPawel Jakub Dawidek 36429441ba3SXin LI #define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 7) 36529441ba3SXin LI #define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 7, x) 3661ba4a712SPawel Jakub Dawidek 3671ba4a712SPawel Jakub Dawidek #define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8) 3681ba4a712SPawel Jakub Dawidek #define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x) 3691ba4a712SPawel Jakub Dawidek 3701ba4a712SPawel Jakub Dawidek #define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8) 3711ba4a712SPawel Jakub Dawidek #define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x) 3721ba4a712SPawel Jakub Dawidek 3731ba4a712SPawel Jakub Dawidek #define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5) 3741ba4a712SPawel Jakub Dawidek #define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x) 3751ba4a712SPawel Jakub Dawidek 37629441ba3SXin LI #define BP_IS_EMBEDDED(bp) BF64_GET((bp)->blk_prop, 39, 1) 37729441ba3SXin LI 37810b9d77bSPawel Jakub Dawidek #define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1) 37910b9d77bSPawel Jakub Dawidek #define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x) 38010b9d77bSPawel Jakub Dawidek 381f4c8ba83SXin LI #define BP_GET_BYTEORDER(bp) BF64_GET((bp)->blk_prop, 63, 1) 3821ba4a712SPawel Jakub Dawidek #define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x) 3831ba4a712SPawel Jakub Dawidek 38410b9d77bSPawel Jakub Dawidek #define BP_PHYSICAL_BIRTH(bp) \ 38510b9d77bSPawel Jakub Dawidek ((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth) 38610b9d77bSPawel Jakub Dawidek 3871ba4a712SPawel Jakub Dawidek #define BP_GET_ASIZE(bp) \ 3881ba4a712SPawel Jakub Dawidek (DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ 3891ba4a712SPawel Jakub Dawidek DVA_GET_ASIZE(&(bp)->blk_dva[2])) 3901ba4a712SPawel Jakub Dawidek 3911ba4a712SPawel Jakub Dawidek #define BP_GET_UCSIZE(bp) \ 3921ba4a712SPawel Jakub Dawidek ((BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) ? \ 3931ba4a712SPawel Jakub Dawidek BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp)); 3941ba4a712SPawel Jakub Dawidek 3951ba4a712SPawel Jakub Dawidek #define BP_GET_NDVAS(bp) \ 3961ba4a712SPawel Jakub Dawidek (!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \ 3971ba4a712SPawel Jakub Dawidek !!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ 3981ba4a712SPawel Jakub Dawidek !!DVA_GET_ASIZE(&(bp)->blk_dva[2])) 3991ba4a712SPawel Jakub Dawidek 4001ba4a712SPawel Jakub Dawidek #define DVA_EQUAL(dva1, dva2) \ 4011ba4a712SPawel Jakub Dawidek ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \ 4021ba4a712SPawel Jakub Dawidek (dva1)->dva_word[0] == (dva2)->dva_word[0]) 4031ba4a712SPawel Jakub Dawidek 4041ba4a712SPawel Jakub Dawidek #define ZIO_CHECKSUM_EQUAL(zc1, zc2) \ 4051ba4a712SPawel Jakub Dawidek (0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \ 4061ba4a712SPawel Jakub Dawidek ((zc1).zc_word[1] - (zc2).zc_word[1]) | \ 4071ba4a712SPawel Jakub Dawidek ((zc1).zc_word[2] - (zc2).zc_word[2]) | \ 4081ba4a712SPawel Jakub Dawidek ((zc1).zc_word[3] - (zc2).zc_word[3]))) 4091ba4a712SPawel Jakub Dawidek 4101ba4a712SPawel Jakub Dawidek 4111ba4a712SPawel Jakub Dawidek #define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0) 4121ba4a712SPawel Jakub Dawidek 4131ba4a712SPawel Jakub Dawidek #define ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3) \ 4141ba4a712SPawel Jakub Dawidek { \ 4151ba4a712SPawel Jakub Dawidek (zcp)->zc_word[0] = w0; \ 4161ba4a712SPawel Jakub Dawidek (zcp)->zc_word[1] = w1; \ 4171ba4a712SPawel Jakub Dawidek (zcp)->zc_word[2] = w2; \ 4181ba4a712SPawel Jakub Dawidek (zcp)->zc_word[3] = w3; \ 4191ba4a712SPawel Jakub Dawidek } 4201ba4a712SPawel Jakub Dawidek 4211ba4a712SPawel Jakub Dawidek #define BP_IDENTITY(bp) (&(bp)->blk_dva[0]) 4221ba4a712SPawel Jakub Dawidek #define BP_IS_GANG(bp) DVA_GET_GANG(BP_IDENTITY(bp)) 423f4c8ba83SXin LI #define DVA_IS_EMPTY(dva) ((dva)->dva_word[0] == 0ULL && \ 424f4c8ba83SXin LI (dva)->dva_word[1] == 0ULL) 425f4c8ba83SXin LI #define BP_IS_HOLE(bp) DVA_IS_EMPTY(BP_IDENTITY(bp)) 4261ba4a712SPawel Jakub Dawidek #define BP_IS_OLDER(bp, txg) (!BP_IS_HOLE(bp) && (bp)->blk_birth < (txg)) 4271ba4a712SPawel Jakub Dawidek 4281ba4a712SPawel Jakub Dawidek #define BP_ZERO(bp) \ 4291ba4a712SPawel Jakub Dawidek { \ 4301ba4a712SPawel Jakub Dawidek (bp)->blk_dva[0].dva_word[0] = 0; \ 4311ba4a712SPawel Jakub Dawidek (bp)->blk_dva[0].dva_word[1] = 0; \ 4321ba4a712SPawel Jakub Dawidek (bp)->blk_dva[1].dva_word[0] = 0; \ 4331ba4a712SPawel Jakub Dawidek (bp)->blk_dva[1].dva_word[1] = 0; \ 4341ba4a712SPawel Jakub Dawidek (bp)->blk_dva[2].dva_word[0] = 0; \ 4351ba4a712SPawel Jakub Dawidek (bp)->blk_dva[2].dva_word[1] = 0; \ 4361ba4a712SPawel Jakub Dawidek (bp)->blk_prop = 0; \ 4371ba4a712SPawel Jakub Dawidek (bp)->blk_pad[0] = 0; \ 4381ba4a712SPawel Jakub Dawidek (bp)->blk_pad[1] = 0; \ 43910b9d77bSPawel Jakub Dawidek (bp)->blk_phys_birth = 0; \ 4401ba4a712SPawel Jakub Dawidek (bp)->blk_birth = 0; \ 4411ba4a712SPawel Jakub Dawidek (bp)->blk_fill = 0; \ 4421ba4a712SPawel Jakub Dawidek ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \ 4431ba4a712SPawel Jakub Dawidek } 4441ba4a712SPawel Jakub Dawidek 44529441ba3SXin LI #define BPE_NUM_WORDS 14 44629441ba3SXin LI #define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t)) 44729441ba3SXin LI #define BPE_IS_PAYLOADWORD(bp, wp) \ 44829441ba3SXin LI ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth) 44929441ba3SXin LI 45010b9d77bSPawel Jakub Dawidek /* 45110b9d77bSPawel Jakub Dawidek * Embedded checksum 45210b9d77bSPawel Jakub Dawidek */ 45310b9d77bSPawel Jakub Dawidek #define ZEC_MAGIC 0x210da7ab10c7a11ULL 4541ba4a712SPawel Jakub Dawidek 45510b9d77bSPawel Jakub Dawidek typedef struct zio_eck { 45610b9d77bSPawel Jakub Dawidek uint64_t zec_magic; /* for validation, endianness */ 45710b9d77bSPawel Jakub Dawidek zio_cksum_t zec_cksum; /* 256-bit checksum */ 45810b9d77bSPawel Jakub Dawidek } zio_eck_t; 45910b9d77bSPawel Jakub Dawidek 46010b9d77bSPawel Jakub Dawidek /* 46110b9d77bSPawel Jakub Dawidek * Gang block headers are self-checksumming and contain an array 46210b9d77bSPawel Jakub Dawidek * of block pointers. 46310b9d77bSPawel Jakub Dawidek */ 46410b9d77bSPawel Jakub Dawidek #define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE 46510b9d77bSPawel Jakub Dawidek #define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \ 46610b9d77bSPawel Jakub Dawidek sizeof (zio_eck_t)) / sizeof (blkptr_t)) 46710b9d77bSPawel Jakub Dawidek #define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \ 46810b9d77bSPawel Jakub Dawidek sizeof (zio_eck_t) - \ 46910b9d77bSPawel Jakub Dawidek (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\ 47010b9d77bSPawel Jakub Dawidek sizeof (uint64_t)) 47110b9d77bSPawel Jakub Dawidek 47210b9d77bSPawel Jakub Dawidek typedef struct zio_gbh { 47310b9d77bSPawel Jakub Dawidek blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS]; 47410b9d77bSPawel Jakub Dawidek uint64_t zg_filler[SPA_GBH_FILLER]; 47510b9d77bSPawel Jakub Dawidek zio_eck_t zg_tail; 47610b9d77bSPawel Jakub Dawidek } zio_gbh_phys_t; 47710b9d77bSPawel Jakub Dawidek 47810b9d77bSPawel Jakub Dawidek #define VDEV_RAIDZ_MAXPARITY 3 4791ba4a712SPawel Jakub Dawidek 4808fc25799SMartin Matuska #define VDEV_PAD_SIZE (8 << 10) 4818fc25799SMartin Matuska /* 2 padding areas (vl_pad1 and vl_pad2) to skip */ 4828fc25799SMartin Matuska #define VDEV_SKIP_SIZE VDEV_PAD_SIZE * 2 4831ba4a712SPawel Jakub Dawidek #define VDEV_PHYS_SIZE (112 << 10) 4841ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_RING (128 << 10) 4851ba4a712SPawel Jakub Dawidek 4861ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_SHIFT(vd) \ 48710b9d77bSPawel Jakub Dawidek MAX((vd)->v_top->v_ashift, UBERBLOCK_SHIFT) 4881ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_COUNT(vd) \ 4891ba4a712SPawel Jakub Dawidek (VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(vd)) 4901ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_OFFSET(vd, n) \ 4911ba4a712SPawel Jakub Dawidek offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(vd)]) 4921ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_SIZE(vd) (1ULL << VDEV_UBERBLOCK_SHIFT(vd)) 4931ba4a712SPawel Jakub Dawidek 4941ba4a712SPawel Jakub Dawidek typedef struct vdev_phys { 49510b9d77bSPawel Jakub Dawidek char vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)]; 49610b9d77bSPawel Jakub Dawidek zio_eck_t vp_zbt; 4971ba4a712SPawel Jakub Dawidek } vdev_phys_t; 4981ba4a712SPawel Jakub Dawidek 4991ba4a712SPawel Jakub Dawidek typedef struct vdev_label { 5008fc25799SMartin Matuska char vl_pad1[VDEV_PAD_SIZE]; /* 8K */ 5018fc25799SMartin Matuska char vl_pad2[VDEV_PAD_SIZE]; /* 8K */ 5021ba4a712SPawel Jakub Dawidek vdev_phys_t vl_vdev_phys; /* 112K */ 5031ba4a712SPawel Jakub Dawidek char vl_uberblock[VDEV_UBERBLOCK_RING]; /* 128K */ 5041ba4a712SPawel Jakub Dawidek } vdev_label_t; /* 256K total */ 5051ba4a712SPawel Jakub Dawidek 5061ba4a712SPawel Jakub Dawidek /* 5071ba4a712SPawel Jakub Dawidek * vdev_dirty() flags 5081ba4a712SPawel Jakub Dawidek */ 5091ba4a712SPawel Jakub Dawidek #define VDD_METASLAB 0x01 5101ba4a712SPawel Jakub Dawidek #define VDD_DTL 0x02 5111ba4a712SPawel Jakub Dawidek 5121ba4a712SPawel Jakub Dawidek /* 5131ba4a712SPawel Jakub Dawidek * Size and offset of embedded boot loader region on each label. 5141ba4a712SPawel Jakub Dawidek * The total size of the first two labels plus the boot area is 4MB. 5151ba4a712SPawel Jakub Dawidek */ 5161ba4a712SPawel Jakub Dawidek #define VDEV_BOOT_OFFSET (2 * sizeof (vdev_label_t)) 5171ba4a712SPawel Jakub Dawidek #define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */ 5181ba4a712SPawel Jakub Dawidek 5191ba4a712SPawel Jakub Dawidek /* 5201ba4a712SPawel Jakub Dawidek * Size of label regions at the start and end of each leaf device. 5211ba4a712SPawel Jakub Dawidek */ 5221ba4a712SPawel Jakub Dawidek #define VDEV_LABEL_START_SIZE (2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE) 5231ba4a712SPawel Jakub Dawidek #define VDEV_LABEL_END_SIZE (2 * sizeof (vdev_label_t)) 5241ba4a712SPawel Jakub Dawidek #define VDEV_LABELS 4 5251ba4a712SPawel Jakub Dawidek 5261ba4a712SPawel Jakub Dawidek enum zio_checksum { 5271ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_INHERIT = 0, 5281ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_ON, 5291ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_OFF, 5301ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_LABEL, 5311ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_GANG_HEADER, 5321ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_ZILOG, 5331ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_FLETCHER_2, 5341ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_FLETCHER_4, 5351ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_SHA256, 53610b9d77bSPawel Jakub Dawidek ZIO_CHECKSUM_ZILOG2, 5372c55d090SToomas Soome ZIO_CHECKSUM_NOPARITY, 5382c55d090SToomas Soome ZIO_CHECKSUM_SHA512, 5392c55d090SToomas Soome ZIO_CHECKSUM_SKEIN, 5402c55d090SToomas Soome ZIO_CHECKSUM_EDONR, 5411ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_FUNCTIONS 5421ba4a712SPawel Jakub Dawidek }; 5431ba4a712SPawel Jakub Dawidek 54410b9d77bSPawel Jakub Dawidek #define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_4 5451ba4a712SPawel Jakub Dawidek #define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON 5461ba4a712SPawel Jakub Dawidek 5471ba4a712SPawel Jakub Dawidek enum zio_compress { 5481ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_INHERIT = 0, 5491ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_ON, 5501ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_OFF, 5511ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_LZJB, 5521ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_EMPTY, 5531ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_1, 5541ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_2, 5551ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_3, 5561ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_4, 5571ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_5, 5581ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_6, 5591ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_7, 5601ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_8, 5611ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_9, 56210b9d77bSPawel Jakub Dawidek ZIO_COMPRESS_ZLE, 563ef17620fSXin LI ZIO_COMPRESS_LZ4, 5641ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_FUNCTIONS 5651ba4a712SPawel Jakub Dawidek }; 5661ba4a712SPawel Jakub Dawidek 5671ba4a712SPawel Jakub Dawidek #define ZIO_COMPRESS_ON_VALUE ZIO_COMPRESS_LZJB 5681ba4a712SPawel Jakub Dawidek #define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF 5691ba4a712SPawel Jakub Dawidek 5701ba4a712SPawel Jakub Dawidek /* nvlist pack encoding */ 5711ba4a712SPawel Jakub Dawidek #define NV_ENCODE_NATIVE 0 5721ba4a712SPawel Jakub Dawidek #define NV_ENCODE_XDR 1 5731ba4a712SPawel Jakub Dawidek 5741ba4a712SPawel Jakub Dawidek typedef enum { 5751ba4a712SPawel Jakub Dawidek DATA_TYPE_UNKNOWN = 0, 5761ba4a712SPawel Jakub Dawidek DATA_TYPE_BOOLEAN, 5771ba4a712SPawel Jakub Dawidek DATA_TYPE_BYTE, 5781ba4a712SPawel Jakub Dawidek DATA_TYPE_INT16, 5791ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT16, 5801ba4a712SPawel Jakub Dawidek DATA_TYPE_INT32, 5811ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT32, 5821ba4a712SPawel Jakub Dawidek DATA_TYPE_INT64, 5831ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT64, 5841ba4a712SPawel Jakub Dawidek DATA_TYPE_STRING, 5851ba4a712SPawel Jakub Dawidek DATA_TYPE_BYTE_ARRAY, 5861ba4a712SPawel Jakub Dawidek DATA_TYPE_INT16_ARRAY, 5871ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT16_ARRAY, 5881ba4a712SPawel Jakub Dawidek DATA_TYPE_INT32_ARRAY, 5891ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT32_ARRAY, 5901ba4a712SPawel Jakub Dawidek DATA_TYPE_INT64_ARRAY, 5911ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT64_ARRAY, 5921ba4a712SPawel Jakub Dawidek DATA_TYPE_STRING_ARRAY, 5931ba4a712SPawel Jakub Dawidek DATA_TYPE_HRTIME, 5941ba4a712SPawel Jakub Dawidek DATA_TYPE_NVLIST, 5951ba4a712SPawel Jakub Dawidek DATA_TYPE_NVLIST_ARRAY, 5961ba4a712SPawel Jakub Dawidek DATA_TYPE_BOOLEAN_VALUE, 5971ba4a712SPawel Jakub Dawidek DATA_TYPE_INT8, 5981ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT8, 5991ba4a712SPawel Jakub Dawidek DATA_TYPE_BOOLEAN_ARRAY, 6001ba4a712SPawel Jakub Dawidek DATA_TYPE_INT8_ARRAY, 6011ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT8_ARRAY 6021ba4a712SPawel Jakub Dawidek } data_type_t; 6031ba4a712SPawel Jakub Dawidek 6041ba4a712SPawel Jakub Dawidek /* 6051ba4a712SPawel Jakub Dawidek * On-disk version number. 6061ba4a712SPawel Jakub Dawidek */ 6070d16312bSDoug Rabson #define SPA_VERSION_1 1ULL 6080d16312bSDoug Rabson #define SPA_VERSION_2 2ULL 6090d16312bSDoug Rabson #define SPA_VERSION_3 3ULL 6100d16312bSDoug Rabson #define SPA_VERSION_4 4ULL 6110d16312bSDoug Rabson #define SPA_VERSION_5 5ULL 6120d16312bSDoug Rabson #define SPA_VERSION_6 6ULL 6130d16312bSDoug Rabson #define SPA_VERSION_7 7ULL 6140d16312bSDoug Rabson #define SPA_VERSION_8 8ULL 6150d16312bSDoug Rabson #define SPA_VERSION_9 9ULL 6160d16312bSDoug Rabson #define SPA_VERSION_10 10ULL 6170d16312bSDoug Rabson #define SPA_VERSION_11 11ULL 618786895f6SDoug Rabson #define SPA_VERSION_12 12ULL 619786895f6SDoug Rabson #define SPA_VERSION_13 13ULL 62091891290SXin LI #define SPA_VERSION_14 14ULL 6218fc25799SMartin Matuska #define SPA_VERSION_15 15ULL 62210b9d77bSPawel Jakub Dawidek #define SPA_VERSION_16 16ULL 62310b9d77bSPawel Jakub Dawidek #define SPA_VERSION_17 17ULL 62410b9d77bSPawel Jakub Dawidek #define SPA_VERSION_18 18ULL 62510b9d77bSPawel Jakub Dawidek #define SPA_VERSION_19 19ULL 62610b9d77bSPawel Jakub Dawidek #define SPA_VERSION_20 20ULL 62710b9d77bSPawel Jakub Dawidek #define SPA_VERSION_21 21ULL 62810b9d77bSPawel Jakub Dawidek #define SPA_VERSION_22 22ULL 62910b9d77bSPawel Jakub Dawidek #define SPA_VERSION_23 23ULL 63010b9d77bSPawel Jakub Dawidek #define SPA_VERSION_24 24ULL 63110b9d77bSPawel Jakub Dawidek #define SPA_VERSION_25 25ULL 63210b9d77bSPawel Jakub Dawidek #define SPA_VERSION_26 26ULL 63310b9d77bSPawel Jakub Dawidek #define SPA_VERSION_27 27ULL 63410b9d77bSPawel Jakub Dawidek #define SPA_VERSION_28 28ULL 6352d9cf57eSMartin Matuska #define SPA_VERSION_5000 5000ULL 63610b9d77bSPawel Jakub Dawidek 6371ba4a712SPawel Jakub Dawidek /* 63810b9d77bSPawel Jakub Dawidek * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk 63910b9d77bSPawel Jakub Dawidek * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*}, 64010b9d77bSPawel Jakub Dawidek * and do the appropriate changes. Also bump the version number in 64110b9d77bSPawel Jakub Dawidek * usr/src/grub/capability. 6421ba4a712SPawel Jakub Dawidek */ 6432d9cf57eSMartin Matuska #define SPA_VERSION SPA_VERSION_5000 6442d9cf57eSMartin Matuska #define SPA_VERSION_STRING "5000" 6451ba4a712SPawel Jakub Dawidek 6461ba4a712SPawel Jakub Dawidek /* 6470d16312bSDoug Rabson * Symbolic names for the changes that caused a SPA_VERSION switch. 6481ba4a712SPawel Jakub Dawidek * Used in the code when checking for presence or absence of a feature. 6491ba4a712SPawel Jakub Dawidek * Feel free to define multiple symbolic names for each version if there 6501ba4a712SPawel Jakub Dawidek * were multiple changes to on-disk structures during that version. 6511ba4a712SPawel Jakub Dawidek * 6520d16312bSDoug Rabson * NOTE: When checking the current SPA_VERSION in your code, be sure 6531ba4a712SPawel Jakub Dawidek * to use spa_version() since it reports the version of the 6541ba4a712SPawel Jakub Dawidek * last synced uberblock. Checking the in-flight version can 6551ba4a712SPawel Jakub Dawidek * be dangerous in some cases. 6561ba4a712SPawel Jakub Dawidek */ 6570d16312bSDoug Rabson #define SPA_VERSION_INITIAL SPA_VERSION_1 6580d16312bSDoug Rabson #define SPA_VERSION_DITTO_BLOCKS SPA_VERSION_2 6590d16312bSDoug Rabson #define SPA_VERSION_SPARES SPA_VERSION_3 6600d16312bSDoug Rabson #define SPA_VERSION_RAID6 SPA_VERSION_3 6610d16312bSDoug Rabson #define SPA_VERSION_BPLIST_ACCOUNT SPA_VERSION_3 6620d16312bSDoug Rabson #define SPA_VERSION_RAIDZ_DEFLATE SPA_VERSION_3 6630d16312bSDoug Rabson #define SPA_VERSION_DNODE_BYTES SPA_VERSION_3 6640d16312bSDoug Rabson #define SPA_VERSION_ZPOOL_HISTORY SPA_VERSION_4 6650d16312bSDoug Rabson #define SPA_VERSION_GZIP_COMPRESSION SPA_VERSION_5 6660d16312bSDoug Rabson #define SPA_VERSION_BOOTFS SPA_VERSION_6 667786895f6SDoug Rabson #define SPA_VERSION_SLOGS SPA_VERSION_7 668786895f6SDoug Rabson #define SPA_VERSION_DELEGATED_PERMS SPA_VERSION_8 669786895f6SDoug Rabson #define SPA_VERSION_FUID SPA_VERSION_9 670786895f6SDoug Rabson #define SPA_VERSION_REFRESERVATION SPA_VERSION_9 671786895f6SDoug Rabson #define SPA_VERSION_REFQUOTA SPA_VERSION_9 672786895f6SDoug Rabson #define SPA_VERSION_UNIQUE_ACCURATE SPA_VERSION_9 673786895f6SDoug Rabson #define SPA_VERSION_L2CACHE SPA_VERSION_10 674786895f6SDoug Rabson #define SPA_VERSION_NEXT_CLONES SPA_VERSION_11 675786895f6SDoug Rabson #define SPA_VERSION_ORIGIN SPA_VERSION_11 676786895f6SDoug Rabson #define SPA_VERSION_DSL_SCRUB SPA_VERSION_11 677786895f6SDoug Rabson #define SPA_VERSION_SNAP_PROPS SPA_VERSION_12 678786895f6SDoug Rabson #define SPA_VERSION_USED_BREAKDOWN SPA_VERSION_13 67991891290SXin LI #define SPA_VERSION_PASSTHROUGH_X SPA_VERSION_14 6808fc25799SMartin Matuska #define SPA_VERSION_USERSPACE SPA_VERSION_15 68110b9d77bSPawel Jakub Dawidek #define SPA_VERSION_STMF_PROP SPA_VERSION_16 68210b9d77bSPawel Jakub Dawidek #define SPA_VERSION_RAIDZ3 SPA_VERSION_17 68310b9d77bSPawel Jakub Dawidek #define SPA_VERSION_USERREFS SPA_VERSION_18 68410b9d77bSPawel Jakub Dawidek #define SPA_VERSION_HOLES SPA_VERSION_19 68510b9d77bSPawel Jakub Dawidek #define SPA_VERSION_ZLE_COMPRESSION SPA_VERSION_20 68610b9d77bSPawel Jakub Dawidek #define SPA_VERSION_DEDUP SPA_VERSION_21 68710b9d77bSPawel Jakub Dawidek #define SPA_VERSION_RECVD_PROPS SPA_VERSION_22 68810b9d77bSPawel Jakub Dawidek #define SPA_VERSION_SLIM_ZIL SPA_VERSION_23 68910b9d77bSPawel Jakub Dawidek #define SPA_VERSION_SA SPA_VERSION_24 69010b9d77bSPawel Jakub Dawidek #define SPA_VERSION_SCAN SPA_VERSION_25 69110b9d77bSPawel Jakub Dawidek #define SPA_VERSION_DIR_CLONES SPA_VERSION_26 69210b9d77bSPawel Jakub Dawidek #define SPA_VERSION_DEADLISTS SPA_VERSION_26 69310b9d77bSPawel Jakub Dawidek #define SPA_VERSION_FAST_SNAP SPA_VERSION_27 69410b9d77bSPawel Jakub Dawidek #define SPA_VERSION_MULTI_REPLACE SPA_VERSION_28 6952d9cf57eSMartin Matuska #define SPA_VERSION_BEFORE_FEATURES SPA_VERSION_28 6962d9cf57eSMartin Matuska #define SPA_VERSION_FEATURES SPA_VERSION_5000 6972d9cf57eSMartin Matuska 6982d9cf57eSMartin Matuska #define SPA_VERSION_IS_SUPPORTED(v) \ 6992d9cf57eSMartin Matuska (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \ 7002d9cf57eSMartin Matuska ((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION)) 7011ba4a712SPawel Jakub Dawidek 7021ba4a712SPawel Jakub Dawidek /* 7031ba4a712SPawel Jakub Dawidek * The following are configuration names used in the nvlist describing a pool's 7041ba4a712SPawel Jakub Dawidek * configuration. 7051ba4a712SPawel Jakub Dawidek */ 7061ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_VERSION "version" 7071ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_NAME "name" 7081ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_STATE "state" 7091ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_TXG "txg" 7101ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_GUID "pool_guid" 7111ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_CREATE_TXG "create_txg" 7121ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_TOP_GUID "top_guid" 7131ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_VDEV_TREE "vdev_tree" 7141ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_TYPE "type" 7151ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_CHILDREN "children" 7161ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ID "id" 7171ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_GUID "guid" 718*b1b93268SToomas Soome #define ZPOOL_CONFIG_INDIRECT_OBJECT "com.delphix:indirect_object" 719*b1b93268SToomas Soome #define ZPOOL_CONFIG_INDIRECT_BIRTHS "com.delphix:indirect_births" 720*b1b93268SToomas Soome #define ZPOOL_CONFIG_PREV_INDIRECT_VDEV "com.delphix:prev_indirect_vdev" 7211ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_PATH "path" 7221ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_DEVID "devid" 7231ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array" 7241ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift" 7251ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ASHIFT "ashift" 7261ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ASIZE "asize" 7271ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_DTL "DTL" 7281ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_STATS "stats" 7291ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_WHOLE_DISK "whole_disk" 7301ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ERRCOUNT "error_count" 7311ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_NOT_PRESENT "not_present" 7321ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_SPARES "spares" 7331ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_IS_SPARE "is_spare" 7341ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_NPARITY "nparity" 7351ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_HOSTID "hostid" 7361ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_HOSTNAME "hostname" 7376a85b5e0SPawel Jakub Dawidek #define ZPOOL_CONFIG_IS_LOG "is_log" 7381ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */ 7392d9cf57eSMartin Matuska #define ZPOOL_CONFIG_FEATURES_FOR_READ "features_for_read" 7401ba4a712SPawel Jakub Dawidek 74103ec6213SXin LI /* 74203ec6213SXin LI * The persistent vdev state is stored as separate values rather than a single 74303ec6213SXin LI * 'vdev_state' entry. This is because a device can be in multiple states, such 74403ec6213SXin LI * as offline and degraded. 74503ec6213SXin LI */ 74603ec6213SXin LI #define ZPOOL_CONFIG_OFFLINE "offline" 74703ec6213SXin LI #define ZPOOL_CONFIG_FAULTED "faulted" 74803ec6213SXin LI #define ZPOOL_CONFIG_DEGRADED "degraded" 74903ec6213SXin LI #define ZPOOL_CONFIG_REMOVED "removed" 75010b9d77bSPawel Jakub Dawidek #define ZPOOL_CONFIG_FRU "fru" 75110b9d77bSPawel Jakub Dawidek #define ZPOOL_CONFIG_AUX_STATE "aux_state" 75203ec6213SXin LI 7531ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_ROOT "root" 7541ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_MIRROR "mirror" 7551ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_REPLACING "replacing" 7561ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_RAIDZ "raidz" 7571ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_DISK "disk" 7581ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_FILE "file" 7591ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_MISSING "missing" 76010b9d77bSPawel Jakub Dawidek #define VDEV_TYPE_HOLE "hole" 7611ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_SPARE "spare" 76210b9d77bSPawel Jakub Dawidek #define VDEV_TYPE_LOG "log" 76310b9d77bSPawel Jakub Dawidek #define VDEV_TYPE_L2CACHE "l2cache" 764*b1b93268SToomas Soome #define VDEV_TYPE_INDIRECT "indirect" 7651ba4a712SPawel Jakub Dawidek 7661ba4a712SPawel Jakub Dawidek /* 7671ba4a712SPawel Jakub Dawidek * This is needed in userland to report the minimum necessary device size. 7681ba4a712SPawel Jakub Dawidek */ 7691ba4a712SPawel Jakub Dawidek #define SPA_MINDEVSIZE (64ULL << 20) 7701ba4a712SPawel Jakub Dawidek 7711ba4a712SPawel Jakub Dawidek /* 7721ba4a712SPawel Jakub Dawidek * The location of the pool configuration repository, shared between kernel and 7731ba4a712SPawel Jakub Dawidek * userland. 7741ba4a712SPawel Jakub Dawidek */ 77510b9d77bSPawel Jakub Dawidek #define ZPOOL_CACHE "/boot/zfs/zpool.cache" 7761ba4a712SPawel Jakub Dawidek 7771ba4a712SPawel Jakub Dawidek /* 7781ba4a712SPawel Jakub Dawidek * vdev states are ordered from least to most healthy. 7791ba4a712SPawel Jakub Dawidek * A vdev that's CANT_OPEN or below is considered unusable. 7801ba4a712SPawel Jakub Dawidek */ 7811ba4a712SPawel Jakub Dawidek typedef enum vdev_state { 7821ba4a712SPawel Jakub Dawidek VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev */ 7831ba4a712SPawel Jakub Dawidek VDEV_STATE_CLOSED, /* Not currently open */ 7841ba4a712SPawel Jakub Dawidek VDEV_STATE_OFFLINE, /* Not allowed to open */ 78503ec6213SXin LI VDEV_STATE_REMOVED, /* Explicitly removed from system */ 7861ba4a712SPawel Jakub Dawidek VDEV_STATE_CANT_OPEN, /* Tried to open, but failed */ 78703ec6213SXin LI VDEV_STATE_FAULTED, /* External request to fault device */ 7881ba4a712SPawel Jakub Dawidek VDEV_STATE_DEGRADED, /* Replicated vdev with unhealthy kids */ 7891ba4a712SPawel Jakub Dawidek VDEV_STATE_HEALTHY /* Presumed good */ 7901ba4a712SPawel Jakub Dawidek } vdev_state_t; 7911ba4a712SPawel Jakub Dawidek 7921ba4a712SPawel Jakub Dawidek /* 7931ba4a712SPawel Jakub Dawidek * vdev aux states. When a vdev is in the CANT_OPEN state, the aux field 7941ba4a712SPawel Jakub Dawidek * of the vdev stats structure uses these constants to distinguish why. 7951ba4a712SPawel Jakub Dawidek */ 7961ba4a712SPawel Jakub Dawidek typedef enum vdev_aux { 7971ba4a712SPawel Jakub Dawidek VDEV_AUX_NONE, /* no error */ 7981ba4a712SPawel Jakub Dawidek VDEV_AUX_OPEN_FAILED, /* ldi_open_*() or vn_open() failed */ 7991ba4a712SPawel Jakub Dawidek VDEV_AUX_CORRUPT_DATA, /* bad label or disk contents */ 8001ba4a712SPawel Jakub Dawidek VDEV_AUX_NO_REPLICAS, /* insufficient number of replicas */ 8011ba4a712SPawel Jakub Dawidek VDEV_AUX_BAD_GUID_SUM, /* vdev guid sum doesn't match */ 8021ba4a712SPawel Jakub Dawidek VDEV_AUX_TOO_SMALL, /* vdev size is too small */ 8031ba4a712SPawel Jakub Dawidek VDEV_AUX_BAD_LABEL, /* the label is OK but invalid */ 8041ba4a712SPawel Jakub Dawidek VDEV_AUX_VERSION_NEWER, /* on-disk version is too new */ 8051ba4a712SPawel Jakub Dawidek VDEV_AUX_VERSION_OLDER, /* on-disk version is too old */ 8061ba4a712SPawel Jakub Dawidek VDEV_AUX_SPARED /* hot spare used in another pool */ 8071ba4a712SPawel Jakub Dawidek } vdev_aux_t; 8081ba4a712SPawel Jakub Dawidek 8091ba4a712SPawel Jakub Dawidek /* 8101ba4a712SPawel Jakub Dawidek * pool state. The following states are written to disk as part of the normal 8111ba4a712SPawel Jakub Dawidek * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE. The remaining states are 8121ba4a712SPawel Jakub Dawidek * software abstractions used at various levels to communicate pool state. 8131ba4a712SPawel Jakub Dawidek */ 8141ba4a712SPawel Jakub Dawidek typedef enum pool_state { 8151ba4a712SPawel Jakub Dawidek POOL_STATE_ACTIVE = 0, /* In active use */ 8161ba4a712SPawel Jakub Dawidek POOL_STATE_EXPORTED, /* Explicitly exported */ 8171ba4a712SPawel Jakub Dawidek POOL_STATE_DESTROYED, /* Explicitly destroyed */ 8181ba4a712SPawel Jakub Dawidek POOL_STATE_SPARE, /* Reserved for hot spare use */ 8191ba4a712SPawel Jakub Dawidek POOL_STATE_UNINITIALIZED, /* Internal spa_t state */ 8201ba4a712SPawel Jakub Dawidek POOL_STATE_UNAVAIL, /* Internal libzfs state */ 8211ba4a712SPawel Jakub Dawidek POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */ 8221ba4a712SPawel Jakub Dawidek } pool_state_t; 8231ba4a712SPawel Jakub Dawidek 8241ba4a712SPawel Jakub Dawidek /* 8251ba4a712SPawel Jakub Dawidek * The uberblock version is incremented whenever an incompatible on-disk 8261ba4a712SPawel Jakub Dawidek * format change is made to the SPA, DMU, or ZAP. 8271ba4a712SPawel Jakub Dawidek * 8281ba4a712SPawel Jakub Dawidek * Note: the first two fields should never be moved. When a storage pool 8291ba4a712SPawel Jakub Dawidek * is opened, the uberblock must be read off the disk before the version 8301ba4a712SPawel Jakub Dawidek * can be checked. If the ub_version field is moved, we may not detect 8311ba4a712SPawel Jakub Dawidek * version mismatch. If the ub_magic field is moved, applications that 8321ba4a712SPawel Jakub Dawidek * expect the magic number in the first word won't work. 8331ba4a712SPawel Jakub Dawidek */ 8341ba4a712SPawel Jakub Dawidek #define UBERBLOCK_MAGIC 0x00bab10c /* oo-ba-bloc! */ 8351ba4a712SPawel Jakub Dawidek #define UBERBLOCK_SHIFT 10 /* up to 1K */ 8361ba4a712SPawel Jakub Dawidek 8371ba4a712SPawel Jakub Dawidek struct uberblock { 8381ba4a712SPawel Jakub Dawidek uint64_t ub_magic; /* UBERBLOCK_MAGIC */ 8390d16312bSDoug Rabson uint64_t ub_version; /* SPA_VERSION */ 8401ba4a712SPawel Jakub Dawidek uint64_t ub_txg; /* txg of last sync */ 8411ba4a712SPawel Jakub Dawidek uint64_t ub_guid_sum; /* sum of all vdev guids */ 8421ba4a712SPawel Jakub Dawidek uint64_t ub_timestamp; /* UTC time of last sync */ 8431ba4a712SPawel Jakub Dawidek blkptr_t ub_rootbp; /* MOS objset_phys_t */ 8441ba4a712SPawel Jakub Dawidek }; 8451ba4a712SPawel Jakub Dawidek 8461ba4a712SPawel Jakub Dawidek /* 8471ba4a712SPawel Jakub Dawidek * Flags. 8481ba4a712SPawel Jakub Dawidek */ 8491ba4a712SPawel Jakub Dawidek #define DNODE_MUST_BE_ALLOCATED 1 8501ba4a712SPawel Jakub Dawidek #define DNODE_MUST_BE_FREE 2 8511ba4a712SPawel Jakub Dawidek 8521ba4a712SPawel Jakub Dawidek /* 8531ba4a712SPawel Jakub Dawidek * Fixed constants. 8541ba4a712SPawel Jakub Dawidek */ 8551ba4a712SPawel Jakub Dawidek #define DNODE_SHIFT 9 /* 512 bytes */ 856263f396eSXin LI #define DN_MIN_INDBLKSHIFT 12 /* 4k */ 857*b1b93268SToomas Soome #define DN_MAX_INDBLKSHIFT 17 /* 128k */ 8581ba4a712SPawel Jakub Dawidek #define DNODE_BLOCK_SHIFT 14 /* 16k */ 8591ba4a712SPawel Jakub Dawidek #define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */ 8601ba4a712SPawel Jakub Dawidek #define DN_MAX_OBJECT_SHIFT 48 /* 256 trillion (zfs_fid_t limit) */ 8611ba4a712SPawel Jakub Dawidek #define DN_MAX_OFFSET_SHIFT 64 /* 2^64 bytes in a dnode */ 8621ba4a712SPawel Jakub Dawidek 8631ba4a712SPawel Jakub Dawidek /* 8641ba4a712SPawel Jakub Dawidek * Derived constants. 8651ba4a712SPawel Jakub Dawidek */ 866b40aaca6SToomas Soome #define DNODE_MIN_SIZE (1 << DNODE_SHIFT) 867b40aaca6SToomas Soome #define DNODE_MAX_SIZE (1 << DNODE_BLOCK_SHIFT) 868b40aaca6SToomas Soome #define DNODE_BLOCK_SIZE (1 << DNODE_BLOCK_SHIFT) 869b40aaca6SToomas Soome #define DNODE_MIN_SLOTS (DNODE_MIN_SIZE >> DNODE_SHIFT) 870b40aaca6SToomas Soome #define DNODE_MAX_SLOTS (DNODE_MAX_SIZE >> DNODE_SHIFT) 871b40aaca6SToomas Soome #define DN_BONUS_SIZE(dnsize) ((dnsize) - DNODE_CORE_SIZE - \ 872b40aaca6SToomas Soome (1 << SPA_BLKPTRSHIFT)) 873b40aaca6SToomas Soome #define DN_SLOTS_TO_BONUSLEN(slots) DN_BONUS_SIZE((slots) << DNODE_SHIFT) 874b40aaca6SToomas Soome #define DN_OLD_MAX_BONUSLEN (DN_BONUS_SIZE(DNODE_MIN_SIZE)) 875b40aaca6SToomas Soome #define DN_MAX_NBLKPTR ((DNODE_MIN_SIZE - DNODE_CORE_SIZE) >> \ 876b40aaca6SToomas Soome SPA_BLKPTRSHIFT) 8771ba4a712SPawel Jakub Dawidek #define DN_MAX_OBJECT (1ULL << DN_MAX_OBJECT_SHIFT) 878b40aaca6SToomas Soome #define DN_ZERO_BONUSLEN (DN_BONUS_SIZE(DNODE_MAX_SIZE) + 1) 8791ba4a712SPawel Jakub Dawidek 8801ba4a712SPawel Jakub Dawidek #define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT) 8811ba4a712SPawel Jakub Dawidek #define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT) 8821ba4a712SPawel Jakub Dawidek #define DNODES_PER_LEVEL_SHIFT (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT) 8831ba4a712SPawel Jakub Dawidek 8841ba4a712SPawel Jakub Dawidek /* The +2 here is a cheesy way to round up */ 8851ba4a712SPawel Jakub Dawidek #define DN_MAX_LEVELS (2 + ((DN_MAX_OFFSET_SHIFT - SPA_MINBLOCKSHIFT) / \ 8861ba4a712SPawel Jakub Dawidek (DN_MIN_INDBLKSHIFT - SPA_BLKPTRSHIFT))) 8871ba4a712SPawel Jakub Dawidek 8881ba4a712SPawel Jakub Dawidek #define DN_BONUS(dnp) ((void*)((dnp)->dn_bonus + \ 8891ba4a712SPawel Jakub Dawidek (((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t)))) 8901ba4a712SPawel Jakub Dawidek 8911ba4a712SPawel Jakub Dawidek #define DN_USED_BYTES(dnp) (((dnp)->dn_flags & DNODE_FLAG_USED_BYTES) ? \ 8921ba4a712SPawel Jakub Dawidek (dnp)->dn_used : (dnp)->dn_used << SPA_MINBLOCKSHIFT) 8931ba4a712SPawel Jakub Dawidek 8941ba4a712SPawel Jakub Dawidek #define EPB(blkshift, typeshift) (1 << (blkshift - typeshift)) 8951ba4a712SPawel Jakub Dawidek 8961ba4a712SPawel Jakub Dawidek /* Is dn_used in bytes? if not, it's in multiples of SPA_MINBLOCKSIZE */ 8971ba4a712SPawel Jakub Dawidek #define DNODE_FLAG_USED_BYTES (1<<0) 89810b9d77bSPawel Jakub Dawidek #define DNODE_FLAG_USERUSED_ACCOUNTED (1<<1) 89910b9d77bSPawel Jakub Dawidek 90010b9d77bSPawel Jakub Dawidek /* Does dnode have a SA spill blkptr in bonus? */ 90110b9d77bSPawel Jakub Dawidek #define DNODE_FLAG_SPILL_BLKPTR (1<<2) 9021ba4a712SPawel Jakub Dawidek 9031ba4a712SPawel Jakub Dawidek typedef struct dnode_phys { 9041ba4a712SPawel Jakub Dawidek uint8_t dn_type; /* dmu_object_type_t */ 9051ba4a712SPawel Jakub Dawidek uint8_t dn_indblkshift; /* ln2(indirect block size) */ 9061ba4a712SPawel Jakub Dawidek uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */ 9071ba4a712SPawel Jakub Dawidek uint8_t dn_nblkptr; /* length of dn_blkptr */ 9081ba4a712SPawel Jakub Dawidek uint8_t dn_bonustype; /* type of data in bonus buffer */ 9091ba4a712SPawel Jakub Dawidek uint8_t dn_checksum; /* ZIO_CHECKSUM type */ 9101ba4a712SPawel Jakub Dawidek uint8_t dn_compress; /* ZIO_COMPRESS type */ 9111ba4a712SPawel Jakub Dawidek uint8_t dn_flags; /* DNODE_FLAG_* */ 9121ba4a712SPawel Jakub Dawidek uint16_t dn_datablkszsec; /* data block size in 512b sectors */ 9131ba4a712SPawel Jakub Dawidek uint16_t dn_bonuslen; /* length of dn_bonus */ 914b40aaca6SToomas Soome uint8_t dn_extra_slots; /* # of subsequent slots consumed */ 915b40aaca6SToomas Soome uint8_t dn_pad2[3]; 9161ba4a712SPawel Jakub Dawidek 9171ba4a712SPawel Jakub Dawidek /* accounting is protected by dn_dirty_mtx */ 9181ba4a712SPawel Jakub Dawidek uint64_t dn_maxblkid; /* largest allocated block ID */ 9191ba4a712SPawel Jakub Dawidek uint64_t dn_used; /* bytes (or sectors) of disk space */ 9201ba4a712SPawel Jakub Dawidek 9211ba4a712SPawel Jakub Dawidek uint64_t dn_pad3[4]; 9221ba4a712SPawel Jakub Dawidek 923b40aaca6SToomas Soome /* 924b40aaca6SToomas Soome * The tail region is 448 bytes for a 512 byte dnode, and 925b40aaca6SToomas Soome * correspondingly larger for larger dnode sizes. The spill 926b40aaca6SToomas Soome * block pointer, when present, is always at the end of the tail 927b40aaca6SToomas Soome * region. There are three ways this space may be used, using 928b40aaca6SToomas Soome * a 512 byte dnode for this diagram: 929b40aaca6SToomas Soome * 930b40aaca6SToomas Soome * 0 64 128 192 256 320 384 448 (offset) 931b40aaca6SToomas Soome * +---------------+---------------+---------------+-------+ 932b40aaca6SToomas Soome * | dn_blkptr[0] | dn_blkptr[1] | dn_blkptr[2] | / | 933b40aaca6SToomas Soome * +---------------+---------------+---------------+-------+ 934b40aaca6SToomas Soome * | dn_blkptr[0] | dn_bonus[0..319] | 935b40aaca6SToomas Soome * +---------------+-----------------------+---------------+ 936b40aaca6SToomas Soome * | dn_blkptr[0] | dn_bonus[0..191] | dn_spill | 937b40aaca6SToomas Soome * +---------------+-----------------------+---------------+ 938b40aaca6SToomas Soome */ 939b40aaca6SToomas Soome union { 940b40aaca6SToomas Soome blkptr_t dn_blkptr[1+DN_OLD_MAX_BONUSLEN/sizeof (blkptr_t)]; 941b40aaca6SToomas Soome struct { 942b40aaca6SToomas Soome blkptr_t __dn_ignore1; 943b40aaca6SToomas Soome uint8_t dn_bonus[DN_OLD_MAX_BONUSLEN]; 944b40aaca6SToomas Soome }; 945b40aaca6SToomas Soome struct { 946b40aaca6SToomas Soome blkptr_t __dn_ignore2; 947b40aaca6SToomas Soome uint8_t __dn_ignore3[DN_OLD_MAX_BONUSLEN - 948b40aaca6SToomas Soome sizeof (blkptr_t)]; 94910b9d77bSPawel Jakub Dawidek blkptr_t dn_spill; 950b40aaca6SToomas Soome }; 951b40aaca6SToomas Soome }; 9521ba4a712SPawel Jakub Dawidek } dnode_phys_t; 9531ba4a712SPawel Jakub Dawidek 954b40aaca6SToomas Soome #define DN_SPILL_BLKPTR(dnp) (blkptr_t *)((char *)(dnp) + \ 955b40aaca6SToomas Soome (((dnp)->dn_extra_slots + 1) << DNODE_SHIFT) - (1 << SPA_BLKPTRSHIFT)) 956b40aaca6SToomas Soome 9574deb8929SAllan Jude typedef enum dmu_object_byteswap { 9584deb8929SAllan Jude DMU_BSWAP_UINT8, 9594deb8929SAllan Jude DMU_BSWAP_UINT16, 9604deb8929SAllan Jude DMU_BSWAP_UINT32, 9614deb8929SAllan Jude DMU_BSWAP_UINT64, 9624deb8929SAllan Jude DMU_BSWAP_ZAP, 9634deb8929SAllan Jude DMU_BSWAP_DNODE, 9644deb8929SAllan Jude DMU_BSWAP_OBJSET, 9654deb8929SAllan Jude DMU_BSWAP_ZNODE, 9664deb8929SAllan Jude DMU_BSWAP_OLDACL, 9674deb8929SAllan Jude DMU_BSWAP_ACL, 9684deb8929SAllan Jude /* 9694deb8929SAllan Jude * Allocating a new byteswap type number makes the on-disk format 9704deb8929SAllan Jude * incompatible with any other format that uses the same number. 9714deb8929SAllan Jude * 9724deb8929SAllan Jude * Data can usually be structured to work with one of the 9734deb8929SAllan Jude * DMU_BSWAP_UINT* or DMU_BSWAP_ZAP types. 9744deb8929SAllan Jude */ 9754deb8929SAllan Jude DMU_BSWAP_NUMFUNCS 9764deb8929SAllan Jude } dmu_object_byteswap_t; 9774deb8929SAllan Jude 9784deb8929SAllan Jude #define DMU_OT_NEWTYPE 0x80 9794deb8929SAllan Jude #define DMU_OT_METADATA 0x40 9804deb8929SAllan Jude #define DMU_OT_BYTESWAP_MASK 0x3f 9814deb8929SAllan Jude 9824deb8929SAllan Jude /* 9834deb8929SAllan Jude * Defines a uint8_t object type. Object types specify if the data 9844deb8929SAllan Jude * in the object is metadata (boolean) and how to byteswap the data 9854deb8929SAllan Jude * (dmu_object_byteswap_t). 9864deb8929SAllan Jude */ 9874deb8929SAllan Jude #define DMU_OT(byteswap, metadata) \ 9884deb8929SAllan Jude (DMU_OT_NEWTYPE | \ 9894deb8929SAllan Jude ((metadata) ? DMU_OT_METADATA : 0) | \ 9904deb8929SAllan Jude ((byteswap) & DMU_OT_BYTESWAP_MASK)) 9914deb8929SAllan Jude 9921ba4a712SPawel Jakub Dawidek typedef enum dmu_object_type { 9931ba4a712SPawel Jakub Dawidek DMU_OT_NONE, 9941ba4a712SPawel Jakub Dawidek /* general: */ 9951ba4a712SPawel Jakub Dawidek DMU_OT_OBJECT_DIRECTORY, /* ZAP */ 9961ba4a712SPawel Jakub Dawidek DMU_OT_OBJECT_ARRAY, /* UINT64 */ 9971ba4a712SPawel Jakub Dawidek DMU_OT_PACKED_NVLIST, /* UINT8 (XDR by nvlist_pack/unpack) */ 9981ba4a712SPawel Jakub Dawidek DMU_OT_PACKED_NVLIST_SIZE, /* UINT64 */ 9991ba4a712SPawel Jakub Dawidek DMU_OT_BPLIST, /* UINT64 */ 10001ba4a712SPawel Jakub Dawidek DMU_OT_BPLIST_HDR, /* UINT64 */ 10011ba4a712SPawel Jakub Dawidek /* spa: */ 10021ba4a712SPawel Jakub Dawidek DMU_OT_SPACE_MAP_HEADER, /* UINT64 */ 10031ba4a712SPawel Jakub Dawidek DMU_OT_SPACE_MAP, /* UINT64 */ 10041ba4a712SPawel Jakub Dawidek /* zil: */ 10051ba4a712SPawel Jakub Dawidek DMU_OT_INTENT_LOG, /* UINT64 */ 10061ba4a712SPawel Jakub Dawidek /* dmu: */ 10071ba4a712SPawel Jakub Dawidek DMU_OT_DNODE, /* DNODE */ 10081ba4a712SPawel Jakub Dawidek DMU_OT_OBJSET, /* OBJSET */ 10091ba4a712SPawel Jakub Dawidek /* dsl: */ 10101ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DIR, /* UINT64 */ 10111ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DIR_CHILD_MAP, /* ZAP */ 10121ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DS_SNAP_MAP, /* ZAP */ 10131ba4a712SPawel Jakub Dawidek DMU_OT_DSL_PROPS, /* ZAP */ 10141ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DATASET, /* UINT64 */ 10151ba4a712SPawel Jakub Dawidek /* zpl: */ 10161ba4a712SPawel Jakub Dawidek DMU_OT_ZNODE, /* ZNODE */ 101710b9d77bSPawel Jakub Dawidek DMU_OT_OLDACL, /* Old ACL */ 10181ba4a712SPawel Jakub Dawidek DMU_OT_PLAIN_FILE_CONTENTS, /* UINT8 */ 10191ba4a712SPawel Jakub Dawidek DMU_OT_DIRECTORY_CONTENTS, /* ZAP */ 10201ba4a712SPawel Jakub Dawidek DMU_OT_MASTER_NODE, /* ZAP */ 10211ba4a712SPawel Jakub Dawidek DMU_OT_UNLINKED_SET, /* ZAP */ 10221ba4a712SPawel Jakub Dawidek /* zvol: */ 10231ba4a712SPawel Jakub Dawidek DMU_OT_ZVOL, /* UINT8 */ 10241ba4a712SPawel Jakub Dawidek DMU_OT_ZVOL_PROP, /* ZAP */ 10251ba4a712SPawel Jakub Dawidek /* other; for testing only! */ 10261ba4a712SPawel Jakub Dawidek DMU_OT_PLAIN_OTHER, /* UINT8 */ 10271ba4a712SPawel Jakub Dawidek DMU_OT_UINT64_OTHER, /* UINT64 */ 10281ba4a712SPawel Jakub Dawidek DMU_OT_ZAP_OTHER, /* ZAP */ 10291ba4a712SPawel Jakub Dawidek /* new object types: */ 10301ba4a712SPawel Jakub Dawidek DMU_OT_ERROR_LOG, /* ZAP */ 10311ba4a712SPawel Jakub Dawidek DMU_OT_SPA_HISTORY, /* UINT8 */ 10321ba4a712SPawel Jakub Dawidek DMU_OT_SPA_HISTORY_OFFSETS, /* spa_his_phys_t */ 10331ba4a712SPawel Jakub Dawidek DMU_OT_POOL_PROPS, /* ZAP */ 103410b9d77bSPawel Jakub Dawidek DMU_OT_DSL_PERMS, /* ZAP */ 103510b9d77bSPawel Jakub Dawidek DMU_OT_ACL, /* ACL */ 103610b9d77bSPawel Jakub Dawidek DMU_OT_SYSACL, /* SYSACL */ 103710b9d77bSPawel Jakub Dawidek DMU_OT_FUID, /* FUID table (Packed NVLIST UINT8) */ 103810b9d77bSPawel Jakub Dawidek DMU_OT_FUID_SIZE, /* FUID table size UINT64 */ 103910b9d77bSPawel Jakub Dawidek DMU_OT_NEXT_CLONES, /* ZAP */ 104010b9d77bSPawel Jakub Dawidek DMU_OT_SCAN_QUEUE, /* ZAP */ 104110b9d77bSPawel Jakub Dawidek DMU_OT_USERGROUP_USED, /* ZAP */ 104210b9d77bSPawel Jakub Dawidek DMU_OT_USERGROUP_QUOTA, /* ZAP */ 104310b9d77bSPawel Jakub Dawidek DMU_OT_USERREFS, /* ZAP */ 104410b9d77bSPawel Jakub Dawidek DMU_OT_DDT_ZAP, /* ZAP */ 104510b9d77bSPawel Jakub Dawidek DMU_OT_DDT_STATS, /* ZAP */ 104610b9d77bSPawel Jakub Dawidek DMU_OT_SA, /* System attr */ 104710b9d77bSPawel Jakub Dawidek DMU_OT_SA_MASTER_NODE, /* ZAP */ 104810b9d77bSPawel Jakub Dawidek DMU_OT_SA_ATTR_REGISTRATION, /* ZAP */ 104910b9d77bSPawel Jakub Dawidek DMU_OT_SA_ATTR_LAYOUTS, /* ZAP */ 105010b9d77bSPawel Jakub Dawidek DMU_OT_SCAN_XLATE, /* ZAP */ 105110b9d77bSPawel Jakub Dawidek DMU_OT_DEDUP, /* fake dedup BP from ddt_bp_create() */ 10524deb8929SAllan Jude DMU_OT_NUMTYPES, 10534deb8929SAllan Jude 10544deb8929SAllan Jude /* 10554deb8929SAllan Jude * Names for valid types declared with DMU_OT(). 10564deb8929SAllan Jude */ 10574deb8929SAllan Jude DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE), 10584deb8929SAllan Jude DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE), 10594deb8929SAllan Jude DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE), 10604deb8929SAllan Jude DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE), 10614deb8929SAllan Jude DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE), 10624deb8929SAllan Jude DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE), 10634deb8929SAllan Jude DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE), 10644deb8929SAllan Jude DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE), 10654deb8929SAllan Jude DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE), 10664deb8929SAllan Jude DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE) 10671ba4a712SPawel Jakub Dawidek } dmu_object_type_t; 10681ba4a712SPawel Jakub Dawidek 10691ba4a712SPawel Jakub Dawidek typedef enum dmu_objset_type { 10701ba4a712SPawel Jakub Dawidek DMU_OST_NONE, 10711ba4a712SPawel Jakub Dawidek DMU_OST_META, 10721ba4a712SPawel Jakub Dawidek DMU_OST_ZFS, 10731ba4a712SPawel Jakub Dawidek DMU_OST_ZVOL, 10741ba4a712SPawel Jakub Dawidek DMU_OST_OTHER, /* For testing only! */ 10751ba4a712SPawel Jakub Dawidek DMU_OST_ANY, /* Be careful! */ 10761ba4a712SPawel Jakub Dawidek DMU_OST_NUMTYPES 10771ba4a712SPawel Jakub Dawidek } dmu_objset_type_t; 10781ba4a712SPawel Jakub Dawidek 10791ba4a712SPawel Jakub Dawidek /* 108010b9d77bSPawel Jakub Dawidek * header for all bonus and spill buffers. 108110b9d77bSPawel Jakub Dawidek * The header has a fixed portion with a variable number 108210b9d77bSPawel Jakub Dawidek * of "lengths" depending on the number of variable sized 108310b9d77bSPawel Jakub Dawidek * attribues which are determined by the "layout number" 108410b9d77bSPawel Jakub Dawidek */ 108510b9d77bSPawel Jakub Dawidek 108610b9d77bSPawel Jakub Dawidek #define SA_MAGIC 0x2F505A /* ZFS SA */ 108710b9d77bSPawel Jakub Dawidek typedef struct sa_hdr_phys { 108810b9d77bSPawel Jakub Dawidek uint32_t sa_magic; 108910b9d77bSPawel Jakub Dawidek uint16_t sa_layout_info; /* Encoded with hdrsize and layout number */ 109010b9d77bSPawel Jakub Dawidek uint16_t sa_lengths[1]; /* optional sizes for variable length attrs */ 109110b9d77bSPawel Jakub Dawidek /* ... Data follows the lengths. */ 109210b9d77bSPawel Jakub Dawidek } sa_hdr_phys_t; 109310b9d77bSPawel Jakub Dawidek 109410b9d77bSPawel Jakub Dawidek /* 109510b9d77bSPawel Jakub Dawidek * sa_hdr_phys -> sa_layout_info 109610b9d77bSPawel Jakub Dawidek * 109710b9d77bSPawel Jakub Dawidek * 16 10 0 109810b9d77bSPawel Jakub Dawidek * +--------+-------+ 109910b9d77bSPawel Jakub Dawidek * | hdrsz |layout | 110010b9d77bSPawel Jakub Dawidek * +--------+-------+ 110110b9d77bSPawel Jakub Dawidek * 110210b9d77bSPawel Jakub Dawidek * Bits 0-10 are the layout number 110310b9d77bSPawel Jakub Dawidek * Bits 11-16 are the size of the header. 110410b9d77bSPawel Jakub Dawidek * The hdrsize is the number * 8 110510b9d77bSPawel Jakub Dawidek * 110610b9d77bSPawel Jakub Dawidek * For example. 110710b9d77bSPawel Jakub Dawidek * hdrsz of 1 ==> 8 byte header 110810b9d77bSPawel Jakub Dawidek * 2 ==> 16 byte header 110910b9d77bSPawel Jakub Dawidek * 111010b9d77bSPawel Jakub Dawidek */ 111110b9d77bSPawel Jakub Dawidek 111210b9d77bSPawel Jakub Dawidek #define SA_HDR_LAYOUT_NUM(hdr) BF32_GET(hdr->sa_layout_info, 0, 10) 111310b9d77bSPawel Jakub Dawidek #define SA_HDR_SIZE(hdr) BF32_GET_SB(hdr->sa_layout_info, 10, 16, 3, 0) 111410b9d77bSPawel Jakub Dawidek #define SA_HDR_LAYOUT_INFO_ENCODE(x, num, size) \ 111510b9d77bSPawel Jakub Dawidek { \ 111610b9d77bSPawel Jakub Dawidek BF32_SET_SB(x, 10, 6, 3, 0, size); \ 111710b9d77bSPawel Jakub Dawidek BF32_SET(x, 0, 10, num); \ 111810b9d77bSPawel Jakub Dawidek } 111910b9d77bSPawel Jakub Dawidek 112010b9d77bSPawel Jakub Dawidek #define SA_MODE_OFFSET 0 112110b9d77bSPawel Jakub Dawidek #define SA_SIZE_OFFSET 8 112210b9d77bSPawel Jakub Dawidek #define SA_GEN_OFFSET 16 112310b9d77bSPawel Jakub Dawidek #define SA_UID_OFFSET 24 112410b9d77bSPawel Jakub Dawidek #define SA_GID_OFFSET 32 112510b9d77bSPawel Jakub Dawidek #define SA_PARENT_OFFSET 40 112684a6eddcSToomas Soome #define SA_SYMLINK_OFFSET 160 112710b9d77bSPawel Jakub Dawidek 112827e05a19SMatt Macy #define ZIO_OBJSET_MAC_LEN 32 112927e05a19SMatt Macy 113010b9d77bSPawel Jakub Dawidek /* 11311ba4a712SPawel Jakub Dawidek * Intent log header - this on disk structure holds fields to manage 11321ba4a712SPawel Jakub Dawidek * the log. All fields are 64 bit to easily handle cross architectures. 11331ba4a712SPawel Jakub Dawidek */ 11341ba4a712SPawel Jakub Dawidek typedef struct zil_header { 11351ba4a712SPawel Jakub Dawidek uint64_t zh_claim_txg; /* txg in which log blocks were claimed */ 11361ba4a712SPawel Jakub Dawidek uint64_t zh_replay_seq; /* highest replayed sequence number */ 11371ba4a712SPawel Jakub Dawidek blkptr_t zh_log; /* log chain */ 11381ba4a712SPawel Jakub Dawidek uint64_t zh_claim_seq; /* highest claimed sequence number */ 11391ba4a712SPawel Jakub Dawidek uint64_t zh_pad[5]; 11401ba4a712SPawel Jakub Dawidek } zil_header_t; 11411ba4a712SPawel Jakub Dawidek 114227e05a19SMatt Macy #define OBJSET_PHYS_SIZE_V2 2048 114327e05a19SMatt Macy #define OBJSET_PHYS_SIZE_V3 4096 114410b9d77bSPawel Jakub Dawidek 11451ba4a712SPawel Jakub Dawidek typedef struct objset_phys { 11461ba4a712SPawel Jakub Dawidek dnode_phys_t os_meta_dnode; 11471ba4a712SPawel Jakub Dawidek zil_header_t os_zil_header; 11481ba4a712SPawel Jakub Dawidek uint64_t os_type; 11498fc25799SMartin Matuska uint64_t os_flags; 115027e05a19SMatt Macy uint8_t os_portable_mac[ZIO_OBJSET_MAC_LEN]; 115127e05a19SMatt Macy uint8_t os_local_mac[ZIO_OBJSET_MAC_LEN]; 115227e05a19SMatt Macy char os_pad0[OBJSET_PHYS_SIZE_V2 - sizeof (dnode_phys_t)*3 - 115327e05a19SMatt Macy sizeof (zil_header_t) - sizeof (uint64_t)*2 - 115427e05a19SMatt Macy 2*ZIO_OBJSET_MAC_LEN]; 11558fc25799SMartin Matuska dnode_phys_t os_userused_dnode; 11568fc25799SMartin Matuska dnode_phys_t os_groupused_dnode; 115727e05a19SMatt Macy dnode_phys_t os_projectused_dnode; 115827e05a19SMatt Macy char os_pad1[OBJSET_PHYS_SIZE_V3 - OBJSET_PHYS_SIZE_V2 - 115927e05a19SMatt Macy sizeof (dnode_phys_t)]; 11601ba4a712SPawel Jakub Dawidek } objset_phys_t; 11611ba4a712SPawel Jakub Dawidek 11621ba4a712SPawel Jakub Dawidek typedef struct dsl_dir_phys { 11631ba4a712SPawel Jakub Dawidek uint64_t dd_creation_time; /* not actually used */ 11641ba4a712SPawel Jakub Dawidek uint64_t dd_head_dataset_obj; 11651ba4a712SPawel Jakub Dawidek uint64_t dd_parent_obj; 11661ba4a712SPawel Jakub Dawidek uint64_t dd_clone_parent_obj; 11671ba4a712SPawel Jakub Dawidek uint64_t dd_child_dir_zapobj; 11681ba4a712SPawel Jakub Dawidek /* 11691ba4a712SPawel Jakub Dawidek * how much space our children are accounting for; for leaf 11701ba4a712SPawel Jakub Dawidek * datasets, == physical space used by fs + snaps 11711ba4a712SPawel Jakub Dawidek */ 11721ba4a712SPawel Jakub Dawidek uint64_t dd_used_bytes; 11731ba4a712SPawel Jakub Dawidek uint64_t dd_compressed_bytes; 11741ba4a712SPawel Jakub Dawidek uint64_t dd_uncompressed_bytes; 11751ba4a712SPawel Jakub Dawidek /* Administrative quota setting */ 11761ba4a712SPawel Jakub Dawidek uint64_t dd_quota; 11771ba4a712SPawel Jakub Dawidek /* Administrative reservation setting */ 11781ba4a712SPawel Jakub Dawidek uint64_t dd_reserved; 11791ba4a712SPawel Jakub Dawidek uint64_t dd_props_zapobj; 11801ba4a712SPawel Jakub Dawidek uint64_t dd_pad[21]; /* pad out to 256 bytes for good measure */ 11811ba4a712SPawel Jakub Dawidek } dsl_dir_phys_t; 11821ba4a712SPawel Jakub Dawidek 11831ba4a712SPawel Jakub Dawidek typedef struct dsl_dataset_phys { 11841ba4a712SPawel Jakub Dawidek uint64_t ds_dir_obj; 11851ba4a712SPawel Jakub Dawidek uint64_t ds_prev_snap_obj; 11861ba4a712SPawel Jakub Dawidek uint64_t ds_prev_snap_txg; 11871ba4a712SPawel Jakub Dawidek uint64_t ds_next_snap_obj; 11881ba4a712SPawel Jakub Dawidek uint64_t ds_snapnames_zapobj; /* zap obj of snaps; ==0 for snaps */ 11891ba4a712SPawel Jakub Dawidek uint64_t ds_num_children; /* clone/snap children; ==0 for head */ 11901ba4a712SPawel Jakub Dawidek uint64_t ds_creation_time; /* seconds since 1970 */ 11911ba4a712SPawel Jakub Dawidek uint64_t ds_creation_txg; 11921ba4a712SPawel Jakub Dawidek uint64_t ds_deadlist_obj; 11931ba4a712SPawel Jakub Dawidek uint64_t ds_used_bytes; 11941ba4a712SPawel Jakub Dawidek uint64_t ds_compressed_bytes; 11951ba4a712SPawel Jakub Dawidek uint64_t ds_uncompressed_bytes; 11961ba4a712SPawel Jakub Dawidek uint64_t ds_unique_bytes; /* only relevant to snapshots */ 11971ba4a712SPawel Jakub Dawidek /* 11981ba4a712SPawel Jakub Dawidek * The ds_fsid_guid is a 56-bit ID that can change to avoid 11991ba4a712SPawel Jakub Dawidek * collisions. The ds_guid is a 64-bit ID that will never 12001ba4a712SPawel Jakub Dawidek * change, so there is a small probability that it will collide. 12011ba4a712SPawel Jakub Dawidek */ 12021ba4a712SPawel Jakub Dawidek uint64_t ds_fsid_guid; 12031ba4a712SPawel Jakub Dawidek uint64_t ds_guid; 12041ba4a712SPawel Jakub Dawidek uint64_t ds_flags; 12051ba4a712SPawel Jakub Dawidek blkptr_t ds_bp; 12061ba4a712SPawel Jakub Dawidek uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */ 12071ba4a712SPawel Jakub Dawidek } dsl_dataset_phys_t; 12081ba4a712SPawel Jakub Dawidek 12091ba4a712SPawel Jakub Dawidek /* 12101ba4a712SPawel Jakub Dawidek * The names of zap entries in the DIRECTORY_OBJECT of the MOS. 12111ba4a712SPawel Jakub Dawidek */ 12121ba4a712SPawel Jakub Dawidek #define DMU_POOL_DIRECTORY_OBJECT 1 12131ba4a712SPawel Jakub Dawidek #define DMU_POOL_CONFIG "config" 12144deb8929SAllan Jude #define DMU_POOL_FEATURES_FOR_READ "features_for_read" 12151ba4a712SPawel Jakub Dawidek #define DMU_POOL_ROOT_DATASET "root_dataset" 12161ba4a712SPawel Jakub Dawidek #define DMU_POOL_SYNC_BPLIST "sync_bplist" 12171ba4a712SPawel Jakub Dawidek #define DMU_POOL_ERRLOG_SCRUB "errlog_scrub" 12181ba4a712SPawel Jakub Dawidek #define DMU_POOL_ERRLOG_LAST "errlog_last" 12191ba4a712SPawel Jakub Dawidek #define DMU_POOL_SPARES "spares" 12201ba4a712SPawel Jakub Dawidek #define DMU_POOL_DEFLATE "deflate" 12211ba4a712SPawel Jakub Dawidek #define DMU_POOL_HISTORY "history" 12221ba4a712SPawel Jakub Dawidek #define DMU_POOL_PROPS "pool_props" 12232c55d090SToomas Soome #define DMU_POOL_CHECKSUM_SALT "org.illumos:checksum_salt" 1224*b1b93268SToomas Soome #define DMU_POOL_REMOVING "com.delphix:removing" 1225*b1b93268SToomas Soome #define DMU_POOL_OBSOLETE_BPOBJ "com.delphix:obsolete_bpobj" 1226*b1b93268SToomas Soome #define DMU_POOL_CONDENSING_INDIRECT "com.delphix:condensing_indirect" 12271ba4a712SPawel Jakub Dawidek 12281ba4a712SPawel Jakub Dawidek #define ZAP_MAGIC 0x2F52AB2ABULL 12291ba4a712SPawel Jakub Dawidek 12301ba4a712SPawel Jakub Dawidek #define FZAP_BLOCK_SHIFT(zap) ((zap)->zap_block_shift) 12311ba4a712SPawel Jakub Dawidek 12321ba4a712SPawel Jakub Dawidek #define ZAP_MAXCD (uint32_t)(-1) 12331ba4a712SPawel Jakub Dawidek #define ZAP_HASHBITS 28 12341ba4a712SPawel Jakub Dawidek #define MZAP_ENT_LEN 64 12351ba4a712SPawel Jakub Dawidek #define MZAP_NAME_LEN (MZAP_ENT_LEN - 8 - 4 - 2) 12361ba4a712SPawel Jakub Dawidek #define MZAP_MAX_BLKSHIFT SPA_MAXBLOCKSHIFT 12371ba4a712SPawel Jakub Dawidek #define MZAP_MAX_BLKSZ (1 << MZAP_MAX_BLKSHIFT) 12381ba4a712SPawel Jakub Dawidek 12391ba4a712SPawel Jakub Dawidek typedef struct mzap_ent_phys { 12401ba4a712SPawel Jakub Dawidek uint64_t mze_value; 12411ba4a712SPawel Jakub Dawidek uint32_t mze_cd; 12421ba4a712SPawel Jakub Dawidek uint16_t mze_pad; /* in case we want to chain them someday */ 12431ba4a712SPawel Jakub Dawidek char mze_name[MZAP_NAME_LEN]; 12441ba4a712SPawel Jakub Dawidek } mzap_ent_phys_t; 12451ba4a712SPawel Jakub Dawidek 12461ba4a712SPawel Jakub Dawidek typedef struct mzap_phys { 12471ba4a712SPawel Jakub Dawidek uint64_t mz_block_type; /* ZBT_MICRO */ 12481ba4a712SPawel Jakub Dawidek uint64_t mz_salt; 12491ba4a712SPawel Jakub Dawidek uint64_t mz_pad[6]; 12501ba4a712SPawel Jakub Dawidek mzap_ent_phys_t mz_chunk[1]; 12511ba4a712SPawel Jakub Dawidek /* actually variable size depending on block size */ 12521ba4a712SPawel Jakub Dawidek } mzap_phys_t; 12531ba4a712SPawel Jakub Dawidek 12541ba4a712SPawel Jakub Dawidek /* 12551ba4a712SPawel Jakub Dawidek * The (fat) zap is stored in one object. It is an array of 12561ba4a712SPawel Jakub Dawidek * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of: 12571ba4a712SPawel Jakub Dawidek * 12581ba4a712SPawel Jakub Dawidek * ptrtbl fits in first block: 12591ba4a712SPawel Jakub Dawidek * [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ... 12601ba4a712SPawel Jakub Dawidek * 12611ba4a712SPawel Jakub Dawidek * ptrtbl too big for first block: 12621ba4a712SPawel Jakub Dawidek * [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ... 12631ba4a712SPawel Jakub Dawidek * 12641ba4a712SPawel Jakub Dawidek */ 12651ba4a712SPawel Jakub Dawidek 12661ba4a712SPawel Jakub Dawidek #define ZBT_LEAF ((1ULL << 63) + 0) 12671ba4a712SPawel Jakub Dawidek #define ZBT_HEADER ((1ULL << 63) + 1) 12681ba4a712SPawel Jakub Dawidek #define ZBT_MICRO ((1ULL << 63) + 3) 12691ba4a712SPawel Jakub Dawidek /* any other values are ptrtbl blocks */ 12701ba4a712SPawel Jakub Dawidek 12711ba4a712SPawel Jakub Dawidek /* 12721ba4a712SPawel Jakub Dawidek * the embedded pointer table takes up half a block: 12731ba4a712SPawel Jakub Dawidek * block size / entry size (2^3) / 2 12741ba4a712SPawel Jakub Dawidek */ 12751ba4a712SPawel Jakub Dawidek #define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1) 12761ba4a712SPawel Jakub Dawidek 12771ba4a712SPawel Jakub Dawidek /* 12781ba4a712SPawel Jakub Dawidek * The embedded pointer table starts half-way through the block. Since 12791ba4a712SPawel Jakub Dawidek * the pointer table itself is half the block, it starts at (64-bit) 12801ba4a712SPawel Jakub Dawidek * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)). 12811ba4a712SPawel Jakub Dawidek */ 12821ba4a712SPawel Jakub Dawidek #define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \ 12831ba4a712SPawel Jakub Dawidek ((uint64_t *)(zap)->zap_phys) \ 12841ba4a712SPawel Jakub Dawidek [(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))] 12851ba4a712SPawel Jakub Dawidek 12861ba4a712SPawel Jakub Dawidek /* 12871ba4a712SPawel Jakub Dawidek * TAKE NOTE: 12881ba4a712SPawel Jakub Dawidek * If zap_phys_t is modified, zap_byteswap() must be modified. 12891ba4a712SPawel Jakub Dawidek */ 12901ba4a712SPawel Jakub Dawidek typedef struct zap_phys { 12911ba4a712SPawel Jakub Dawidek uint64_t zap_block_type; /* ZBT_HEADER */ 12921ba4a712SPawel Jakub Dawidek uint64_t zap_magic; /* ZAP_MAGIC */ 12931ba4a712SPawel Jakub Dawidek 12941ba4a712SPawel Jakub Dawidek struct zap_table_phys { 12951ba4a712SPawel Jakub Dawidek uint64_t zt_blk; /* starting block number */ 12961ba4a712SPawel Jakub Dawidek uint64_t zt_numblks; /* number of blocks */ 12971ba4a712SPawel Jakub Dawidek uint64_t zt_shift; /* bits to index it */ 12981ba4a712SPawel Jakub Dawidek uint64_t zt_nextblk; /* next (larger) copy start block */ 12991ba4a712SPawel Jakub Dawidek uint64_t zt_blks_copied; /* number source blocks copied */ 13001ba4a712SPawel Jakub Dawidek } zap_ptrtbl; 13011ba4a712SPawel Jakub Dawidek 13021ba4a712SPawel Jakub Dawidek uint64_t zap_freeblk; /* the next free block */ 13031ba4a712SPawel Jakub Dawidek uint64_t zap_num_leafs; /* number of leafs */ 13041ba4a712SPawel Jakub Dawidek uint64_t zap_num_entries; /* number of entries */ 13051ba4a712SPawel Jakub Dawidek uint64_t zap_salt; /* salt to stir into hash function */ 13061ba4a712SPawel Jakub Dawidek /* 13071ba4a712SPawel Jakub Dawidek * This structure is followed by padding, and then the embedded 13081ba4a712SPawel Jakub Dawidek * pointer table. The embedded pointer table takes up second 13091ba4a712SPawel Jakub Dawidek * half of the block. It is accessed using the 13101ba4a712SPawel Jakub Dawidek * ZAP_EMBEDDED_PTRTBL_ENT() macro. 13111ba4a712SPawel Jakub Dawidek */ 13121ba4a712SPawel Jakub Dawidek } zap_phys_t; 13131ba4a712SPawel Jakub Dawidek 13141ba4a712SPawel Jakub Dawidek typedef struct zap_table_phys zap_table_phys_t; 13151ba4a712SPawel Jakub Dawidek 13161ba4a712SPawel Jakub Dawidek typedef struct fat_zap { 13171ba4a712SPawel Jakub Dawidek int zap_block_shift; /* block size shift */ 13181ba4a712SPawel Jakub Dawidek zap_phys_t *zap_phys; 13191ba4a712SPawel Jakub Dawidek } fat_zap_t; 13201ba4a712SPawel Jakub Dawidek 13211ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_MAGIC 0x2AB1EAF 13221ba4a712SPawel Jakub Dawidek 13231ba4a712SPawel Jakub Dawidek /* chunk size = 24 bytes */ 13241ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_CHUNKSIZE 24 13251ba4a712SPawel Jakub Dawidek 13261ba4a712SPawel Jakub Dawidek /* 13271ba4a712SPawel Jakub Dawidek * The amount of space available for chunks is: 13281ba4a712SPawel Jakub Dawidek * block size (1<<l->l_bs) - hash entry size (2) * number of hash 13291ba4a712SPawel Jakub Dawidek * entries - header space (2*chunksize) 13301ba4a712SPawel Jakub Dawidek */ 13311ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_NUMCHUNKS(l) \ 13321ba4a712SPawel Jakub Dawidek (((1<<(l)->l_bs) - 2*ZAP_LEAF_HASH_NUMENTRIES(l)) / \ 13331ba4a712SPawel Jakub Dawidek ZAP_LEAF_CHUNKSIZE - 2) 13341ba4a712SPawel Jakub Dawidek 13351ba4a712SPawel Jakub Dawidek /* 13361ba4a712SPawel Jakub Dawidek * The amount of space within the chunk available for the array is: 13371ba4a712SPawel Jakub Dawidek * chunk size - space for type (1) - space for next pointer (2) 13381ba4a712SPawel Jakub Dawidek */ 13391ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3) 13401ba4a712SPawel Jakub Dawidek 13411ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_ARRAY_NCHUNKS(bytes) \ 13421ba4a712SPawel Jakub Dawidek (((bytes)+ZAP_LEAF_ARRAY_BYTES-1)/ZAP_LEAF_ARRAY_BYTES) 13431ba4a712SPawel Jakub Dawidek 13441ba4a712SPawel Jakub Dawidek /* 13451ba4a712SPawel Jakub Dawidek * Low water mark: when there are only this many chunks free, start 13461ba4a712SPawel Jakub Dawidek * growing the ptrtbl. Ideally, this should be larger than a 13471ba4a712SPawel Jakub Dawidek * "reasonably-sized" entry. 20 chunks is more than enough for the 13481ba4a712SPawel Jakub Dawidek * largest directory entry (MAXNAMELEN (256) byte name, 8-byte value), 13491ba4a712SPawel Jakub Dawidek * while still being only around 3% for 16k blocks. 13501ba4a712SPawel Jakub Dawidek */ 13511ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_LOW_WATER (20) 13521ba4a712SPawel Jakub Dawidek 13531ba4a712SPawel Jakub Dawidek /* 13541ba4a712SPawel Jakub Dawidek * The leaf hash table has block size / 2^5 (32) number of entries, 13551ba4a712SPawel Jakub Dawidek * which should be more than enough for the maximum number of entries, 13561ba4a712SPawel Jakub Dawidek * which is less than block size / CHUNKSIZE (24) / minimum number of 13571ba4a712SPawel Jakub Dawidek * chunks per entry (3). 13581ba4a712SPawel Jakub Dawidek */ 13591ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_HASH_SHIFT(l) ((l)->l_bs - 5) 13601ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_HASH_NUMENTRIES(l) (1 << ZAP_LEAF_HASH_SHIFT(l)) 13611ba4a712SPawel Jakub Dawidek 13621ba4a712SPawel Jakub Dawidek /* 13631ba4a712SPawel Jakub Dawidek * The chunks start immediately after the hash table. The end of the 13641ba4a712SPawel Jakub Dawidek * hash table is at l_hash + HASH_NUMENTRIES, which we simply cast to a 13651ba4a712SPawel Jakub Dawidek * chunk_t. 13661ba4a712SPawel Jakub Dawidek */ 13671ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_CHUNK(l, idx) \ 13681ba4a712SPawel Jakub Dawidek ((zap_leaf_chunk_t *) \ 13691ba4a712SPawel Jakub Dawidek ((l)->l_phys->l_hash + ZAP_LEAF_HASH_NUMENTRIES(l)))[idx] 13701ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_ENTRY(l, idx) (&ZAP_LEAF_CHUNK(l, idx).l_entry) 13711ba4a712SPawel Jakub Dawidek 13721ba4a712SPawel Jakub Dawidek typedef enum zap_chunk_type { 13731ba4a712SPawel Jakub Dawidek ZAP_CHUNK_FREE = 253, 13741ba4a712SPawel Jakub Dawidek ZAP_CHUNK_ENTRY = 252, 13751ba4a712SPawel Jakub Dawidek ZAP_CHUNK_ARRAY = 251, 13761ba4a712SPawel Jakub Dawidek ZAP_CHUNK_TYPE_MAX = 250 13771ba4a712SPawel Jakub Dawidek } zap_chunk_type_t; 13781ba4a712SPawel Jakub Dawidek 13791ba4a712SPawel Jakub Dawidek /* 13801ba4a712SPawel Jakub Dawidek * TAKE NOTE: 13811ba4a712SPawel Jakub Dawidek * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified. 13821ba4a712SPawel Jakub Dawidek */ 13831ba4a712SPawel Jakub Dawidek typedef struct zap_leaf_phys { 13841ba4a712SPawel Jakub Dawidek struct zap_leaf_header { 13851ba4a712SPawel Jakub Dawidek uint64_t lh_block_type; /* ZBT_LEAF */ 13861ba4a712SPawel Jakub Dawidek uint64_t lh_pad1; 13871ba4a712SPawel Jakub Dawidek uint64_t lh_prefix; /* hash prefix of this leaf */ 13881ba4a712SPawel Jakub Dawidek uint32_t lh_magic; /* ZAP_LEAF_MAGIC */ 13891ba4a712SPawel Jakub Dawidek uint16_t lh_nfree; /* number free chunks */ 13901ba4a712SPawel Jakub Dawidek uint16_t lh_nentries; /* number of entries */ 13911ba4a712SPawel Jakub Dawidek uint16_t lh_prefix_len; /* num bits used to id this */ 13921ba4a712SPawel Jakub Dawidek 13931ba4a712SPawel Jakub Dawidek /* above is accessable to zap, below is zap_leaf private */ 13941ba4a712SPawel Jakub Dawidek 13951ba4a712SPawel Jakub Dawidek uint16_t lh_freelist; /* chunk head of free list */ 13961ba4a712SPawel Jakub Dawidek uint8_t lh_pad2[12]; 13971ba4a712SPawel Jakub Dawidek } l_hdr; /* 2 24-byte chunks */ 13981ba4a712SPawel Jakub Dawidek 13991ba4a712SPawel Jakub Dawidek /* 14001ba4a712SPawel Jakub Dawidek * The header is followed by a hash table with 14011ba4a712SPawel Jakub Dawidek * ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is 14021ba4a712SPawel Jakub Dawidek * followed by an array of ZAP_LEAF_NUMCHUNKS(zap) 14031ba4a712SPawel Jakub Dawidek * zap_leaf_chunk structures. These structures are accessed 14041ba4a712SPawel Jakub Dawidek * with the ZAP_LEAF_CHUNK() macro. 14051ba4a712SPawel Jakub Dawidek */ 14061ba4a712SPawel Jakub Dawidek 14071ba4a712SPawel Jakub Dawidek uint16_t l_hash[1]; 14081ba4a712SPawel Jakub Dawidek } zap_leaf_phys_t; 14091ba4a712SPawel Jakub Dawidek 14101ba4a712SPawel Jakub Dawidek typedef union zap_leaf_chunk { 14111ba4a712SPawel Jakub Dawidek struct zap_leaf_entry { 14121ba4a712SPawel Jakub Dawidek uint8_t le_type; /* always ZAP_CHUNK_ENTRY */ 14134ed4f4cfSAndriy Gapon uint8_t le_value_intlen; /* size of ints */ 14141ba4a712SPawel Jakub Dawidek uint16_t le_next; /* next entry in hash chain */ 14151ba4a712SPawel Jakub Dawidek uint16_t le_name_chunk; /* first chunk of the name */ 14164ed4f4cfSAndriy Gapon uint16_t le_name_numints; /* bytes in name, incl null */ 14171ba4a712SPawel Jakub Dawidek uint16_t le_value_chunk; /* first chunk of the value */ 14184ed4f4cfSAndriy Gapon uint16_t le_value_numints; /* value length in ints */ 14191ba4a712SPawel Jakub Dawidek uint32_t le_cd; /* collision differentiator */ 14201ba4a712SPawel Jakub Dawidek uint64_t le_hash; /* hash value of the name */ 14211ba4a712SPawel Jakub Dawidek } l_entry; 14221ba4a712SPawel Jakub Dawidek struct zap_leaf_array { 14231ba4a712SPawel Jakub Dawidek uint8_t la_type; /* always ZAP_CHUNK_ARRAY */ 14241ba4a712SPawel Jakub Dawidek uint8_t la_array[ZAP_LEAF_ARRAY_BYTES]; 14251ba4a712SPawel Jakub Dawidek uint16_t la_next; /* next blk or CHAIN_END */ 14261ba4a712SPawel Jakub Dawidek } l_array; 14271ba4a712SPawel Jakub Dawidek struct zap_leaf_free { 14281ba4a712SPawel Jakub Dawidek uint8_t lf_type; /* always ZAP_CHUNK_FREE */ 14291ba4a712SPawel Jakub Dawidek uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES]; 14301ba4a712SPawel Jakub Dawidek uint16_t lf_next; /* next in free list, or CHAIN_END */ 14311ba4a712SPawel Jakub Dawidek } l_free; 14321ba4a712SPawel Jakub Dawidek } zap_leaf_chunk_t; 14331ba4a712SPawel Jakub Dawidek 14341ba4a712SPawel Jakub Dawidek typedef struct zap_leaf { 14351ba4a712SPawel Jakub Dawidek int l_bs; /* block size shift */ 14361ba4a712SPawel Jakub Dawidek zap_leaf_phys_t *l_phys; 14371ba4a712SPawel Jakub Dawidek } zap_leaf_t; 14381ba4a712SPawel Jakub Dawidek 14391ba4a712SPawel Jakub Dawidek /* 14401ba4a712SPawel Jakub Dawidek * Define special zfs pflags 14411ba4a712SPawel Jakub Dawidek */ 14421ba4a712SPawel Jakub Dawidek #define ZFS_XATTR 0x1 /* is an extended attribute */ 14431ba4a712SPawel Jakub Dawidek #define ZFS_INHERIT_ACE 0x2 /* ace has inheritable ACEs */ 14441ba4a712SPawel Jakub Dawidek #define ZFS_ACL_TRIVIAL 0x4 /* files ACL is trivial */ 14451ba4a712SPawel Jakub Dawidek 14461ba4a712SPawel Jakub Dawidek #define MASTER_NODE_OBJ 1 14471ba4a712SPawel Jakub Dawidek 14481ba4a712SPawel Jakub Dawidek /* 14491ba4a712SPawel Jakub Dawidek * special attributes for master node. 14501ba4a712SPawel Jakub Dawidek */ 14511ba4a712SPawel Jakub Dawidek 14521ba4a712SPawel Jakub Dawidek #define ZFS_FSID "FSID" 14531ba4a712SPawel Jakub Dawidek #define ZFS_UNLINKED_SET "DELETE_QUEUE" 14541ba4a712SPawel Jakub Dawidek #define ZFS_ROOT_OBJ "ROOT" 14551ba4a712SPawel Jakub Dawidek #define ZPL_VERSION_OBJ "VERSION" 14561ba4a712SPawel Jakub Dawidek #define ZFS_PROP_BLOCKPERPAGE "BLOCKPERPAGE" 14571ba4a712SPawel Jakub Dawidek #define ZFS_PROP_NOGROWBLOCKS "NOGROWBLOCKS" 14581ba4a712SPawel Jakub Dawidek 14591ba4a712SPawel Jakub Dawidek #define ZFS_FLAG_BLOCKPERPAGE 0x1 14601ba4a712SPawel Jakub Dawidek #define ZFS_FLAG_NOGROWBLOCKS 0x2 14611ba4a712SPawel Jakub Dawidek 14621ba4a712SPawel Jakub Dawidek /* 14631ba4a712SPawel Jakub Dawidek * ZPL version - rev'd whenever an incompatible on-disk format change 14641ba4a712SPawel Jakub Dawidek * occurs. Independent of SPA/DMU/ZAP versioning. 14651ba4a712SPawel Jakub Dawidek */ 14661ba4a712SPawel Jakub Dawidek 14671ba4a712SPawel Jakub Dawidek #define ZPL_VERSION 1ULL 14681ba4a712SPawel Jakub Dawidek 14691ba4a712SPawel Jakub Dawidek /* 14701ba4a712SPawel Jakub Dawidek * The directory entry has the type (currently unused on Solaris) in the 14711ba4a712SPawel Jakub Dawidek * top 4 bits, and the object number in the low 48 bits. The "middle" 14721ba4a712SPawel Jakub Dawidek * 12 bits are unused. 14731ba4a712SPawel Jakub Dawidek */ 14741ba4a712SPawel Jakub Dawidek #define ZFS_DIRENT_TYPE(de) BF64_GET(de, 60, 4) 14751ba4a712SPawel Jakub Dawidek #define ZFS_DIRENT_OBJ(de) BF64_GET(de, 0, 48) 14761ba4a712SPawel Jakub Dawidek #define ZFS_DIRENT_MAKE(type, obj) (((uint64_t)type << 60) | obj) 14771ba4a712SPawel Jakub Dawidek 14781ba4a712SPawel Jakub Dawidek typedef struct ace { 14791ba4a712SPawel Jakub Dawidek uid_t a_who; /* uid or gid */ 14801ba4a712SPawel Jakub Dawidek uint32_t a_access_mask; /* read,write,... */ 14811ba4a712SPawel Jakub Dawidek uint16_t a_flags; /* see below */ 14821ba4a712SPawel Jakub Dawidek uint16_t a_type; /* allow or deny */ 14831ba4a712SPawel Jakub Dawidek } ace_t; 14841ba4a712SPawel Jakub Dawidek 14851ba4a712SPawel Jakub Dawidek #define ACE_SLOT_CNT 6 14861ba4a712SPawel Jakub Dawidek 14871ba4a712SPawel Jakub Dawidek typedef struct zfs_znode_acl { 14881ba4a712SPawel Jakub Dawidek uint64_t z_acl_extern_obj; /* ext acl pieces */ 14891ba4a712SPawel Jakub Dawidek uint32_t z_acl_count; /* Number of ACEs */ 14901ba4a712SPawel Jakub Dawidek uint16_t z_acl_version; /* acl version */ 14911ba4a712SPawel Jakub Dawidek uint16_t z_acl_pad; /* pad */ 14921ba4a712SPawel Jakub Dawidek ace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */ 14931ba4a712SPawel Jakub Dawidek } zfs_znode_acl_t; 14941ba4a712SPawel Jakub Dawidek 14951ba4a712SPawel Jakub Dawidek /* 14961ba4a712SPawel Jakub Dawidek * This is the persistent portion of the znode. It is stored 14971ba4a712SPawel Jakub Dawidek * in the "bonus buffer" of the file. Short symbolic links 14981ba4a712SPawel Jakub Dawidek * are also stored in the bonus buffer. 14991ba4a712SPawel Jakub Dawidek */ 15001ba4a712SPawel Jakub Dawidek typedef struct znode_phys { 15011ba4a712SPawel Jakub Dawidek uint64_t zp_atime[2]; /* 0 - last file access time */ 15021ba4a712SPawel Jakub Dawidek uint64_t zp_mtime[2]; /* 16 - last file modification time */ 15031ba4a712SPawel Jakub Dawidek uint64_t zp_ctime[2]; /* 32 - last file change time */ 15041ba4a712SPawel Jakub Dawidek uint64_t zp_crtime[2]; /* 48 - creation time */ 15051ba4a712SPawel Jakub Dawidek uint64_t zp_gen; /* 64 - generation (txg of creation) */ 15061ba4a712SPawel Jakub Dawidek uint64_t zp_mode; /* 72 - file mode bits */ 15071ba4a712SPawel Jakub Dawidek uint64_t zp_size; /* 80 - size of file */ 15081ba4a712SPawel Jakub Dawidek uint64_t zp_parent; /* 88 - directory parent (`..') */ 15091ba4a712SPawel Jakub Dawidek uint64_t zp_links; /* 96 - number of links to file */ 15101ba4a712SPawel Jakub Dawidek uint64_t zp_xattr; /* 104 - DMU object for xattrs */ 15111ba4a712SPawel Jakub Dawidek uint64_t zp_rdev; /* 112 - dev_t for VBLK & VCHR files */ 15121ba4a712SPawel Jakub Dawidek uint64_t zp_flags; /* 120 - persistent flags */ 15131ba4a712SPawel Jakub Dawidek uint64_t zp_uid; /* 128 - file owner */ 15141ba4a712SPawel Jakub Dawidek uint64_t zp_gid; /* 136 - owning group */ 15151ba4a712SPawel Jakub Dawidek uint64_t zp_pad[4]; /* 144 - future */ 15161ba4a712SPawel Jakub Dawidek zfs_znode_acl_t zp_acl; /* 176 - 263 ACL */ 15171ba4a712SPawel Jakub Dawidek /* 15181ba4a712SPawel Jakub Dawidek * Data may pad out any remaining bytes in the znode buffer, eg: 15191ba4a712SPawel Jakub Dawidek * 15201ba4a712SPawel Jakub Dawidek * |<---------------------- dnode_phys (512) ------------------------>| 15211ba4a712SPawel Jakub Dawidek * |<-- dnode (192) --->|<----------- "bonus" buffer (320) ---------->| 15221ba4a712SPawel Jakub Dawidek * |<---- znode (264) ---->|<---- data (56) ---->| 15231ba4a712SPawel Jakub Dawidek * 15241ba4a712SPawel Jakub Dawidek * At present, we only use this space to store symbolic links. 15251ba4a712SPawel Jakub Dawidek */ 15261ba4a712SPawel Jakub Dawidek } znode_phys_t; 15271ba4a712SPawel Jakub Dawidek 15281ba4a712SPawel Jakub Dawidek /* 15291ba4a712SPawel Jakub Dawidek * In-core vdev representation. 15301ba4a712SPawel Jakub Dawidek */ 15311ba4a712SPawel Jakub Dawidek struct vdev; 15322c55d090SToomas Soome struct spa; 1533e1899ef6SDoug Rabson typedef int vdev_phys_read_t(struct vdev *vdev, void *priv, 1534e1899ef6SDoug Rabson off_t offset, void *buf, size_t bytes); 1535e1899ef6SDoug Rabson typedef int vdev_read_t(struct vdev *vdev, const blkptr_t *bp, 1536e1899ef6SDoug Rabson void *buf, off_t offset, size_t bytes); 15371ba4a712SPawel Jakub Dawidek 15381ba4a712SPawel Jakub Dawidek typedef STAILQ_HEAD(vdev_list, vdev) vdev_list_t; 15391ba4a712SPawel Jakub Dawidek 1540*b1b93268SToomas Soome typedef struct vdev_indirect_mapping_entry_phys { 1541*b1b93268SToomas Soome /* 1542*b1b93268SToomas Soome * Decode with DVA_MAPPING_* macros. 1543*b1b93268SToomas Soome * Contains: 1544*b1b93268SToomas Soome * the source offset (low 63 bits) 1545*b1b93268SToomas Soome * the one-bit "mark", used for garbage collection (by zdb) 1546*b1b93268SToomas Soome */ 1547*b1b93268SToomas Soome uint64_t vimep_src; 1548*b1b93268SToomas Soome 1549*b1b93268SToomas Soome /* 1550*b1b93268SToomas Soome * Note: the DVA's asize is 24 bits, and can thus store ranges 1551*b1b93268SToomas Soome * up to 8GB. 1552*b1b93268SToomas Soome */ 1553*b1b93268SToomas Soome dva_t vimep_dst; 1554*b1b93268SToomas Soome } vdev_indirect_mapping_entry_phys_t; 1555*b1b93268SToomas Soome 1556*b1b93268SToomas Soome #define DVA_MAPPING_GET_SRC_OFFSET(vimep) \ 1557*b1b93268SToomas Soome BF64_GET_SB((vimep)->vimep_src, 0, 63, SPA_MINBLOCKSHIFT, 0) 1558*b1b93268SToomas Soome #define DVA_MAPPING_SET_SRC_OFFSET(vimep, x) \ 1559*b1b93268SToomas Soome BF64_SET_SB((vimep)->vimep_src, 0, 63, SPA_MINBLOCKSHIFT, 0, x) 1560*b1b93268SToomas Soome 1561*b1b93268SToomas Soome typedef struct vdev_indirect_mapping_entry { 1562*b1b93268SToomas Soome vdev_indirect_mapping_entry_phys_t vime_mapping; 1563*b1b93268SToomas Soome uint32_t vime_obsolete_count; 1564*b1b93268SToomas Soome list_node_t vime_node; 1565*b1b93268SToomas Soome } vdev_indirect_mapping_entry_t; 1566*b1b93268SToomas Soome 1567*b1b93268SToomas Soome /* 1568*b1b93268SToomas Soome * This is stored in the bonus buffer of the mapping object, see comment of 1569*b1b93268SToomas Soome * vdev_indirect_config for more details. 1570*b1b93268SToomas Soome */ 1571*b1b93268SToomas Soome typedef struct vdev_indirect_mapping_phys { 1572*b1b93268SToomas Soome uint64_t vimp_max_offset; 1573*b1b93268SToomas Soome uint64_t vimp_bytes_mapped; 1574*b1b93268SToomas Soome uint64_t vimp_num_entries; /* number of v_i_m_entry_phys_t's */ 1575*b1b93268SToomas Soome 1576*b1b93268SToomas Soome /* 1577*b1b93268SToomas Soome * For each entry in the mapping object, this object contains an 1578*b1b93268SToomas Soome * entry representing the number of bytes of that mapping entry 1579*b1b93268SToomas Soome * that were no longer in use by the pool at the time this indirect 1580*b1b93268SToomas Soome * vdev was last condensed. 1581*b1b93268SToomas Soome */ 1582*b1b93268SToomas Soome uint64_t vimp_counts_object; 1583*b1b93268SToomas Soome } vdev_indirect_mapping_phys_t; 1584*b1b93268SToomas Soome 1585*b1b93268SToomas Soome #define VDEV_INDIRECT_MAPPING_SIZE_V0 (3 * sizeof (uint64_t)) 1586*b1b93268SToomas Soome 1587*b1b93268SToomas Soome typedef struct vdev_indirect_mapping { 1588*b1b93268SToomas Soome uint64_t vim_object; 1589*b1b93268SToomas Soome boolean_t vim_havecounts; 1590*b1b93268SToomas Soome 1591*b1b93268SToomas Soome /* vim_entries segment offset currently in memory. */ 1592*b1b93268SToomas Soome uint64_t vim_entry_offset; 1593*b1b93268SToomas Soome /* vim_entries segment size. */ 1594*b1b93268SToomas Soome size_t vim_num_entries; 1595*b1b93268SToomas Soome 1596*b1b93268SToomas Soome /* Needed by dnode_read() */ 1597*b1b93268SToomas Soome const void *vim_spa; 1598*b1b93268SToomas Soome dnode_phys_t *vim_dn; 1599*b1b93268SToomas Soome 1600*b1b93268SToomas Soome /* 1601*b1b93268SToomas Soome * An ordered array of mapping entries, sorted by source offset. 1602*b1b93268SToomas Soome * Note that vim_entries is needed during a removal (and contains 1603*b1b93268SToomas Soome * mappings that have been synced to disk so far) to handle frees 1604*b1b93268SToomas Soome * from the removing device. 1605*b1b93268SToomas Soome */ 1606*b1b93268SToomas Soome vdev_indirect_mapping_entry_phys_t *vim_entries; 1607*b1b93268SToomas Soome objset_phys_t *vim_objset; 1608*b1b93268SToomas Soome vdev_indirect_mapping_phys_t *vim_phys; 1609*b1b93268SToomas Soome } vdev_indirect_mapping_t; 1610*b1b93268SToomas Soome 1611*b1b93268SToomas Soome /* 1612*b1b93268SToomas Soome * On-disk indirect vdev state. 1613*b1b93268SToomas Soome * 1614*b1b93268SToomas Soome * An indirect vdev is described exclusively in the MOS config of a pool. 1615*b1b93268SToomas Soome * The config for an indirect vdev includes several fields, which are 1616*b1b93268SToomas Soome * accessed in memory by a vdev_indirect_config_t. 1617*b1b93268SToomas Soome */ 1618*b1b93268SToomas Soome typedef struct vdev_indirect_config { 1619*b1b93268SToomas Soome /* 1620*b1b93268SToomas Soome * Object (in MOS) which contains the indirect mapping. This object 1621*b1b93268SToomas Soome * contains an array of vdev_indirect_mapping_entry_phys_t ordered by 1622*b1b93268SToomas Soome * vimep_src. The bonus buffer for this object is a 1623*b1b93268SToomas Soome * vdev_indirect_mapping_phys_t. This object is allocated when a vdev 1624*b1b93268SToomas Soome * removal is initiated. 1625*b1b93268SToomas Soome * 1626*b1b93268SToomas Soome * Note that this object can be empty if none of the data on the vdev 1627*b1b93268SToomas Soome * has been copied yet. 1628*b1b93268SToomas Soome */ 1629*b1b93268SToomas Soome uint64_t vic_mapping_object; 1630*b1b93268SToomas Soome 1631*b1b93268SToomas Soome /* 1632*b1b93268SToomas Soome * Object (in MOS) which contains the birth times for the mapping 1633*b1b93268SToomas Soome * entries. This object contains an array of 1634*b1b93268SToomas Soome * vdev_indirect_birth_entry_phys_t sorted by vibe_offset. The bonus 1635*b1b93268SToomas Soome * buffer for this object is a vdev_indirect_birth_phys_t. This object 1636*b1b93268SToomas Soome * is allocated when a vdev removal is initiated. 1637*b1b93268SToomas Soome * 1638*b1b93268SToomas Soome * Note that this object can be empty if none of the vdev has yet been 1639*b1b93268SToomas Soome * copied. 1640*b1b93268SToomas Soome */ 1641*b1b93268SToomas Soome uint64_t vic_births_object; 1642*b1b93268SToomas Soome 1643*b1b93268SToomas Soome /* 1644*b1b93268SToomas Soome * This is the vdev ID which was removed previous to this vdev, or 1645*b1b93268SToomas Soome * UINT64_MAX if there are no previously removed vdevs. 1646*b1b93268SToomas Soome */ 1647*b1b93268SToomas Soome uint64_t vic_prev_indirect_vdev; 1648*b1b93268SToomas Soome } vdev_indirect_config_t; 1649*b1b93268SToomas Soome 16501ba4a712SPawel Jakub Dawidek typedef struct vdev { 16511ba4a712SPawel Jakub Dawidek STAILQ_ENTRY(vdev) v_childlink; /* link in parent's child list */ 16521ba4a712SPawel Jakub Dawidek STAILQ_ENTRY(vdev) v_alllink; /* link in global vdev list */ 16531ba4a712SPawel Jakub Dawidek vdev_list_t v_children; /* children of this vdev */ 165410b9d77bSPawel Jakub Dawidek const char *v_name; /* vdev name */ 16551ba4a712SPawel Jakub Dawidek uint64_t v_guid; /* vdev guid */ 16561ba4a712SPawel Jakub Dawidek int v_id; /* index in parent */ 1657e1899ef6SDoug Rabson int v_ashift; /* offset to block shift */ 1658e1899ef6SDoug Rabson int v_nparity; /* # parity for raidz */ 165910b9d77bSPawel Jakub Dawidek struct vdev *v_top; /* parent vdev */ 1660e1899ef6SDoug Rabson int v_nchildren; /* # children */ 16611ba4a712SPawel Jakub Dawidek vdev_state_t v_state; /* current state */ 1662e1899ef6SDoug Rabson vdev_phys_read_t *v_phys_read; /* read from raw leaf vdev */ 1663e1899ef6SDoug Rabson vdev_read_t *v_read; /* read from vdev */ 16641ba4a712SPawel Jakub Dawidek void *v_read_priv; /* private data for read function */ 16652c55d090SToomas Soome struct spa *spa; /* link to spa */ 1666*b1b93268SToomas Soome /* 1667*b1b93268SToomas Soome * Values stored in the config for an indirect or removing vdev. 1668*b1b93268SToomas Soome */ 1669*b1b93268SToomas Soome vdev_indirect_config_t vdev_indirect_config; 1670*b1b93268SToomas Soome vdev_indirect_mapping_t *v_mapping; 16711ba4a712SPawel Jakub Dawidek } vdev_t; 16721ba4a712SPawel Jakub Dawidek 16731ba4a712SPawel Jakub Dawidek /* 16741ba4a712SPawel Jakub Dawidek * In-core pool representation. 16751ba4a712SPawel Jakub Dawidek */ 16761ba4a712SPawel Jakub Dawidek typedef STAILQ_HEAD(spa_list, spa) spa_list_t; 16771ba4a712SPawel Jakub Dawidek 16781ba4a712SPawel Jakub Dawidek typedef struct spa { 16791ba4a712SPawel Jakub Dawidek STAILQ_ENTRY(spa) spa_link; /* link in global pool list */ 16801ba4a712SPawel Jakub Dawidek char *spa_name; /* pool name */ 16811ba4a712SPawel Jakub Dawidek uint64_t spa_guid; /* pool guid */ 16821ba4a712SPawel Jakub Dawidek uint64_t spa_txg; /* most recent transaction */ 16831ba4a712SPawel Jakub Dawidek struct uberblock spa_uberblock; /* best uberblock so far */ 16841ba4a712SPawel Jakub Dawidek vdev_list_t spa_vdevs; /* list of all toplevel vdevs */ 16851ba4a712SPawel Jakub Dawidek objset_phys_t spa_mos; /* MOS for this pool */ 16862c55d090SToomas Soome zio_cksum_salt_t spa_cksum_salt; /* secret salt for cksum */ 16872c55d090SToomas Soome void *spa_cksum_tmpls[ZIO_CHECKSUM_FUNCTIONS]; 16889da75f3aSAndriy Gapon int spa_inited; /* initialized */ 16891ba4a712SPawel Jakub Dawidek } spa_t; 169029441ba3SXin LI 1691*b1b93268SToomas Soome /* IO related arguments. */ 1692*b1b93268SToomas Soome typedef struct zio { 1693*b1b93268SToomas Soome spa_t *io_spa; 1694*b1b93268SToomas Soome blkptr_t *io_bp; 1695*b1b93268SToomas Soome void *io_data; 1696*b1b93268SToomas Soome uint64_t io_size; 1697*b1b93268SToomas Soome uint64_t io_offset; 1698*b1b93268SToomas Soome 1699*b1b93268SToomas Soome /* Stuff for the vdev stack */ 1700*b1b93268SToomas Soome vdev_t *io_vd; 1701*b1b93268SToomas Soome void *io_vsd; 1702*b1b93268SToomas Soome 1703*b1b93268SToomas Soome int io_error; 1704*b1b93268SToomas Soome } zio_t; 1705*b1b93268SToomas Soome 170629441ba3SXin LI static void decode_embedded_bp_compressed(const blkptr_t *, void *); 1707