xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/spa.h (revision 628e3cbed6489fa1db545d8524a06cd6535af456)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_SPA_H
27 #define	_SYS_SPA_H
28 
29 #include <sys/avl.h>
30 #include <sys/zfs_context.h>
31 #include <sys/nvpair.h>
32 #include <sys/sysmacros.h>
33 #include <sys/types.h>
34 #include <sys/fs/zfs.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * Forward references that lots of things need.
42  */
43 typedef struct spa spa_t;
44 typedef struct vdev vdev_t;
45 typedef struct metaslab metaslab_t;
46 typedef struct zilog zilog_t;
47 typedef struct spa_aux_vdev spa_aux_vdev_t;
48 struct dsl_pool;
49 
50 /*
51  * General-purpose 32-bit and 64-bit bitfield encodings.
52  */
53 #define	BF32_DECODE(x, low, len)	P2PHASE((x) >> (low), 1U << (len))
54 #define	BF64_DECODE(x, low, len)	P2PHASE((x) >> (low), 1ULL << (len))
55 #define	BF32_ENCODE(x, low, len)	(P2PHASE((x), 1U << (len)) << (low))
56 #define	BF64_ENCODE(x, low, len)	(P2PHASE((x), 1ULL << (len)) << (low))
57 
58 #define	BF32_GET(x, low, len)		BF32_DECODE(x, low, len)
59 #define	BF64_GET(x, low, len)		BF64_DECODE(x, low, len)
60 
61 #define	BF32_SET(x, low, len, val)	\
62 	((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len))
63 #define	BF64_SET(x, low, len, val)	\
64 	((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len))
65 
66 #define	BF32_GET_SB(x, low, len, shift, bias)	\
67 	((BF32_GET(x, low, len) + (bias)) << (shift))
68 #define	BF64_GET_SB(x, low, len, shift, bias)	\
69 	((BF64_GET(x, low, len) + (bias)) << (shift))
70 
71 #define	BF32_SET_SB(x, low, len, shift, bias, val)	\
72 	BF32_SET(x, low, len, ((val) >> (shift)) - (bias))
73 #define	BF64_SET_SB(x, low, len, shift, bias, val)	\
74 	BF64_SET(x, low, len, ((val) >> (shift)) - (bias))
75 
76 /*
77  * We currently support nine block sizes, from 512 bytes to 128K.
78  * We could go higher, but the benefits are near-zero and the cost
79  * of COWing a giant block to modify one byte would become excessive.
80  */
81 #define	SPA_MINBLOCKSHIFT	9
82 #define	SPA_MAXBLOCKSHIFT	17
83 #define	SPA_MINBLOCKSIZE	(1ULL << SPA_MINBLOCKSHIFT)
84 #define	SPA_MAXBLOCKSIZE	(1ULL << SPA_MAXBLOCKSHIFT)
85 
86 #define	SPA_BLOCKSIZES		(SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)
87 
88 /*
89  * Size of block to hold the configuration data (a packed nvlist)
90  */
91 #define	SPA_CONFIG_BLOCKSIZE	(1 << 14)
92 
93 /*
94  * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
95  * The ASIZE encoding should be at least 64 times larger (6 more bits)
96  * to support up to 4-way RAID-Z mirror mode with worst-case gang block
97  * overhead, three DVAs per bp, plus one more bit in case we do anything
98  * else that expands the ASIZE.
99  */
100 #define	SPA_LSIZEBITS		16	/* LSIZE up to 32M (2^16 * 512)	*/
101 #define	SPA_PSIZEBITS		16	/* PSIZE up to 32M (2^16 * 512)	*/
102 #define	SPA_ASIZEBITS		24	/* ASIZE up to 64 times larger	*/
103 
104 /*
105  * All SPA data is represented by 128-bit data virtual addresses (DVAs).
106  * The members of the dva_t should be considered opaque outside the SPA.
107  */
108 typedef struct dva {
109 	uint64_t	dva_word[2];
110 } dva_t;
111 
112 /*
113  * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
114  */
115 typedef struct zio_cksum {
116 	uint64_t	zc_word[4];
117 } zio_cksum_t;
118 
119 /*
120  * Each block is described by its DVAs, time of birth, checksum, etc.
121  * The word-by-word, bit-by-bit layout of the blkptr is as follows:
122  *
123  *	64	56	48	40	32	24	16	8	0
124  *	+-------+-------+-------+-------+-------+-------+-------+-------+
125  * 0	|		vdev1		| GRID  |	  ASIZE		|
126  *	+-------+-------+-------+-------+-------+-------+-------+-------+
127  * 1	|G|			 offset1				|
128  *	+-------+-------+-------+-------+-------+-------+-------+-------+
129  * 2	|		vdev2		| GRID  |	  ASIZE		|
130  *	+-------+-------+-------+-------+-------+-------+-------+-------+
131  * 3	|G|			 offset2				|
132  *	+-------+-------+-------+-------+-------+-------+-------+-------+
133  * 4	|		vdev3		| GRID  |	  ASIZE		|
134  *	+-------+-------+-------+-------+-------+-------+-------+-------+
135  * 5	|G|			 offset3				|
136  *	+-------+-------+-------+-------+-------+-------+-------+-------+
137  * 6	|E| lvl | type	| cksum | comp	|     PSIZE	|     LSIZE	|
138  *	+-------+-------+-------+-------+-------+-------+-------+-------+
139  * 7	|			padding					|
140  *	+-------+-------+-------+-------+-------+-------+-------+-------+
141  * 8	|			padding					|
142  *	+-------+-------+-------+-------+-------+-------+-------+-------+
143  * 9	|			padding					|
144  *	+-------+-------+-------+-------+-------+-------+-------+-------+
145  * a	|			birth txg				|
146  *	+-------+-------+-------+-------+-------+-------+-------+-------+
147  * b	|			fill count				|
148  *	+-------+-------+-------+-------+-------+-------+-------+-------+
149  * c	|			checksum[0]				|
150  *	+-------+-------+-------+-------+-------+-------+-------+-------+
151  * d	|			checksum[1]				|
152  *	+-------+-------+-------+-------+-------+-------+-------+-------+
153  * e	|			checksum[2]				|
154  *	+-------+-------+-------+-------+-------+-------+-------+-------+
155  * f	|			checksum[3]				|
156  *	+-------+-------+-------+-------+-------+-------+-------+-------+
157  *
158  * Legend:
159  *
160  * vdev		virtual device ID
161  * offset	offset into virtual device
162  * LSIZE	logical size
163  * PSIZE	physical size (after compression)
164  * ASIZE	allocated size (including RAID-Z parity and gang block headers)
165  * GRID		RAID-Z layout information (reserved for future use)
166  * cksum	checksum function
167  * comp		compression function
168  * G		gang block indicator
169  * E		endianness
170  * type		DMU object type
171  * lvl		level of indirection
172  * birth txg	transaction group in which the block was born
173  * fill count	number of non-zero blocks under this bp
174  * checksum[4]	256-bit checksum of the data this bp describes
175  */
176 typedef struct blkptr {
177 	dva_t		blk_dva[3];	/* 128-bit Data Virtual Address	*/
178 	uint64_t	blk_prop;	/* size, compression, type, etc	*/
179 	uint64_t	blk_pad[3];	/* Extra space for the future	*/
180 	uint64_t	blk_birth;	/* transaction group at birth	*/
181 	uint64_t	blk_fill;	/* fill count			*/
182 	zio_cksum_t	blk_cksum;	/* 256-bit checksum		*/
183 } blkptr_t;
184 
185 #define	SPA_BLKPTRSHIFT	7		/* blkptr_t is 128 bytes	*/
186 #define	SPA_DVAS_PER_BP	3		/* Number of DVAs in a bp	*/
187 
188 /*
189  * Macros to get and set fields in a bp or DVA.
190  */
191 #define	DVA_GET_ASIZE(dva)	\
192 	BF64_GET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0)
193 #define	DVA_SET_ASIZE(dva, x)	\
194 	BF64_SET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0, x)
195 
196 #define	DVA_GET_GRID(dva)	BF64_GET((dva)->dva_word[0], 24, 8)
197 #define	DVA_SET_GRID(dva, x)	BF64_SET((dva)->dva_word[0], 24, 8, x)
198 
199 #define	DVA_GET_VDEV(dva)	BF64_GET((dva)->dva_word[0], 32, 32)
200 #define	DVA_SET_VDEV(dva, x)	BF64_SET((dva)->dva_word[0], 32, 32, x)
201 
202 #define	DVA_GET_OFFSET(dva)	\
203 	BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0)
204 #define	DVA_SET_OFFSET(dva, x)	\
205 	BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x)
206 
207 #define	DVA_GET_GANG(dva)	BF64_GET((dva)->dva_word[1], 63, 1)
208 #define	DVA_SET_GANG(dva, x)	BF64_SET((dva)->dva_word[1], 63, 1, x)
209 
210 #define	BP_GET_LSIZE(bp)	\
211 	(BP_IS_HOLE(bp) ? 0 : \
212 	BF64_GET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1))
213 #define	BP_SET_LSIZE(bp, x)	\
214 	BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
215 
216 #define	BP_GET_PSIZE(bp)	\
217 	BF64_GET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1)
218 #define	BP_SET_PSIZE(bp, x)	\
219 	BF64_SET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1, x)
220 
221 #define	BP_GET_COMPRESS(bp)	BF64_GET((bp)->blk_prop, 32, 8)
222 #define	BP_SET_COMPRESS(bp, x)	BF64_SET((bp)->blk_prop, 32, 8, x)
223 
224 #define	BP_GET_CHECKSUM(bp)	BF64_GET((bp)->blk_prop, 40, 8)
225 #define	BP_SET_CHECKSUM(bp, x)	BF64_SET((bp)->blk_prop, 40, 8, x)
226 
227 #define	BP_GET_TYPE(bp)		BF64_GET((bp)->blk_prop, 48, 8)
228 #define	BP_SET_TYPE(bp, x)	BF64_SET((bp)->blk_prop, 48, 8, x)
229 
230 #define	BP_GET_LEVEL(bp)	BF64_GET((bp)->blk_prop, 56, 5)
231 #define	BP_SET_LEVEL(bp, x)	BF64_SET((bp)->blk_prop, 56, 5, x)
232 
233 #define	BP_GET_BYTEORDER(bp)	(0 - BF64_GET((bp)->blk_prop, 63, 1))
234 #define	BP_SET_BYTEORDER(bp, x)	BF64_SET((bp)->blk_prop, 63, 1, x)
235 
236 #define	BP_GET_ASIZE(bp)	\
237 	(DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
238 		DVA_GET_ASIZE(&(bp)->blk_dva[2]))
239 
240 #define	BP_GET_UCSIZE(bp) \
241 	((BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) ? \
242 	BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp));
243 
244 #define	BP_GET_NDVAS(bp)	\
245 	(!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
246 	!!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
247 	!!DVA_GET_ASIZE(&(bp)->blk_dva[2]))
248 
249 #define	BP_COUNT_GANG(bp)	\
250 	(DVA_GET_GANG(&(bp)->blk_dva[0]) + \
251 	DVA_GET_GANG(&(bp)->blk_dva[1]) + \
252 	DVA_GET_GANG(&(bp)->blk_dva[2]))
253 
254 #define	DVA_EQUAL(dva1, dva2)	\
255 	((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
256 	(dva1)->dva_word[0] == (dva2)->dva_word[0])
257 
258 #define	ZIO_CHECKSUM_EQUAL(zc1, zc2) \
259 	(0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
260 	((zc1).zc_word[1] - (zc2).zc_word[1]) | \
261 	((zc1).zc_word[2] - (zc2).zc_word[2]) | \
262 	((zc1).zc_word[3] - (zc2).zc_word[3])))
263 
264 #define	DVA_IS_VALID(dva)	(DVA_GET_ASIZE(dva) != 0)
265 
266 #define	ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3)	\
267 {						\
268 	(zcp)->zc_word[0] = w0;			\
269 	(zcp)->zc_word[1] = w1;			\
270 	(zcp)->zc_word[2] = w2;			\
271 	(zcp)->zc_word[3] = w3;			\
272 }
273 
274 #define	BP_IDENTITY(bp)		(&(bp)->blk_dva[0])
275 #define	BP_IS_GANG(bp)		DVA_GET_GANG(BP_IDENTITY(bp))
276 #define	BP_IS_HOLE(bp)		((bp)->blk_birth == 0)
277 #define	BP_IS_OLDER(bp, txg)	(!BP_IS_HOLE(bp) && (bp)->blk_birth < (txg))
278 
279 #define	BP_ZERO(bp)				\
280 {						\
281 	(bp)->blk_dva[0].dva_word[0] = 0;	\
282 	(bp)->blk_dva[0].dva_word[1] = 0;	\
283 	(bp)->blk_dva[1].dva_word[0] = 0;	\
284 	(bp)->blk_dva[1].dva_word[1] = 0;	\
285 	(bp)->blk_dva[2].dva_word[0] = 0;	\
286 	(bp)->blk_dva[2].dva_word[1] = 0;	\
287 	(bp)->blk_prop = 0;			\
288 	(bp)->blk_pad[0] = 0;			\
289 	(bp)->blk_pad[1] = 0;			\
290 	(bp)->blk_pad[2] = 0;			\
291 	(bp)->blk_birth = 0;			\
292 	(bp)->blk_fill = 0;			\
293 	ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0);	\
294 }
295 
296 #define	BLK_FILL_ALREADY_FREED	(-1ULL)
297 
298 /*
299  * Note: the byteorder is either 0 or -1, both of which are palindromes.
300  * This simplifies the endianness handling a bit.
301  */
302 #ifdef _BIG_ENDIAN
303 #define	ZFS_HOST_BYTEORDER	(0ULL)
304 #else
305 #define	ZFS_HOST_BYTEORDER	(-1ULL)
306 #endif
307 
308 #define	BP_SHOULD_BYTESWAP(bp)	(BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER)
309 
310 #define	BP_SPRINTF_LEN	320
311 
312 #include <sys/dmu.h>
313 
314 #define	BP_GET_BUFC_TYPE(bp)						\
315 	(((BP_GET_LEVEL(bp) > 0) || (dmu_ot[BP_GET_TYPE(bp)].ot_metadata)) ? \
316 	ARC_BUFC_METADATA : ARC_BUFC_DATA);
317 /*
318  * Routines found in spa.c
319  */
320 
321 /* state manipulation functions */
322 extern int spa_open(const char *pool, spa_t **, void *tag);
323 extern int spa_get_stats(const char *pool, nvlist_t **config,
324     char *altroot, size_t buflen);
325 extern int spa_create(const char *pool, nvlist_t *config, nvlist_t *props,
326     const char *history_str, nvlist_t *zplprops);
327 extern int spa_check_rootconf(char *devpath, char *devid,
328     nvlist_t **bestconf, uint64_t *besttxg);
329 extern boolean_t spa_rootdev_validate(nvlist_t *nv);
330 extern int spa_import_rootpool(char *devpath, char *devid);
331 extern int spa_import(const char *pool, nvlist_t *config, nvlist_t *props);
332 extern int spa_import_faulted(const char *, nvlist_t *, nvlist_t *);
333 extern nvlist_t *spa_tryimport(nvlist_t *tryconfig);
334 extern int spa_destroy(char *pool);
335 extern int spa_export(char *pool, nvlist_t **oldconfig, boolean_t force);
336 extern int spa_reset(char *pool);
337 extern void spa_async_request(spa_t *spa, int flag);
338 extern void spa_async_unrequest(spa_t *spa, int flag);
339 extern void spa_async_suspend(spa_t *spa);
340 extern void spa_async_resume(spa_t *spa);
341 extern spa_t *spa_inject_addref(char *pool);
342 extern void spa_inject_delref(spa_t *spa);
343 
344 #define	SPA_ASYNC_CONFIG_UPDATE	0x01
345 #define	SPA_ASYNC_REMOVE	0x02
346 #define	SPA_ASYNC_PROBE		0x04
347 #define	SPA_ASYNC_RESILVER_DONE	0x08
348 #define	SPA_ASYNC_RESILVER	0x10
349 
350 /* device manipulation */
351 extern int spa_vdev_add(spa_t *spa, nvlist_t *nvroot);
352 extern int spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot,
353     int replacing);
354 extern int spa_vdev_detach(spa_t *spa, uint64_t guid, int replace_done);
355 extern int spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare);
356 extern int spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath);
357 
358 /* spare state (which is global across all pools) */
359 extern void spa_spare_add(vdev_t *vd);
360 extern void spa_spare_remove(vdev_t *vd);
361 extern boolean_t spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt);
362 extern void spa_spare_activate(vdev_t *vd);
363 
364 /* L2ARC state (which is global across all pools) */
365 extern void spa_l2cache_add(vdev_t *vd);
366 extern void spa_l2cache_remove(vdev_t *vd);
367 extern boolean_t spa_l2cache_exists(uint64_t guid, uint64_t *pool);
368 extern void spa_l2cache_activate(vdev_t *vd);
369 extern void spa_l2cache_drop(spa_t *spa);
370 extern void spa_l2cache_space_update(vdev_t *vd, int64_t space, int64_t alloc);
371 
372 /* scrubbing */
373 extern int spa_scrub(spa_t *spa, pool_scrub_type_t type);
374 
375 /* spa syncing */
376 extern void spa_sync(spa_t *spa, uint64_t txg); /* only for DMU use */
377 extern void spa_sync_allpools(void);
378 
379 /* spa namespace global mutex */
380 extern kmutex_t spa_namespace_lock;
381 
382 /*
383  * SPA configuration functions in spa_config.c
384  */
385 
386 #define	SPA_CONFIG_UPDATE_POOL	0
387 #define	SPA_CONFIG_UPDATE_VDEVS	1
388 
389 extern void spa_config_sync(spa_t *, boolean_t, boolean_t);
390 extern void spa_config_load(void);
391 extern nvlist_t *spa_all_configs(uint64_t *);
392 extern void spa_config_set(spa_t *spa, nvlist_t *config);
393 extern nvlist_t *spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg,
394     int getstats);
395 extern void spa_config_update(spa_t *spa, int what);
396 extern void spa_config_update_common(spa_t *spa, int what, boolean_t isroot);
397 
398 /*
399  * Miscellaneous SPA routines in spa_misc.c
400  */
401 
402 /* Namespace manipulation */
403 extern spa_t *spa_lookup(const char *name);
404 extern spa_t *spa_add(const char *name, const char *altroot);
405 extern void spa_remove(spa_t *spa);
406 extern spa_t *spa_next(spa_t *prev);
407 
408 /* Refcount functions */
409 extern void spa_open_ref(spa_t *spa, void *tag);
410 extern void spa_close(spa_t *spa, void *tag);
411 extern boolean_t spa_refcount_zero(spa_t *spa);
412 
413 #define	SCL_CONFIG	0x01
414 #define	SCL_STATE	0x02
415 #define	SCL_L2ARC	0x04		/* hack until L2ARC 2.0 */
416 #define	SCL_ALLOC	0x08
417 #define	SCL_ZIO		0x10
418 #define	SCL_FREE	0x20
419 #define	SCL_VDEV	0x40
420 #define	SCL_LOCKS	7
421 #define	SCL_ALL		((1 << SCL_LOCKS) - 1)
422 #define	SCL_STATE_ALL	(SCL_STATE | SCL_L2ARC | SCL_ZIO)
423 
424 /* Pool configuration locks */
425 extern int spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw);
426 extern void spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw);
427 extern void spa_config_exit(spa_t *spa, int locks, void *tag);
428 extern int spa_config_held(spa_t *spa, int locks, krw_t rw);
429 
430 /* Pool vdev add/remove lock */
431 extern uint64_t spa_vdev_enter(spa_t *spa);
432 extern int spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error);
433 
434 /* Pool vdev state change lock */
435 extern void spa_vdev_state_enter(spa_t *spa);
436 extern int spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error);
437 
438 /* Accessor functions */
439 extern boolean_t spa_shutting_down(spa_t *spa);
440 extern struct dsl_pool *spa_get_dsl(spa_t *spa);
441 extern blkptr_t *spa_get_rootblkptr(spa_t *spa);
442 extern void spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp);
443 extern void spa_altroot(spa_t *, char *, size_t);
444 extern int spa_sync_pass(spa_t *spa);
445 extern char *spa_name(spa_t *spa);
446 extern uint64_t spa_guid(spa_t *spa);
447 extern uint64_t spa_last_synced_txg(spa_t *spa);
448 extern uint64_t spa_first_txg(spa_t *spa);
449 extern uint64_t spa_version(spa_t *spa);
450 extern pool_state_t spa_state(spa_t *spa);
451 extern uint64_t spa_freeze_txg(spa_t *spa);
452 extern uint64_t spa_get_alloc(spa_t *spa);
453 extern uint64_t spa_get_space(spa_t *spa);
454 extern uint64_t spa_get_dspace(spa_t *spa);
455 extern uint64_t spa_get_asize(spa_t *spa, uint64_t lsize);
456 extern uint64_t spa_version(spa_t *spa);
457 extern int spa_max_replication(spa_t *spa);
458 extern int spa_busy(void);
459 extern uint8_t spa_get_failmode(spa_t *spa);
460 extern boolean_t spa_suspended(spa_t *spa);
461 
462 /* Miscellaneous support routines */
463 extern int spa_rename(const char *oldname, const char *newname);
464 extern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid);
465 extern char *spa_strdup(const char *);
466 extern void spa_strfree(char *);
467 extern uint64_t spa_get_random(uint64_t range);
468 extern void sprintf_blkptr(char *buf, int len, const blkptr_t *bp);
469 extern void spa_freeze(spa_t *spa);
470 extern void spa_upgrade(spa_t *spa, uint64_t version);
471 extern void spa_evict_all(void);
472 extern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid,
473     boolean_t l2cache);
474 extern boolean_t spa_has_spare(spa_t *, uint64_t guid);
475 extern uint64_t bp_get_dasize(spa_t *spa, const blkptr_t *bp);
476 extern boolean_t spa_has_slogs(spa_t *spa);
477 extern boolean_t spa_is_root(spa_t *spa);
478 
479 /* history logging */
480 typedef enum history_log_type {
481 	LOG_CMD_POOL_CREATE,
482 	LOG_CMD_NORMAL,
483 	LOG_INTERNAL
484 } history_log_type_t;
485 
486 typedef struct history_arg {
487 	const char *ha_history_str;
488 	history_log_type_t ha_log_type;
489 	history_internal_events_t ha_event;
490 	char ha_zone[MAXPATHLEN];
491 } history_arg_t;
492 
493 extern char *spa_his_ievent_table[];
494 
495 extern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx);
496 extern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read,
497     char *his_buf);
498 extern int spa_history_log(spa_t *spa, const char *his_buf,
499     history_log_type_t what);
500 void spa_history_internal_log(history_internal_events_t event, spa_t *spa,
501     dmu_tx_t *tx, cred_t *cr, const char *fmt, ...);
502 
503 /* error handling */
504 struct zbookmark;
505 struct zio;
506 extern void spa_log_error(spa_t *spa, struct zio *zio);
507 extern void zfs_ereport_post(const char *class, spa_t *spa, vdev_t *vd,
508     struct zio *zio, uint64_t stateoroffset, uint64_t length);
509 extern void zfs_post_remove(spa_t *spa, vdev_t *vd);
510 extern void zfs_post_autoreplace(spa_t *spa, vdev_t *vd);
511 extern uint64_t spa_get_errlog_size(spa_t *spa);
512 extern int spa_get_errlog(spa_t *spa, void *uaddr, size_t *count);
513 extern void spa_errlog_rotate(spa_t *spa);
514 extern void spa_errlog_drain(spa_t *spa);
515 extern void spa_errlog_sync(spa_t *spa, uint64_t txg);
516 extern void spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub);
517 
518 /* vdev cache */
519 extern void vdev_cache_stat_init(void);
520 extern void vdev_cache_stat_fini(void);
521 
522 /* Initialization and termination */
523 extern void spa_init(int flags);
524 extern void spa_fini(void);
525 extern void spa_boot_init();
526 
527 /* properties */
528 extern int spa_prop_set(spa_t *spa, nvlist_t *nvp);
529 extern int spa_prop_get(spa_t *spa, nvlist_t **nvp);
530 extern void spa_prop_clear_bootfs(spa_t *spa, uint64_t obj, dmu_tx_t *tx);
531 
532 /* asynchronous event notification */
533 extern void spa_event_notify(spa_t *spa, vdev_t *vdev, const char *name);
534 
535 #ifdef ZFS_DEBUG
536 #define	dprintf_bp(bp, fmt, ...) do {				\
537 	if (zfs_flags & ZFS_DEBUG_DPRINTF) { 			\
538 	char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP);	\
539 	sprintf_blkptr(__blkbuf, BP_SPRINTF_LEN, (bp));		\
540 	dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf);		\
541 	kmem_free(__blkbuf, BP_SPRINTF_LEN);			\
542 	} \
543 _NOTE(CONSTCOND) } while (0)
544 #else
545 #define	dprintf_bp(bp, fmt, ...)
546 #endif
547 
548 extern int spa_mode;			/* mode, e.g. FREAD | FWRITE */
549 
550 #ifdef	__cplusplus
551 }
552 #endif
553 
554 #endif	/* _SYS_SPA_H */
555