spa.h revision e9103aaee0c546d4644791198c54abb03c89969e
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.
2309c9d37George Wilson * Copyright (c) 2011 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;
57fa9e406ahrens * General-purpose 32-bit and 64-bit bitfield encodings.
58fa9e406ahrens */
59fa9e406ahrens#define	BF32_DECODE(x, low, len)	P2PHASE((x) >> (low), 1U << (len))
60fa9e406ahrens#define	BF64_DECODE(x, low, len)	P2PHASE((x) >> (low), 1ULL << (len))
61fa9e406ahrens#define	BF32_ENCODE(x, low, len)	(P2PHASE((x), 1U << (len)) << (low))
62fa9e406ahrens#define	BF64_ENCODE(x, low, len)	(P2PHASE((x), 1ULL << (len)) << (low))
64fa9e406ahrens#define	BF32_GET(x, low, len)		BF32_DECODE(x, low, len)
65fa9e406ahrens#define	BF64_GET(x, low, len)		BF64_DECODE(x, low, len)
67fa9e406ahrens#define	BF32_SET(x, low, len, val)	\
685ad8204nd	((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len))
69fa9e406ahrens#define	BF64_SET(x, low, len, val)	\
705ad8204nd	((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len))
72fa9e406ahrens#define	BF32_GET_SB(x, low, len, shift, bias)	\
73fa9e406ahrens	((BF32_GET(x, low, len) + (bias)) << (shift))
74fa9e406ahrens#define	BF64_GET_SB(x, low, len, shift, bias)	\
75fa9e406ahrens	((BF64_GET(x, low, len) + (bias)) << (shift))
77fa9e406ahrens#define	BF32_SET_SB(x, low, len, shift, bias, val)	\
78fa9e406ahrens	BF32_SET(x, low, len, ((val) >> (shift)) - (bias))
79fa9e406ahrens#define	BF64_SET_SB(x, low, len, shift, bias, val)	\
80fa9e406ahrens	BF64_SET(x, low, len, ((val) >> (shift)) - (bias))
83fa9e406ahrens * We currently support nine block sizes, from 512 bytes to 128K.
84fa9e406ahrens * We could go higher, but the benefits are near-zero and the cost
85fa9e406ahrens * of COWing a giant block to modify one byte would become excessive.
86fa9e406ahrens */
87fa9e406ahrens#define	SPA_MINBLOCKSHIFT	9
88fa9e406ahrens#define	SPA_MAXBLOCKSHIFT	17
95f7991baTim Haley * Size of block to hold the configuration data (a packed nvlist)
96f7991baTim Haley */
97f7991baTim Haley#define	SPA_CONFIG_BLOCKSIZE	(1 << 14)
98f7991baTim Haley
99f7991baTim Haley/*
100fa9e406ahrens * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
101fa9e406ahrens * The ASIZE encoding should be at least 64 times larger (6 more bits)
102fa9e406ahrens * to support up to 4-way RAID-Z mirror mode with worst-case gang block
103fa9e406ahrens * overhead, three DVAs per bp, plus one more bit in case we do anything
104fa9e406ahrens * else that expands the ASIZE.
105fa9e406ahrens */
106fa9e406ahrens#define	SPA_LSIZEBITS		16	/* LSIZE up to 32M (2^16 * 512)	*/
107fa9e406ahrens#define	SPA_PSIZEBITS		16	/* PSIZE up to 32M (2^16 * 512)	*/
108fa9e406ahrens#define	SPA_ASIZEBITS		24	/* ASIZE up to 64 times larger	*/
111fa9e406ahrens * All SPA data is represented by 128-bit data virtual addresses (DVAs).
112fa9e406ahrens * The members of the dva_t should be considered opaque outside the SPA.
113fa9e406ahrens */
114fa9e406ahrenstypedef struct dva {
115fa9e406ahrens	uint64_t	dva_word[2];
116fa9e406ahrens} dva_t;
119fa9e406ahrens * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
120fa9e406ahrens */
121fa9e406ahrenstypedef struct zio_cksum {
122fa9e406ahrens	uint64_t	zc_word[4];
123fa9e406ahrens} zio_cksum_t;
126fa9e406ahrens * Each block is described by its DVAs, time of birth, checksum, etc.
127fa9e406ahrens * The word-by-word, bit-by-bit layout of the blkptr is as follows:
128fa9e406ahrens *
129fa9e406ahrens *	64	56	48	40	32	24	16	8	0
130fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
131fa9e406ahrens * 0	|		vdev1		| GRID  |	  ASIZE		|
132fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
133fa9e406ahrens * 1	|G|			 offset1				|
134fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
135fa9e406ahrens * 2	|		vdev2		| GRID  |	  ASIZE		|
136fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
137fa9e406ahrens * 3	|G|			 offset2				|
138fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
139fa9e406ahrens * 4	|		vdev3		| GRID  |	  ASIZE		|
140fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
141fa9e406ahrens * 5	|G|			 offset3				|
142fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
143b24ab67Jeff Bonwick * 6	|BDX|lvl| type	| cksum | comp	|     PSIZE	|     LSIZE	|
144fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
145fa9e406ahrens * 7	|			padding					|
146fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
147fa9e406ahrens * 8	|			padding					|
148fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
149b24ab67Jeff Bonwick * 9	|			physical birth txg			|
150fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
151b24ab67Jeff Bonwick * a	|			logical birth txg			|
152fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
153fa9e406ahrens * b	|			fill count				|
154fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
155fa9e406ahrens * c	|			checksum[0]				|
156fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
157fa9e406ahrens * d	|			checksum[1]				|
158fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
159fa9e406ahrens * e	|			checksum[2]				|
160fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
161fa9e406ahrens * f	|			checksum[3]				|
162fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
163fa9e406ahrens *
164fa9e406ahrens * Legend:
165fa9e406ahrens *
166fa9e406ahrens * vdev		virtual device ID
167fa9e406ahrens * offset	offset into virtual device
168fa9e406ahrens * LSIZE	logical size
169fa9e406ahrens * PSIZE	physical size (after compression)
170fa9e406ahrens * ASIZE	allocated size (including RAID-Z parity and gang block headers)
171fa9e406ahrens * GRID		RAID-Z layout information (reserved for future use)
172fa9e406ahrens * cksum	checksum function
173fa9e406ahrens * comp		compression function
174fa9e406ahrens * G		gang block indicator
175b24ab67Jeff Bonwick * B		byteorder (endianness)
176b24ab67Jeff Bonwick * D		dedup
177b24ab67Jeff Bonwick * X		unused
178fa9e406ahrens * lvl		level of indirection
179b24ab67Jeff Bonwick * type		DMU object type
180b24ab67Jeff Bonwick * phys birth	txg of block allocation; zero if same as logical birth txg
181b24ab67Jeff Bonwick * log. birth	transaction group in which the block was logically born
182fa9e406ahrens * fill count	number of non-zero blocks under this bp
183fa9e406ahrens * checksum[4]	256-bit checksum of the data this bp describes
184fa9e406ahrens */
185fa9e406ahrens#define	SPA_BLKPTRSHIFT	7		/* blkptr_t is 128 bytes	*/
186fa9e406ahrens#define	SPA_DVAS_PER_BP	3		/* Number of DVAs in a bp	*/
188b24ab67Jeff Bonwicktypedef struct blkptr {
189b24ab67Jeff Bonwick	dva_t		blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */
190b24ab67Jeff Bonwick	uint64_t	blk_prop;	/* size, compression, type, etc	    */
191b24ab67Jeff Bonwick	uint64_t	blk_pad[2];	/* Extra space for the future	    */
192b24ab67Jeff Bonwick	uint64_t	blk_phys_birth;	/* txg when block was allocated	    */
193b24ab67Jeff Bonwick	uint64_t	blk_birth;	/* transaction group at birth	    */
194b24ab67Jeff Bonwick	uint64_t	blk_fill;	/* fill count			    */
195b24ab67Jeff Bonwick	zio_cksum_t	blk_cksum;	/* 256-bit checksum		    */
196b24ab67Jeff Bonwick} blkptr_t;
197b24ab67Jeff Bonwick
199fa9e406ahrens * Macros to get and set fields in a bp or DVA.
200fa9e406ahrens */
201fa9e406ahrens#define	DVA_GET_ASIZE(dva)	\
202fa9e406ahrens	BF64_GET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0)
203fa9e406ahrens#define	DVA_SET_ASIZE(dva, x)	\
204fa9e406ahrens	BF64_SET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0, x)
206fa9e406ahrens#define	DVA_GET_GRID(dva)	BF64_GET((dva)->dva_word[0], 24, 8)
207fa9e406ahrens#define	DVA_SET_GRID(dva, x)	BF64_SET((dva)->dva_word[0], 24, 8, x)
209fa9e406ahrens#define	DVA_GET_VDEV(dva)	BF64_GET((dva)->dva_word[0], 32, 32)
210fa9e406ahrens#define	DVA_SET_VDEV(dva, x)	BF64_SET((dva)->dva_word[0], 32, 32, x)
212fa9e406ahrens#define	DVA_GET_OFFSET(dva)	\
213fa9e406ahrens	BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0)
214fa9e406ahrens#define	DVA_SET_OFFSET(dva, x)	\
215fa9e406ahrens	BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x)
217fa9e406ahrens#define	DVA_GET_GANG(dva)	BF64_GET((dva)->dva_word[1], 63, 1)
218fa9e406ahrens#define	DVA_SET_GANG(dva, x)	BF64_SET((dva)->dva_word[1], 63, 1, x)
220fa9e406ahrens#define	BP_GET_LSIZE(bp)	\
221975c32aNeil Perrin	BF64_GET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1)
222fa9e406ahrens#define	BP_SET_LSIZE(bp, x)	\
223fa9e406ahrens	BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
225fa9e406ahrens#define	BP_GET_PSIZE(bp)	\
226fa9e406ahrens	BF64_GET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1)
227fa9e406ahrens#define	BP_SET_PSIZE(bp, x)	\
228fa9e406ahrens	BF64_SET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1, x)
230b24ab67Jeff Bonwick#define	BP_GET_COMPRESS(bp)		BF64_GET((bp)->blk_prop, 32, 8)
231b24ab67Jeff Bonwick#define	BP_SET_COMPRESS(bp, x)		BF64_SET((bp)->blk_prop, 32, 8, x)
232b24ab67Jeff Bonwick
233b24ab67Jeff Bonwick#define	BP_GET_CHECKSUM(bp)		BF64_GET((bp)->blk_prop, 40, 8)
234b24ab67Jeff Bonwick#define	BP_SET_CHECKSUM(bp, x)		BF64_SET((bp)->blk_prop, 40, 8, x)
235b24ab67Jeff Bonwick
236b24ab67Jeff Bonwick#define	BP_GET_TYPE(bp)			BF64_GET((bp)->blk_prop, 48, 8)
237b24ab67Jeff Bonwick#define	BP_SET_TYPE(bp, x)		BF64_SET((bp)->blk_prop, 48, 8, x)
239b24ab67Jeff Bonwick#define	BP_GET_LEVEL(bp)		BF64_GET((bp)->blk_prop, 56, 5)
240b24ab67Jeff Bonwick#define	BP_SET_LEVEL(bp, x)		BF64_SET((bp)->blk_prop, 56, 5, x)
242b24ab67Jeff Bonwick#define	BP_GET_PROP_BIT_61(bp)		BF64_GET((bp)->blk_prop, 61, 1)
243b24ab67Jeff Bonwick#define	BP_SET_PROP_BIT_61(bp, x)	BF64_SET((bp)->blk_prop, 61, 1, x)
245b24ab67Jeff Bonwick#define	BP_GET_DEDUP(bp)		BF64_GET((bp)->blk_prop, 62, 1)
246b24ab67Jeff Bonwick#define	BP_SET_DEDUP(bp, x)		BF64_SET((bp)->blk_prop, 62, 1, x)
248b24ab67Jeff Bonwick#define	BP_GET_BYTEORDER(bp)		(0 - BF64_GET((bp)->blk_prop, 63, 1))
249b24ab67Jeff Bonwick#define	BP_SET_BYTEORDER(bp, x)		BF64_SET((bp)->blk_prop, 63, 1, x)
250b24ab67Jeff Bonwick
251b24ab67Jeff Bonwick#define	BP_PHYSICAL_BIRTH(bp)		\
252b24ab67Jeff Bonwick	((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)
253b24ab67Jeff Bonwick
254b24ab67Jeff Bonwick#define	BP_SET_BIRTH(bp, logical, physical)	\
255b24ab67Jeff Bonwick{						\
256b24ab67Jeff Bonwick	(bp)->blk_birth = (logical);		\
257b24ab67Jeff Bonwick	(bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \
258b24ab67Jeff Bonwick}
260fa9e406ahrens#define	BP_GET_ASIZE(bp)	\
261fa9e406ahrens	(DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
26299653d4eschrock		DVA_GET_ASIZE(&(bp)->blk_dva[2]))
26499653d4eschrock#define	BP_GET_UCSIZE(bp) \
26599653d4eschrock	((BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) ? \
2663f9d6adLin Ling	BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp))
26844cd46cbillm#define	BP_GET_NDVAS(bp)	\
26944cd46cbillm	(!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
27044cd46cbillm	!!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
27144cd46cbillm	!!DVA_GET_ASIZE(&(bp)->blk_dva[2]))
27344cd46cbillm#define	BP_COUNT_GANG(bp)	\
27444cd46cbillm	(DVA_GET_GANG(&(bp)->blk_dva[0]) + \
27544cd46cbillm	DVA_GET_GANG(&(bp)->blk_dva[1]) + \
27644cd46cbillm	DVA_GET_GANG(&(bp)->blk_dva[2]))
278fa9e406ahrens#define	DVA_EQUAL(dva1, dva2)	\
279fa9e406ahrens	((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
280fa9e406ahrens	(dva1)->dva_word[0] == (dva2)->dva_word[0])
282b24ab67Jeff Bonwick#define	BP_EQUAL(bp1, bp2)	\
283b24ab67Jeff Bonwick	(BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) &&	\
284b24ab67Jeff Bonwick	DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) &&	\
285b24ab67Jeff Bonwick	DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) &&	\
286b24ab67Jeff Bonwick	DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2]))
287b24ab67Jeff Bonwick
2886b4acc8ahrens#define	ZIO_CHECKSUM_EQUAL(zc1, zc2) \
2896b4acc8ahrens	(0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
2906b4acc8ahrens	((zc1).zc_word[1] - (zc2).zc_word[1]) | \
2916b4acc8ahrens	((zc1).zc_word[2] - (zc2).zc_word[2]) | \
2926b4acc8ahrens	((zc1).zc_word[3] - (zc2).zc_word[3])))
294fa9e406ahrens#define	DVA_IS_VALID(dva)	(DVA_GET_ASIZE(dva) != 0)
296fa9e406ahrens#define	ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3)	\
297fa9e406ahrens{						\
298fa9e406ahrens	(zcp)->zc_word[0] = w0;			\
299fa9e406ahrens	(zcp)->zc_word[1] = w1;			\
300fa9e406ahrens	(zcp)->zc_word[2] = w2;			\
301fa9e406ahrens	(zcp)->zc_word[3] = w3;			\
304fa9e406ahrens#define	BP_IDENTITY(bp)		(&(bp)->blk_dva[0])
30544cd46cbillm#define	BP_IS_GANG(bp)		DVA_GET_GANG(BP_IDENTITY(bp))
30644cd46cbillm#define	BP_IS_HOLE(bp)		((bp)->blk_birth == 0)
3086e1f5caNeil Perrin/* BP_IS_RAIDZ(bp) assumes no block compression */
3096e1f5caNeil Perrin#define	BP_IS_RAIDZ(bp)		(DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \
3106e1f5caNeil Perrin				BP_GET_PSIZE(bp))
3116e1f5caNeil Perrin
312e14bb32Jeff Bonwick#define	BP_ZERO(bp)				\
313fa9e406ahrens{						\
314fa9e406ahrens	(bp)->blk_dva[0].dva_word[0] = 0;	\
315fa9e406ahrens	(bp)->blk_dva[0].dva_word[1] = 0;	\
316fa9e406ahrens	(bp)->blk_dva[1].dva_word[0] = 0;	\
317fa9e406ahrens	(bp)->blk_dva[1].dva_word[1] = 0;	\
318fa9e406ahrens	(bp)->blk_dva[2].dva_word[0] = 0;	\
319fa9e406ahrens	(bp)->blk_dva[2].dva_word[1] = 0;	\
320fa9e406ahrens	(bp)->blk_prop = 0;			\
321fa9e406ahrens	(bp)->blk_pad[0] = 0;			\
322fa9e406ahrens	(bp)->blk_pad[1] = 0;			\
323b24ab67Jeff Bonwick	(bp)->blk_phys_birth = 0;		\
324e14bb32Jeff Bonwick	(bp)->blk_birth = 0;			\
325fa9e406ahrens	(bp)->blk_fill = 0;			\
326fa9e406ahrens	ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0);	\
330fa9e406ahrens * Note: the byteorder is either 0 or -1, both of which are palindromes.
331fa9e406ahrens * This simplifies the endianness handling a bit.
332fa9e406ahrens */
333fa9e406ahrens#ifdef _BIG_ENDIAN
334fa9e406ahrens#define	ZFS_HOST_BYTEORDER	(0ULL)
336fa9e406ahrens#define	ZFS_HOST_BYTEORDER	(-1ULL)
34144cd46cbillm#define	BP_SPRINTF_LEN	320
343b24ab67Jeff Bonwick/*
344b24ab67Jeff Bonwick * This macro allows code sharing between zfs, libzpool, and mdb.
345b24ab67Jeff Bonwick * 'func' is either snprintf() or mdb_snprintf().
346b24ab67Jeff Bonwick * 'ws' (whitespace) can be ' ' for single-line format, '\n' for multi-line.
347b24ab67Jeff Bonwick */
348b24ab67Jeff Bonwick#define	SPRINTF_BLKPTR(func, ws, buf, bp, type, checksum, compress)	\
349b24ab67Jeff Bonwick{									\
350b24ab67Jeff Bonwick	static const char *copyname[] =					\
351b24ab67Jeff Bonwick	    { "zero", "single", "double", "triple" };			\
352b24ab67Jeff Bonwick	int size = BP_SPRINTF_LEN;					\
353b24ab67Jeff Bonwick	int len = 0;							\
354b24ab67Jeff Bonwick	int copies = 0;							\
355b24ab67Jeff Bonwick									\
356b24ab67Jeff Bonwick	if (bp == NULL) {						\
357b24ab67Jeff Bonwick		len = func(buf + len, size - len, "<NULL>");		\
358b24ab67Jeff Bonwick	} else if (BP_IS_HOLE(bp)) {					\
359b24ab67Jeff Bonwick		len = func(buf + len, size - len, "<hole>");		\
360b24ab67Jeff Bonwick	} else {							\
361b24ab67Jeff Bonwick		for (int d = 0; d < BP_GET_NDVAS(bp); d++) {		\
362b24ab67Jeff Bonwick			const dva_t *dva = &bp->blk_dva[d];		\
363b24ab67Jeff Bonwick			if (DVA_IS_VALID(dva))				\
364b24ab67Jeff Bonwick				copies++;				\
365b24ab67Jeff Bonwick			len += func(buf + len, size - len,		\
366b24ab67Jeff Bonwick			    "DVA[%d]=<%llu:%llx:%llx>%c", d,		\
367b24ab67Jeff Bonwick			    (u_longlong_t)DVA_GET_VDEV(dva),		\
368b24ab67Jeff Bonwick			    (u_longlong_t)DVA_GET_OFFSET(dva),		\
369b24ab67Jeff Bonwick			    (u_longlong_t)DVA_GET_ASIZE(dva),		\
370b24ab67Jeff Bonwick			    ws);					\
371b24ab67Jeff Bonwick		}							\
372b24ab67Jeff Bonwick		if (BP_IS_GANG(bp) &&					\
373b24ab67Jeff Bonwick		    DVA_GET_ASIZE(&bp->blk_dva[2]) <=			\
374b24ab67Jeff Bonwick		    DVA_GET_ASIZE(&bp->blk_dva[1]) / 2)			\
375b24ab67Jeff Bonwick			copies--;					\
376b24ab67Jeff Bonwick		len += func(buf + len, size - len,			\
377b24ab67Jeff Bonwick		    "[L%llu %s] %s %s %s %s %s %s%c"			\
378b24ab67Jeff Bonwick		    "size=%llxL/%llxP birth=%lluL/%lluP fill=%llu%c"	\
379b24ab67Jeff Bonwick		    "cksum=%llx:%llx:%llx:%llx",			\
380b24ab67Jeff Bonwick		    (u_longlong_t)BP_GET_LEVEL(bp),			\
381b24ab67Jeff Bonwick		    type,						\
382b24ab67Jeff Bonwick		    checksum,						\
383b24ab67Jeff Bonwick		    compress,						\
384b24ab67Jeff Bonwick		    BP_GET_BYTEORDER(bp) == 0 ? "BE" : "LE",		\
385b24ab67Jeff Bonwick		    BP_IS_GANG(bp) ? "gang" : "contiguous",		\
386b24ab67Jeff Bonwick		    BP_GET_DEDUP(bp) ? "dedup" : "unique",		\
387b24ab67Jeff Bonwick		    copyname[copies],					\
388b24ab67Jeff Bonwick		    ws,							\
389b24ab67Jeff Bonwick		    (u_longlong_t)BP_GET_LSIZE(bp),			\
390b24ab67Jeff Bonwick		    (u_longlong_t)BP_GET_PSIZE(bp),			\
391b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_birth,			\
392b24ab67Jeff Bonwick		    (u_longlong_t)BP_PHYSICAL_BIRTH(bp),		\
393b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_fill,				\
394b24ab67Jeff Bonwick		    ws,							\
395b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[0],		\
396b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[1],		\
397b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[2],		\
398b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[3]);		\
399b24ab67Jeff Bonwick	}								\
400b24ab67Jeff Bonwick	ASSERT(len < size);						\
401b24ab67Jeff Bonwick}
402b24ab67Jeff Bonwick
403fa9e406ahrens#include <sys/dmu.h>
405ad23a2djohansen#define	BP_GET_BUFC_TYPE(bp)						\
406ad23a2djohansen	(((BP_GET_LEVEL(bp) > 0) || (dmu_ot[BP_GET_TYPE(bp)].ot_metadata)) ? \
407ad23a2djohansen	ARC_BUFC_METADATA : ARC_BUFC_DATA);
4091195e68Mark J Musantetypedef enum spa_import_type {
4101195e68Mark J Musante	SPA_IMPORT_EXISTING,
4111195e68Mark J Musante	SPA_IMPORT_ASSEMBLE
4121195e68Mark J Musante} spa_import_type_t;
4131195e68Mark J Musante
414fa9e406ahrens/* state manipulation functions */
415fa9e406ahrensextern int spa_open(const char *pool, spa_t **, void *tag);
416468c413Tim Haleyextern int spa_open_rewind(const char *pool, spa_t **, void *tag,
417468c413Tim Haley    nvlist_t *policy, nvlist_t **config);
418ea8dc4beschrockextern int spa_get_stats(const char *pool, nvlist_t **config,
419ea8dc4beschrock    char *altroot, size_t buflen);
420990b485llingextern int spa_create(const char *pool, nvlist_t *config, nvlist_t *props,
4210a48a24timh    const char *history_str, nvlist_t *zplprops);
422051aabetaylorextern int spa_import_rootpool(char *devpath, char *devid);
4234b964adGeorge Wilsonextern int spa_import(const char *pool, nvlist_t *config, nvlist_t *props,
4244b964adGeorge Wilson    uint64_t flags);
425fa9e406ahrensextern nvlist_t *spa_tryimport(nvlist_t *tryconfig);
426fa9e406ahrensextern int spa_destroy(char *pool);
427394ab0cGeorge Wilsonextern int spa_export(char *pool, nvlist_t **oldconfig, boolean_t force,
428394ab0cGeorge Wilson    boolean_t hardforce);
429ea8dc4beschrockextern int spa_reset(char *pool);
430ea8dc4beschrockextern void spa_async_request(spa_t *spa, int flag);
431088f389ahrensextern void spa_async_unrequest(spa_t *spa, int flag);
432ea8dc4beschrockextern void spa_async_suspend(spa_t *spa);
433ea8dc4beschrockextern void spa_async_resume(spa_t *spa);
434ea8dc4beschrockextern spa_t *spa_inject_addref(char *pool);
435ea8dc4beschrockextern void spa_inject_delref(spa_t *spa);
4363f9d6adLin Lingextern void spa_scan_stat_init(spa_t *spa);
4373f9d6adLin Lingextern int spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps);
439e14bb32Jeff Bonwick#define	SPA_ASYNC_CONFIG_UPDATE	0x01
440e14bb32Jeff Bonwick#define	SPA_ASYNC_REMOVE	0x02
441e14bb32Jeff Bonwick#define	SPA_ASYNC_PROBE		0x04
442e14bb32Jeff Bonwick#define	SPA_ASYNC_RESILVER_DONE	0x08
443e14bb32Jeff Bonwick#define	SPA_ASYNC_RESILVER	0x10
444573ca77George Wilson#define	SPA_ASYNC_AUTOEXPAND	0x20
4453f9d6adLin Ling#define	SPA_ASYNC_REMOVE_DONE	0x40
4463f9d6adLin Ling#define	SPA_ASYNC_REMOVE_STOP	0x80
4473f9d6adLin Ling
4483f9d6adLin Ling/*
4493f9d6adLin Ling * Controls the behavior of spa_vdev_remove().
4503f9d6adLin Ling */
4513f9d6adLin Ling#define	SPA_REMOVE_UNSPARE	0x01
4523f9d6adLin Ling#define	SPA_REMOVE_DONE		0x02
454fa9e406ahrens/* device manipulation */
455fa9e406ahrensextern int spa_vdev_add(spa_t *spa, nvlist_t *nvroot);
456ea8dc4beschrockextern int spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot,
457fa9e406ahrens    int replacing);
4588ad4d6dJeff Bonwickextern int spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid,
4598ad4d6dJeff Bonwick    int replace_done);
46099653d4eschrockextern int spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare);
4613f9d6adLin Lingextern boolean_t spa_vdev_remove_active(spa_t *spa);
462c67d967eschrockextern int spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath);
4636809eb4Eric Schrockextern int spa_vdev_setfru(spa_t *spa, uint64_t guid, const char *newfru);
4641195e68Mark J Musanteextern int spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
4651195e68Mark J Musante    nvlist_t *props, boolean_t exp);
46799653d4eschrock/* spare state (which is global across all pools) */
46839c2341eschrockextern void spa_spare_add(vdev_t *vd);
46939c2341eschrockextern void spa_spare_remove(vdev_t *vd);
47089a89ebllingextern boolean_t spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt);
47139c2341eschrockextern void spa_spare_activate(vdev_t *vd);
473fa94a07brendan/* L2ARC state (which is global across all pools) */
474fa94a07brendanextern void spa_l2cache_add(vdev_t *vd);
475fa94a07brendanextern void spa_l2cache_remove(vdev_t *vd);
476fa94a07brendanextern boolean_t spa_l2cache_exists(uint64_t guid, uint64_t *pool);
477fa94a07brendanextern void spa_l2cache_activate(vdev_t *vd);
478fa94a07brendanextern void spa_l2cache_drop(spa_t *spa);
4803f9d6adLin Ling/* scanning */
4813f9d6adLin Lingextern int spa_scan(spa_t *spa, pool_scan_func_t func);
4823f9d6adLin Lingextern int spa_scan_stop(spa_t *spa);
484fa9e406ahrens/* spa syncing */
485fa9e406ahrensextern void spa_sync(spa_t *spa, uint64_t txg); /* only for DMU use */
486fa9e406ahrensextern void spa_sync_allpools(void);
4883f9d6adLin Ling/*
4893f9d6adLin Ling * DEFERRED_FREE must be large enough that regular blocks are not
4903f9d6adLin Ling * deferred.  XXX so can't we change it back to 1?
4913f9d6adLin Ling */
4923f9d6adLin Ling#define	SYNC_PASS_DEFERRED_FREE	2	/* defer frees after this pass */
493b24ab67Jeff Bonwick#define	SYNC_PASS_DONT_COMPRESS	4	/* don't compress after this pass */
494b24ab67Jeff Bonwick#define	SYNC_PASS_REWRITE	1	/* rewrite new bps after this pass */
495b24ab67Jeff Bonwick
4963a737e0brendan/* spa namespace global mutex */
4973a737e0brendanextern kmutex_t spa_namespace_lock;
500fa9e406ahrens * SPA configuration functions in spa_config.c
501fa9e406ahrens */
5030373e76bonwick#define	SPA_CONFIG_UPDATE_POOL	0
5040373e76bonwick#define	SPA_CONFIG_UPDATE_VDEVS	1
506c5904d1eschrockextern void spa_config_sync(spa_t *, boolean_t, boolean_t);
507fa9e406ahrensextern void spa_config_load(void);
508fa9e406ahrensextern nvlist_t *spa_all_configs(uint64_t *);
509fa9e406ahrensextern void spa_config_set(spa_t *spa, nvlist_t *config);
510fa9e406ahrensextern nvlist_t *spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg,
511fa9e406ahrens    int getstats);
5120373e76bonwickextern void spa_config_update(spa_t *spa, int what);
515fa9e406ahrens * Miscellaneous SPA routines in spa_misc.c
516fa9e406ahrens */
518fa9e406ahrens/* Namespace manipulation */
519fa9e406ahrensextern spa_t *spa_lookup(const char *name);
520468c413Tim Haleyextern spa_t *spa_add(const char *name, nvlist_t *config, const char *altroot);
521fa9e406ahrensextern void spa_remove(spa_t *spa);
522fa9e406ahrensextern spa_t *spa_next(spa_t *prev);
524fa9e406ahrens/* Refcount functions */
525fa9e406ahrensextern void spa_open_ref(spa_t *spa, void *tag);
526fa9e406ahrensextern void spa_close(spa_t *spa, void *tag);
527fa9e406ahrensextern boolean_t spa_refcount_zero(spa_t *spa);
5298f18d1fGeorge Wilson#define	SCL_NONE	0x00
530e14bb32Jeff Bonwick#define	SCL_CONFIG	0x01
531e14bb32Jeff Bonwick#define	SCL_STATE	0x02
532e14bb32Jeff Bonwick#define	SCL_L2ARC	0x04		/* hack until L2ARC 2.0 */
533e14bb32Jeff Bonwick#define	SCL_ALLOC	0x08
534e14bb32Jeff Bonwick#define	SCL_ZIO		0x10
535e14bb32Jeff Bonwick#define	SCL_FREE	0x20
536e14bb32Jeff Bonwick#define	SCL_VDEV	0x40
537e14bb32Jeff Bonwick#define	SCL_LOCKS	7
538e14bb32Jeff Bonwick#define	SCL_ALL		((1 << SCL_LOCKS) - 1)
539e14bb32Jeff Bonwick#define	SCL_STATE_ALL	(SCL_STATE | SCL_L2ARC | SCL_ZIO)
540e14bb32Jeff Bonwick
541e14bb32Jeff Bonwick/* Pool configuration locks */
542e14bb32Jeff Bonwickextern int spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw);
543e14bb32Jeff Bonwickextern void spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw);
544e14bb32Jeff Bonwickextern void spa_config_exit(spa_t *spa, int locks, void *tag);
545e14bb32Jeff Bonwickextern int spa_config_held(spa_t *spa, int locks, krw_t rw);
547fa9e406ahrens/* Pool vdev add/remove lock */
548fa9e406ahrensextern uint64_t spa_vdev_enter(spa_t *spa);
54988ecc94George Wilsonextern uint64_t spa_vdev_config_enter(spa_t *spa);
55088ecc94George Wilsonextern void spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg,
55188ecc94George Wilson    int error, char *tag);
552fa9e406ahrensextern int spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error);
554e14bb32Jeff Bonwick/* Pool vdev state change lock */
5558f18d1fGeorge Wilsonextern void spa_vdev_state_enter(spa_t *spa, int oplock);
556e14bb32Jeff Bonwickextern int spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error);
557e14bb32Jeff Bonwick
558b24ab67Jeff Bonwick/* Log state */
559b24ab67Jeff Bonwicktypedef enum spa_log_state {
560b24ab67Jeff Bonwick	SPA_LOG_UNKNOWN = 0,	/* unknown log state */
561b24ab67Jeff Bonwick	SPA_LOG_MISSING,	/* missing log(s) */
562b24ab67Jeff Bonwick	SPA_LOG_CLEAR,		/* clear the log(s) */
563b24ab67Jeff Bonwick	SPA_LOG_GOOD,		/* log(s) are good */
564b24ab67Jeff Bonwick} spa_log_state_t;
565b24ab67Jeff Bonwick
566b24ab67Jeff Bonwickextern spa_log_state_t spa_get_log_state(spa_t *spa);
567b24ab67Jeff Bonwickextern void spa_set_log_state(spa_t *spa, spa_log_state_t state);
5681195e68Mark J Musanteextern int spa_offline_log(spa_t *spa);
569b24ab67Jeff Bonwick
570b24ab67Jeff Bonwick/* Log claim callback */
571b24ab67Jeff Bonwickextern void spa_claim_notify(zio_t *zio);
572b24ab67Jeff Bonwick
573fa9e406ahrens/* Accessor functions */
57488b7b0fMatthew Ahrensextern boolean_t spa_shutting_down(spa_t *spa);
575fa9e406ahrensextern struct dsl_pool *spa_get_dsl(spa_t *spa);
576fa9e406ahrensextern blkptr_t *spa_get_rootblkptr(spa_t *spa);
577fa9e406ahrensextern void spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp);
578fa9e406ahrensextern void spa_altroot(spa_t *, char *, size_t);
579fa9e406ahrensextern int spa_sync_pass(spa_t *spa);
580fa9e406ahrensextern char *spa_name(spa_t *spa);
581fa9e406ahrensextern uint64_t spa_guid(spa_t *spa);
582e9103aaGarrett D'Amoreextern uint64_t spa_load_guid(spa_t *spa);
583fa9e406ahrensextern uint64_t spa_last_synced_txg(spa_t *spa);
584fa9e406ahrensextern uint64_t spa_first_txg(spa_t *spa);
585b24ab67Jeff Bonwickextern uint64_t spa_syncing_txg(spa_t *spa);
58699653d4eschrockextern uint64_t spa_version(spa_t *spa);
58788b7b0fMatthew Ahrensextern pool_state_t spa_state(spa_t *spa);
588b16da2eGeorge Wilsonextern spa_load_state_t spa_load_state(spa_t *spa);
589fa9e406ahrensextern uint64_t spa_freeze_txg(spa_t *spa);
590fa9e406ahrensextern uint64_t spa_get_asize(spa_t *spa, uint64_t lsize);
591485bbbfGeorge Wilsonextern uint64_t spa_get_dspace(spa_t *spa);
592485bbbfGeorge Wilsonextern void spa_update_dspace(spa_t *spa);
59344cd46cbillmextern uint64_t spa_version(spa_t *spa);
594b24ab67Jeff Bonwickextern boolean_t spa_deflate(spa_t *spa);
595b24ab67Jeff Bonwickextern metaslab_class_t *spa_normal_class(spa_t *spa);
596b24ab67Jeff Bonwickextern metaslab_class_t *spa_log_class(spa_t *spa);
59744cd46cbillmextern int spa_max_replication(spa_t *spa);
5983f9d6adLin Lingextern int spa_prev_software_version(spa_t *spa);
599fa9e406ahrensextern int spa_busy(void);
6000a4e951gwextern uint8_t spa_get_failmode(spa_t *spa);
601e14bb32Jeff Bonwickextern boolean_t spa_suspended(spa_t *spa);
602b24ab67Jeff Bonwickextern uint64_t spa_bootfs(spa_t *spa);
603b24ab67Jeff Bonwickextern uint64_t spa_delegation(spa_t *spa);
604b24ab67Jeff Bonwickextern objset_t *spa_meta_objset(spa_t *spa);
606fa9e406ahrens/* Miscellaneous support routines */
607fa9e406ahrensextern int spa_rename(const char *oldname, const char *newname);
608f9af39bGeorge Wilsonextern spa_t *spa_by_guid(uint64_t pool_guid, uint64_t device_guid);
609fa9e406ahrensextern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid);
610fa9e406ahrensextern char *spa_strdup(const char *);
611fa9e406ahrensextern void spa_strfree(char *);
612fa9e406ahrensextern uint64_t spa_get_random(uint64_t range);
6131195e68Mark J Musanteextern uint64_t spa_generate_guid(spa_t *spa);
614b24ab67Jeff Bonwickextern void sprintf_blkptr(char *buf, const blkptr_t *bp);
615fa9e406ahrensextern void spa_freeze(spa_t *spa);
616e9103aaGarrett D'Amoreextern int spa_change_guid(spa_t *spa);
617990b485llingextern void spa_upgrade(spa_t *spa, uint64_t version);
618fa9e406ahrensextern void spa_evict_all(void);
619c5904d1eschrockextern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid,
620c5904d1eschrock    boolean_t l2cache);
62199653d4eschrockextern boolean_t spa_has_spare(spa_t *, uint64_t guid);
622b24ab67Jeff Bonwickextern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva);
623b24ab67Jeff Bonwickextern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp);
624b24ab67Jeff Bonwickextern uint64_t bp_get_dsize(spa_t *spa, const blkptr_t *bp);
6256ce0521perrinextern boolean_t spa_has_slogs(spa_t *spa);
626bf82a41eschrockextern boolean_t spa_is_root(spa_t *spa);
6278ad4d6dJeff Bonwickextern boolean_t spa_writeable(spa_t *spa);
628468c413Tim Haley
6298ad4d6dJeff Bonwickextern int spa_mode(spa_t *spa);
630ca45db4Chris Kirbyextern uint64_t strtonum(const char *str, char **nptr);
63206eeb2aek/* history logging */
633ecd6cf8markstypedef enum history_log_type {
634ecd6cf8marks	LOG_CMD_POOL_CREATE,
635ecd6cf8marks	LOG_CMD_NORMAL,
636ecd6cf8marks	LOG_INTERNAL
637ecd6cf8marks} history_log_type_t;
639ecd6cf8markstypedef struct history_arg {
640495807dMatthew Ahrens	char *ha_history_str;
641ecd6cf8marks	history_log_type_t ha_log_type;
642ecd6cf8marks	history_internal_events_t ha_event;
643495807dMatthew Ahrens	char *ha_zone;
644495807dMatthew Ahrens	uid_t ha_uid;
645ecd6cf8marks} history_arg_t;
647ecd6cf8marksextern char *spa_his_ievent_table[];
64906eeb2aekextern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx);
65006eeb2aekextern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read,
65106eeb2aek    char *his_buf);
65206eeb2aekextern int spa_history_log(spa_t *spa, const char *his_buf,
653ecd6cf8marks    history_log_type_t what);
6543f9d6adLin Lingextern void spa_history_log_internal(history_internal_events_t event,
6553f9d6adLin Ling    spa_t *spa, dmu_tx_t *tx, const char *fmt, ...);
656c8e1f6dMark J Musanteextern void spa_history_log_version(spa_t *spa, history_internal_events_t evt);
658ea8dc4beschrock/* error handling */
659ea8dc4beschrockstruct zbookmark;
660b24ab67Jeff Bonwickextern void spa_log_error(spa_t *spa, zio_t *zio);
661ea8dc4beschrockextern void zfs_ereport_post(const char *class, spa_t *spa, vdev_t *vd,
662b24ab67Jeff Bonwick    zio_t *zio, uint64_t stateoroffset, uint64_t length);
6633d7072feschrockextern void zfs_post_remove(spa_t *spa, vdev_t *vd);
664069f55eEric Schrockextern void zfs_post_state_change(spa_t *spa, vdev_t *vd);
6653d7072feschrockextern void zfs_post_autoreplace(spa_t *spa, vdev_t *vd);
666ea8dc4beschrockextern uint64_t spa_get_errlog_size(spa_t *spa);
667ea8dc4beschrockextern int spa_get_errlog(spa_t *spa, void *uaddr, size_t *count);
668ea8dc4beschrockextern void spa_errlog_rotate(spa_t *spa);
669ea8dc4beschrockextern void spa_errlog_drain(spa_t *spa);
670ea8dc4beschrockextern void spa_errlog_sync(spa_t *spa, uint64_t txg);
671ea8dc4beschrockextern void spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub);
67387db74cek/* vdev cache */
67487db74cekextern void vdev_cache_stat_init(void);
67587db74cekextern void vdev_cache_stat_fini(void);
677fa9e406ahrens/* Initialization and termination */
678fa9e406ahrensextern void spa_init(int flags);
679fa9e406ahrensextern void spa_fini(void);
680e7cbe64gwextern void spa_boot_init();
682b1b8ab3lling/* properties */
683990b485llingextern int spa_prop_set(spa_t *spa, nvlist_t *nvp);
684990b485llingextern int spa_prop_get(spa_t *spa, nvlist_t **nvp);
685990b485llingextern void spa_prop_clear_bootfs(spa_t *spa, uint64_t obj, dmu_tx_t *tx);
686379c004Eric Schrockextern void spa_configfile_set(spa_t *, nvlist_t *, boolean_t);
6883d7072feschrock/* asynchronous event notification */
6893d7072feschrockextern void spa_event_notify(spa_t *spa, vdev_t *vdev, const char *name);
691fa9e406ahrens#ifdef ZFS_DEBUG
692c0a8126ek#define	dprintf_bp(bp, fmt, ...) do {				\
693c0a8126ek	if (zfs_flags & ZFS_DEBUG_DPRINTF) { 			\
694c0a8126ek	char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP);	\
695b24ab67Jeff Bonwick	sprintf_blkptr(__blkbuf, (bp));				\
696c0a8126ek	dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf);		\
697c0a8126ek	kmem_free(__blkbuf, BP_SPRINTF_LEN);			\
698fa9e406ahrens	} \
699fa9e406ahrens_NOTE(CONSTCOND) } while (0)
701fa9e406ahrens#define	dprintf_bp(bp, fmt, ...)
70409c9d37George Wilsonextern boolean_t spa_debug_enabled(spa_t *spa);
70509c9d37George Wilson#define	spa_dbgmsg(spa, ...)			\
70609c9d37George Wilson{						\
70709c9d37George Wilson	if (spa_debug_enabled(spa))		\
70809c9d37George Wilson		zfs_dbgmsg(__VA_ARGS__);	\
70909c9d37George Wilson}
71009c9d37George Wilson
7118ad4d6dJeff Bonwickextern int spa_mode_global;			/* mode, e.g. FREAD | FWRITE */
713fa9e406ahrens#ifdef	__cplusplus
717fa9e406ahrens#endif	/* _SYS_SPA_H */