spa.h revision ad135b5d644628e791c3188a6ecbd9c257961ef8
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.
23ad135b5Christopher Siden * Copyright (c) 2012 by Delphix. All rights reserved.
24e9103aaGarrett D'Amore * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
25fa9e406ahrens */
26fa9e406ahrens
27fa9e406ahrens#ifndef _SYS_SPA_H
28fa9e406ahrens#define	_SYS_SPA_H
29fa9e406ahrens
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>
36fa9e406ahrens
37fa9e406ahrens#ifdef	__cplusplus
38fa9e406ahrensextern "C" {
39fa9e406ahrens#endif
40fa9e406ahrens
41fa9e406ahrens/*
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;
55fa9e406ahrens
56fa9e406ahrens/*
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))
63fa9e406ahrens
64fa9e406ahrens#define	BF32_GET(x, low, len)		BF32_DECODE(x, low, len)
65fa9e406ahrens#define	BF64_GET(x, low, len)		BF64_DECODE(x, low, len)
66fa9e406ahrens
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))
71fa9e406ahrens
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))
76fa9e406ahrens
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))
81fa9e406ahrens
82fa9e406ahrens/*
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
89fa9e406ahrens#define	SPA_MINBLOCKSIZE	(1ULL << SPA_MINBLOCKSHIFT)
90fa9e406ahrens#define	SPA_MAXBLOCKSIZE	(1ULL << SPA_MAXBLOCKSHIFT)
91fa9e406ahrens
92fa9e406ahrens#define	SPA_BLOCKSIZES		(SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)
93fa9e406ahrens
94fa9e406ahrens/*
95f7991baTim Haley * Size of block to hold the configuration data (a packed nvlist)
96f7991baTim Haley */
97ad135b5Christopher Siden#define	SPA_CONFIG_BLOCKSIZE	(1ULL << 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	*/
109fa9e406ahrens
110fa9e406ahrens/*
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;
117fa9e406ahrens
118fa9e406ahrens/*
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;
124fa9e406ahrens
125fa9e406ahrens/*
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	*/
187fa9e406ahrens
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
198fa9e406ahrens/*
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)
205fa9e406ahrens
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)
208fa9e406ahrens
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)
211fa9e406ahrens
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)
216fa9e406ahrens
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)
219fa9e406ahrens
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)
224fa9e406ahrens
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)
229fa9e406ahrens
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)
238fa9e406ahrens
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)
241fa9e406ahrens
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)
244fa9e406ahrens
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)
247fa9e406ahrens
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}
259fa9e406ahrens
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]))
26399653d4eschrock
26499653d4eschrock#define	BP_GET_UCSIZE(bp) \
265ad135b5Christopher Siden	((BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp))) ? \
2663f9d6adLin Ling	BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp))
267fa9e406ahrens
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]))
27244cd46cbillm
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]))
27744cd46cbillm
278fa9e406ahrens#define	DVA_EQUAL(dva1, dva2)	\
279fa9e406ahrens	((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
280fa9e406ahrens	(dva1)->dva_word[0] == (dva2)->dva_word[0])
281fa9e406ahrens
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])))
2936b4acc8ahrens
294fa9e406ahrens#define	DVA_IS_VALID(dva)	(DVA_GET_ASIZE(dva) != 0)
295fa9e406ahrens
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;			\
302fa9e406ahrens}
303fa9e406ahrens
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)
307fa9e406ahrens
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);	\
327fa9e406ahrens}
328fa9e406ahrens
329fa9e406ahrens/*
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)
335fa9e406ahrens#else
336fa9e406ahrens#define	ZFS_HOST_BYTEORDER	(-1ULL)
337fa9e406ahrens#endif
338fa9e406ahrens
339fa9e406ahrens#define	BP_SHOULD_BYTESWAP(bp)	(BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER)
340fa9e406ahrens
34144cd46cbillm#define	BP_SPRINTF_LEN	320
342fbabab8maybee
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>
404fa9e406ahrens
405ad23a2djohansen#define	BP_GET_BUFC_TYPE(bp)						\
406ad135b5Christopher Siden	(((BP_GET_LEVEL(bp) > 0) || (DMU_OT_IS_METADATA(BP_GET_TYPE(bp)))) ? \
407ad135b5Christopher Siden	ARC_BUFC_METADATA : ARC_BUFC_DATA)
408fa9e406ahrens
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);
418ad135b5Christopher Sidenextern int spa_get_stats(const char *pool, nvlist_t **config, char *altroot,
419ad135b5Christopher Siden    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);
438ea8dc4beschrock
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
453fa9e406ahrens
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);
466fa9e406ahrens
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);
47299653d4eschrock
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);
479fa94a07brendan
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);
483fa9e406ahrens
484fa9e406ahrens/* spa syncing */
485fa9e406ahrensextern void spa_sync(spa_t *spa, uint64_t txg); /* only for DMU use */
486fa9e406ahrensextern void spa_sync_allpools(void);
487fa9e406ahrens
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;
4983a737e0brendan
499fa9e406ahrens/*
500fa9e406ahrens * SPA configuration functions in spa_config.c
501fa9e406ahrens */
5020373e76bonwick
5030373e76bonwick#define	SPA_CONFIG_UPDATE_POOL	0
5040373e76bonwick#define	SPA_CONFIG_UPDATE_VDEVS	1
5050373e76bonwick
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);
513fa9e406ahrens
514fa9e406ahrens/*
515fa9e406ahrens * Miscellaneous SPA routines in spa_misc.c
516fa9e406ahrens */
517fa9e406ahrens
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);
523fa9e406ahrens
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);
528fa9e406ahrens
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);
546fa9e406ahrens
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);
553fa9e406ahrens
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);
576ad135b5Christopher Sidenextern boolean_t spa_is_initializing(spa_t *spa);
577fa9e406ahrensextern blkptr_t *spa_get_rootblkptr(spa_t *spa);
578fa9e406ahrensextern void spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp);
579fa9e406ahrensextern void spa_altroot(spa_t *, char *, size_t);
580fa9e406ahrensextern int spa_sync_pass(spa_t *spa);
581fa9e406ahrensextern char *spa_name(spa_t *spa);
582fa9e406ahrensextern uint64_t spa_guid(spa_t *spa);
583e9103aaGarrett D'Amoreextern uint64_t spa_load_guid(spa_t *spa);
584fa9e406ahrensextern uint64_t spa_last_synced_txg(spa_t *spa);
585fa9e406ahrensextern uint64_t spa_first_txg(spa_t *spa);
586b24ab67Jeff Bonwickextern uint64_t spa_syncing_txg(spa_t *spa);
58799653d4eschrockextern uint64_t spa_version(spa_t *spa);
58888b7b0fMatthew Ahrensextern pool_state_t spa_state(spa_t *spa);
589b16da2eGeorge Wilsonextern spa_load_state_t spa_load_state(spa_t *spa);
590fa9e406ahrensextern uint64_t spa_freeze_txg(spa_t *spa);
591fa9e406ahrensextern uint64_t spa_get_asize(spa_t *spa, uint64_t lsize);
592485bbbfGeorge Wilsonextern uint64_t spa_get_dspace(spa_t *spa);
593485bbbfGeorge Wilsonextern void spa_update_dspace(spa_t *spa);
59444cd46cbillmextern uint64_t spa_version(spa_t *spa);
595b24ab67Jeff Bonwickextern boolean_t spa_deflate(spa_t *spa);
596b24ab67Jeff Bonwickextern metaslab_class_t *spa_normal_class(spa_t *spa);
597b24ab67Jeff Bonwickextern metaslab_class_t *spa_log_class(spa_t *spa);
59844cd46cbillmextern int spa_max_replication(spa_t *spa);
5993f9d6adLin Lingextern int spa_prev_software_version(spa_t *spa);
600fa9e406ahrensextern int spa_busy(void);
6010a4e951gwextern uint8_t spa_get_failmode(spa_t *spa);
602e14bb32Jeff Bonwickextern boolean_t spa_suspended(spa_t *spa);
603b24ab67Jeff Bonwickextern uint64_t spa_bootfs(spa_t *spa);
604b24ab67Jeff Bonwickextern uint64_t spa_delegation(spa_t *spa);
605b24ab67Jeff Bonwickextern objset_t *spa_meta_objset(spa_t *spa);
606fa9e406ahrens
607fa9e406ahrens/* Miscellaneous support routines */
608ad135b5Christopher Sidenextern void spa_activate_mos_feature(spa_t *spa, const char *feature);
609ad135b5Christopher Sidenextern void spa_deactivate_mos_feature(spa_t *spa, const char *feature);
610fa9e406ahrensextern int spa_rename(const char *oldname, const char *newname);
611f9af39bGeorge Wilsonextern spa_t *spa_by_guid(uint64_t pool_guid, uint64_t device_guid);
612fa9e406ahrensextern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid);
613fa9e406ahrensextern char *spa_strdup(const char *);
614fa9e406ahrensextern void spa_strfree(char *);
615fa9e406ahrensextern uint64_t spa_get_random(uint64_t range);
6161195e68Mark J Musanteextern uint64_t spa_generate_guid(spa_t *spa);
617b24ab67Jeff Bonwickextern void sprintf_blkptr(char *buf, const blkptr_t *bp);
618fa9e406ahrensextern void spa_freeze(spa_t *spa);
619e9103aaGarrett D'Amoreextern int spa_change_guid(spa_t *spa);
620990b485llingextern void spa_upgrade(spa_t *spa, uint64_t version);
621fa9e406ahrensextern void spa_evict_all(void);
622c5904d1eschrockextern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid,
623c5904d1eschrock    boolean_t l2cache);
62499653d4eschrockextern boolean_t spa_has_spare(spa_t *, uint64_t guid);
625b24ab67Jeff Bonwickextern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva);
626b24ab67Jeff Bonwickextern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp);
627b24ab67Jeff Bonwickextern uint64_t bp_get_dsize(spa_t *spa, const blkptr_t *bp);
6286ce0521perrinextern boolean_t spa_has_slogs(spa_t *spa);
629bf82a41eschrockextern boolean_t spa_is_root(spa_t *spa);
6308ad4d6dJeff Bonwickextern boolean_t spa_writeable(spa_t *spa);
631468c413Tim Haley
6328ad4d6dJeff Bonwickextern int spa_mode(spa_t *spa);
633ca45db4Chris Kirbyextern uint64_t strtonum(const char *str, char **nptr);
634ea8dc4beschrock
63506eeb2aek/* history logging */
636ecd6cf8markstypedef enum history_log_type {
637ecd6cf8marks	LOG_CMD_POOL_CREATE,
638ecd6cf8marks	LOG_CMD_NORMAL,
639ecd6cf8marks	LOG_INTERNAL
640ecd6cf8marks} history_log_type_t;
641ecd6cf8marks
642ecd6cf8markstypedef struct history_arg {
643495807dMatthew Ahrens	char *ha_history_str;
644ecd6cf8marks	history_log_type_t ha_log_type;
645ecd6cf8marks	history_internal_events_t ha_event;
646495807dMatthew Ahrens	char *ha_zone;
647495807dMatthew Ahrens	uid_t ha_uid;
648ecd6cf8marks} history_arg_t;
649ecd6cf8marks
650ecd6cf8marksextern char *spa_his_ievent_table[];
651ecd6cf8marks
65206eeb2aekextern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx);
65306eeb2aekextern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read,
65406eeb2aek    char *his_buf);
65506eeb2aekextern int spa_history_log(spa_t *spa, const char *his_buf,
656ecd6cf8marks    history_log_type_t what);
6573f9d6adLin Lingextern void spa_history_log_internal(history_internal_events_t event,
6583f9d6adLin Ling    spa_t *spa, dmu_tx_t *tx, const char *fmt, ...);
659c8e1f6dMark J Musanteextern void spa_history_log_version(spa_t *spa, history_internal_events_t evt);
66006eeb2aek
661ea8dc4beschrock/* error handling */
662ea8dc4beschrockstruct zbookmark;
663b24ab67Jeff Bonwickextern void spa_log_error(spa_t *spa, zio_t *zio);
664ea8dc4beschrockextern void zfs_ereport_post(const char *class, spa_t *spa, vdev_t *vd,
665b24ab67Jeff Bonwick    zio_t *zio, uint64_t stateoroffset, uint64_t length);
6663d7072feschrockextern void zfs_post_remove(spa_t *spa, vdev_t *vd);
667069f55eEric Schrockextern void zfs_post_state_change(spa_t *spa, vdev_t *vd);
6683d7072feschrockextern void zfs_post_autoreplace(spa_t *spa, vdev_t *vd);
669ea8dc4beschrockextern uint64_t spa_get_errlog_size(spa_t *spa);
670ea8dc4beschrockextern int spa_get_errlog(spa_t *spa, void *uaddr, size_t *count);
671ea8dc4beschrockextern void spa_errlog_rotate(spa_t *spa);
672ea8dc4beschrockextern void spa_errlog_drain(spa_t *spa);
673ea8dc4beschrockextern void spa_errlog_sync(spa_t *spa, uint64_t txg);
674ea8dc4beschrockextern void spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub);
675fa9e406ahrens
67687db74cek/* vdev cache */
67787db74cekextern void vdev_cache_stat_init(void);
67887db74cekextern void vdev_cache_stat_fini(void);
67987db74cek
680fa9e406ahrens/* Initialization and termination */
681fa9e406ahrensextern void spa_init(int flags);
682fa9e406ahrensextern void spa_fini(void);
683e7cbe64gwextern void spa_boot_init();
684fa9e406ahrens
685b1b8ab3lling/* properties */
686990b485llingextern int spa_prop_set(spa_t *spa, nvlist_t *nvp);
687990b485llingextern int spa_prop_get(spa_t *spa, nvlist_t **nvp);
688990b485llingextern void spa_prop_clear_bootfs(spa_t *spa, uint64_t obj, dmu_tx_t *tx);
689379c004Eric Schrockextern void spa_configfile_set(spa_t *, nvlist_t *, boolean_t);
690b1b8ab3lling
6913d7072feschrock/* asynchronous event notification */
6923d7072feschrockextern void spa_event_notify(spa_t *spa, vdev_t *vdev, const char *name);
6933d7072feschrock
694fa9e406ahrens#ifdef ZFS_DEBUG
695c0a8126ek#define	dprintf_bp(bp, fmt, ...) do {				\
696c0a8126ek	if (zfs_flags & ZFS_DEBUG_DPRINTF) { 			\
697c0a8126ek	char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP);	\
698b24ab67Jeff Bonwick	sprintf_blkptr(__blkbuf, (bp));				\
699c0a8126ek	dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf);		\
700c0a8126ek	kmem_free(__blkbuf, BP_SPRINTF_LEN);			\
701fa9e406ahrens	} \
702fa9e406ahrens_NOTE(CONSTCOND) } while (0)
703fa9e406ahrens#else
704fa9e406ahrens#define	dprintf_bp(bp, fmt, ...)
705fa9e406ahrens#endif
706fa9e406ahrens
70709c9d37George Wilsonextern boolean_t spa_debug_enabled(spa_t *spa);
70809c9d37George Wilson#define	spa_dbgmsg(spa, ...)			\
70909c9d37George Wilson{						\
71009c9d37George Wilson	if (spa_debug_enabled(spa))		\
71109c9d37George Wilson		zfs_dbgmsg(__VA_ARGS__);	\
71209c9d37George Wilson}
71309c9d37George Wilson
7148ad4d6dJeff Bonwickextern int spa_mode_global;			/* mode, e.g. FREAD | FWRITE */
715fa9e406ahrens
716fa9e406ahrens#ifdef	__cplusplus
717fa9e406ahrens}
718fa9e406ahrens#endif
719fa9e406ahrens
720fa9e406ahrens#endif	/* _SYS_SPA_H */
721