xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/spa.h (revision ce1577b04976f1d8bb5f235b6eaaab15b46a3068)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
223f9d6ad7SLin Ling  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
234ba5b961SDan Kimmel  * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
24e9103aaeSGarrett D'Amore  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
25bc9014e6SJustin Gibbs  * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
2645818ee1SMatthew Ahrens  * Copyright 2013 Saso Kiselkov. All rights reserved.
27c3d26abcSMatthew Ahrens  * Copyright (c) 2014 Integros [integros.com]
28*ce1577b0SDave Eddy  * Copyright 2017 Joyent, Inc.
29fa9e4066Sahrens  */
30fa9e4066Sahrens 
31fa9e4066Sahrens #ifndef _SYS_SPA_H
32fa9e4066Sahrens #define	_SYS_SPA_H
33fa9e4066Sahrens 
34fa9e4066Sahrens #include <sys/avl.h>
35fa9e4066Sahrens #include <sys/zfs_context.h>
36fa9e4066Sahrens #include <sys/nvpair.h>
37fa9e4066Sahrens #include <sys/sysmacros.h>
38fa9e4066Sahrens #include <sys/types.h>
39fa9e4066Sahrens #include <sys/fs/zfs.h>
404ba5b961SDan Kimmel #include <sys/dmu.h>
41fa9e4066Sahrens 
42fa9e4066Sahrens #ifdef	__cplusplus
43fa9e4066Sahrens extern "C" {
44fa9e4066Sahrens #endif
45fa9e4066Sahrens 
46fa9e4066Sahrens /*
47fa9e4066Sahrens  * Forward references that lots of things need.
48fa9e4066Sahrens  */
49fa9e4066Sahrens typedef struct spa spa_t;
50fa9e4066Sahrens typedef struct vdev vdev_t;
51fa9e4066Sahrens typedef struct metaslab metaslab_t;
52b24ab676SJeff Bonwick typedef struct metaslab_group metaslab_group_t;
53b24ab676SJeff Bonwick typedef struct metaslab_class metaslab_class_t;
54b24ab676SJeff Bonwick typedef struct zio zio_t;
55fa9e4066Sahrens typedef struct zilog zilog_t;
56fa94a07fSbrendan typedef struct spa_aux_vdev spa_aux_vdev_t;
57b24ab676SJeff Bonwick typedef struct ddt ddt_t;
58b24ab676SJeff Bonwick typedef struct ddt_entry ddt_entry_t;
59fa9e4066Sahrens struct dsl_pool;
604445fffbSMatthew Ahrens struct dsl_dataset;
61fa9e4066Sahrens 
62fa9e4066Sahrens /*
63fa9e4066Sahrens  * General-purpose 32-bit and 64-bit bitfield encodings.
64fa9e4066Sahrens  */
65fa9e4066Sahrens #define	BF32_DECODE(x, low, len)	P2PHASE((x) >> (low), 1U << (len))
66fa9e4066Sahrens #define	BF64_DECODE(x, low, len)	P2PHASE((x) >> (low), 1ULL << (len))
67fa9e4066Sahrens #define	BF32_ENCODE(x, low, len)	(P2PHASE((x), 1U << (len)) << (low))
68fa9e4066Sahrens #define	BF64_ENCODE(x, low, len)	(P2PHASE((x), 1ULL << (len)) << (low))
69fa9e4066Sahrens 
70fa9e4066Sahrens #define	BF32_GET(x, low, len)		BF32_DECODE(x, low, len)
71fa9e4066Sahrens #define	BF64_GET(x, low, len)		BF64_DECODE(x, low, len)
72fa9e4066Sahrens 
7343466aaeSMax Grossman #define	BF32_SET(x, low, len, val) do { \
7443466aaeSMax Grossman 	ASSERT3U(val, <, 1U << (len)); \
7543466aaeSMax Grossman 	ASSERT3U(low + len, <=, 32); \
7643466aaeSMax Grossman 	(x) ^= BF32_ENCODE((x >> low) ^ (val), low, len); \
7743466aaeSMax Grossman _NOTE(CONSTCOND) } while (0)
7843466aaeSMax Grossman 
7943466aaeSMax Grossman #define	BF64_SET(x, low, len, val) do { \
8043466aaeSMax Grossman 	ASSERT3U(val, <, 1ULL << (len)); \
8143466aaeSMax Grossman 	ASSERT3U(low + len, <=, 64); \
8243466aaeSMax Grossman 	((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len)); \
8343466aaeSMax Grossman _NOTE(CONSTCOND) } while (0)
84fa9e4066Sahrens 
85fa9e4066Sahrens #define	BF32_GET_SB(x, low, len, shift, bias)	\
86fa9e4066Sahrens 	((BF32_GET(x, low, len) + (bias)) << (shift))
87fa9e4066Sahrens #define	BF64_GET_SB(x, low, len, shift, bias)	\
88fa9e4066Sahrens 	((BF64_GET(x, low, len) + (bias)) << (shift))
89fa9e4066Sahrens 
9043466aaeSMax Grossman #define	BF32_SET_SB(x, low, len, shift, bias, val) do { \
9143466aaeSMax Grossman 	ASSERT(IS_P2ALIGNED(val, 1U << shift)); \
9243466aaeSMax Grossman 	ASSERT3S((val) >> (shift), >=, bias); \
9343466aaeSMax Grossman 	BF32_SET(x, low, len, ((val) >> (shift)) - (bias)); \
9443466aaeSMax Grossman _NOTE(CONSTCOND) } while (0)
9543466aaeSMax Grossman #define	BF64_SET_SB(x, low, len, shift, bias, val) do { \
9643466aaeSMax Grossman 	ASSERT(IS_P2ALIGNED(val, 1ULL << shift)); \
9743466aaeSMax Grossman 	ASSERT3S((val) >> (shift), >=, bias); \
9843466aaeSMax Grossman 	BF64_SET(x, low, len, ((val) >> (shift)) - (bias)); \
9943466aaeSMax Grossman _NOTE(CONSTCOND) } while (0)
100fa9e4066Sahrens 
101fa9e4066Sahrens /*
102b5152584SMatthew Ahrens  * We currently support block sizes from 512 bytes to 16MB.
103b5152584SMatthew Ahrens  * The benefits of larger blocks, and thus larger IO, need to be weighed
104b5152584SMatthew Ahrens  * against the cost of COWing a giant block to modify one byte, and the
105b5152584SMatthew Ahrens  * large latency of reading or writing a large block.
106b5152584SMatthew Ahrens  *
107b5152584SMatthew Ahrens  * Note that although blocks up to 16MB are supported, the recordsize
108b5152584SMatthew Ahrens  * property can not be set larger than zfs_max_recordsize (default 1MB).
109b5152584SMatthew Ahrens  * See the comment near zfs_max_recordsize in dsl_dataset.c for details.
110b5152584SMatthew Ahrens  *
111b5152584SMatthew Ahrens  * Note that although the LSIZE field of the blkptr_t can store sizes up
112b5152584SMatthew Ahrens  * to 32MB, the dnode's dn_datablkszsec can only store sizes up to
113b5152584SMatthew Ahrens  * 32MB - 512 bytes.  Therefore, we limit SPA_MAXBLOCKSIZE to 16MB.
114fa9e4066Sahrens  */
115fa9e4066Sahrens #define	SPA_MINBLOCKSHIFT	9
116b5152584SMatthew Ahrens #define	SPA_OLD_MAXBLOCKSHIFT	17
117b5152584SMatthew Ahrens #define	SPA_MAXBLOCKSHIFT	24
118fa9e4066Sahrens #define	SPA_MINBLOCKSIZE	(1ULL << SPA_MINBLOCKSHIFT)
119b5152584SMatthew Ahrens #define	SPA_OLD_MAXBLOCKSIZE	(1ULL << SPA_OLD_MAXBLOCKSHIFT)
120fa9e4066Sahrens #define	SPA_MAXBLOCKSIZE	(1ULL << SPA_MAXBLOCKSHIFT)
121fa9e4066Sahrens 
122f7991ba4STim Haley /*
123f7991ba4STim Haley  * Size of block to hold the configuration data (a packed nvlist)
124f7991ba4STim Haley  */
125ad135b5dSChristopher Siden #define	SPA_CONFIG_BLOCKSIZE	(1ULL << 14)
126f7991ba4STim Haley 
127fa9e4066Sahrens /*
128fa9e4066Sahrens  * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
129fa9e4066Sahrens  * The ASIZE encoding should be at least 64 times larger (6 more bits)
130fa9e4066Sahrens  * to support up to 4-way RAID-Z mirror mode with worst-case gang block
131fa9e4066Sahrens  * overhead, three DVAs per bp, plus one more bit in case we do anything
132fa9e4066Sahrens  * else that expands the ASIZE.
133fa9e4066Sahrens  */
134fa9e4066Sahrens #define	SPA_LSIZEBITS		16	/* LSIZE up to 32M (2^16 * 512)	*/
135fa9e4066Sahrens #define	SPA_PSIZEBITS		16	/* PSIZE up to 32M (2^16 * 512)	*/
136fa9e4066Sahrens #define	SPA_ASIZEBITS		24	/* ASIZE up to 64 times larger	*/
137fa9e4066Sahrens 
138dcbf3bd6SGeorge Wilson #define	SPA_COMPRESSBITS	7
139dcbf3bd6SGeorge Wilson 
140fa9e4066Sahrens /*
141fa9e4066Sahrens  * All SPA data is represented by 128-bit data virtual addresses (DVAs).
142fa9e4066Sahrens  * The members of the dva_t should be considered opaque outside the SPA.
143fa9e4066Sahrens  */
144fa9e4066Sahrens typedef struct dva {
145fa9e4066Sahrens 	uint64_t	dva_word[2];
146fa9e4066Sahrens } dva_t;
147fa9e4066Sahrens 
148fa9e4066Sahrens /*
149fa9e4066Sahrens  * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
150fa9e4066Sahrens  */
151fa9e4066Sahrens typedef struct zio_cksum {
152fa9e4066Sahrens 	uint64_t	zc_word[4];
153fa9e4066Sahrens } zio_cksum_t;
154fa9e4066Sahrens 
15545818ee1SMatthew Ahrens /*
15645818ee1SMatthew Ahrens  * Some checksums/hashes need a 256-bit initialization salt. This salt is kept
15745818ee1SMatthew Ahrens  * secret and is suitable for use in MAC algorithms as the key.
15845818ee1SMatthew Ahrens  */
15945818ee1SMatthew Ahrens typedef struct zio_cksum_salt {
16045818ee1SMatthew Ahrens 	uint8_t		zcs_bytes[32];
16145818ee1SMatthew Ahrens } zio_cksum_salt_t;
16245818ee1SMatthew Ahrens 
163fa9e4066Sahrens /*
164fa9e4066Sahrens  * Each block is described by its DVAs, time of birth, checksum, etc.
165fa9e4066Sahrens  * The word-by-word, bit-by-bit layout of the blkptr is as follows:
166fa9e4066Sahrens  *
167fa9e4066Sahrens  *	64	56	48	40	32	24	16	8	0
168fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
169fa9e4066Sahrens  * 0	|		vdev1		| GRID  |	  ASIZE		|
170fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
171fa9e4066Sahrens  * 1	|G|			 offset1				|
172fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
173fa9e4066Sahrens  * 2	|		vdev2		| GRID  |	  ASIZE		|
174fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
175fa9e4066Sahrens  * 3	|G|			 offset2				|
176fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
177fa9e4066Sahrens  * 4	|		vdev3		| GRID  |	  ASIZE		|
178fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
179fa9e4066Sahrens  * 5	|G|			 offset3				|
180fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
1815d7b4d43SMatthew Ahrens  * 6	|BDX|lvl| type	| cksum |E| comp|    PSIZE	|     LSIZE	|
182fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
183fa9e4066Sahrens  * 7	|			padding					|
184fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
185fa9e4066Sahrens  * 8	|			padding					|
186fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
187b24ab676SJeff Bonwick  * 9	|			physical birth txg			|
188fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
189b24ab676SJeff Bonwick  * a	|			logical birth txg			|
190fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
191fa9e4066Sahrens  * b	|			fill count				|
192fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
193fa9e4066Sahrens  * c	|			checksum[0]				|
194fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
195fa9e4066Sahrens  * d	|			checksum[1]				|
196fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
197fa9e4066Sahrens  * e	|			checksum[2]				|
198fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
199fa9e4066Sahrens  * f	|			checksum[3]				|
200fa9e4066Sahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
201fa9e4066Sahrens  *
202fa9e4066Sahrens  * Legend:
203fa9e4066Sahrens  *
204fa9e4066Sahrens  * vdev		virtual device ID
205fa9e4066Sahrens  * offset	offset into virtual device
206fa9e4066Sahrens  * LSIZE	logical size
207fa9e4066Sahrens  * PSIZE	physical size (after compression)
208fa9e4066Sahrens  * ASIZE	allocated size (including RAID-Z parity and gang block headers)
209fa9e4066Sahrens  * GRID		RAID-Z layout information (reserved for future use)
210fa9e4066Sahrens  * cksum	checksum function
211fa9e4066Sahrens  * comp		compression function
212fa9e4066Sahrens  * G		gang block indicator
213b24ab676SJeff Bonwick  * B		byteorder (endianness)
214b24ab676SJeff Bonwick  * D		dedup
2155d7b4d43SMatthew Ahrens  * X		encryption (on version 30, which is not supported)
2165d7b4d43SMatthew Ahrens  * E		blkptr_t contains embedded data (see below)
217fa9e4066Sahrens  * lvl		level of indirection
218b24ab676SJeff Bonwick  * type		DMU object type
219b24ab676SJeff Bonwick  * phys birth	txg of block allocation; zero if same as logical birth txg
220b24ab676SJeff Bonwick  * log. birth	transaction group in which the block was logically born
221fa9e4066Sahrens  * fill count	number of non-zero blocks under this bp
222fa9e4066Sahrens  * checksum[4]	256-bit checksum of the data this bp describes
223fa9e4066Sahrens  */
2245d7b4d43SMatthew Ahrens 
2255d7b4d43SMatthew Ahrens /*
2265d7b4d43SMatthew Ahrens  * "Embedded" blkptr_t's don't actually point to a block, instead they
2275d7b4d43SMatthew Ahrens  * have a data payload embedded in the blkptr_t itself.  See the comment
2285d7b4d43SMatthew Ahrens  * in blkptr.c for more details.
2295d7b4d43SMatthew Ahrens  *
2305d7b4d43SMatthew Ahrens  * The blkptr_t is laid out as follows:
2315d7b4d43SMatthew Ahrens  *
2325d7b4d43SMatthew Ahrens  *	64	56	48	40	32	24	16	8	0
2335d7b4d43SMatthew Ahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
2345d7b4d43SMatthew Ahrens  * 0	|      payload                                                  |
2355d7b4d43SMatthew Ahrens  * 1	|      payload                                                  |
2365d7b4d43SMatthew Ahrens  * 2	|      payload                                                  |
2375d7b4d43SMatthew Ahrens  * 3	|      payload                                                  |
2385d7b4d43SMatthew Ahrens  * 4	|      payload                                                  |
2395d7b4d43SMatthew Ahrens  * 5	|      payload                                                  |
2405d7b4d43SMatthew Ahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
2415d7b4d43SMatthew Ahrens  * 6	|BDX|lvl| type	| etype |E| comp| PSIZE|              LSIZE	|
2425d7b4d43SMatthew Ahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
2435d7b4d43SMatthew Ahrens  * 7	|      payload                                                  |
2445d7b4d43SMatthew Ahrens  * 8	|      payload                                                  |
2455d7b4d43SMatthew Ahrens  * 9	|      payload                                                  |
2465d7b4d43SMatthew Ahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
2475d7b4d43SMatthew Ahrens  * a	|			logical birth txg			|
2485d7b4d43SMatthew Ahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
2495d7b4d43SMatthew Ahrens  * b	|      payload                                                  |
2505d7b4d43SMatthew Ahrens  * c	|      payload                                                  |
2515d7b4d43SMatthew Ahrens  * d	|      payload                                                  |
2525d7b4d43SMatthew Ahrens  * e	|      payload                                                  |
2535d7b4d43SMatthew Ahrens  * f	|      payload                                                  |
2545d7b4d43SMatthew Ahrens  *	+-------+-------+-------+-------+-------+-------+-------+-------+
2555d7b4d43SMatthew Ahrens  *
2565d7b4d43SMatthew Ahrens  * Legend:
2575d7b4d43SMatthew Ahrens  *
2585d7b4d43SMatthew Ahrens  * payload		contains the embedded data
2595d7b4d43SMatthew Ahrens  * B (byteorder)	byteorder (endianness)
2605d7b4d43SMatthew Ahrens  * D (dedup)		padding (set to zero)
2615d7b4d43SMatthew Ahrens  * X			encryption (set to zero; see above)
2625d7b4d43SMatthew Ahrens  * E (embedded)		set to one
2635d7b4d43SMatthew Ahrens  * lvl			indirection level
2645d7b4d43SMatthew Ahrens  * type			DMU object type
2655d7b4d43SMatthew Ahrens  * etype		how to interpret embedded data (BP_EMBEDDED_TYPE_*)
2665d7b4d43SMatthew Ahrens  * comp			compression function of payload
2675d7b4d43SMatthew Ahrens  * PSIZE		size of payload after compression, in bytes
2685d7b4d43SMatthew Ahrens  * LSIZE		logical size of payload, in bytes
2695d7b4d43SMatthew Ahrens  *			note that 25 bits is enough to store the largest
2705d7b4d43SMatthew Ahrens  *			"normal" BP's LSIZE (2^16 * 2^9) in bytes
2715d7b4d43SMatthew Ahrens  * log. birth		transaction group in which the block was logically born
2725d7b4d43SMatthew Ahrens  *
2735d7b4d43SMatthew Ahrens  * Note that LSIZE and PSIZE are stored in bytes, whereas for non-embedded
2745d7b4d43SMatthew Ahrens  * bp's they are stored in units of SPA_MINBLOCKSHIFT.
2755d7b4d43SMatthew Ahrens  * Generally, the generic BP_GET_*() macros can be used on embedded BP's.
2765d7b4d43SMatthew Ahrens  * The B, D, X, lvl, type, and comp fields are stored the same as with normal
2775d7b4d43SMatthew Ahrens  * BP's so the BP_SET_* macros can be used with them.  etype, PSIZE, LSIZE must
2785d7b4d43SMatthew Ahrens  * be set with the BPE_SET_* macros.  BP_SET_EMBEDDED() should be called before
2795d7b4d43SMatthew Ahrens  * other macros, as they assert that they are only used on BP's of the correct
2805d7b4d43SMatthew Ahrens  * "embedded-ness".
2815d7b4d43SMatthew Ahrens  */
2825d7b4d43SMatthew Ahrens 
2835d7b4d43SMatthew Ahrens #define	BPE_GET_ETYPE(bp)	\
2845d7b4d43SMatthew Ahrens 	(ASSERT(BP_IS_EMBEDDED(bp)), \
2855d7b4d43SMatthew Ahrens 	BF64_GET((bp)->blk_prop, 40, 8))
2865d7b4d43SMatthew Ahrens #define	BPE_SET_ETYPE(bp, t)	do { \
2875d7b4d43SMatthew Ahrens 	ASSERT(BP_IS_EMBEDDED(bp)); \
2885d7b4d43SMatthew Ahrens 	BF64_SET((bp)->blk_prop, 40, 8, t); \
2895d7b4d43SMatthew Ahrens _NOTE(CONSTCOND) } while (0)
2905d7b4d43SMatthew Ahrens 
2915d7b4d43SMatthew Ahrens #define	BPE_GET_LSIZE(bp)	\
2925d7b4d43SMatthew Ahrens 	(ASSERT(BP_IS_EMBEDDED(bp)), \
2935d7b4d43SMatthew Ahrens 	BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1))
2945d7b4d43SMatthew Ahrens #define	BPE_SET_LSIZE(bp, x)	do { \
2955d7b4d43SMatthew Ahrens 	ASSERT(BP_IS_EMBEDDED(bp)); \
2965d7b4d43SMatthew Ahrens 	BF64_SET_SB((bp)->blk_prop, 0, 25, 0, 1, x); \
2975d7b4d43SMatthew Ahrens _NOTE(CONSTCOND) } while (0)
2985d7b4d43SMatthew Ahrens 
2995d7b4d43SMatthew Ahrens #define	BPE_GET_PSIZE(bp)	\
3005d7b4d43SMatthew Ahrens 	(ASSERT(BP_IS_EMBEDDED(bp)), \
3015d7b4d43SMatthew Ahrens 	BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1))
3025d7b4d43SMatthew Ahrens #define	BPE_SET_PSIZE(bp, x)	do { \
3035d7b4d43SMatthew Ahrens 	ASSERT(BP_IS_EMBEDDED(bp)); \
3045d7b4d43SMatthew Ahrens 	BF64_SET_SB((bp)->blk_prop, 25, 7, 0, 1, x); \
3055d7b4d43SMatthew Ahrens _NOTE(CONSTCOND) } while (0)
3065d7b4d43SMatthew Ahrens 
3075d7b4d43SMatthew Ahrens typedef enum bp_embedded_type {
3085d7b4d43SMatthew Ahrens 	BP_EMBEDDED_TYPE_DATA,
3095d7b4d43SMatthew Ahrens 	BP_EMBEDDED_TYPE_RESERVED, /* Reserved for an unintegrated feature. */
3105d7b4d43SMatthew Ahrens 	NUM_BP_EMBEDDED_TYPES = BP_EMBEDDED_TYPE_RESERVED
3115d7b4d43SMatthew Ahrens } bp_embedded_type_t;
3125d7b4d43SMatthew Ahrens 
3135d7b4d43SMatthew Ahrens #define	BPE_NUM_WORDS 14
3145d7b4d43SMatthew Ahrens #define	BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t))
3155d7b4d43SMatthew Ahrens #define	BPE_IS_PAYLOADWORD(bp, wp) \
3165d7b4d43SMatthew Ahrens 	((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth)
3175d7b4d43SMatthew Ahrens 
318fa9e4066Sahrens #define	SPA_BLKPTRSHIFT	7		/* blkptr_t is 128 bytes	*/
319fa9e4066Sahrens #define	SPA_DVAS_PER_BP	3		/* Number of DVAs in a bp	*/
320fa9e4066Sahrens 
32143466aaeSMax Grossman /*
32243466aaeSMax Grossman  * A block is a hole when it has either 1) never been written to, or
32343466aaeSMax Grossman  * 2) is zero-filled. In both cases, ZFS can return all zeroes for all reads
32443466aaeSMax Grossman  * without physically allocating disk space. Holes are represented in the
32543466aaeSMax Grossman  * blkptr_t structure by zeroed blk_dva. Correct checking for holes is
32643466aaeSMax Grossman  * done through the BP_IS_HOLE macro. For holes, the logical size, level,
32743466aaeSMax Grossman  * DMU object type, and birth times are all also stored for holes that
32843466aaeSMax Grossman  * were written to at some point (i.e. were punched after having been filled).
32943466aaeSMax Grossman  */
330b24ab676SJeff Bonwick typedef struct blkptr {
331b24ab676SJeff Bonwick 	dva_t		blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */
332b24ab676SJeff Bonwick 	uint64_t	blk_prop;	/* size, compression, type, etc	    */
333b24ab676SJeff Bonwick 	uint64_t	blk_pad[2];	/* Extra space for the future	    */
334b24ab676SJeff Bonwick 	uint64_t	blk_phys_birth;	/* txg when block was allocated	    */
335b24ab676SJeff Bonwick 	uint64_t	blk_birth;	/* transaction group at birth	    */
336b24ab676SJeff Bonwick 	uint64_t	blk_fill;	/* fill count			    */
337b24ab676SJeff Bonwick 	zio_cksum_t	blk_cksum;	/* 256-bit checksum		    */
338b24ab676SJeff Bonwick } blkptr_t;
339b24ab676SJeff Bonwick 
340fa9e4066Sahrens /*
341fa9e4066Sahrens  * Macros to get and set fields in a bp or DVA.
342fa9e4066Sahrens  */
343fa9e4066Sahrens #define	DVA_GET_ASIZE(dva)	\
34443466aaeSMax Grossman 	BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0)
345fa9e4066Sahrens #define	DVA_SET_ASIZE(dva, x)	\
34643466aaeSMax Grossman 	BF64_SET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, \
34743466aaeSMax Grossman 	SPA_MINBLOCKSHIFT, 0, x)
348fa9e4066Sahrens 
349fa9e4066Sahrens #define	DVA_GET_GRID(dva)	BF64_GET((dva)->dva_word[0], 24, 8)
350fa9e4066Sahrens #define	DVA_SET_GRID(dva, x)	BF64_SET((dva)->dva_word[0], 24, 8, x)
351fa9e4066Sahrens 
352fa9e4066Sahrens #define	DVA_GET_VDEV(dva)	BF64_GET((dva)->dva_word[0], 32, 32)
353fa9e4066Sahrens #define	DVA_SET_VDEV(dva, x)	BF64_SET((dva)->dva_word[0], 32, 32, x)
354fa9e4066Sahrens 
355fa9e4066Sahrens #define	DVA_GET_OFFSET(dva)	\
356fa9e4066Sahrens 	BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0)
357fa9e4066Sahrens #define	DVA_SET_OFFSET(dva, x)	\
358fa9e4066Sahrens 	BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x)
359fa9e4066Sahrens 
360fa9e4066Sahrens #define	DVA_GET_GANG(dva)	BF64_GET((dva)->dva_word[1], 63, 1)
361fa9e4066Sahrens #define	DVA_SET_GANG(dva, x)	BF64_SET((dva)->dva_word[1], 63, 1, x)
362fa9e4066Sahrens 
363fa9e4066Sahrens #define	BP_GET_LSIZE(bp)	\
3645d7b4d43SMatthew Ahrens 	(BP_IS_EMBEDDED(bp) ?	\
3655d7b4d43SMatthew Ahrens 	(BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA ? BPE_GET_LSIZE(bp) : 0): \
3665d7b4d43SMatthew Ahrens 	BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1))
3675d7b4d43SMatthew Ahrens #define	BP_SET_LSIZE(bp, x)	do { \
3685d7b4d43SMatthew Ahrens 	ASSERT(!BP_IS_EMBEDDED(bp)); \
3695d7b4d43SMatthew Ahrens 	BF64_SET_SB((bp)->blk_prop, \
3705d7b4d43SMatthew Ahrens 	    0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \
3715d7b4d43SMatthew Ahrens _NOTE(CONSTCOND) } while (0)
372fa9e4066Sahrens 
373fa9e4066Sahrens #define	BP_GET_PSIZE(bp)	\
3745d7b4d43SMatthew Ahrens 	(BP_IS_EMBEDDED(bp) ? 0 : \
3755d7b4d43SMatthew Ahrens 	BF64_GET_SB((bp)->blk_prop, 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1))
3765d7b4d43SMatthew Ahrens #define	BP_SET_PSIZE(bp, x)	do { \
3775d7b4d43SMatthew Ahrens 	ASSERT(!BP_IS_EMBEDDED(bp)); \
3785d7b4d43SMatthew Ahrens 	BF64_SET_SB((bp)->blk_prop, \
3795d7b4d43SMatthew Ahrens 	    16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \
3805d7b4d43SMatthew Ahrens _NOTE(CONSTCOND) } while (0)
3815d7b4d43SMatthew Ahrens 
382dcbf3bd6SGeorge Wilson #define	BP_GET_COMPRESS(bp)		\
383dcbf3bd6SGeorge Wilson 	BF64_GET((bp)->blk_prop, 32, SPA_COMPRESSBITS)
384dcbf3bd6SGeorge Wilson #define	BP_SET_COMPRESS(bp, x)		\
385dcbf3bd6SGeorge Wilson 	BF64_SET((bp)->blk_prop, 32, SPA_COMPRESSBITS, x)
386fa9e4066Sahrens 
3875d7b4d43SMatthew Ahrens #define	BP_IS_EMBEDDED(bp)		BF64_GET((bp)->blk_prop, 39, 1)
3885d7b4d43SMatthew Ahrens #define	BP_SET_EMBEDDED(bp, x)		BF64_SET((bp)->blk_prop, 39, 1, x)
389b24ab676SJeff Bonwick 
3905d7b4d43SMatthew Ahrens #define	BP_GET_CHECKSUM(bp)		\
3915d7b4d43SMatthew Ahrens 	(BP_IS_EMBEDDED(bp) ? ZIO_CHECKSUM_OFF : \
3925d7b4d43SMatthew Ahrens 	BF64_GET((bp)->blk_prop, 40, 8))
3935d7b4d43SMatthew Ahrens #define	BP_SET_CHECKSUM(bp, x)		do { \
3945d7b4d43SMatthew Ahrens 	ASSERT(!BP_IS_EMBEDDED(bp)); \
3955d7b4d43SMatthew Ahrens 	BF64_SET((bp)->blk_prop, 40, 8, x); \
3965d7b4d43SMatthew Ahrens _NOTE(CONSTCOND) } while (0)
397b24ab676SJeff Bonwick 
398b24ab676SJeff Bonwick #define	BP_GET_TYPE(bp)			BF64_GET((bp)->blk_prop, 48, 8)
399b24ab676SJeff Bonwick #define	BP_SET_TYPE(bp, x)		BF64_SET((bp)->blk_prop, 48, 8, x)
400fa9e4066Sahrens 
401b24ab676SJeff Bonwick #define	BP_GET_LEVEL(bp)		BF64_GET((bp)->blk_prop, 56, 5)
402b24ab676SJeff Bonwick #define	BP_SET_LEVEL(bp, x)		BF64_SET((bp)->blk_prop, 56, 5, x)
403fa9e4066Sahrens 
404b24ab676SJeff Bonwick #define	BP_GET_DEDUP(bp)		BF64_GET((bp)->blk_prop, 62, 1)
405b24ab676SJeff Bonwick #define	BP_SET_DEDUP(bp, x)		BF64_SET((bp)->blk_prop, 62, 1, x)
406fa9e4066Sahrens 
40743466aaeSMax Grossman #define	BP_GET_BYTEORDER(bp)		BF64_GET((bp)->blk_prop, 63, 1)
408b24ab676SJeff Bonwick #define	BP_SET_BYTEORDER(bp, x)		BF64_SET((bp)->blk_prop, 63, 1, x)
409b24ab676SJeff Bonwick 
410b24ab676SJeff Bonwick #define	BP_PHYSICAL_BIRTH(bp)		\
4115d7b4d43SMatthew Ahrens 	(BP_IS_EMBEDDED(bp) ? 0 : \
4125d7b4d43SMatthew Ahrens 	(bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)
413b24ab676SJeff Bonwick 
414b24ab676SJeff Bonwick #define	BP_SET_BIRTH(bp, logical, physical)	\
415b24ab676SJeff Bonwick {						\
4165d7b4d43SMatthew Ahrens 	ASSERT(!BP_IS_EMBEDDED(bp));		\
417b24ab676SJeff Bonwick 	(bp)->blk_birth = (logical);		\
418b24ab676SJeff Bonwick 	(bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \
419b24ab676SJeff Bonwick }
420fa9e4066Sahrens 
4215d7b4d43SMatthew Ahrens #define	BP_GET_FILL(bp) (BP_IS_EMBEDDED(bp) ? 1 : (bp)->blk_fill)
4225d7b4d43SMatthew Ahrens 
423770499e1SDan Kimmel #define	BP_IS_METADATA(bp)	\
424770499e1SDan Kimmel 	(BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp)))
425770499e1SDan Kimmel 
426fa9e4066Sahrens #define	BP_GET_ASIZE(bp)	\
4275d7b4d43SMatthew Ahrens 	(BP_IS_EMBEDDED(bp) ? 0 : \
4285d7b4d43SMatthew Ahrens 	DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
4295d7b4d43SMatthew Ahrens 	DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
4305d7b4d43SMatthew Ahrens 	DVA_GET_ASIZE(&(bp)->blk_dva[2]))
43199653d4eSeschrock 
432770499e1SDan Kimmel #define	BP_GET_UCSIZE(bp)	\
433770499e1SDan Kimmel 	(BP_IS_METADATA(bp) ? BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp))
434fa9e4066Sahrens 
43544cd46caSbillm #define	BP_GET_NDVAS(bp)	\
4365d7b4d43SMatthew Ahrens 	(BP_IS_EMBEDDED(bp) ? 0 : \
4375d7b4d43SMatthew Ahrens 	!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
43844cd46caSbillm 	!!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
43944cd46caSbillm 	!!DVA_GET_ASIZE(&(bp)->blk_dva[2]))
44044cd46caSbillm 
44144cd46caSbillm #define	BP_COUNT_GANG(bp)	\
4425d7b4d43SMatthew Ahrens 	(BP_IS_EMBEDDED(bp) ? 0 : \
44344cd46caSbillm 	(DVA_GET_GANG(&(bp)->blk_dva[0]) + \
44444cd46caSbillm 	DVA_GET_GANG(&(bp)->blk_dva[1]) + \
4455d7b4d43SMatthew Ahrens 	DVA_GET_GANG(&(bp)->blk_dva[2])))
44644cd46caSbillm 
447fa9e4066Sahrens #define	DVA_EQUAL(dva1, dva2)	\
448fa9e4066Sahrens 	((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
449fa9e4066Sahrens 	(dva1)->dva_word[0] == (dva2)->dva_word[0])
450fa9e4066Sahrens 
451b24ab676SJeff Bonwick #define	BP_EQUAL(bp1, bp2)	\
452b24ab676SJeff Bonwick 	(BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) &&	\
4535d7b4d43SMatthew Ahrens 	(bp1)->blk_birth == (bp2)->blk_birth &&			\
454b24ab676SJeff Bonwick 	DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) &&	\
455b24ab676SJeff Bonwick 	DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) &&	\
456b24ab676SJeff Bonwick 	DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2]))
457b24ab676SJeff Bonwick 
4586b4acc8bSahrens #define	ZIO_CHECKSUM_EQUAL(zc1, zc2) \
4596b4acc8bSahrens 	(0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
4606b4acc8bSahrens 	((zc1).zc_word[1] - (zc2).zc_word[1]) | \
4616b4acc8bSahrens 	((zc1).zc_word[2] - (zc2).zc_word[2]) | \
4626b4acc8bSahrens 	((zc1).zc_word[3] - (zc2).zc_word[3])))
4636b4acc8bSahrens 
46498110f08SMatthew Ahrens #define	ZIO_CHECKSUM_IS_ZERO(zc) \
46598110f08SMatthew Ahrens 	(0 == ((zc)->zc_word[0] | (zc)->zc_word[1] | \
46698110f08SMatthew Ahrens 	(zc)->zc_word[2] | (zc)->zc_word[3]))
46798110f08SMatthew Ahrens 
46898110f08SMatthew Ahrens #define	ZIO_CHECKSUM_BSWAP(zcp)					\
46998110f08SMatthew Ahrens {								\
47098110f08SMatthew Ahrens 	(zcp)->zc_word[0] = BSWAP_64((zcp)->zc_word[0]);	\
47198110f08SMatthew Ahrens 	(zcp)->zc_word[1] = BSWAP_64((zcp)->zc_word[1]);	\
47298110f08SMatthew Ahrens 	(zcp)->zc_word[2] = BSWAP_64((zcp)->zc_word[2]);	\
47398110f08SMatthew Ahrens 	(zcp)->zc_word[3] = BSWAP_64((zcp)->zc_word[3]);	\
47498110f08SMatthew Ahrens }
47598110f08SMatthew Ahrens 
47698110f08SMatthew Ahrens 
477fa9e4066Sahrens #define	DVA_IS_VALID(dva)	(DVA_GET_ASIZE(dva) != 0)
478fa9e4066Sahrens 
479fa9e4066Sahrens #define	ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3)	\
480fa9e4066Sahrens {						\
481fa9e4066Sahrens 	(zcp)->zc_word[0] = w0;			\
482fa9e4066Sahrens 	(zcp)->zc_word[1] = w1;			\
483fa9e4066Sahrens 	(zcp)->zc_word[2] = w2;			\
484fa9e4066Sahrens 	(zcp)->zc_word[3] = w3;			\
485fa9e4066Sahrens }
486fa9e4066Sahrens 
4875d7b4d43SMatthew Ahrens #define	BP_IDENTITY(bp)		(ASSERT(!BP_IS_EMBEDDED(bp)), &(bp)->blk_dva[0])
4885d7b4d43SMatthew Ahrens #define	BP_IS_GANG(bp)		\
4895d7b4d43SMatthew Ahrens 	(BP_IS_EMBEDDED(bp) ? B_FALSE : DVA_GET_GANG(BP_IDENTITY(bp)))
49043466aaeSMax Grossman #define	DVA_IS_EMPTY(dva)	((dva)->dva_word[0] == 0ULL &&	\
49143466aaeSMax Grossman 				(dva)->dva_word[1] == 0ULL)
4925d7b4d43SMatthew Ahrens #define	BP_IS_HOLE(bp) \
4935d7b4d43SMatthew Ahrens 	(!BP_IS_EMBEDDED(bp) && DVA_IS_EMPTY(BP_IDENTITY(bp)))
494fa9e4066Sahrens 
4956e1f5caaSNeil Perrin /* BP_IS_RAIDZ(bp) assumes no block compression */
4966e1f5caaSNeil Perrin #define	BP_IS_RAIDZ(bp)		(DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \
4976e1f5caaSNeil Perrin 				BP_GET_PSIZE(bp))
4986e1f5caaSNeil Perrin 
499e14bb325SJeff Bonwick #define	BP_ZERO(bp)				\
500fa9e4066Sahrens {						\
501fa9e4066Sahrens 	(bp)->blk_dva[0].dva_word[0] = 0;	\
502fa9e4066Sahrens 	(bp)->blk_dva[0].dva_word[1] = 0;	\
503fa9e4066Sahrens 	(bp)->blk_dva[1].dva_word[0] = 0;	\
504fa9e4066Sahrens 	(bp)->blk_dva[1].dva_word[1] = 0;	\
505fa9e4066Sahrens 	(bp)->blk_dva[2].dva_word[0] = 0;	\
506fa9e4066Sahrens 	(bp)->blk_dva[2].dva_word[1] = 0;	\
507fa9e4066Sahrens 	(bp)->blk_prop = 0;			\
508fa9e4066Sahrens 	(bp)->blk_pad[0] = 0;			\
509fa9e4066Sahrens 	(bp)->blk_pad[1] = 0;			\
510b24ab676SJeff Bonwick 	(bp)->blk_phys_birth = 0;		\
511e14bb325SJeff Bonwick 	(bp)->blk_birth = 0;			\
512fa9e4066Sahrens 	(bp)->blk_fill = 0;			\
513fa9e4066Sahrens 	ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0);	\
514fa9e4066Sahrens }
515fa9e4066Sahrens 
516fa9e4066Sahrens #ifdef _BIG_ENDIAN
517fa9e4066Sahrens #define	ZFS_HOST_BYTEORDER	(0ULL)
518fa9e4066Sahrens #else
51943466aaeSMax Grossman #define	ZFS_HOST_BYTEORDER	(1ULL)
520fa9e4066Sahrens #endif
521fa9e4066Sahrens 
522fa9e4066Sahrens #define	BP_SHOULD_BYTESWAP(bp)	(BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER)
523fa9e4066Sahrens 
52444cd46caSbillm #define	BP_SPRINTF_LEN	320
525fbabab8fSmaybee 
526b24ab676SJeff Bonwick /*
527b24ab676SJeff Bonwick  * This macro allows code sharing between zfs, libzpool, and mdb.
528b24ab676SJeff Bonwick  * 'func' is either snprintf() or mdb_snprintf().
529b24ab676SJeff Bonwick  * 'ws' (whitespace) can be ' ' for single-line format, '\n' for multi-line.
530b24ab676SJeff Bonwick  */
53143466aaeSMax Grossman #define	SNPRINTF_BLKPTR(func, ws, buf, size, bp, type, checksum, compress) \
532b24ab676SJeff Bonwick {									\
533b24ab676SJeff Bonwick 	static const char *copyname[] =					\
534b24ab676SJeff Bonwick 	    { "zero", "single", "double", "triple" };			\
535b24ab676SJeff Bonwick 	int len = 0;							\
536b24ab676SJeff Bonwick 	int copies = 0;							\
537b24ab676SJeff Bonwick 									\
538b24ab676SJeff Bonwick 	if (bp == NULL) {						\
53943466aaeSMax Grossman 		len += func(buf + len, size - len, "<NULL>");		\
540b24ab676SJeff Bonwick 	} else if (BP_IS_HOLE(bp)) {					\
54170163ac5SPrakash Surya 		len += func(buf + len, size - len,			\
54270163ac5SPrakash Surya 		    "HOLE [L%llu %s] "					\
54370163ac5SPrakash Surya 		    "size=%llxL birth=%lluL",				\
54470163ac5SPrakash Surya 		    (u_longlong_t)BP_GET_LEVEL(bp),			\
54570163ac5SPrakash Surya 		    type,						\
54670163ac5SPrakash Surya 		    (u_longlong_t)BP_GET_LSIZE(bp),			\
54770163ac5SPrakash Surya 		    (u_longlong_t)bp->blk_birth);			\
5485d7b4d43SMatthew Ahrens 	} else if (BP_IS_EMBEDDED(bp)) {				\
5495d7b4d43SMatthew Ahrens 		len = func(buf + len, size - len,			\
5505d7b4d43SMatthew Ahrens 		    "EMBEDDED [L%llu %s] et=%u %s "			\
5515d7b4d43SMatthew Ahrens 		    "size=%llxL/%llxP birth=%lluL",			\
5525d7b4d43SMatthew Ahrens 		    (u_longlong_t)BP_GET_LEVEL(bp),			\
5535d7b4d43SMatthew Ahrens 		    type,						\
5545d7b4d43SMatthew Ahrens 		    (int)BPE_GET_ETYPE(bp),				\
5555d7b4d43SMatthew Ahrens 		    compress,						\
5565d7b4d43SMatthew Ahrens 		    (u_longlong_t)BPE_GET_LSIZE(bp),			\
5575d7b4d43SMatthew Ahrens 		    (u_longlong_t)BPE_GET_PSIZE(bp),			\
5585d7b4d43SMatthew Ahrens 		    (u_longlong_t)bp->blk_birth);			\
559b24ab676SJeff Bonwick 	} else {							\
560b24ab676SJeff Bonwick 		for (int d = 0; d < BP_GET_NDVAS(bp); d++) {		\
561b24ab676SJeff Bonwick 			const dva_t *dva = &bp->blk_dva[d];		\
562b24ab676SJeff Bonwick 			if (DVA_IS_VALID(dva))				\
563b24ab676SJeff Bonwick 				copies++;				\
564b24ab676SJeff Bonwick 			len += func(buf + len, size - len,		\
565b24ab676SJeff Bonwick 			    "DVA[%d]=<%llu:%llx:%llx>%c", d,		\
566b24ab676SJeff Bonwick 			    (u_longlong_t)DVA_GET_VDEV(dva),		\
567b24ab676SJeff Bonwick 			    (u_longlong_t)DVA_GET_OFFSET(dva),		\
568b24ab676SJeff Bonwick 			    (u_longlong_t)DVA_GET_ASIZE(dva),		\
569b24ab676SJeff Bonwick 			    ws);					\
570b24ab676SJeff Bonwick 		}							\
571b24ab676SJeff Bonwick 		if (BP_IS_GANG(bp) &&					\
572b24ab676SJeff Bonwick 		    DVA_GET_ASIZE(&bp->blk_dva[2]) <=			\
573b24ab676SJeff Bonwick 		    DVA_GET_ASIZE(&bp->blk_dva[1]) / 2)			\
574b24ab676SJeff Bonwick 			copies--;					\
575b24ab676SJeff Bonwick 		len += func(buf + len, size - len,			\
576b24ab676SJeff Bonwick 		    "[L%llu %s] %s %s %s %s %s %s%c"			\
577b24ab676SJeff Bonwick 		    "size=%llxL/%llxP birth=%lluL/%lluP fill=%llu%c"	\
578b24ab676SJeff Bonwick 		    "cksum=%llx:%llx:%llx:%llx",			\
579b24ab676SJeff Bonwick 		    (u_longlong_t)BP_GET_LEVEL(bp),			\
580b24ab676SJeff Bonwick 		    type,						\
581b24ab676SJeff Bonwick 		    checksum,						\
582b24ab676SJeff Bonwick 		    compress,						\
583b24ab676SJeff Bonwick 		    BP_GET_BYTEORDER(bp) == 0 ? "BE" : "LE",		\
584b24ab676SJeff Bonwick 		    BP_IS_GANG(bp) ? "gang" : "contiguous",		\
585b24ab676SJeff Bonwick 		    BP_GET_DEDUP(bp) ? "dedup" : "unique",		\
586b24ab676SJeff Bonwick 		    copyname[copies],					\
587b24ab676SJeff Bonwick 		    ws,							\
588b24ab676SJeff Bonwick 		    (u_longlong_t)BP_GET_LSIZE(bp),			\
589b24ab676SJeff Bonwick 		    (u_longlong_t)BP_GET_PSIZE(bp),			\
590b24ab676SJeff Bonwick 		    (u_longlong_t)bp->blk_birth,			\
591b24ab676SJeff Bonwick 		    (u_longlong_t)BP_PHYSICAL_BIRTH(bp),		\
5925d7b4d43SMatthew Ahrens 		    (u_longlong_t)BP_GET_FILL(bp),			\
593b24ab676SJeff Bonwick 		    ws,							\
594b24ab676SJeff Bonwick 		    (u_longlong_t)bp->blk_cksum.zc_word[0],		\
595b24ab676SJeff Bonwick 		    (u_longlong_t)bp->blk_cksum.zc_word[1],		\
596b24ab676SJeff Bonwick 		    (u_longlong_t)bp->blk_cksum.zc_word[2],		\
597b24ab676SJeff Bonwick 		    (u_longlong_t)bp->blk_cksum.zc_word[3]);		\
598b24ab676SJeff Bonwick 	}								\
599b24ab676SJeff Bonwick 	ASSERT(len < size);						\
600b24ab676SJeff Bonwick }
601b24ab676SJeff Bonwick 
602ad23a2dbSjohansen #define	BP_GET_BUFC_TYPE(bp)						\
603770499e1SDan Kimmel 	(BP_IS_METADATA(bp) ? ARC_BUFC_METADATA : ARC_BUFC_DATA)
604fa9e4066Sahrens 
6051195e687SMark J Musante typedef enum spa_import_type {
6061195e687SMark J Musante 	SPA_IMPORT_EXISTING,
6071195e687SMark J Musante 	SPA_IMPORT_ASSEMBLE
6081195e687SMark J Musante } spa_import_type_t;
6091195e687SMark J Musante 
610fa9e4066Sahrens /* state manipulation functions */
611fa9e4066Sahrens extern int spa_open(const char *pool, spa_t **, void *tag);
612468c413aSTim Haley extern int spa_open_rewind(const char *pool, spa_t **, void *tag,
613468c413aSTim Haley     nvlist_t *policy, nvlist_t **config);
614ad135b5dSChristopher Siden extern int spa_get_stats(const char *pool, nvlist_t **config, char *altroot,
615ad135b5dSChristopher Siden     size_t buflen);
616990b4856Slling extern int spa_create(const char *pool, nvlist_t *config, nvlist_t *props,
6174445fffbSMatthew Ahrens     nvlist_t *zplprops);
618051aabe6Staylor extern int spa_import_rootpool(char *devpath, char *devid);
6194b964adaSGeorge Wilson extern int spa_import(const char *pool, nvlist_t *config, nvlist_t *props,
6204b964adaSGeorge Wilson     uint64_t flags);
621fa9e4066Sahrens extern nvlist_t *spa_tryimport(nvlist_t *tryconfig);
622fa9e4066Sahrens extern int spa_destroy(char *pool);
623394ab0cbSGeorge Wilson extern int spa_export(char *pool, nvlist_t **oldconfig, boolean_t force,
624394ab0cbSGeorge Wilson     boolean_t hardforce);
625ea8dc4b6Seschrock extern int spa_reset(char *pool);
626ea8dc4b6Seschrock extern void spa_async_request(spa_t *spa, int flag);
627088f3894Sahrens extern void spa_async_unrequest(spa_t *spa, int flag);
628ea8dc4b6Seschrock extern void spa_async_suspend(spa_t *spa);
629ea8dc4b6Seschrock extern void spa_async_resume(spa_t *spa);
630ea8dc4b6Seschrock extern spa_t *spa_inject_addref(char *pool);
631ea8dc4b6Seschrock extern void spa_inject_delref(spa_t *spa);
6323f9d6ad7SLin Ling extern void spa_scan_stat_init(spa_t *spa);
6333f9d6ad7SLin Ling extern int spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps);
634ea8dc4b6Seschrock 
635e14bb325SJeff Bonwick #define	SPA_ASYNC_CONFIG_UPDATE	0x01
636e14bb325SJeff Bonwick #define	SPA_ASYNC_REMOVE	0x02
637e14bb325SJeff Bonwick #define	SPA_ASYNC_PROBE		0x04
638e14bb325SJeff Bonwick #define	SPA_ASYNC_RESILVER_DONE	0x08
639e14bb325SJeff Bonwick #define	SPA_ASYNC_RESILVER	0x10
640573ca77eSGeorge Wilson #define	SPA_ASYNC_AUTOEXPAND	0x20
6413f9d6ad7SLin Ling #define	SPA_ASYNC_REMOVE_DONE	0x40
6423f9d6ad7SLin Ling #define	SPA_ASYNC_REMOVE_STOP	0x80
6433f9d6ad7SLin Ling 
6443f9d6ad7SLin Ling /*
6453f9d6ad7SLin Ling  * Controls the behavior of spa_vdev_remove().
6463f9d6ad7SLin Ling  */
6473f9d6ad7SLin Ling #define	SPA_REMOVE_UNSPARE	0x01
6483f9d6ad7SLin Ling #define	SPA_REMOVE_DONE		0x02
649fa9e4066Sahrens 
650fa9e4066Sahrens /* device manipulation */
651fa9e4066Sahrens extern int spa_vdev_add(spa_t *spa, nvlist_t *nvroot);
652ea8dc4b6Seschrock extern int spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot,
653fa9e4066Sahrens     int replacing);
6548ad4d6ddSJeff Bonwick extern int spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid,
6558ad4d6ddSJeff Bonwick     int replace_done);
65699653d4eSeschrock extern int spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare);
6573f9d6ad7SLin Ling extern boolean_t spa_vdev_remove_active(spa_t *spa);
658c67d9675Seschrock extern int spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath);
6596809eb4eSEric Schrock extern int spa_vdev_setfru(spa_t *spa, uint64_t guid, const char *newfru);
6601195e687SMark J Musante extern int spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
6611195e687SMark J Musante     nvlist_t *props, boolean_t exp);
662fa9e4066Sahrens 
66399653d4eSeschrock /* spare state (which is global across all pools) */
66439c23413Seschrock extern void spa_spare_add(vdev_t *vd);
66539c23413Seschrock extern void spa_spare_remove(vdev_t *vd);
66689a89ebfSlling extern boolean_t spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt);
66739c23413Seschrock extern void spa_spare_activate(vdev_t *vd);
66899653d4eSeschrock 
669fa94a07fSbrendan /* L2ARC state (which is global across all pools) */
670fa94a07fSbrendan extern void spa_l2cache_add(vdev_t *vd);
671fa94a07fSbrendan extern void spa_l2cache_remove(vdev_t *vd);
672fa94a07fSbrendan extern boolean_t spa_l2cache_exists(uint64_t guid, uint64_t *pool);
673fa94a07fSbrendan extern void spa_l2cache_activate(vdev_t *vd);
674fa94a07fSbrendan extern void spa_l2cache_drop(spa_t *spa);
675fa94a07fSbrendan 
6763f9d6ad7SLin Ling /* scanning */
6773f9d6ad7SLin Ling extern int spa_scan(spa_t *spa, pool_scan_func_t func);
6783f9d6ad7SLin Ling extern int spa_scan_stop(spa_t *spa);
679fa9e4066Sahrens 
680fa9e4066Sahrens /* spa syncing */
681fa9e4066Sahrens extern void spa_sync(spa_t *spa, uint64_t txg); /* only for DMU use */
682fa9e4066Sahrens extern void spa_sync_allpools(void);
683fa9e4066Sahrens 
6843a737e0dSbrendan /* spa namespace global mutex */
6853a737e0dSbrendan extern kmutex_t spa_namespace_lock;
6863a737e0dSbrendan 
687fa9e4066Sahrens /*
688fa9e4066Sahrens  * SPA configuration functions in spa_config.c
689fa9e4066Sahrens  */
6900373e76bSbonwick 
6910373e76bSbonwick #define	SPA_CONFIG_UPDATE_POOL	0
6920373e76bSbonwick #define	SPA_CONFIG_UPDATE_VDEVS	1
6930373e76bSbonwick 
694c5904d13Seschrock extern void spa_config_sync(spa_t *, boolean_t, boolean_t);
695fa9e4066Sahrens extern void spa_config_load(void);
696fa9e4066Sahrens extern nvlist_t *spa_all_configs(uint64_t *);
697fa9e4066Sahrens extern void spa_config_set(spa_t *spa, nvlist_t *config);
698fa9e4066Sahrens extern nvlist_t *spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg,
699fa9e4066Sahrens     int getstats);
7000373e76bSbonwick extern void spa_config_update(spa_t *spa, int what);
701fa9e4066Sahrens 
702fa9e4066Sahrens /*
703fa9e4066Sahrens  * Miscellaneous SPA routines in spa_misc.c
704fa9e4066Sahrens  */
705fa9e4066Sahrens 
706fa9e4066Sahrens /* Namespace manipulation */
707fa9e4066Sahrens extern spa_t *spa_lookup(const char *name);
708468c413aSTim Haley extern spa_t *spa_add(const char *name, nvlist_t *config, const char *altroot);
709fa9e4066Sahrens extern void spa_remove(spa_t *spa);
710fa9e4066Sahrens extern spa_t *spa_next(spa_t *prev);
711fa9e4066Sahrens 
712fa9e4066Sahrens /* Refcount functions */
713fa9e4066Sahrens extern void spa_open_ref(spa_t *spa, void *tag);
714fa9e4066Sahrens extern void spa_close(spa_t *spa, void *tag);
715bc9014e6SJustin Gibbs extern void spa_async_close(spa_t *spa, void *tag);
716fa9e4066Sahrens extern boolean_t spa_refcount_zero(spa_t *spa);
717fa9e4066Sahrens 
7188f18d1faSGeorge Wilson #define	SCL_NONE	0x00
719e14bb325SJeff Bonwick #define	SCL_CONFIG	0x01
720e14bb325SJeff Bonwick #define	SCL_STATE	0x02
721e14bb325SJeff Bonwick #define	SCL_L2ARC	0x04		/* hack until L2ARC 2.0 */
722e14bb325SJeff Bonwick #define	SCL_ALLOC	0x08
723e14bb325SJeff Bonwick #define	SCL_ZIO		0x10
724e14bb325SJeff Bonwick #define	SCL_FREE	0x20
725e14bb325SJeff Bonwick #define	SCL_VDEV	0x40
726e14bb325SJeff Bonwick #define	SCL_LOCKS	7
727e14bb325SJeff Bonwick #define	SCL_ALL		((1 << SCL_LOCKS) - 1)
728e14bb325SJeff Bonwick #define	SCL_STATE_ALL	(SCL_STATE | SCL_L2ARC | SCL_ZIO)
729e14bb325SJeff Bonwick 
730e14bb325SJeff Bonwick /* Pool configuration locks */
731e14bb325SJeff Bonwick extern int spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw);
732e14bb325SJeff Bonwick extern void spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw);
733e14bb325SJeff Bonwick extern void spa_config_exit(spa_t *spa, int locks, void *tag);
734e14bb325SJeff Bonwick extern int spa_config_held(spa_t *spa, int locks, krw_t rw);
735fa9e4066Sahrens 
736fa9e4066Sahrens /* Pool vdev add/remove lock */
737fa9e4066Sahrens extern uint64_t spa_vdev_enter(spa_t *spa);
73888ecc943SGeorge Wilson extern uint64_t spa_vdev_config_enter(spa_t *spa);
73988ecc943SGeorge Wilson extern void spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg,
74088ecc943SGeorge Wilson     int error, char *tag);
741fa9e4066Sahrens extern int spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error);
742fa9e4066Sahrens 
743e14bb325SJeff Bonwick /* Pool vdev state change lock */
7448f18d1faSGeorge Wilson extern void spa_vdev_state_enter(spa_t *spa, int oplock);
745e14bb325SJeff Bonwick extern int spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error);
746e14bb325SJeff Bonwick 
747b24ab676SJeff Bonwick /* Log state */
748b24ab676SJeff Bonwick typedef enum spa_log_state {
749b24ab676SJeff Bonwick 	SPA_LOG_UNKNOWN = 0,	/* unknown log state */
750b24ab676SJeff Bonwick 	SPA_LOG_MISSING,	/* missing log(s) */
751b24ab676SJeff Bonwick 	SPA_LOG_CLEAR,		/* clear the log(s) */
752b24ab676SJeff Bonwick 	SPA_LOG_GOOD,		/* log(s) are good */
753b24ab676SJeff Bonwick } spa_log_state_t;
754b24ab676SJeff Bonwick 
755b24ab676SJeff Bonwick extern spa_log_state_t spa_get_log_state(spa_t *spa);
756b24ab676SJeff Bonwick extern void spa_set_log_state(spa_t *spa, spa_log_state_t state);
7571195e687SMark J Musante extern int spa_offline_log(spa_t *spa);
758b24ab676SJeff Bonwick 
759b24ab676SJeff Bonwick /* Log claim callback */
760b24ab676SJeff Bonwick extern void spa_claim_notify(zio_t *zio);
761b24ab676SJeff Bonwick 
762fa9e4066Sahrens /* Accessor functions */
76388b7b0f2SMatthew Ahrens extern boolean_t spa_shutting_down(spa_t *spa);
764fa9e4066Sahrens extern struct dsl_pool *spa_get_dsl(spa_t *spa);
765ad135b5dSChristopher Siden extern boolean_t spa_is_initializing(spa_t *spa);
766fa9e4066Sahrens extern blkptr_t *spa_get_rootblkptr(spa_t *spa);
767fa9e4066Sahrens extern void spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp);
768fa9e4066Sahrens extern void spa_altroot(spa_t *, char *, size_t);
769fa9e4066Sahrens extern int spa_sync_pass(spa_t *spa);
770fa9e4066Sahrens extern char *spa_name(spa_t *spa);
771fa9e4066Sahrens extern uint64_t spa_guid(spa_t *spa);
772e9103aaeSGarrett D'Amore extern uint64_t spa_load_guid(spa_t *spa);
773fa9e4066Sahrens extern uint64_t spa_last_synced_txg(spa_t *spa);
774fa9e4066Sahrens extern uint64_t spa_first_txg(spa_t *spa);
775b24ab676SJeff Bonwick extern uint64_t spa_syncing_txg(spa_t *spa);
7763991b535SGeorge Wilson extern uint64_t spa_final_dirty_txg(spa_t *spa);
77799653d4eSeschrock extern uint64_t spa_version(spa_t *spa);
77888b7b0f2SMatthew Ahrens extern pool_state_t spa_state(spa_t *spa);
779b16da2e2SGeorge Wilson extern spa_load_state_t spa_load_state(spa_t *spa);
780fa9e4066Sahrens extern uint64_t spa_freeze_txg(spa_t *spa);
78161e255ceSMatthew Ahrens extern uint64_t spa_get_worst_case_asize(spa_t *spa, uint64_t lsize);
782485bbbf5SGeorge Wilson extern uint64_t spa_get_dspace(spa_t *spa);
783c39f2c8cSChristopher Siden extern uint64_t spa_get_slop_space(spa_t *spa);
784485bbbf5SGeorge Wilson extern void spa_update_dspace(spa_t *spa);
78544cd46caSbillm extern uint64_t spa_version(spa_t *spa);
786b24ab676SJeff Bonwick extern boolean_t spa_deflate(spa_t *spa);
787b24ab676SJeff Bonwick extern metaslab_class_t *spa_normal_class(spa_t *spa);
788b24ab676SJeff Bonwick extern metaslab_class_t *spa_log_class(spa_t *spa);
789bc9014e6SJustin Gibbs extern void spa_evicting_os_register(spa_t *, objset_t *os);
790bc9014e6SJustin Gibbs extern void spa_evicting_os_deregister(spa_t *, objset_t *os);
791bc9014e6SJustin Gibbs extern void spa_evicting_os_wait(spa_t *spa);
79244cd46caSbillm extern int spa_max_replication(spa_t *spa);
7933f9d6ad7SLin Ling extern int spa_prev_software_version(spa_t *spa);
794fa9e4066Sahrens extern int spa_busy(void);
7950a4e9518Sgw extern uint8_t spa_get_failmode(spa_t *spa);
796e14bb325SJeff Bonwick extern boolean_t spa_suspended(spa_t *spa);
797b24ab676SJeff Bonwick extern uint64_t spa_bootfs(spa_t *spa);
798b24ab676SJeff Bonwick extern uint64_t spa_delegation(spa_t *spa);
799b24ab676SJeff Bonwick extern objset_t *spa_meta_objset(spa_t *spa);
800283b8460SGeorge.Wilson extern uint64_t spa_deadman_synctime(spa_t *spa);
801fa9e4066Sahrens 
802fa9e4066Sahrens /* Miscellaneous support routines */
80343466aaeSMax Grossman extern void spa_activate_mos_feature(spa_t *spa, const char *feature,
80443466aaeSMax Grossman     dmu_tx_t *tx);
805ad135b5dSChristopher Siden extern void spa_deactivate_mos_feature(spa_t *spa, const char *feature);
806fa9e4066Sahrens extern int spa_rename(const char *oldname, const char *newname);
807f9af39baSGeorge Wilson extern spa_t *spa_by_guid(uint64_t pool_guid, uint64_t device_guid);
808fa9e4066Sahrens extern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid);
809fa9e4066Sahrens extern char *spa_strdup(const char *);
810fa9e4066Sahrens extern void spa_strfree(char *);
811fa9e4066Sahrens extern uint64_t spa_get_random(uint64_t range);
8121195e687SMark J Musante extern uint64_t spa_generate_guid(spa_t *spa);
81343466aaeSMax Grossman extern void snprintf_blkptr(char *buf, size_t buflen, const blkptr_t *bp);
814fa9e4066Sahrens extern void spa_freeze(spa_t *spa);
815e9103aaeSGarrett D'Amore extern int spa_change_guid(spa_t *spa);
816990b4856Slling extern void spa_upgrade(spa_t *spa, uint64_t version);
817fa9e4066Sahrens extern void spa_evict_all(void);
818c5904d13Seschrock extern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid,
819c5904d13Seschrock     boolean_t l2cache);
82099653d4eSeschrock extern boolean_t spa_has_spare(spa_t *, uint64_t guid);
821b24ab676SJeff Bonwick extern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva);
822b24ab676SJeff Bonwick extern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp);
823b24ab676SJeff Bonwick extern uint64_t bp_get_dsize(spa_t *spa, const blkptr_t *bp);
8246ce0521aSperrin extern boolean_t spa_has_slogs(spa_t *spa);
825bf82a41bSeschrock extern boolean_t spa_is_root(spa_t *spa);
8268ad4d6ddSJeff Bonwick extern boolean_t spa_writeable(spa_t *spa);
82773527f44SAlex Reece extern boolean_t spa_has_pending_synctask(spa_t *spa);
828b5152584SMatthew Ahrens extern int spa_maxblocksize(spa_t *spa);
829f63ab3d5SMatthew Ahrens extern void zfs_blkptr_verify(spa_t *spa, const blkptr_t *bp);
830468c413aSTim Haley 
8318ad4d6ddSJeff Bonwick extern int spa_mode(spa_t *spa);
832ca45db41SChris Kirby extern uint64_t strtonum(const char *str, char **nptr);
833ea8dc4b6Seschrock 
834ecd6cf80Smarks extern char *spa_his_ievent_table[];
835ecd6cf80Smarks 
83606eeb2adSek extern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx);
83706eeb2adSek extern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read,
83806eeb2adSek     char *his_buf);
8394445fffbSMatthew Ahrens extern int spa_history_log(spa_t *spa, const char *his_buf);
8404445fffbSMatthew Ahrens extern int spa_history_log_nvl(spa_t *spa, nvlist_t *nvl);
8414445fffbSMatthew Ahrens extern void spa_history_log_version(spa_t *spa, const char *operation);
8424445fffbSMatthew Ahrens extern void spa_history_log_internal(spa_t *spa, const char *operation,
8434445fffbSMatthew Ahrens     dmu_tx_t *tx, const char *fmt, ...);
8444445fffbSMatthew Ahrens extern void spa_history_log_internal_ds(struct dsl_dataset *ds, const char *op,
8454445fffbSMatthew Ahrens     dmu_tx_t *tx, const char *fmt, ...);
8464445fffbSMatthew Ahrens extern void spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation,
8474445fffbSMatthew Ahrens     dmu_tx_t *tx, const char *fmt, ...);
84806eeb2adSek 
849ea8dc4b6Seschrock /* error handling */
8507802d7bfSMatthew Ahrens struct zbookmark_phys;
851b24ab676SJeff Bonwick extern void spa_log_error(spa_t *spa, zio_t *zio);
852ea8dc4b6Seschrock extern void zfs_ereport_post(const char *class, spa_t *spa, vdev_t *vd,
853b24ab676SJeff Bonwick     zio_t *zio, uint64_t stateoroffset, uint64_t length);
8543d7072f8Seschrock extern void zfs_post_remove(spa_t *spa, vdev_t *vd);
855069f55e2SEric Schrock extern void zfs_post_state_change(spa_t *spa, vdev_t *vd);
8563d7072f8Seschrock extern void zfs_post_autoreplace(spa_t *spa, vdev_t *vd);
857ea8dc4b6Seschrock extern uint64_t spa_get_errlog_size(spa_t *spa);
858ea8dc4b6Seschrock extern int spa_get_errlog(spa_t *spa, void *uaddr, size_t *count);
859ea8dc4b6Seschrock extern void spa_errlog_rotate(spa_t *spa);
860ea8dc4b6Seschrock extern void spa_errlog_drain(spa_t *spa);
861ea8dc4b6Seschrock extern void spa_errlog_sync(spa_t *spa, uint64_t txg);
862ea8dc4b6Seschrock extern void spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub);
863fa9e4066Sahrens 
86487db74c1Sek /* vdev cache */
86587db74c1Sek extern void vdev_cache_stat_init(void);
86687db74c1Sek extern void vdev_cache_stat_fini(void);
86787db74c1Sek 
868fa9e4066Sahrens /* Initialization and termination */
869fa9e4066Sahrens extern void spa_init(int flags);
870fa9e4066Sahrens extern void spa_fini(void);
871e7cbe64fSgw extern void spa_boot_init();
872fa9e4066Sahrens 
873b1b8ab34Slling /* properties */
874990b4856Slling extern int spa_prop_set(spa_t *spa, nvlist_t *nvp);
875990b4856Slling extern int spa_prop_get(spa_t *spa, nvlist_t **nvp);
876990b4856Slling extern void spa_prop_clear_bootfs(spa_t *spa, uint64_t obj, dmu_tx_t *tx);
877379c004dSEric Schrock extern void spa_configfile_set(spa_t *, nvlist_t *, boolean_t);
878b1b8ab34Slling 
8793d7072f8Seschrock /* asynchronous event notification */
880*ce1577b0SDave Eddy extern void spa_event_notify(spa_t *spa, vdev_t *vdev, nvlist_t *hist_nvl,
881*ce1577b0SDave Eddy     const char *name);
8823d7072f8Seschrock 
883fa9e4066Sahrens #ifdef ZFS_DEBUG
884c0a81264Sek #define	dprintf_bp(bp, fmt, ...) do {				\
88543466aaeSMax Grossman 	if (zfs_flags & ZFS_DEBUG_DPRINTF) {			\
886c0a81264Sek 	char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP);	\
88743466aaeSMax Grossman 	snprintf_blkptr(__blkbuf, BP_SPRINTF_LEN, (bp));	\
888c0a81264Sek 	dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf);		\
889c0a81264Sek 	kmem_free(__blkbuf, BP_SPRINTF_LEN);			\
890fa9e4066Sahrens 	} \
891fa9e4066Sahrens _NOTE(CONSTCOND) } while (0)
892fa9e4066Sahrens #else
893fa9e4066Sahrens #define	dprintf_bp(bp, fmt, ...)
894fa9e4066Sahrens #endif
895fa9e4066Sahrens 
89609c9d376SGeorge Wilson extern boolean_t spa_debug_enabled(spa_t *spa);
89709c9d376SGeorge Wilson #define	spa_dbgmsg(spa, ...)			\
89809c9d376SGeorge Wilson {						\
89909c9d376SGeorge Wilson 	if (spa_debug_enabled(spa))		\
90009c9d376SGeorge Wilson 		zfs_dbgmsg(__VA_ARGS__);	\
90109c9d376SGeorge Wilson }
90209c9d376SGeorge Wilson 
9038ad4d6ddSJeff Bonwick extern int spa_mode_global;			/* mode, e.g. FREAD | FWRITE */
904fa9e4066Sahrens 
905fa9e4066Sahrens #ifdef	__cplusplus
906fa9e4066Sahrens }
907fa9e4066Sahrens #endif
908fa9e4066Sahrens 
909fa9e4066Sahrens #endif	/* _SYS_SPA_H */
910