spa.h revision fa9e4066f08beec538e775443c5be79dd423fcab
1fa9e406ahrens/*
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5fa9e406ahrens * Common Development and Distribution License, Version 1.0 only
6fa9e406ahrens * (the "License").  You may not use this file except in compliance
7fa9e406ahrens * with the License.
8fa9e406ahrens *
9fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
11fa9e406ahrens * See the License for the specific language governing permissions
12fa9e406ahrens * and limitations under the License.
13fa9e406ahrens *
14fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
15fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
17fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
18fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
19fa9e406ahrens *
20fa9e406ahrens * CDDL HEADER END
21fa9e406ahrens */
22fa9e406ahrens/*
23fa9e406ahrens * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24fa9e406ahrens * Use is subject to license terms.
25fa9e406ahrens */
26fa9e406ahrens
27fa9e406ahrens#ifndef _SYS_SPA_H
28fa9e406ahrens#define	_SYS_SPA_H
29fa9e406ahrens
30fa9e406ahrens#pragma ident	"%Z%%M%	%I%	%E% SMI"
31fa9e406ahrens
32fa9e406ahrens#include <sys/avl.h>
33fa9e406ahrens#include <sys/zfs_context.h>
34fa9e406ahrens#include <sys/nvpair.h>
35fa9e406ahrens#include <sys/sysmacros.h>
36fa9e406ahrens#include <sys/types.h>
37fa9e406ahrens#include <sys/fs/zfs.h>
38fa9e406ahrens
39fa9e406ahrens#ifdef	__cplusplus
40fa9e406ahrensextern "C" {
41fa9e406ahrens#endif
42fa9e406ahrens
43fa9e406ahrens/*
44fa9e406ahrens * Forward references that lots of things need.
45fa9e406ahrens */
46fa9e406ahrenstypedef struct spa spa_t;
47fa9e406ahrenstypedef struct vdev vdev_t;
48fa9e406ahrenstypedef struct metaslab metaslab_t;
49fa9e406ahrenstypedef struct zilog zilog_t;
50fa9e406ahrenstypedef struct traverse_handle traverse_handle_t;
51fa9e406ahrensstruct dsl_pool;
52fa9e406ahrens
53fa9e406ahrens/*
54fa9e406ahrens * General-purpose 32-bit and 64-bit bitfield encodings.
55fa9e406ahrens */
56fa9e406ahrens#define	BF32_DECODE(x, low, len)	P2PHASE((x) >> (low), 1U << (len))
57fa9e406ahrens#define	BF64_DECODE(x, low, len)	P2PHASE((x) >> (low), 1ULL << (len))
58fa9e406ahrens#define	BF32_ENCODE(x, low, len)	(P2PHASE((x), 1U << (len)) << (low))
59fa9e406ahrens#define	BF64_ENCODE(x, low, len)	(P2PHASE((x), 1ULL << (len)) << (low))
60fa9e406ahrens
61fa9e406ahrens#define	BF32_GET(x, low, len)		BF32_DECODE(x, low, len)
62fa9e406ahrens#define	BF64_GET(x, low, len)		BF64_DECODE(x, low, len)
63fa9e406ahrens
64fa9e406ahrens#define	BF32_SET(x, low, len, val)	\
65fa9e406ahrens	((x) ^= BF32_ENCODE((x >> low) ^ val, low, len))
66fa9e406ahrens#define	BF64_SET(x, low, len, val)	\
67fa9e406ahrens	((x) ^= BF64_ENCODE((x >> low) ^ val, low, len))
68fa9e406ahrens
69fa9e406ahrens#define	BF32_GET_SB(x, low, len, shift, bias)	\
70fa9e406ahrens	((BF32_GET(x, low, len) + (bias)) << (shift))
71fa9e406ahrens#define	BF64_GET_SB(x, low, len, shift, bias)	\
72fa9e406ahrens	((BF64_GET(x, low, len) + (bias)) << (shift))
73fa9e406ahrens
74fa9e406ahrens#define	BF32_SET_SB(x, low, len, shift, bias, val)	\
75fa9e406ahrens	BF32_SET(x, low, len, ((val) >> (shift)) - (bias))
76fa9e406ahrens#define	BF64_SET_SB(x, low, len, shift, bias, val)	\
77fa9e406ahrens	BF64_SET(x, low, len, ((val) >> (shift)) - (bias))
78fa9e406ahrens
79fa9e406ahrens/*
80fa9e406ahrens * We currently support nine block sizes, from 512 bytes to 128K.
81fa9e406ahrens * We could go higher, but the benefits are near-zero and the cost
82fa9e406ahrens * of COWing a giant block to modify one byte would become excessive.
83fa9e406ahrens */
84fa9e406ahrens#define	SPA_MINBLOCKSHIFT	9
85fa9e406ahrens#define	SPA_MAXBLOCKSHIFT	17
86fa9e406ahrens#define	SPA_MINBLOCKSIZE	(1ULL << SPA_MINBLOCKSHIFT)
87fa9e406ahrens#define	SPA_MAXBLOCKSIZE	(1ULL << SPA_MAXBLOCKSHIFT)
88fa9e406ahrens
89fa9e406ahrens#define	SPA_BLOCKSIZES		(SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)
90fa9e406ahrens
91fa9e406ahrens/*
92fa9e406ahrens * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
93fa9e406ahrens * The ASIZE encoding should be at least 64 times larger (6 more bits)
94fa9e406ahrens * to support up to 4-way RAID-Z mirror mode with worst-case gang block
95fa9e406ahrens * overhead, three DVAs per bp, plus one more bit in case we do anything
96fa9e406ahrens * else that expands the ASIZE.
97fa9e406ahrens */
98fa9e406ahrens#define	SPA_LSIZEBITS		16	/* LSIZE up to 32M (2^16 * 512)	*/
99fa9e406ahrens#define	SPA_PSIZEBITS		16	/* PSIZE up to 32M (2^16 * 512)	*/
100fa9e406ahrens#define	SPA_ASIZEBITS		24	/* ASIZE up to 64 times larger	*/
101fa9e406ahrens
102fa9e406ahrens/*
103fa9e406ahrens * All SPA data is represented by 128-bit data virtual addresses (DVAs).
104fa9e406ahrens * The members of the dva_t should be considered opaque outside the SPA.
105fa9e406ahrens */
106fa9e406ahrenstypedef struct dva {
107fa9e406ahrens	uint64_t	dva_word[2];
108fa9e406ahrens} dva_t;
109fa9e406ahrens
110fa9e406ahrens/*
111fa9e406ahrens * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
112fa9e406ahrens */
113fa9e406ahrenstypedef struct zio_cksum {
114fa9e406ahrens	uint64_t	zc_word[4];
115fa9e406ahrens} zio_cksum_t;
116fa9e406ahrens
117fa9e406ahrens/*
118fa9e406ahrens * Each block is described by its DVAs, time of birth, checksum, etc.
119fa9e406ahrens * The word-by-word, bit-by-bit layout of the blkptr is as follows:
120fa9e406ahrens *
121fa9e406ahrens *	64	56	48	40	32	24	16	8	0
122fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
123fa9e406ahrens * 0	|		vdev1		| GRID  |	  ASIZE		|
124fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
125fa9e406ahrens * 1	|G|			 offset1				|
126fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
127fa9e406ahrens * 2	|		vdev2		| GRID  |	  ASIZE		|
128fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
129fa9e406ahrens * 3	|G|			 offset2				|
130fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
131fa9e406ahrens * 4	|		vdev3		| GRID  |	  ASIZE		|
132fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
133fa9e406ahrens * 5	|G|			 offset3				|
134fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
135fa9e406ahrens * 6	|E| lvl | type	| cksum | comp	|     PSIZE	|     LSIZE	|
136fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
137fa9e406ahrens * 7	|			padding					|
138fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
139fa9e406ahrens * 8	|			padding					|
140fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
141fa9e406ahrens * 9	|			padding					|
142fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
143fa9e406ahrens * a	|			birth txg				|
144fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
145fa9e406ahrens * b	|			fill count				|
146fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
147fa9e406ahrens * c	|			checksum[0]				|
148fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
149fa9e406ahrens * d	|			checksum[1]				|
150fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
151fa9e406ahrens * e	|			checksum[2]				|
152fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
153fa9e406ahrens * f	|			checksum[3]				|
154fa9e406ahrens *	+-------+-------+-------+-------+-------+-------+-------+-------+
155fa9e406ahrens *
156fa9e406ahrens * Legend:
157fa9e406ahrens *
158fa9e406ahrens * vdev		virtual device ID
159fa9e406ahrens * offset	offset into virtual device
160fa9e406ahrens * LSIZE	logical size
161fa9e406ahrens * PSIZE	physical size (after compression)
162fa9e406ahrens * ASIZE	allocated size (including RAID-Z parity and gang block headers)
163fa9e406ahrens * GRID		RAID-Z layout information (reserved for future use)
164fa9e406ahrens * cksum	checksum function
165fa9e406ahrens * comp		compression function
166fa9e406ahrens * G		gang block indicator
167fa9e406ahrens * E		endianness
168fa9e406ahrens * type		DMU object type
169fa9e406ahrens * lvl		level of indirection
170fa9e406ahrens * birth txg	transaction group in which the block was born
171fa9e406ahrens * fill count	number of non-zero blocks under this bp
172fa9e406ahrens * checksum[4]	256-bit checksum of the data this bp describes
173fa9e406ahrens */
174fa9e406ahrenstypedef struct blkptr {
175fa9e406ahrens	dva_t		blk_dva[3];	/* 128-bit Data Virtual Address	*/
176fa9e406ahrens	uint64_t	blk_prop;	/* size, compression, type, etc	*/
177fa9e406ahrens	uint64_t	blk_pad[3];	/* Extra space for the future	*/
178fa9e406ahrens	uint64_t	blk_birth;	/* transaction group at birth	*/
179fa9e406ahrens	uint64_t	blk_fill;	/* fill count			*/
180fa9e406ahrens	zio_cksum_t	blk_cksum;	/* 256-bit checksum		*/
181fa9e406ahrens} blkptr_t;
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
186fa9e406ahrens/*
187fa9e406ahrens * Macros to get and set fields in a bp or DVA.
188fa9e406ahrens */
189fa9e406ahrens#define	DVA_GET_ASIZE(dva)	\
190fa9e406ahrens	BF64_GET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0)
191fa9e406ahrens#define	DVA_SET_ASIZE(dva, x)	\
192fa9e406ahrens	BF64_SET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0, x)
193fa9e406ahrens
194fa9e406ahrens#define	DVA_GET_GRID(dva)	BF64_GET((dva)->dva_word[0], 24, 8)
195fa9e406ahrens#define	DVA_SET_GRID(dva, x)	BF64_SET((dva)->dva_word[0], 24, 8, x)
196fa9e406ahrens
197fa9e406ahrens#define	DVA_GET_VDEV(dva)	BF64_GET((dva)->dva_word[0], 32, 32)
198fa9e406ahrens#define	DVA_SET_VDEV(dva, x)	BF64_SET((dva)->dva_word[0], 32, 32, x)
199fa9e406ahrens
200fa9e406ahrens#define	DVA_GET_OFFSET(dva)	\
201fa9e406ahrens	BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0)
202fa9e406ahrens#define	DVA_SET_OFFSET(dva, x)	\
203fa9e406ahrens	BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x)
204fa9e406ahrens
205fa9e406ahrens#define	DVA_GET_GANG(dva)	BF64_GET((dva)->dva_word[1], 63, 1)
206fa9e406ahrens#define	DVA_SET_GANG(dva, x)	BF64_SET((dva)->dva_word[1], 63, 1, x)
207fa9e406ahrens
208fa9e406ahrens#define	BP_GET_LSIZE(bp)	\
209fa9e406ahrens	(BP_IS_HOLE(bp) ? 0 : \
210fa9e406ahrens	BF64_GET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1))
211fa9e406ahrens#define	BP_SET_LSIZE(bp, x)	\
212fa9e406ahrens	BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
213fa9e406ahrens
214fa9e406ahrens#define	BP_GET_PSIZE(bp)	\
215fa9e406ahrens	BF64_GET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1)
216fa9e406ahrens#define	BP_SET_PSIZE(bp, x)	\
217fa9e406ahrens	BF64_SET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1, x)
218fa9e406ahrens
219fa9e406ahrens#define	BP_GET_COMPRESS(bp)	BF64_GET((bp)->blk_prop, 32, 8)
220fa9e406ahrens#define	BP_SET_COMPRESS(bp, x)	BF64_SET((bp)->blk_prop, 32, 8, x)
221fa9e406ahrens
222fa9e406ahrens#define	BP_GET_CHECKSUM(bp)	BF64_GET((bp)->blk_prop, 40, 8)
223fa9e406ahrens#define	BP_SET_CHECKSUM(bp, x)	BF64_SET((bp)->blk_prop, 40, 8, x)
224fa9e406ahrens
225fa9e406ahrens#define	BP_GET_TYPE(bp)		BF64_GET((bp)->blk_prop, 48, 8)
226fa9e406ahrens#define	BP_SET_TYPE(bp, x)	BF64_SET((bp)->blk_prop, 48, 8, x)
227fa9e406ahrens
228fa9e406ahrens#define	BP_GET_LEVEL(bp)	BF64_GET((bp)->blk_prop, 56, 5)
229fa9e406ahrens#define	BP_SET_LEVEL(bp, x)	BF64_SET((bp)->blk_prop, 56, 5, x)
230fa9e406ahrens
231fa9e406ahrens#define	BP_GET_BYTEORDER(bp)	(0 - BF64_GET((bp)->blk_prop, 63, 1))
232fa9e406ahrens#define	BP_SET_BYTEORDER(bp, x)	BF64_SET((bp)->blk_prop, 63, 1, x)
233fa9e406ahrens
234fa9e406ahrens#define	BP_GET_ASIZE(bp)	\
235fa9e406ahrens	(DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
236fa9e406ahrens	DVA_GET_ASIZE(&(bp)->blk_dva[2]))
237fa9e406ahrens
238fa9e406ahrens#define	DVA_EQUAL(dva1, dva2)	\
239fa9e406ahrens	((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
240fa9e406ahrens	(dva1)->dva_word[0] == (dva2)->dva_word[0])
241fa9e406ahrens
242fa9e406ahrens#define	DVA_IS_VALID(dva)	(DVA_GET_ASIZE(dva) != 0)
243fa9e406ahrens
244fa9e406ahrens#define	ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3)	\
245fa9e406ahrens{						\
246fa9e406ahrens	(zcp)->zc_word[0] = w0;			\
247fa9e406ahrens	(zcp)->zc_word[1] = w1;			\
248fa9e406ahrens	(zcp)->zc_word[2] = w2;			\
249fa9e406ahrens	(zcp)->zc_word[3] = w3;			\
250fa9e406ahrens}
251fa9e406ahrens
252fa9e406ahrens#define	BP_IS_HOLE(bp)		((bp)->blk_birth == 0)
253fa9e406ahrens
254fa9e406ahrens#define	BP_IDENTITY(bp)		(&(bp)->blk_dva[0])
255fa9e406ahrens
256fa9e406ahrens#define	BP_ZERO(bp)				\
257fa9e406ahrens{						\
258fa9e406ahrens	(bp)->blk_dva[0].dva_word[0] = 0;	\
259fa9e406ahrens	(bp)->blk_dva[0].dva_word[1] = 0;	\
260fa9e406ahrens	(bp)->blk_dva[1].dva_word[0] = 0;	\
261fa9e406ahrens	(bp)->blk_dva[1].dva_word[1] = 0;	\
262fa9e406ahrens	(bp)->blk_dva[2].dva_word[0] = 0;	\
263fa9e406ahrens	(bp)->blk_dva[2].dva_word[1] = 0;	\
264fa9e406ahrens	(bp)->blk_prop = 0;			\
265fa9e406ahrens	(bp)->blk_pad[0] = 0;			\
266fa9e406ahrens	(bp)->blk_pad[1] = 0;			\
267fa9e406ahrens	(bp)->blk_pad[2] = 0;			\
268fa9e406ahrens	(bp)->blk_birth = 0;			\
269fa9e406ahrens	(bp)->blk_fill = 0;			\
270fa9e406ahrens	ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0);	\
271fa9e406ahrens}
272fa9e406ahrens
273fa9e406ahrens/*
274fa9e406ahrens * Note: the byteorder is either 0 or -1, both of which are palindromes.
275fa9e406ahrens * This simplifies the endianness handling a bit.
276fa9e406ahrens */
277fa9e406ahrens#ifdef _BIG_ENDIAN
278fa9e406ahrens#define	ZFS_HOST_BYTEORDER	(0ULL)
279fa9e406ahrens#else
280fa9e406ahrens#define	ZFS_HOST_BYTEORDER	(-1ULL)
281fa9e406ahrens#endif
282fa9e406ahrens
283fa9e406ahrens#define	BP_SHOULD_BYTESWAP(bp)	(BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER)
284fa9e406ahrens
285fa9e406ahrens#include <sys/dmu.h>
286fa9e406ahrens
287fa9e406ahrens/*
288fa9e406ahrens * Routines found in spa.c
289fa9e406ahrens */
290fa9e406ahrens
291fa9e406ahrens/* state manipulation functions */
292fa9e406ahrensextern int spa_open(const char *pool, spa_t **, void *tag);
293fa9e406ahrensextern int spa_get_stats(const char *pool, nvlist_t **config);
294fa9e406ahrensextern int spa_create(const char *pool, nvlist_t *config, char *altroot);
295fa9e406ahrensextern int spa_import(const char *pool, nvlist_t *config, char *altroot);
296fa9e406ahrensextern nvlist_t *spa_tryimport(nvlist_t *tryconfig);
297fa9e406ahrensextern int spa_destroy(char *pool);
298fa9e406ahrensextern int spa_export(char *pool);
299fa9e406ahrens
300fa9e406ahrens/* device manipulation */
301fa9e406ahrensextern int spa_vdev_add(spa_t *spa, nvlist_t *nvroot);
302fa9e406ahrensextern int spa_vdev_add_unlocked(spa_t *spa, nvlist_t *nvroot);
303fa9e406ahrensextern int spa_vdev_attach(spa_t *spa, const char *path, nvlist_t *nvroot,
304fa9e406ahrens    int replacing);
305fa9e406ahrensextern int spa_vdev_detach(spa_t *spa, const char *path, uint64_t guid,
306fa9e406ahrens    int replace_done);
307fa9e406ahrensextern void spa_vdev_replace_done(spa_t *spa);
308fa9e406ahrens
309fa9e406ahrens/* scrubbing */
310fa9e406ahrensextern int spa_scrub(spa_t *spa, pool_scrub_type_t type, boolean_t force);
311fa9e406ahrensextern void spa_scrub_suspend(spa_t *spa);
312fa9e406ahrensextern void spa_scrub_resume(spa_t *spa);
313fa9e406ahrensextern void spa_scrub_restart(spa_t *spa, uint64_t txg);
314fa9e406ahrens
315fa9e406ahrens/* spa syncing */
316fa9e406ahrensextern void spa_sync(spa_t *spa, uint64_t txg); /* only for DMU use */
317fa9e406ahrensextern void spa_sync_allpools(void);
318fa9e406ahrens
319fa9e406ahrens/*
320fa9e406ahrens * SPA configuration functions in spa_config.c
321fa9e406ahrens */
322fa9e406ahrensextern void spa_config_sync(void);
323fa9e406ahrensextern void spa_config_load(void);
324fa9e406ahrensextern nvlist_t *spa_all_configs(uint64_t *);
325fa9e406ahrensextern void spa_config_set(spa_t *spa, nvlist_t *config);
326fa9e406ahrensextern nvlist_t *spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg,
327fa9e406ahrens    int getstats);
328fa9e406ahrens
329fa9e406ahrens/*
330fa9e406ahrens * Miscellaneous SPA routines in spa_misc.c
331fa9e406ahrens */
332fa9e406ahrens
333fa9e406ahrens/* Namespace manipulation */
334fa9e406ahrensextern spa_t *spa_lookup(const char *name);
335fa9e406ahrensextern spa_t *spa_add(const char *name);
336fa9e406ahrensextern void spa_remove(spa_t *spa);
337fa9e406ahrensextern spa_t *spa_next(spa_t *prev);
338fa9e406ahrens
339fa9e406ahrens/* Refcount functions */
340fa9e406ahrensextern void spa_open_ref(spa_t *spa, void *tag);
341fa9e406ahrensextern void spa_close(spa_t *spa, void *tag);
342fa9e406ahrensextern boolean_t spa_refcount_zero(spa_t *spa);
343fa9e406ahrens
344fa9e406ahrens/* Pool configuration lock */
345fa9e406ahrensextern void spa_config_enter(spa_t *spa, krw_t rw);
346fa9e406ahrensextern void spa_config_exit(spa_t *spa);
347fa9e406ahrensextern boolean_t spa_config_held(spa_t *spa, krw_t rw);
348fa9e406ahrens
349fa9e406ahrens/* Pool vdev add/remove lock */
350fa9e406ahrensextern uint64_t spa_vdev_enter(spa_t *spa);
351fa9e406ahrensextern int spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error);
352fa9e406ahrens
353fa9e406ahrens/* Accessor functions */
354fa9e406ahrensextern krwlock_t *spa_traverse_rwlock(spa_t *spa);
355fa9e406ahrensextern int spa_traverse_wanted(spa_t *spa);
356fa9e406ahrensextern struct dsl_pool *spa_get_dsl(spa_t *spa);
357fa9e406ahrensextern blkptr_t *spa_get_rootblkptr(spa_t *spa);
358fa9e406ahrensextern void spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp);
359fa9e406ahrensextern void spa_altroot(spa_t *, char *, size_t);
360fa9e406ahrensextern int spa_sync_pass(spa_t *spa);
361fa9e406ahrensextern char *spa_name(spa_t *spa);
362fa9e406ahrensextern uint64_t spa_guid(spa_t *spa);
363fa9e406ahrensextern uint64_t spa_last_synced_txg(spa_t *spa);
364fa9e406ahrensextern uint64_t spa_first_txg(spa_t *spa);
365fa9e406ahrensextern int spa_state(spa_t *spa);
366fa9e406ahrensextern uint64_t spa_freeze_txg(spa_t *spa);
367fa9e406ahrensstruct metaslab_class;
368fa9e406ahrensextern struct metaslab_class *spa_metaslab_class_select(spa_t *spa);
369fa9e406ahrensextern uint64_t spa_get_alloc(spa_t *spa);
370fa9e406ahrensextern uint64_t spa_get_space(spa_t *spa);
371fa9e406ahrensextern uint64_t spa_get_asize(spa_t *spa, uint64_t lsize);
372fa9e406ahrensextern int spa_busy(void);
373fa9e406ahrens
374fa9e406ahrens/* Miscellaneous support routines */
375fa9e406ahrensextern int spa_rename(const char *oldname, const char *newname);
376fa9e406ahrensextern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid);
377fa9e406ahrensextern char *spa_strdup(const char *);
378fa9e406ahrensextern void spa_strfree(char *);
379fa9e406ahrensextern uint64_t spa_get_random(uint64_t range);
380fa9e406ahrensextern void sprintf_blkptr(char *buf, blkptr_t *bp);
381fa9e406ahrensextern void spa_freeze(spa_t *spa);
382fa9e406ahrensextern void spa_evict_all(void);
383fa9e406ahrens
384fa9e406ahrens/* Initialization and termination */
385fa9e406ahrensextern void spa_init(int flags);
386fa9e406ahrensextern void spa_fini(void);
387fa9e406ahrens
388fa9e406ahrens#ifdef ZFS_DEBUG
389fa9e406ahrens#define	dprintf_bp(bp, fmt, ...) do {			\
390fa9e406ahrens	if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
391fa9e406ahrens	char __blkbuf[200];				\
392fa9e406ahrens	sprintf_blkptr(__blkbuf, (bp));			\
393fa9e406ahrens	dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf);	\
394fa9e406ahrens	} \
395fa9e406ahrens_NOTE(CONSTCOND) } while (0)
396fa9e406ahrens#else
397fa9e406ahrens#define	dprintf_bp(bp, fmt, ...)
398fa9e406ahrens#endif
399fa9e406ahrens
400fa9e406ahrensextern int spa_mode;			/* mode, e.g. FREAD | FWRITE */
401fa9e406ahrens
402fa9e406ahrens#ifdef	__cplusplus
403fa9e406ahrens}
404fa9e406ahrens#endif
405fa9e406ahrens
406fa9e406ahrens#endif	/* _SYS_SPA_H */
407