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 /* 593830659eSToomas Soome * Copyright (c) 2020 by Delphix. All rights reserved. 6029441ba3SXin LI */ 611ba4a712SPawel Jakub Dawidek 623830659eSToomas Soome #include <sys/queue.h> 633830659eSToomas Soome 643830659eSToomas Soome #ifndef _ZFSIMPL_H_ 653830659eSToomas Soome #define _ZFSIMPL_H_ 663830659eSToomas Soome 672d9cf57eSMartin Matuska #define MAXNAMELEN 256 682d9cf57eSMartin Matuska 6929441ba3SXin LI #define _NOTE(s) 7029441ba3SXin LI 7179a4bf89SToomas Soome /* 7279a4bf89SToomas Soome * AVL comparator helpers 7379a4bf89SToomas Soome */ 7479a4bf89SToomas Soome #define AVL_ISIGN(a) (((a) > 0) - ((a) < 0)) 7579a4bf89SToomas Soome #define AVL_CMP(a, b) (((a) > (b)) - ((a) < (b))) 7679a4bf89SToomas Soome #define AVL_PCMP(a, b) \ 7779a4bf89SToomas Soome (((uintptr_t)(a) > (uintptr_t)(b)) - ((uintptr_t)(a) < (uintptr_t)(b))) 7879a4bf89SToomas Soome 794deb8929SAllan Jude typedef enum { B_FALSE, B_TRUE } boolean_t; 804deb8929SAllan Jude 811ba4a712SPawel Jakub Dawidek /* CRC64 table */ 821ba4a712SPawel Jakub Dawidek #define ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */ 831ba4a712SPawel Jakub Dawidek 841ba4a712SPawel Jakub Dawidek /* 851ba4a712SPawel Jakub Dawidek * Macros for various sorts of alignment and rounding when the alignment 861ba4a712SPawel Jakub Dawidek * is known to be a power of 2. 871ba4a712SPawel Jakub Dawidek */ 881ba4a712SPawel Jakub Dawidek #define P2ALIGN(x, align) ((x) & -(align)) 891ba4a712SPawel Jakub Dawidek #define P2PHASE(x, align) ((x) & ((align) - 1)) 901ba4a712SPawel Jakub Dawidek #define P2NPHASE(x, align) (-(x) & ((align) - 1)) 911ba4a712SPawel Jakub Dawidek #define P2ROUNDUP(x, align) (-(-(x) & -(align))) 921ba4a712SPawel Jakub Dawidek #define P2END(x, align) (-(~(x) & -(align))) 931ba4a712SPawel Jakub Dawidek #define P2PHASEUP(x, align, phase) ((phase) - (((phase) - (x)) & -(align))) 94c43d127aSMartin Matuska #define P2BOUNDARY(off, len, align) (((off) ^ ((off) + (len) - 1)) > (align) - 1) 951ba4a712SPawel Jakub Dawidek 961ba4a712SPawel Jakub Dawidek /* 971ba4a712SPawel Jakub Dawidek * General-purpose 32-bit and 64-bit bitfield encodings. 981ba4a712SPawel Jakub Dawidek */ 991ba4a712SPawel Jakub Dawidek #define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len)) 1001ba4a712SPawel Jakub Dawidek #define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len)) 1011ba4a712SPawel Jakub Dawidek #define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low)) 1021ba4a712SPawel Jakub Dawidek #define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low)) 1031ba4a712SPawel Jakub Dawidek 1041ba4a712SPawel Jakub Dawidek #define BF32_GET(x, low, len) BF32_DECODE(x, low, len) 1051ba4a712SPawel Jakub Dawidek #define BF64_GET(x, low, len) BF64_DECODE(x, low, len) 1061ba4a712SPawel Jakub Dawidek 1071ba4a712SPawel Jakub Dawidek #define BF32_SET(x, low, len, val) \ 1081ba4a712SPawel Jakub Dawidek ((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len)) 1091ba4a712SPawel Jakub Dawidek #define BF64_SET(x, low, len, val) \ 1101ba4a712SPawel Jakub Dawidek ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len)) 1111ba4a712SPawel Jakub Dawidek 1121ba4a712SPawel Jakub Dawidek #define BF32_GET_SB(x, low, len, shift, bias) \ 1131ba4a712SPawel Jakub Dawidek ((BF32_GET(x, low, len) + (bias)) << (shift)) 1141ba4a712SPawel Jakub Dawidek #define BF64_GET_SB(x, low, len, shift, bias) \ 1151ba4a712SPawel Jakub Dawidek ((BF64_GET(x, low, len) + (bias)) << (shift)) 1161ba4a712SPawel Jakub Dawidek 1171ba4a712SPawel Jakub Dawidek #define BF32_SET_SB(x, low, len, shift, bias, val) \ 1181ba4a712SPawel Jakub Dawidek BF32_SET(x, low, len, ((val) >> (shift)) - (bias)) 1191ba4a712SPawel Jakub Dawidek #define BF64_SET_SB(x, low, len, shift, bias, val) \ 1201ba4a712SPawel Jakub Dawidek BF64_SET(x, low, len, ((val) >> (shift)) - (bias)) 1211ba4a712SPawel Jakub Dawidek 1221ba4a712SPawel Jakub Dawidek /* 12310b9d77bSPawel Jakub Dawidek * Macros to reverse byte order 12410b9d77bSPawel Jakub Dawidek */ 12510b9d77bSPawel Jakub Dawidek #define BSWAP_8(x) ((x) & 0xff) 12610b9d77bSPawel Jakub Dawidek #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8)) 12710b9d77bSPawel Jakub Dawidek #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16)) 12810b9d77bSPawel Jakub Dawidek #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32)) 12910b9d77bSPawel Jakub Dawidek 1301ba4a712SPawel Jakub Dawidek #define SPA_MINBLOCKSHIFT 9 1312c55d090SToomas Soome #define SPA_OLDMAXBLOCKSHIFT 17 1322c55d090SToomas Soome #define SPA_MAXBLOCKSHIFT 24 1331ba4a712SPawel Jakub Dawidek #define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT) 1342c55d090SToomas Soome #define SPA_OLDMAXBLOCKSIZE (1ULL << SPA_OLDMAXBLOCKSHIFT) 1351ba4a712SPawel Jakub Dawidek #define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT) 1361ba4a712SPawel Jakub Dawidek 1371ba4a712SPawel Jakub Dawidek /* 1381ba4a712SPawel Jakub Dawidek * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB. 1391ba4a712SPawel Jakub Dawidek * The ASIZE encoding should be at least 64 times larger (6 more bits) 1401ba4a712SPawel Jakub Dawidek * to support up to 4-way RAID-Z mirror mode with worst-case gang block 1411ba4a712SPawel Jakub Dawidek * overhead, three DVAs per bp, plus one more bit in case we do anything 1421ba4a712SPawel Jakub Dawidek * else that expands the ASIZE. 1431ba4a712SPawel Jakub Dawidek */ 1441ba4a712SPawel Jakub Dawidek #define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */ 1451ba4a712SPawel Jakub Dawidek #define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */ 1461ba4a712SPawel Jakub Dawidek #define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */ 1471ba4a712SPawel Jakub Dawidek 1481ba4a712SPawel Jakub Dawidek /* 1491ba4a712SPawel Jakub Dawidek * All SPA data is represented by 128-bit data virtual addresses (DVAs). 1501ba4a712SPawel Jakub Dawidek * The members of the dva_t should be considered opaque outside the SPA. 1511ba4a712SPawel Jakub Dawidek */ 1521ba4a712SPawel Jakub Dawidek typedef struct dva { 1531ba4a712SPawel Jakub Dawidek uint64_t dva_word[2]; 1541ba4a712SPawel Jakub Dawidek } dva_t; 1551ba4a712SPawel Jakub Dawidek 1561ba4a712SPawel Jakub Dawidek /* 1571ba4a712SPawel Jakub Dawidek * Each block has a 256-bit checksum -- strong enough for cryptographic hashes. 1581ba4a712SPawel Jakub Dawidek */ 1591ba4a712SPawel Jakub Dawidek typedef struct zio_cksum { 1601ba4a712SPawel Jakub Dawidek uint64_t zc_word[4]; 1611ba4a712SPawel Jakub Dawidek } zio_cksum_t; 1621ba4a712SPawel Jakub Dawidek 1631ba4a712SPawel Jakub Dawidek /* 1642c55d090SToomas Soome * Some checksums/hashes need a 256-bit initialization salt. This salt is kept 1652c55d090SToomas Soome * secret and is suitable for use in MAC algorithms as the key. 1662c55d090SToomas Soome */ 1672c55d090SToomas Soome typedef struct zio_cksum_salt { 1682c55d090SToomas Soome uint8_t zcs_bytes[32]; 1692c55d090SToomas Soome } zio_cksum_salt_t; 1702c55d090SToomas Soome 1712c55d090SToomas Soome /* 1721ba4a712SPawel Jakub Dawidek * Each block is described by its DVAs, time of birth, checksum, etc. 1731ba4a712SPawel Jakub Dawidek * The word-by-word, bit-by-bit layout of the blkptr is as follows: 1741ba4a712SPawel Jakub Dawidek * 1751ba4a712SPawel Jakub Dawidek * 64 56 48 40 32 24 16 8 0 1761ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1771ba4a712SPawel Jakub Dawidek * 0 | vdev1 | GRID | ASIZE | 1781ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1791ba4a712SPawel Jakub Dawidek * 1 |G| offset1 | 1801ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1811ba4a712SPawel Jakub Dawidek * 2 | vdev2 | GRID | ASIZE | 1821ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1831ba4a712SPawel Jakub Dawidek * 3 |G| offset2 | 1841ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1851ba4a712SPawel Jakub Dawidek * 4 | vdev3 | GRID | ASIZE | 1861ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1871ba4a712SPawel Jakub Dawidek * 5 |G| offset3 | 1881ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 18929441ba3SXin LI * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE | 1901ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1911ba4a712SPawel Jakub Dawidek * 7 | padding | 1921ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1931ba4a712SPawel Jakub Dawidek * 8 | padding | 1941ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 19510b9d77bSPawel Jakub Dawidek * 9 | physical birth txg | 1961ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 19710b9d77bSPawel Jakub Dawidek * a | logical birth txg | 1981ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1991ba4a712SPawel Jakub Dawidek * b | fill count | 2001ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 2011ba4a712SPawel Jakub Dawidek * c | checksum[0] | 2021ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 2031ba4a712SPawel Jakub Dawidek * d | checksum[1] | 2041ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 2051ba4a712SPawel Jakub Dawidek * e | checksum[2] | 2061ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 2071ba4a712SPawel Jakub Dawidek * f | checksum[3] | 2081ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 2091ba4a712SPawel Jakub Dawidek * 2101ba4a712SPawel Jakub Dawidek * Legend: 2111ba4a712SPawel Jakub Dawidek * 2121ba4a712SPawel Jakub Dawidek * vdev virtual device ID 2131ba4a712SPawel Jakub Dawidek * offset offset into virtual device 2141ba4a712SPawel Jakub Dawidek * LSIZE logical size 2151ba4a712SPawel Jakub Dawidek * PSIZE physical size (after compression) 2161ba4a712SPawel Jakub Dawidek * ASIZE allocated size (including RAID-Z parity and gang block headers) 2171ba4a712SPawel Jakub Dawidek * GRID RAID-Z layout information (reserved for future use) 2181ba4a712SPawel Jakub Dawidek * cksum checksum function 2191ba4a712SPawel Jakub Dawidek * comp compression function 2201ba4a712SPawel Jakub Dawidek * G gang block indicator 22110b9d77bSPawel Jakub Dawidek * B byteorder (endianness) 22210b9d77bSPawel Jakub Dawidek * D dedup 22329441ba3SXin LI * X encryption (on version 30, which is not supported) 22429441ba3SXin LI * E blkptr_t contains embedded data (see below) 2251ba4a712SPawel Jakub Dawidek * lvl level of indirection 22610b9d77bSPawel Jakub Dawidek * type DMU object type 22710b9d77bSPawel Jakub Dawidek * phys birth txg of block allocation; zero if same as logical birth txg 22810b9d77bSPawel Jakub Dawidek * log. birth transaction group in which the block was logically born 2291ba4a712SPawel Jakub Dawidek * fill count number of non-zero blocks under this bp 2301ba4a712SPawel Jakub Dawidek * checksum[4] 256-bit checksum of the data this bp describes 2311ba4a712SPawel Jakub Dawidek */ 23229441ba3SXin LI 23329441ba3SXin LI /* 23429441ba3SXin LI * "Embedded" blkptr_t's don't actually point to a block, instead they 23529441ba3SXin LI * have a data payload embedded in the blkptr_t itself. See the comment 23629441ba3SXin LI * in blkptr.c for more details. 23729441ba3SXin LI * 23829441ba3SXin LI * The blkptr_t is laid out as follows: 23929441ba3SXin LI * 24029441ba3SXin LI * 64 56 48 40 32 24 16 8 0 24129441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 24229441ba3SXin LI * 0 | payload | 24329441ba3SXin LI * 1 | payload | 24429441ba3SXin LI * 2 | payload | 24529441ba3SXin LI * 3 | payload | 24629441ba3SXin LI * 4 | payload | 24729441ba3SXin LI * 5 | payload | 24829441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 24929441ba3SXin LI * 6 |BDX|lvl| type | etype |E| comp| PSIZE| LSIZE | 25029441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 25129441ba3SXin LI * 7 | payload | 25229441ba3SXin LI * 8 | payload | 25329441ba3SXin LI * 9 | payload | 25429441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 25529441ba3SXin LI * a | logical birth txg | 25629441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 25729441ba3SXin LI * b | payload | 25829441ba3SXin LI * c | payload | 25929441ba3SXin LI * d | payload | 26029441ba3SXin LI * e | payload | 26129441ba3SXin LI * f | payload | 26229441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 26329441ba3SXin LI * 26429441ba3SXin LI * Legend: 26529441ba3SXin LI * 26629441ba3SXin LI * payload contains the embedded data 26729441ba3SXin LI * B (byteorder) byteorder (endianness) 26829441ba3SXin LI * D (dedup) padding (set to zero) 26929441ba3SXin LI * X encryption (set to zero; see above) 27029441ba3SXin LI * E (embedded) set to one 27129441ba3SXin LI * lvl indirection level 27229441ba3SXin LI * type DMU object type 27329441ba3SXin LI * etype how to interpret embedded data (BP_EMBEDDED_TYPE_*) 27429441ba3SXin LI * comp compression function of payload 27529441ba3SXin LI * PSIZE size of payload after compression, in bytes 27629441ba3SXin LI * LSIZE logical size of payload, in bytes 27729441ba3SXin LI * note that 25 bits is enough to store the largest 27829441ba3SXin LI * "normal" BP's LSIZE (2^16 * 2^9) in bytes 27929441ba3SXin LI * log. birth transaction group in which the block was logically born 28029441ba3SXin LI * 28129441ba3SXin LI * Note that LSIZE and PSIZE are stored in bytes, whereas for non-embedded 28229441ba3SXin LI * bp's they are stored in units of SPA_MINBLOCKSHIFT. 28329441ba3SXin LI * Generally, the generic BP_GET_*() macros can be used on embedded BP's. 28429441ba3SXin LI * The B, D, X, lvl, type, and comp fields are stored the same as with normal 28529441ba3SXin LI * BP's so the BP_SET_* macros can be used with them. etype, PSIZE, LSIZE must 28629441ba3SXin LI * be set with the BPE_SET_* macros. BP_SET_EMBEDDED() should be called before 28729441ba3SXin LI * other macros, as they assert that they are only used on BP's of the correct 28829441ba3SXin LI * "embedded-ness". 28929441ba3SXin LI */ 29029441ba3SXin LI 29129441ba3SXin LI #define BPE_GET_ETYPE(bp) \ 29229441ba3SXin LI (ASSERT(BP_IS_EMBEDDED(bp)), \ 29329441ba3SXin LI BF64_GET((bp)->blk_prop, 40, 8)) 29429441ba3SXin LI #define BPE_SET_ETYPE(bp, t) do { \ 29529441ba3SXin LI ASSERT(BP_IS_EMBEDDED(bp)); \ 29629441ba3SXin LI BF64_SET((bp)->blk_prop, 40, 8, t); \ 29729441ba3SXin LI _NOTE(CONSTCOND) } while (0) 29829441ba3SXin LI 29929441ba3SXin LI #define BPE_GET_LSIZE(bp) \ 30029441ba3SXin LI (ASSERT(BP_IS_EMBEDDED(bp)), \ 30129441ba3SXin LI BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1)) 30229441ba3SXin LI #define BPE_SET_LSIZE(bp, x) do { \ 30329441ba3SXin LI ASSERT(BP_IS_EMBEDDED(bp)); \ 30429441ba3SXin LI BF64_SET_SB((bp)->blk_prop, 0, 25, 0, 1, x); \ 30529441ba3SXin LI _NOTE(CONSTCOND) } while (0) 30629441ba3SXin LI 30729441ba3SXin LI #define BPE_GET_PSIZE(bp) \ 30829441ba3SXin LI (ASSERT(BP_IS_EMBEDDED(bp)), \ 30929441ba3SXin LI BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1)) 31029441ba3SXin LI #define BPE_SET_PSIZE(bp, x) do { \ 31129441ba3SXin LI ASSERT(BP_IS_EMBEDDED(bp)); \ 31229441ba3SXin LI BF64_SET_SB((bp)->blk_prop, 25, 7, 0, 1, x); \ 31329441ba3SXin LI _NOTE(CONSTCOND) } while (0) 31429441ba3SXin LI 31529441ba3SXin LI typedef enum bp_embedded_type { 31629441ba3SXin LI BP_EMBEDDED_TYPE_DATA, 31729441ba3SXin LI BP_EMBEDDED_TYPE_RESERVED, /* Reserved for an unintegrated feature. */ 31829441ba3SXin LI NUM_BP_EMBEDDED_TYPES = BP_EMBEDDED_TYPE_RESERVED 31929441ba3SXin LI } bp_embedded_type_t; 32029441ba3SXin LI 32129441ba3SXin LI #define BPE_NUM_WORDS 14 32229441ba3SXin LI #define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t)) 32329441ba3SXin LI #define BPE_IS_PAYLOADWORD(bp, wp) \ 32429441ba3SXin LI ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth) 32529441ba3SXin LI 32610b9d77bSPawel Jakub Dawidek #define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */ 32710b9d77bSPawel Jakub Dawidek #define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */ 32810b9d77bSPawel Jakub Dawidek 3291ba4a712SPawel Jakub Dawidek typedef struct blkptr { 33010b9d77bSPawel Jakub Dawidek dva_t blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */ 3311ba4a712SPawel Jakub Dawidek uint64_t blk_prop; /* size, compression, type, etc */ 33210b9d77bSPawel Jakub Dawidek uint64_t blk_pad[2]; /* Extra space for the future */ 33310b9d77bSPawel Jakub Dawidek uint64_t blk_phys_birth; /* txg when block was allocated */ 3341ba4a712SPawel Jakub Dawidek uint64_t blk_birth; /* transaction group at birth */ 3351ba4a712SPawel Jakub Dawidek uint64_t blk_fill; /* fill count */ 3361ba4a712SPawel Jakub Dawidek zio_cksum_t blk_cksum; /* 256-bit checksum */ 3371ba4a712SPawel Jakub Dawidek } blkptr_t; 3381ba4a712SPawel Jakub Dawidek 3391ba4a712SPawel Jakub Dawidek /* 3401ba4a712SPawel Jakub Dawidek * Macros to get and set fields in a bp or DVA. 3411ba4a712SPawel Jakub Dawidek */ 3421ba4a712SPawel Jakub Dawidek #define DVA_GET_ASIZE(dva) \ 343f4c8ba83SXin LI BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0) 3441ba4a712SPawel Jakub Dawidek #define DVA_SET_ASIZE(dva, x) \ 345f4c8ba83SXin LI BF64_SET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, \ 346f4c8ba83SXin LI SPA_MINBLOCKSHIFT, 0, x) 3471ba4a712SPawel Jakub Dawidek 3481ba4a712SPawel Jakub Dawidek #define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8) 3491ba4a712SPawel Jakub Dawidek #define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x) 3501ba4a712SPawel Jakub Dawidek 3511ba4a712SPawel Jakub Dawidek #define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, 32) 3521ba4a712SPawel Jakub Dawidek #define DVA_SET_VDEV(dva, x) BF64_SET((dva)->dva_word[0], 32, 32, x) 3531ba4a712SPawel Jakub Dawidek 3541ba4a712SPawel Jakub Dawidek #define DVA_GET_OFFSET(dva) \ 3551ba4a712SPawel Jakub Dawidek BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0) 3561ba4a712SPawel Jakub Dawidek #define DVA_SET_OFFSET(dva, x) \ 3571ba4a712SPawel Jakub Dawidek BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x) 3581ba4a712SPawel Jakub Dawidek 3591ba4a712SPawel Jakub Dawidek #define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1) 3601ba4a712SPawel Jakub Dawidek #define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x) 3611ba4a712SPawel Jakub Dawidek 3621ba4a712SPawel Jakub Dawidek #define BP_GET_LSIZE(bp) \ 36329441ba3SXin LI (BP_IS_EMBEDDED(bp) ? \ 36429441ba3SXin LI (BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA ? BPE_GET_LSIZE(bp) : 0): \ 365f4c8ba83SXin LI BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1)) 36629441ba3SXin LI #define BP_SET_LSIZE(bp, x) do { \ 36729441ba3SXin LI ASSERT(!BP_IS_EMBEDDED(bp)); \ 36829441ba3SXin LI BF64_SET_SB((bp)->blk_prop, \ 36929441ba3SXin LI 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \ 37029441ba3SXin LI _NOTE(CONSTCOND) } while (0) 3711ba4a712SPawel Jakub Dawidek 3721ba4a712SPawel Jakub Dawidek #define BP_GET_PSIZE(bp) \ 373f4c8ba83SXin LI BF64_GET_SB((bp)->blk_prop, 16, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1) 3741ba4a712SPawel Jakub Dawidek #define BP_SET_PSIZE(bp, x) \ 375f4c8ba83SXin LI BF64_SET_SB((bp)->blk_prop, 16, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x) 3761ba4a712SPawel Jakub Dawidek 37729441ba3SXin LI #define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 7) 37829441ba3SXin LI #define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 7, x) 3791ba4a712SPawel Jakub Dawidek 3801ba4a712SPawel Jakub Dawidek #define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8) 3811ba4a712SPawel Jakub Dawidek #define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x) 3821ba4a712SPawel Jakub Dawidek 3831ba4a712SPawel Jakub Dawidek #define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8) 3841ba4a712SPawel Jakub Dawidek #define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x) 3851ba4a712SPawel Jakub Dawidek 3861ba4a712SPawel Jakub Dawidek #define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5) 3871ba4a712SPawel Jakub Dawidek #define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x) 3881ba4a712SPawel Jakub Dawidek 38929441ba3SXin LI #define BP_IS_EMBEDDED(bp) BF64_GET((bp)->blk_prop, 39, 1) 39029441ba3SXin LI 39110b9d77bSPawel Jakub Dawidek #define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1) 39210b9d77bSPawel Jakub Dawidek #define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x) 39310b9d77bSPawel Jakub Dawidek 394f4c8ba83SXin LI #define BP_GET_BYTEORDER(bp) BF64_GET((bp)->blk_prop, 63, 1) 3951ba4a712SPawel Jakub Dawidek #define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x) 3961ba4a712SPawel Jakub Dawidek 39710b9d77bSPawel Jakub Dawidek #define BP_PHYSICAL_BIRTH(bp) \ 39810b9d77bSPawel Jakub Dawidek ((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth) 39910b9d77bSPawel Jakub Dawidek 400*77649f35SMark Johnston #define BP_SET_BIRTH(bp, logical, physical) \ 401*77649f35SMark Johnston { \ 402*77649f35SMark Johnston ASSERT(!BP_IS_EMBEDDED(bp)); \ 403*77649f35SMark Johnston (bp)->blk_birth = (logical); \ 404*77649f35SMark Johnston (bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \ 405*77649f35SMark Johnston } 406*77649f35SMark Johnston 407*77649f35SMark Johnston #define BP_GET_FILL(bp) \ 408*77649f35SMark Johnston ((BP_IS_EMBEDDED(bp)) ? 1 : (bp)->blk_fill) 409*77649f35SMark Johnston 410*77649f35SMark Johnston #define BP_SET_FILL(bp, fill) \ 411*77649f35SMark Johnston { \ 412*77649f35SMark Johnston (bp)->blk_fill = fill; \ 413*77649f35SMark Johnston } 414*77649f35SMark Johnston 4151ba4a712SPawel Jakub Dawidek #define BP_GET_ASIZE(bp) \ 4161ba4a712SPawel Jakub Dawidek (DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ 4171ba4a712SPawel Jakub Dawidek DVA_GET_ASIZE(&(bp)->blk_dva[2])) 4181ba4a712SPawel Jakub Dawidek 4191ba4a712SPawel Jakub Dawidek #define BP_GET_UCSIZE(bp) \ 4201ba4a712SPawel Jakub Dawidek ((BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) ? \ 4211ba4a712SPawel Jakub Dawidek BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp)); 4221ba4a712SPawel Jakub Dawidek 4231ba4a712SPawel Jakub Dawidek #define BP_GET_NDVAS(bp) \ 4241ba4a712SPawel Jakub Dawidek (!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \ 4251ba4a712SPawel Jakub Dawidek !!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ 4261ba4a712SPawel Jakub Dawidek !!DVA_GET_ASIZE(&(bp)->blk_dva[2])) 4271ba4a712SPawel Jakub Dawidek 4281ba4a712SPawel Jakub Dawidek #define DVA_EQUAL(dva1, dva2) \ 4291ba4a712SPawel Jakub Dawidek ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \ 4301ba4a712SPawel Jakub Dawidek (dva1)->dva_word[0] == (dva2)->dva_word[0]) 4311ba4a712SPawel Jakub Dawidek 4321ba4a712SPawel Jakub Dawidek #define ZIO_CHECKSUM_EQUAL(zc1, zc2) \ 4331ba4a712SPawel Jakub Dawidek (0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \ 4341ba4a712SPawel Jakub Dawidek ((zc1).zc_word[1] - (zc2).zc_word[1]) | \ 4351ba4a712SPawel Jakub Dawidek ((zc1).zc_word[2] - (zc2).zc_word[2]) | \ 4361ba4a712SPawel Jakub Dawidek ((zc1).zc_word[3] - (zc2).zc_word[3]))) 4371ba4a712SPawel Jakub Dawidek 4381ba4a712SPawel Jakub Dawidek 4391ba4a712SPawel Jakub Dawidek #define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0) 4401ba4a712SPawel Jakub Dawidek 4411ba4a712SPawel Jakub Dawidek #define ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3) \ 4421ba4a712SPawel Jakub Dawidek { \ 4431ba4a712SPawel Jakub Dawidek (zcp)->zc_word[0] = w0; \ 4441ba4a712SPawel Jakub Dawidek (zcp)->zc_word[1] = w1; \ 4451ba4a712SPawel Jakub Dawidek (zcp)->zc_word[2] = w2; \ 4461ba4a712SPawel Jakub Dawidek (zcp)->zc_word[3] = w3; \ 4471ba4a712SPawel Jakub Dawidek } 4481ba4a712SPawel Jakub Dawidek 4491ba4a712SPawel Jakub Dawidek #define BP_IDENTITY(bp) (&(bp)->blk_dva[0]) 4501ba4a712SPawel Jakub Dawidek #define BP_IS_GANG(bp) DVA_GET_GANG(BP_IDENTITY(bp)) 451f4c8ba83SXin LI #define DVA_IS_EMPTY(dva) ((dva)->dva_word[0] == 0ULL && \ 452f4c8ba83SXin LI (dva)->dva_word[1] == 0ULL) 453f4c8ba83SXin LI #define BP_IS_HOLE(bp) DVA_IS_EMPTY(BP_IDENTITY(bp)) 4541ba4a712SPawel Jakub Dawidek #define BP_IS_OLDER(bp, txg) (!BP_IS_HOLE(bp) && (bp)->blk_birth < (txg)) 4551ba4a712SPawel Jakub Dawidek 4561ba4a712SPawel Jakub Dawidek #define BP_ZERO(bp) \ 4571ba4a712SPawel Jakub Dawidek { \ 4581ba4a712SPawel Jakub Dawidek (bp)->blk_dva[0].dva_word[0] = 0; \ 4591ba4a712SPawel Jakub Dawidek (bp)->blk_dva[0].dva_word[1] = 0; \ 4601ba4a712SPawel Jakub Dawidek (bp)->blk_dva[1].dva_word[0] = 0; \ 4611ba4a712SPawel Jakub Dawidek (bp)->blk_dva[1].dva_word[1] = 0; \ 4621ba4a712SPawel Jakub Dawidek (bp)->blk_dva[2].dva_word[0] = 0; \ 4631ba4a712SPawel Jakub Dawidek (bp)->blk_dva[2].dva_word[1] = 0; \ 4641ba4a712SPawel Jakub Dawidek (bp)->blk_prop = 0; \ 4651ba4a712SPawel Jakub Dawidek (bp)->blk_pad[0] = 0; \ 4661ba4a712SPawel Jakub Dawidek (bp)->blk_pad[1] = 0; \ 46710b9d77bSPawel Jakub Dawidek (bp)->blk_phys_birth = 0; \ 4681ba4a712SPawel Jakub Dawidek (bp)->blk_birth = 0; \ 4691ba4a712SPawel Jakub Dawidek (bp)->blk_fill = 0; \ 4701ba4a712SPawel Jakub Dawidek ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \ 4711ba4a712SPawel Jakub Dawidek } 4721ba4a712SPawel Jakub Dawidek 473903fe2b7SToomas Soome #if BYTE_ORDER == _BIG_ENDIAN 474903fe2b7SToomas Soome #define ZFS_HOST_BYTEORDER (0ULL) 475903fe2b7SToomas Soome #else 476903fe2b7SToomas Soome #define ZFS_HOST_BYTEORDER (1ULL) 477903fe2b7SToomas Soome #endif 478903fe2b7SToomas Soome 479903fe2b7SToomas Soome #define BP_SHOULD_BYTESWAP(bp) (BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER) 48029441ba3SXin LI #define BPE_NUM_WORDS 14 48129441ba3SXin LI #define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t)) 48229441ba3SXin LI #define BPE_IS_PAYLOADWORD(bp, wp) \ 48329441ba3SXin LI ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth) 48429441ba3SXin LI 48510b9d77bSPawel Jakub Dawidek /* 48610b9d77bSPawel Jakub Dawidek * Embedded checksum 48710b9d77bSPawel Jakub Dawidek */ 48810b9d77bSPawel Jakub Dawidek #define ZEC_MAGIC 0x210da7ab10c7a11ULL 4891ba4a712SPawel Jakub Dawidek 49010b9d77bSPawel Jakub Dawidek typedef struct zio_eck { 49110b9d77bSPawel Jakub Dawidek uint64_t zec_magic; /* for validation, endianness */ 49210b9d77bSPawel Jakub Dawidek zio_cksum_t zec_cksum; /* 256-bit checksum */ 49310b9d77bSPawel Jakub Dawidek } zio_eck_t; 49410b9d77bSPawel Jakub Dawidek 49510b9d77bSPawel Jakub Dawidek /* 49610b9d77bSPawel Jakub Dawidek * Gang block headers are self-checksumming and contain an array 49710b9d77bSPawel Jakub Dawidek * of block pointers. 49810b9d77bSPawel Jakub Dawidek */ 49910b9d77bSPawel Jakub Dawidek #define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE 50010b9d77bSPawel Jakub Dawidek #define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \ 50110b9d77bSPawel Jakub Dawidek sizeof (zio_eck_t)) / sizeof (blkptr_t)) 50210b9d77bSPawel Jakub Dawidek #define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \ 50310b9d77bSPawel Jakub Dawidek sizeof (zio_eck_t) - \ 50410b9d77bSPawel Jakub Dawidek (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\ 50510b9d77bSPawel Jakub Dawidek sizeof (uint64_t)) 50610b9d77bSPawel Jakub Dawidek 50710b9d77bSPawel Jakub Dawidek typedef struct zio_gbh { 50810b9d77bSPawel Jakub Dawidek blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS]; 50910b9d77bSPawel Jakub Dawidek uint64_t zg_filler[SPA_GBH_FILLER]; 51010b9d77bSPawel Jakub Dawidek zio_eck_t zg_tail; 51110b9d77bSPawel Jakub Dawidek } zio_gbh_phys_t; 51210b9d77bSPawel Jakub Dawidek 51310b9d77bSPawel Jakub Dawidek #define VDEV_RAIDZ_MAXPARITY 3 5141ba4a712SPawel Jakub Dawidek 5158fc25799SMartin Matuska #define VDEV_PAD_SIZE (8 << 10) 5163830659eSToomas Soome /* 2 padding areas (vl_pad1 and vl_be) to skip */ 5178fc25799SMartin Matuska #define VDEV_SKIP_SIZE VDEV_PAD_SIZE * 2 5181ba4a712SPawel Jakub Dawidek #define VDEV_PHYS_SIZE (112 << 10) 5191ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_RING (128 << 10) 5201ba4a712SPawel Jakub Dawidek 52179a4bf89SToomas Soome /* 52279a4bf89SToomas Soome * MMP blocks occupy the last MMP_BLOCKS_PER_LABEL slots in the uberblock 52379a4bf89SToomas Soome * ring when MMP is enabled. 52479a4bf89SToomas Soome */ 52579a4bf89SToomas Soome #define MMP_BLOCKS_PER_LABEL 1 52679a4bf89SToomas Soome 52779a4bf89SToomas Soome /* The largest uberblock we support is 8k. */ 52879a4bf89SToomas Soome #define MAX_UBERBLOCK_SHIFT (13) 5291ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_SHIFT(vd) \ 53079a4bf89SToomas Soome MIN(MAX((vd)->v_top->v_ashift, UBERBLOCK_SHIFT), MAX_UBERBLOCK_SHIFT) 5311ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_COUNT(vd) \ 5321ba4a712SPawel Jakub Dawidek (VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(vd)) 5331ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_OFFSET(vd, n) \ 5341ba4a712SPawel Jakub Dawidek offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(vd)]) 5351ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_SIZE(vd) (1ULL << VDEV_UBERBLOCK_SHIFT(vd)) 5361ba4a712SPawel Jakub Dawidek 5371ba4a712SPawel Jakub Dawidek typedef struct vdev_phys { 53810b9d77bSPawel Jakub Dawidek char vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)]; 53910b9d77bSPawel Jakub Dawidek zio_eck_t vp_zbt; 5401ba4a712SPawel Jakub Dawidek } vdev_phys_t; 5411ba4a712SPawel Jakub Dawidek 5423830659eSToomas Soome typedef enum vbe_vers { 5433830659eSToomas Soome /* The bootenv file is stored as ascii text in the envblock */ 5443830659eSToomas Soome VB_RAW = 0, 5453830659eSToomas Soome 5463830659eSToomas Soome /* 5473830659eSToomas Soome * The bootenv file is converted to an nvlist and then packed into the 5483830659eSToomas Soome * envblock. 5493830659eSToomas Soome */ 5503830659eSToomas Soome VB_NVLIST = 1 5513830659eSToomas Soome } vbe_vers_t; 5523830659eSToomas Soome 5533830659eSToomas Soome typedef struct vdev_boot_envblock { 5543830659eSToomas Soome uint64_t vbe_version; 5553830659eSToomas Soome char vbe_bootenv[VDEV_PAD_SIZE - sizeof (uint64_t) - 5563830659eSToomas Soome sizeof (zio_eck_t)]; 5573830659eSToomas Soome zio_eck_t vbe_zbt; 5583830659eSToomas Soome } vdev_boot_envblock_t; 5593830659eSToomas Soome 560*77649f35SMark Johnston _Static_assert(sizeof (vdev_boot_envblock_t) == VDEV_PAD_SIZE, 561*77649f35SMark Johnston "bad size for vdev_boot_envblock_t"); 5623830659eSToomas Soome 5631ba4a712SPawel Jakub Dawidek typedef struct vdev_label { 5648fc25799SMartin Matuska char vl_pad1[VDEV_PAD_SIZE]; /* 8K */ 5653830659eSToomas Soome vdev_boot_envblock_t vl_be; /* 8K */ 5661ba4a712SPawel Jakub Dawidek vdev_phys_t vl_vdev_phys; /* 112K */ 5671ba4a712SPawel Jakub Dawidek char vl_uberblock[VDEV_UBERBLOCK_RING]; /* 128K */ 5681ba4a712SPawel Jakub Dawidek } vdev_label_t; /* 256K total */ 5691ba4a712SPawel Jakub Dawidek 5701ba4a712SPawel Jakub Dawidek /* 5711ba4a712SPawel Jakub Dawidek * vdev_dirty() flags 5721ba4a712SPawel Jakub Dawidek */ 5731ba4a712SPawel Jakub Dawidek #define VDD_METASLAB 0x01 5741ba4a712SPawel Jakub Dawidek #define VDD_DTL 0x02 5751ba4a712SPawel Jakub Dawidek 5761ba4a712SPawel Jakub Dawidek /* 5771ba4a712SPawel Jakub Dawidek * Size and offset of embedded boot loader region on each label. 5781ba4a712SPawel Jakub Dawidek * The total size of the first two labels plus the boot area is 4MB. 5791ba4a712SPawel Jakub Dawidek */ 5801ba4a712SPawel Jakub Dawidek #define VDEV_BOOT_OFFSET (2 * sizeof (vdev_label_t)) 5811ba4a712SPawel Jakub Dawidek #define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */ 5821ba4a712SPawel Jakub Dawidek 5831ba4a712SPawel Jakub Dawidek /* 5841ba4a712SPawel Jakub Dawidek * Size of label regions at the start and end of each leaf device. 5851ba4a712SPawel Jakub Dawidek */ 5861ba4a712SPawel Jakub Dawidek #define VDEV_LABEL_START_SIZE (2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE) 5871ba4a712SPawel Jakub Dawidek #define VDEV_LABEL_END_SIZE (2 * sizeof (vdev_label_t)) 5881ba4a712SPawel Jakub Dawidek #define VDEV_LABELS 4 5891ba4a712SPawel Jakub Dawidek 5901ba4a712SPawel Jakub Dawidek enum zio_checksum { 5911ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_INHERIT = 0, 5921ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_ON, 5931ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_OFF, 5941ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_LABEL, 5951ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_GANG_HEADER, 5961ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_ZILOG, 5971ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_FLETCHER_2, 5981ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_FLETCHER_4, 5991ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_SHA256, 60010b9d77bSPawel Jakub Dawidek ZIO_CHECKSUM_ZILOG2, 6012c55d090SToomas Soome ZIO_CHECKSUM_NOPARITY, 6022c55d090SToomas Soome ZIO_CHECKSUM_SHA512, 6032c55d090SToomas Soome ZIO_CHECKSUM_SKEIN, 6042c55d090SToomas Soome ZIO_CHECKSUM_EDONR, 6051ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_FUNCTIONS 6061ba4a712SPawel Jakub Dawidek }; 6071ba4a712SPawel Jakub Dawidek 60810b9d77bSPawel Jakub Dawidek #define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_4 6091ba4a712SPawel Jakub Dawidek #define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON 6101ba4a712SPawel Jakub Dawidek 6111ba4a712SPawel Jakub Dawidek enum zio_compress { 6121ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_INHERIT = 0, 6131ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_ON, 6141ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_OFF, 6151ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_LZJB, 6161ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_EMPTY, 6171ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_1, 6181ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_2, 6191ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_3, 6201ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_4, 6211ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_5, 6221ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_6, 6231ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_7, 6241ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_8, 6251ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_9, 62610b9d77bSPawel Jakub Dawidek ZIO_COMPRESS_ZLE, 627ef17620fSXin LI ZIO_COMPRESS_LZ4, 6282fec3ae8SWarner Losh ZIO_COMPRESS_ZSTD, 6291ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_FUNCTIONS 6301ba4a712SPawel Jakub Dawidek }; 6311ba4a712SPawel Jakub Dawidek 6322fec3ae8SWarner Losh enum zio_zstd_levels { 6332fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_INHERIT = 0, 6342fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_1, 6352fec3ae8SWarner Losh #define ZIO_ZSTD_LEVEL_MIN ZIO_ZSTD_LEVEL_1 6362fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_2, 6372fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_3, 6382fec3ae8SWarner Losh #define ZIO_ZSTD_LEVEL_DEFAULT ZIO_ZSTD_LEVEL_3 6392fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_4, 6402fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_5, 6412fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_6, 6422fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_7, 6432fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_8, 6442fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_9, 6452fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_10, 6462fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_11, 6472fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_12, 6482fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_13, 6492fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_14, 6502fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_15, 6512fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_16, 6522fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_17, 6532fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_18, 6542fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_19, 6552fec3ae8SWarner Losh #define ZIO_ZSTD_LEVEL_MAX ZIO_ZSTD_LEVEL_19 6562fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_RESERVE = 101, /* Leave room for new positive levels */ 6572fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST, /* Fast levels are negative */ 6582fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_1, 6592fec3ae8SWarner Losh #define ZIO_ZSTD_LEVEL_FAST_DEFAULT ZIO_ZSTD_LEVEL_FAST_1 6602fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_2, 6612fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_3, 6622fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_4, 6632fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_5, 6642fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_6, 6652fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_7, 6662fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_8, 6672fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_9, 6682fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_10, 6692fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_20, 6702fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_30, 6712fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_40, 6722fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_50, 6732fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_60, 6742fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_70, 6752fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_80, 6762fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_90, 6772fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_100, 6782fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_500, 6792fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_FAST_1000, 6802fec3ae8SWarner Losh #define ZIO_ZSTD_LEVEL_FAST_MAX ZIO_ZSTD_LEVEL_FAST_1000 6812fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_AUTO = 251, /* Reserved for future use */ 6822fec3ae8SWarner Losh ZIO_ZSTD_LEVEL_LEVELS 6832fec3ae8SWarner Losh }; 6842fec3ae8SWarner Losh 6851ba4a712SPawel Jakub Dawidek #define ZIO_COMPRESS_ON_VALUE ZIO_COMPRESS_LZJB 6861ba4a712SPawel Jakub Dawidek #define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF 6871ba4a712SPawel Jakub Dawidek 6881ba4a712SPawel Jakub Dawidek /* 6891ba4a712SPawel Jakub Dawidek * On-disk version number. 6901ba4a712SPawel Jakub Dawidek */ 6910d16312bSDoug Rabson #define SPA_VERSION_1 1ULL 6920d16312bSDoug Rabson #define SPA_VERSION_2 2ULL 6930d16312bSDoug Rabson #define SPA_VERSION_3 3ULL 6940d16312bSDoug Rabson #define SPA_VERSION_4 4ULL 6950d16312bSDoug Rabson #define SPA_VERSION_5 5ULL 6960d16312bSDoug Rabson #define SPA_VERSION_6 6ULL 6970d16312bSDoug Rabson #define SPA_VERSION_7 7ULL 6980d16312bSDoug Rabson #define SPA_VERSION_8 8ULL 6990d16312bSDoug Rabson #define SPA_VERSION_9 9ULL 7000d16312bSDoug Rabson #define SPA_VERSION_10 10ULL 7010d16312bSDoug Rabson #define SPA_VERSION_11 11ULL 702786895f6SDoug Rabson #define SPA_VERSION_12 12ULL 703786895f6SDoug Rabson #define SPA_VERSION_13 13ULL 70491891290SXin LI #define SPA_VERSION_14 14ULL 7058fc25799SMartin Matuska #define SPA_VERSION_15 15ULL 70610b9d77bSPawel Jakub Dawidek #define SPA_VERSION_16 16ULL 70710b9d77bSPawel Jakub Dawidek #define SPA_VERSION_17 17ULL 70810b9d77bSPawel Jakub Dawidek #define SPA_VERSION_18 18ULL 70910b9d77bSPawel Jakub Dawidek #define SPA_VERSION_19 19ULL 71010b9d77bSPawel Jakub Dawidek #define SPA_VERSION_20 20ULL 71110b9d77bSPawel Jakub Dawidek #define SPA_VERSION_21 21ULL 71210b9d77bSPawel Jakub Dawidek #define SPA_VERSION_22 22ULL 71310b9d77bSPawel Jakub Dawidek #define SPA_VERSION_23 23ULL 71410b9d77bSPawel Jakub Dawidek #define SPA_VERSION_24 24ULL 71510b9d77bSPawel Jakub Dawidek #define SPA_VERSION_25 25ULL 71610b9d77bSPawel Jakub Dawidek #define SPA_VERSION_26 26ULL 71710b9d77bSPawel Jakub Dawidek #define SPA_VERSION_27 27ULL 71810b9d77bSPawel Jakub Dawidek #define SPA_VERSION_28 28ULL 7192d9cf57eSMartin Matuska #define SPA_VERSION_5000 5000ULL 72010b9d77bSPawel Jakub Dawidek 7211ba4a712SPawel Jakub Dawidek /* 72210b9d77bSPawel Jakub Dawidek * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk 72310b9d77bSPawel Jakub Dawidek * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*}, 72410b9d77bSPawel Jakub Dawidek * and do the appropriate changes. Also bump the version number in 72510b9d77bSPawel Jakub Dawidek * usr/src/grub/capability. 7261ba4a712SPawel Jakub Dawidek */ 7272d9cf57eSMartin Matuska #define SPA_VERSION SPA_VERSION_5000 7282d9cf57eSMartin Matuska #define SPA_VERSION_STRING "5000" 7291ba4a712SPawel Jakub Dawidek 7301ba4a712SPawel Jakub Dawidek /* 7310d16312bSDoug Rabson * Symbolic names for the changes that caused a SPA_VERSION switch. 7321ba4a712SPawel Jakub Dawidek * Used in the code when checking for presence or absence of a feature. 7331ba4a712SPawel Jakub Dawidek * Feel free to define multiple symbolic names for each version if there 7341ba4a712SPawel Jakub Dawidek * were multiple changes to on-disk structures during that version. 7351ba4a712SPawel Jakub Dawidek * 7360d16312bSDoug Rabson * NOTE: When checking the current SPA_VERSION in your code, be sure 7371ba4a712SPawel Jakub Dawidek * to use spa_version() since it reports the version of the 7381ba4a712SPawel Jakub Dawidek * last synced uberblock. Checking the in-flight version can 7391ba4a712SPawel Jakub Dawidek * be dangerous in some cases. 7401ba4a712SPawel Jakub Dawidek */ 7410d16312bSDoug Rabson #define SPA_VERSION_INITIAL SPA_VERSION_1 7420d16312bSDoug Rabson #define SPA_VERSION_DITTO_BLOCKS SPA_VERSION_2 7430d16312bSDoug Rabson #define SPA_VERSION_SPARES SPA_VERSION_3 7440d16312bSDoug Rabson #define SPA_VERSION_RAID6 SPA_VERSION_3 7450d16312bSDoug Rabson #define SPA_VERSION_BPLIST_ACCOUNT SPA_VERSION_3 7460d16312bSDoug Rabson #define SPA_VERSION_RAIDZ_DEFLATE SPA_VERSION_3 7470d16312bSDoug Rabson #define SPA_VERSION_DNODE_BYTES SPA_VERSION_3 7480d16312bSDoug Rabson #define SPA_VERSION_ZPOOL_HISTORY SPA_VERSION_4 7490d16312bSDoug Rabson #define SPA_VERSION_GZIP_COMPRESSION SPA_VERSION_5 7500d16312bSDoug Rabson #define SPA_VERSION_BOOTFS SPA_VERSION_6 751786895f6SDoug Rabson #define SPA_VERSION_SLOGS SPA_VERSION_7 752786895f6SDoug Rabson #define SPA_VERSION_DELEGATED_PERMS SPA_VERSION_8 753786895f6SDoug Rabson #define SPA_VERSION_FUID SPA_VERSION_9 754786895f6SDoug Rabson #define SPA_VERSION_REFRESERVATION SPA_VERSION_9 755786895f6SDoug Rabson #define SPA_VERSION_REFQUOTA SPA_VERSION_9 756786895f6SDoug Rabson #define SPA_VERSION_UNIQUE_ACCURATE SPA_VERSION_9 757786895f6SDoug Rabson #define SPA_VERSION_L2CACHE SPA_VERSION_10 758786895f6SDoug Rabson #define SPA_VERSION_NEXT_CLONES SPA_VERSION_11 759786895f6SDoug Rabson #define SPA_VERSION_ORIGIN SPA_VERSION_11 760786895f6SDoug Rabson #define SPA_VERSION_DSL_SCRUB SPA_VERSION_11 761786895f6SDoug Rabson #define SPA_VERSION_SNAP_PROPS SPA_VERSION_12 762786895f6SDoug Rabson #define SPA_VERSION_USED_BREAKDOWN SPA_VERSION_13 76391891290SXin LI #define SPA_VERSION_PASSTHROUGH_X SPA_VERSION_14 7648fc25799SMartin Matuska #define SPA_VERSION_USERSPACE SPA_VERSION_15 76510b9d77bSPawel Jakub Dawidek #define SPA_VERSION_STMF_PROP SPA_VERSION_16 76610b9d77bSPawel Jakub Dawidek #define SPA_VERSION_RAIDZ3 SPA_VERSION_17 76710b9d77bSPawel Jakub Dawidek #define SPA_VERSION_USERREFS SPA_VERSION_18 76810b9d77bSPawel Jakub Dawidek #define SPA_VERSION_HOLES SPA_VERSION_19 76910b9d77bSPawel Jakub Dawidek #define SPA_VERSION_ZLE_COMPRESSION SPA_VERSION_20 77010b9d77bSPawel Jakub Dawidek #define SPA_VERSION_DEDUP SPA_VERSION_21 77110b9d77bSPawel Jakub Dawidek #define SPA_VERSION_RECVD_PROPS SPA_VERSION_22 77210b9d77bSPawel Jakub Dawidek #define SPA_VERSION_SLIM_ZIL SPA_VERSION_23 77310b9d77bSPawel Jakub Dawidek #define SPA_VERSION_SA SPA_VERSION_24 77410b9d77bSPawel Jakub Dawidek #define SPA_VERSION_SCAN SPA_VERSION_25 77510b9d77bSPawel Jakub Dawidek #define SPA_VERSION_DIR_CLONES SPA_VERSION_26 77610b9d77bSPawel Jakub Dawidek #define SPA_VERSION_DEADLISTS SPA_VERSION_26 77710b9d77bSPawel Jakub Dawidek #define SPA_VERSION_FAST_SNAP SPA_VERSION_27 77810b9d77bSPawel Jakub Dawidek #define SPA_VERSION_MULTI_REPLACE SPA_VERSION_28 7792d9cf57eSMartin Matuska #define SPA_VERSION_BEFORE_FEATURES SPA_VERSION_28 7802d9cf57eSMartin Matuska #define SPA_VERSION_FEATURES SPA_VERSION_5000 7812d9cf57eSMartin Matuska 7822d9cf57eSMartin Matuska #define SPA_VERSION_IS_SUPPORTED(v) \ 7832d9cf57eSMartin Matuska (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \ 7842d9cf57eSMartin Matuska ((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION)) 7851ba4a712SPawel Jakub Dawidek 7861ba4a712SPawel Jakub Dawidek /* 7871ba4a712SPawel Jakub Dawidek * The following are configuration names used in the nvlist describing a pool's 7881ba4a712SPawel Jakub Dawidek * configuration. 7891ba4a712SPawel Jakub Dawidek */ 7901ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_VERSION "version" 7911ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_NAME "name" 7921ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_STATE "state" 7931ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_TXG "txg" 7941ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_GUID "pool_guid" 7951ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_CREATE_TXG "create_txg" 7961ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_TOP_GUID "top_guid" 7971ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_VDEV_TREE "vdev_tree" 7981ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_TYPE "type" 7991ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_CHILDREN "children" 8001ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ID "id" 8011ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_GUID "guid" 802b1b93268SToomas Soome #define ZPOOL_CONFIG_INDIRECT_OBJECT "com.delphix:indirect_object" 803b1b93268SToomas Soome #define ZPOOL_CONFIG_INDIRECT_BIRTHS "com.delphix:indirect_births" 804b1b93268SToomas Soome #define ZPOOL_CONFIG_PREV_INDIRECT_VDEV "com.delphix:prev_indirect_vdev" 8051ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_PATH "path" 8061ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_DEVID "devid" 8071ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array" 8081ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift" 8091ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ASHIFT "ashift" 8101ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ASIZE "asize" 8111ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_DTL "DTL" 8121ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_STATS "stats" 8131ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_WHOLE_DISK "whole_disk" 8141ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ERRCOUNT "error_count" 8151ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_NOT_PRESENT "not_present" 8161ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_SPARES "spares" 8171ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_IS_SPARE "is_spare" 8181ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_NPARITY "nparity" 8191ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_HOSTID "hostid" 8201ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_HOSTNAME "hostname" 8216a85b5e0SPawel Jakub Dawidek #define ZPOOL_CONFIG_IS_LOG "is_log" 8221ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */ 8232d9cf57eSMartin Matuska #define ZPOOL_CONFIG_FEATURES_FOR_READ "features_for_read" 8243c2db0efSToomas Soome #define ZPOOL_CONFIG_VDEV_CHILDREN "vdev_children" 8251ba4a712SPawel Jakub Dawidek 82603ec6213SXin LI /* 82703ec6213SXin LI * The persistent vdev state is stored as separate values rather than a single 82803ec6213SXin LI * 'vdev_state' entry. This is because a device can be in multiple states, such 82903ec6213SXin LI * as offline and degraded. 83003ec6213SXin LI */ 83103ec6213SXin LI #define ZPOOL_CONFIG_OFFLINE "offline" 83203ec6213SXin LI #define ZPOOL_CONFIG_FAULTED "faulted" 83303ec6213SXin LI #define ZPOOL_CONFIG_DEGRADED "degraded" 83403ec6213SXin LI #define ZPOOL_CONFIG_REMOVED "removed" 83510b9d77bSPawel Jakub Dawidek #define ZPOOL_CONFIG_FRU "fru" 83610b9d77bSPawel Jakub Dawidek #define ZPOOL_CONFIG_AUX_STATE "aux_state" 83703ec6213SXin LI 8381ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_ROOT "root" 8391ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_MIRROR "mirror" 8401ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_REPLACING "replacing" 8411ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_RAIDZ "raidz" 8421ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_DISK "disk" 8431ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_FILE "file" 8441ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_MISSING "missing" 84510b9d77bSPawel Jakub Dawidek #define VDEV_TYPE_HOLE "hole" 8461ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_SPARE "spare" 84710b9d77bSPawel Jakub Dawidek #define VDEV_TYPE_LOG "log" 84810b9d77bSPawel Jakub Dawidek #define VDEV_TYPE_L2CACHE "l2cache" 849b1b93268SToomas Soome #define VDEV_TYPE_INDIRECT "indirect" 8501ba4a712SPawel Jakub Dawidek 8511ba4a712SPawel Jakub Dawidek /* 8521ba4a712SPawel Jakub Dawidek * This is needed in userland to report the minimum necessary device size. 8531ba4a712SPawel Jakub Dawidek */ 8541ba4a712SPawel Jakub Dawidek #define SPA_MINDEVSIZE (64ULL << 20) 8551ba4a712SPawel Jakub Dawidek 8561ba4a712SPawel Jakub Dawidek /* 8571ba4a712SPawel Jakub Dawidek * The location of the pool configuration repository, shared between kernel and 8581ba4a712SPawel Jakub Dawidek * userland. 8591ba4a712SPawel Jakub Dawidek */ 86010b9d77bSPawel Jakub Dawidek #define ZPOOL_CACHE "/boot/zfs/zpool.cache" 8611ba4a712SPawel Jakub Dawidek 8621ba4a712SPawel Jakub Dawidek /* 8631ba4a712SPawel Jakub Dawidek * vdev states are ordered from least to most healthy. 8641ba4a712SPawel Jakub Dawidek * A vdev that's CANT_OPEN or below is considered unusable. 8651ba4a712SPawel Jakub Dawidek */ 8661ba4a712SPawel Jakub Dawidek typedef enum vdev_state { 8671ba4a712SPawel Jakub Dawidek VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev */ 8681ba4a712SPawel Jakub Dawidek VDEV_STATE_CLOSED, /* Not currently open */ 8691ba4a712SPawel Jakub Dawidek VDEV_STATE_OFFLINE, /* Not allowed to open */ 87003ec6213SXin LI VDEV_STATE_REMOVED, /* Explicitly removed from system */ 8711ba4a712SPawel Jakub Dawidek VDEV_STATE_CANT_OPEN, /* Tried to open, but failed */ 87203ec6213SXin LI VDEV_STATE_FAULTED, /* External request to fault device */ 8731ba4a712SPawel Jakub Dawidek VDEV_STATE_DEGRADED, /* Replicated vdev with unhealthy kids */ 8741ba4a712SPawel Jakub Dawidek VDEV_STATE_HEALTHY /* Presumed good */ 8751ba4a712SPawel Jakub Dawidek } vdev_state_t; 8761ba4a712SPawel Jakub Dawidek 8771ba4a712SPawel Jakub Dawidek /* 8781ba4a712SPawel Jakub Dawidek * vdev aux states. When a vdev is in the CANT_OPEN state, the aux field 8791ba4a712SPawel Jakub Dawidek * of the vdev stats structure uses these constants to distinguish why. 8801ba4a712SPawel Jakub Dawidek */ 8811ba4a712SPawel Jakub Dawidek typedef enum vdev_aux { 8821ba4a712SPawel Jakub Dawidek VDEV_AUX_NONE, /* no error */ 8831ba4a712SPawel Jakub Dawidek VDEV_AUX_OPEN_FAILED, /* ldi_open_*() or vn_open() failed */ 8841ba4a712SPawel Jakub Dawidek VDEV_AUX_CORRUPT_DATA, /* bad label or disk contents */ 8851ba4a712SPawel Jakub Dawidek VDEV_AUX_NO_REPLICAS, /* insufficient number of replicas */ 8861ba4a712SPawel Jakub Dawidek VDEV_AUX_BAD_GUID_SUM, /* vdev guid sum doesn't match */ 8871ba4a712SPawel Jakub Dawidek VDEV_AUX_TOO_SMALL, /* vdev size is too small */ 8881ba4a712SPawel Jakub Dawidek VDEV_AUX_BAD_LABEL, /* the label is OK but invalid */ 8891ba4a712SPawel Jakub Dawidek VDEV_AUX_VERSION_NEWER, /* on-disk version is too new */ 8901ba4a712SPawel Jakub Dawidek VDEV_AUX_VERSION_OLDER, /* on-disk version is too old */ 8911ba4a712SPawel Jakub Dawidek VDEV_AUX_SPARED /* hot spare used in another pool */ 8921ba4a712SPawel Jakub Dawidek } vdev_aux_t; 8931ba4a712SPawel Jakub Dawidek 8941ba4a712SPawel Jakub Dawidek /* 8951ba4a712SPawel Jakub Dawidek * pool state. The following states are written to disk as part of the normal 8961ba4a712SPawel Jakub Dawidek * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE. The remaining states are 8971ba4a712SPawel Jakub Dawidek * software abstractions used at various levels to communicate pool state. 8981ba4a712SPawel Jakub Dawidek */ 8991ba4a712SPawel Jakub Dawidek typedef enum pool_state { 9001ba4a712SPawel Jakub Dawidek POOL_STATE_ACTIVE = 0, /* In active use */ 9011ba4a712SPawel Jakub Dawidek POOL_STATE_EXPORTED, /* Explicitly exported */ 9021ba4a712SPawel Jakub Dawidek POOL_STATE_DESTROYED, /* Explicitly destroyed */ 9031ba4a712SPawel Jakub Dawidek POOL_STATE_SPARE, /* Reserved for hot spare use */ 9041ba4a712SPawel Jakub Dawidek POOL_STATE_UNINITIALIZED, /* Internal spa_t state */ 9051ba4a712SPawel Jakub Dawidek POOL_STATE_UNAVAIL, /* Internal libzfs state */ 9061ba4a712SPawel Jakub Dawidek POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */ 9071ba4a712SPawel Jakub Dawidek } pool_state_t; 9081ba4a712SPawel Jakub Dawidek 9091ba4a712SPawel Jakub Dawidek /* 9101ba4a712SPawel Jakub Dawidek * The uberblock version is incremented whenever an incompatible on-disk 9111ba4a712SPawel Jakub Dawidek * format change is made to the SPA, DMU, or ZAP. 9121ba4a712SPawel Jakub Dawidek * 9131ba4a712SPawel Jakub Dawidek * Note: the first two fields should never be moved. When a storage pool 9141ba4a712SPawel Jakub Dawidek * is opened, the uberblock must be read off the disk before the version 9151ba4a712SPawel Jakub Dawidek * can be checked. If the ub_version field is moved, we may not detect 9161ba4a712SPawel Jakub Dawidek * version mismatch. If the ub_magic field is moved, applications that 9171ba4a712SPawel Jakub Dawidek * expect the magic number in the first word won't work. 9181ba4a712SPawel Jakub Dawidek */ 9191ba4a712SPawel Jakub Dawidek #define UBERBLOCK_MAGIC 0x00bab10c /* oo-ba-bloc! */ 9201ba4a712SPawel Jakub Dawidek #define UBERBLOCK_SHIFT 10 /* up to 1K */ 9211ba4a712SPawel Jakub Dawidek 92279a4bf89SToomas Soome #define MMP_MAGIC 0xa11cea11 /* all-see-all */ 92379a4bf89SToomas Soome 92479a4bf89SToomas Soome #define MMP_INTERVAL_VALID_BIT 0x01 92579a4bf89SToomas Soome #define MMP_SEQ_VALID_BIT 0x02 92679a4bf89SToomas Soome #define MMP_FAIL_INT_VALID_BIT 0x04 92779a4bf89SToomas Soome 92879a4bf89SToomas Soome #define MMP_VALID(ubp) (ubp->ub_magic == UBERBLOCK_MAGIC && \ 92979a4bf89SToomas Soome ubp->ub_mmp_magic == MMP_MAGIC) 93079a4bf89SToomas Soome #define MMP_INTERVAL_VALID(ubp) (MMP_VALID(ubp) && (ubp->ub_mmp_config & \ 93179a4bf89SToomas Soome MMP_INTERVAL_VALID_BIT)) 93279a4bf89SToomas Soome #define MMP_SEQ_VALID(ubp) (MMP_VALID(ubp) && (ubp->ub_mmp_config & \ 93379a4bf89SToomas Soome MMP_SEQ_VALID_BIT)) 93479a4bf89SToomas Soome #define MMP_FAIL_INT_VALID(ubp) (MMP_VALID(ubp) && (ubp->ub_mmp_config & \ 93579a4bf89SToomas Soome MMP_FAIL_INT_VALID_BIT)) 93679a4bf89SToomas Soome 93779a4bf89SToomas Soome #define MMP_INTERVAL(ubp) ((ubp->ub_mmp_config & 0x00000000FFFFFF00) \ 93879a4bf89SToomas Soome >> 8) 93979a4bf89SToomas Soome #define MMP_SEQ(ubp) ((ubp->ub_mmp_config & 0x0000FFFF00000000) \ 94079a4bf89SToomas Soome >> 32) 94179a4bf89SToomas Soome #define MMP_FAIL_INT(ubp) ((ubp->ub_mmp_config & 0xFFFF000000000000) \ 94279a4bf89SToomas Soome >> 48) 94379a4bf89SToomas Soome 94479a4bf89SToomas Soome typedef struct uberblock { 9451ba4a712SPawel Jakub Dawidek uint64_t ub_magic; /* UBERBLOCK_MAGIC */ 9460d16312bSDoug Rabson uint64_t ub_version; /* SPA_VERSION */ 9471ba4a712SPawel Jakub Dawidek uint64_t ub_txg; /* txg of last sync */ 9481ba4a712SPawel Jakub Dawidek uint64_t ub_guid_sum; /* sum of all vdev guids */ 9491ba4a712SPawel Jakub Dawidek uint64_t ub_timestamp; /* UTC time of last sync */ 9501ba4a712SPawel Jakub Dawidek blkptr_t ub_rootbp; /* MOS objset_phys_t */ 95179a4bf89SToomas Soome /* highest SPA_VERSION supported by software that wrote this txg */ 95279a4bf89SToomas Soome uint64_t ub_software_version; 95379a4bf89SToomas Soome /* Maybe missing in uberblocks we read, but always written */ 95479a4bf89SToomas Soome uint64_t ub_mmp_magic; 95579a4bf89SToomas Soome /* 95679a4bf89SToomas Soome * If ub_mmp_delay == 0 and ub_mmp_magic is valid, MMP is off. 95779a4bf89SToomas Soome * Otherwise, nanosec since last MMP write. 95879a4bf89SToomas Soome */ 95979a4bf89SToomas Soome uint64_t ub_mmp_delay; 96079a4bf89SToomas Soome 96179a4bf89SToomas Soome /* 96279a4bf89SToomas Soome * The ub_mmp_config contains the multihost write interval, multihost 96379a4bf89SToomas Soome * fail intervals, sequence number for sub-second granularity, and 96479a4bf89SToomas Soome * valid bit mask. This layout is as follows: 96579a4bf89SToomas Soome * 96679a4bf89SToomas Soome * 64 56 48 40 32 24 16 8 0 96779a4bf89SToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+ 96879a4bf89SToomas Soome * 0 | Fail Intervals| Seq | Write Interval (ms) | VALID | 96979a4bf89SToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+ 97079a4bf89SToomas Soome * 97179a4bf89SToomas Soome * This allows a write_interval of (2^24/1000)s, over 4.5 hours 97279a4bf89SToomas Soome * 97379a4bf89SToomas Soome * VALID Bits: 97479a4bf89SToomas Soome * - 0x01 - Write Interval (ms) 97579a4bf89SToomas Soome * - 0x02 - Sequence number exists 97679a4bf89SToomas Soome * - 0x04 - Fail Intervals 97779a4bf89SToomas Soome * - 0xf8 - Reserved 97879a4bf89SToomas Soome */ 97979a4bf89SToomas Soome uint64_t ub_mmp_config; 98079a4bf89SToomas Soome 98179a4bf89SToomas Soome /* 98279a4bf89SToomas Soome * ub_checkpoint_txg indicates two things about the current uberblock: 98379a4bf89SToomas Soome * 98479a4bf89SToomas Soome * 1] If it is not zero then this uberblock is a checkpoint. If it is 98579a4bf89SToomas Soome * zero, then this uberblock is not a checkpoint. 98679a4bf89SToomas Soome * 98779a4bf89SToomas Soome * 2] On checkpointed uberblocks, the value of ub_checkpoint_txg is 98879a4bf89SToomas Soome * the ub_txg that the uberblock had at the time we moved it to 98979a4bf89SToomas Soome * the MOS config. 99079a4bf89SToomas Soome * 99179a4bf89SToomas Soome * The field is set when we checkpoint the uberblock and continues to 99279a4bf89SToomas Soome * hold that value even after we've rewound (unlike the ub_txg that 99379a4bf89SToomas Soome * is reset to a higher value). 99479a4bf89SToomas Soome * 99579a4bf89SToomas Soome * Besides checks used to determine whether we are reopening the 99679a4bf89SToomas Soome * pool from a checkpointed uberblock [see spa_ld_select_uberblock()], 99779a4bf89SToomas Soome * the value of the field is used to determine which ZIL blocks have 99879a4bf89SToomas Soome * been allocated according to the ms_sm when we are rewinding to a 99979a4bf89SToomas Soome * checkpoint. Specifically, if blk_birth > ub_checkpoint_txg, then 100079a4bf89SToomas Soome * the ZIL block is not allocated [see uses of spa_min_claim_txg()]. 100179a4bf89SToomas Soome */ 100279a4bf89SToomas Soome uint64_t ub_checkpoint_txg; 100379a4bf89SToomas Soome } uberblock_t; 10041ba4a712SPawel Jakub Dawidek 10051ba4a712SPawel Jakub Dawidek /* 10061ba4a712SPawel Jakub Dawidek * Flags. 10071ba4a712SPawel Jakub Dawidek */ 10081ba4a712SPawel Jakub Dawidek #define DNODE_MUST_BE_ALLOCATED 1 10091ba4a712SPawel Jakub Dawidek #define DNODE_MUST_BE_FREE 2 10101ba4a712SPawel Jakub Dawidek 10111ba4a712SPawel Jakub Dawidek /* 10121ba4a712SPawel Jakub Dawidek * Fixed constants. 10131ba4a712SPawel Jakub Dawidek */ 10141ba4a712SPawel Jakub Dawidek #define DNODE_SHIFT 9 /* 512 bytes */ 1015263f396eSXin LI #define DN_MIN_INDBLKSHIFT 12 /* 4k */ 1016b1b93268SToomas Soome #define DN_MAX_INDBLKSHIFT 17 /* 128k */ 10171ba4a712SPawel Jakub Dawidek #define DNODE_BLOCK_SHIFT 14 /* 16k */ 10181ba4a712SPawel Jakub Dawidek #define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */ 10191ba4a712SPawel Jakub Dawidek #define DN_MAX_OBJECT_SHIFT 48 /* 256 trillion (zfs_fid_t limit) */ 10201ba4a712SPawel Jakub Dawidek #define DN_MAX_OFFSET_SHIFT 64 /* 2^64 bytes in a dnode */ 10211ba4a712SPawel Jakub Dawidek 10221ba4a712SPawel Jakub Dawidek /* 10231ba4a712SPawel Jakub Dawidek * Derived constants. 10241ba4a712SPawel Jakub Dawidek */ 1025b40aaca6SToomas Soome #define DNODE_MIN_SIZE (1 << DNODE_SHIFT) 1026b40aaca6SToomas Soome #define DNODE_MAX_SIZE (1 << DNODE_BLOCK_SHIFT) 1027b40aaca6SToomas Soome #define DNODE_BLOCK_SIZE (1 << DNODE_BLOCK_SHIFT) 1028b40aaca6SToomas Soome #define DNODE_MIN_SLOTS (DNODE_MIN_SIZE >> DNODE_SHIFT) 1029b40aaca6SToomas Soome #define DNODE_MAX_SLOTS (DNODE_MAX_SIZE >> DNODE_SHIFT) 1030b40aaca6SToomas Soome #define DN_BONUS_SIZE(dnsize) ((dnsize) - DNODE_CORE_SIZE - \ 1031b40aaca6SToomas Soome (1 << SPA_BLKPTRSHIFT)) 1032b40aaca6SToomas Soome #define DN_SLOTS_TO_BONUSLEN(slots) DN_BONUS_SIZE((slots) << DNODE_SHIFT) 1033b40aaca6SToomas Soome #define DN_OLD_MAX_BONUSLEN (DN_BONUS_SIZE(DNODE_MIN_SIZE)) 1034b40aaca6SToomas Soome #define DN_MAX_NBLKPTR ((DNODE_MIN_SIZE - DNODE_CORE_SIZE) >> \ 1035b40aaca6SToomas Soome SPA_BLKPTRSHIFT) 10361ba4a712SPawel Jakub Dawidek #define DN_MAX_OBJECT (1ULL << DN_MAX_OBJECT_SHIFT) 1037b40aaca6SToomas Soome #define DN_ZERO_BONUSLEN (DN_BONUS_SIZE(DNODE_MAX_SIZE) + 1) 10381ba4a712SPawel Jakub Dawidek 10391ba4a712SPawel Jakub Dawidek #define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT) 10401ba4a712SPawel Jakub Dawidek #define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT) 10411ba4a712SPawel Jakub Dawidek #define DNODES_PER_LEVEL_SHIFT (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT) 10421ba4a712SPawel Jakub Dawidek 10431ba4a712SPawel Jakub Dawidek /* The +2 here is a cheesy way to round up */ 10441ba4a712SPawel Jakub Dawidek #define DN_MAX_LEVELS (2 + ((DN_MAX_OFFSET_SHIFT - SPA_MINBLOCKSHIFT) / \ 10451ba4a712SPawel Jakub Dawidek (DN_MIN_INDBLKSHIFT - SPA_BLKPTRSHIFT))) 10461ba4a712SPawel Jakub Dawidek 10471ba4a712SPawel Jakub Dawidek #define DN_BONUS(dnp) ((void*)((dnp)->dn_bonus + \ 10481ba4a712SPawel Jakub Dawidek (((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t)))) 10491ba4a712SPawel Jakub Dawidek 10501ba4a712SPawel Jakub Dawidek #define DN_USED_BYTES(dnp) (((dnp)->dn_flags & DNODE_FLAG_USED_BYTES) ? \ 10511ba4a712SPawel Jakub Dawidek (dnp)->dn_used : (dnp)->dn_used << SPA_MINBLOCKSHIFT) 10521ba4a712SPawel Jakub Dawidek 10531ba4a712SPawel Jakub Dawidek #define EPB(blkshift, typeshift) (1 << (blkshift - typeshift)) 10541ba4a712SPawel Jakub Dawidek 10551ba4a712SPawel Jakub Dawidek /* Is dn_used in bytes? if not, it's in multiples of SPA_MINBLOCKSIZE */ 10561ba4a712SPawel Jakub Dawidek #define DNODE_FLAG_USED_BYTES (1<<0) 105710b9d77bSPawel Jakub Dawidek #define DNODE_FLAG_USERUSED_ACCOUNTED (1<<1) 105810b9d77bSPawel Jakub Dawidek 105910b9d77bSPawel Jakub Dawidek /* Does dnode have a SA spill blkptr in bonus? */ 106010b9d77bSPawel Jakub Dawidek #define DNODE_FLAG_SPILL_BLKPTR (1<<2) 10611ba4a712SPawel Jakub Dawidek 10621ba4a712SPawel Jakub Dawidek typedef struct dnode_phys { 10631ba4a712SPawel Jakub Dawidek uint8_t dn_type; /* dmu_object_type_t */ 10641ba4a712SPawel Jakub Dawidek uint8_t dn_indblkshift; /* ln2(indirect block size) */ 10651ba4a712SPawel Jakub Dawidek uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */ 10661ba4a712SPawel Jakub Dawidek uint8_t dn_nblkptr; /* length of dn_blkptr */ 10671ba4a712SPawel Jakub Dawidek uint8_t dn_bonustype; /* type of data in bonus buffer */ 10681ba4a712SPawel Jakub Dawidek uint8_t dn_checksum; /* ZIO_CHECKSUM type */ 10691ba4a712SPawel Jakub Dawidek uint8_t dn_compress; /* ZIO_COMPRESS type */ 10701ba4a712SPawel Jakub Dawidek uint8_t dn_flags; /* DNODE_FLAG_* */ 10711ba4a712SPawel Jakub Dawidek uint16_t dn_datablkszsec; /* data block size in 512b sectors */ 10721ba4a712SPawel Jakub Dawidek uint16_t dn_bonuslen; /* length of dn_bonus */ 1073b40aaca6SToomas Soome uint8_t dn_extra_slots; /* # of subsequent slots consumed */ 1074b40aaca6SToomas Soome uint8_t dn_pad2[3]; 10751ba4a712SPawel Jakub Dawidek 10761ba4a712SPawel Jakub Dawidek /* accounting is protected by dn_dirty_mtx */ 10771ba4a712SPawel Jakub Dawidek uint64_t dn_maxblkid; /* largest allocated block ID */ 10781ba4a712SPawel Jakub Dawidek uint64_t dn_used; /* bytes (or sectors) of disk space */ 10791ba4a712SPawel Jakub Dawidek 10801ba4a712SPawel Jakub Dawidek uint64_t dn_pad3[4]; 10811ba4a712SPawel Jakub Dawidek 1082b40aaca6SToomas Soome /* 1083b40aaca6SToomas Soome * The tail region is 448 bytes for a 512 byte dnode, and 1084b40aaca6SToomas Soome * correspondingly larger for larger dnode sizes. The spill 1085b40aaca6SToomas Soome * block pointer, when present, is always at the end of the tail 1086b40aaca6SToomas Soome * region. There are three ways this space may be used, using 1087b40aaca6SToomas Soome * a 512 byte dnode for this diagram: 1088b40aaca6SToomas Soome * 1089b40aaca6SToomas Soome * 0 64 128 192 256 320 384 448 (offset) 1090b40aaca6SToomas Soome * +---------------+---------------+---------------+-------+ 1091b40aaca6SToomas Soome * | dn_blkptr[0] | dn_blkptr[1] | dn_blkptr[2] | / | 1092b40aaca6SToomas Soome * +---------------+---------------+---------------+-------+ 1093b40aaca6SToomas Soome * | dn_blkptr[0] | dn_bonus[0..319] | 1094b40aaca6SToomas Soome * +---------------+-----------------------+---------------+ 1095b40aaca6SToomas Soome * | dn_blkptr[0] | dn_bonus[0..191] | dn_spill | 1096b40aaca6SToomas Soome * +---------------+-----------------------+---------------+ 1097b40aaca6SToomas Soome */ 1098b40aaca6SToomas Soome union { 1099b40aaca6SToomas Soome blkptr_t dn_blkptr[1+DN_OLD_MAX_BONUSLEN/sizeof (blkptr_t)]; 1100b40aaca6SToomas Soome struct { 1101b40aaca6SToomas Soome blkptr_t __dn_ignore1; 1102b40aaca6SToomas Soome uint8_t dn_bonus[DN_OLD_MAX_BONUSLEN]; 1103b40aaca6SToomas Soome }; 1104b40aaca6SToomas Soome struct { 1105b40aaca6SToomas Soome blkptr_t __dn_ignore2; 1106b40aaca6SToomas Soome uint8_t __dn_ignore3[DN_OLD_MAX_BONUSLEN - 1107b40aaca6SToomas Soome sizeof (blkptr_t)]; 110810b9d77bSPawel Jakub Dawidek blkptr_t dn_spill; 1109b40aaca6SToomas Soome }; 1110b40aaca6SToomas Soome }; 11111ba4a712SPawel Jakub Dawidek } dnode_phys_t; 11121ba4a712SPawel Jakub Dawidek 1113b40aaca6SToomas Soome #define DN_SPILL_BLKPTR(dnp) (blkptr_t *)((char *)(dnp) + \ 1114b40aaca6SToomas Soome (((dnp)->dn_extra_slots + 1) << DNODE_SHIFT) - (1 << SPA_BLKPTRSHIFT)) 1115b40aaca6SToomas Soome 11164deb8929SAllan Jude typedef enum dmu_object_byteswap { 11174deb8929SAllan Jude DMU_BSWAP_UINT8, 11184deb8929SAllan Jude DMU_BSWAP_UINT16, 11194deb8929SAllan Jude DMU_BSWAP_UINT32, 11204deb8929SAllan Jude DMU_BSWAP_UINT64, 11214deb8929SAllan Jude DMU_BSWAP_ZAP, 11224deb8929SAllan Jude DMU_BSWAP_DNODE, 11234deb8929SAllan Jude DMU_BSWAP_OBJSET, 11244deb8929SAllan Jude DMU_BSWAP_ZNODE, 11254deb8929SAllan Jude DMU_BSWAP_OLDACL, 11264deb8929SAllan Jude DMU_BSWAP_ACL, 11274deb8929SAllan Jude /* 11284deb8929SAllan Jude * Allocating a new byteswap type number makes the on-disk format 11294deb8929SAllan Jude * incompatible with any other format that uses the same number. 11304deb8929SAllan Jude * 11314deb8929SAllan Jude * Data can usually be structured to work with one of the 11324deb8929SAllan Jude * DMU_BSWAP_UINT* or DMU_BSWAP_ZAP types. 11334deb8929SAllan Jude */ 11344deb8929SAllan Jude DMU_BSWAP_NUMFUNCS 11354deb8929SAllan Jude } dmu_object_byteswap_t; 11364deb8929SAllan Jude 11374deb8929SAllan Jude #define DMU_OT_NEWTYPE 0x80 11384deb8929SAllan Jude #define DMU_OT_METADATA 0x40 11394deb8929SAllan Jude #define DMU_OT_BYTESWAP_MASK 0x3f 11404deb8929SAllan Jude 11414deb8929SAllan Jude /* 11424deb8929SAllan Jude * Defines a uint8_t object type. Object types specify if the data 11434deb8929SAllan Jude * in the object is metadata (boolean) and how to byteswap the data 11444deb8929SAllan Jude * (dmu_object_byteswap_t). 11454deb8929SAllan Jude */ 11464deb8929SAllan Jude #define DMU_OT(byteswap, metadata) \ 11474deb8929SAllan Jude (DMU_OT_NEWTYPE | \ 11484deb8929SAllan Jude ((metadata) ? DMU_OT_METADATA : 0) | \ 11494deb8929SAllan Jude ((byteswap) & DMU_OT_BYTESWAP_MASK)) 11504deb8929SAllan Jude 11511ba4a712SPawel Jakub Dawidek typedef enum dmu_object_type { 11521ba4a712SPawel Jakub Dawidek DMU_OT_NONE, 11531ba4a712SPawel Jakub Dawidek /* general: */ 11541ba4a712SPawel Jakub Dawidek DMU_OT_OBJECT_DIRECTORY, /* ZAP */ 11551ba4a712SPawel Jakub Dawidek DMU_OT_OBJECT_ARRAY, /* UINT64 */ 11561ba4a712SPawel Jakub Dawidek DMU_OT_PACKED_NVLIST, /* UINT8 (XDR by nvlist_pack/unpack) */ 11571ba4a712SPawel Jakub Dawidek DMU_OT_PACKED_NVLIST_SIZE, /* UINT64 */ 1158*77649f35SMark Johnston DMU_OT_BPOBJ, /* UINT64 */ 1159*77649f35SMark Johnston DMU_OT_BPOBJ_HDR, /* UINT64 */ 11601ba4a712SPawel Jakub Dawidek /* spa: */ 11611ba4a712SPawel Jakub Dawidek DMU_OT_SPACE_MAP_HEADER, /* UINT64 */ 11621ba4a712SPawel Jakub Dawidek DMU_OT_SPACE_MAP, /* UINT64 */ 11631ba4a712SPawel Jakub Dawidek /* zil: */ 11641ba4a712SPawel Jakub Dawidek DMU_OT_INTENT_LOG, /* UINT64 */ 11651ba4a712SPawel Jakub Dawidek /* dmu: */ 11661ba4a712SPawel Jakub Dawidek DMU_OT_DNODE, /* DNODE */ 11671ba4a712SPawel Jakub Dawidek DMU_OT_OBJSET, /* OBJSET */ 11681ba4a712SPawel Jakub Dawidek /* dsl: */ 11691ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DIR, /* UINT64 */ 11701ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DIR_CHILD_MAP, /* ZAP */ 11711ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DS_SNAP_MAP, /* ZAP */ 11721ba4a712SPawel Jakub Dawidek DMU_OT_DSL_PROPS, /* ZAP */ 11731ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DATASET, /* UINT64 */ 11741ba4a712SPawel Jakub Dawidek /* zpl: */ 11751ba4a712SPawel Jakub Dawidek DMU_OT_ZNODE, /* ZNODE */ 117610b9d77bSPawel Jakub Dawidek DMU_OT_OLDACL, /* Old ACL */ 11771ba4a712SPawel Jakub Dawidek DMU_OT_PLAIN_FILE_CONTENTS, /* UINT8 */ 11781ba4a712SPawel Jakub Dawidek DMU_OT_DIRECTORY_CONTENTS, /* ZAP */ 11791ba4a712SPawel Jakub Dawidek DMU_OT_MASTER_NODE, /* ZAP */ 11801ba4a712SPawel Jakub Dawidek DMU_OT_UNLINKED_SET, /* ZAP */ 11811ba4a712SPawel Jakub Dawidek /* zvol: */ 11821ba4a712SPawel Jakub Dawidek DMU_OT_ZVOL, /* UINT8 */ 11831ba4a712SPawel Jakub Dawidek DMU_OT_ZVOL_PROP, /* ZAP */ 11841ba4a712SPawel Jakub Dawidek /* other; for testing only! */ 11851ba4a712SPawel Jakub Dawidek DMU_OT_PLAIN_OTHER, /* UINT8 */ 11861ba4a712SPawel Jakub Dawidek DMU_OT_UINT64_OTHER, /* UINT64 */ 11871ba4a712SPawel Jakub Dawidek DMU_OT_ZAP_OTHER, /* ZAP */ 11881ba4a712SPawel Jakub Dawidek /* new object types: */ 11891ba4a712SPawel Jakub Dawidek DMU_OT_ERROR_LOG, /* ZAP */ 11901ba4a712SPawel Jakub Dawidek DMU_OT_SPA_HISTORY, /* UINT8 */ 11911ba4a712SPawel Jakub Dawidek DMU_OT_SPA_HISTORY_OFFSETS, /* spa_his_phys_t */ 11921ba4a712SPawel Jakub Dawidek DMU_OT_POOL_PROPS, /* ZAP */ 119310b9d77bSPawel Jakub Dawidek DMU_OT_DSL_PERMS, /* ZAP */ 119410b9d77bSPawel Jakub Dawidek DMU_OT_ACL, /* ACL */ 119510b9d77bSPawel Jakub Dawidek DMU_OT_SYSACL, /* SYSACL */ 119610b9d77bSPawel Jakub Dawidek DMU_OT_FUID, /* FUID table (Packed NVLIST UINT8) */ 119710b9d77bSPawel Jakub Dawidek DMU_OT_FUID_SIZE, /* FUID table size UINT64 */ 119810b9d77bSPawel Jakub Dawidek DMU_OT_NEXT_CLONES, /* ZAP */ 119910b9d77bSPawel Jakub Dawidek DMU_OT_SCAN_QUEUE, /* ZAP */ 120010b9d77bSPawel Jakub Dawidek DMU_OT_USERGROUP_USED, /* ZAP */ 120110b9d77bSPawel Jakub Dawidek DMU_OT_USERGROUP_QUOTA, /* ZAP */ 120210b9d77bSPawel Jakub Dawidek DMU_OT_USERREFS, /* ZAP */ 120310b9d77bSPawel Jakub Dawidek DMU_OT_DDT_ZAP, /* ZAP */ 120410b9d77bSPawel Jakub Dawidek DMU_OT_DDT_STATS, /* ZAP */ 120510b9d77bSPawel Jakub Dawidek DMU_OT_SA, /* System attr */ 120610b9d77bSPawel Jakub Dawidek DMU_OT_SA_MASTER_NODE, /* ZAP */ 120710b9d77bSPawel Jakub Dawidek DMU_OT_SA_ATTR_REGISTRATION, /* ZAP */ 120810b9d77bSPawel Jakub Dawidek DMU_OT_SA_ATTR_LAYOUTS, /* ZAP */ 120910b9d77bSPawel Jakub Dawidek DMU_OT_SCAN_XLATE, /* ZAP */ 121010b9d77bSPawel Jakub Dawidek DMU_OT_DEDUP, /* fake dedup BP from ddt_bp_create() */ 1211*77649f35SMark Johnston DMU_OT_DEADLIST, /* ZAP */ 1212*77649f35SMark Johnston DMU_OT_DEADLIST_HDR, /* UINT64 */ 1213*77649f35SMark Johnston DMU_OT_DSL_CLONES, /* ZAP */ 1214*77649f35SMark Johnston DMU_OT_BPOBJ_SUBOBJ, /* UINT64 */ 12154deb8929SAllan Jude DMU_OT_NUMTYPES, 12164deb8929SAllan Jude 12174deb8929SAllan Jude /* 12184deb8929SAllan Jude * Names for valid types declared with DMU_OT(). 12194deb8929SAllan Jude */ 12204deb8929SAllan Jude DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE), 12214deb8929SAllan Jude DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE), 12224deb8929SAllan Jude DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE), 12234deb8929SAllan Jude DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE), 12244deb8929SAllan Jude DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE), 12254deb8929SAllan Jude DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE), 12264deb8929SAllan Jude DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE), 12274deb8929SAllan Jude DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE), 12284deb8929SAllan Jude DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE), 12294deb8929SAllan Jude DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE) 12301ba4a712SPawel Jakub Dawidek } dmu_object_type_t; 12311ba4a712SPawel Jakub Dawidek 12321ba4a712SPawel Jakub Dawidek typedef enum dmu_objset_type { 12331ba4a712SPawel Jakub Dawidek DMU_OST_NONE, 12341ba4a712SPawel Jakub Dawidek DMU_OST_META, 12351ba4a712SPawel Jakub Dawidek DMU_OST_ZFS, 12361ba4a712SPawel Jakub Dawidek DMU_OST_ZVOL, 12371ba4a712SPawel Jakub Dawidek DMU_OST_OTHER, /* For testing only! */ 12381ba4a712SPawel Jakub Dawidek DMU_OST_ANY, /* Be careful! */ 12391ba4a712SPawel Jakub Dawidek DMU_OST_NUMTYPES 12401ba4a712SPawel Jakub Dawidek } dmu_objset_type_t; 12411ba4a712SPawel Jakub Dawidek 12423c2db0efSToomas Soome #define ZAP_MAXVALUELEN (1024 * 8) 12433c2db0efSToomas Soome 12441ba4a712SPawel Jakub Dawidek /* 124510b9d77bSPawel Jakub Dawidek * header for all bonus and spill buffers. 124610b9d77bSPawel Jakub Dawidek * The header has a fixed portion with a variable number 124710b9d77bSPawel Jakub Dawidek * of "lengths" depending on the number of variable sized 124810b9d77bSPawel Jakub Dawidek * attribues which are determined by the "layout number" 124910b9d77bSPawel Jakub Dawidek */ 125010b9d77bSPawel Jakub Dawidek 125110b9d77bSPawel Jakub Dawidek #define SA_MAGIC 0x2F505A /* ZFS SA */ 125210b9d77bSPawel Jakub Dawidek typedef struct sa_hdr_phys { 125310b9d77bSPawel Jakub Dawidek uint32_t sa_magic; 125410b9d77bSPawel Jakub Dawidek uint16_t sa_layout_info; /* Encoded with hdrsize and layout number */ 125510b9d77bSPawel Jakub Dawidek uint16_t sa_lengths[1]; /* optional sizes for variable length attrs */ 125610b9d77bSPawel Jakub Dawidek /* ... Data follows the lengths. */ 125710b9d77bSPawel Jakub Dawidek } sa_hdr_phys_t; 125810b9d77bSPawel Jakub Dawidek 125910b9d77bSPawel Jakub Dawidek /* 126010b9d77bSPawel Jakub Dawidek * sa_hdr_phys -> sa_layout_info 126110b9d77bSPawel Jakub Dawidek * 126210b9d77bSPawel Jakub Dawidek * 16 10 0 126310b9d77bSPawel Jakub Dawidek * +--------+-------+ 126410b9d77bSPawel Jakub Dawidek * | hdrsz |layout | 126510b9d77bSPawel Jakub Dawidek * +--------+-------+ 126610b9d77bSPawel Jakub Dawidek * 126710b9d77bSPawel Jakub Dawidek * Bits 0-10 are the layout number 126810b9d77bSPawel Jakub Dawidek * Bits 11-16 are the size of the header. 126910b9d77bSPawel Jakub Dawidek * The hdrsize is the number * 8 127010b9d77bSPawel Jakub Dawidek * 127110b9d77bSPawel Jakub Dawidek * For example. 127210b9d77bSPawel Jakub Dawidek * hdrsz of 1 ==> 8 byte header 127310b9d77bSPawel Jakub Dawidek * 2 ==> 16 byte header 127410b9d77bSPawel Jakub Dawidek * 127510b9d77bSPawel Jakub Dawidek */ 127610b9d77bSPawel Jakub Dawidek 127710b9d77bSPawel Jakub Dawidek #define SA_HDR_LAYOUT_NUM(hdr) BF32_GET(hdr->sa_layout_info, 0, 10) 127810b9d77bSPawel Jakub Dawidek #define SA_HDR_SIZE(hdr) BF32_GET_SB(hdr->sa_layout_info, 10, 16, 3, 0) 127910b9d77bSPawel Jakub Dawidek #define SA_HDR_LAYOUT_INFO_ENCODE(x, num, size) \ 128010b9d77bSPawel Jakub Dawidek { \ 128110b9d77bSPawel Jakub Dawidek BF32_SET_SB(x, 10, 6, 3, 0, size); \ 128210b9d77bSPawel Jakub Dawidek BF32_SET(x, 0, 10, num); \ 128310b9d77bSPawel Jakub Dawidek } 128410b9d77bSPawel Jakub Dawidek 1285*77649f35SMark Johnston #define SA_ATTR_BSWAP(x) BF32_GET(x, 16, 8) 1286*77649f35SMark Johnston #define SA_ATTR_LENGTH(x) BF32_GET(x, 24, 16) 1287*77649f35SMark Johnston #define SA_ATTR_NUM(x) BF32_GET(x, 0, 16) 1288*77649f35SMark Johnston #define SA_ATTR_ENCODE(x, attr, length, bswap) \ 1289*77649f35SMark Johnston { \ 1290*77649f35SMark Johnston BF64_SET(x, 24, 16, length); \ 1291*77649f35SMark Johnston BF64_SET(x, 16, 8, bswap); \ 1292*77649f35SMark Johnston BF64_SET(x, 0, 16, attr); \ 1293*77649f35SMark Johnston } 1294*77649f35SMark Johnston 129510b9d77bSPawel Jakub Dawidek #define SA_MODE_OFFSET 0 129610b9d77bSPawel Jakub Dawidek #define SA_SIZE_OFFSET 8 129710b9d77bSPawel Jakub Dawidek #define SA_GEN_OFFSET 16 129810b9d77bSPawel Jakub Dawidek #define SA_UID_OFFSET 24 129910b9d77bSPawel Jakub Dawidek #define SA_GID_OFFSET 32 130010b9d77bSPawel Jakub Dawidek #define SA_PARENT_OFFSET 40 130184a6eddcSToomas Soome #define SA_SYMLINK_OFFSET 160 130210b9d77bSPawel Jakub Dawidek 1303*77649f35SMark Johnston #define SA_REGISTRY "REGISTRY" 1304*77649f35SMark Johnston #define SA_LAYOUTS "LAYOUTS" 1305*77649f35SMark Johnston 1306*77649f35SMark Johnston typedef enum sa_bswap_type { 1307*77649f35SMark Johnston SA_UINT64_ARRAY, 1308*77649f35SMark Johnston SA_UINT32_ARRAY, 1309*77649f35SMark Johnston SA_UINT16_ARRAY, 1310*77649f35SMark Johnston SA_UINT8_ARRAY, 1311*77649f35SMark Johnston SA_ACL, 1312*77649f35SMark Johnston } sa_bswap_type_t; 1313*77649f35SMark Johnston 1314*77649f35SMark Johnston typedef uint16_t sa_attr_type_t; 1315*77649f35SMark Johnston 131627e05a19SMatt Macy #define ZIO_OBJSET_MAC_LEN 32 131727e05a19SMatt Macy 131810b9d77bSPawel Jakub Dawidek /* 13191ba4a712SPawel Jakub Dawidek * Intent log header - this on disk structure holds fields to manage 13201ba4a712SPawel Jakub Dawidek * the log. All fields are 64 bit to easily handle cross architectures. 13211ba4a712SPawel Jakub Dawidek */ 13221ba4a712SPawel Jakub Dawidek typedef struct zil_header { 13231ba4a712SPawel Jakub Dawidek uint64_t zh_claim_txg; /* txg in which log blocks were claimed */ 13241ba4a712SPawel Jakub Dawidek uint64_t zh_replay_seq; /* highest replayed sequence number */ 13251ba4a712SPawel Jakub Dawidek blkptr_t zh_log; /* log chain */ 13261ba4a712SPawel Jakub Dawidek uint64_t zh_claim_seq; /* highest claimed sequence number */ 13271ba4a712SPawel Jakub Dawidek uint64_t zh_pad[5]; 13281ba4a712SPawel Jakub Dawidek } zil_header_t; 13291ba4a712SPawel Jakub Dawidek 133027e05a19SMatt Macy #define OBJSET_PHYS_SIZE_V2 2048 133127e05a19SMatt Macy #define OBJSET_PHYS_SIZE_V3 4096 133210b9d77bSPawel Jakub Dawidek 13331ba4a712SPawel Jakub Dawidek typedef struct objset_phys { 13341ba4a712SPawel Jakub Dawidek dnode_phys_t os_meta_dnode; 13351ba4a712SPawel Jakub Dawidek zil_header_t os_zil_header; 13361ba4a712SPawel Jakub Dawidek uint64_t os_type; 13378fc25799SMartin Matuska uint64_t os_flags; 133827e05a19SMatt Macy uint8_t os_portable_mac[ZIO_OBJSET_MAC_LEN]; 133927e05a19SMatt Macy uint8_t os_local_mac[ZIO_OBJSET_MAC_LEN]; 134027e05a19SMatt Macy char os_pad0[OBJSET_PHYS_SIZE_V2 - sizeof (dnode_phys_t)*3 - 134127e05a19SMatt Macy sizeof (zil_header_t) - sizeof (uint64_t)*2 - 134227e05a19SMatt Macy 2*ZIO_OBJSET_MAC_LEN]; 13438fc25799SMartin Matuska dnode_phys_t os_userused_dnode; 13448fc25799SMartin Matuska dnode_phys_t os_groupused_dnode; 134527e05a19SMatt Macy dnode_phys_t os_projectused_dnode; 134627e05a19SMatt Macy char os_pad1[OBJSET_PHYS_SIZE_V3 - OBJSET_PHYS_SIZE_V2 - 134727e05a19SMatt Macy sizeof (dnode_phys_t)]; 13481ba4a712SPawel Jakub Dawidek } objset_phys_t; 13491ba4a712SPawel Jakub Dawidek 1350*77649f35SMark Johnston typedef struct space_map_phys { 1351*77649f35SMark Johnston /* object number: not needed but kept for backwards compatibility */ 1352*77649f35SMark Johnston uint64_t smp_object; 1353*77649f35SMark Johnston 1354*77649f35SMark Johnston /* length of the object in bytes */ 1355*77649f35SMark Johnston uint64_t smp_length; 1356*77649f35SMark Johnston 1357*77649f35SMark Johnston /* space allocated from the map */ 1358*77649f35SMark Johnston int64_t smp_alloc; 1359*77649f35SMark Johnston } space_map_phys_t; 1360*77649f35SMark Johnston 1361*77649f35SMark Johnston typedef enum { 1362*77649f35SMark Johnston SM_ALLOC, 1363*77649f35SMark Johnston SM_FREE 1364*77649f35SMark Johnston } maptype_t; 1365*77649f35SMark Johnston 1366*77649f35SMark Johnston /* one-word entry constants */ 1367*77649f35SMark Johnston #define SM_DEBUG_PREFIX 2 1368*77649f35SMark Johnston #define SM_OFFSET_BITS 47 1369*77649f35SMark Johnston #define SM_RUN_BITS 15 1370*77649f35SMark Johnston 1371*77649f35SMark Johnston /* two-word entry constants */ 1372*77649f35SMark Johnston #define SM2_PREFIX 3 1373*77649f35SMark Johnston #define SM2_OFFSET_BITS 63 1374*77649f35SMark Johnston #define SM2_RUN_BITS 36 1375*77649f35SMark Johnston 1376*77649f35SMark Johnston #define SM_PREFIX_DECODE(x) BF64_DECODE(x, 62, 2) 1377*77649f35SMark Johnston #define SM_PREFIX_ENCODE(x) BF64_ENCODE(x, 62, 2) 1378*77649f35SMark Johnston 1379*77649f35SMark Johnston #define SM_DEBUG_ACTION_DECODE(x) BF64_DECODE(x, 60, 2) 1380*77649f35SMark Johnston #define SM_DEBUG_ACTION_ENCODE(x) BF64_ENCODE(x, 60, 2) 1381*77649f35SMark Johnston #define SM_DEBUG_SYNCPASS_DECODE(x) BF64_DECODE(x, 50, 10) 1382*77649f35SMark Johnston #define SM_DEBUG_SYNCPASS_ENCODE(x) BF64_ENCODE(x, 50, 10) 1383*77649f35SMark Johnston #define SM_DEBUG_TXG_DECODE(x) BF64_DECODE(x, 0, 50) 1384*77649f35SMark Johnston #define SM_DEBUG_TXG_ENCODE(x) BF64_ENCODE(x, 0, 50) 1385*77649f35SMark Johnston 1386*77649f35SMark Johnston #define SM_OFFSET_DECODE(x) BF64_DECODE(x, 16, SM_OFFSET_BITS) 1387*77649f35SMark Johnston #define SM_OFFSET_ENCODE(x) BF64_ENCODE(x, 16, SM_OFFSET_BITS) 1388*77649f35SMark Johnston #define SM_TYPE_DECODE(x) BF64_DECODE(x, 15, 1) 1389*77649f35SMark Johnston #define SM_TYPE_ENCODE(x) BF64_ENCODE(x, 15, 1) 1390*77649f35SMark Johnston #define SM_RUN_DECODE(x) (BF64_DECODE(x, 0, SM_RUN_BITS) + 1) 1391*77649f35SMark Johnston #define SM_RUN_ENCODE(x) BF64_ENCODE((x) - 1, 0, SM_RUN_BITS) 1392*77649f35SMark Johnston #define SM_RUN_MAX SM_RUN_DECODE(~0ULL) 1393*77649f35SMark Johnston #define SM_OFFSET_MAX SM_OFFSET_DECODE(~0ULL) 1394*77649f35SMark Johnston 1395*77649f35SMark Johnston #define SM2_RUN_DECODE(x) (BF64_DECODE(x, 24, SM2_RUN_BITS) + 1) 1396*77649f35SMark Johnston #define SM2_RUN_ENCODE(x) BF64_ENCODE((x) - 1, 24, SM2_RUN_BITS) 1397*77649f35SMark Johnston #define SM2_VDEV_DECODE(x) BF64_DECODE(x, 0, 24) 1398*77649f35SMark Johnston #define SM2_VDEV_ENCODE(x) BF64_ENCODE(x, 0, 24) 1399*77649f35SMark Johnston #define SM2_TYPE_DECODE(x) BF64_DECODE(x, SM2_OFFSET_BITS, 1) 1400*77649f35SMark Johnston #define SM2_TYPE_ENCODE(x) BF64_ENCODE(x, SM2_OFFSET_BITS, 1) 1401*77649f35SMark Johnston #define SM2_OFFSET_DECODE(x) BF64_DECODE(x, 0, SM2_OFFSET_BITS) 1402*77649f35SMark Johnston #define SM2_OFFSET_ENCODE(x) BF64_ENCODE(x, 0, SM2_OFFSET_BITS) 1403*77649f35SMark Johnston #define SM2_RUN_MAX SM2_RUN_DECODE(~0ULL) 1404*77649f35SMark Johnston #define SM2_OFFSET_MAX SM2_OFFSET_DECODE(~0ULL) 1405*77649f35SMark Johnston 14061ba4a712SPawel Jakub Dawidek typedef struct dsl_dir_phys { 14071ba4a712SPawel Jakub Dawidek uint64_t dd_creation_time; /* not actually used */ 14081ba4a712SPawel Jakub Dawidek uint64_t dd_head_dataset_obj; 14091ba4a712SPawel Jakub Dawidek uint64_t dd_parent_obj; 14101ba4a712SPawel Jakub Dawidek uint64_t dd_clone_parent_obj; 14111ba4a712SPawel Jakub Dawidek uint64_t dd_child_dir_zapobj; 14121ba4a712SPawel Jakub Dawidek /* 14131ba4a712SPawel Jakub Dawidek * how much space our children are accounting for; for leaf 14141ba4a712SPawel Jakub Dawidek * datasets, == physical space used by fs + snaps 14151ba4a712SPawel Jakub Dawidek */ 14161ba4a712SPawel Jakub Dawidek uint64_t dd_used_bytes; 14171ba4a712SPawel Jakub Dawidek uint64_t dd_compressed_bytes; 14181ba4a712SPawel Jakub Dawidek uint64_t dd_uncompressed_bytes; 14191ba4a712SPawel Jakub Dawidek /* Administrative quota setting */ 14201ba4a712SPawel Jakub Dawidek uint64_t dd_quota; 14211ba4a712SPawel Jakub Dawidek /* Administrative reservation setting */ 14221ba4a712SPawel Jakub Dawidek uint64_t dd_reserved; 14231ba4a712SPawel Jakub Dawidek uint64_t dd_props_zapobj; 1424*77649f35SMark Johnston uint64_t dd_pad[7]; 1425*77649f35SMark Johnston uint64_t dd_clones; 1426*77649f35SMark Johnston uint64_t dd_pad1[13]; /* pad out to 256 bytes for good measure */ 14271ba4a712SPawel Jakub Dawidek } dsl_dir_phys_t; 14281ba4a712SPawel Jakub Dawidek 14291ba4a712SPawel Jakub Dawidek typedef struct dsl_dataset_phys { 14301ba4a712SPawel Jakub Dawidek uint64_t ds_dir_obj; 14311ba4a712SPawel Jakub Dawidek uint64_t ds_prev_snap_obj; 14321ba4a712SPawel Jakub Dawidek uint64_t ds_prev_snap_txg; 14331ba4a712SPawel Jakub Dawidek uint64_t ds_next_snap_obj; 14341ba4a712SPawel Jakub Dawidek uint64_t ds_snapnames_zapobj; /* zap obj of snaps; ==0 for snaps */ 14351ba4a712SPawel Jakub Dawidek uint64_t ds_num_children; /* clone/snap children; ==0 for head */ 14361ba4a712SPawel Jakub Dawidek uint64_t ds_creation_time; /* seconds since 1970 */ 14371ba4a712SPawel Jakub Dawidek uint64_t ds_creation_txg; 14381ba4a712SPawel Jakub Dawidek uint64_t ds_deadlist_obj; 14391ba4a712SPawel Jakub Dawidek uint64_t ds_used_bytes; 14401ba4a712SPawel Jakub Dawidek uint64_t ds_compressed_bytes; 14411ba4a712SPawel Jakub Dawidek uint64_t ds_uncompressed_bytes; 14421ba4a712SPawel Jakub Dawidek uint64_t ds_unique_bytes; /* only relevant to snapshots */ 14431ba4a712SPawel Jakub Dawidek /* 14441ba4a712SPawel Jakub Dawidek * The ds_fsid_guid is a 56-bit ID that can change to avoid 14451ba4a712SPawel Jakub Dawidek * collisions. The ds_guid is a 64-bit ID that will never 14461ba4a712SPawel Jakub Dawidek * change, so there is a small probability that it will collide. 14471ba4a712SPawel Jakub Dawidek */ 14481ba4a712SPawel Jakub Dawidek uint64_t ds_fsid_guid; 14491ba4a712SPawel Jakub Dawidek uint64_t ds_guid; 14501ba4a712SPawel Jakub Dawidek uint64_t ds_flags; 14511ba4a712SPawel Jakub Dawidek blkptr_t ds_bp; 14521ba4a712SPawel Jakub Dawidek uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */ 14531ba4a712SPawel Jakub Dawidek } dsl_dataset_phys_t; 14541ba4a712SPawel Jakub Dawidek 1455*77649f35SMark Johnston typedef struct dsl_deadlist_phys { 1456*77649f35SMark Johnston uint64_t dl_used; 1457*77649f35SMark Johnston uint64_t dl_comp; 1458*77649f35SMark Johnston uint64_t dl_uncomp; 1459*77649f35SMark Johnston uint64_t dl_pad[37]; /* pad out to 320b for future expansion */ 1460*77649f35SMark Johnston } dsl_deadlist_phys_t; 1461*77649f35SMark Johnston 1462*77649f35SMark Johnston #define BPOBJ_SIZE_V2 (6 * sizeof (uint64_t)) 1463*77649f35SMark Johnston 1464*77649f35SMark Johnston typedef struct bpobj_phys { 1465*77649f35SMark Johnston uint64_t bpo_num_blkptrs; 1466*77649f35SMark Johnston uint64_t bpo_bytes; 1467*77649f35SMark Johnston uint64_t bpo_comp; 1468*77649f35SMark Johnston uint64_t bpo_uncomp; 1469*77649f35SMark Johnston uint64_t bpo_subobjs; 1470*77649f35SMark Johnston uint64_t bpo_num_subobjs; 1471*77649f35SMark Johnston uint64_t bpo_num_freed; 1472*77649f35SMark Johnston } bpobj_phys_t; 1473*77649f35SMark Johnston 14741ba4a712SPawel Jakub Dawidek /* 14751ba4a712SPawel Jakub Dawidek * The names of zap entries in the DIRECTORY_OBJECT of the MOS. 14761ba4a712SPawel Jakub Dawidek */ 14771ba4a712SPawel Jakub Dawidek #define DMU_POOL_DIRECTORY_OBJECT 1 14781ba4a712SPawel Jakub Dawidek #define DMU_POOL_CONFIG "config" 14794deb8929SAllan Jude #define DMU_POOL_FEATURES_FOR_READ "features_for_read" 1480*77649f35SMark Johnston #define DMU_POOL_FEATURES_FOR_WRITE "features_for_write" 1481*77649f35SMark Johnston #define DMU_POOL_FEATURE_DESCRIPTIONS "feature_descriptions" 14821ba4a712SPawel Jakub Dawidek #define DMU_POOL_ROOT_DATASET "root_dataset" 14831ba4a712SPawel Jakub Dawidek #define DMU_POOL_SYNC_BPLIST "sync_bplist" 14841ba4a712SPawel Jakub Dawidek #define DMU_POOL_ERRLOG_SCRUB "errlog_scrub" 14851ba4a712SPawel Jakub Dawidek #define DMU_POOL_ERRLOG_LAST "errlog_last" 14861ba4a712SPawel Jakub Dawidek #define DMU_POOL_SPARES "spares" 14871ba4a712SPawel Jakub Dawidek #define DMU_POOL_DEFLATE "deflate" 14881ba4a712SPawel Jakub Dawidek #define DMU_POOL_HISTORY "history" 14891ba4a712SPawel Jakub Dawidek #define DMU_POOL_PROPS "pool_props" 1490*77649f35SMark Johnston #define DMU_POOL_FREE_BPOBJ "free_bpobj" 1491*77649f35SMark Johnston #define DMU_POOL_BPTREE_OBJ "bptree_obj" 1492*77649f35SMark Johnston #define DMU_POOL_EMPTY_BPOBJ "empty_bpobj" 1493*77649f35SMark Johnston #define DMU_POOL_TMP_USERREFS "tmp_userrefs" 14942c55d090SToomas Soome #define DMU_POOL_CHECKSUM_SALT "org.illumos:checksum_salt" 1495b1b93268SToomas Soome #define DMU_POOL_REMOVING "com.delphix:removing" 1496b1b93268SToomas Soome #define DMU_POOL_OBSOLETE_BPOBJ "com.delphix:obsolete_bpobj" 1497b1b93268SToomas Soome #define DMU_POOL_CONDENSING_INDIRECT "com.delphix:condensing_indirect" 1498277f38abSMariusz Zaborski #define DMU_POOL_ZPOOL_CHECKPOINT "com.delphix:zpool_checkpoint" 14991ba4a712SPawel Jakub Dawidek 15001ba4a712SPawel Jakub Dawidek #define ZAP_MAGIC 0x2F52AB2ABULL 15011ba4a712SPawel Jakub Dawidek 15021ba4a712SPawel Jakub Dawidek #define FZAP_BLOCK_SHIFT(zap) ((zap)->zap_block_shift) 15031ba4a712SPawel Jakub Dawidek 15041ba4a712SPawel Jakub Dawidek #define ZAP_MAXCD (uint32_t)(-1) 15051ba4a712SPawel Jakub Dawidek #define ZAP_HASHBITS 28 15061ba4a712SPawel Jakub Dawidek #define MZAP_ENT_LEN 64 1507*77649f35SMark Johnston #define MZAP_ENT_MAX \ 1508*77649f35SMark Johnston ((MZAP_MAX_BLKSZ - sizeof(mzap_phys_t)) / sizeof(mzap_ent_phys_t) + 1) 15091ba4a712SPawel Jakub Dawidek #define MZAP_NAME_LEN (MZAP_ENT_LEN - 8 - 4 - 2) 1510*77649f35SMark Johnston #define MZAP_MAX_BLKSZ SPA_OLDMAXBLOCKSIZE 15111ba4a712SPawel Jakub Dawidek 15121ba4a712SPawel Jakub Dawidek typedef struct mzap_ent_phys { 15131ba4a712SPawel Jakub Dawidek uint64_t mze_value; 15141ba4a712SPawel Jakub Dawidek uint32_t mze_cd; 15151ba4a712SPawel Jakub Dawidek uint16_t mze_pad; /* in case we want to chain them someday */ 15161ba4a712SPawel Jakub Dawidek char mze_name[MZAP_NAME_LEN]; 15171ba4a712SPawel Jakub Dawidek } mzap_ent_phys_t; 15181ba4a712SPawel Jakub Dawidek 15191ba4a712SPawel Jakub Dawidek typedef struct mzap_phys { 15201ba4a712SPawel Jakub Dawidek uint64_t mz_block_type; /* ZBT_MICRO */ 15211ba4a712SPawel Jakub Dawidek uint64_t mz_salt; 15224d297e70SToomas Soome uint64_t mz_normflags; 15234d297e70SToomas Soome uint64_t mz_pad[5]; 15241ba4a712SPawel Jakub Dawidek mzap_ent_phys_t mz_chunk[1]; 15251ba4a712SPawel Jakub Dawidek /* actually variable size depending on block size */ 15261ba4a712SPawel Jakub Dawidek } mzap_phys_t; 15271ba4a712SPawel Jakub Dawidek 15281ba4a712SPawel Jakub Dawidek /* 15291ba4a712SPawel Jakub Dawidek * The (fat) zap is stored in one object. It is an array of 15301ba4a712SPawel Jakub Dawidek * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of: 15311ba4a712SPawel Jakub Dawidek * 15321ba4a712SPawel Jakub Dawidek * ptrtbl fits in first block: 15331ba4a712SPawel Jakub Dawidek * [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ... 15341ba4a712SPawel Jakub Dawidek * 15351ba4a712SPawel Jakub Dawidek * ptrtbl too big for first block: 15361ba4a712SPawel Jakub Dawidek * [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ... 15371ba4a712SPawel Jakub Dawidek * 15381ba4a712SPawel Jakub Dawidek */ 15391ba4a712SPawel Jakub Dawidek 15401ba4a712SPawel Jakub Dawidek #define ZBT_LEAF ((1ULL << 63) + 0) 15411ba4a712SPawel Jakub Dawidek #define ZBT_HEADER ((1ULL << 63) + 1) 15421ba4a712SPawel Jakub Dawidek #define ZBT_MICRO ((1ULL << 63) + 3) 15431ba4a712SPawel Jakub Dawidek /* any other values are ptrtbl blocks */ 15441ba4a712SPawel Jakub Dawidek 15451ba4a712SPawel Jakub Dawidek /* 15461ba4a712SPawel Jakub Dawidek * the embedded pointer table takes up half a block: 15471ba4a712SPawel Jakub Dawidek * block size / entry size (2^3) / 2 15481ba4a712SPawel Jakub Dawidek */ 15491ba4a712SPawel Jakub Dawidek #define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1) 15501ba4a712SPawel Jakub Dawidek 15511ba4a712SPawel Jakub Dawidek /* 15521ba4a712SPawel Jakub Dawidek * The embedded pointer table starts half-way through the block. Since 15531ba4a712SPawel Jakub Dawidek * the pointer table itself is half the block, it starts at (64-bit) 15541ba4a712SPawel Jakub Dawidek * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)). 15551ba4a712SPawel Jakub Dawidek */ 15561ba4a712SPawel Jakub Dawidek #define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \ 15571ba4a712SPawel Jakub Dawidek ((uint64_t *)(zap)->zap_phys) \ 15581ba4a712SPawel Jakub Dawidek [(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))] 15591ba4a712SPawel Jakub Dawidek 1560*77649f35SMark Johnston #define ZAP_HASH_IDX(hash, n) (((n) == 0) ? 0 : ((hash) >> (64 - (n)))) 1561*77649f35SMark Johnston 15621ba4a712SPawel Jakub Dawidek /* 15631ba4a712SPawel Jakub Dawidek * TAKE NOTE: 15641ba4a712SPawel Jakub Dawidek * If zap_phys_t is modified, zap_byteswap() must be modified. 15651ba4a712SPawel Jakub Dawidek */ 15661ba4a712SPawel Jakub Dawidek typedef struct zap_phys { 15671ba4a712SPawel Jakub Dawidek uint64_t zap_block_type; /* ZBT_HEADER */ 15681ba4a712SPawel Jakub Dawidek uint64_t zap_magic; /* ZAP_MAGIC */ 15691ba4a712SPawel Jakub Dawidek 15701ba4a712SPawel Jakub Dawidek struct zap_table_phys { 15711ba4a712SPawel Jakub Dawidek uint64_t zt_blk; /* starting block number */ 15721ba4a712SPawel Jakub Dawidek uint64_t zt_numblks; /* number of blocks */ 15731ba4a712SPawel Jakub Dawidek uint64_t zt_shift; /* bits to index it */ 15741ba4a712SPawel Jakub Dawidek uint64_t zt_nextblk; /* next (larger) copy start block */ 15751ba4a712SPawel Jakub Dawidek uint64_t zt_blks_copied; /* number source blocks copied */ 15761ba4a712SPawel Jakub Dawidek } zap_ptrtbl; 15771ba4a712SPawel Jakub Dawidek 15781ba4a712SPawel Jakub Dawidek uint64_t zap_freeblk; /* the next free block */ 15791ba4a712SPawel Jakub Dawidek uint64_t zap_num_leafs; /* number of leafs */ 15801ba4a712SPawel Jakub Dawidek uint64_t zap_num_entries; /* number of entries */ 15811ba4a712SPawel Jakub Dawidek uint64_t zap_salt; /* salt to stir into hash function */ 15824d297e70SToomas Soome uint64_t zap_normflags; /* flags for u8_textprep_str() */ 15834d297e70SToomas Soome uint64_t zap_flags; /* zap_flags_t */ 15841ba4a712SPawel Jakub Dawidek /* 15851ba4a712SPawel Jakub Dawidek * This structure is followed by padding, and then the embedded 15861ba4a712SPawel Jakub Dawidek * pointer table. The embedded pointer table takes up second 15871ba4a712SPawel Jakub Dawidek * half of the block. It is accessed using the 15881ba4a712SPawel Jakub Dawidek * ZAP_EMBEDDED_PTRTBL_ENT() macro. 15891ba4a712SPawel Jakub Dawidek */ 15901ba4a712SPawel Jakub Dawidek } zap_phys_t; 15911ba4a712SPawel Jakub Dawidek 15921ba4a712SPawel Jakub Dawidek typedef struct zap_table_phys zap_table_phys_t; 15931ba4a712SPawel Jakub Dawidek 15944d297e70SToomas Soome struct spa; 15951ba4a712SPawel Jakub Dawidek typedef struct fat_zap { 15961ba4a712SPawel Jakub Dawidek int zap_block_shift; /* block size shift */ 15971ba4a712SPawel Jakub Dawidek zap_phys_t *zap_phys; 15984d297e70SToomas Soome const struct spa *zap_spa; 15994d297e70SToomas Soome const dnode_phys_t *zap_dnode; 16001ba4a712SPawel Jakub Dawidek } fat_zap_t; 16011ba4a712SPawel Jakub Dawidek 16021ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_MAGIC 0x2AB1EAF 16031ba4a712SPawel Jakub Dawidek 16041ba4a712SPawel Jakub Dawidek /* chunk size = 24 bytes */ 16051ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_CHUNKSIZE 24 16061ba4a712SPawel Jakub Dawidek 16071ba4a712SPawel Jakub Dawidek /* 16081ba4a712SPawel Jakub Dawidek * The amount of space available for chunks is: 16091ba4a712SPawel Jakub Dawidek * block size (1<<l->l_bs) - hash entry size (2) * number of hash 16101ba4a712SPawel Jakub Dawidek * entries - header space (2*chunksize) 16111ba4a712SPawel Jakub Dawidek */ 16121ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_NUMCHUNKS(l) \ 16131ba4a712SPawel Jakub Dawidek (((1<<(l)->l_bs) - 2*ZAP_LEAF_HASH_NUMENTRIES(l)) / \ 16141ba4a712SPawel Jakub Dawidek ZAP_LEAF_CHUNKSIZE - 2) 16151ba4a712SPawel Jakub Dawidek 16161ba4a712SPawel Jakub Dawidek /* 16171ba4a712SPawel Jakub Dawidek * The amount of space within the chunk available for the array is: 16181ba4a712SPawel Jakub Dawidek * chunk size - space for type (1) - space for next pointer (2) 16191ba4a712SPawel Jakub Dawidek */ 16201ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3) 16211ba4a712SPawel Jakub Dawidek 16221ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_ARRAY_NCHUNKS(bytes) \ 16231ba4a712SPawel Jakub Dawidek (((bytes)+ZAP_LEAF_ARRAY_BYTES-1)/ZAP_LEAF_ARRAY_BYTES) 16241ba4a712SPawel Jakub Dawidek 16251ba4a712SPawel Jakub Dawidek /* 16261ba4a712SPawel Jakub Dawidek * Low water mark: when there are only this many chunks free, start 16271ba4a712SPawel Jakub Dawidek * growing the ptrtbl. Ideally, this should be larger than a 16281ba4a712SPawel Jakub Dawidek * "reasonably-sized" entry. 20 chunks is more than enough for the 16291ba4a712SPawel Jakub Dawidek * largest directory entry (MAXNAMELEN (256) byte name, 8-byte value), 16301ba4a712SPawel Jakub Dawidek * while still being only around 3% for 16k blocks. 16311ba4a712SPawel Jakub Dawidek */ 16321ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_LOW_WATER (20) 16331ba4a712SPawel Jakub Dawidek 16341ba4a712SPawel Jakub Dawidek /* 16351ba4a712SPawel Jakub Dawidek * The leaf hash table has block size / 2^5 (32) number of entries, 16361ba4a712SPawel Jakub Dawidek * which should be more than enough for the maximum number of entries, 16371ba4a712SPawel Jakub Dawidek * which is less than block size / CHUNKSIZE (24) / minimum number of 16381ba4a712SPawel Jakub Dawidek * chunks per entry (3). 16391ba4a712SPawel Jakub Dawidek */ 16401ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_HASH_SHIFT(l) ((l)->l_bs - 5) 16411ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_HASH_NUMENTRIES(l) (1 << ZAP_LEAF_HASH_SHIFT(l)) 16421ba4a712SPawel Jakub Dawidek 16431ba4a712SPawel Jakub Dawidek /* 16441ba4a712SPawel Jakub Dawidek * The chunks start immediately after the hash table. The end of the 16451ba4a712SPawel Jakub Dawidek * hash table is at l_hash + HASH_NUMENTRIES, which we simply cast to a 16461ba4a712SPawel Jakub Dawidek * chunk_t. 16471ba4a712SPawel Jakub Dawidek */ 16481ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_CHUNK(l, idx) \ 1649*77649f35SMark Johnston ((zap_leaf_chunk_t *)(void *) \ 16501ba4a712SPawel Jakub Dawidek ((l)->l_phys->l_hash + ZAP_LEAF_HASH_NUMENTRIES(l)))[idx] 16511ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_ENTRY(l, idx) (&ZAP_LEAF_CHUNK(l, idx).l_entry) 16521ba4a712SPawel Jakub Dawidek 1653*77649f35SMark Johnston #define ZAP_LEAF_HASH(l, h) \ 1654*77649f35SMark Johnston ((ZAP_LEAF_HASH_NUMENTRIES(l)-1) & \ 1655*77649f35SMark Johnston ((h) >> \ 1656*77649f35SMark Johnston (64 - ZAP_LEAF_HASH_SHIFT(l) - (l)->l_phys->l_hdr.lh_prefix_len))) 1657*77649f35SMark Johnston #define ZAP_LEAF_HASH_ENTPTR(l, h) (&(l)->l_phys->l_hash[ZAP_LEAF_HASH(l, h)]) 1658*77649f35SMark Johnston 16591ba4a712SPawel Jakub Dawidek typedef enum zap_chunk_type { 16601ba4a712SPawel Jakub Dawidek ZAP_CHUNK_FREE = 253, 16611ba4a712SPawel Jakub Dawidek ZAP_CHUNK_ENTRY = 252, 16621ba4a712SPawel Jakub Dawidek ZAP_CHUNK_ARRAY = 251, 16631ba4a712SPawel Jakub Dawidek ZAP_CHUNK_TYPE_MAX = 250 16641ba4a712SPawel Jakub Dawidek } zap_chunk_type_t; 16651ba4a712SPawel Jakub Dawidek 16661ba4a712SPawel Jakub Dawidek /* 16671ba4a712SPawel Jakub Dawidek * TAKE NOTE: 16681ba4a712SPawel Jakub Dawidek * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified. 16691ba4a712SPawel Jakub Dawidek */ 16701ba4a712SPawel Jakub Dawidek typedef struct zap_leaf_phys { 16711ba4a712SPawel Jakub Dawidek struct zap_leaf_header { 16721ba4a712SPawel Jakub Dawidek uint64_t lh_block_type; /* ZBT_LEAF */ 16731ba4a712SPawel Jakub Dawidek uint64_t lh_pad1; 16741ba4a712SPawel Jakub Dawidek uint64_t lh_prefix; /* hash prefix of this leaf */ 16751ba4a712SPawel Jakub Dawidek uint32_t lh_magic; /* ZAP_LEAF_MAGIC */ 16761ba4a712SPawel Jakub Dawidek uint16_t lh_nfree; /* number free chunks */ 16771ba4a712SPawel Jakub Dawidek uint16_t lh_nentries; /* number of entries */ 16781ba4a712SPawel Jakub Dawidek uint16_t lh_prefix_len; /* num bits used to id this */ 16791ba4a712SPawel Jakub Dawidek 16801ba4a712SPawel Jakub Dawidek /* above is accessable to zap, below is zap_leaf private */ 16811ba4a712SPawel Jakub Dawidek 16821ba4a712SPawel Jakub Dawidek uint16_t lh_freelist; /* chunk head of free list */ 16831ba4a712SPawel Jakub Dawidek uint8_t lh_pad2[12]; 16841ba4a712SPawel Jakub Dawidek } l_hdr; /* 2 24-byte chunks */ 16851ba4a712SPawel Jakub Dawidek 16861ba4a712SPawel Jakub Dawidek /* 16871ba4a712SPawel Jakub Dawidek * The header is followed by a hash table with 16881ba4a712SPawel Jakub Dawidek * ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is 16891ba4a712SPawel Jakub Dawidek * followed by an array of ZAP_LEAF_NUMCHUNKS(zap) 16901ba4a712SPawel Jakub Dawidek * zap_leaf_chunk structures. These structures are accessed 16911ba4a712SPawel Jakub Dawidek * with the ZAP_LEAF_CHUNK() macro. 16921ba4a712SPawel Jakub Dawidek */ 16931ba4a712SPawel Jakub Dawidek 16941ba4a712SPawel Jakub Dawidek uint16_t l_hash[1]; 16951ba4a712SPawel Jakub Dawidek } zap_leaf_phys_t; 16961ba4a712SPawel Jakub Dawidek 16971ba4a712SPawel Jakub Dawidek typedef union zap_leaf_chunk { 16981ba4a712SPawel Jakub Dawidek struct zap_leaf_entry { 16991ba4a712SPawel Jakub Dawidek uint8_t le_type; /* always ZAP_CHUNK_ENTRY */ 17004ed4f4cfSAndriy Gapon uint8_t le_value_intlen; /* size of ints */ 17011ba4a712SPawel Jakub Dawidek uint16_t le_next; /* next entry in hash chain */ 17021ba4a712SPawel Jakub Dawidek uint16_t le_name_chunk; /* first chunk of the name */ 17034ed4f4cfSAndriy Gapon uint16_t le_name_numints; /* bytes in name, incl null */ 17041ba4a712SPawel Jakub Dawidek uint16_t le_value_chunk; /* first chunk of the value */ 17054ed4f4cfSAndriy Gapon uint16_t le_value_numints; /* value length in ints */ 17061ba4a712SPawel Jakub Dawidek uint32_t le_cd; /* collision differentiator */ 17071ba4a712SPawel Jakub Dawidek uint64_t le_hash; /* hash value of the name */ 17081ba4a712SPawel Jakub Dawidek } l_entry; 17091ba4a712SPawel Jakub Dawidek struct zap_leaf_array { 17101ba4a712SPawel Jakub Dawidek uint8_t la_type; /* always ZAP_CHUNK_ARRAY */ 17111ba4a712SPawel Jakub Dawidek uint8_t la_array[ZAP_LEAF_ARRAY_BYTES]; 17121ba4a712SPawel Jakub Dawidek uint16_t la_next; /* next blk or CHAIN_END */ 17131ba4a712SPawel Jakub Dawidek } l_array; 17141ba4a712SPawel Jakub Dawidek struct zap_leaf_free { 17151ba4a712SPawel Jakub Dawidek uint8_t lf_type; /* always ZAP_CHUNK_FREE */ 17161ba4a712SPawel Jakub Dawidek uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES]; 17171ba4a712SPawel Jakub Dawidek uint16_t lf_next; /* next in free list, or CHAIN_END */ 17181ba4a712SPawel Jakub Dawidek } l_free; 17191ba4a712SPawel Jakub Dawidek } zap_leaf_chunk_t; 17201ba4a712SPawel Jakub Dawidek 17211ba4a712SPawel Jakub Dawidek typedef struct zap_leaf { 17221ba4a712SPawel Jakub Dawidek int l_bs; /* block size shift */ 17231ba4a712SPawel Jakub Dawidek zap_leaf_phys_t *l_phys; 17241ba4a712SPawel Jakub Dawidek } zap_leaf_t; 17251ba4a712SPawel Jakub Dawidek 1726*77649f35SMark Johnston #define ZAP_MAXNAMELEN 256 1727*77649f35SMark Johnston #define ZAP_MAXVALUELEN (1024 * 8) 1728*77649f35SMark Johnston 1729*77649f35SMark Johnston #define ACE_READ_DATA 0x00000001 /* file: read data */ 1730*77649f35SMark Johnston #define ACE_LIST_DIRECTORY 0x00000001 /* dir: list files */ 1731*77649f35SMark Johnston #define ACE_WRITE_DATA 0x00000002 /* file: write data */ 1732*77649f35SMark Johnston #define ACE_ADD_FILE 0x00000002 /* dir: create file */ 1733*77649f35SMark Johnston #define ACE_APPEND_DATA 0x00000004 /* file: append data */ 1734*77649f35SMark Johnston #define ACE_ADD_SUBDIRECTORY 0x00000004 /* dir: create subdir */ 1735*77649f35SMark Johnston #define ACE_READ_NAMED_ATTRS 0x00000008 /* FILE_READ_EA */ 1736*77649f35SMark Johnston #define ACE_WRITE_NAMED_ATTRS 0x00000010 /* FILE_WRITE_EA */ 1737*77649f35SMark Johnston #define ACE_EXECUTE 0x00000020 /* file: execute */ 1738*77649f35SMark Johnston #define ACE_TRAVERSE 0x00000020 /* dir: lookup name */ 1739*77649f35SMark Johnston #define ACE_DELETE_CHILD 0x00000040 /* dir: unlink child */ 1740*77649f35SMark Johnston #define ACE_READ_ATTRIBUTES 0x00000080 /* (all) stat, etc. */ 1741*77649f35SMark Johnston #define ACE_WRITE_ATTRIBUTES 0x00000100 /* (all) utimes, etc. */ 1742*77649f35SMark Johnston #define ACE_DELETE 0x00010000 /* (all) unlink self */ 1743*77649f35SMark Johnston #define ACE_READ_ACL 0x00020000 /* (all) getsecattr */ 1744*77649f35SMark Johnston #define ACE_WRITE_ACL 0x00040000 /* (all) setsecattr */ 1745*77649f35SMark Johnston #define ACE_WRITE_OWNER 0x00080000 /* (all) chown */ 1746*77649f35SMark Johnston #define ACE_SYNCHRONIZE 0x00100000 /* (all) */ 1747*77649f35SMark Johnston 1748*77649f35SMark Johnston #define ACE_FILE_INHERIT_ACE 0x0001 1749*77649f35SMark Johnston #define ACE_DIRECTORY_INHERIT_ACE 0x0002 1750*77649f35SMark Johnston #define ACE_NO_PROPAGATE_INHERIT_ACE 0x0004 1751*77649f35SMark Johnston #define ACE_INHERIT_ONLY_ACE 0x0008 1752*77649f35SMark Johnston #define ACE_SUCCESSFUL_ACCESS_ACE_FLAG 0x0010 1753*77649f35SMark Johnston #define ACE_FAILED_ACCESS_ACE_FLAG 0x0020 1754*77649f35SMark Johnston #define ACE_IDENTIFIER_GROUP 0x0040 1755*77649f35SMark Johnston #define ACE_INHERITED_ACE 0x0080 1756*77649f35SMark Johnston #define ACE_OWNER 0x1000 1757*77649f35SMark Johnston #define ACE_GROUP 0x2000 1758*77649f35SMark Johnston #define ACE_EVERYONE 0x4000 1759*77649f35SMark Johnston 1760*77649f35SMark Johnston #define ACE_ACCESS_ALLOWED_ACE_TYPE 0x0000 1761*77649f35SMark Johnston #define ACE_ACCESS_DENIED_ACE_TYPE 0x0001 1762*77649f35SMark Johnston #define ACE_SYSTEM_AUDIT_ACE_TYPE 0x0002 1763*77649f35SMark Johnston #define ACE_SYSTEM_ALARM_ACE_TYPE 0x0003 1764*77649f35SMark Johnston 1765*77649f35SMark Johnston typedef struct zfs_ace_hdr { 1766*77649f35SMark Johnston uint16_t z_type; 1767*77649f35SMark Johnston uint16_t z_flags; 1768*77649f35SMark Johnston uint32_t z_access_mask; 1769*77649f35SMark Johnston } zfs_ace_hdr_t; 1770*77649f35SMark Johnston 17711ba4a712SPawel Jakub Dawidek /* 17721ba4a712SPawel Jakub Dawidek * Define special zfs pflags 17731ba4a712SPawel Jakub Dawidek */ 17741ba4a712SPawel Jakub Dawidek #define ZFS_XATTR 0x1 /* is an extended attribute */ 17751ba4a712SPawel Jakub Dawidek #define ZFS_INHERIT_ACE 0x2 /* ace has inheritable ACEs */ 17761ba4a712SPawel Jakub Dawidek #define ZFS_ACL_TRIVIAL 0x4 /* files ACL is trivial */ 1777*77649f35SMark Johnston #define ZFS_ACL_OBJ_ACE 0x8 /* ACL has CMPLX Object ACE */ 1778*77649f35SMark Johnston #define ZFS_ACL_PROTECTED 0x10 /* ACL protected */ 1779*77649f35SMark Johnston #define ZFS_ACL_DEFAULTED 0x20 /* ACL should be defaulted */ 1780*77649f35SMark Johnston #define ZFS_ACL_AUTO_INHERIT 0x40 /* ACL should be inherited */ 1781*77649f35SMark Johnston #define ZFS_BONUS_SCANSTAMP 0x80 /* Scanstamp in bonus area */ 1782*77649f35SMark Johnston #define ZFS_NO_EXECS_DENIED 0x100 /* exec was given to everyone */ 1783*77649f35SMark Johnston 1784*77649f35SMark Johnston #define ZFS_READONLY 0x0000000100000000ull 1785*77649f35SMark Johnston #define ZFS_HIDDEN 0x0000000200000000ull 1786*77649f35SMark Johnston #define ZFS_SYSTEM 0x0000000400000000ull 1787*77649f35SMark Johnston #define ZFS_ARCHIVE 0x0000000800000000ull 1788*77649f35SMark Johnston #define ZFS_IMMUTABLE 0x0000001000000000ull 1789*77649f35SMark Johnston #define ZFS_NOUNLINK 0x0000002000000000ull 1790*77649f35SMark Johnston #define ZFS_APPENDONLY 0x0000004000000000ull 1791*77649f35SMark Johnston #define ZFS_NODUMP 0x0000008000000000ull 1792*77649f35SMark Johnston #define ZFS_OPAQUE 0x0000010000000000ull 1793*77649f35SMark Johnston #define ZFS_AV_QUARANTINED 0x0000020000000000ull 1794*77649f35SMark Johnston #define ZFS_AV_MODIFIED 0x0000040000000000ull 1795*77649f35SMark Johnston #define ZFS_REPARSE 0x0000080000000000ull 1796*77649f35SMark Johnston #define ZFS_OFFLINE 0x0000100000000000ull 1797*77649f35SMark Johnston #define ZFS_SPARSE 0x0000200000000000ull 17981ba4a712SPawel Jakub Dawidek 17991ba4a712SPawel Jakub Dawidek #define MASTER_NODE_OBJ 1 18001ba4a712SPawel Jakub Dawidek 18011ba4a712SPawel Jakub Dawidek /* 18021ba4a712SPawel Jakub Dawidek * special attributes for master node. 18031ba4a712SPawel Jakub Dawidek */ 18041ba4a712SPawel Jakub Dawidek 18051ba4a712SPawel Jakub Dawidek #define ZFS_FSID "FSID" 18061ba4a712SPawel Jakub Dawidek #define ZFS_UNLINKED_SET "DELETE_QUEUE" 18071ba4a712SPawel Jakub Dawidek #define ZFS_ROOT_OBJ "ROOT" 18081ba4a712SPawel Jakub Dawidek #define ZPL_VERSION_OBJ "VERSION" 18091ba4a712SPawel Jakub Dawidek #define ZFS_PROP_BLOCKPERPAGE "BLOCKPERPAGE" 18101ba4a712SPawel Jakub Dawidek #define ZFS_PROP_NOGROWBLOCKS "NOGROWBLOCKS" 1811*77649f35SMark Johnston #define ZFS_SA_ATTRS "SA_ATTRS" 18121ba4a712SPawel Jakub Dawidek 18131ba4a712SPawel Jakub Dawidek #define ZFS_FLAG_BLOCKPERPAGE 0x1 18141ba4a712SPawel Jakub Dawidek #define ZFS_FLAG_NOGROWBLOCKS 0x2 18151ba4a712SPawel Jakub Dawidek 18161ba4a712SPawel Jakub Dawidek /* 18171ba4a712SPawel Jakub Dawidek * ZPL version - rev'd whenever an incompatible on-disk format change 18181ba4a712SPawel Jakub Dawidek * occurs. Independent of SPA/DMU/ZAP versioning. 18191ba4a712SPawel Jakub Dawidek */ 18201ba4a712SPawel Jakub Dawidek 18211ba4a712SPawel Jakub Dawidek #define ZPL_VERSION 1ULL 18221ba4a712SPawel Jakub Dawidek 18231ba4a712SPawel Jakub Dawidek /* 18241ba4a712SPawel Jakub Dawidek * The directory entry has the type (currently unused on Solaris) in the 18251ba4a712SPawel Jakub Dawidek * top 4 bits, and the object number in the low 48 bits. The "middle" 18261ba4a712SPawel Jakub Dawidek * 12 bits are unused. 18271ba4a712SPawel Jakub Dawidek */ 18281ba4a712SPawel Jakub Dawidek #define ZFS_DIRENT_TYPE(de) BF64_GET(de, 60, 4) 18291ba4a712SPawel Jakub Dawidek #define ZFS_DIRENT_OBJ(de) BF64_GET(de, 0, 48) 18301ba4a712SPawel Jakub Dawidek #define ZFS_DIRENT_MAKE(type, obj) (((uint64_t)type << 60) | obj) 18311ba4a712SPawel Jakub Dawidek 18321ba4a712SPawel Jakub Dawidek typedef struct ace { 18331ba4a712SPawel Jakub Dawidek uid_t a_who; /* uid or gid */ 18341ba4a712SPawel Jakub Dawidek uint32_t a_access_mask; /* read,write,... */ 18351ba4a712SPawel Jakub Dawidek uint16_t a_flags; /* see below */ 18361ba4a712SPawel Jakub Dawidek uint16_t a_type; /* allow or deny */ 18371ba4a712SPawel Jakub Dawidek } ace_t; 18381ba4a712SPawel Jakub Dawidek 18391ba4a712SPawel Jakub Dawidek #define ACE_SLOT_CNT 6 18401ba4a712SPawel Jakub Dawidek 18411ba4a712SPawel Jakub Dawidek typedef struct zfs_znode_acl { 18421ba4a712SPawel Jakub Dawidek uint64_t z_acl_extern_obj; /* ext acl pieces */ 18431ba4a712SPawel Jakub Dawidek uint32_t z_acl_count; /* Number of ACEs */ 18441ba4a712SPawel Jakub Dawidek uint16_t z_acl_version; /* acl version */ 18451ba4a712SPawel Jakub Dawidek uint16_t z_acl_pad; /* pad */ 18461ba4a712SPawel Jakub Dawidek ace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */ 18471ba4a712SPawel Jakub Dawidek } zfs_znode_acl_t; 18481ba4a712SPawel Jakub Dawidek 18491ba4a712SPawel Jakub Dawidek /* 18501ba4a712SPawel Jakub Dawidek * This is the persistent portion of the znode. It is stored 18511ba4a712SPawel Jakub Dawidek * in the "bonus buffer" of the file. Short symbolic links 18521ba4a712SPawel Jakub Dawidek * are also stored in the bonus buffer. 18531ba4a712SPawel Jakub Dawidek */ 18541ba4a712SPawel Jakub Dawidek typedef struct znode_phys { 18551ba4a712SPawel Jakub Dawidek uint64_t zp_atime[2]; /* 0 - last file access time */ 18561ba4a712SPawel Jakub Dawidek uint64_t zp_mtime[2]; /* 16 - last file modification time */ 18571ba4a712SPawel Jakub Dawidek uint64_t zp_ctime[2]; /* 32 - last file change time */ 18581ba4a712SPawel Jakub Dawidek uint64_t zp_crtime[2]; /* 48 - creation time */ 18591ba4a712SPawel Jakub Dawidek uint64_t zp_gen; /* 64 - generation (txg of creation) */ 18601ba4a712SPawel Jakub Dawidek uint64_t zp_mode; /* 72 - file mode bits */ 18611ba4a712SPawel Jakub Dawidek uint64_t zp_size; /* 80 - size of file */ 18621ba4a712SPawel Jakub Dawidek uint64_t zp_parent; /* 88 - directory parent (`..') */ 18631ba4a712SPawel Jakub Dawidek uint64_t zp_links; /* 96 - number of links to file */ 18641ba4a712SPawel Jakub Dawidek uint64_t zp_xattr; /* 104 - DMU object for xattrs */ 18651ba4a712SPawel Jakub Dawidek uint64_t zp_rdev; /* 112 - dev_t for VBLK & VCHR files */ 18661ba4a712SPawel Jakub Dawidek uint64_t zp_flags; /* 120 - persistent flags */ 18671ba4a712SPawel Jakub Dawidek uint64_t zp_uid; /* 128 - file owner */ 18681ba4a712SPawel Jakub Dawidek uint64_t zp_gid; /* 136 - owning group */ 18691ba4a712SPawel Jakub Dawidek uint64_t zp_pad[4]; /* 144 - future */ 18701ba4a712SPawel Jakub Dawidek zfs_znode_acl_t zp_acl; /* 176 - 263 ACL */ 18711ba4a712SPawel Jakub Dawidek /* 18721ba4a712SPawel Jakub Dawidek * Data may pad out any remaining bytes in the znode buffer, eg: 18731ba4a712SPawel Jakub Dawidek * 18741ba4a712SPawel Jakub Dawidek * |<---------------------- dnode_phys (512) ------------------------>| 18751ba4a712SPawel Jakub Dawidek * |<-- dnode (192) --->|<----------- "bonus" buffer (320) ---------->| 18761ba4a712SPawel Jakub Dawidek * |<---- znode (264) ---->|<---- data (56) ---->| 18771ba4a712SPawel Jakub Dawidek * 18781ba4a712SPawel Jakub Dawidek * At present, we only use this space to store symbolic links. 18791ba4a712SPawel Jakub Dawidek */ 18801ba4a712SPawel Jakub Dawidek } znode_phys_t; 18811ba4a712SPawel Jakub Dawidek 18821ba4a712SPawel Jakub Dawidek /* 18831ba4a712SPawel Jakub Dawidek * In-core vdev representation. 18841ba4a712SPawel Jakub Dawidek */ 18851ba4a712SPawel Jakub Dawidek struct vdev; 18862c55d090SToomas Soome struct spa; 1887e307eb94SToomas Soome typedef int vdev_phys_read_t(struct vdev *, void *, off_t, void *, size_t); 1888e307eb94SToomas Soome typedef int vdev_phys_write_t(struct vdev *, off_t, void *, size_t); 1889e307eb94SToomas Soome typedef int vdev_read_t(struct vdev *, const blkptr_t *, void *, off_t, size_t); 18901ba4a712SPawel Jakub Dawidek 18911ba4a712SPawel Jakub Dawidek typedef STAILQ_HEAD(vdev_list, vdev) vdev_list_t; 18921ba4a712SPawel Jakub Dawidek 1893b1b93268SToomas Soome typedef struct vdev_indirect_mapping_entry_phys { 1894b1b93268SToomas Soome /* 1895b1b93268SToomas Soome * Decode with DVA_MAPPING_* macros. 1896b1b93268SToomas Soome * Contains: 1897b1b93268SToomas Soome * the source offset (low 63 bits) 1898b1b93268SToomas Soome * the one-bit "mark", used for garbage collection (by zdb) 1899b1b93268SToomas Soome */ 1900b1b93268SToomas Soome uint64_t vimep_src; 1901b1b93268SToomas Soome 1902b1b93268SToomas Soome /* 1903b1b93268SToomas Soome * Note: the DVA's asize is 24 bits, and can thus store ranges 1904b1b93268SToomas Soome * up to 8GB. 1905b1b93268SToomas Soome */ 1906b1b93268SToomas Soome dva_t vimep_dst; 1907b1b93268SToomas Soome } vdev_indirect_mapping_entry_phys_t; 1908b1b93268SToomas Soome 1909b1b93268SToomas Soome #define DVA_MAPPING_GET_SRC_OFFSET(vimep) \ 1910b1b93268SToomas Soome BF64_GET_SB((vimep)->vimep_src, 0, 63, SPA_MINBLOCKSHIFT, 0) 1911b1b93268SToomas Soome #define DVA_MAPPING_SET_SRC_OFFSET(vimep, x) \ 1912b1b93268SToomas Soome BF64_SET_SB((vimep)->vimep_src, 0, 63, SPA_MINBLOCKSHIFT, 0, x) 1913b1b93268SToomas Soome 1914b1b93268SToomas Soome /* 1915b1b93268SToomas Soome * This is stored in the bonus buffer of the mapping object, see comment of 1916b1b93268SToomas Soome * vdev_indirect_config for more details. 1917b1b93268SToomas Soome */ 1918b1b93268SToomas Soome typedef struct vdev_indirect_mapping_phys { 1919b1b93268SToomas Soome uint64_t vimp_max_offset; 1920b1b93268SToomas Soome uint64_t vimp_bytes_mapped; 1921b1b93268SToomas Soome uint64_t vimp_num_entries; /* number of v_i_m_entry_phys_t's */ 1922b1b93268SToomas Soome 1923b1b93268SToomas Soome /* 1924b1b93268SToomas Soome * For each entry in the mapping object, this object contains an 1925b1b93268SToomas Soome * entry representing the number of bytes of that mapping entry 1926b1b93268SToomas Soome * that were no longer in use by the pool at the time this indirect 1927b1b93268SToomas Soome * vdev was last condensed. 1928b1b93268SToomas Soome */ 1929b1b93268SToomas Soome uint64_t vimp_counts_object; 1930b1b93268SToomas Soome } vdev_indirect_mapping_phys_t; 1931b1b93268SToomas Soome 1932b1b93268SToomas Soome #define VDEV_INDIRECT_MAPPING_SIZE_V0 (3 * sizeof (uint64_t)) 1933b1b93268SToomas Soome 1934b1b93268SToomas Soome typedef struct vdev_indirect_mapping { 1935b1b93268SToomas Soome uint64_t vim_object; 1936b1b93268SToomas Soome boolean_t vim_havecounts; 1937b1b93268SToomas Soome 1938b1b93268SToomas Soome /* vim_entries segment offset currently in memory. */ 1939b1b93268SToomas Soome uint64_t vim_entry_offset; 1940b1b93268SToomas Soome /* vim_entries segment size. */ 1941b1b93268SToomas Soome size_t vim_num_entries; 1942b1b93268SToomas Soome 1943b1b93268SToomas Soome /* Needed by dnode_read() */ 1944b1b93268SToomas Soome const void *vim_spa; 1945b1b93268SToomas Soome dnode_phys_t *vim_dn; 1946b1b93268SToomas Soome 1947b1b93268SToomas Soome /* 1948b1b93268SToomas Soome * An ordered array of mapping entries, sorted by source offset. 1949b1b93268SToomas Soome * Note that vim_entries is needed during a removal (and contains 1950b1b93268SToomas Soome * mappings that have been synced to disk so far) to handle frees 1951b1b93268SToomas Soome * from the removing device. 1952b1b93268SToomas Soome */ 1953b1b93268SToomas Soome vdev_indirect_mapping_entry_phys_t *vim_entries; 1954b1b93268SToomas Soome objset_phys_t *vim_objset; 1955b1b93268SToomas Soome vdev_indirect_mapping_phys_t *vim_phys; 1956b1b93268SToomas Soome } vdev_indirect_mapping_t; 1957b1b93268SToomas Soome 1958b1b93268SToomas Soome /* 1959b1b93268SToomas Soome * On-disk indirect vdev state. 1960b1b93268SToomas Soome * 1961b1b93268SToomas Soome * An indirect vdev is described exclusively in the MOS config of a pool. 1962b1b93268SToomas Soome * The config for an indirect vdev includes several fields, which are 1963b1b93268SToomas Soome * accessed in memory by a vdev_indirect_config_t. 1964b1b93268SToomas Soome */ 1965b1b93268SToomas Soome typedef struct vdev_indirect_config { 1966b1b93268SToomas Soome /* 1967b1b93268SToomas Soome * Object (in MOS) which contains the indirect mapping. This object 1968b1b93268SToomas Soome * contains an array of vdev_indirect_mapping_entry_phys_t ordered by 1969b1b93268SToomas Soome * vimep_src. The bonus buffer for this object is a 1970b1b93268SToomas Soome * vdev_indirect_mapping_phys_t. This object is allocated when a vdev 1971b1b93268SToomas Soome * removal is initiated. 1972b1b93268SToomas Soome * 1973b1b93268SToomas Soome * Note that this object can be empty if none of the data on the vdev 1974b1b93268SToomas Soome * has been copied yet. 1975b1b93268SToomas Soome */ 1976b1b93268SToomas Soome uint64_t vic_mapping_object; 1977b1b93268SToomas Soome 1978b1b93268SToomas Soome /* 1979b1b93268SToomas Soome * Object (in MOS) which contains the birth times for the mapping 1980b1b93268SToomas Soome * entries. This object contains an array of 1981b1b93268SToomas Soome * vdev_indirect_birth_entry_phys_t sorted by vibe_offset. The bonus 1982b1b93268SToomas Soome * buffer for this object is a vdev_indirect_birth_phys_t. This object 1983b1b93268SToomas Soome * is allocated when a vdev removal is initiated. 1984b1b93268SToomas Soome * 1985b1b93268SToomas Soome * Note that this object can be empty if none of the vdev has yet been 1986b1b93268SToomas Soome * copied. 1987b1b93268SToomas Soome */ 1988b1b93268SToomas Soome uint64_t vic_births_object; 1989b1b93268SToomas Soome 1990b1b93268SToomas Soome /* 1991b1b93268SToomas Soome * This is the vdev ID which was removed previous to this vdev, or 1992b1b93268SToomas Soome * UINT64_MAX if there are no previously removed vdevs. 1993b1b93268SToomas Soome */ 1994b1b93268SToomas Soome uint64_t vic_prev_indirect_vdev; 1995b1b93268SToomas Soome } vdev_indirect_config_t; 1996b1b93268SToomas Soome 19971ba4a712SPawel Jakub Dawidek typedef struct vdev { 19981ba4a712SPawel Jakub Dawidek STAILQ_ENTRY(vdev) v_childlink; /* link in parent's child list */ 19991ba4a712SPawel Jakub Dawidek STAILQ_ENTRY(vdev) v_alllink; /* link in global vdev list */ 20001ba4a712SPawel Jakub Dawidek vdev_list_t v_children; /* children of this vdev */ 200110b9d77bSPawel Jakub Dawidek const char *v_name; /* vdev name */ 20021ba4a712SPawel Jakub Dawidek uint64_t v_guid; /* vdev guid */ 2003abca0bd5SToomas Soome uint64_t v_id; /* index in parent */ 2004abca0bd5SToomas Soome uint64_t v_psize; /* physical device capacity */ 2005e1899ef6SDoug Rabson int v_ashift; /* offset to block shift */ 2006e1899ef6SDoug Rabson int v_nparity; /* # parity for raidz */ 200710b9d77bSPawel Jakub Dawidek struct vdev *v_top; /* parent vdev */ 20083c2db0efSToomas Soome size_t v_nchildren; /* # children */ 20091ba4a712SPawel Jakub Dawidek vdev_state_t v_state; /* current state */ 2010e1899ef6SDoug Rabson vdev_phys_read_t *v_phys_read; /* read from raw leaf vdev */ 2011e307eb94SToomas Soome vdev_phys_write_t *v_phys_write; /* write to raw leaf vdev */ 2012e1899ef6SDoug Rabson vdev_read_t *v_read; /* read from vdev */ 2013e307eb94SToomas Soome void *v_priv; /* data for read/write function */ 20140c0a882cSToomas Soome boolean_t v_islog; 20153c2db0efSToomas Soome struct spa *v_spa; /* link to spa */ 2016b1b93268SToomas Soome /* 2017b1b93268SToomas Soome * Values stored in the config for an indirect or removing vdev. 2018b1b93268SToomas Soome */ 2019b1b93268SToomas Soome vdev_indirect_config_t vdev_indirect_config; 2020b1b93268SToomas Soome vdev_indirect_mapping_t *v_mapping; 20211ba4a712SPawel Jakub Dawidek } vdev_t; 20221ba4a712SPawel Jakub Dawidek 20231ba4a712SPawel Jakub Dawidek /* 20241ba4a712SPawel Jakub Dawidek * In-core pool representation. 20251ba4a712SPawel Jakub Dawidek */ 20261ba4a712SPawel Jakub Dawidek typedef STAILQ_HEAD(spa_list, spa) spa_list_t; 20271ba4a712SPawel Jakub Dawidek 20281ba4a712SPawel Jakub Dawidek typedef struct spa { 20291ba4a712SPawel Jakub Dawidek STAILQ_ENTRY(spa) spa_link; /* link in global pool list */ 20301ba4a712SPawel Jakub Dawidek char *spa_name; /* pool name */ 20311ba4a712SPawel Jakub Dawidek uint64_t spa_guid; /* pool guid */ 20321ba4a712SPawel Jakub Dawidek uint64_t spa_txg; /* most recent transaction */ 2033277f38abSMariusz Zaborski struct uberblock *spa_uberblock; /* best uberblock so far */ 20343c2db0efSToomas Soome vdev_t *spa_root_vdev; /* toplevel vdev container */ 2035277f38abSMariusz Zaborski objset_phys_t *spa_mos; /* MOS for this pool */ 20362c55d090SToomas Soome zio_cksum_salt_t spa_cksum_salt; /* secret salt for cksum */ 20372c55d090SToomas Soome void *spa_cksum_tmpls[ZIO_CHECKSUM_FUNCTIONS]; 20380c0a882cSToomas Soome boolean_t spa_with_log; /* this pool has log */ 2039277f38abSMariusz Zaborski 2040277f38abSMariusz Zaborski struct uberblock spa_uberblock_master; /* best uberblock so far */ 2041277f38abSMariusz Zaborski objset_phys_t spa_mos_master; /* MOS for this pool */ 2042277f38abSMariusz Zaborski struct uberblock spa_uberblock_checkpoint; /* checkpoint uberblock */ 2043277f38abSMariusz Zaborski objset_phys_t spa_mos_checkpoint; /* Checkpoint MOS */ 2044e307eb94SToomas Soome void *spa_bootenv; /* bootenv from pool label */ 20451ba4a712SPawel Jakub Dawidek } spa_t; 204629441ba3SXin LI 2047b1b93268SToomas Soome /* IO related arguments. */ 2048b1b93268SToomas Soome typedef struct zio { 2049b1b93268SToomas Soome spa_t *io_spa; 2050b1b93268SToomas Soome blkptr_t *io_bp; 2051b1b93268SToomas Soome void *io_data; 2052b1b93268SToomas Soome uint64_t io_size; 2053b1b93268SToomas Soome uint64_t io_offset; 2054b1b93268SToomas Soome 2055b1b93268SToomas Soome /* Stuff for the vdev stack */ 2056b1b93268SToomas Soome vdev_t *io_vd; 2057b1b93268SToomas Soome void *io_vsd; 2058b1b93268SToomas Soome 2059b1b93268SToomas Soome int io_error; 2060b1b93268SToomas Soome } zio_t; 2061b1b93268SToomas Soome 2062*77649f35SMark Johnston extern void decode_embedded_bp_compressed(const blkptr_t *, void *); 20633830659eSToomas Soome 20643830659eSToomas Soome #endif /* _ZFSIMPL_H_ */ 2065