spa.h revision 3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5
1fa9e406ahrens/*
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 http://www.opensolaris.org/os/licensing.
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 */
21fa9e406ahrens/*
223f9d6adLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23fa9e406ahrens */
24fa9e406ahrens
25fa9e406ahrens#ifndef _SYS_SPA_H
26fa9e406ahrens#define	_SYS_SPA_H
27fa9e406ahrens
28fa9e406ahrens#include <sys/avl.h>
29fa9e406ahrens#include <sys/zfs_context.h>
30fa9e406ahrens#include <sys/nvpair.h>
31fa9e406ahrens#include <sys/sysmacros.h>
32fa9e406ahrens#include <sys/types.h>
33fa9e406ahrens#include <sys/fs/zfs.h>
34fa9e406ahrens
35fa9e406ahrens#ifdef	__cplusplus
36fa9e406ahrensextern "C" {
37fa9e406ahrens#endif
38fa9e406ahrens
39fa9e406ahrens/*
40fa9e406ahrens * Forward references that lots of things need.
41fa9e406ahrens */
42fa9e406ahrenstypedef struct spa spa_t;
43fa9e406ahrenstypedef struct vdev vdev_t;
44fa9e406ahrenstypedef struct metaslab metaslab_t;
45b24ab67Jeff Bonwicktypedef struct metaslab_group metaslab_group_t;
46b24ab67Jeff Bonwicktypedef struct metaslab_class metaslab_class_t;
47b24ab67Jeff Bonwicktypedef struct zio zio_t;
48fa9e406ahrenstypedef struct zilog zilog_t;
49fa94a07brendantypedef struct spa_aux_vdev spa_aux_vdev_t;
50b24ab67Jeff Bonwicktypedef struct ddt ddt_t;
51b24ab67Jeff Bonwicktypedef struct ddt_entry ddt_entry_t;
52fa9e406ahrensstruct dsl_pool;
53fa9e406ahrens
54fa9e406ahrens/*
55fa9e406ahrens * General-purpose 32-bit and 64-bit bitfield encodings.
56fa9e406ahrens */
57fa9e406ahrens#define	BF32_DECODE(x, low, len)	P2PHASE((x) >> (low), 1U << (len))
58fa9e406ahrens#define	BF64_DECODE(x, low, len)	P2PHASE((x) >> (low), 1ULL << (len))
59fa9e406ahrens#define	BF32_ENCODE(x, low, len)	(P2PHASE((x), 1U << (len)) << (low))
60fa9e406ahrens#define	BF64_ENCODE(x, low, len)	(P2PHASE((x), 1ULL << (len)) << (low))
61fa9e406ahrens
62fa9e406ahrens#define	BF32_GET(x, low, len)		BF32_DECODE(x, low, len)
63fa9e406ahrens#define	BF64_GET(x, low, len)		BF64_DECODE(x, low, len)
64fa9e406ahrens
65fa9e406ahrens#define	BF32_SET(x, low, len, val)	\
665ad8204nd	((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len))
67fa9e406ahrens#define	BF64_SET(x, low, len, val)	\
685ad8204nd	((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len))
69fa9e406ahrens
70fa9e406ahrens#define	BF32_GET_SB(x, low, len, shift, bias)	\
71fa9e406ahrens	((BF32_GET(x, low, len) + (bias)) << (shift))
72fa9e406ahrens#define	BF64_GET_SB(x, low, len, shift, bias)	\
73fa9e406ahrens	((BF64_GET(x, low, len) + (bias)) << (shift))
74fa9e406ahrens
75fa9e406ahrens#define	BF32_SET_SB(x, low, len, shift, bias, val)	\
76fa9e406ahrens	BF32_SET(x, low, len, ((val) >> (shift)) - (bias))
77fa9e406ahrens#define	BF64_SET_SB(x, low, len, shift, bias, val)	\
78fa9e406ahrens	BF64_SET(x, low, len, ((val) >> (shift)) - (bias))
79fa9e406ahrens
80fa9e406ahrens/*
81fa9e406ahrens * We currently support nine block sizes, from 512 bytes to 128K.
82fa9e406ahrens * We could go higher, but the benefits are near-zero and the cost
83fa9e406ahrens * of COWing a giant block to modify one byte would become excessive.
84fa9e406ahrens */
85fa9e406ahrens#define	SPA_MINBLOCKSHIFT	9
86fa9e406ahrens#define	SPA_MAXBLOCKSHIFT	17
87fa9e406ahrens#define	SPA_MINBLOCKSIZE	(1ULL << SPA_MINBLOCKSHIFT)
88fa9e406ahrens#define	SPA_MAXBLOCKSIZE	(1ULL << SPA_MAXBLOCKSHIFT)
89fa9e406ahrens
90fa9e406ahrens#define	SPA_BLOCKSIZES		(SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)
91fa9e406ahrens
92fa9e406ahrens/*
93f7991baTim Haley * Size of block to hold the configuration data (a packed nvlist)
94f7991baTim Haley */
95f7991baTim Haley#define	SPA_CONFIG_BLOCKSIZE	(1 << 14)
96f7991baTim Haley
97f7991baTim Haley/*
98fa9e406ahrens * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
99fa9e406ahrens * The ASIZE encoding should be at least 64 times larger (6 more bits)
100fa9e406ahrens * to support up to 4-way RAID-Z mirror mode with worst-case gang block
101fa9e406ahrens * overhead, three DVAs per bp, plus one more bit in case we do anything
102fa9e406ahrens * else that expands the ASIZE.
103fa9e406ahrens */
104fa9e406ahrens#define	SPA_LSIZEBITS		16	/* LSIZE up to 32M (2^16 * 512)	*/
105fa9e406ahrens#define	SPA_PSIZEBITS		16	/* PSIZE up to 32M (2^16 * 512)	*/
106fa9e406ahrens#define	SPA_ASIZEBITS		24	/* ASIZE up to 64 times larger	*/
107fa9e406ahrens
108fa9e406ahrens/*
109fa9e406ahrens * All SPA data is represented by 128-bit data virtual addresses (DVAs).
110fa9e406ahrens * The members of the dva_t should be considered opaque outside the SPA.
111fa9e406ahrens */
112fa9e406ahrenstypedef struct dva {
113fa9e406ahrens	uint64_t	dva_word[2];
114fa9e406ahrens} dva_t;
115fa9e406ahrens
116fa9e406ahrens/*
117fa9e406ahrens * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
118fa9e406ahrens */
119fa9e406ahrenstypedef struct zio_cksum {
120fa9e406ahrens	uint64_t	zc_word[4];
121fa9e406ahrens} zio_cksum_t;
122fa9e406ahrens
123fa9e406ahrens/*
124fa9e406ahrens * Each block is described by its DVAs, time of birth, checksum, etc.
125fa9e406ahrens * The word-by-word, bit-by-bit layout of the blkptr is as follows:
126fa9e406ahrens *
127fa9e406ahrens *	64	56	48	40	32	24	16	8	0
128fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
129fa9e406ahrens * 0	|		vdev1		| GRID  |	  ASIZE		|
130fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
131fa9e406ahrens * 1	|G|			 offset1				|
132fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
133fa9e406ahrens * 2	|		vdev2		| GRID  |	  ASIZE		|
134fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
135fa9e406ahrens * 3	|G|			 offset2				|
136fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
137fa9e406ahrens * 4	|		vdev3		| GRID  |	  ASIZE		|
138fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
139fa9e406ahrens * 5	|G|			 offset3				|
140fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
141b24ab67Jeff Bonwick * 6	|BDX|lvl| type	| cksum | comp	|     PSIZE	|     LSIZE	|
142fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
143fa9e406ahrens * 7	|			padding					|
144fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
145fa9e406ahrens * 8	|			padding					|
146fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
147b24ab67Jeff Bonwick * 9	|			physical birth txg			|
148fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
149b24ab67Jeff Bonwick * a	|			logical birth txg			|
150fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
151fa9e406ahrens * b	|			fill count				|
152fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
153fa9e406ahrens * c	|			checksum[0]				|
154fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
155fa9e406ahrens * d	|			checksum[1]				|
156fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
157fa9e406ahrens * e	|			checksum[2]				|
158fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
159fa9e406ahrens * f	|			checksum[3]				|
160fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
161fa9e406ahrens *
162fa9e406ahrens * Legend:
163fa9e406ahrens *
164fa9e406ahrens * vdev		virtual device ID
165fa9e406ahrens * offset	offset into virtual device
166fa9e406ahrens * LSIZE	logical size
167fa9e406ahrens * PSIZE	physical size (after compression)
168fa9e406ahrens * ASIZE	allocated size (including RAID-Z parity and gang block headers)
169fa9e406ahrens * GRID		RAID-Z layout information (reserved for future use)
170fa9e406ahrens * cksum	checksum function
171fa9e406ahrens * comp		compression function
172fa9e406ahrens * G		gang block indicator
173b24ab67Jeff Bonwick * B		byteorder (endianness)
174b24ab67Jeff Bonwick * D		dedup
175b24ab67Jeff Bonwick * X		unused
176fa9e406ahrens * lvl		level of indirection
177b24ab67Jeff Bonwick * type		DMU object type
178b24ab67Jeff Bonwick * phys birth	txg of block allocation; zero if same as logical birth txg
179b24ab67Jeff Bonwick * log. birth	transaction group in which the block was logically born
180fa9e406ahrens * fill count	number of non-zero blocks under this bp
181fa9e406ahrens * checksum[4]	256-bit checksum of the data this bp describes
182fa9e406ahrens */
183fa9e406ahrens#define	SPA_BLKPTRSHIFT	7		/* blkptr_t is 128 bytes	*/
184fa9e406ahrens#define	SPA_DVAS_PER_BP	3		/* Number of DVAs in a bp	*/
185fa9e406ahrens
186b24ab67Jeff Bonwicktypedef struct blkptr {
187b24ab67Jeff Bonwick	dva_t		blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */
188b24ab67Jeff Bonwick	uint64_t	blk_prop;	/* size, compression, type, etc	    */
189b24ab67Jeff Bonwick	uint64_t	blk_pad[2];	/* Extra space for the future	    */
190b24ab67Jeff Bonwick	uint64_t	blk_phys_birth;	/* txg when block was allocated	    */
191b24ab67Jeff Bonwick	uint64_t	blk_birth;	/* transaction group at birth	    */
192b24ab67Jeff Bonwick	uint64_t	blk_fill;	/* fill count			    */
193b24ab67Jeff Bonwick	zio_cksum_t	blk_cksum;	/* 256-bit checksum		    */
194b24ab67Jeff Bonwick} blkptr_t;
195b24ab67Jeff Bonwick
196fa9e406ahrens/*
197fa9e406ahrens * Macros to get and set fields in a bp or DVA.
198fa9e406ahrens */
199fa9e406ahrens#define	DVA_GET_ASIZE(dva)	\
200fa9e406ahrens	BF64_GET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0)
201fa9e406ahrens#define	DVA_SET_ASIZE(dva, x)	\
202fa9e406ahrens	BF64_SET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0, x)
203fa9e406ahrens
204fa9e406ahrens#define	DVA_GET_GRID(dva)	BF64_GET((dva)->dva_word[0], 24, 8)
205fa9e406ahrens#define	DVA_SET_GRID(dva, x)	BF64_SET((dva)->dva_word[0], 24, 8, x)
206fa9e406ahrens
207fa9e406ahrens#define	DVA_GET_VDEV(dva)	BF64_GET((dva)->dva_word[0], 32, 32)
208fa9e406ahrens#define	DVA_SET_VDEV(dva, x)	BF64_SET((dva)->dva_word[0], 32, 32, x)
209fa9e406ahrens
210fa9e406ahrens#define	DVA_GET_OFFSET(dva)	\
211fa9e406ahrens	BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0)
212fa9e406ahrens#define	DVA_SET_OFFSET(dva, x)	\
213fa9e406ahrens	BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x)
214fa9e406ahrens
215fa9e406ahrens#define	DVA_GET_GANG(dva)	BF64_GET((dva)->dva_word[1], 63, 1)
216fa9e406ahrens#define	DVA_SET_GANG(dva, x)	BF64_SET((dva)->dva_word[1], 63, 1, x)
217fa9e406ahrens
218fa9e406ahrens#define	BP_GET_LSIZE(bp)	\
219975c32aNeil Perrin	BF64_GET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1)
220fa9e406ahrens#define	BP_SET_LSIZE(bp, x)	\
221fa9e406ahrens	BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
222fa9e406ahrens
223fa9e406ahrens#define	BP_GET_PSIZE(bp)	\
224fa9e406ahrens	BF64_GET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1)
225fa9e406ahrens#define	BP_SET_PSIZE(bp, x)	\
226fa9e406ahrens	BF64_SET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1, x)
227fa9e406ahrens
228b24ab67Jeff Bonwick#define	BP_GET_COMPRESS(bp)		BF64_GET((bp)->blk_prop, 32, 8)
229b24ab67Jeff Bonwick#define	BP_SET_COMPRESS(bp, x)		BF64_SET((bp)->blk_prop, 32, 8, x)
230b24ab67Jeff Bonwick
231b24ab67Jeff Bonwick#define	BP_GET_CHECKSUM(bp)		BF64_GET((bp)->blk_prop, 40, 8)
232b24ab67Jeff Bonwick#define	BP_SET_CHECKSUM(bp, x)		BF64_SET((bp)->blk_prop, 40, 8, x)
233b24ab67Jeff Bonwick
234b24ab67Jeff Bonwick#define	BP_GET_TYPE(bp)			BF64_GET((bp)->blk_prop, 48, 8)
235b24ab67Jeff Bonwick#define	BP_SET_TYPE(bp, x)		BF64_SET((bp)->blk_prop, 48, 8, x)
236fa9e406ahrens
237b24ab67Jeff Bonwick#define	BP_GET_LEVEL(bp)		BF64_GET((bp)->blk_prop, 56, 5)
238b24ab67Jeff Bonwick#define	BP_SET_LEVEL(bp, x)		BF64_SET((bp)->blk_prop, 56, 5, x)
239fa9e406ahrens
240b24ab67Jeff Bonwick#define	BP_GET_PROP_BIT_61(bp)		BF64_GET((bp)->blk_prop, 61, 1)
241b24ab67Jeff Bonwick#define	BP_SET_PROP_BIT_61(bp, x)	BF64_SET((bp)->blk_prop, 61, 1, x)
242fa9e406ahrens
243b24ab67Jeff Bonwick#define	BP_GET_DEDUP(bp)		BF64_GET((bp)->blk_prop, 62, 1)
244b24ab67Jeff Bonwick#define	BP_SET_DEDUP(bp, x)		BF64_SET((bp)->blk_prop, 62, 1, x)
245fa9e406ahrens
246b24ab67Jeff Bonwick#define	BP_GET_BYTEORDER(bp)		(0 - BF64_GET((bp)->blk_prop, 63, 1))
247b24ab67Jeff Bonwick#define	BP_SET_BYTEORDER(bp, x)		BF64_SET((bp)->blk_prop, 63, 1, x)
248b24ab67Jeff Bonwick
249b24ab67Jeff Bonwick#define	BP_PHYSICAL_BIRTH(bp)		\
250b24ab67Jeff Bonwick	((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)
251b24ab67Jeff Bonwick
252b24ab67Jeff Bonwick#define	BP_SET_BIRTH(bp, logical, physical)	\
253b24ab67Jeff Bonwick{						\
254b24ab67Jeff Bonwick	(bp)->blk_birth = (logical);		\
255b24ab67Jeff Bonwick	(bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \
256b24ab67Jeff Bonwick}
257fa9e406ahrens
258fa9e406ahrens#define	BP_GET_ASIZE(bp)	\
259fa9e406ahrens	(DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
26099653d4eschrock		DVA_GET_ASIZE(&(bp)->blk_dva[2]))
26199653d4eschrock
26299653d4eschrock#define	BP_GET_UCSIZE(bp) \
26399653d4eschrock	((BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) ? \
2643f9d6adLin Ling	BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp))
265fa9e406ahrens
26644cd46cbillm#define	BP_GET_NDVAS(bp)	\
26744cd46cbillm	(!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
26844cd46cbillm	!!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
26944cd46cbillm	!!DVA_GET_ASIZE(&(bp)->blk_dva[2]))
27044cd46cbillm
27144cd46cbillm#define	BP_COUNT_GANG(bp)	\
27244cd46cbillm	(DVA_GET_GANG(&(bp)->blk_dva[0]) + \
27344cd46cbillm	DVA_GET_GANG(&(bp)->blk_dva[1]) + \
27444cd46cbillm	DVA_GET_GANG(&(bp)->blk_dva[2]))
27544cd46cbillm
276fa9e406ahrens#define	DVA_EQUAL(dva1, dva2)	\
277fa9e406ahrens	((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
278fa9e406ahrens	(dva1)->dva_word[0] == (dva2)->dva_word[0])
279fa9e406ahrens
280b24ab67Jeff Bonwick#define	BP_EQUAL(bp1, bp2)	\
281b24ab67Jeff Bonwick	(BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) &&	\
282b24ab67Jeff Bonwick	DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) &&	\
283b24ab67Jeff Bonwick	DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) &&	\
284b24ab67Jeff Bonwick	DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2]))
285b24ab67Jeff Bonwick
2866b4acc8ahrens#define	ZIO_CHECKSUM_EQUAL(zc1, zc2) \
2876b4acc8ahrens	(0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
2886b4acc8ahrens	((zc1).zc_word[1] - (zc2).zc_word[1]) | \
2896b4acc8ahrens	((zc1).zc_word[2] - (zc2).zc_word[2]) | \
2906b4acc8ahrens	((zc1).zc_word[3] - (zc2).zc_word[3])))
2916b4acc8ahrens
292fa9e406ahrens#define	DVA_IS_VALID(dva)	(DVA_GET_ASIZE(dva) != 0)
293fa9e406ahrens
294fa9e406ahrens#define	ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3)	\
295fa9e406ahrens{						\
296fa9e406ahrens	(zcp)->zc_word[0] = w0;			\
297fa9e406ahrens	(zcp)->zc_word[1] = w1;			\
298fa9e406ahrens	(zcp)->zc_word[2] = w2;			\
299fa9e406ahrens	(zcp)->zc_word[3] = w3;			\
300fa9e406ahrens}
301fa9e406ahrens
302fa9e406ahrens#define	BP_IDENTITY(bp)		(&(bp)->blk_dva[0])
30344cd46cbillm#define	BP_IS_GANG(bp)		DVA_GET_GANG(BP_IDENTITY(bp))
30444cd46cbillm#define	BP_IS_HOLE(bp)		((bp)->blk_birth == 0)
305fa9e406ahrens
3066e1f5caNeil Perrin/* BP_IS_RAIDZ(bp) assumes no block compression */
3076e1f5caNeil Perrin#define	BP_IS_RAIDZ(bp)		(DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \
3086e1f5caNeil Perrin				BP_GET_PSIZE(bp))
3096e1f5caNeil Perrin
310e14bb32Jeff Bonwick#define	BP_ZERO(bp)				\
311fa9e406ahrens{						\
312fa9e406ahrens	(bp)->blk_dva[0].dva_word[0] = 0;	\
313fa9e406ahrens	(bp)->blk_dva[0].dva_word[1] = 0;	\
314fa9e406ahrens	(bp)->blk_dva[1].dva_word[0] = 0;	\
315fa9e406ahrens	(bp)->blk_dva[1].dva_word[1] = 0;	\
316fa9e406ahrens	(bp)->blk_dva[2].dva_word[0] = 0;	\
317fa9e406ahrens	(bp)->blk_dva[2].dva_word[1] = 0;	\
318fa9e406ahrens	(bp)->blk_prop = 0;			\
319fa9e406ahrens	(bp)->blk_pad[0] = 0;			\
320fa9e406ahrens	(bp)->blk_pad[1] = 0;			\
321b24ab67Jeff Bonwick	(bp)->blk_phys_birth = 0;		\
322e14bb32Jeff Bonwick	(bp)->blk_birth = 0;			\
323fa9e406ahrens	(bp)->blk_fill = 0;			\
324fa9e406ahrens	ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0);	\
325fa9e406ahrens}
326fa9e406ahrens
327fa9e406ahrens/*
328fa9e406ahrens * Note: the byteorder is either 0 or -1, both of which are palindromes.
329fa9e406ahrens * This simplifies the endianness handling a bit.
330fa9e406ahrens */
331fa9e406ahrens#ifdef _BIG_ENDIAN
332fa9e406ahrens#define	ZFS_HOST_BYTEORDER	(0ULL)
333fa9e406ahrens#else
334fa9e406ahrens#define	ZFS_HOST_BYTEORDER	(-1ULL)
335fa9e406ahrens#endif
336fa9e406ahrens
337fa9e406ahrens#define	BP_SHOULD_BYTESWAP(bp)	(BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER)
338fa9e406ahrens
33944cd46cbillm#define	BP_SPRINTF_LEN	320
340fbabab8maybee
341b24ab67Jeff Bonwick/*
342b24ab67Jeff Bonwick * This macro allows code sharing between zfs, libzpool, and mdb.
343b24ab67Jeff Bonwick * 'func' is either snprintf() or mdb_snprintf().
344b24ab67Jeff Bonwick * 'ws' (whitespace) can be ' ' for single-line format, '\n' for multi-line.
345b24ab67Jeff Bonwick */
346b24ab67Jeff Bonwick#define	SPRINTF_BLKPTR(func, ws, buf, bp, type, checksum, compress)	\
347b24ab67Jeff Bonwick{									\
348b24ab67Jeff Bonwick	static const char *copyname[] =					\
349b24ab67Jeff Bonwick	    { "zero", "single", "double", "triple" };			\
350b24ab67Jeff Bonwick	int size = BP_SPRINTF_LEN;					\
351b24ab67Jeff Bonwick	int len = 0;							\
352b24ab67Jeff Bonwick	int copies = 0;							\
353b24ab67Jeff Bonwick									\
354b24ab67Jeff Bonwick	if (bp == NULL) {						\
355b24ab67Jeff Bonwick		len = func(buf + len, size - len, "<NULL>");		\
356b24ab67Jeff Bonwick	} else if (BP_IS_HOLE(bp)) {					\
357b24ab67Jeff Bonwick		len = func(buf + len, size - len, "<hole>");		\
358b24ab67Jeff Bonwick	} else {							\
359b24ab67Jeff Bonwick		for (int d = 0; d < BP_GET_NDVAS(bp); d++) {		\
360b24ab67Jeff Bonwick			const dva_t *dva = &bp->blk_dva[d];		\
361b24ab67Jeff Bonwick			if (DVA_IS_VALID(dva))				\
362b24ab67Jeff Bonwick				copies++;				\
363b24ab67Jeff Bonwick			len += func(buf + len, size - len,		\
364b24ab67Jeff Bonwick			    "DVA[%d]=<%llu:%llx:%llx>%c", d,		\
365b24ab67Jeff Bonwick			    (u_longlong_t)DVA_GET_VDEV(dva),		\
366b24ab67Jeff Bonwick			    (u_longlong_t)DVA_GET_OFFSET(dva),		\
367b24ab67Jeff Bonwick			    (u_longlong_t)DVA_GET_ASIZE(dva),		\
368b24ab67Jeff Bonwick			    ws);					\
369b24ab67Jeff Bonwick		}							\
370b24ab67Jeff Bonwick		if (BP_IS_GANG(bp) &&					\
371b24ab67Jeff Bonwick		    DVA_GET_ASIZE(&bp->blk_dva[2]) <=			\
372b24ab67Jeff Bonwick		    DVA_GET_ASIZE(&bp->blk_dva[1]) / 2)			\
373b24ab67Jeff Bonwick			copies--;					\
374b24ab67Jeff Bonwick		len += func(buf + len, size - len,			\
375b24ab67Jeff Bonwick		    "[L%llu %s] %s %s %s %s %s %s%c"			\
376b24ab67Jeff Bonwick		    "size=%llxL/%llxP birth=%lluL/%lluP fill=%llu%c"	\
377b24ab67Jeff Bonwick		    "cksum=%llx:%llx:%llx:%llx",			\
378b24ab67Jeff Bonwick		    (u_longlong_t)BP_GET_LEVEL(bp),			\
379b24ab67Jeff Bonwick		    type,						\
380b24ab67Jeff Bonwick		    checksum,						\
381b24ab67Jeff Bonwick		    compress,						\
382b24ab67Jeff Bonwick		    BP_GET_BYTEORDER(bp) == 0 ? "BE" : "LE",		\
383b24ab67Jeff Bonwick		    BP_IS_GANG(bp) ? "gang" : "contiguous",		\
384b24ab67Jeff Bonwick		    BP_GET_DEDUP(bp) ? "dedup" : "unique",		\
385b24ab67Jeff Bonwick		    copyname[copies],					\
386b24ab67Jeff Bonwick		    ws,							\
387b24ab67Jeff Bonwick		    (u_longlong_t)BP_GET_LSIZE(bp),			\
388b24ab67Jeff Bonwick		    (u_longlong_t)BP_GET_PSIZE(bp),			\
389b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_birth,			\
390b24ab67Jeff Bonwick		    (u_longlong_t)BP_PHYSICAL_BIRTH(bp),		\
391b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_fill,				\
392b24ab67Jeff Bonwick		    ws,							\
393b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[0],		\
394b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[1],		\
395b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[2],		\
396b24ab67Jeff Bonwick		    (u_longlong_t)bp->blk_cksum.zc_word[3]);		\
397b24ab67Jeff Bonwick	}								\
398b24ab67Jeff Bonwick	ASSERT(len < size);						\
399b24ab67Jeff Bonwick}
400b24ab67Jeff Bonwick
401fa9e406ahrens#include <sys/dmu.h>
402fa9e406ahrens
403ad23a2djohansen#define	BP_GET_BUFC_TYPE(bp)						\
404ad23a2djohansen	(((BP_GET_LEVEL(bp) > 0) || (dmu_ot[BP_GET_TYPE(bp)].ot_metadata)) ? \
405ad23a2djohansen	ARC_BUFC_METADATA : ARC_BUFC_DATA);
406fa9e406ahrens
4071195e68Mark J Musantetypedef enum spa_import_type {
4081195e68Mark J Musante	SPA_IMPORT_EXISTING,
4091195e68Mark J Musante	SPA_IMPORT_ASSEMBLE
4101195e68Mark J Musante} spa_import_type_t;
4111195e68Mark J Musante
412fa9e406ahrens/* state manipulation functions */
413fa9e406ahrensextern int spa_open(const char *pool, spa_t **, void *tag);
414468c413Tim Haleyextern int spa_open_rewind(const char *pool, spa_t **, void *tag,
415468c413Tim Haley    nvlist_t *policy, nvlist_t **config);
416ea8dc4beschrockextern int spa_get_stats(const char *pool, nvlist_t **config,
417ea8dc4beschrock    char *altroot, size_t buflen);
418990b485llingextern int spa_create(const char *pool, nvlist_t *config, nvlist_t *props,
4190a48a24timh    const char *history_str, nvlist_t *zplprops);
420051aabetaylorextern int spa_import_rootpool(char *devpath, char *devid);
421990b485llingextern int spa_import(const char *pool, nvlist_t *config, nvlist_t *props);
4226809eb4Eric Schrockextern int spa_import_verbatim(const char *, nvlist_t *, nvlist_t *);
423fa9e406ahrensextern nvlist_t *spa_tryimport(nvlist_t *tryconfig);
424fa9e406ahrensextern int spa_destroy(char *pool);
425394ab0cGeorge Wilsonextern int spa_export(char *pool, nvlist_t **oldconfig, boolean_t force,
426394ab0cGeorge Wilson    boolean_t hardforce);
427ea8dc4beschrockextern int spa_reset(char *pool);
428ea8dc4beschrockextern void spa_async_request(spa_t *spa, int flag);
429088f389ahrensextern void spa_async_unrequest(spa_t *spa, int flag);
430ea8dc4beschrockextern void spa_async_suspend(spa_t *spa);
431ea8dc4beschrockextern void spa_async_resume(spa_t *spa);
432ea8dc4beschrockextern spa_t *spa_inject_addref(char *pool);
433ea8dc4beschrockextern void spa_inject_delref(spa_t *spa);
4343f9d6adLin Lingextern void spa_scan_stat_init(spa_t *spa);
4353f9d6adLin Lingextern int spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps);
436ea8dc4beschrock
437e14bb32Jeff Bonwick#define	SPA_ASYNC_CONFIG_UPDATE	0x01
438e14bb32Jeff Bonwick#define	SPA_ASYNC_REMOVE	0x02
439e14bb32Jeff Bonwick#define	SPA_ASYNC_PROBE		0x04
440e14bb32Jeff Bonwick#define	SPA_ASYNC_RESILVER_DONE	0x08
441e14bb32Jeff Bonwick#define	SPA_ASYNC_RESILVER	0x10
442573ca77George Wilson#define	SPA_ASYNC_AUTOEXPAND	0x20
4433f9d6adLin Ling#define	SPA_ASYNC_REMOVE_DONE	0x40
4443f9d6adLin Ling#define	SPA_ASYNC_REMOVE_STOP	0x80
4453f9d6adLin Ling
4463f9d6adLin Ling/*
4473f9d6adLin Ling * Controls the behavior of spa_vdev_remove().
4483f9d6adLin Ling */
4493f9d6adLin Ling#define	SPA_REMOVE_UNSPARE	0x01
4503f9d6adLin Ling#define	SPA_REMOVE_DONE		0x02
451fa9e406ahrens
452fa9e406ahrens/* device manipulation */
453fa9e406ahrensextern int spa_vdev_add(spa_t *spa, nvlist_t *nvroot);
454ea8dc4beschrockextern int spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot,
455fa9e406ahrens    int replacing);
4568ad4d6dJeff Bonwickextern int spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid,
4578ad4d6dJeff Bonwick    int replace_done);
45899653d4eschrockextern int spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare);
4593f9d6adLin Lingextern boolean_t spa_vdev_remove_active(spa_t *spa);
460c67d967eschrockextern int spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath);
4616809eb4Eric Schrockextern int spa_vdev_setfru(spa_t *spa, uint64_t guid, const char *newfru);
4621195e68Mark J Musanteextern int spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
4631195e68Mark J Musante    nvlist_t *props, boolean_t exp);
464fa9e406ahrens
46599653d4eschrock/* spare state (which is global across all pools) */
46639c2341eschrockextern void spa_spare_add(vdev_t *vd);
46739c2341eschrockextern void spa_spare_remove(vdev_t *vd);
46889a89ebllingextern boolean_t spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt);
46939c2341eschrockextern void spa_spare_activate(vdev_t *vd);
47099653d4eschrock
471fa94a07brendan/* L2ARC state (which is global across all pools) */
472fa94a07brendanextern void spa_l2cache_add(vdev_t *vd);
473fa94a07brendanextern void spa_l2cache_remove(vdev_t *vd);
474fa94a07brendanextern boolean_t spa_l2cache_exists(uint64_t guid, uint64_t *pool);
475fa94a07brendanextern void spa_l2cache_activate(vdev_t *vd);
476fa94a07brendanextern void spa_l2cache_drop(spa_t *spa);
477fa94a07brendan
4783f9d6adLin Ling/* scanning */
4793f9d6adLin Lingextern int spa_scan(spa_t *spa, pool_scan_func_t func);
4803f9d6adLin Lingextern int spa_scan_stop(spa_t *spa);
481fa9e406ahrens
482fa9e406ahrens/* spa syncing */
483fa9e406ahrensextern void spa_sync(spa_t *spa, uint64_t txg); /* only for DMU use */
484fa9e406ahrensextern void spa_sync_allpools(void);
485fa9e406ahrens
4863f9d6adLin Ling/*
4873f9d6adLin Ling * DEFERRED_FREE must be large enough that regular blocks are not
4883f9d6adLin Ling * deferred.  XXX so can't we change it back to 1?
4893f9d6adLin Ling */
4903f9d6adLin Ling#define	SYNC_PASS_DEFERRED_FREE	2	/* defer frees after this pass */
491b24ab67Jeff Bonwick#define	SYNC_PASS_DONT_COMPRESS	4	/* don't compress after this pass */
492b24ab67Jeff Bonwick#define	SYNC_PASS_REWRITE	1	/* rewrite new bps after this pass */
493b24ab67Jeff Bonwick
4943a737e0brendan/* spa namespace global mutex */
4953a737e0brendanextern kmutex_t spa_namespace_lock;
4963a737e0brendan
497fa9e406ahrens/*
498fa9e406ahrens * SPA configuration functions in spa_config.c
499fa9e406ahrens */
5000373e76bonwick
5010373e76bonwick#define	SPA_CONFIG_UPDATE_POOL	0
5020373e76bonwick#define	SPA_CONFIG_UPDATE_VDEVS	1
5030373e76bonwick
504c5904d1eschrockextern void spa_config_sync(spa_t *, boolean_t, boolean_t);
505fa9e406ahrensextern void spa_config_load(void);
506fa9e406ahrensextern nvlist_t *spa_all_configs(uint64_t *);
507fa9e406ahrensextern void spa_config_set(spa_t *spa, nvlist_t *config);
508fa9e406ahrensextern nvlist_t *spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg,
509fa9e406ahrens    int getstats);
5100373e76bonwickextern void spa_config_update(spa_t *spa, int what);
511fa9e406ahrens
512fa9e406ahrens/*
513fa9e406ahrens * Miscellaneous SPA routines in spa_misc.c
514fa9e406ahrens */
515fa9e406ahrens
516fa9e406ahrens/* Namespace manipulation */
517fa9e406ahrensextern spa_t *spa_lookup(const char *name);
518468c413Tim Haleyextern spa_t *spa_add(const char *name, nvlist_t *config, const char *altroot);
519fa9e406ahrensextern void spa_remove(spa_t *spa);
520fa9e406ahrensextern spa_t *spa_next(spa_t *prev);
521fa9e406ahrens
522fa9e406ahrens/* Refcount functions */
523fa9e406ahrensextern void spa_open_ref(spa_t *spa, void *tag);
524fa9e406ahrensextern void spa_close(spa_t *spa, void *tag);
525fa9e406ahrensextern boolean_t spa_refcount_zero(spa_t *spa);
526fa9e406ahrens
5278f18d1fGeorge Wilson#define	SCL_NONE	0x00
528e14bb32Jeff Bonwick#define	SCL_CONFIG	0x01
529e14bb32Jeff Bonwick#define	SCL_STATE	0x02
530e14bb32Jeff Bonwick#define	SCL_L2ARC	0x04		/* hack until L2ARC 2.0 */
531e14bb32Jeff Bonwick#define	SCL_ALLOC	0x08
532e14bb32Jeff Bonwick#define	SCL_ZIO		0x10
533e14bb32Jeff Bonwick#define	SCL_FREE	0x20
534e14bb32Jeff Bonwick#define	SCL_VDEV	0x40
535e14bb32Jeff Bonwick#define	SCL_LOCKS	7
536e14bb32Jeff Bonwick#define	SCL_ALL		((1 << SCL_LOCKS) - 1)
537e14bb32Jeff Bonwick#define	SCL_STATE_ALL	(SCL_STATE | SCL_L2ARC | SCL_ZIO)
538e14bb32Jeff Bonwick
539e14bb32Jeff Bonwick/* Pool configuration locks */
540e14bb32Jeff Bonwickextern int spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw);
541e14bb32Jeff Bonwickextern void spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw);
542e14bb32Jeff Bonwickextern void spa_config_exit(spa_t *spa, int locks, void *tag);
543e14bb32Jeff Bonwickextern int spa_config_held(spa_t *spa, int locks, krw_t rw);
544fa9e406ahrens
545fa9e406ahrens/* Pool vdev add/remove lock */
546fa9e406ahrensextern uint64_t spa_vdev_enter(spa_t *spa);
54788ecc94George Wilsonextern uint64_t spa_vdev_config_enter(spa_t *spa);
54888ecc94George Wilsonextern void spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg,
54988ecc94George Wilson    int error, char *tag);
550fa9e406ahrensextern int spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error);
551fa9e406ahrens
552e14bb32Jeff Bonwick/* Pool vdev state change lock */
5538f18d1fGeorge Wilsonextern void spa_vdev_state_enter(spa_t *spa, int oplock);
554e14bb32Jeff Bonwickextern int spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error);
555e14bb32Jeff Bonwick
556b24ab67Jeff Bonwick/* Log state */
557b24ab67Jeff Bonwicktypedef enum spa_log_state {
558b24ab67Jeff Bonwick	SPA_LOG_UNKNOWN = 0,	/* unknown log state */
559b24ab67Jeff Bonwick	SPA_LOG_MISSING,	/* missing log(s) */
560b24ab67Jeff Bonwick	SPA_LOG_CLEAR,		/* clear the log(s) */
561b24ab67Jeff Bonwick	SPA_LOG_GOOD,		/* log(s) are good */
562b24ab67Jeff Bonwick} spa_log_state_t;
563b24ab67Jeff Bonwick
564b24ab67Jeff Bonwickextern spa_log_state_t spa_get_log_state(spa_t *spa);
565b24ab67Jeff Bonwickextern void spa_set_log_state(spa_t *spa, spa_log_state_t state);
5661195e68Mark J Musanteextern int spa_offline_log(spa_t *spa);
567b24ab67Jeff Bonwick
568b24ab67Jeff Bonwick/* Log claim callback */
569b24ab67Jeff Bonwickextern void spa_claim_notify(zio_t *zio);
570b24ab67Jeff Bonwick
571fa9e406ahrens/* Accessor functions */
57288b7b0fMatthew Ahrensextern boolean_t spa_shutting_down(spa_t *spa);
573fa9e406ahrensextern struct dsl_pool *spa_get_dsl(spa_t *spa);
574fa9e406ahrensextern blkptr_t *spa_get_rootblkptr(spa_t *spa);
575fa9e406ahrensextern void spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp);
576fa9e406ahrensextern void spa_altroot(spa_t *, char *, size_t);
577fa9e406ahrensextern int spa_sync_pass(spa_t *spa);
578fa9e406ahrensextern char *spa_name(spa_t *spa);
579fa9e406ahrensextern uint64_t spa_guid(spa_t *spa);
580fa9e406ahrensextern uint64_t spa_last_synced_txg(spa_t *spa);
581fa9e406ahrensextern uint64_t spa_first_txg(spa_t *spa);
582b24ab67Jeff Bonwickextern uint64_t spa_syncing_txg(spa_t *spa);
58399653d4eschrockextern uint64_t spa_version(spa_t *spa);
58488b7b0fMatthew Ahrensextern pool_state_t spa_state(spa_t *spa);
585b16da2eGeorge Wilsonextern spa_load_state_t spa_load_state(spa_t *spa);
586fa9e406ahrensextern uint64_t spa_freeze_txg(spa_t *spa);
587fa9e406ahrensextern uint64_t spa_get_asize(spa_t *spa, uint64_t lsize);
588485bbbfGeorge Wilsonextern uint64_t spa_get_dspace(spa_t *spa);
589485bbbfGeorge Wilsonextern void spa_update_dspace(spa_t *spa);
59044cd46cbillmextern uint64_t spa_version(spa_t *spa);
591b24ab67Jeff Bonwickextern boolean_t spa_deflate(spa_t *spa);
592b24ab67Jeff Bonwickextern metaslab_class_t *spa_normal_class(spa_t *spa);
593b24ab67Jeff Bonwickextern metaslab_class_t *spa_log_class(spa_t *spa);
59444cd46cbillmextern int spa_max_replication(spa_t *spa);
5953f9d6adLin Lingextern int spa_prev_software_version(spa_t *spa);
596fa9e406ahrensextern int spa_busy(void);
5970a4e951gwextern uint8_t spa_get_failmode(spa_t *spa);
598e14bb32Jeff Bonwickextern boolean_t spa_suspended(spa_t *spa);
599b24ab67Jeff Bonwickextern uint64_t spa_bootfs(spa_t *spa);
600b24ab67Jeff Bonwickextern uint64_t spa_delegation(spa_t *spa);
601b24ab67Jeff Bonwickextern objset_t *spa_meta_objset(spa_t *spa);
602b24ab67Jeff Bonwickextern enum zio_checksum spa_dedup_checksum(spa_t *spa);
603fa9e406ahrens
604fa9e406ahrens/* Miscellaneous support routines */
605fa9e406ahrensextern int spa_rename(const char *oldname, const char *newname);
606fa9e406ahrensextern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid);
607fa9e406ahrensextern char *spa_strdup(const char *);
608fa9e406ahrensextern void spa_strfree(char *);
609fa9e406ahrensextern uint64_t spa_get_random(uint64_t range);
6101195e68Mark J Musanteextern uint64_t spa_generate_guid(spa_t *spa);
611b24ab67Jeff Bonwickextern void sprintf_blkptr(char *buf, const blkptr_t *bp);
612fa9e406ahrensextern void spa_freeze(spa_t *spa);
613990b485llingextern void spa_upgrade(spa_t *spa, uint64_t version);
614fa9e406ahrensextern void spa_evict_all(void);
615c5904d1eschrockextern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid,
616c5904d1eschrock    boolean_t l2cache);
61799653d4eschrockextern boolean_t spa_has_spare(spa_t *, uint64_t guid);
618b24ab67Jeff Bonwickextern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva);
619b24ab67Jeff Bonwickextern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp);
620b24ab67Jeff Bonwickextern uint64_t bp_get_dsize(spa_t *spa, const blkptr_t *bp);
6216ce0521perrinextern boolean_t spa_has_slogs(spa_t *spa);
622bf82a41eschrockextern boolean_t spa_is_root(spa_t *spa);
6238ad4d6dJeff Bonwickextern boolean_t spa_writeable(spa_t *spa);
624468c413Tim Haleyextern void spa_rewind_data_to_nvlist(spa_t *spa, nvlist_t *to);
625468c413Tim Haley
6268ad4d6dJeff Bonwickextern int spa_mode(spa_t *spa);
627ca45db4Chris Kirbyextern uint64_t strtonum(const char *str, char **nptr);
628ea8dc4beschrock
62906eeb2aek/* history logging */
630ecd6cf8markstypedef enum history_log_type {
631ecd6cf8marks	LOG_CMD_POOL_CREATE,
632ecd6cf8marks	LOG_CMD_NORMAL,
633ecd6cf8marks	LOG_INTERNAL
634ecd6cf8marks} history_log_type_t;
635ecd6cf8marks
636ecd6cf8markstypedef struct history_arg {
637495807dMatthew Ahrens	char *ha_history_str;
638ecd6cf8marks	history_log_type_t ha_log_type;
639ecd6cf8marks	history_internal_events_t ha_event;
640495807dMatthew Ahrens	char *ha_zone;
641495807dMatthew Ahrens	uid_t ha_uid;
642ecd6cf8marks} history_arg_t;
643ecd6cf8marks
644ecd6cf8marksextern char *spa_his_ievent_table[];
645ecd6cf8marks
64606eeb2aekextern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx);
64706eeb2aekextern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read,
64806eeb2aek    char *his_buf);
64906eeb2aekextern int spa_history_log(spa_t *spa, const char *his_buf,
650ecd6cf8marks    history_log_type_t what);
6513f9d6adLin Lingextern void spa_history_log_internal(history_internal_events_t event,
6523f9d6adLin Ling    spa_t *spa, dmu_tx_t *tx, const char *fmt, ...);
653c8e1f6dMark J Musanteextern void spa_history_log_version(spa_t *spa, history_internal_events_t evt);
65406eeb2aek
655ea8dc4beschrock/* error handling */
656ea8dc4beschrockstruct zbookmark;
657b24ab67Jeff Bonwickextern void spa_log_error(spa_t *spa, zio_t *zio);
658ea8dc4beschrockextern void zfs_ereport_post(const char *class, spa_t *spa, vdev_t *vd,
659b24ab67Jeff Bonwick    zio_t *zio, uint64_t stateoroffset, uint64_t length);
6603d7072feschrockextern void zfs_post_remove(spa_t *spa, vdev_t *vd);
661069f55eEric Schrockextern void zfs_post_state_change(spa_t *spa, vdev_t *vd);
6623d7072feschrockextern void zfs_post_autoreplace(spa_t *spa, vdev_t *vd);
663ea8dc4beschrockextern uint64_t spa_get_errlog_size(spa_t *spa);
664ea8dc4beschrockextern int spa_get_errlog(spa_t *spa, void *uaddr, size_t *count);
665ea8dc4beschrockextern void spa_errlog_rotate(spa_t *spa);
666ea8dc4beschrockextern void spa_errlog_drain(spa_t *spa);
667ea8dc4beschrockextern void spa_errlog_sync(spa_t *spa, uint64_t txg);
668ea8dc4beschrockextern void spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub);
669fa9e406ahrens
67087db74cek/* vdev cache */
67187db74cekextern void vdev_cache_stat_init(void);
67287db74cekextern void vdev_cache_stat_fini(void);
67387db74cek
674fa9e406ahrens/* Initialization and termination */
675fa9e406ahrensextern void spa_init(int flags);
676fa9e406ahrensextern void spa_fini(void);
677e7cbe64gwextern void spa_boot_init();
678fa9e406ahrens
679b1b8ab3lling/* properties */
680990b485llingextern int spa_prop_set(spa_t *spa, nvlist_t *nvp);
681990b485llingextern int spa_prop_get(spa_t *spa, nvlist_t **nvp);
682990b485llingextern void spa_prop_clear_bootfs(spa_t *spa, uint64_t obj, dmu_tx_t *tx);
683379c004Eric Schrockextern void spa_configfile_set(spa_t *, nvlist_t *, boolean_t);
684b1b8ab3lling
6853d7072feschrock/* asynchronous event notification */
6863d7072feschrockextern void spa_event_notify(spa_t *spa, vdev_t *vdev, const char *name);
6873d7072feschrock
688fa9e406ahrens#ifdef ZFS_DEBUG
689c0a8126ek#define	dprintf_bp(bp, fmt, ...) do {				\
690c0a8126ek	if (zfs_flags & ZFS_DEBUG_DPRINTF) { 			\
691c0a8126ek	char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP);	\
692b24ab67Jeff Bonwick	sprintf_blkptr(__blkbuf, (bp));				\
693c0a8126ek	dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf);		\
694c0a8126ek	kmem_free(__blkbuf, BP_SPRINTF_LEN);			\
695fa9e406ahrens	} \
696fa9e406ahrens_NOTE(CONSTCOND) } while (0)
697fa9e406ahrens#else
698fa9e406ahrens#define	dprintf_bp(bp, fmt, ...)
699fa9e406ahrens#endif
700fa9e406ahrens
7018ad4d6dJeff Bonwickextern int spa_mode_global;			/* mode, e.g. FREAD | FWRITE */
702fa9e406ahrens
703fa9e406ahrens#ifdef	__cplusplus
704fa9e406ahrens}
705fa9e406ahrens#endif
706fa9e406ahrens
707fa9e406ahrens#endif	/* _SYS_SPA_H */
708