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