spa.h revision 43466aae47bfcd2ad9bf501faec8e75c08095e4f
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5ea8dc4beschrock * Common Development and Distribution License (the "License").
6ea8dc4beschrock * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
223f9d6adLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2343466aaMax Grossman * Copyright (c) 2013 by Delphix. All rights reserved.
24e9103aaGarrett D'Amore * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
25fa9e406ahrens */
27fa9e406ahrens#ifndef _SYS_SPA_H
28fa9e406ahrens#define	_SYS_SPA_H
30fa9e406ahrens#include <sys/avl.h>
31fa9e406ahrens#include <sys/zfs_context.h>
32fa9e406ahrens#include <sys/nvpair.h>
33fa9e406ahrens#include <sys/sysmacros.h>
34fa9e406ahrens#include <sys/types.h>
35fa9e406ahrens#include <sys/fs/zfs.h>
37fa9e406ahrens#ifdef	__cplusplus
38fa9e406ahrensextern "C" {
42fa9e406ahrens * Forward references that lots of things need.
43fa9e406ahrens */
44fa9e406ahrenstypedef struct spa spa_t;
45fa9e406ahrenstypedef struct vdev vdev_t;
46fa9e406ahrenstypedef struct metaslab metaslab_t;
47b24ab67Jeff Bonwicktypedef struct metaslab_group metaslab_group_t;
48b24ab67Jeff Bonwicktypedef struct metaslab_class metaslab_class_t;
49b24ab67Jeff Bonwicktypedef struct zio zio_t;
50fa9e406ahrenstypedef struct zilog zilog_t;
51fa94a07brendantypedef struct spa_aux_vdev spa_aux_vdev_t;
52b24ab67Jeff Bonwicktypedef struct ddt ddt_t;
53b24ab67Jeff Bonwicktypedef struct ddt_entry ddt_entry_t;
54fa9e406ahrensstruct dsl_pool;
554445fffMatthew Ahrensstruct dsl_dataset;
58fa9e406ahrens * General-purpose 32-bit and 64-bit bitfield encodings.
59fa9e406ahrens */
60fa9e406ahrens#define	BF32_DECODE(x, low, len)	P2PHASE((x) >> (low), 1U << (len))
61fa9e406ahrens#define	BF64_DECODE(x, low, len)	P2PHASE((x) >> (low), 1ULL << (len))
62fa9e406ahrens#define	BF32_ENCODE(x, low, len)	(P2PHASE((x), 1U << (len)) << (low))
63fa9e406ahrens#define	BF64_ENCODE(x, low, len)	(P2PHASE((x), 1ULL << (len)) << (low))
65fa9e406ahrens#define	BF32_GET(x, low, len)		BF32_DECODE(x, low, len)
66fa9e406ahrens#define	BF64_GET(x, low, len)		BF64_DECODE(x, low, len)
6843466aaMax Grossman#define	BF32_SET(x, low, len, val) do { \
6943466aaMax Grossman	ASSERT3U(val, <, 1U << (len)); \
7043466aaMax Grossman	ASSERT3U(low + len, <=, 32); \
7143466aaMax Grossman	(x) ^= BF32_ENCODE((x >> low) ^ (val), low, len); \
7243466aaMax Grossman_NOTE(CONSTCOND) } while (0)
7343466aaMax Grossman
7443466aaMax Grossman#define	BF64_SET(x, low, len, val) do { \
7543466aaMax Grossman	ASSERT3U(val, <, 1ULL << (len)); \
7643466aaMax Grossman	ASSERT3U(low + len, <=, 64); \
7743466aaMax Grossman	((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len)); \
7843466aaMax Grossman_NOTE(CONSTCOND) } while (0)
80fa9e406ahrens#define	BF32_GET_SB(x, low, len, shift, bias)	\
81fa9e406ahrens	((BF32_GET(x, low, len) + (bias)) << (shift))
82fa9e406ahrens#define	BF64_GET_SB(x, low, len, shift, bias)	\
83fa9e406ahrens	((BF64_GET(x, low, len) + (bias)) << (shift))
8543466aaMax Grossman#define	BF32_SET_SB(x, low, len, shift, bias, val) do { \
8643466aaMax Grossman	ASSERT(IS_P2ALIGNED(val, 1U << shift)); \
8743466aaMax Grossman	ASSERT3S((val) >> (shift), >=, bias); \
8843466aaMax Grossman	BF32_SET(x, low, len, ((val) >> (shift)) - (bias)); \
8943466aaMax Grossman_NOTE(CONSTCOND) } while (0)
9043466aaMax Grossman#define	BF64_SET_SB(x, low, len, shift, bias, val) do { \
9143466aaMax Grossman	ASSERT(IS_P2ALIGNED(val, 1ULL << shift)); \
9243466aaMax Grossman	ASSERT3S((val) >> (shift), >=, bias); \
9343466aaMax Grossman	BF64_SET(x, low, len, ((val) >> (shift)) - (bias)); \
9443466aaMax Grossman_NOTE(CONSTCOND) } while (0)
97fa9e406ahrens * We currently support nine block sizes, from 512 bytes to 128K.
98fa9e406ahrens * We could go higher, but the benefits are near-zero and the cost
99fa9e406ahrens * of COWing a giant block to modify one byte would become excessive.
100fa9e406ahrens */
101fa9e406ahrens#define	SPA_MINBLOCKSHIFT	9
102fa9e406ahrens#define	SPA_MAXBLOCKSHIFT	17
103fa9e406ahrens#define	SPA_MINBLOCKSIZE	(1ULL << SPA_MINBLOCKSHIFT)
104fa9e406ahrens#define	SPA_MAXBLOCKSIZE	(1ULL << SPA_MAXBLOCKSHIFT)
109f7991baTim Haley * Size of block to hold the configuration data (a packed nvlist)
110f7991baTim Haley */
111ad135b5Christopher Siden#define	SPA_CONFIG_BLOCKSIZE	(1ULL << 14)
112f7991baTim Haley
113f7991baTim Haley/*
114fa9e406ahrens * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
115fa9e406ahrens * The ASIZE encoding should be at least 64 times larger (6 more bits)
116fa9e406ahrens * to support up to 4-way RAID-Z mirror mode with worst-case gang block
117fa9e406ahrens * overhead, three DVAs per bp, plus one more bit in case we do anything
118fa9e406ahrens * else that expands the ASIZE.
119fa9e406ahrens */
120fa9e406ahrens#define	SPA_LSIZEBITS		16	/* LSIZE up to 32M (2^16 * 512)	*/
121fa9e406ahrens#define	SPA_PSIZEBITS		16	/* PSIZE up to 32M (2^16 * 512)	*/
122fa9e406ahrens#define	SPA_ASIZEBITS		24	/* ASIZE up to 64 times larger	*/
125fa9e406ahrens * All SPA data is represented by 128-bit data virtual addresses (DVAs).
126fa9e406ahrens * The members of the dva_t should be considered opaque outside the SPA.
127fa9e406ahrens */
128fa9e406ahrenstypedef struct dva {
129fa9e406ahrens	uint64_t	dva_word[2];
130fa9e406ahrens} dva_t;
133fa9e406ahrens * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
134fa9e406ahrens */
135fa9e406ahrenstypedef struct zio_cksum {
136fa9e406ahrens	uint64_t	zc_word[4];
137fa9e406ahrens} zio_cksum_t;
140fa9e406ahrens * Each block is described by its DVAs, time of birth, checksum, etc.
141fa9e406ahrens * The word-by-word, bit-by-bit layout of the blkptr is as follows:
142fa9e406ahrens *
143fa9e406ahrens *	64	56	48	40	32	24	16	8	0
144fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
145fa9e406ahrens * 0	|		vdev1		| GRID  |	  ASIZE		|
146fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
147fa9e406ahrens * 1	|G|			 offset1				|
148fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
149fa9e406ahrens * 2	|		vdev2		| GRID  |	  ASIZE		|
150fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
151fa9e406ahrens * 3	|G|			 offset2				|
152fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
153fa9e406ahrens * 4	|		vdev3		| GRID  |	  ASIZE		|
154fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
155fa9e406ahrens * 5	|G|			 offset3				|
156fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
157b24ab67Jeff Bonwick * 6	|BDX|lvl| type	| cksum | comp	|     PSIZE	|     LSIZE	|
158fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
159fa9e406ahrens * 7	|			padding					|
160fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
161fa9e406ahrens * 8	|			padding					|
162fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
163b24ab67Jeff Bonwick * 9	|			physical birth txg			|
164fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
165b24ab67Jeff Bonwick * a	|			logical birth txg			|
166fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
167fa9e406ahrens * b	|			fill count				|
168fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
169fa9e406ahrens * c	|			checksum[0]				|
170fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
171fa9e406ahrens * d	|			checksum[1]				|
172fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
173fa9e406ahrens * e	|			checksum[2]				|
174fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
175fa9e406ahrens * f	|			checksum[3]				|
176fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
177fa9e406ahrens *
178fa9e406ahrens * Legend:
179fa9e406ahrens *
180fa9e406ahrens * vdev		virtual device ID
181fa9e406ahrens * offset	offset into virtual device
182fa9e406ahrens * LSIZE	logical size
183fa9e406ahrens * PSIZE	physical size (after compression)
184fa9e406ahrens * ASIZE	allocated size (including RAID-Z parity and gang block headers)
185fa9e406ahrens * GRID		RAID-Z layout information (reserved for future use)
186fa9e406ahrens * cksum	checksum function
187fa9e406ahrens * comp		compression function
188fa9e406ahrens * G		gang block indicator
189b24ab67Jeff Bonwick * B		byteorder (endianness)
190b24ab67Jeff Bonwick * D		dedup
191b24ab67Jeff Bonwick * X		unused
192fa9e406ahrens * lvl		level of indirection
193b24ab67Jeff Bonwick * type		DMU object type
194b24ab67Jeff Bonwick * phys birth	txg of block allocation; zero if same as logical birth txg
195b24ab67Jeff Bonwick * log. birth	transaction group in which the block was logically born
196fa9e406ahrens * fill count	number of non-zero blocks under this bp
197fa9e406ahrens * checksum[4]	256-bit checksum of the data this bp describes
198fa9e406ahrens */
199fa9e406ahrens#define	SPA_BLKPTRSHIFT	7		/* blkptr_t is 128 bytes	*/
200fa9e406ahrens#define	SPA_DVAS_PER_BP	3		/* Number of DVAs in a bp	*/
20243466aaMax Grossman/*
20343466aaMax Grossman * A block is a hole when it has either 1) never been written to, or
20443466aaMax Grossman * 2) is zero-filled. In both cases, ZFS can return all zeroes for all reads
20543466aaMax Grossman * without physically allocating disk space. Holes are represented in the
20643466aaMax Grossman * blkptr_t structure by zeroed blk_dva. Correct checking for holes is
20743466aaMax Grossman * done through the BP_IS_HOLE macro. For holes, the logical size, level,
20843466aaMax Grossman * DMU object type, and birth times are all also stored for holes that
20943466aaMax Grossman * were written to at some point (i.e. were punched after having been filled).
21043466aaMax Grossman */
211b24ab67Jeff Bonwicktypedef struct blkptr {
212b24ab67Jeff Bonwick	dva_t		blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */
213b24ab67Jeff Bonwick	uint64_t	blk_prop;	/* size, compression, type, etc	    */
214b24ab67Jeff Bonwick	uint64_t	blk_pad[2];	/* Extra space for the future	    */
215b24ab67Jeff Bonwick	uint64_t	blk_phys_birth;	/* txg when block was allocated	    */
216b24ab67Jeff Bonwick	uint64_t	blk_birth;	/* transaction group at birth	    */
217b24ab67Jeff Bonwick	uint64_t	blk_fill;	/* fill count			    */
218b24ab67Jeff Bonwick	zio_cksum_t	blk_cksum;	/* 256-bit checksum		    */
219b24ab67Jeff Bonwick} blkptr_t;
220b24ab67Jeff Bonwick
222fa9e406ahrens * Macros to get and set fields in a bp or DVA.
223fa9e406ahrens */
224fa9e406ahrens#define	DVA_GET_ASIZE(dva)	\
22543466aaMax Grossman	BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0)
226fa9e406ahrens#define	DVA_SET_ASIZE(dva, x)	\
22743466aaMax Grossman	BF64_SET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, \
22843466aaMax Grossman	SPA_MINBLOCKSHIFT, 0, x)
230fa9e406ahrens#define	DVA_GET_GRID(dva)	BF64_GET((dva)->dva_word[0], 24, 8)
231fa9e406ahrens#define	DVA_SET_GRID(dva, x)	BF64_SET((dva)->dva_word[0], 24, 8, x)
233fa9e406ahrens#define	DVA_GET_VDEV(dva)	BF64_GET((dva)->dva_word[0], 32, 32)
234fa9e406ahrens#define	DVA_SET_VDEV(dva, x)	BF64_SET((dva)->dva_word[0], 32, 32, x)
236fa9e406ahrens#define	DVA_GET_OFFSET(dva)	\
237fa9e406ahrens	BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0)
238fa9e406ahrens#define	DVA_SET_OFFSET(dva, x)	\
239fa9e406ahrens	BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x)
241fa9e406ahrens#define	DVA_GET_GANG(dva)	BF64_GET((dva)->dva_word[1], 63, 1)
242fa9e406ahrens#define	DVA_SET_GANG(dva, x)	BF64_SET((dva)->dva_word[1], 63, 1, x)
244fa9e406ahrens#define	BP_GET_LSIZE(bp)	\
24543466aaMax Grossman	BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1)
246fa9e406ahrens#define	BP_SET_LSIZE(bp, x)	\
24743466aaMax Grossman	BF64_SET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x)
249fa9e406ahrens#define	BP_GET_PSIZE(bp)	\
25043466aaMax Grossman	BF64_GET_SB((bp)->blk_prop, 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1)
251fa9e406ahrens#define	BP_SET_PSIZE(bp, x)	\
25243466aaMax Grossman	BF64_SET_SB((bp)->blk_prop, 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1, x)
254b24ab67Jeff Bonwick#define	BP_GET_COMPRESS(bp)		BF64_GET((bp)->blk_prop, 32, 8)
255b24ab67Jeff Bonwick#define	BP_SET_COMPRESS(bp, x)		BF64_SET((bp)->blk_prop, 32, 8, x)
256b24ab67Jeff Bonwick
257b24ab67Jeff Bonwick#define	BP_GET_CHECKSUM(bp)		BF64_GET((bp)->blk_prop, 40, 8)
258b24ab67Jeff Bonwick#define	BP_SET_CHECKSUM(bp, x)		BF64_SET((bp)->blk_prop, 40, 8, x)
259b24ab67Jeff Bonwick
260b24ab67Jeff Bonwick#define	BP_GET_TYPE(bp)			BF64_GET((bp)->blk_prop, 48, 8)
261b24ab67Jeff Bonwick#define	BP_SET_TYPE(bp, x)		BF64_SET((bp)->blk_prop, 48, 8, x)
263b24ab67Jeff Bonwick#define	BP_GET_LEVEL(bp)		BF64_GET((bp)->blk_prop, 56, 5)
264b24ab67Jeff Bonwick#define	BP_SET_LEVEL(bp, x)		BF64_SET((bp)->blk_prop, 56, 5, x)
266b24ab67Jeff Bonwick#define	BP_GET_PROP_BIT_61(bp)		BF64_GET((bp)->blk_prop, 61, 1)
267b24ab67Jeff Bonwick#define	BP_SET_PROP_BIT_61(bp, x)	BF64_SET((bp)->blk_prop, 61, 1, x)
269b24ab67Jeff Bonwick#define	BP_GET_DEDUP(bp)		BF64_GET((bp)->blk_prop, 62, 1)
270b24ab67Jeff Bonwick#define	BP_SET_DEDUP(bp, x)		BF64_SET((bp)->blk_prop, 62, 1, x)
27243466aaMax Grossman#define	BP_GET_BYTEORDER(bp)		BF64_GET((bp)->blk_prop, 63, 1)
273b24ab67Jeff Bonwick#define	BP_SET_BYTEORDER(bp, x)		BF64_SET((bp)->blk_prop, 63, 1, x)
274b24ab67Jeff Bonwick
275b24ab67Jeff Bonwick#define	BP_PHYSICAL_BIRTH(bp)		\
276b24ab67Jeff Bonwick	((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)
277b24ab67Jeff Bonwick
278b24ab67Jeff Bonwick#define	BP_SET_BIRTH(bp, logical, physical)	\
279b24ab67Jeff Bonwick{						\
280b24ab67Jeff Bonwick	(bp)->blk_birth = (logical);		\
281b24ab67Jeff Bonwick	(bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \
282b24ab67Jeff Bonwick}
284fa9e406ahrens#define	BP_GET_ASIZE(bp)	\
285fa9e406ahrens	(DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
28699653d4eschrock		DVA_GET_ASIZE(&(bp)->blk_dva[2]))
28899653d4eschrock#define	BP_GET_UCSIZE(bp) \
289ad135b5Christopher Siden	((BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp))) ? \
2903f9d6adLin Ling	BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp))
29244cd46cbillm#define	BP_GET_NDVAS(bp)	\
29344cd46cbillm	(!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
29444cd46cbillm	!!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
29544cd46cbillm	!!DVA_GET_ASIZE(&(bp)->blk_dva[2]))
29744cd46cbillm#define	BP_COUNT_GANG(bp)	\
29844cd46cbillm	(DVA_GET_GANG(&(bp)->blk_dva[0]) + \
29944cd46cbillm	DVA_GET_GANG(&(bp)->blk_dva[1]) + \
30044cd46cbillm	DVA_GET_GANG(&(bp)->blk_dva[2]))
302fa9e406ahrens#define	DVA_EQUAL(dva1, dva2)	\
303fa9e406ahrens	((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
304fa9e406ahrens	(dva1)->dva_word[0] == (dva2)->dva_word[0])
306b24ab67Jeff Bonwick#define	BP_EQUAL(bp1, bp2)	\
307b24ab67Jeff Bonwick	(BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) &&	\
308b24ab67Jeff Bonwick	DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) &&	\
309b24ab67Jeff Bonwick	DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) &&	\
310b24ab67Jeff Bonwick	DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2]))
311b24ab67Jeff Bonwick
3126b4acc8ahrens#define	ZIO_CHECKSUM_EQUAL(zc1, zc2) \
3136b4acc8ahrens	(0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
3146b4acc8ahrens	((zc1).zc_word[1] - (zc2).zc_word[1]) | \
3156b4acc8ahrens	((zc1).zc_word[2] - (zc2).zc_word[2]) | \
3166b4acc8ahrens	((zc1).zc_word[3] - (zc2).zc_word[3])))
318fa9e406ahrens#define	DVA_IS_VALID(dva)	(DVA_GET_ASIZE(dva) != 0)
320fa9e406ahrens#define	ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3)	\
321fa9e406ahrens{						\
322fa9e406ahrens	(zcp)->zc_word[0] = w0;			\
323fa9e406ahrens	(zcp)->zc_word[1] = w1;			\
324fa9e406ahrens	(zcp)->zc_word[2] = w2;			\
325fa9e406ahrens	(zcp)->zc_word[3] = w3;			\
328fa9e406ahrens#define	BP_IDENTITY(bp)		(&(bp)->blk_dva[0])
32944cd46cbillm#define	BP_IS_GANG(bp)		DVA_GET_GANG(BP_IDENTITY(bp))
33043466aaMax Grossman#define	DVA_IS_EMPTY(dva)	((dva)->dva_word[0] == 0ULL &&	\
33143466aaMax Grossman				(dva)->dva_word[1] == 0ULL)
33243466aaMax Grossman#define	BP_IS_HOLE(bp)		DVA_IS_EMPTY(BP_IDENTITY(bp))
3346e1f5caNeil Perrin/* BP_IS_RAIDZ(bp) assumes no block compression */
3356e1f5caNeil Perrin#define	BP_IS_RAIDZ(bp)		(DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \
3366e1f5caNeil Perrin				BP_GET_PSIZE(bp))
3376e1f5caNeil Perrin
338e14bb32Jeff Bonwick#define	BP_ZERO(bp)				\
339fa9e406ahrens{						\
340fa9e406ahrens	(bp)->blk_dva[0].dva_word[0] = 0;	\
341fa9e406ahrens	(bp)->blk_dva[0].dva_word[1] = 0;	\
342fa9e406ahrens	(bp)->blk_dva[1].dva_word[0] = 0;	\
343fa9e406ahrens	(bp)->blk_dva[1].dva_word[1] = 0;	\
344fa9e406ahrens	(bp)->blk_dva[2].dva_word[0] = 0;	\
345fa9e406ahrens	(bp)->blk_dva[2].dva_word[1] = 0;	\
346fa9e406ahrens	(bp)->blk_prop = 0;			\
347fa9e406ahrens	(bp)->blk_pad[0] = 0;			\
348fa9e406ahrens	(bp)->blk_pad[1] = 0;			\
349b24ab67Jeff Bonwick	(bp)->blk_phys_birth = 0;		\
350e14bb32Jeff Bonwick	(bp)->blk_birth = 0;			\
351fa9e406ahrens	(bp)->blk_fill = 0;			\
352fa9e406ahrens	ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0);	\
355fa9e406ahrens#ifdef _BIG_ENDIAN
356fa9e406ahrens#define	ZFS_HOST_BYTEORDER	(0ULL)
35843466aaMax Grossman#define	ZFS_HOST_BYTEORDER	(1ULL)
36344cd46cbillm#define	BP_SPRINTF_LEN	320
365b24ab67Jeff Bonwick/*
366b24ab67Jeff Bonwick * This macro allows code sharing between zfs, libzpool, and mdb.
367b24ab67Jeff Bonwick * 'func' is either snprintf() or mdb_snprintf().
368b24ab67Jeff Bonwick * 'ws' (whitespace) can be ' ' for single-line format, '\n' for multi-line.
369b24ab67Jeff Bonwick */
37043466aaMax Grossman#define	SNPRINTF_BLKPTR(func, ws, buf, size, bp, type, checksum, compress) \
371b24ab67Jeff Bonwick{									\
372b24ab67Jeff Bonwick	static const char *copyname[] =					\
373b24ab67Jeff Bonwick	    { "zero", "single", "double", "triple" };			\
374b24ab67Jeff Bonwick	int len = 0;							\
375b24ab67Jeff Bonwick	int copies = 0;							\
376b24ab67Jeff Bonwick									\
377b24ab67Jeff Bonwick	if (bp == NULL) {						\
37843466aaMax Grossman		len += func(buf + len, size - len, "<NULL>");		\
379b24ab67Jeff Bonwick	} else if (BP_IS_HOLE(bp)) {					\
38043466aaMax Grossman		len += func(buf + len, size - len, "<hole>");		\
38143466aaMax Grossman		if (bp->blk_birth > 0) {				\
38243466aaMax Grossman			len += func(buf + len, size - len,		\
38343466aaMax Grossman			    " birth=%lluL",				\
38443466aaMax Grossman			    (u_longlong_t)bp->blk_birth);		\
38543466aaMax Grossman		}							\
386b24ab67Jeff Bonwick	} else {							\
387b24ab67Jeff Bonwick		for (int d = 0; d < BP_GET_NDVAS(bp); d++) {		\
388b24ab67Jeff Bonwick			const dva_t *dva = &bp->blk_dva[d];		\
389b24ab67Jeff Bonwick			if (DVA_IS_VALID(dva))				\
390b24ab67Jeff Bonwick				copies++;				\
391b24ab67Jeff Bonwick			len += func(buf + len, size - len,		\
392b24ab67Jeff Bonwick			    "DVA[%d]=<%llu:%llx:%llx>%c", d,		\
393b24ab67Jeff Bonwick			    (u_longlong_t)DVA_GET_VDEV(dva),		\
394b24ab67Jeff Bonwick			    (u_longlong_t)DVA_GET_OFFSET(dva),		\
395b24ab67Jeff Bonwick			    (u_longlong_t)DVA_GET_ASIZE(dva),		\
396b24ab67Jeff Bonwick			    ws);					\
397b24ab67Jeff Bonwick		}							\
398b24ab67Jeff Bonwick		if (BP_IS_GANG(bp) &&					\
399b24ab67Jeff Bonwick		    DVA_GET_ASIZE(&bp->blk_dva[2]) <=			\
400b24ab67Jeff Bonwick		    DVA_GET_ASIZE(&bp->blk_dva[1]) / 2)			\
401b24ab67Jeff Bonwick			copies--;					\
402b24ab67Jeff Bonwick		len += func(buf + len, size - len,			\
403b24ab67Jeff Bonwick		    "[L%llu %s] %s %s %s %s %s %s%c"			\
404b24ab67Jeff Bonwick		    "size=%llxL/%llxP birth=%lluL/%lluP fill=%llu%c"	\
405b24ab67Jeff Bonwick		    "cksum=%llx:%llx:%llx:%llx",			\
406b24ab67Jeff Bonwick		    (u_longlong_t)BP_GET_LEVEL(bp),			\
407b24ab67Jeff Bonwick		    type,						\
408b24ab67Jeff Bonwick		    checksum,						\
409b24ab67Jeff Bonwick		    compress,						\
410b24ab67Jeff Bonwick		    BP_GET_BYTEORDER(bp) == 0 ? "BE" : "LE",		\
411b24ab67Jeff Bonwick		    BP_IS_GANG(bp) ? "gang" : "contiguous",		\
412b24ab67Jeff Bonwick		    BP_GET_DEDUP(bp) ? "dedup" : "unique",		\
413b24ab67Jeff Bonwick		    copyname[copies],					\
414b24ab67Jeff Bonwick		    ws,							\
415b24ab67Jeff Bonwick		    (u_longlong_t)BP_GET_LSIZE(bp),			\
416b24ab67Jeff Bonwick		    (u_longlong_t)BP_GET_PSIZE(bp),			\
417b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_birth,			\
418b24ab67Jeff Bonwick		    (u_longlong_t)BP_PHYSICAL_BIRTH(bp),		\
419b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_fill,				\
420b24ab67Jeff Bonwick		    ws,							\
421b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[0],		\
422b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[1],		\
423b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[2],		\
424b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[3]);		\
425b24ab67Jeff Bonwick	}								\
426b24ab67Jeff Bonwick	ASSERT(len < size);						\
427b24ab67Jeff Bonwick}
428b24ab67Jeff Bonwick
429fa9e406ahrens#include <sys/dmu.h>
431ad23a2djohansen#define	BP_GET_BUFC_TYPE(bp)						\
432ad135b5Christopher Siden	(((BP_GET_LEVEL(bp) > 0) || (DMU_OT_IS_METADATA(BP_GET_TYPE(bp)))) ? \
433ad135b5Christopher Siden	ARC_BUFC_METADATA : ARC_BUFC_DATA)
4351195e68Mark J Musantetypedef enum spa_import_type {
4361195e68Mark J Musante	SPA_IMPORT_EXISTING,
4371195e68Mark J Musante	SPA_IMPORT_ASSEMBLE
4381195e68Mark J Musante} spa_import_type_t;
4391195e68Mark J Musante
440fa9e406ahrens/* state manipulation functions */
441fa9e406ahrensextern int spa_open(const char *pool, spa_t **, void *tag);
442468c413Tim Haleyextern int spa_open_rewind(const char *pool, spa_t **, void *tag,
443468c413Tim Haley    nvlist_t *policy, nvlist_t **config);
444ad135b5Christopher Sidenextern int spa_get_stats(const char *pool, nvlist_t **config, char *altroot,
445ad135b5Christopher Siden    size_t buflen);
446990b485llingextern int spa_create(const char *pool, nvlist_t *config, nvlist_t *props,
4474445fffMatthew Ahrens    nvlist_t *zplprops);
448051aabetaylorextern int spa_import_rootpool(char *devpath, char *devid);
4494b964adGeorge Wilsonextern int spa_import(const char *pool, nvlist_t *config, nvlist_t *props,
4504b964adGeorge Wilson    uint64_t flags);
451fa9e406ahrensextern nvlist_t *spa_tryimport(nvlist_t *tryconfig);
452fa9e406ahrensextern int spa_destroy(char *pool);
453394ab0cGeorge Wilsonextern int spa_export(char *pool, nvlist_t **oldconfig, boolean_t force,
454394ab0cGeorge Wilson    boolean_t hardforce);
455ea8dc4beschrockextern int spa_reset(char *pool);
456ea8dc4beschrockextern void spa_async_request(spa_t *spa, int flag);
457088f389ahrensextern void spa_async_unrequest(spa_t *spa, int flag);
458ea8dc4beschrockextern void spa_async_suspend(spa_t *spa);
459ea8dc4beschrockextern void spa_async_resume(spa_t *spa);
460ea8dc4beschrockextern spa_t *spa_inject_addref(char *pool);
461ea8dc4beschrockextern void spa_inject_delref(spa_t *spa);
4623f9d6adLin Lingextern void spa_scan_stat_init(spa_t *spa);
4633f9d6adLin Lingextern int spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps);
465e14bb32Jeff Bonwick#define	SPA_ASYNC_CONFIG_UPDATE	0x01
466e14bb32Jeff Bonwick#define	SPA_ASYNC_REMOVE	0x02
467e14bb32Jeff Bonwick#define	SPA_ASYNC_PROBE		0x04
468e14bb32Jeff Bonwick#define	SPA_ASYNC_RESILVER_DONE	0x08
469e14bb32Jeff Bonwick#define	SPA_ASYNC_RESILVER	0x10
470573ca77George Wilson#define	SPA_ASYNC_AUTOEXPAND	0x20
4713f9d6adLin Ling#define	SPA_ASYNC_REMOVE_DONE	0x40
4723f9d6adLin Ling#define	SPA_ASYNC_REMOVE_STOP	0x80
4733f9d6adLin Ling
4743f9d6adLin Ling/*
4753f9d6adLin Ling * Controls the behavior of spa_vdev_remove().
4763f9d6adLin Ling */
4773f9d6adLin Ling#define	SPA_REMOVE_UNSPARE	0x01
4783f9d6adLin Ling#define	SPA_REMOVE_DONE		0x02
480fa9e406ahrens/* device manipulation */
481fa9e406ahrensextern int spa_vdev_add(spa_t *spa, nvlist_t *nvroot);
482ea8dc4beschrockextern int spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot,
483fa9e406ahrens    int replacing);
4848ad4d6dJeff Bonwickextern int spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid,
4858ad4d6dJeff Bonwick    int replace_done);
48699653d4eschrockextern int spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare);
4873f9d6adLin Lingextern boolean_t spa_vdev_remove_active(spa_t *spa);
488c67d967eschrockextern int spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath);
4896809eb4Eric Schrockextern int spa_vdev_setfru(spa_t *spa, uint64_t guid, const char *newfru);
4901195e68Mark J Musanteextern int spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
4911195e68Mark J Musante    nvlist_t *props, boolean_t exp);
49399653d4eschrock/* spare state (which is global across all pools) */
49439c2341eschrockextern void spa_spare_add(vdev_t *vd);
49539c2341eschrockextern void spa_spare_remove(vdev_t *vd);
49689a89ebllingextern boolean_t spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt);
49739c2341eschrockextern void spa_spare_activate(vdev_t *vd);
499fa94a07brendan/* L2ARC state (which is global across all pools) */
500fa94a07brendanextern void spa_l2cache_add(vdev_t *vd);
501fa94a07brendanextern void spa_l2cache_remove(vdev_t *vd);
502fa94a07brendanextern boolean_t spa_l2cache_exists(uint64_t guid, uint64_t *pool);
503fa94a07brendanextern void spa_l2cache_activate(vdev_t *vd);
504fa94a07brendanextern void spa_l2cache_drop(spa_t *spa);
5063f9d6adLin Ling/* scanning */
5073f9d6adLin Lingextern int spa_scan(spa_t *spa, pool_scan_func_t func);
5083f9d6adLin Lingextern int spa_scan_stop(spa_t *spa);
510fa9e406ahrens/* spa syncing */
511fa9e406ahrensextern void spa_sync(spa_t *spa, uint64_t txg); /* only for DMU use */
512fa9e406ahrensextern void spa_sync_allpools(void);
5143a737e0brendan/* spa namespace global mutex */
5153a737e0brendanextern kmutex_t spa_namespace_lock;
518fa9e406ahrens * SPA configuration functions in spa_config.c
519fa9e406ahrens */
5210373e76bonwick#define	SPA_CONFIG_UPDATE_POOL	0
5220373e76bonwick#define	SPA_CONFIG_UPDATE_VDEVS	1
524c5904d1eschrockextern void spa_config_sync(spa_t *, boolean_t, boolean_t);
525fa9e406ahrensextern void spa_config_load(void);
526fa9e406ahrensextern nvlist_t *spa_all_configs(uint64_t *);
527fa9e406ahrensextern void spa_config_set(spa_t *spa, nvlist_t *config);
528fa9e406ahrensextern nvlist_t *spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg,
529fa9e406ahrens    int getstats);
5300373e76bonwickextern void spa_config_update(spa_t *spa, int what);
533fa9e406ahrens * Miscellaneous SPA routines in spa_misc.c
534fa9e406ahrens */
536fa9e406ahrens/* Namespace manipulation */
537fa9e406ahrensextern spa_t *spa_lookup(const char *name);
538468c413Tim Haleyextern spa_t *spa_add(const char *name, nvlist_t *config, const char *altroot);
539fa9e406ahrensextern void spa_remove(spa_t *spa);
540fa9e406ahrensextern spa_t *spa_next(spa_t *prev);
542fa9e406ahrens/* Refcount functions */
543fa9e406ahrensextern void spa_open_ref(spa_t *spa, void *tag);
544fa9e406ahrensextern void spa_close(spa_t *spa, void *tag);
545fa9e406ahrensextern boolean_t spa_refcount_zero(spa_t *spa);
5478f18d1fGeorge Wilson#define	SCL_NONE	0x00
548e14bb32Jeff Bonwick#define	SCL_CONFIG	0x01
549e14bb32Jeff Bonwick#define	SCL_STATE	0x02
550e14bb32Jeff Bonwick#define	SCL_L2ARC	0x04		/* hack until L2ARC 2.0 */
551e14bb32Jeff Bonwick#define	SCL_ALLOC	0x08
552e14bb32Jeff Bonwick#define	SCL_ZIO		0x10
553e14bb32Jeff Bonwick#define	SCL_FREE	0x20
554e14bb32Jeff Bonwick#define	SCL_VDEV	0x40
555e14bb32Jeff Bonwick#define	SCL_LOCKS	7
556e14bb32Jeff Bonwick#define	SCL_ALL		((1 << SCL_LOCKS) - 1)
557e14bb32Jeff Bonwick#define	SCL_STATE_ALL	(SCL_STATE | SCL_L2ARC | SCL_ZIO)
558e14bb32Jeff Bonwick
559e14bb32Jeff Bonwick/* Pool configuration locks */
560e14bb32Jeff Bonwickextern int spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw);
561e14bb32Jeff Bonwickextern void spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw);
562e14bb32Jeff Bonwickextern void spa_config_exit(spa_t *spa, int locks, void *tag);
563e14bb32Jeff Bonwickextern int spa_config_held(spa_t *spa, int locks, krw_t rw);
565fa9e406ahrens/* Pool vdev add/remove lock */
566fa9e406ahrensextern uint64_t spa_vdev_enter(spa_t *spa);
56788ecc94George Wilsonextern uint64_t spa_vdev_config_enter(spa_t *spa);
56888ecc94George Wilsonextern void spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg,
56988ecc94George Wilson    int error, char *tag);
570fa9e406ahrensextern int spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error);
572e14bb32Jeff Bonwick/* Pool vdev state change lock */
5738f18d1fGeorge Wilsonextern void spa_vdev_state_enter(spa_t *spa, int oplock);
574e14bb32Jeff Bonwickextern int spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error);
575e14bb32Jeff Bonwick
576b24ab67Jeff Bonwick/* Log state */
577b24ab67Jeff Bonwicktypedef enum spa_log_state {
578b24ab67Jeff Bonwick	SPA_LOG_UNKNOWN = 0,	/* unknown log state */
579b24ab67Jeff Bonwick	SPA_LOG_MISSING,	/* missing log(s) */
580b24ab67Jeff Bonwick	SPA_LOG_CLEAR,		/* clear the log(s) */
581b24ab67Jeff Bonwick	SPA_LOG_GOOD,		/* log(s) are good */
582b24ab67Jeff Bonwick} spa_log_state_t;
583b24ab67Jeff Bonwick
584b24ab67Jeff Bonwickextern spa_log_state_t spa_get_log_state(spa_t *spa);
585b24ab67Jeff Bonwickextern void spa_set_log_state(spa_t *spa, spa_log_state_t state);
5861195e68Mark J Musanteextern int spa_offline_log(spa_t *spa);
587b24ab67Jeff Bonwick
588b24ab67Jeff Bonwick/* Log claim callback */
589b24ab67Jeff Bonwickextern void spa_claim_notify(zio_t *zio);
590b24ab67Jeff Bonwick
591fa9e406ahrens/* Accessor functions */
59288b7b0fMatthew Ahrensextern boolean_t spa_shutting_down(spa_t *spa);
593fa9e406ahrensextern struct dsl_pool *spa_get_dsl(spa_t *spa);
594ad135b5Christopher Sidenextern boolean_t spa_is_initializing(spa_t *spa);
595fa9e406ahrensextern blkptr_t *spa_get_rootblkptr(spa_t *spa);
596fa9e406ahrensextern void spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp);
597fa9e406ahrensextern void spa_altroot(spa_t *, char *, size_t);
598fa9e406ahrensextern int spa_sync_pass(spa_t *spa);
599fa9e406ahrensextern char *spa_name(spa_t *spa);
600fa9e406ahrensextern uint64_t spa_guid(spa_t *spa);
601e9103aaGarrett D'Amoreextern uint64_t spa_load_guid(spa_t *spa);
602fa9e406ahrensextern uint64_t spa_last_synced_txg(spa_t *spa);
603fa9e406ahrensextern uint64_t spa_first_txg(spa_t *spa);
604b24ab67Jeff Bonwickextern uint64_t spa_syncing_txg(spa_t *spa);
60599653d4eschrockextern uint64_t spa_version(spa_t *spa);
60688b7b0fMatthew Ahrensextern pool_state_t spa_state(spa_t *spa);
607b16da2eGeorge Wilsonextern spa_load_state_t spa_load_state(spa_t *spa);
608fa9e406ahrensextern uint64_t spa_freeze_txg(spa_t *spa);
609fa9e406ahrensextern uint64_t spa_get_asize(spa_t *spa, uint64_t lsize);
610485bbbfGeorge Wilsonextern uint64_t spa_get_dspace(spa_t *spa);
611485bbbfGeorge Wilsonextern void spa_update_dspace(spa_t *spa);
61244cd46cbillmextern uint64_t spa_version(spa_t *spa);
613b24ab67Jeff Bonwickextern boolean_t spa_deflate(spa_t *spa);
614b24ab67Jeff Bonwickextern metaslab_class_t *spa_normal_class(spa_t *spa);
615b24ab67Jeff Bonwickextern metaslab_class_t *spa_log_class(spa_t *spa);
61644cd46cbillmextern int spa_max_replication(spa_t *spa);
6173f9d6adLin Lingextern int spa_prev_software_version(spa_t *spa);
618fa9e406ahrensextern int spa_busy(void);
6190a4e951gwextern uint8_t spa_get_failmode(spa_t *spa);
620e14bb32Jeff Bonwickextern boolean_t spa_suspended(spa_t *spa);
621b24ab67Jeff Bonwickextern uint64_t spa_bootfs(spa_t *spa);
622b24ab67Jeff Bonwickextern uint64_t spa_delegation(spa_t *spa);
623b24ab67Jeff Bonwickextern objset_t *spa_meta_objset(spa_t *spa);
624283b846George.Wilsonextern uint64_t spa_deadman_synctime(spa_t *spa);
626fa9e406ahrens/* Miscellaneous support routines */
62743466aaMax Grossmanextern void spa_activate_mos_feature(spa_t *spa, const char *feature,
62843466aaMax Grossman    dmu_tx_t *tx);
629ad135b5Christopher Sidenextern void spa_deactivate_mos_feature(spa_t *spa, const char *feature);
630fa9e406ahrensextern int spa_rename(const char *oldname, const char *newname);
631f9af39bGeorge Wilsonextern spa_t *spa_by_guid(uint64_t pool_guid, uint64_t device_guid);
632fa9e406ahrensextern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid);
633fa9e406ahrensextern char *spa_strdup(const char *);
634fa9e406ahrensextern void spa_strfree(char *);
635fa9e406ahrensextern uint64_t spa_get_random(uint64_t range);
6361195e68Mark J Musanteextern uint64_t spa_generate_guid(spa_t *spa);
63743466aaMax Grossmanextern void snprintf_blkptr(char *buf, size_t buflen, const blkptr_t *bp);
638fa9e406ahrensextern void spa_freeze(spa_t *spa);
639e9103aaGarrett D'Amoreextern int spa_change_guid(spa_t *spa);
640990b485llingextern void spa_upgrade(spa_t *spa, uint64_t version);
641fa9e406ahrensextern void spa_evict_all(void);
642c5904d1eschrockextern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid,
643c5904d1eschrock    boolean_t l2cache);
64499653d4eschrockextern boolean_t spa_has_spare(spa_t *, uint64_t guid);
645b24ab67Jeff Bonwickextern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva);
646b24ab67Jeff Bonwickextern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp);
647b24ab67Jeff Bonwickextern uint64_t bp_get_dsize(spa_t *spa, const blkptr_t *bp);
6486ce0521perrinextern boolean_t spa_has_slogs(spa_t *spa);
649bf82a41eschrockextern boolean_t spa_is_root(spa_t *spa);
6508ad4d6dJeff Bonwickextern boolean_t spa_writeable(spa_t *spa);
651468c413Tim Haley
6528ad4d6dJeff Bonwickextern int spa_mode(spa_t *spa);
653ca45db4Chris Kirbyextern uint64_t strtonum(const char *str, char **nptr);
655ecd6cf8marksextern char *spa_his_ievent_table[];
65706eeb2aekextern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx);
65806eeb2aekextern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read,
65906eeb2aek    char *his_buf);
6604445fffMatthew Ahrensextern int spa_history_log(spa_t *spa, const char *his_buf);
6614445fffMatthew Ahrensextern int spa_history_log_nvl(spa_t *spa, nvlist_t *nvl);
6624445fffMatthew Ahrensextern void spa_history_log_version(spa_t *spa, const char *operation);
6634445fffMatthew Ahrensextern void spa_history_log_internal(spa_t *spa, const char *operation,
6644445fffMatthew Ahrens    dmu_tx_t *tx, const char *fmt, ...);
6654445fffMatthew Ahrensextern void spa_history_log_internal_ds(struct dsl_dataset *ds, const char *op,
6664445fffMatthew Ahrens    dmu_tx_t *tx, const char *fmt, ...);
6674445fffMatthew Ahrensextern void spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation,
6684445fffMatthew Ahrens    dmu_tx_t *tx, const char *fmt, ...);
670ea8dc4beschrock/* error handling */
671ea8dc4beschrockstruct zbookmark;
672b24ab67Jeff Bonwickextern void spa_log_error(spa_t *spa, zio_t *zio);
673ea8dc4beschrockextern void zfs_ereport_post(const char *class, spa_t *spa, vdev_t *vd,
674b24ab67Jeff Bonwick    zio_t *zio, uint64_t stateoroffset, uint64_t length);
6753d7072feschrockextern void zfs_post_remove(spa_t *spa, vdev_t *vd);
676069f55eEric Schrockextern void zfs_post_state_change(spa_t *spa, vdev_t *vd);
6773d7072feschrockextern void zfs_post_autoreplace(spa_t *spa, vdev_t *vd);
678ea8dc4beschrockextern uint64_t spa_get_errlog_size(spa_t *spa);
679ea8dc4beschrockextern int spa_get_errlog(spa_t *spa, void *uaddr, size_t *count);
680ea8dc4beschrockextern void spa_errlog_rotate(spa_t *spa);
681ea8dc4beschrockextern void spa_errlog_drain(spa_t *spa);
682ea8dc4beschrockextern void spa_errlog_sync(spa_t *spa, uint64_t txg);
683ea8dc4beschrockextern void spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub);
68587db74cek/* vdev cache */
68687db74cekextern void vdev_cache_stat_init(void);
68787db74cekextern void vdev_cache_stat_fini(void);
689fa9e406ahrens/* Initialization and termination */
690fa9e406ahrensextern void spa_init(int flags);
691fa9e406ahrensextern void spa_fini(void);
692e7cbe64gwextern void spa_boot_init();
694b1b8ab3lling/* properties */
695990b485llingextern int spa_prop_set(spa_t *spa, nvlist_t *nvp);
696990b485llingextern int spa_prop_get(spa_t *spa, nvlist_t **nvp);
697990b485llingextern void spa_prop_clear_bootfs(spa_t *spa, uint64_t obj, dmu_tx_t *tx);
698379c004Eric Schrockextern void spa_configfile_set(spa_t *, nvlist_t *, boolean_t);
7003d7072feschrock/* asynchronous event notification */
7013d7072feschrockextern void spa_event_notify(spa_t *spa, vdev_t *vdev, const char *name);
703fa9e406ahrens#ifdef ZFS_DEBUG
704c0a8126ek#define	dprintf_bp(bp, fmt, ...) do {				\
70543466aaMax Grossman	if (zfs_flags & ZFS_DEBUG_DPRINTF) {			\
706c0a8126ek	char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP);	\
70743466aaMax Grossman	snprintf_blkptr(__blkbuf, BP_SPRINTF_LEN, (bp));	\
708c0a8126ek	dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf);		\
709c0a8126ek	kmem_free(__blkbuf, BP_SPRINTF_LEN);			\
710fa9e406ahrens	} \
711fa9e406ahrens_NOTE(CONSTCOND) } while (0)
713fa9e406ahrens#define	dprintf_bp(bp, fmt, ...)
71609c9d37George Wilsonextern boolean_t spa_debug_enabled(spa_t *spa);
71709c9d37George Wilson#define	spa_dbgmsg(spa, ...)			\
71809c9d37George Wilson{						\
71909c9d37George Wilson	if (spa_debug_enabled(spa))		\
72009c9d37George Wilson		zfs_dbgmsg(__VA_ARGS__);	\
72109c9d37George Wilson}
72209c9d37George Wilson
7238ad4d6dJeff Bonwickextern int spa_mode_global;			/* mode, e.g. FREAD | FWRITE */
725fa9e406ahrens#ifdef	__cplusplus
729fa9e406ahrens#endif	/* _SYS_SPA_H */