11ba4a712SPawel Jakub Dawidek /*- 21ba4a712SPawel Jakub Dawidek * Copyright (c) 2002 McAfee, Inc. 31ba4a712SPawel Jakub Dawidek * All rights reserved. 41ba4a712SPawel Jakub Dawidek * 51ba4a712SPawel Jakub Dawidek * This software was developed for the FreeBSD Project by Marshall 61ba4a712SPawel Jakub Dawidek * Kirk McKusick and McAfee Research,, the Security Research Division of 71ba4a712SPawel Jakub Dawidek * McAfee, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as 81ba4a712SPawel Jakub Dawidek * part of the DARPA CHATS research program 91ba4a712SPawel Jakub Dawidek * 101ba4a712SPawel Jakub Dawidek * Redistribution and use in source and binary forms, with or without 111ba4a712SPawel Jakub Dawidek * modification, are permitted provided that the following conditions 121ba4a712SPawel Jakub Dawidek * are met: 131ba4a712SPawel Jakub Dawidek * 1. Redistributions of source code must retain the above copyright 141ba4a712SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer. 151ba4a712SPawel Jakub Dawidek * 2. Redistributions in binary form must reproduce the above copyright 161ba4a712SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer in the 171ba4a712SPawel Jakub Dawidek * documentation and/or other materials provided with the distribution. 181ba4a712SPawel Jakub Dawidek * 191ba4a712SPawel Jakub Dawidek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 201ba4a712SPawel Jakub Dawidek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 211ba4a712SPawel Jakub Dawidek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221ba4a712SPawel Jakub Dawidek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 231ba4a712SPawel Jakub Dawidek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241ba4a712SPawel Jakub Dawidek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251ba4a712SPawel Jakub Dawidek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 261ba4a712SPawel Jakub Dawidek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271ba4a712SPawel Jakub Dawidek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 281ba4a712SPawel Jakub Dawidek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 291ba4a712SPawel Jakub Dawidek * SUCH DAMAGE. 301ba4a712SPawel Jakub Dawidek */ 311ba4a712SPawel Jakub Dawidek /* 321ba4a712SPawel Jakub Dawidek * CDDL HEADER START 331ba4a712SPawel Jakub Dawidek * 341ba4a712SPawel Jakub Dawidek * The contents of this file are subject to the terms of the 351ba4a712SPawel Jakub Dawidek * Common Development and Distribution License (the "License"). 361ba4a712SPawel Jakub Dawidek * You may not use this file except in compliance with the License. 371ba4a712SPawel Jakub Dawidek * 381ba4a712SPawel Jakub Dawidek * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 391ba4a712SPawel Jakub Dawidek * or http://www.opensolaris.org/os/licensing. 401ba4a712SPawel Jakub Dawidek * See the License for the specific language governing permissions 411ba4a712SPawel Jakub Dawidek * and limitations under the License. 421ba4a712SPawel Jakub Dawidek * 431ba4a712SPawel Jakub Dawidek * When distributing Covered Code, include this CDDL HEADER in each 441ba4a712SPawel Jakub Dawidek * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 451ba4a712SPawel Jakub Dawidek * If applicable, add the following below this CDDL HEADER, with the 461ba4a712SPawel Jakub Dawidek * fields enclosed by brackets "[]" replaced with your own identifying 471ba4a712SPawel Jakub Dawidek * information: Portions Copyright [yyyy] [name of copyright owner] 481ba4a712SPawel Jakub Dawidek * 491ba4a712SPawel Jakub Dawidek * CDDL HEADER END 501ba4a712SPawel Jakub Dawidek */ 511ba4a712SPawel Jakub Dawidek /* 528fc25799SMartin Matuska * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 531ba4a712SPawel Jakub Dawidek * Use is subject to license terms. 541ba4a712SPawel Jakub Dawidek */ 55ef17620fSXin LI /* 56ef17620fSXin LI * Copyright 2013 by Saso Kiselkov. All rights reserved. 57ef17620fSXin LI */ 5829441ba3SXin LI /* 5929441ba3SXin LI * Copyright (c) 2013 by Delphix. All rights reserved. 6029441ba3SXin LI */ 611ba4a712SPawel Jakub Dawidek 622d9cf57eSMartin Matuska #define MAXNAMELEN 256 632d9cf57eSMartin Matuska 6429441ba3SXin LI #define _NOTE(s) 6529441ba3SXin LI 6679a4bf89SToomas Soome /* 6779a4bf89SToomas Soome * AVL comparator helpers 6879a4bf89SToomas Soome */ 6979a4bf89SToomas Soome #define AVL_ISIGN(a) (((a) > 0) - ((a) < 0)) 7079a4bf89SToomas Soome #define AVL_CMP(a, b) (((a) > (b)) - ((a) < (b))) 7179a4bf89SToomas Soome #define AVL_PCMP(a, b) \ 7279a4bf89SToomas Soome (((uintptr_t)(a) > (uintptr_t)(b)) - ((uintptr_t)(a) < (uintptr_t)(b))) 7379a4bf89SToomas Soome 744deb8929SAllan Jude typedef enum { B_FALSE, B_TRUE } boolean_t; 754deb8929SAllan Jude 761ba4a712SPawel Jakub Dawidek /* CRC64 table */ 771ba4a712SPawel Jakub Dawidek #define ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */ 781ba4a712SPawel Jakub Dawidek 791ba4a712SPawel Jakub Dawidek /* 801ba4a712SPawel Jakub Dawidek * Macros for various sorts of alignment and rounding when the alignment 811ba4a712SPawel Jakub Dawidek * is known to be a power of 2. 821ba4a712SPawel Jakub Dawidek */ 831ba4a712SPawel Jakub Dawidek #define P2ALIGN(x, align) ((x) & -(align)) 841ba4a712SPawel Jakub Dawidek #define P2PHASE(x, align) ((x) & ((align) - 1)) 851ba4a712SPawel Jakub Dawidek #define P2NPHASE(x, align) (-(x) & ((align) - 1)) 861ba4a712SPawel Jakub Dawidek #define P2ROUNDUP(x, align) (-(-(x) & -(align))) 871ba4a712SPawel Jakub Dawidek #define P2END(x, align) (-(~(x) & -(align))) 881ba4a712SPawel Jakub Dawidek #define P2PHASEUP(x, align, phase) ((phase) - (((phase) - (x)) & -(align))) 89c43d127aSMartin Matuska #define P2BOUNDARY(off, len, align) (((off) ^ ((off) + (len) - 1)) > (align) - 1) 901ba4a712SPawel Jakub Dawidek 911ba4a712SPawel Jakub Dawidek /* 921ba4a712SPawel Jakub Dawidek * General-purpose 32-bit and 64-bit bitfield encodings. 931ba4a712SPawel Jakub Dawidek */ 941ba4a712SPawel Jakub Dawidek #define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len)) 951ba4a712SPawel Jakub Dawidek #define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len)) 961ba4a712SPawel Jakub Dawidek #define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low)) 971ba4a712SPawel Jakub Dawidek #define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low)) 981ba4a712SPawel Jakub Dawidek 991ba4a712SPawel Jakub Dawidek #define BF32_GET(x, low, len) BF32_DECODE(x, low, len) 1001ba4a712SPawel Jakub Dawidek #define BF64_GET(x, low, len) BF64_DECODE(x, low, len) 1011ba4a712SPawel Jakub Dawidek 1021ba4a712SPawel Jakub Dawidek #define BF32_SET(x, low, len, val) \ 1031ba4a712SPawel Jakub Dawidek ((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len)) 1041ba4a712SPawel Jakub Dawidek #define BF64_SET(x, low, len, val) \ 1051ba4a712SPawel Jakub Dawidek ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len)) 1061ba4a712SPawel Jakub Dawidek 1071ba4a712SPawel Jakub Dawidek #define BF32_GET_SB(x, low, len, shift, bias) \ 1081ba4a712SPawel Jakub Dawidek ((BF32_GET(x, low, len) + (bias)) << (shift)) 1091ba4a712SPawel Jakub Dawidek #define BF64_GET_SB(x, low, len, shift, bias) \ 1101ba4a712SPawel Jakub Dawidek ((BF64_GET(x, low, len) + (bias)) << (shift)) 1111ba4a712SPawel Jakub Dawidek 1121ba4a712SPawel Jakub Dawidek #define BF32_SET_SB(x, low, len, shift, bias, val) \ 1131ba4a712SPawel Jakub Dawidek BF32_SET(x, low, len, ((val) >> (shift)) - (bias)) 1141ba4a712SPawel Jakub Dawidek #define BF64_SET_SB(x, low, len, shift, bias, val) \ 1151ba4a712SPawel Jakub Dawidek BF64_SET(x, low, len, ((val) >> (shift)) - (bias)) 1161ba4a712SPawel Jakub Dawidek 1171ba4a712SPawel Jakub Dawidek /* 11810b9d77bSPawel Jakub Dawidek * Macros to reverse byte order 11910b9d77bSPawel Jakub Dawidek */ 12010b9d77bSPawel Jakub Dawidek #define BSWAP_8(x) ((x) & 0xff) 12110b9d77bSPawel Jakub Dawidek #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8)) 12210b9d77bSPawel Jakub Dawidek #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16)) 12310b9d77bSPawel Jakub Dawidek #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32)) 12410b9d77bSPawel Jakub Dawidek 1251ba4a712SPawel Jakub Dawidek #define SPA_MINBLOCKSHIFT 9 1262c55d090SToomas Soome #define SPA_OLDMAXBLOCKSHIFT 17 1272c55d090SToomas Soome #define SPA_MAXBLOCKSHIFT 24 1281ba4a712SPawel Jakub Dawidek #define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT) 1292c55d090SToomas Soome #define SPA_OLDMAXBLOCKSIZE (1ULL << SPA_OLDMAXBLOCKSHIFT) 1301ba4a712SPawel Jakub Dawidek #define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT) 1311ba4a712SPawel Jakub Dawidek 1321ba4a712SPawel Jakub Dawidek /* 1331ba4a712SPawel Jakub Dawidek * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB. 1341ba4a712SPawel Jakub Dawidek * The ASIZE encoding should be at least 64 times larger (6 more bits) 1351ba4a712SPawel Jakub Dawidek * to support up to 4-way RAID-Z mirror mode with worst-case gang block 1361ba4a712SPawel Jakub Dawidek * overhead, three DVAs per bp, plus one more bit in case we do anything 1371ba4a712SPawel Jakub Dawidek * else that expands the ASIZE. 1381ba4a712SPawel Jakub Dawidek */ 1391ba4a712SPawel Jakub Dawidek #define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */ 1401ba4a712SPawel Jakub Dawidek #define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */ 1411ba4a712SPawel Jakub Dawidek #define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */ 1421ba4a712SPawel Jakub Dawidek 1431ba4a712SPawel Jakub Dawidek /* 1441ba4a712SPawel Jakub Dawidek * All SPA data is represented by 128-bit data virtual addresses (DVAs). 1451ba4a712SPawel Jakub Dawidek * The members of the dva_t should be considered opaque outside the SPA. 1461ba4a712SPawel Jakub Dawidek */ 1471ba4a712SPawel Jakub Dawidek typedef struct dva { 1481ba4a712SPawel Jakub Dawidek uint64_t dva_word[2]; 1491ba4a712SPawel Jakub Dawidek } dva_t; 1501ba4a712SPawel Jakub Dawidek 1511ba4a712SPawel Jakub Dawidek /* 1521ba4a712SPawel Jakub Dawidek * Each block has a 256-bit checksum -- strong enough for cryptographic hashes. 1531ba4a712SPawel Jakub Dawidek */ 1541ba4a712SPawel Jakub Dawidek typedef struct zio_cksum { 1551ba4a712SPawel Jakub Dawidek uint64_t zc_word[4]; 1561ba4a712SPawel Jakub Dawidek } zio_cksum_t; 1571ba4a712SPawel Jakub Dawidek 1581ba4a712SPawel Jakub Dawidek /* 1592c55d090SToomas Soome * Some checksums/hashes need a 256-bit initialization salt. This salt is kept 1602c55d090SToomas Soome * secret and is suitable for use in MAC algorithms as the key. 1612c55d090SToomas Soome */ 1622c55d090SToomas Soome typedef struct zio_cksum_salt { 1632c55d090SToomas Soome uint8_t zcs_bytes[32]; 1642c55d090SToomas Soome } zio_cksum_salt_t; 1652c55d090SToomas Soome 1662c55d090SToomas Soome /* 1671ba4a712SPawel Jakub Dawidek * Each block is described by its DVAs, time of birth, checksum, etc. 1681ba4a712SPawel Jakub Dawidek * The word-by-word, bit-by-bit layout of the blkptr is as follows: 1691ba4a712SPawel Jakub Dawidek * 1701ba4a712SPawel Jakub Dawidek * 64 56 48 40 32 24 16 8 0 1711ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1721ba4a712SPawel Jakub Dawidek * 0 | vdev1 | GRID | ASIZE | 1731ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1741ba4a712SPawel Jakub Dawidek * 1 |G| offset1 | 1751ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1761ba4a712SPawel Jakub Dawidek * 2 | vdev2 | GRID | ASIZE | 1771ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1781ba4a712SPawel Jakub Dawidek * 3 |G| offset2 | 1791ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1801ba4a712SPawel Jakub Dawidek * 4 | vdev3 | GRID | ASIZE | 1811ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1821ba4a712SPawel Jakub Dawidek * 5 |G| offset3 | 1831ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 18429441ba3SXin LI * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE | 1851ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1861ba4a712SPawel Jakub Dawidek * 7 | padding | 1871ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1881ba4a712SPawel Jakub Dawidek * 8 | padding | 1891ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 19010b9d77bSPawel Jakub Dawidek * 9 | physical birth txg | 1911ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 19210b9d77bSPawel Jakub Dawidek * a | logical birth txg | 1931ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1941ba4a712SPawel Jakub Dawidek * b | fill count | 1951ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1961ba4a712SPawel Jakub Dawidek * c | checksum[0] | 1971ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 1981ba4a712SPawel Jakub Dawidek * d | checksum[1] | 1991ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 2001ba4a712SPawel Jakub Dawidek * e | checksum[2] | 2011ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 2021ba4a712SPawel Jakub Dawidek * f | checksum[3] | 2031ba4a712SPawel Jakub Dawidek * +-------+-------+-------+-------+-------+-------+-------+-------+ 2041ba4a712SPawel Jakub Dawidek * 2051ba4a712SPawel Jakub Dawidek * Legend: 2061ba4a712SPawel Jakub Dawidek * 2071ba4a712SPawel Jakub Dawidek * vdev virtual device ID 2081ba4a712SPawel Jakub Dawidek * offset offset into virtual device 2091ba4a712SPawel Jakub Dawidek * LSIZE logical size 2101ba4a712SPawel Jakub Dawidek * PSIZE physical size (after compression) 2111ba4a712SPawel Jakub Dawidek * ASIZE allocated size (including RAID-Z parity and gang block headers) 2121ba4a712SPawel Jakub Dawidek * GRID RAID-Z layout information (reserved for future use) 2131ba4a712SPawel Jakub Dawidek * cksum checksum function 2141ba4a712SPawel Jakub Dawidek * comp compression function 2151ba4a712SPawel Jakub Dawidek * G gang block indicator 21610b9d77bSPawel Jakub Dawidek * B byteorder (endianness) 21710b9d77bSPawel Jakub Dawidek * D dedup 21829441ba3SXin LI * X encryption (on version 30, which is not supported) 21929441ba3SXin LI * E blkptr_t contains embedded data (see below) 2201ba4a712SPawel Jakub Dawidek * lvl level of indirection 22110b9d77bSPawel Jakub Dawidek * type DMU object type 22210b9d77bSPawel Jakub Dawidek * phys birth txg of block allocation; zero if same as logical birth txg 22310b9d77bSPawel Jakub Dawidek * log. birth transaction group in which the block was logically born 2241ba4a712SPawel Jakub Dawidek * fill count number of non-zero blocks under this bp 2251ba4a712SPawel Jakub Dawidek * checksum[4] 256-bit checksum of the data this bp describes 2261ba4a712SPawel Jakub Dawidek */ 22729441ba3SXin LI 22829441ba3SXin LI /* 22929441ba3SXin LI * "Embedded" blkptr_t's don't actually point to a block, instead they 23029441ba3SXin LI * have a data payload embedded in the blkptr_t itself. See the comment 23129441ba3SXin LI * in blkptr.c for more details. 23229441ba3SXin LI * 23329441ba3SXin LI * The blkptr_t is laid out as follows: 23429441ba3SXin LI * 23529441ba3SXin LI * 64 56 48 40 32 24 16 8 0 23629441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 23729441ba3SXin LI * 0 | payload | 23829441ba3SXin LI * 1 | payload | 23929441ba3SXin LI * 2 | payload | 24029441ba3SXin LI * 3 | payload | 24129441ba3SXin LI * 4 | payload | 24229441ba3SXin LI * 5 | payload | 24329441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 24429441ba3SXin LI * 6 |BDX|lvl| type | etype |E| comp| PSIZE| LSIZE | 24529441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 24629441ba3SXin LI * 7 | payload | 24729441ba3SXin LI * 8 | payload | 24829441ba3SXin LI * 9 | payload | 24929441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 25029441ba3SXin LI * a | logical birth txg | 25129441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 25229441ba3SXin LI * b | payload | 25329441ba3SXin LI * c | payload | 25429441ba3SXin LI * d | payload | 25529441ba3SXin LI * e | payload | 25629441ba3SXin LI * f | payload | 25729441ba3SXin LI * +-------+-------+-------+-------+-------+-------+-------+-------+ 25829441ba3SXin LI * 25929441ba3SXin LI * Legend: 26029441ba3SXin LI * 26129441ba3SXin LI * payload contains the embedded data 26229441ba3SXin LI * B (byteorder) byteorder (endianness) 26329441ba3SXin LI * D (dedup) padding (set to zero) 26429441ba3SXin LI * X encryption (set to zero; see above) 26529441ba3SXin LI * E (embedded) set to one 26629441ba3SXin LI * lvl indirection level 26729441ba3SXin LI * type DMU object type 26829441ba3SXin LI * etype how to interpret embedded data (BP_EMBEDDED_TYPE_*) 26929441ba3SXin LI * comp compression function of payload 27029441ba3SXin LI * PSIZE size of payload after compression, in bytes 27129441ba3SXin LI * LSIZE logical size of payload, in bytes 27229441ba3SXin LI * note that 25 bits is enough to store the largest 27329441ba3SXin LI * "normal" BP's LSIZE (2^16 * 2^9) in bytes 27429441ba3SXin LI * log. birth transaction group in which the block was logically born 27529441ba3SXin LI * 27629441ba3SXin LI * Note that LSIZE and PSIZE are stored in bytes, whereas for non-embedded 27729441ba3SXin LI * bp's they are stored in units of SPA_MINBLOCKSHIFT. 27829441ba3SXin LI * Generally, the generic BP_GET_*() macros can be used on embedded BP's. 27929441ba3SXin LI * The B, D, X, lvl, type, and comp fields are stored the same as with normal 28029441ba3SXin LI * BP's so the BP_SET_* macros can be used with them. etype, PSIZE, LSIZE must 28129441ba3SXin LI * be set with the BPE_SET_* macros. BP_SET_EMBEDDED() should be called before 28229441ba3SXin LI * other macros, as they assert that they are only used on BP's of the correct 28329441ba3SXin LI * "embedded-ness". 28429441ba3SXin LI */ 28529441ba3SXin LI 28629441ba3SXin LI #define BPE_GET_ETYPE(bp) \ 28729441ba3SXin LI (ASSERT(BP_IS_EMBEDDED(bp)), \ 28829441ba3SXin LI BF64_GET((bp)->blk_prop, 40, 8)) 28929441ba3SXin LI #define BPE_SET_ETYPE(bp, t) do { \ 29029441ba3SXin LI ASSERT(BP_IS_EMBEDDED(bp)); \ 29129441ba3SXin LI BF64_SET((bp)->blk_prop, 40, 8, t); \ 29229441ba3SXin LI _NOTE(CONSTCOND) } while (0) 29329441ba3SXin LI 29429441ba3SXin LI #define BPE_GET_LSIZE(bp) \ 29529441ba3SXin LI (ASSERT(BP_IS_EMBEDDED(bp)), \ 29629441ba3SXin LI BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1)) 29729441ba3SXin LI #define BPE_SET_LSIZE(bp, x) do { \ 29829441ba3SXin LI ASSERT(BP_IS_EMBEDDED(bp)); \ 29929441ba3SXin LI BF64_SET_SB((bp)->blk_prop, 0, 25, 0, 1, x); \ 30029441ba3SXin LI _NOTE(CONSTCOND) } while (0) 30129441ba3SXin LI 30229441ba3SXin LI #define BPE_GET_PSIZE(bp) \ 30329441ba3SXin LI (ASSERT(BP_IS_EMBEDDED(bp)), \ 30429441ba3SXin LI BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1)) 30529441ba3SXin LI #define BPE_SET_PSIZE(bp, x) do { \ 30629441ba3SXin LI ASSERT(BP_IS_EMBEDDED(bp)); \ 30729441ba3SXin LI BF64_SET_SB((bp)->blk_prop, 25, 7, 0, 1, x); \ 30829441ba3SXin LI _NOTE(CONSTCOND) } while (0) 30929441ba3SXin LI 31029441ba3SXin LI typedef enum bp_embedded_type { 31129441ba3SXin LI BP_EMBEDDED_TYPE_DATA, 31229441ba3SXin LI BP_EMBEDDED_TYPE_RESERVED, /* Reserved for an unintegrated feature. */ 31329441ba3SXin LI NUM_BP_EMBEDDED_TYPES = BP_EMBEDDED_TYPE_RESERVED 31429441ba3SXin LI } bp_embedded_type_t; 31529441ba3SXin LI 31629441ba3SXin LI #define BPE_NUM_WORDS 14 31729441ba3SXin LI #define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t)) 31829441ba3SXin LI #define BPE_IS_PAYLOADWORD(bp, wp) \ 31929441ba3SXin LI ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth) 32029441ba3SXin LI 32110b9d77bSPawel Jakub Dawidek #define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */ 32210b9d77bSPawel Jakub Dawidek #define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */ 32310b9d77bSPawel Jakub Dawidek 3241ba4a712SPawel Jakub Dawidek typedef struct blkptr { 32510b9d77bSPawel Jakub Dawidek dva_t blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */ 3261ba4a712SPawel Jakub Dawidek uint64_t blk_prop; /* size, compression, type, etc */ 32710b9d77bSPawel Jakub Dawidek uint64_t blk_pad[2]; /* Extra space for the future */ 32810b9d77bSPawel Jakub Dawidek uint64_t blk_phys_birth; /* txg when block was allocated */ 3291ba4a712SPawel Jakub Dawidek uint64_t blk_birth; /* transaction group at birth */ 3301ba4a712SPawel Jakub Dawidek uint64_t blk_fill; /* fill count */ 3311ba4a712SPawel Jakub Dawidek zio_cksum_t blk_cksum; /* 256-bit checksum */ 3321ba4a712SPawel Jakub Dawidek } blkptr_t; 3331ba4a712SPawel Jakub Dawidek 3341ba4a712SPawel Jakub Dawidek /* 3351ba4a712SPawel Jakub Dawidek * Macros to get and set fields in a bp or DVA. 3361ba4a712SPawel Jakub Dawidek */ 3371ba4a712SPawel Jakub Dawidek #define DVA_GET_ASIZE(dva) \ 338f4c8ba83SXin LI BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0) 3391ba4a712SPawel Jakub Dawidek #define DVA_SET_ASIZE(dva, x) \ 340f4c8ba83SXin LI BF64_SET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, \ 341f4c8ba83SXin LI SPA_MINBLOCKSHIFT, 0, x) 3421ba4a712SPawel Jakub Dawidek 3431ba4a712SPawel Jakub Dawidek #define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8) 3441ba4a712SPawel Jakub Dawidek #define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x) 3451ba4a712SPawel Jakub Dawidek 3461ba4a712SPawel Jakub Dawidek #define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, 32) 3471ba4a712SPawel Jakub Dawidek #define DVA_SET_VDEV(dva, x) BF64_SET((dva)->dva_word[0], 32, 32, x) 3481ba4a712SPawel Jakub Dawidek 3491ba4a712SPawel Jakub Dawidek #define DVA_GET_OFFSET(dva) \ 3501ba4a712SPawel Jakub Dawidek BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0) 3511ba4a712SPawel Jakub Dawidek #define DVA_SET_OFFSET(dva, x) \ 3521ba4a712SPawel Jakub Dawidek BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x) 3531ba4a712SPawel Jakub Dawidek 3541ba4a712SPawel Jakub Dawidek #define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1) 3551ba4a712SPawel Jakub Dawidek #define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x) 3561ba4a712SPawel Jakub Dawidek 3571ba4a712SPawel Jakub Dawidek #define BP_GET_LSIZE(bp) \ 35829441ba3SXin LI (BP_IS_EMBEDDED(bp) ? \ 35929441ba3SXin LI (BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA ? BPE_GET_LSIZE(bp) : 0): \ 360f4c8ba83SXin LI BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1)) 36129441ba3SXin LI #define BP_SET_LSIZE(bp, x) do { \ 36229441ba3SXin LI ASSERT(!BP_IS_EMBEDDED(bp)); \ 36329441ba3SXin LI BF64_SET_SB((bp)->blk_prop, \ 36429441ba3SXin LI 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \ 36529441ba3SXin LI _NOTE(CONSTCOND) } while (0) 3661ba4a712SPawel Jakub Dawidek 3671ba4a712SPawel Jakub Dawidek #define BP_GET_PSIZE(bp) \ 368f4c8ba83SXin LI BF64_GET_SB((bp)->blk_prop, 16, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1) 3691ba4a712SPawel Jakub Dawidek #define BP_SET_PSIZE(bp, x) \ 370f4c8ba83SXin LI BF64_SET_SB((bp)->blk_prop, 16, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x) 3711ba4a712SPawel Jakub Dawidek 37229441ba3SXin LI #define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 7) 37329441ba3SXin LI #define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 7, x) 3741ba4a712SPawel Jakub Dawidek 3751ba4a712SPawel Jakub Dawidek #define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8) 3761ba4a712SPawel Jakub Dawidek #define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x) 3771ba4a712SPawel Jakub Dawidek 3781ba4a712SPawel Jakub Dawidek #define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8) 3791ba4a712SPawel Jakub Dawidek #define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x) 3801ba4a712SPawel Jakub Dawidek 3811ba4a712SPawel Jakub Dawidek #define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5) 3821ba4a712SPawel Jakub Dawidek #define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x) 3831ba4a712SPawel Jakub Dawidek 38429441ba3SXin LI #define BP_IS_EMBEDDED(bp) BF64_GET((bp)->blk_prop, 39, 1) 38529441ba3SXin LI 38610b9d77bSPawel Jakub Dawidek #define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1) 38710b9d77bSPawel Jakub Dawidek #define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x) 38810b9d77bSPawel Jakub Dawidek 389f4c8ba83SXin LI #define BP_GET_BYTEORDER(bp) BF64_GET((bp)->blk_prop, 63, 1) 3901ba4a712SPawel Jakub Dawidek #define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x) 3911ba4a712SPawel Jakub Dawidek 39210b9d77bSPawel Jakub Dawidek #define BP_PHYSICAL_BIRTH(bp) \ 39310b9d77bSPawel Jakub Dawidek ((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth) 39410b9d77bSPawel Jakub Dawidek 3951ba4a712SPawel Jakub Dawidek #define BP_GET_ASIZE(bp) \ 3961ba4a712SPawel Jakub Dawidek (DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ 3971ba4a712SPawel Jakub Dawidek DVA_GET_ASIZE(&(bp)->blk_dva[2])) 3981ba4a712SPawel Jakub Dawidek 3991ba4a712SPawel Jakub Dawidek #define BP_GET_UCSIZE(bp) \ 4001ba4a712SPawel Jakub Dawidek ((BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) ? \ 4011ba4a712SPawel Jakub Dawidek BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp)); 4021ba4a712SPawel Jakub Dawidek 4031ba4a712SPawel Jakub Dawidek #define BP_GET_NDVAS(bp) \ 4041ba4a712SPawel Jakub Dawidek (!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \ 4051ba4a712SPawel Jakub Dawidek !!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ 4061ba4a712SPawel Jakub Dawidek !!DVA_GET_ASIZE(&(bp)->blk_dva[2])) 4071ba4a712SPawel Jakub Dawidek 4081ba4a712SPawel Jakub Dawidek #define DVA_EQUAL(dva1, dva2) \ 4091ba4a712SPawel Jakub Dawidek ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \ 4101ba4a712SPawel Jakub Dawidek (dva1)->dva_word[0] == (dva2)->dva_word[0]) 4111ba4a712SPawel Jakub Dawidek 4121ba4a712SPawel Jakub Dawidek #define ZIO_CHECKSUM_EQUAL(zc1, zc2) \ 4131ba4a712SPawel Jakub Dawidek (0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \ 4141ba4a712SPawel Jakub Dawidek ((zc1).zc_word[1] - (zc2).zc_word[1]) | \ 4151ba4a712SPawel Jakub Dawidek ((zc1).zc_word[2] - (zc2).zc_word[2]) | \ 4161ba4a712SPawel Jakub Dawidek ((zc1).zc_word[3] - (zc2).zc_word[3]))) 4171ba4a712SPawel Jakub Dawidek 4181ba4a712SPawel Jakub Dawidek 4191ba4a712SPawel Jakub Dawidek #define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0) 4201ba4a712SPawel Jakub Dawidek 4211ba4a712SPawel Jakub Dawidek #define ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3) \ 4221ba4a712SPawel Jakub Dawidek { \ 4231ba4a712SPawel Jakub Dawidek (zcp)->zc_word[0] = w0; \ 4241ba4a712SPawel Jakub Dawidek (zcp)->zc_word[1] = w1; \ 4251ba4a712SPawel Jakub Dawidek (zcp)->zc_word[2] = w2; \ 4261ba4a712SPawel Jakub Dawidek (zcp)->zc_word[3] = w3; \ 4271ba4a712SPawel Jakub Dawidek } 4281ba4a712SPawel Jakub Dawidek 4291ba4a712SPawel Jakub Dawidek #define BP_IDENTITY(bp) (&(bp)->blk_dva[0]) 4301ba4a712SPawel Jakub Dawidek #define BP_IS_GANG(bp) DVA_GET_GANG(BP_IDENTITY(bp)) 431f4c8ba83SXin LI #define DVA_IS_EMPTY(dva) ((dva)->dva_word[0] == 0ULL && \ 432f4c8ba83SXin LI (dva)->dva_word[1] == 0ULL) 433f4c8ba83SXin LI #define BP_IS_HOLE(bp) DVA_IS_EMPTY(BP_IDENTITY(bp)) 4341ba4a712SPawel Jakub Dawidek #define BP_IS_OLDER(bp, txg) (!BP_IS_HOLE(bp) && (bp)->blk_birth < (txg)) 4351ba4a712SPawel Jakub Dawidek 4361ba4a712SPawel Jakub Dawidek #define BP_ZERO(bp) \ 4371ba4a712SPawel Jakub Dawidek { \ 4381ba4a712SPawel Jakub Dawidek (bp)->blk_dva[0].dva_word[0] = 0; \ 4391ba4a712SPawel Jakub Dawidek (bp)->blk_dva[0].dva_word[1] = 0; \ 4401ba4a712SPawel Jakub Dawidek (bp)->blk_dva[1].dva_word[0] = 0; \ 4411ba4a712SPawel Jakub Dawidek (bp)->blk_dva[1].dva_word[1] = 0; \ 4421ba4a712SPawel Jakub Dawidek (bp)->blk_dva[2].dva_word[0] = 0; \ 4431ba4a712SPawel Jakub Dawidek (bp)->blk_dva[2].dva_word[1] = 0; \ 4441ba4a712SPawel Jakub Dawidek (bp)->blk_prop = 0; \ 4451ba4a712SPawel Jakub Dawidek (bp)->blk_pad[0] = 0; \ 4461ba4a712SPawel Jakub Dawidek (bp)->blk_pad[1] = 0; \ 44710b9d77bSPawel Jakub Dawidek (bp)->blk_phys_birth = 0; \ 4481ba4a712SPawel Jakub Dawidek (bp)->blk_birth = 0; \ 4491ba4a712SPawel Jakub Dawidek (bp)->blk_fill = 0; \ 4501ba4a712SPawel Jakub Dawidek ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \ 4511ba4a712SPawel Jakub Dawidek } 4521ba4a712SPawel Jakub Dawidek 453903fe2b7SToomas Soome #if BYTE_ORDER == _BIG_ENDIAN 454903fe2b7SToomas Soome #define ZFS_HOST_BYTEORDER (0ULL) 455903fe2b7SToomas Soome #else 456903fe2b7SToomas Soome #define ZFS_HOST_BYTEORDER (1ULL) 457903fe2b7SToomas Soome #endif 458903fe2b7SToomas Soome 459903fe2b7SToomas Soome #define BP_SHOULD_BYTESWAP(bp) (BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER) 46029441ba3SXin LI #define BPE_NUM_WORDS 14 46129441ba3SXin LI #define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t)) 46229441ba3SXin LI #define BPE_IS_PAYLOADWORD(bp, wp) \ 46329441ba3SXin LI ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth) 46429441ba3SXin LI 46510b9d77bSPawel Jakub Dawidek /* 46610b9d77bSPawel Jakub Dawidek * Embedded checksum 46710b9d77bSPawel Jakub Dawidek */ 46810b9d77bSPawel Jakub Dawidek #define ZEC_MAGIC 0x210da7ab10c7a11ULL 4691ba4a712SPawel Jakub Dawidek 47010b9d77bSPawel Jakub Dawidek typedef struct zio_eck { 47110b9d77bSPawel Jakub Dawidek uint64_t zec_magic; /* for validation, endianness */ 47210b9d77bSPawel Jakub Dawidek zio_cksum_t zec_cksum; /* 256-bit checksum */ 47310b9d77bSPawel Jakub Dawidek } zio_eck_t; 47410b9d77bSPawel Jakub Dawidek 47510b9d77bSPawel Jakub Dawidek /* 47610b9d77bSPawel Jakub Dawidek * Gang block headers are self-checksumming and contain an array 47710b9d77bSPawel Jakub Dawidek * of block pointers. 47810b9d77bSPawel Jakub Dawidek */ 47910b9d77bSPawel Jakub Dawidek #define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE 48010b9d77bSPawel Jakub Dawidek #define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \ 48110b9d77bSPawel Jakub Dawidek sizeof (zio_eck_t)) / sizeof (blkptr_t)) 48210b9d77bSPawel Jakub Dawidek #define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \ 48310b9d77bSPawel Jakub Dawidek sizeof (zio_eck_t) - \ 48410b9d77bSPawel Jakub Dawidek (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\ 48510b9d77bSPawel Jakub Dawidek sizeof (uint64_t)) 48610b9d77bSPawel Jakub Dawidek 48710b9d77bSPawel Jakub Dawidek typedef struct zio_gbh { 48810b9d77bSPawel Jakub Dawidek blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS]; 48910b9d77bSPawel Jakub Dawidek uint64_t zg_filler[SPA_GBH_FILLER]; 49010b9d77bSPawel Jakub Dawidek zio_eck_t zg_tail; 49110b9d77bSPawel Jakub Dawidek } zio_gbh_phys_t; 49210b9d77bSPawel Jakub Dawidek 49310b9d77bSPawel Jakub Dawidek #define VDEV_RAIDZ_MAXPARITY 3 4941ba4a712SPawel Jakub Dawidek 4958fc25799SMartin Matuska #define VDEV_PAD_SIZE (8 << 10) 4968fc25799SMartin Matuska /* 2 padding areas (vl_pad1 and vl_pad2) to skip */ 4978fc25799SMartin Matuska #define VDEV_SKIP_SIZE VDEV_PAD_SIZE * 2 4981ba4a712SPawel Jakub Dawidek #define VDEV_PHYS_SIZE (112 << 10) 4991ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_RING (128 << 10) 5001ba4a712SPawel Jakub Dawidek 50179a4bf89SToomas Soome /* 50279a4bf89SToomas Soome * MMP blocks occupy the last MMP_BLOCKS_PER_LABEL slots in the uberblock 50379a4bf89SToomas Soome * ring when MMP is enabled. 50479a4bf89SToomas Soome */ 50579a4bf89SToomas Soome #define MMP_BLOCKS_PER_LABEL 1 50679a4bf89SToomas Soome 50779a4bf89SToomas Soome /* The largest uberblock we support is 8k. */ 50879a4bf89SToomas Soome #define MAX_UBERBLOCK_SHIFT (13) 5091ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_SHIFT(vd) \ 51079a4bf89SToomas Soome MIN(MAX((vd)->v_top->v_ashift, UBERBLOCK_SHIFT), MAX_UBERBLOCK_SHIFT) 5111ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_COUNT(vd) \ 5121ba4a712SPawel Jakub Dawidek (VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(vd)) 5131ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_OFFSET(vd, n) \ 5141ba4a712SPawel Jakub Dawidek offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(vd)]) 5151ba4a712SPawel Jakub Dawidek #define VDEV_UBERBLOCK_SIZE(vd) (1ULL << VDEV_UBERBLOCK_SHIFT(vd)) 5161ba4a712SPawel Jakub Dawidek 5171ba4a712SPawel Jakub Dawidek typedef struct vdev_phys { 51810b9d77bSPawel Jakub Dawidek char vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)]; 51910b9d77bSPawel Jakub Dawidek zio_eck_t vp_zbt; 5201ba4a712SPawel Jakub Dawidek } vdev_phys_t; 5211ba4a712SPawel Jakub Dawidek 5221ba4a712SPawel Jakub Dawidek typedef struct vdev_label { 5238fc25799SMartin Matuska char vl_pad1[VDEV_PAD_SIZE]; /* 8K */ 5248fc25799SMartin Matuska char vl_pad2[VDEV_PAD_SIZE]; /* 8K */ 5251ba4a712SPawel Jakub Dawidek vdev_phys_t vl_vdev_phys; /* 112K */ 5261ba4a712SPawel Jakub Dawidek char vl_uberblock[VDEV_UBERBLOCK_RING]; /* 128K */ 5271ba4a712SPawel Jakub Dawidek } vdev_label_t; /* 256K total */ 5281ba4a712SPawel Jakub Dawidek 5291ba4a712SPawel Jakub Dawidek /* 5301ba4a712SPawel Jakub Dawidek * vdev_dirty() flags 5311ba4a712SPawel Jakub Dawidek */ 5321ba4a712SPawel Jakub Dawidek #define VDD_METASLAB 0x01 5331ba4a712SPawel Jakub Dawidek #define VDD_DTL 0x02 5341ba4a712SPawel Jakub Dawidek 5351ba4a712SPawel Jakub Dawidek /* 5361ba4a712SPawel Jakub Dawidek * Size and offset of embedded boot loader region on each label. 5371ba4a712SPawel Jakub Dawidek * The total size of the first two labels plus the boot area is 4MB. 5381ba4a712SPawel Jakub Dawidek */ 5391ba4a712SPawel Jakub Dawidek #define VDEV_BOOT_OFFSET (2 * sizeof (vdev_label_t)) 5401ba4a712SPawel Jakub Dawidek #define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */ 5411ba4a712SPawel Jakub Dawidek 5421ba4a712SPawel Jakub Dawidek /* 5431ba4a712SPawel Jakub Dawidek * Size of label regions at the start and end of each leaf device. 5441ba4a712SPawel Jakub Dawidek */ 5451ba4a712SPawel Jakub Dawidek #define VDEV_LABEL_START_SIZE (2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE) 5461ba4a712SPawel Jakub Dawidek #define VDEV_LABEL_END_SIZE (2 * sizeof (vdev_label_t)) 5471ba4a712SPawel Jakub Dawidek #define VDEV_LABELS 4 5481ba4a712SPawel Jakub Dawidek 5491ba4a712SPawel Jakub Dawidek enum zio_checksum { 5501ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_INHERIT = 0, 5511ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_ON, 5521ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_OFF, 5531ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_LABEL, 5541ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_GANG_HEADER, 5551ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_ZILOG, 5561ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_FLETCHER_2, 5571ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_FLETCHER_4, 5581ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_SHA256, 55910b9d77bSPawel Jakub Dawidek ZIO_CHECKSUM_ZILOG2, 5602c55d090SToomas Soome ZIO_CHECKSUM_NOPARITY, 5612c55d090SToomas Soome ZIO_CHECKSUM_SHA512, 5622c55d090SToomas Soome ZIO_CHECKSUM_SKEIN, 5632c55d090SToomas Soome ZIO_CHECKSUM_EDONR, 5641ba4a712SPawel Jakub Dawidek ZIO_CHECKSUM_FUNCTIONS 5651ba4a712SPawel Jakub Dawidek }; 5661ba4a712SPawel Jakub Dawidek 56710b9d77bSPawel Jakub Dawidek #define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_4 5681ba4a712SPawel Jakub Dawidek #define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON 5691ba4a712SPawel Jakub Dawidek 5701ba4a712SPawel Jakub Dawidek enum zio_compress { 5711ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_INHERIT = 0, 5721ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_ON, 5731ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_OFF, 5741ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_LZJB, 5751ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_EMPTY, 5761ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_1, 5771ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_2, 5781ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_3, 5791ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_4, 5801ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_5, 5811ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_6, 5821ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_7, 5831ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_8, 5841ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_GZIP_9, 58510b9d77bSPawel Jakub Dawidek ZIO_COMPRESS_ZLE, 586ef17620fSXin LI ZIO_COMPRESS_LZ4, 5871ba4a712SPawel Jakub Dawidek ZIO_COMPRESS_FUNCTIONS 5881ba4a712SPawel Jakub Dawidek }; 5891ba4a712SPawel Jakub Dawidek 5901ba4a712SPawel Jakub Dawidek #define ZIO_COMPRESS_ON_VALUE ZIO_COMPRESS_LZJB 5911ba4a712SPawel Jakub Dawidek #define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF 5921ba4a712SPawel Jakub Dawidek 5931ba4a712SPawel Jakub Dawidek /* nvlist pack encoding */ 5941ba4a712SPawel Jakub Dawidek #define NV_ENCODE_NATIVE 0 5951ba4a712SPawel Jakub Dawidek #define NV_ENCODE_XDR 1 5961ba4a712SPawel Jakub Dawidek 5971ba4a712SPawel Jakub Dawidek typedef enum { 5981ba4a712SPawel Jakub Dawidek DATA_TYPE_UNKNOWN = 0, 5991ba4a712SPawel Jakub Dawidek DATA_TYPE_BOOLEAN, 6001ba4a712SPawel Jakub Dawidek DATA_TYPE_BYTE, 6011ba4a712SPawel Jakub Dawidek DATA_TYPE_INT16, 6021ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT16, 6031ba4a712SPawel Jakub Dawidek DATA_TYPE_INT32, 6041ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT32, 6051ba4a712SPawel Jakub Dawidek DATA_TYPE_INT64, 6061ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT64, 6071ba4a712SPawel Jakub Dawidek DATA_TYPE_STRING, 6081ba4a712SPawel Jakub Dawidek DATA_TYPE_BYTE_ARRAY, 6091ba4a712SPawel Jakub Dawidek DATA_TYPE_INT16_ARRAY, 6101ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT16_ARRAY, 6111ba4a712SPawel Jakub Dawidek DATA_TYPE_INT32_ARRAY, 6121ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT32_ARRAY, 6131ba4a712SPawel Jakub Dawidek DATA_TYPE_INT64_ARRAY, 6141ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT64_ARRAY, 6151ba4a712SPawel Jakub Dawidek DATA_TYPE_STRING_ARRAY, 6161ba4a712SPawel Jakub Dawidek DATA_TYPE_HRTIME, 6171ba4a712SPawel Jakub Dawidek DATA_TYPE_NVLIST, 6181ba4a712SPawel Jakub Dawidek DATA_TYPE_NVLIST_ARRAY, 6191ba4a712SPawel Jakub Dawidek DATA_TYPE_BOOLEAN_VALUE, 6201ba4a712SPawel Jakub Dawidek DATA_TYPE_INT8, 6211ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT8, 6221ba4a712SPawel Jakub Dawidek DATA_TYPE_BOOLEAN_ARRAY, 6231ba4a712SPawel Jakub Dawidek DATA_TYPE_INT8_ARRAY, 6241ba4a712SPawel Jakub Dawidek DATA_TYPE_UINT8_ARRAY 6251ba4a712SPawel Jakub Dawidek } data_type_t; 6261ba4a712SPawel Jakub Dawidek 6271ba4a712SPawel Jakub Dawidek /* 6281ba4a712SPawel Jakub Dawidek * On-disk version number. 6291ba4a712SPawel Jakub Dawidek */ 6300d16312bSDoug Rabson #define SPA_VERSION_1 1ULL 6310d16312bSDoug Rabson #define SPA_VERSION_2 2ULL 6320d16312bSDoug Rabson #define SPA_VERSION_3 3ULL 6330d16312bSDoug Rabson #define SPA_VERSION_4 4ULL 6340d16312bSDoug Rabson #define SPA_VERSION_5 5ULL 6350d16312bSDoug Rabson #define SPA_VERSION_6 6ULL 6360d16312bSDoug Rabson #define SPA_VERSION_7 7ULL 6370d16312bSDoug Rabson #define SPA_VERSION_8 8ULL 6380d16312bSDoug Rabson #define SPA_VERSION_9 9ULL 6390d16312bSDoug Rabson #define SPA_VERSION_10 10ULL 6400d16312bSDoug Rabson #define SPA_VERSION_11 11ULL 641786895f6SDoug Rabson #define SPA_VERSION_12 12ULL 642786895f6SDoug Rabson #define SPA_VERSION_13 13ULL 64391891290SXin LI #define SPA_VERSION_14 14ULL 6448fc25799SMartin Matuska #define SPA_VERSION_15 15ULL 64510b9d77bSPawel Jakub Dawidek #define SPA_VERSION_16 16ULL 64610b9d77bSPawel Jakub Dawidek #define SPA_VERSION_17 17ULL 64710b9d77bSPawel Jakub Dawidek #define SPA_VERSION_18 18ULL 64810b9d77bSPawel Jakub Dawidek #define SPA_VERSION_19 19ULL 64910b9d77bSPawel Jakub Dawidek #define SPA_VERSION_20 20ULL 65010b9d77bSPawel Jakub Dawidek #define SPA_VERSION_21 21ULL 65110b9d77bSPawel Jakub Dawidek #define SPA_VERSION_22 22ULL 65210b9d77bSPawel Jakub Dawidek #define SPA_VERSION_23 23ULL 65310b9d77bSPawel Jakub Dawidek #define SPA_VERSION_24 24ULL 65410b9d77bSPawel Jakub Dawidek #define SPA_VERSION_25 25ULL 65510b9d77bSPawel Jakub Dawidek #define SPA_VERSION_26 26ULL 65610b9d77bSPawel Jakub Dawidek #define SPA_VERSION_27 27ULL 65710b9d77bSPawel Jakub Dawidek #define SPA_VERSION_28 28ULL 6582d9cf57eSMartin Matuska #define SPA_VERSION_5000 5000ULL 65910b9d77bSPawel Jakub Dawidek 6601ba4a712SPawel Jakub Dawidek /* 66110b9d77bSPawel Jakub Dawidek * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk 66210b9d77bSPawel Jakub Dawidek * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*}, 66310b9d77bSPawel Jakub Dawidek * and do the appropriate changes. Also bump the version number in 66410b9d77bSPawel Jakub Dawidek * usr/src/grub/capability. 6651ba4a712SPawel Jakub Dawidek */ 6662d9cf57eSMartin Matuska #define SPA_VERSION SPA_VERSION_5000 6672d9cf57eSMartin Matuska #define SPA_VERSION_STRING "5000" 6681ba4a712SPawel Jakub Dawidek 6691ba4a712SPawel Jakub Dawidek /* 6700d16312bSDoug Rabson * Symbolic names for the changes that caused a SPA_VERSION switch. 6711ba4a712SPawel Jakub Dawidek * Used in the code when checking for presence or absence of a feature. 6721ba4a712SPawel Jakub Dawidek * Feel free to define multiple symbolic names for each version if there 6731ba4a712SPawel Jakub Dawidek * were multiple changes to on-disk structures during that version. 6741ba4a712SPawel Jakub Dawidek * 6750d16312bSDoug Rabson * NOTE: When checking the current SPA_VERSION in your code, be sure 6761ba4a712SPawel Jakub Dawidek * to use spa_version() since it reports the version of the 6771ba4a712SPawel Jakub Dawidek * last synced uberblock. Checking the in-flight version can 6781ba4a712SPawel Jakub Dawidek * be dangerous in some cases. 6791ba4a712SPawel Jakub Dawidek */ 6800d16312bSDoug Rabson #define SPA_VERSION_INITIAL SPA_VERSION_1 6810d16312bSDoug Rabson #define SPA_VERSION_DITTO_BLOCKS SPA_VERSION_2 6820d16312bSDoug Rabson #define SPA_VERSION_SPARES SPA_VERSION_3 6830d16312bSDoug Rabson #define SPA_VERSION_RAID6 SPA_VERSION_3 6840d16312bSDoug Rabson #define SPA_VERSION_BPLIST_ACCOUNT SPA_VERSION_3 6850d16312bSDoug Rabson #define SPA_VERSION_RAIDZ_DEFLATE SPA_VERSION_3 6860d16312bSDoug Rabson #define SPA_VERSION_DNODE_BYTES SPA_VERSION_3 6870d16312bSDoug Rabson #define SPA_VERSION_ZPOOL_HISTORY SPA_VERSION_4 6880d16312bSDoug Rabson #define SPA_VERSION_GZIP_COMPRESSION SPA_VERSION_5 6890d16312bSDoug Rabson #define SPA_VERSION_BOOTFS SPA_VERSION_6 690786895f6SDoug Rabson #define SPA_VERSION_SLOGS SPA_VERSION_7 691786895f6SDoug Rabson #define SPA_VERSION_DELEGATED_PERMS SPA_VERSION_8 692786895f6SDoug Rabson #define SPA_VERSION_FUID SPA_VERSION_9 693786895f6SDoug Rabson #define SPA_VERSION_REFRESERVATION SPA_VERSION_9 694786895f6SDoug Rabson #define SPA_VERSION_REFQUOTA SPA_VERSION_9 695786895f6SDoug Rabson #define SPA_VERSION_UNIQUE_ACCURATE SPA_VERSION_9 696786895f6SDoug Rabson #define SPA_VERSION_L2CACHE SPA_VERSION_10 697786895f6SDoug Rabson #define SPA_VERSION_NEXT_CLONES SPA_VERSION_11 698786895f6SDoug Rabson #define SPA_VERSION_ORIGIN SPA_VERSION_11 699786895f6SDoug Rabson #define SPA_VERSION_DSL_SCRUB SPA_VERSION_11 700786895f6SDoug Rabson #define SPA_VERSION_SNAP_PROPS SPA_VERSION_12 701786895f6SDoug Rabson #define SPA_VERSION_USED_BREAKDOWN SPA_VERSION_13 70291891290SXin LI #define SPA_VERSION_PASSTHROUGH_X SPA_VERSION_14 7038fc25799SMartin Matuska #define SPA_VERSION_USERSPACE SPA_VERSION_15 70410b9d77bSPawel Jakub Dawidek #define SPA_VERSION_STMF_PROP SPA_VERSION_16 70510b9d77bSPawel Jakub Dawidek #define SPA_VERSION_RAIDZ3 SPA_VERSION_17 70610b9d77bSPawel Jakub Dawidek #define SPA_VERSION_USERREFS SPA_VERSION_18 70710b9d77bSPawel Jakub Dawidek #define SPA_VERSION_HOLES SPA_VERSION_19 70810b9d77bSPawel Jakub Dawidek #define SPA_VERSION_ZLE_COMPRESSION SPA_VERSION_20 70910b9d77bSPawel Jakub Dawidek #define SPA_VERSION_DEDUP SPA_VERSION_21 71010b9d77bSPawel Jakub Dawidek #define SPA_VERSION_RECVD_PROPS SPA_VERSION_22 71110b9d77bSPawel Jakub Dawidek #define SPA_VERSION_SLIM_ZIL SPA_VERSION_23 71210b9d77bSPawel Jakub Dawidek #define SPA_VERSION_SA SPA_VERSION_24 71310b9d77bSPawel Jakub Dawidek #define SPA_VERSION_SCAN SPA_VERSION_25 71410b9d77bSPawel Jakub Dawidek #define SPA_VERSION_DIR_CLONES SPA_VERSION_26 71510b9d77bSPawel Jakub Dawidek #define SPA_VERSION_DEADLISTS SPA_VERSION_26 71610b9d77bSPawel Jakub Dawidek #define SPA_VERSION_FAST_SNAP SPA_VERSION_27 71710b9d77bSPawel Jakub Dawidek #define SPA_VERSION_MULTI_REPLACE SPA_VERSION_28 7182d9cf57eSMartin Matuska #define SPA_VERSION_BEFORE_FEATURES SPA_VERSION_28 7192d9cf57eSMartin Matuska #define SPA_VERSION_FEATURES SPA_VERSION_5000 7202d9cf57eSMartin Matuska 7212d9cf57eSMartin Matuska #define SPA_VERSION_IS_SUPPORTED(v) \ 7222d9cf57eSMartin Matuska (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \ 7232d9cf57eSMartin Matuska ((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION)) 7241ba4a712SPawel Jakub Dawidek 7251ba4a712SPawel Jakub Dawidek /* 7261ba4a712SPawel Jakub Dawidek * The following are configuration names used in the nvlist describing a pool's 7271ba4a712SPawel Jakub Dawidek * configuration. 7281ba4a712SPawel Jakub Dawidek */ 7291ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_VERSION "version" 7301ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_NAME "name" 7311ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_STATE "state" 7321ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_TXG "txg" 7331ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_POOL_GUID "pool_guid" 7341ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_CREATE_TXG "create_txg" 7351ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_TOP_GUID "top_guid" 7361ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_VDEV_TREE "vdev_tree" 7371ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_TYPE "type" 7381ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_CHILDREN "children" 7391ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ID "id" 7401ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_GUID "guid" 741b1b93268SToomas Soome #define ZPOOL_CONFIG_INDIRECT_OBJECT "com.delphix:indirect_object" 742b1b93268SToomas Soome #define ZPOOL_CONFIG_INDIRECT_BIRTHS "com.delphix:indirect_births" 743b1b93268SToomas Soome #define ZPOOL_CONFIG_PREV_INDIRECT_VDEV "com.delphix:prev_indirect_vdev" 7441ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_PATH "path" 7451ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_DEVID "devid" 7461ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array" 7471ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift" 7481ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ASHIFT "ashift" 7491ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ASIZE "asize" 7501ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_DTL "DTL" 7511ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_STATS "stats" 7521ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_WHOLE_DISK "whole_disk" 7531ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_ERRCOUNT "error_count" 7541ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_NOT_PRESENT "not_present" 7551ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_SPARES "spares" 7561ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_IS_SPARE "is_spare" 7571ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_NPARITY "nparity" 7581ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_HOSTID "hostid" 7591ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_HOSTNAME "hostname" 7606a85b5e0SPawel Jakub Dawidek #define ZPOOL_CONFIG_IS_LOG "is_log" 7611ba4a712SPawel Jakub Dawidek #define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */ 7622d9cf57eSMartin Matuska #define ZPOOL_CONFIG_FEATURES_FOR_READ "features_for_read" 7633c2db0efSToomas Soome #define ZPOOL_CONFIG_VDEV_CHILDREN "vdev_children" 7641ba4a712SPawel Jakub Dawidek 76503ec6213SXin LI /* 76603ec6213SXin LI * The persistent vdev state is stored as separate values rather than a single 76703ec6213SXin LI * 'vdev_state' entry. This is because a device can be in multiple states, such 76803ec6213SXin LI * as offline and degraded. 76903ec6213SXin LI */ 77003ec6213SXin LI #define ZPOOL_CONFIG_OFFLINE "offline" 77103ec6213SXin LI #define ZPOOL_CONFIG_FAULTED "faulted" 77203ec6213SXin LI #define ZPOOL_CONFIG_DEGRADED "degraded" 77303ec6213SXin LI #define ZPOOL_CONFIG_REMOVED "removed" 77410b9d77bSPawel Jakub Dawidek #define ZPOOL_CONFIG_FRU "fru" 77510b9d77bSPawel Jakub Dawidek #define ZPOOL_CONFIG_AUX_STATE "aux_state" 77603ec6213SXin LI 7771ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_ROOT "root" 7781ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_MIRROR "mirror" 7791ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_REPLACING "replacing" 7801ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_RAIDZ "raidz" 7811ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_DISK "disk" 7821ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_FILE "file" 7831ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_MISSING "missing" 78410b9d77bSPawel Jakub Dawidek #define VDEV_TYPE_HOLE "hole" 7851ba4a712SPawel Jakub Dawidek #define VDEV_TYPE_SPARE "spare" 78610b9d77bSPawel Jakub Dawidek #define VDEV_TYPE_LOG "log" 78710b9d77bSPawel Jakub Dawidek #define VDEV_TYPE_L2CACHE "l2cache" 788b1b93268SToomas Soome #define VDEV_TYPE_INDIRECT "indirect" 7891ba4a712SPawel Jakub Dawidek 7901ba4a712SPawel Jakub Dawidek /* 7911ba4a712SPawel Jakub Dawidek * This is needed in userland to report the minimum necessary device size. 7921ba4a712SPawel Jakub Dawidek */ 7931ba4a712SPawel Jakub Dawidek #define SPA_MINDEVSIZE (64ULL << 20) 7941ba4a712SPawel Jakub Dawidek 7951ba4a712SPawel Jakub Dawidek /* 7961ba4a712SPawel Jakub Dawidek * The location of the pool configuration repository, shared between kernel and 7971ba4a712SPawel Jakub Dawidek * userland. 7981ba4a712SPawel Jakub Dawidek */ 79910b9d77bSPawel Jakub Dawidek #define ZPOOL_CACHE "/boot/zfs/zpool.cache" 8001ba4a712SPawel Jakub Dawidek 8011ba4a712SPawel Jakub Dawidek /* 8021ba4a712SPawel Jakub Dawidek * vdev states are ordered from least to most healthy. 8031ba4a712SPawel Jakub Dawidek * A vdev that's CANT_OPEN or below is considered unusable. 8041ba4a712SPawel Jakub Dawidek */ 8051ba4a712SPawel Jakub Dawidek typedef enum vdev_state { 8061ba4a712SPawel Jakub Dawidek VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev */ 8071ba4a712SPawel Jakub Dawidek VDEV_STATE_CLOSED, /* Not currently open */ 8081ba4a712SPawel Jakub Dawidek VDEV_STATE_OFFLINE, /* Not allowed to open */ 80903ec6213SXin LI VDEV_STATE_REMOVED, /* Explicitly removed from system */ 8101ba4a712SPawel Jakub Dawidek VDEV_STATE_CANT_OPEN, /* Tried to open, but failed */ 81103ec6213SXin LI VDEV_STATE_FAULTED, /* External request to fault device */ 8121ba4a712SPawel Jakub Dawidek VDEV_STATE_DEGRADED, /* Replicated vdev with unhealthy kids */ 8131ba4a712SPawel Jakub Dawidek VDEV_STATE_HEALTHY /* Presumed good */ 8141ba4a712SPawel Jakub Dawidek } vdev_state_t; 8151ba4a712SPawel Jakub Dawidek 8161ba4a712SPawel Jakub Dawidek /* 8171ba4a712SPawel Jakub Dawidek * vdev aux states. When a vdev is in the CANT_OPEN state, the aux field 8181ba4a712SPawel Jakub Dawidek * of the vdev stats structure uses these constants to distinguish why. 8191ba4a712SPawel Jakub Dawidek */ 8201ba4a712SPawel Jakub Dawidek typedef enum vdev_aux { 8211ba4a712SPawel Jakub Dawidek VDEV_AUX_NONE, /* no error */ 8221ba4a712SPawel Jakub Dawidek VDEV_AUX_OPEN_FAILED, /* ldi_open_*() or vn_open() failed */ 8231ba4a712SPawel Jakub Dawidek VDEV_AUX_CORRUPT_DATA, /* bad label or disk contents */ 8241ba4a712SPawel Jakub Dawidek VDEV_AUX_NO_REPLICAS, /* insufficient number of replicas */ 8251ba4a712SPawel Jakub Dawidek VDEV_AUX_BAD_GUID_SUM, /* vdev guid sum doesn't match */ 8261ba4a712SPawel Jakub Dawidek VDEV_AUX_TOO_SMALL, /* vdev size is too small */ 8271ba4a712SPawel Jakub Dawidek VDEV_AUX_BAD_LABEL, /* the label is OK but invalid */ 8281ba4a712SPawel Jakub Dawidek VDEV_AUX_VERSION_NEWER, /* on-disk version is too new */ 8291ba4a712SPawel Jakub Dawidek VDEV_AUX_VERSION_OLDER, /* on-disk version is too old */ 8301ba4a712SPawel Jakub Dawidek VDEV_AUX_SPARED /* hot spare used in another pool */ 8311ba4a712SPawel Jakub Dawidek } vdev_aux_t; 8321ba4a712SPawel Jakub Dawidek 8331ba4a712SPawel Jakub Dawidek /* 8341ba4a712SPawel Jakub Dawidek * pool state. The following states are written to disk as part of the normal 8351ba4a712SPawel Jakub Dawidek * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE. The remaining states are 8361ba4a712SPawel Jakub Dawidek * software abstractions used at various levels to communicate pool state. 8371ba4a712SPawel Jakub Dawidek */ 8381ba4a712SPawel Jakub Dawidek typedef enum pool_state { 8391ba4a712SPawel Jakub Dawidek POOL_STATE_ACTIVE = 0, /* In active use */ 8401ba4a712SPawel Jakub Dawidek POOL_STATE_EXPORTED, /* Explicitly exported */ 8411ba4a712SPawel Jakub Dawidek POOL_STATE_DESTROYED, /* Explicitly destroyed */ 8421ba4a712SPawel Jakub Dawidek POOL_STATE_SPARE, /* Reserved for hot spare use */ 8431ba4a712SPawel Jakub Dawidek POOL_STATE_UNINITIALIZED, /* Internal spa_t state */ 8441ba4a712SPawel Jakub Dawidek POOL_STATE_UNAVAIL, /* Internal libzfs state */ 8451ba4a712SPawel Jakub Dawidek POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */ 8461ba4a712SPawel Jakub Dawidek } pool_state_t; 8471ba4a712SPawel Jakub Dawidek 8481ba4a712SPawel Jakub Dawidek /* 8491ba4a712SPawel Jakub Dawidek * The uberblock version is incremented whenever an incompatible on-disk 8501ba4a712SPawel Jakub Dawidek * format change is made to the SPA, DMU, or ZAP. 8511ba4a712SPawel Jakub Dawidek * 8521ba4a712SPawel Jakub Dawidek * Note: the first two fields should never be moved. When a storage pool 8531ba4a712SPawel Jakub Dawidek * is opened, the uberblock must be read off the disk before the version 8541ba4a712SPawel Jakub Dawidek * can be checked. If the ub_version field is moved, we may not detect 8551ba4a712SPawel Jakub Dawidek * version mismatch. If the ub_magic field is moved, applications that 8561ba4a712SPawel Jakub Dawidek * expect the magic number in the first word won't work. 8571ba4a712SPawel Jakub Dawidek */ 8581ba4a712SPawel Jakub Dawidek #define UBERBLOCK_MAGIC 0x00bab10c /* oo-ba-bloc! */ 8591ba4a712SPawel Jakub Dawidek #define UBERBLOCK_SHIFT 10 /* up to 1K */ 8601ba4a712SPawel Jakub Dawidek 86179a4bf89SToomas Soome #define MMP_MAGIC 0xa11cea11 /* all-see-all */ 86279a4bf89SToomas Soome 86379a4bf89SToomas Soome #define MMP_INTERVAL_VALID_BIT 0x01 86479a4bf89SToomas Soome #define MMP_SEQ_VALID_BIT 0x02 86579a4bf89SToomas Soome #define MMP_FAIL_INT_VALID_BIT 0x04 86679a4bf89SToomas Soome 86779a4bf89SToomas Soome #define MMP_VALID(ubp) (ubp->ub_magic == UBERBLOCK_MAGIC && \ 86879a4bf89SToomas Soome ubp->ub_mmp_magic == MMP_MAGIC) 86979a4bf89SToomas Soome #define MMP_INTERVAL_VALID(ubp) (MMP_VALID(ubp) && (ubp->ub_mmp_config & \ 87079a4bf89SToomas Soome MMP_INTERVAL_VALID_BIT)) 87179a4bf89SToomas Soome #define MMP_SEQ_VALID(ubp) (MMP_VALID(ubp) && (ubp->ub_mmp_config & \ 87279a4bf89SToomas Soome MMP_SEQ_VALID_BIT)) 87379a4bf89SToomas Soome #define MMP_FAIL_INT_VALID(ubp) (MMP_VALID(ubp) && (ubp->ub_mmp_config & \ 87479a4bf89SToomas Soome MMP_FAIL_INT_VALID_BIT)) 87579a4bf89SToomas Soome 87679a4bf89SToomas Soome #define MMP_INTERVAL(ubp) ((ubp->ub_mmp_config & 0x00000000FFFFFF00) \ 87779a4bf89SToomas Soome >> 8) 87879a4bf89SToomas Soome #define MMP_SEQ(ubp) ((ubp->ub_mmp_config & 0x0000FFFF00000000) \ 87979a4bf89SToomas Soome >> 32) 88079a4bf89SToomas Soome #define MMP_FAIL_INT(ubp) ((ubp->ub_mmp_config & 0xFFFF000000000000) \ 88179a4bf89SToomas Soome >> 48) 88279a4bf89SToomas Soome 88379a4bf89SToomas Soome typedef struct uberblock { 8841ba4a712SPawel Jakub Dawidek uint64_t ub_magic; /* UBERBLOCK_MAGIC */ 8850d16312bSDoug Rabson uint64_t ub_version; /* SPA_VERSION */ 8861ba4a712SPawel Jakub Dawidek uint64_t ub_txg; /* txg of last sync */ 8871ba4a712SPawel Jakub Dawidek uint64_t ub_guid_sum; /* sum of all vdev guids */ 8881ba4a712SPawel Jakub Dawidek uint64_t ub_timestamp; /* UTC time of last sync */ 8891ba4a712SPawel Jakub Dawidek blkptr_t ub_rootbp; /* MOS objset_phys_t */ 89079a4bf89SToomas Soome /* highest SPA_VERSION supported by software that wrote this txg */ 89179a4bf89SToomas Soome uint64_t ub_software_version; 89279a4bf89SToomas Soome /* Maybe missing in uberblocks we read, but always written */ 89379a4bf89SToomas Soome uint64_t ub_mmp_magic; 89479a4bf89SToomas Soome /* 89579a4bf89SToomas Soome * If ub_mmp_delay == 0 and ub_mmp_magic is valid, MMP is off. 89679a4bf89SToomas Soome * Otherwise, nanosec since last MMP write. 89779a4bf89SToomas Soome */ 89879a4bf89SToomas Soome uint64_t ub_mmp_delay; 89979a4bf89SToomas Soome 90079a4bf89SToomas Soome /* 90179a4bf89SToomas Soome * The ub_mmp_config contains the multihost write interval, multihost 90279a4bf89SToomas Soome * fail intervals, sequence number for sub-second granularity, and 90379a4bf89SToomas Soome * valid bit mask. This layout is as follows: 90479a4bf89SToomas Soome * 90579a4bf89SToomas Soome * 64 56 48 40 32 24 16 8 0 90679a4bf89SToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+ 90779a4bf89SToomas Soome * 0 | Fail Intervals| Seq | Write Interval (ms) | VALID | 90879a4bf89SToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+ 90979a4bf89SToomas Soome * 91079a4bf89SToomas Soome * This allows a write_interval of (2^24/1000)s, over 4.5 hours 91179a4bf89SToomas Soome * 91279a4bf89SToomas Soome * VALID Bits: 91379a4bf89SToomas Soome * - 0x01 - Write Interval (ms) 91479a4bf89SToomas Soome * - 0x02 - Sequence number exists 91579a4bf89SToomas Soome * - 0x04 - Fail Intervals 91679a4bf89SToomas Soome * - 0xf8 - Reserved 91779a4bf89SToomas Soome */ 91879a4bf89SToomas Soome uint64_t ub_mmp_config; 91979a4bf89SToomas Soome 92079a4bf89SToomas Soome /* 92179a4bf89SToomas Soome * ub_checkpoint_txg indicates two things about the current uberblock: 92279a4bf89SToomas Soome * 92379a4bf89SToomas Soome * 1] If it is not zero then this uberblock is a checkpoint. If it is 92479a4bf89SToomas Soome * zero, then this uberblock is not a checkpoint. 92579a4bf89SToomas Soome * 92679a4bf89SToomas Soome * 2] On checkpointed uberblocks, the value of ub_checkpoint_txg is 92779a4bf89SToomas Soome * the ub_txg that the uberblock had at the time we moved it to 92879a4bf89SToomas Soome * the MOS config. 92979a4bf89SToomas Soome * 93079a4bf89SToomas Soome * The field is set when we checkpoint the uberblock and continues to 93179a4bf89SToomas Soome * hold that value even after we've rewound (unlike the ub_txg that 93279a4bf89SToomas Soome * is reset to a higher value). 93379a4bf89SToomas Soome * 93479a4bf89SToomas Soome * Besides checks used to determine whether we are reopening the 93579a4bf89SToomas Soome * pool from a checkpointed uberblock [see spa_ld_select_uberblock()], 93679a4bf89SToomas Soome * the value of the field is used to determine which ZIL blocks have 93779a4bf89SToomas Soome * been allocated according to the ms_sm when we are rewinding to a 93879a4bf89SToomas Soome * checkpoint. Specifically, if blk_birth > ub_checkpoint_txg, then 93979a4bf89SToomas Soome * the ZIL block is not allocated [see uses of spa_min_claim_txg()]. 94079a4bf89SToomas Soome */ 94179a4bf89SToomas Soome uint64_t ub_checkpoint_txg; 94279a4bf89SToomas Soome } uberblock_t; 9431ba4a712SPawel Jakub Dawidek 9441ba4a712SPawel Jakub Dawidek /* 9451ba4a712SPawel Jakub Dawidek * Flags. 9461ba4a712SPawel Jakub Dawidek */ 9471ba4a712SPawel Jakub Dawidek #define DNODE_MUST_BE_ALLOCATED 1 9481ba4a712SPawel Jakub Dawidek #define DNODE_MUST_BE_FREE 2 9491ba4a712SPawel Jakub Dawidek 9501ba4a712SPawel Jakub Dawidek /* 9511ba4a712SPawel Jakub Dawidek * Fixed constants. 9521ba4a712SPawel Jakub Dawidek */ 9531ba4a712SPawel Jakub Dawidek #define DNODE_SHIFT 9 /* 512 bytes */ 954263f396eSXin LI #define DN_MIN_INDBLKSHIFT 12 /* 4k */ 955b1b93268SToomas Soome #define DN_MAX_INDBLKSHIFT 17 /* 128k */ 9561ba4a712SPawel Jakub Dawidek #define DNODE_BLOCK_SHIFT 14 /* 16k */ 9571ba4a712SPawel Jakub Dawidek #define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */ 9581ba4a712SPawel Jakub Dawidek #define DN_MAX_OBJECT_SHIFT 48 /* 256 trillion (zfs_fid_t limit) */ 9591ba4a712SPawel Jakub Dawidek #define DN_MAX_OFFSET_SHIFT 64 /* 2^64 bytes in a dnode */ 9601ba4a712SPawel Jakub Dawidek 9611ba4a712SPawel Jakub Dawidek /* 9621ba4a712SPawel Jakub Dawidek * Derived constants. 9631ba4a712SPawel Jakub Dawidek */ 964b40aaca6SToomas Soome #define DNODE_MIN_SIZE (1 << DNODE_SHIFT) 965b40aaca6SToomas Soome #define DNODE_MAX_SIZE (1 << DNODE_BLOCK_SHIFT) 966b40aaca6SToomas Soome #define DNODE_BLOCK_SIZE (1 << DNODE_BLOCK_SHIFT) 967b40aaca6SToomas Soome #define DNODE_MIN_SLOTS (DNODE_MIN_SIZE >> DNODE_SHIFT) 968b40aaca6SToomas Soome #define DNODE_MAX_SLOTS (DNODE_MAX_SIZE >> DNODE_SHIFT) 969b40aaca6SToomas Soome #define DN_BONUS_SIZE(dnsize) ((dnsize) - DNODE_CORE_SIZE - \ 970b40aaca6SToomas Soome (1 << SPA_BLKPTRSHIFT)) 971b40aaca6SToomas Soome #define DN_SLOTS_TO_BONUSLEN(slots) DN_BONUS_SIZE((slots) << DNODE_SHIFT) 972b40aaca6SToomas Soome #define DN_OLD_MAX_BONUSLEN (DN_BONUS_SIZE(DNODE_MIN_SIZE)) 973b40aaca6SToomas Soome #define DN_MAX_NBLKPTR ((DNODE_MIN_SIZE - DNODE_CORE_SIZE) >> \ 974b40aaca6SToomas Soome SPA_BLKPTRSHIFT) 9751ba4a712SPawel Jakub Dawidek #define DN_MAX_OBJECT (1ULL << DN_MAX_OBJECT_SHIFT) 976b40aaca6SToomas Soome #define DN_ZERO_BONUSLEN (DN_BONUS_SIZE(DNODE_MAX_SIZE) + 1) 9771ba4a712SPawel Jakub Dawidek 9781ba4a712SPawel Jakub Dawidek #define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT) 9791ba4a712SPawel Jakub Dawidek #define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT) 9801ba4a712SPawel Jakub Dawidek #define DNODES_PER_LEVEL_SHIFT (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT) 9811ba4a712SPawel Jakub Dawidek 9821ba4a712SPawel Jakub Dawidek /* The +2 here is a cheesy way to round up */ 9831ba4a712SPawel Jakub Dawidek #define DN_MAX_LEVELS (2 + ((DN_MAX_OFFSET_SHIFT - SPA_MINBLOCKSHIFT) / \ 9841ba4a712SPawel Jakub Dawidek (DN_MIN_INDBLKSHIFT - SPA_BLKPTRSHIFT))) 9851ba4a712SPawel Jakub Dawidek 9861ba4a712SPawel Jakub Dawidek #define DN_BONUS(dnp) ((void*)((dnp)->dn_bonus + \ 9871ba4a712SPawel Jakub Dawidek (((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t)))) 9881ba4a712SPawel Jakub Dawidek 9891ba4a712SPawel Jakub Dawidek #define DN_USED_BYTES(dnp) (((dnp)->dn_flags & DNODE_FLAG_USED_BYTES) ? \ 9901ba4a712SPawel Jakub Dawidek (dnp)->dn_used : (dnp)->dn_used << SPA_MINBLOCKSHIFT) 9911ba4a712SPawel Jakub Dawidek 9921ba4a712SPawel Jakub Dawidek #define EPB(blkshift, typeshift) (1 << (blkshift - typeshift)) 9931ba4a712SPawel Jakub Dawidek 9941ba4a712SPawel Jakub Dawidek /* Is dn_used in bytes? if not, it's in multiples of SPA_MINBLOCKSIZE */ 9951ba4a712SPawel Jakub Dawidek #define DNODE_FLAG_USED_BYTES (1<<0) 99610b9d77bSPawel Jakub Dawidek #define DNODE_FLAG_USERUSED_ACCOUNTED (1<<1) 99710b9d77bSPawel Jakub Dawidek 99810b9d77bSPawel Jakub Dawidek /* Does dnode have a SA spill blkptr in bonus? */ 99910b9d77bSPawel Jakub Dawidek #define DNODE_FLAG_SPILL_BLKPTR (1<<2) 10001ba4a712SPawel Jakub Dawidek 10011ba4a712SPawel Jakub Dawidek typedef struct dnode_phys { 10021ba4a712SPawel Jakub Dawidek uint8_t dn_type; /* dmu_object_type_t */ 10031ba4a712SPawel Jakub Dawidek uint8_t dn_indblkshift; /* ln2(indirect block size) */ 10041ba4a712SPawel Jakub Dawidek uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */ 10051ba4a712SPawel Jakub Dawidek uint8_t dn_nblkptr; /* length of dn_blkptr */ 10061ba4a712SPawel Jakub Dawidek uint8_t dn_bonustype; /* type of data in bonus buffer */ 10071ba4a712SPawel Jakub Dawidek uint8_t dn_checksum; /* ZIO_CHECKSUM type */ 10081ba4a712SPawel Jakub Dawidek uint8_t dn_compress; /* ZIO_COMPRESS type */ 10091ba4a712SPawel Jakub Dawidek uint8_t dn_flags; /* DNODE_FLAG_* */ 10101ba4a712SPawel Jakub Dawidek uint16_t dn_datablkszsec; /* data block size in 512b sectors */ 10111ba4a712SPawel Jakub Dawidek uint16_t dn_bonuslen; /* length of dn_bonus */ 1012b40aaca6SToomas Soome uint8_t dn_extra_slots; /* # of subsequent slots consumed */ 1013b40aaca6SToomas Soome uint8_t dn_pad2[3]; 10141ba4a712SPawel Jakub Dawidek 10151ba4a712SPawel Jakub Dawidek /* accounting is protected by dn_dirty_mtx */ 10161ba4a712SPawel Jakub Dawidek uint64_t dn_maxblkid; /* largest allocated block ID */ 10171ba4a712SPawel Jakub Dawidek uint64_t dn_used; /* bytes (or sectors) of disk space */ 10181ba4a712SPawel Jakub Dawidek 10191ba4a712SPawel Jakub Dawidek uint64_t dn_pad3[4]; 10201ba4a712SPawel Jakub Dawidek 1021b40aaca6SToomas Soome /* 1022b40aaca6SToomas Soome * The tail region is 448 bytes for a 512 byte dnode, and 1023b40aaca6SToomas Soome * correspondingly larger for larger dnode sizes. The spill 1024b40aaca6SToomas Soome * block pointer, when present, is always at the end of the tail 1025b40aaca6SToomas Soome * region. There are three ways this space may be used, using 1026b40aaca6SToomas Soome * a 512 byte dnode for this diagram: 1027b40aaca6SToomas Soome * 1028b40aaca6SToomas Soome * 0 64 128 192 256 320 384 448 (offset) 1029b40aaca6SToomas Soome * +---------------+---------------+---------------+-------+ 1030b40aaca6SToomas Soome * | dn_blkptr[0] | dn_blkptr[1] | dn_blkptr[2] | / | 1031b40aaca6SToomas Soome * +---------------+---------------+---------------+-------+ 1032b40aaca6SToomas Soome * | dn_blkptr[0] | dn_bonus[0..319] | 1033b40aaca6SToomas Soome * +---------------+-----------------------+---------------+ 1034b40aaca6SToomas Soome * | dn_blkptr[0] | dn_bonus[0..191] | dn_spill | 1035b40aaca6SToomas Soome * +---------------+-----------------------+---------------+ 1036b40aaca6SToomas Soome */ 1037b40aaca6SToomas Soome union { 1038b40aaca6SToomas Soome blkptr_t dn_blkptr[1+DN_OLD_MAX_BONUSLEN/sizeof (blkptr_t)]; 1039b40aaca6SToomas Soome struct { 1040b40aaca6SToomas Soome blkptr_t __dn_ignore1; 1041b40aaca6SToomas Soome uint8_t dn_bonus[DN_OLD_MAX_BONUSLEN]; 1042b40aaca6SToomas Soome }; 1043b40aaca6SToomas Soome struct { 1044b40aaca6SToomas Soome blkptr_t __dn_ignore2; 1045b40aaca6SToomas Soome uint8_t __dn_ignore3[DN_OLD_MAX_BONUSLEN - 1046b40aaca6SToomas Soome sizeof (blkptr_t)]; 104710b9d77bSPawel Jakub Dawidek blkptr_t dn_spill; 1048b40aaca6SToomas Soome }; 1049b40aaca6SToomas Soome }; 10501ba4a712SPawel Jakub Dawidek } dnode_phys_t; 10511ba4a712SPawel Jakub Dawidek 1052b40aaca6SToomas Soome #define DN_SPILL_BLKPTR(dnp) (blkptr_t *)((char *)(dnp) + \ 1053b40aaca6SToomas Soome (((dnp)->dn_extra_slots + 1) << DNODE_SHIFT) - (1 << SPA_BLKPTRSHIFT)) 1054b40aaca6SToomas Soome 10554deb8929SAllan Jude typedef enum dmu_object_byteswap { 10564deb8929SAllan Jude DMU_BSWAP_UINT8, 10574deb8929SAllan Jude DMU_BSWAP_UINT16, 10584deb8929SAllan Jude DMU_BSWAP_UINT32, 10594deb8929SAllan Jude DMU_BSWAP_UINT64, 10604deb8929SAllan Jude DMU_BSWAP_ZAP, 10614deb8929SAllan Jude DMU_BSWAP_DNODE, 10624deb8929SAllan Jude DMU_BSWAP_OBJSET, 10634deb8929SAllan Jude DMU_BSWAP_ZNODE, 10644deb8929SAllan Jude DMU_BSWAP_OLDACL, 10654deb8929SAllan Jude DMU_BSWAP_ACL, 10664deb8929SAllan Jude /* 10674deb8929SAllan Jude * Allocating a new byteswap type number makes the on-disk format 10684deb8929SAllan Jude * incompatible with any other format that uses the same number. 10694deb8929SAllan Jude * 10704deb8929SAllan Jude * Data can usually be structured to work with one of the 10714deb8929SAllan Jude * DMU_BSWAP_UINT* or DMU_BSWAP_ZAP types. 10724deb8929SAllan Jude */ 10734deb8929SAllan Jude DMU_BSWAP_NUMFUNCS 10744deb8929SAllan Jude } dmu_object_byteswap_t; 10754deb8929SAllan Jude 10764deb8929SAllan Jude #define DMU_OT_NEWTYPE 0x80 10774deb8929SAllan Jude #define DMU_OT_METADATA 0x40 10784deb8929SAllan Jude #define DMU_OT_BYTESWAP_MASK 0x3f 10794deb8929SAllan Jude 10804deb8929SAllan Jude /* 10814deb8929SAllan Jude * Defines a uint8_t object type. Object types specify if the data 10824deb8929SAllan Jude * in the object is metadata (boolean) and how to byteswap the data 10834deb8929SAllan Jude * (dmu_object_byteswap_t). 10844deb8929SAllan Jude */ 10854deb8929SAllan Jude #define DMU_OT(byteswap, metadata) \ 10864deb8929SAllan Jude (DMU_OT_NEWTYPE | \ 10874deb8929SAllan Jude ((metadata) ? DMU_OT_METADATA : 0) | \ 10884deb8929SAllan Jude ((byteswap) & DMU_OT_BYTESWAP_MASK)) 10894deb8929SAllan Jude 10901ba4a712SPawel Jakub Dawidek typedef enum dmu_object_type { 10911ba4a712SPawel Jakub Dawidek DMU_OT_NONE, 10921ba4a712SPawel Jakub Dawidek /* general: */ 10931ba4a712SPawel Jakub Dawidek DMU_OT_OBJECT_DIRECTORY, /* ZAP */ 10941ba4a712SPawel Jakub Dawidek DMU_OT_OBJECT_ARRAY, /* UINT64 */ 10951ba4a712SPawel Jakub Dawidek DMU_OT_PACKED_NVLIST, /* UINT8 (XDR by nvlist_pack/unpack) */ 10961ba4a712SPawel Jakub Dawidek DMU_OT_PACKED_NVLIST_SIZE, /* UINT64 */ 10971ba4a712SPawel Jakub Dawidek DMU_OT_BPLIST, /* UINT64 */ 10981ba4a712SPawel Jakub Dawidek DMU_OT_BPLIST_HDR, /* UINT64 */ 10991ba4a712SPawel Jakub Dawidek /* spa: */ 11001ba4a712SPawel Jakub Dawidek DMU_OT_SPACE_MAP_HEADER, /* UINT64 */ 11011ba4a712SPawel Jakub Dawidek DMU_OT_SPACE_MAP, /* UINT64 */ 11021ba4a712SPawel Jakub Dawidek /* zil: */ 11031ba4a712SPawel Jakub Dawidek DMU_OT_INTENT_LOG, /* UINT64 */ 11041ba4a712SPawel Jakub Dawidek /* dmu: */ 11051ba4a712SPawel Jakub Dawidek DMU_OT_DNODE, /* DNODE */ 11061ba4a712SPawel Jakub Dawidek DMU_OT_OBJSET, /* OBJSET */ 11071ba4a712SPawel Jakub Dawidek /* dsl: */ 11081ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DIR, /* UINT64 */ 11091ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DIR_CHILD_MAP, /* ZAP */ 11101ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DS_SNAP_MAP, /* ZAP */ 11111ba4a712SPawel Jakub Dawidek DMU_OT_DSL_PROPS, /* ZAP */ 11121ba4a712SPawel Jakub Dawidek DMU_OT_DSL_DATASET, /* UINT64 */ 11131ba4a712SPawel Jakub Dawidek /* zpl: */ 11141ba4a712SPawel Jakub Dawidek DMU_OT_ZNODE, /* ZNODE */ 111510b9d77bSPawel Jakub Dawidek DMU_OT_OLDACL, /* Old ACL */ 11161ba4a712SPawel Jakub Dawidek DMU_OT_PLAIN_FILE_CONTENTS, /* UINT8 */ 11171ba4a712SPawel Jakub Dawidek DMU_OT_DIRECTORY_CONTENTS, /* ZAP */ 11181ba4a712SPawel Jakub Dawidek DMU_OT_MASTER_NODE, /* ZAP */ 11191ba4a712SPawel Jakub Dawidek DMU_OT_UNLINKED_SET, /* ZAP */ 11201ba4a712SPawel Jakub Dawidek /* zvol: */ 11211ba4a712SPawel Jakub Dawidek DMU_OT_ZVOL, /* UINT8 */ 11221ba4a712SPawel Jakub Dawidek DMU_OT_ZVOL_PROP, /* ZAP */ 11231ba4a712SPawel Jakub Dawidek /* other; for testing only! */ 11241ba4a712SPawel Jakub Dawidek DMU_OT_PLAIN_OTHER, /* UINT8 */ 11251ba4a712SPawel Jakub Dawidek DMU_OT_UINT64_OTHER, /* UINT64 */ 11261ba4a712SPawel Jakub Dawidek DMU_OT_ZAP_OTHER, /* ZAP */ 11271ba4a712SPawel Jakub Dawidek /* new object types: */ 11281ba4a712SPawel Jakub Dawidek DMU_OT_ERROR_LOG, /* ZAP */ 11291ba4a712SPawel Jakub Dawidek DMU_OT_SPA_HISTORY, /* UINT8 */ 11301ba4a712SPawel Jakub Dawidek DMU_OT_SPA_HISTORY_OFFSETS, /* spa_his_phys_t */ 11311ba4a712SPawel Jakub Dawidek DMU_OT_POOL_PROPS, /* ZAP */ 113210b9d77bSPawel Jakub Dawidek DMU_OT_DSL_PERMS, /* ZAP */ 113310b9d77bSPawel Jakub Dawidek DMU_OT_ACL, /* ACL */ 113410b9d77bSPawel Jakub Dawidek DMU_OT_SYSACL, /* SYSACL */ 113510b9d77bSPawel Jakub Dawidek DMU_OT_FUID, /* FUID table (Packed NVLIST UINT8) */ 113610b9d77bSPawel Jakub Dawidek DMU_OT_FUID_SIZE, /* FUID table size UINT64 */ 113710b9d77bSPawel Jakub Dawidek DMU_OT_NEXT_CLONES, /* ZAP */ 113810b9d77bSPawel Jakub Dawidek DMU_OT_SCAN_QUEUE, /* ZAP */ 113910b9d77bSPawel Jakub Dawidek DMU_OT_USERGROUP_USED, /* ZAP */ 114010b9d77bSPawel Jakub Dawidek DMU_OT_USERGROUP_QUOTA, /* ZAP */ 114110b9d77bSPawel Jakub Dawidek DMU_OT_USERREFS, /* ZAP */ 114210b9d77bSPawel Jakub Dawidek DMU_OT_DDT_ZAP, /* ZAP */ 114310b9d77bSPawel Jakub Dawidek DMU_OT_DDT_STATS, /* ZAP */ 114410b9d77bSPawel Jakub Dawidek DMU_OT_SA, /* System attr */ 114510b9d77bSPawel Jakub Dawidek DMU_OT_SA_MASTER_NODE, /* ZAP */ 114610b9d77bSPawel Jakub Dawidek DMU_OT_SA_ATTR_REGISTRATION, /* ZAP */ 114710b9d77bSPawel Jakub Dawidek DMU_OT_SA_ATTR_LAYOUTS, /* ZAP */ 114810b9d77bSPawel Jakub Dawidek DMU_OT_SCAN_XLATE, /* ZAP */ 114910b9d77bSPawel Jakub Dawidek DMU_OT_DEDUP, /* fake dedup BP from ddt_bp_create() */ 11504deb8929SAllan Jude DMU_OT_NUMTYPES, 11514deb8929SAllan Jude 11524deb8929SAllan Jude /* 11534deb8929SAllan Jude * Names for valid types declared with DMU_OT(). 11544deb8929SAllan Jude */ 11554deb8929SAllan Jude DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE), 11564deb8929SAllan Jude DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE), 11574deb8929SAllan Jude DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE), 11584deb8929SAllan Jude DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE), 11594deb8929SAllan Jude DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE), 11604deb8929SAllan Jude DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE), 11614deb8929SAllan Jude DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE), 11624deb8929SAllan Jude DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE), 11634deb8929SAllan Jude DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE), 11644deb8929SAllan Jude DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE) 11651ba4a712SPawel Jakub Dawidek } dmu_object_type_t; 11661ba4a712SPawel Jakub Dawidek 11671ba4a712SPawel Jakub Dawidek typedef enum dmu_objset_type { 11681ba4a712SPawel Jakub Dawidek DMU_OST_NONE, 11691ba4a712SPawel Jakub Dawidek DMU_OST_META, 11701ba4a712SPawel Jakub Dawidek DMU_OST_ZFS, 11711ba4a712SPawel Jakub Dawidek DMU_OST_ZVOL, 11721ba4a712SPawel Jakub Dawidek DMU_OST_OTHER, /* For testing only! */ 11731ba4a712SPawel Jakub Dawidek DMU_OST_ANY, /* Be careful! */ 11741ba4a712SPawel Jakub Dawidek DMU_OST_NUMTYPES 11751ba4a712SPawel Jakub Dawidek } dmu_objset_type_t; 11761ba4a712SPawel Jakub Dawidek 11773c2db0efSToomas Soome #define ZAP_MAXVALUELEN (1024 * 8) 11783c2db0efSToomas Soome 11791ba4a712SPawel Jakub Dawidek /* 118010b9d77bSPawel Jakub Dawidek * header for all bonus and spill buffers. 118110b9d77bSPawel Jakub Dawidek * The header has a fixed portion with a variable number 118210b9d77bSPawel Jakub Dawidek * of "lengths" depending on the number of variable sized 118310b9d77bSPawel Jakub Dawidek * attribues which are determined by the "layout number" 118410b9d77bSPawel Jakub Dawidek */ 118510b9d77bSPawel Jakub Dawidek 118610b9d77bSPawel Jakub Dawidek #define SA_MAGIC 0x2F505A /* ZFS SA */ 118710b9d77bSPawel Jakub Dawidek typedef struct sa_hdr_phys { 118810b9d77bSPawel Jakub Dawidek uint32_t sa_magic; 118910b9d77bSPawel Jakub Dawidek uint16_t sa_layout_info; /* Encoded with hdrsize and layout number */ 119010b9d77bSPawel Jakub Dawidek uint16_t sa_lengths[1]; /* optional sizes for variable length attrs */ 119110b9d77bSPawel Jakub Dawidek /* ... Data follows the lengths. */ 119210b9d77bSPawel Jakub Dawidek } sa_hdr_phys_t; 119310b9d77bSPawel Jakub Dawidek 119410b9d77bSPawel Jakub Dawidek /* 119510b9d77bSPawel Jakub Dawidek * sa_hdr_phys -> sa_layout_info 119610b9d77bSPawel Jakub Dawidek * 119710b9d77bSPawel Jakub Dawidek * 16 10 0 119810b9d77bSPawel Jakub Dawidek * +--------+-------+ 119910b9d77bSPawel Jakub Dawidek * | hdrsz |layout | 120010b9d77bSPawel Jakub Dawidek * +--------+-------+ 120110b9d77bSPawel Jakub Dawidek * 120210b9d77bSPawel Jakub Dawidek * Bits 0-10 are the layout number 120310b9d77bSPawel Jakub Dawidek * Bits 11-16 are the size of the header. 120410b9d77bSPawel Jakub Dawidek * The hdrsize is the number * 8 120510b9d77bSPawel Jakub Dawidek * 120610b9d77bSPawel Jakub Dawidek * For example. 120710b9d77bSPawel Jakub Dawidek * hdrsz of 1 ==> 8 byte header 120810b9d77bSPawel Jakub Dawidek * 2 ==> 16 byte header 120910b9d77bSPawel Jakub Dawidek * 121010b9d77bSPawel Jakub Dawidek */ 121110b9d77bSPawel Jakub Dawidek 121210b9d77bSPawel Jakub Dawidek #define SA_HDR_LAYOUT_NUM(hdr) BF32_GET(hdr->sa_layout_info, 0, 10) 121310b9d77bSPawel Jakub Dawidek #define SA_HDR_SIZE(hdr) BF32_GET_SB(hdr->sa_layout_info, 10, 16, 3, 0) 121410b9d77bSPawel Jakub Dawidek #define SA_HDR_LAYOUT_INFO_ENCODE(x, num, size) \ 121510b9d77bSPawel Jakub Dawidek { \ 121610b9d77bSPawel Jakub Dawidek BF32_SET_SB(x, 10, 6, 3, 0, size); \ 121710b9d77bSPawel Jakub Dawidek BF32_SET(x, 0, 10, num); \ 121810b9d77bSPawel Jakub Dawidek } 121910b9d77bSPawel Jakub Dawidek 122010b9d77bSPawel Jakub Dawidek #define SA_MODE_OFFSET 0 122110b9d77bSPawel Jakub Dawidek #define SA_SIZE_OFFSET 8 122210b9d77bSPawel Jakub Dawidek #define SA_GEN_OFFSET 16 122310b9d77bSPawel Jakub Dawidek #define SA_UID_OFFSET 24 122410b9d77bSPawel Jakub Dawidek #define SA_GID_OFFSET 32 122510b9d77bSPawel Jakub Dawidek #define SA_PARENT_OFFSET 40 122684a6eddcSToomas Soome #define SA_SYMLINK_OFFSET 160 122710b9d77bSPawel Jakub Dawidek 122827e05a19SMatt Macy #define ZIO_OBJSET_MAC_LEN 32 122927e05a19SMatt Macy 123010b9d77bSPawel Jakub Dawidek /* 12311ba4a712SPawel Jakub Dawidek * Intent log header - this on disk structure holds fields to manage 12321ba4a712SPawel Jakub Dawidek * the log. All fields are 64 bit to easily handle cross architectures. 12331ba4a712SPawel Jakub Dawidek */ 12341ba4a712SPawel Jakub Dawidek typedef struct zil_header { 12351ba4a712SPawel Jakub Dawidek uint64_t zh_claim_txg; /* txg in which log blocks were claimed */ 12361ba4a712SPawel Jakub Dawidek uint64_t zh_replay_seq; /* highest replayed sequence number */ 12371ba4a712SPawel Jakub Dawidek blkptr_t zh_log; /* log chain */ 12381ba4a712SPawel Jakub Dawidek uint64_t zh_claim_seq; /* highest claimed sequence number */ 12391ba4a712SPawel Jakub Dawidek uint64_t zh_pad[5]; 12401ba4a712SPawel Jakub Dawidek } zil_header_t; 12411ba4a712SPawel Jakub Dawidek 124227e05a19SMatt Macy #define OBJSET_PHYS_SIZE_V2 2048 124327e05a19SMatt Macy #define OBJSET_PHYS_SIZE_V3 4096 124410b9d77bSPawel Jakub Dawidek 12451ba4a712SPawel Jakub Dawidek typedef struct objset_phys { 12461ba4a712SPawel Jakub Dawidek dnode_phys_t os_meta_dnode; 12471ba4a712SPawel Jakub Dawidek zil_header_t os_zil_header; 12481ba4a712SPawel Jakub Dawidek uint64_t os_type; 12498fc25799SMartin Matuska uint64_t os_flags; 125027e05a19SMatt Macy uint8_t os_portable_mac[ZIO_OBJSET_MAC_LEN]; 125127e05a19SMatt Macy uint8_t os_local_mac[ZIO_OBJSET_MAC_LEN]; 125227e05a19SMatt Macy char os_pad0[OBJSET_PHYS_SIZE_V2 - sizeof (dnode_phys_t)*3 - 125327e05a19SMatt Macy sizeof (zil_header_t) - sizeof (uint64_t)*2 - 125427e05a19SMatt Macy 2*ZIO_OBJSET_MAC_LEN]; 12558fc25799SMartin Matuska dnode_phys_t os_userused_dnode; 12568fc25799SMartin Matuska dnode_phys_t os_groupused_dnode; 125727e05a19SMatt Macy dnode_phys_t os_projectused_dnode; 125827e05a19SMatt Macy char os_pad1[OBJSET_PHYS_SIZE_V3 - OBJSET_PHYS_SIZE_V2 - 125927e05a19SMatt Macy sizeof (dnode_phys_t)]; 12601ba4a712SPawel Jakub Dawidek } objset_phys_t; 12611ba4a712SPawel Jakub Dawidek 12621ba4a712SPawel Jakub Dawidek typedef struct dsl_dir_phys { 12631ba4a712SPawel Jakub Dawidek uint64_t dd_creation_time; /* not actually used */ 12641ba4a712SPawel Jakub Dawidek uint64_t dd_head_dataset_obj; 12651ba4a712SPawel Jakub Dawidek uint64_t dd_parent_obj; 12661ba4a712SPawel Jakub Dawidek uint64_t dd_clone_parent_obj; 12671ba4a712SPawel Jakub Dawidek uint64_t dd_child_dir_zapobj; 12681ba4a712SPawel Jakub Dawidek /* 12691ba4a712SPawel Jakub Dawidek * how much space our children are accounting for; for leaf 12701ba4a712SPawel Jakub Dawidek * datasets, == physical space used by fs + snaps 12711ba4a712SPawel Jakub Dawidek */ 12721ba4a712SPawel Jakub Dawidek uint64_t dd_used_bytes; 12731ba4a712SPawel Jakub Dawidek uint64_t dd_compressed_bytes; 12741ba4a712SPawel Jakub Dawidek uint64_t dd_uncompressed_bytes; 12751ba4a712SPawel Jakub Dawidek /* Administrative quota setting */ 12761ba4a712SPawel Jakub Dawidek uint64_t dd_quota; 12771ba4a712SPawel Jakub Dawidek /* Administrative reservation setting */ 12781ba4a712SPawel Jakub Dawidek uint64_t dd_reserved; 12791ba4a712SPawel Jakub Dawidek uint64_t dd_props_zapobj; 12801ba4a712SPawel Jakub Dawidek uint64_t dd_pad[21]; /* pad out to 256 bytes for good measure */ 12811ba4a712SPawel Jakub Dawidek } dsl_dir_phys_t; 12821ba4a712SPawel Jakub Dawidek 12831ba4a712SPawel Jakub Dawidek typedef struct dsl_dataset_phys { 12841ba4a712SPawel Jakub Dawidek uint64_t ds_dir_obj; 12851ba4a712SPawel Jakub Dawidek uint64_t ds_prev_snap_obj; 12861ba4a712SPawel Jakub Dawidek uint64_t ds_prev_snap_txg; 12871ba4a712SPawel Jakub Dawidek uint64_t ds_next_snap_obj; 12881ba4a712SPawel Jakub Dawidek uint64_t ds_snapnames_zapobj; /* zap obj of snaps; ==0 for snaps */ 12891ba4a712SPawel Jakub Dawidek uint64_t ds_num_children; /* clone/snap children; ==0 for head */ 12901ba4a712SPawel Jakub Dawidek uint64_t ds_creation_time; /* seconds since 1970 */ 12911ba4a712SPawel Jakub Dawidek uint64_t ds_creation_txg; 12921ba4a712SPawel Jakub Dawidek uint64_t ds_deadlist_obj; 12931ba4a712SPawel Jakub Dawidek uint64_t ds_used_bytes; 12941ba4a712SPawel Jakub Dawidek uint64_t ds_compressed_bytes; 12951ba4a712SPawel Jakub Dawidek uint64_t ds_uncompressed_bytes; 12961ba4a712SPawel Jakub Dawidek uint64_t ds_unique_bytes; /* only relevant to snapshots */ 12971ba4a712SPawel Jakub Dawidek /* 12981ba4a712SPawel Jakub Dawidek * The ds_fsid_guid is a 56-bit ID that can change to avoid 12991ba4a712SPawel Jakub Dawidek * collisions. The ds_guid is a 64-bit ID that will never 13001ba4a712SPawel Jakub Dawidek * change, so there is a small probability that it will collide. 13011ba4a712SPawel Jakub Dawidek */ 13021ba4a712SPawel Jakub Dawidek uint64_t ds_fsid_guid; 13031ba4a712SPawel Jakub Dawidek uint64_t ds_guid; 13041ba4a712SPawel Jakub Dawidek uint64_t ds_flags; 13051ba4a712SPawel Jakub Dawidek blkptr_t ds_bp; 13061ba4a712SPawel Jakub Dawidek uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */ 13071ba4a712SPawel Jakub Dawidek } dsl_dataset_phys_t; 13081ba4a712SPawel Jakub Dawidek 13091ba4a712SPawel Jakub Dawidek /* 13101ba4a712SPawel Jakub Dawidek * The names of zap entries in the DIRECTORY_OBJECT of the MOS. 13111ba4a712SPawel Jakub Dawidek */ 13121ba4a712SPawel Jakub Dawidek #define DMU_POOL_DIRECTORY_OBJECT 1 13131ba4a712SPawel Jakub Dawidek #define DMU_POOL_CONFIG "config" 13144deb8929SAllan Jude #define DMU_POOL_FEATURES_FOR_READ "features_for_read" 13151ba4a712SPawel Jakub Dawidek #define DMU_POOL_ROOT_DATASET "root_dataset" 13161ba4a712SPawel Jakub Dawidek #define DMU_POOL_SYNC_BPLIST "sync_bplist" 13171ba4a712SPawel Jakub Dawidek #define DMU_POOL_ERRLOG_SCRUB "errlog_scrub" 13181ba4a712SPawel Jakub Dawidek #define DMU_POOL_ERRLOG_LAST "errlog_last" 13191ba4a712SPawel Jakub Dawidek #define DMU_POOL_SPARES "spares" 13201ba4a712SPawel Jakub Dawidek #define DMU_POOL_DEFLATE "deflate" 13211ba4a712SPawel Jakub Dawidek #define DMU_POOL_HISTORY "history" 13221ba4a712SPawel Jakub Dawidek #define DMU_POOL_PROPS "pool_props" 13232c55d090SToomas Soome #define DMU_POOL_CHECKSUM_SALT "org.illumos:checksum_salt" 1324b1b93268SToomas Soome #define DMU_POOL_REMOVING "com.delphix:removing" 1325b1b93268SToomas Soome #define DMU_POOL_OBSOLETE_BPOBJ "com.delphix:obsolete_bpobj" 1326b1b93268SToomas Soome #define DMU_POOL_CONDENSING_INDIRECT "com.delphix:condensing_indirect" 13271ba4a712SPawel Jakub Dawidek 13281ba4a712SPawel Jakub Dawidek #define ZAP_MAGIC 0x2F52AB2ABULL 13291ba4a712SPawel Jakub Dawidek 13301ba4a712SPawel Jakub Dawidek #define FZAP_BLOCK_SHIFT(zap) ((zap)->zap_block_shift) 13311ba4a712SPawel Jakub Dawidek 13321ba4a712SPawel Jakub Dawidek #define ZAP_MAXCD (uint32_t)(-1) 13331ba4a712SPawel Jakub Dawidek #define ZAP_HASHBITS 28 13341ba4a712SPawel Jakub Dawidek #define MZAP_ENT_LEN 64 13351ba4a712SPawel Jakub Dawidek #define MZAP_NAME_LEN (MZAP_ENT_LEN - 8 - 4 - 2) 1336*4d297e70SToomas Soome #define MZAP_MAX_BLKSZ SPA_OLD_MAXBLOCKSIZE 13371ba4a712SPawel Jakub Dawidek 13381ba4a712SPawel Jakub Dawidek typedef struct mzap_ent_phys { 13391ba4a712SPawel Jakub Dawidek uint64_t mze_value; 13401ba4a712SPawel Jakub Dawidek uint32_t mze_cd; 13411ba4a712SPawel Jakub Dawidek uint16_t mze_pad; /* in case we want to chain them someday */ 13421ba4a712SPawel Jakub Dawidek char mze_name[MZAP_NAME_LEN]; 13431ba4a712SPawel Jakub Dawidek } mzap_ent_phys_t; 13441ba4a712SPawel Jakub Dawidek 13451ba4a712SPawel Jakub Dawidek typedef struct mzap_phys { 13461ba4a712SPawel Jakub Dawidek uint64_t mz_block_type; /* ZBT_MICRO */ 13471ba4a712SPawel Jakub Dawidek uint64_t mz_salt; 1348*4d297e70SToomas Soome uint64_t mz_normflags; 1349*4d297e70SToomas Soome uint64_t mz_pad[5]; 13501ba4a712SPawel Jakub Dawidek mzap_ent_phys_t mz_chunk[1]; 13511ba4a712SPawel Jakub Dawidek /* actually variable size depending on block size */ 13521ba4a712SPawel Jakub Dawidek } mzap_phys_t; 13531ba4a712SPawel Jakub Dawidek 13541ba4a712SPawel Jakub Dawidek /* 13551ba4a712SPawel Jakub Dawidek * The (fat) zap is stored in one object. It is an array of 13561ba4a712SPawel Jakub Dawidek * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of: 13571ba4a712SPawel Jakub Dawidek * 13581ba4a712SPawel Jakub Dawidek * ptrtbl fits in first block: 13591ba4a712SPawel Jakub Dawidek * [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ... 13601ba4a712SPawel Jakub Dawidek * 13611ba4a712SPawel Jakub Dawidek * ptrtbl too big for first block: 13621ba4a712SPawel Jakub Dawidek * [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ... 13631ba4a712SPawel Jakub Dawidek * 13641ba4a712SPawel Jakub Dawidek */ 13651ba4a712SPawel Jakub Dawidek 13661ba4a712SPawel Jakub Dawidek #define ZBT_LEAF ((1ULL << 63) + 0) 13671ba4a712SPawel Jakub Dawidek #define ZBT_HEADER ((1ULL << 63) + 1) 13681ba4a712SPawel Jakub Dawidek #define ZBT_MICRO ((1ULL << 63) + 3) 13691ba4a712SPawel Jakub Dawidek /* any other values are ptrtbl blocks */ 13701ba4a712SPawel Jakub Dawidek 13711ba4a712SPawel Jakub Dawidek /* 13721ba4a712SPawel Jakub Dawidek * the embedded pointer table takes up half a block: 13731ba4a712SPawel Jakub Dawidek * block size / entry size (2^3) / 2 13741ba4a712SPawel Jakub Dawidek */ 13751ba4a712SPawel Jakub Dawidek #define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1) 13761ba4a712SPawel Jakub Dawidek 13771ba4a712SPawel Jakub Dawidek /* 13781ba4a712SPawel Jakub Dawidek * The embedded pointer table starts half-way through the block. Since 13791ba4a712SPawel Jakub Dawidek * the pointer table itself is half the block, it starts at (64-bit) 13801ba4a712SPawel Jakub Dawidek * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)). 13811ba4a712SPawel Jakub Dawidek */ 13821ba4a712SPawel Jakub Dawidek #define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \ 13831ba4a712SPawel Jakub Dawidek ((uint64_t *)(zap)->zap_phys) \ 13841ba4a712SPawel Jakub Dawidek [(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))] 13851ba4a712SPawel Jakub Dawidek 13861ba4a712SPawel Jakub Dawidek /* 13871ba4a712SPawel Jakub Dawidek * TAKE NOTE: 13881ba4a712SPawel Jakub Dawidek * If zap_phys_t is modified, zap_byteswap() must be modified. 13891ba4a712SPawel Jakub Dawidek */ 13901ba4a712SPawel Jakub Dawidek typedef struct zap_phys { 13911ba4a712SPawel Jakub Dawidek uint64_t zap_block_type; /* ZBT_HEADER */ 13921ba4a712SPawel Jakub Dawidek uint64_t zap_magic; /* ZAP_MAGIC */ 13931ba4a712SPawel Jakub Dawidek 13941ba4a712SPawel Jakub Dawidek struct zap_table_phys { 13951ba4a712SPawel Jakub Dawidek uint64_t zt_blk; /* starting block number */ 13961ba4a712SPawel Jakub Dawidek uint64_t zt_numblks; /* number of blocks */ 13971ba4a712SPawel Jakub Dawidek uint64_t zt_shift; /* bits to index it */ 13981ba4a712SPawel Jakub Dawidek uint64_t zt_nextblk; /* next (larger) copy start block */ 13991ba4a712SPawel Jakub Dawidek uint64_t zt_blks_copied; /* number source blocks copied */ 14001ba4a712SPawel Jakub Dawidek } zap_ptrtbl; 14011ba4a712SPawel Jakub Dawidek 14021ba4a712SPawel Jakub Dawidek uint64_t zap_freeblk; /* the next free block */ 14031ba4a712SPawel Jakub Dawidek uint64_t zap_num_leafs; /* number of leafs */ 14041ba4a712SPawel Jakub Dawidek uint64_t zap_num_entries; /* number of entries */ 14051ba4a712SPawel Jakub Dawidek uint64_t zap_salt; /* salt to stir into hash function */ 1406*4d297e70SToomas Soome uint64_t zap_normflags; /* flags for u8_textprep_str() */ 1407*4d297e70SToomas Soome uint64_t zap_flags; /* zap_flags_t */ 14081ba4a712SPawel Jakub Dawidek /* 14091ba4a712SPawel Jakub Dawidek * This structure is followed by padding, and then the embedded 14101ba4a712SPawel Jakub Dawidek * pointer table. The embedded pointer table takes up second 14111ba4a712SPawel Jakub Dawidek * half of the block. It is accessed using the 14121ba4a712SPawel Jakub Dawidek * ZAP_EMBEDDED_PTRTBL_ENT() macro. 14131ba4a712SPawel Jakub Dawidek */ 14141ba4a712SPawel Jakub Dawidek } zap_phys_t; 14151ba4a712SPawel Jakub Dawidek 14161ba4a712SPawel Jakub Dawidek typedef struct zap_table_phys zap_table_phys_t; 14171ba4a712SPawel Jakub Dawidek 1418*4d297e70SToomas Soome struct spa; 14191ba4a712SPawel Jakub Dawidek typedef struct fat_zap { 14201ba4a712SPawel Jakub Dawidek int zap_block_shift; /* block size shift */ 14211ba4a712SPawel Jakub Dawidek zap_phys_t *zap_phys; 1422*4d297e70SToomas Soome const struct spa *zap_spa; 1423*4d297e70SToomas Soome const dnode_phys_t *zap_dnode; 14241ba4a712SPawel Jakub Dawidek } fat_zap_t; 14251ba4a712SPawel Jakub Dawidek 14261ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_MAGIC 0x2AB1EAF 14271ba4a712SPawel Jakub Dawidek 14281ba4a712SPawel Jakub Dawidek /* chunk size = 24 bytes */ 14291ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_CHUNKSIZE 24 14301ba4a712SPawel Jakub Dawidek 14311ba4a712SPawel Jakub Dawidek /* 14321ba4a712SPawel Jakub Dawidek * The amount of space available for chunks is: 14331ba4a712SPawel Jakub Dawidek * block size (1<<l->l_bs) - hash entry size (2) * number of hash 14341ba4a712SPawel Jakub Dawidek * entries - header space (2*chunksize) 14351ba4a712SPawel Jakub Dawidek */ 14361ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_NUMCHUNKS(l) \ 14371ba4a712SPawel Jakub Dawidek (((1<<(l)->l_bs) - 2*ZAP_LEAF_HASH_NUMENTRIES(l)) / \ 14381ba4a712SPawel Jakub Dawidek ZAP_LEAF_CHUNKSIZE - 2) 14391ba4a712SPawel Jakub Dawidek 14401ba4a712SPawel Jakub Dawidek /* 14411ba4a712SPawel Jakub Dawidek * The amount of space within the chunk available for the array is: 14421ba4a712SPawel Jakub Dawidek * chunk size - space for type (1) - space for next pointer (2) 14431ba4a712SPawel Jakub Dawidek */ 14441ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3) 14451ba4a712SPawel Jakub Dawidek 14461ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_ARRAY_NCHUNKS(bytes) \ 14471ba4a712SPawel Jakub Dawidek (((bytes)+ZAP_LEAF_ARRAY_BYTES-1)/ZAP_LEAF_ARRAY_BYTES) 14481ba4a712SPawel Jakub Dawidek 14491ba4a712SPawel Jakub Dawidek /* 14501ba4a712SPawel Jakub Dawidek * Low water mark: when there are only this many chunks free, start 14511ba4a712SPawel Jakub Dawidek * growing the ptrtbl. Ideally, this should be larger than a 14521ba4a712SPawel Jakub Dawidek * "reasonably-sized" entry. 20 chunks is more than enough for the 14531ba4a712SPawel Jakub Dawidek * largest directory entry (MAXNAMELEN (256) byte name, 8-byte value), 14541ba4a712SPawel Jakub Dawidek * while still being only around 3% for 16k blocks. 14551ba4a712SPawel Jakub Dawidek */ 14561ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_LOW_WATER (20) 14571ba4a712SPawel Jakub Dawidek 14581ba4a712SPawel Jakub Dawidek /* 14591ba4a712SPawel Jakub Dawidek * The leaf hash table has block size / 2^5 (32) number of entries, 14601ba4a712SPawel Jakub Dawidek * which should be more than enough for the maximum number of entries, 14611ba4a712SPawel Jakub Dawidek * which is less than block size / CHUNKSIZE (24) / minimum number of 14621ba4a712SPawel Jakub Dawidek * chunks per entry (3). 14631ba4a712SPawel Jakub Dawidek */ 14641ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_HASH_SHIFT(l) ((l)->l_bs - 5) 14651ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_HASH_NUMENTRIES(l) (1 << ZAP_LEAF_HASH_SHIFT(l)) 14661ba4a712SPawel Jakub Dawidek 14671ba4a712SPawel Jakub Dawidek /* 14681ba4a712SPawel Jakub Dawidek * The chunks start immediately after the hash table. The end of the 14691ba4a712SPawel Jakub Dawidek * hash table is at l_hash + HASH_NUMENTRIES, which we simply cast to a 14701ba4a712SPawel Jakub Dawidek * chunk_t. 14711ba4a712SPawel Jakub Dawidek */ 14721ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_CHUNK(l, idx) \ 14731ba4a712SPawel Jakub Dawidek ((zap_leaf_chunk_t *) \ 14741ba4a712SPawel Jakub Dawidek ((l)->l_phys->l_hash + ZAP_LEAF_HASH_NUMENTRIES(l)))[idx] 14751ba4a712SPawel Jakub Dawidek #define ZAP_LEAF_ENTRY(l, idx) (&ZAP_LEAF_CHUNK(l, idx).l_entry) 14761ba4a712SPawel Jakub Dawidek 14771ba4a712SPawel Jakub Dawidek typedef enum zap_chunk_type { 14781ba4a712SPawel Jakub Dawidek ZAP_CHUNK_FREE = 253, 14791ba4a712SPawel Jakub Dawidek ZAP_CHUNK_ENTRY = 252, 14801ba4a712SPawel Jakub Dawidek ZAP_CHUNK_ARRAY = 251, 14811ba4a712SPawel Jakub Dawidek ZAP_CHUNK_TYPE_MAX = 250 14821ba4a712SPawel Jakub Dawidek } zap_chunk_type_t; 14831ba4a712SPawel Jakub Dawidek 14841ba4a712SPawel Jakub Dawidek /* 14851ba4a712SPawel Jakub Dawidek * TAKE NOTE: 14861ba4a712SPawel Jakub Dawidek * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified. 14871ba4a712SPawel Jakub Dawidek */ 14881ba4a712SPawel Jakub Dawidek typedef struct zap_leaf_phys { 14891ba4a712SPawel Jakub Dawidek struct zap_leaf_header { 14901ba4a712SPawel Jakub Dawidek uint64_t lh_block_type; /* ZBT_LEAF */ 14911ba4a712SPawel Jakub Dawidek uint64_t lh_pad1; 14921ba4a712SPawel Jakub Dawidek uint64_t lh_prefix; /* hash prefix of this leaf */ 14931ba4a712SPawel Jakub Dawidek uint32_t lh_magic; /* ZAP_LEAF_MAGIC */ 14941ba4a712SPawel Jakub Dawidek uint16_t lh_nfree; /* number free chunks */ 14951ba4a712SPawel Jakub Dawidek uint16_t lh_nentries; /* number of entries */ 14961ba4a712SPawel Jakub Dawidek uint16_t lh_prefix_len; /* num bits used to id this */ 14971ba4a712SPawel Jakub Dawidek 14981ba4a712SPawel Jakub Dawidek /* above is accessable to zap, below is zap_leaf private */ 14991ba4a712SPawel Jakub Dawidek 15001ba4a712SPawel Jakub Dawidek uint16_t lh_freelist; /* chunk head of free list */ 15011ba4a712SPawel Jakub Dawidek uint8_t lh_pad2[12]; 15021ba4a712SPawel Jakub Dawidek } l_hdr; /* 2 24-byte chunks */ 15031ba4a712SPawel Jakub Dawidek 15041ba4a712SPawel Jakub Dawidek /* 15051ba4a712SPawel Jakub Dawidek * The header is followed by a hash table with 15061ba4a712SPawel Jakub Dawidek * ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is 15071ba4a712SPawel Jakub Dawidek * followed by an array of ZAP_LEAF_NUMCHUNKS(zap) 15081ba4a712SPawel Jakub Dawidek * zap_leaf_chunk structures. These structures are accessed 15091ba4a712SPawel Jakub Dawidek * with the ZAP_LEAF_CHUNK() macro. 15101ba4a712SPawel Jakub Dawidek */ 15111ba4a712SPawel Jakub Dawidek 15121ba4a712SPawel Jakub Dawidek uint16_t l_hash[1]; 15131ba4a712SPawel Jakub Dawidek } zap_leaf_phys_t; 15141ba4a712SPawel Jakub Dawidek 15151ba4a712SPawel Jakub Dawidek typedef union zap_leaf_chunk { 15161ba4a712SPawel Jakub Dawidek struct zap_leaf_entry { 15171ba4a712SPawel Jakub Dawidek uint8_t le_type; /* always ZAP_CHUNK_ENTRY */ 15184ed4f4cfSAndriy Gapon uint8_t le_value_intlen; /* size of ints */ 15191ba4a712SPawel Jakub Dawidek uint16_t le_next; /* next entry in hash chain */ 15201ba4a712SPawel Jakub Dawidek uint16_t le_name_chunk; /* first chunk of the name */ 15214ed4f4cfSAndriy Gapon uint16_t le_name_numints; /* bytes in name, incl null */ 15221ba4a712SPawel Jakub Dawidek uint16_t le_value_chunk; /* first chunk of the value */ 15234ed4f4cfSAndriy Gapon uint16_t le_value_numints; /* value length in ints */ 15241ba4a712SPawel Jakub Dawidek uint32_t le_cd; /* collision differentiator */ 15251ba4a712SPawel Jakub Dawidek uint64_t le_hash; /* hash value of the name */ 15261ba4a712SPawel Jakub Dawidek } l_entry; 15271ba4a712SPawel Jakub Dawidek struct zap_leaf_array { 15281ba4a712SPawel Jakub Dawidek uint8_t la_type; /* always ZAP_CHUNK_ARRAY */ 15291ba4a712SPawel Jakub Dawidek uint8_t la_array[ZAP_LEAF_ARRAY_BYTES]; 15301ba4a712SPawel Jakub Dawidek uint16_t la_next; /* next blk or CHAIN_END */ 15311ba4a712SPawel Jakub Dawidek } l_array; 15321ba4a712SPawel Jakub Dawidek struct zap_leaf_free { 15331ba4a712SPawel Jakub Dawidek uint8_t lf_type; /* always ZAP_CHUNK_FREE */ 15341ba4a712SPawel Jakub Dawidek uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES]; 15351ba4a712SPawel Jakub Dawidek uint16_t lf_next; /* next in free list, or CHAIN_END */ 15361ba4a712SPawel Jakub Dawidek } l_free; 15371ba4a712SPawel Jakub Dawidek } zap_leaf_chunk_t; 15381ba4a712SPawel Jakub Dawidek 15391ba4a712SPawel Jakub Dawidek typedef struct zap_leaf { 15401ba4a712SPawel Jakub Dawidek int l_bs; /* block size shift */ 15411ba4a712SPawel Jakub Dawidek zap_leaf_phys_t *l_phys; 15421ba4a712SPawel Jakub Dawidek } zap_leaf_t; 15431ba4a712SPawel Jakub Dawidek 15441ba4a712SPawel Jakub Dawidek /* 15451ba4a712SPawel Jakub Dawidek * Define special zfs pflags 15461ba4a712SPawel Jakub Dawidek */ 15471ba4a712SPawel Jakub Dawidek #define ZFS_XATTR 0x1 /* is an extended attribute */ 15481ba4a712SPawel Jakub Dawidek #define ZFS_INHERIT_ACE 0x2 /* ace has inheritable ACEs */ 15491ba4a712SPawel Jakub Dawidek #define ZFS_ACL_TRIVIAL 0x4 /* files ACL is trivial */ 15501ba4a712SPawel Jakub Dawidek 15511ba4a712SPawel Jakub Dawidek #define MASTER_NODE_OBJ 1 15521ba4a712SPawel Jakub Dawidek 15531ba4a712SPawel Jakub Dawidek /* 15541ba4a712SPawel Jakub Dawidek * special attributes for master node. 15551ba4a712SPawel Jakub Dawidek */ 15561ba4a712SPawel Jakub Dawidek 15571ba4a712SPawel Jakub Dawidek #define ZFS_FSID "FSID" 15581ba4a712SPawel Jakub Dawidek #define ZFS_UNLINKED_SET "DELETE_QUEUE" 15591ba4a712SPawel Jakub Dawidek #define ZFS_ROOT_OBJ "ROOT" 15601ba4a712SPawel Jakub Dawidek #define ZPL_VERSION_OBJ "VERSION" 15611ba4a712SPawel Jakub Dawidek #define ZFS_PROP_BLOCKPERPAGE "BLOCKPERPAGE" 15621ba4a712SPawel Jakub Dawidek #define ZFS_PROP_NOGROWBLOCKS "NOGROWBLOCKS" 15631ba4a712SPawel Jakub Dawidek 15641ba4a712SPawel Jakub Dawidek #define ZFS_FLAG_BLOCKPERPAGE 0x1 15651ba4a712SPawel Jakub Dawidek #define ZFS_FLAG_NOGROWBLOCKS 0x2 15661ba4a712SPawel Jakub Dawidek 15671ba4a712SPawel Jakub Dawidek /* 15681ba4a712SPawel Jakub Dawidek * ZPL version - rev'd whenever an incompatible on-disk format change 15691ba4a712SPawel Jakub Dawidek * occurs. Independent of SPA/DMU/ZAP versioning. 15701ba4a712SPawel Jakub Dawidek */ 15711ba4a712SPawel Jakub Dawidek 15721ba4a712SPawel Jakub Dawidek #define ZPL_VERSION 1ULL 15731ba4a712SPawel Jakub Dawidek 15741ba4a712SPawel Jakub Dawidek /* 15751ba4a712SPawel Jakub Dawidek * The directory entry has the type (currently unused on Solaris) in the 15761ba4a712SPawel Jakub Dawidek * top 4 bits, and the object number in the low 48 bits. The "middle" 15771ba4a712SPawel Jakub Dawidek * 12 bits are unused. 15781ba4a712SPawel Jakub Dawidek */ 15791ba4a712SPawel Jakub Dawidek #define ZFS_DIRENT_TYPE(de) BF64_GET(de, 60, 4) 15801ba4a712SPawel Jakub Dawidek #define ZFS_DIRENT_OBJ(de) BF64_GET(de, 0, 48) 15811ba4a712SPawel Jakub Dawidek #define ZFS_DIRENT_MAKE(type, obj) (((uint64_t)type << 60) | obj) 15821ba4a712SPawel Jakub Dawidek 15831ba4a712SPawel Jakub Dawidek typedef struct ace { 15841ba4a712SPawel Jakub Dawidek uid_t a_who; /* uid or gid */ 15851ba4a712SPawel Jakub Dawidek uint32_t a_access_mask; /* read,write,... */ 15861ba4a712SPawel Jakub Dawidek uint16_t a_flags; /* see below */ 15871ba4a712SPawel Jakub Dawidek uint16_t a_type; /* allow or deny */ 15881ba4a712SPawel Jakub Dawidek } ace_t; 15891ba4a712SPawel Jakub Dawidek 15901ba4a712SPawel Jakub Dawidek #define ACE_SLOT_CNT 6 15911ba4a712SPawel Jakub Dawidek 15921ba4a712SPawel Jakub Dawidek typedef struct zfs_znode_acl { 15931ba4a712SPawel Jakub Dawidek uint64_t z_acl_extern_obj; /* ext acl pieces */ 15941ba4a712SPawel Jakub Dawidek uint32_t z_acl_count; /* Number of ACEs */ 15951ba4a712SPawel Jakub Dawidek uint16_t z_acl_version; /* acl version */ 15961ba4a712SPawel Jakub Dawidek uint16_t z_acl_pad; /* pad */ 15971ba4a712SPawel Jakub Dawidek ace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */ 15981ba4a712SPawel Jakub Dawidek } zfs_znode_acl_t; 15991ba4a712SPawel Jakub Dawidek 16001ba4a712SPawel Jakub Dawidek /* 16011ba4a712SPawel Jakub Dawidek * This is the persistent portion of the znode. It is stored 16021ba4a712SPawel Jakub Dawidek * in the "bonus buffer" of the file. Short symbolic links 16031ba4a712SPawel Jakub Dawidek * are also stored in the bonus buffer. 16041ba4a712SPawel Jakub Dawidek */ 16051ba4a712SPawel Jakub Dawidek typedef struct znode_phys { 16061ba4a712SPawel Jakub Dawidek uint64_t zp_atime[2]; /* 0 - last file access time */ 16071ba4a712SPawel Jakub Dawidek uint64_t zp_mtime[2]; /* 16 - last file modification time */ 16081ba4a712SPawel Jakub Dawidek uint64_t zp_ctime[2]; /* 32 - last file change time */ 16091ba4a712SPawel Jakub Dawidek uint64_t zp_crtime[2]; /* 48 - creation time */ 16101ba4a712SPawel Jakub Dawidek uint64_t zp_gen; /* 64 - generation (txg of creation) */ 16111ba4a712SPawel Jakub Dawidek uint64_t zp_mode; /* 72 - file mode bits */ 16121ba4a712SPawel Jakub Dawidek uint64_t zp_size; /* 80 - size of file */ 16131ba4a712SPawel Jakub Dawidek uint64_t zp_parent; /* 88 - directory parent (`..') */ 16141ba4a712SPawel Jakub Dawidek uint64_t zp_links; /* 96 - number of links to file */ 16151ba4a712SPawel Jakub Dawidek uint64_t zp_xattr; /* 104 - DMU object for xattrs */ 16161ba4a712SPawel Jakub Dawidek uint64_t zp_rdev; /* 112 - dev_t for VBLK & VCHR files */ 16171ba4a712SPawel Jakub Dawidek uint64_t zp_flags; /* 120 - persistent flags */ 16181ba4a712SPawel Jakub Dawidek uint64_t zp_uid; /* 128 - file owner */ 16191ba4a712SPawel Jakub Dawidek uint64_t zp_gid; /* 136 - owning group */ 16201ba4a712SPawel Jakub Dawidek uint64_t zp_pad[4]; /* 144 - future */ 16211ba4a712SPawel Jakub Dawidek zfs_znode_acl_t zp_acl; /* 176 - 263 ACL */ 16221ba4a712SPawel Jakub Dawidek /* 16231ba4a712SPawel Jakub Dawidek * Data may pad out any remaining bytes in the znode buffer, eg: 16241ba4a712SPawel Jakub Dawidek * 16251ba4a712SPawel Jakub Dawidek * |<---------------------- dnode_phys (512) ------------------------>| 16261ba4a712SPawel Jakub Dawidek * |<-- dnode (192) --->|<----------- "bonus" buffer (320) ---------->| 16271ba4a712SPawel Jakub Dawidek * |<---- znode (264) ---->|<---- data (56) ---->| 16281ba4a712SPawel Jakub Dawidek * 16291ba4a712SPawel Jakub Dawidek * At present, we only use this space to store symbolic links. 16301ba4a712SPawel Jakub Dawidek */ 16311ba4a712SPawel Jakub Dawidek } znode_phys_t; 16321ba4a712SPawel Jakub Dawidek 16331ba4a712SPawel Jakub Dawidek /* 16341ba4a712SPawel Jakub Dawidek * In-core vdev representation. 16351ba4a712SPawel Jakub Dawidek */ 16361ba4a712SPawel Jakub Dawidek struct vdev; 16372c55d090SToomas Soome struct spa; 1638e1899ef6SDoug Rabson typedef int vdev_phys_read_t(struct vdev *vdev, void *priv, 1639e1899ef6SDoug Rabson off_t offset, void *buf, size_t bytes); 1640e1899ef6SDoug Rabson typedef int vdev_read_t(struct vdev *vdev, const blkptr_t *bp, 1641e1899ef6SDoug Rabson void *buf, off_t offset, size_t bytes); 16421ba4a712SPawel Jakub Dawidek 16431ba4a712SPawel Jakub Dawidek typedef STAILQ_HEAD(vdev_list, vdev) vdev_list_t; 16441ba4a712SPawel Jakub Dawidek 1645b1b93268SToomas Soome typedef struct vdev_indirect_mapping_entry_phys { 1646b1b93268SToomas Soome /* 1647b1b93268SToomas Soome * Decode with DVA_MAPPING_* macros. 1648b1b93268SToomas Soome * Contains: 1649b1b93268SToomas Soome * the source offset (low 63 bits) 1650b1b93268SToomas Soome * the one-bit "mark", used for garbage collection (by zdb) 1651b1b93268SToomas Soome */ 1652b1b93268SToomas Soome uint64_t vimep_src; 1653b1b93268SToomas Soome 1654b1b93268SToomas Soome /* 1655b1b93268SToomas Soome * Note: the DVA's asize is 24 bits, and can thus store ranges 1656b1b93268SToomas Soome * up to 8GB. 1657b1b93268SToomas Soome */ 1658b1b93268SToomas Soome dva_t vimep_dst; 1659b1b93268SToomas Soome } vdev_indirect_mapping_entry_phys_t; 1660b1b93268SToomas Soome 1661b1b93268SToomas Soome #define DVA_MAPPING_GET_SRC_OFFSET(vimep) \ 1662b1b93268SToomas Soome BF64_GET_SB((vimep)->vimep_src, 0, 63, SPA_MINBLOCKSHIFT, 0) 1663b1b93268SToomas Soome #define DVA_MAPPING_SET_SRC_OFFSET(vimep, x) \ 1664b1b93268SToomas Soome BF64_SET_SB((vimep)->vimep_src, 0, 63, SPA_MINBLOCKSHIFT, 0, x) 1665b1b93268SToomas Soome 1666b1b93268SToomas Soome typedef struct vdev_indirect_mapping_entry { 1667b1b93268SToomas Soome vdev_indirect_mapping_entry_phys_t vime_mapping; 1668b1b93268SToomas Soome uint32_t vime_obsolete_count; 1669b1b93268SToomas Soome list_node_t vime_node; 1670b1b93268SToomas Soome } vdev_indirect_mapping_entry_t; 1671b1b93268SToomas Soome 1672b1b93268SToomas Soome /* 1673b1b93268SToomas Soome * This is stored in the bonus buffer of the mapping object, see comment of 1674b1b93268SToomas Soome * vdev_indirect_config for more details. 1675b1b93268SToomas Soome */ 1676b1b93268SToomas Soome typedef struct vdev_indirect_mapping_phys { 1677b1b93268SToomas Soome uint64_t vimp_max_offset; 1678b1b93268SToomas Soome uint64_t vimp_bytes_mapped; 1679b1b93268SToomas Soome uint64_t vimp_num_entries; /* number of v_i_m_entry_phys_t's */ 1680b1b93268SToomas Soome 1681b1b93268SToomas Soome /* 1682b1b93268SToomas Soome * For each entry in the mapping object, this object contains an 1683b1b93268SToomas Soome * entry representing the number of bytes of that mapping entry 1684b1b93268SToomas Soome * that were no longer in use by the pool at the time this indirect 1685b1b93268SToomas Soome * vdev was last condensed. 1686b1b93268SToomas Soome */ 1687b1b93268SToomas Soome uint64_t vimp_counts_object; 1688b1b93268SToomas Soome } vdev_indirect_mapping_phys_t; 1689b1b93268SToomas Soome 1690b1b93268SToomas Soome #define VDEV_INDIRECT_MAPPING_SIZE_V0 (3 * sizeof (uint64_t)) 1691b1b93268SToomas Soome 1692b1b93268SToomas Soome typedef struct vdev_indirect_mapping { 1693b1b93268SToomas Soome uint64_t vim_object; 1694b1b93268SToomas Soome boolean_t vim_havecounts; 1695b1b93268SToomas Soome 1696b1b93268SToomas Soome /* vim_entries segment offset currently in memory. */ 1697b1b93268SToomas Soome uint64_t vim_entry_offset; 1698b1b93268SToomas Soome /* vim_entries segment size. */ 1699b1b93268SToomas Soome size_t vim_num_entries; 1700b1b93268SToomas Soome 1701b1b93268SToomas Soome /* Needed by dnode_read() */ 1702b1b93268SToomas Soome const void *vim_spa; 1703b1b93268SToomas Soome dnode_phys_t *vim_dn; 1704b1b93268SToomas Soome 1705b1b93268SToomas Soome /* 1706b1b93268SToomas Soome * An ordered array of mapping entries, sorted by source offset. 1707b1b93268SToomas Soome * Note that vim_entries is needed during a removal (and contains 1708b1b93268SToomas Soome * mappings that have been synced to disk so far) to handle frees 1709b1b93268SToomas Soome * from the removing device. 1710b1b93268SToomas Soome */ 1711b1b93268SToomas Soome vdev_indirect_mapping_entry_phys_t *vim_entries; 1712b1b93268SToomas Soome objset_phys_t *vim_objset; 1713b1b93268SToomas Soome vdev_indirect_mapping_phys_t *vim_phys; 1714b1b93268SToomas Soome } vdev_indirect_mapping_t; 1715b1b93268SToomas Soome 1716b1b93268SToomas Soome /* 1717b1b93268SToomas Soome * On-disk indirect vdev state. 1718b1b93268SToomas Soome * 1719b1b93268SToomas Soome * An indirect vdev is described exclusively in the MOS config of a pool. 1720b1b93268SToomas Soome * The config for an indirect vdev includes several fields, which are 1721b1b93268SToomas Soome * accessed in memory by a vdev_indirect_config_t. 1722b1b93268SToomas Soome */ 1723b1b93268SToomas Soome typedef struct vdev_indirect_config { 1724b1b93268SToomas Soome /* 1725b1b93268SToomas Soome * Object (in MOS) which contains the indirect mapping. This object 1726b1b93268SToomas Soome * contains an array of vdev_indirect_mapping_entry_phys_t ordered by 1727b1b93268SToomas Soome * vimep_src. The bonus buffer for this object is a 1728b1b93268SToomas Soome * vdev_indirect_mapping_phys_t. This object is allocated when a vdev 1729b1b93268SToomas Soome * removal is initiated. 1730b1b93268SToomas Soome * 1731b1b93268SToomas Soome * Note that this object can be empty if none of the data on the vdev 1732b1b93268SToomas Soome * has been copied yet. 1733b1b93268SToomas Soome */ 1734b1b93268SToomas Soome uint64_t vic_mapping_object; 1735b1b93268SToomas Soome 1736b1b93268SToomas Soome /* 1737b1b93268SToomas Soome * Object (in MOS) which contains the birth times for the mapping 1738b1b93268SToomas Soome * entries. This object contains an array of 1739b1b93268SToomas Soome * vdev_indirect_birth_entry_phys_t sorted by vibe_offset. The bonus 1740b1b93268SToomas Soome * buffer for this object is a vdev_indirect_birth_phys_t. This object 1741b1b93268SToomas Soome * is allocated when a vdev removal is initiated. 1742b1b93268SToomas Soome * 1743b1b93268SToomas Soome * Note that this object can be empty if none of the vdev has yet been 1744b1b93268SToomas Soome * copied. 1745b1b93268SToomas Soome */ 1746b1b93268SToomas Soome uint64_t vic_births_object; 1747b1b93268SToomas Soome 1748b1b93268SToomas Soome /* 1749b1b93268SToomas Soome * This is the vdev ID which was removed previous to this vdev, or 1750b1b93268SToomas Soome * UINT64_MAX if there are no previously removed vdevs. 1751b1b93268SToomas Soome */ 1752b1b93268SToomas Soome uint64_t vic_prev_indirect_vdev; 1753b1b93268SToomas Soome } vdev_indirect_config_t; 1754b1b93268SToomas Soome 17551ba4a712SPawel Jakub Dawidek typedef struct vdev { 17561ba4a712SPawel Jakub Dawidek STAILQ_ENTRY(vdev) v_childlink; /* link in parent's child list */ 17571ba4a712SPawel Jakub Dawidek STAILQ_ENTRY(vdev) v_alllink; /* link in global vdev list */ 17581ba4a712SPawel Jakub Dawidek vdev_list_t v_children; /* children of this vdev */ 175910b9d77bSPawel Jakub Dawidek const char *v_name; /* vdev name */ 17601ba4a712SPawel Jakub Dawidek uint64_t v_guid; /* vdev guid */ 1761abca0bd5SToomas Soome uint64_t v_id; /* index in parent */ 1762abca0bd5SToomas Soome uint64_t v_psize; /* physical device capacity */ 1763e1899ef6SDoug Rabson int v_ashift; /* offset to block shift */ 1764e1899ef6SDoug Rabson int v_nparity; /* # parity for raidz */ 176510b9d77bSPawel Jakub Dawidek struct vdev *v_top; /* parent vdev */ 17663c2db0efSToomas Soome size_t v_nchildren; /* # children */ 17671ba4a712SPawel Jakub Dawidek vdev_state_t v_state; /* current state */ 1768e1899ef6SDoug Rabson vdev_phys_read_t *v_phys_read; /* read from raw leaf vdev */ 1769e1899ef6SDoug Rabson vdev_read_t *v_read; /* read from vdev */ 17701ba4a712SPawel Jakub Dawidek void *v_read_priv; /* private data for read function */ 17710c0a882cSToomas Soome boolean_t v_islog; 17723c2db0efSToomas Soome struct spa *v_spa; /* link to spa */ 1773b1b93268SToomas Soome /* 1774b1b93268SToomas Soome * Values stored in the config for an indirect or removing vdev. 1775b1b93268SToomas Soome */ 1776b1b93268SToomas Soome vdev_indirect_config_t vdev_indirect_config; 1777b1b93268SToomas Soome vdev_indirect_mapping_t *v_mapping; 17781ba4a712SPawel Jakub Dawidek } vdev_t; 17791ba4a712SPawel Jakub Dawidek 17801ba4a712SPawel Jakub Dawidek /* 17811ba4a712SPawel Jakub Dawidek * In-core pool representation. 17821ba4a712SPawel Jakub Dawidek */ 17831ba4a712SPawel Jakub Dawidek typedef STAILQ_HEAD(spa_list, spa) spa_list_t; 17841ba4a712SPawel Jakub Dawidek 17851ba4a712SPawel Jakub Dawidek typedef struct spa { 17861ba4a712SPawel Jakub Dawidek STAILQ_ENTRY(spa) spa_link; /* link in global pool list */ 17871ba4a712SPawel Jakub Dawidek char *spa_name; /* pool name */ 17881ba4a712SPawel Jakub Dawidek uint64_t spa_guid; /* pool guid */ 17891ba4a712SPawel Jakub Dawidek uint64_t spa_txg; /* most recent transaction */ 17901ba4a712SPawel Jakub Dawidek struct uberblock spa_uberblock; /* best uberblock so far */ 17913c2db0efSToomas Soome vdev_t *spa_root_vdev; /* toplevel vdev container */ 17921ba4a712SPawel Jakub Dawidek objset_phys_t spa_mos; /* MOS for this pool */ 17932c55d090SToomas Soome zio_cksum_salt_t spa_cksum_salt; /* secret salt for cksum */ 17942c55d090SToomas Soome void *spa_cksum_tmpls[ZIO_CHECKSUM_FUNCTIONS]; 17950c0a882cSToomas Soome boolean_t spa_with_log; /* this pool has log */ 17961ba4a712SPawel Jakub Dawidek } spa_t; 179729441ba3SXin LI 1798b1b93268SToomas Soome /* IO related arguments. */ 1799b1b93268SToomas Soome typedef struct zio { 1800b1b93268SToomas Soome spa_t *io_spa; 1801b1b93268SToomas Soome blkptr_t *io_bp; 1802b1b93268SToomas Soome void *io_data; 1803b1b93268SToomas Soome uint64_t io_size; 1804b1b93268SToomas Soome uint64_t io_offset; 1805b1b93268SToomas Soome 1806b1b93268SToomas Soome /* Stuff for the vdev stack */ 1807b1b93268SToomas Soome vdev_t *io_vd; 1808b1b93268SToomas Soome void *io_vsd; 1809b1b93268SToomas Soome 1810b1b93268SToomas Soome int io_error; 1811b1b93268SToomas Soome } zio_t; 1812b1b93268SToomas Soome 181329441ba3SXin LI static void decode_embedded_bp_compressed(const blkptr_t *, void *); 1814