spa.h revision 094e47e980b0796b94b1b8f51f462a64d246e516
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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
25 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
26 * Copyright 2013 Saso Kiselkov. All rights reserved.
27 * Copyright (c) 2014 Integros [integros.com]
28 * Copyright 2017 Joyent, Inc.
29 * Copyright (c) 2017 Datto Inc.
30 */
31
32#ifndef _SYS_SPA_H
33#define	_SYS_SPA_H
34
35#include <sys/avl.h>
36#include <sys/zfs_context.h>
37#include <sys/nvpair.h>
38#include <sys/sysevent.h>
39#include <sys/sysmacros.h>
40#include <sys/types.h>
41#include <sys/fs/zfs.h>
42#include <sys/dmu.h>
43
44#ifdef	__cplusplus
45extern "C" {
46#endif
47
48/*
49 * Forward references that lots of things need.
50 */
51typedef struct spa spa_t;
52typedef struct vdev vdev_t;
53typedef struct metaslab metaslab_t;
54typedef struct metaslab_group metaslab_group_t;
55typedef struct metaslab_class metaslab_class_t;
56typedef struct zio zio_t;
57typedef struct zilog zilog_t;
58typedef struct spa_aux_vdev spa_aux_vdev_t;
59typedef struct ddt ddt_t;
60typedef struct ddt_entry ddt_entry_t;
61struct dsl_pool;
62struct dsl_dataset;
63
64/*
65 * General-purpose 32-bit and 64-bit bitfield encodings.
66 */
67#define	BF32_DECODE(x, low, len)	P2PHASE((x) >> (low), 1U << (len))
68#define	BF64_DECODE(x, low, len)	P2PHASE((x) >> (low), 1ULL << (len))
69#define	BF32_ENCODE(x, low, len)	(P2PHASE((x), 1U << (len)) << (low))
70#define	BF64_ENCODE(x, low, len)	(P2PHASE((x), 1ULL << (len)) << (low))
71
72#define	BF32_GET(x, low, len)		BF32_DECODE(x, low, len)
73#define	BF64_GET(x, low, len)		BF64_DECODE(x, low, len)
74
75#define	BF32_SET(x, low, len, val) do { \
76	ASSERT3U(val, <, 1U << (len)); \
77	ASSERT3U(low + len, <=, 32); \
78	(x) ^= BF32_ENCODE((x >> low) ^ (val), low, len); \
79_NOTE(CONSTCOND) } while (0)
80
81#define	BF64_SET(x, low, len, val) do { \
82	ASSERT3U(val, <, 1ULL << (len)); \
83	ASSERT3U(low + len, <=, 64); \
84	((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len)); \
85_NOTE(CONSTCOND) } while (0)
86
87#define	BF32_GET_SB(x, low, len, shift, bias)	\
88	((BF32_GET(x, low, len) + (bias)) << (shift))
89#define	BF64_GET_SB(x, low, len, shift, bias)	\
90	((BF64_GET(x, low, len) + (bias)) << (shift))
91
92#define	BF32_SET_SB(x, low, len, shift, bias, val) do { \
93	ASSERT(IS_P2ALIGNED(val, 1U << shift)); \
94	ASSERT3S((val) >> (shift), >=, bias); \
95	BF32_SET(x, low, len, ((val) >> (shift)) - (bias)); \
96_NOTE(CONSTCOND) } while (0)
97#define	BF64_SET_SB(x, low, len, shift, bias, val) do { \
98	ASSERT(IS_P2ALIGNED(val, 1ULL << shift)); \
99	ASSERT3S((val) >> (shift), >=, bias); \
100	BF64_SET(x, low, len, ((val) >> (shift)) - (bias)); \
101_NOTE(CONSTCOND) } while (0)
102
103/*
104 * We currently support block sizes from 512 bytes to 16MB.
105 * The benefits of larger blocks, and thus larger IO, need to be weighed
106 * against the cost of COWing a giant block to modify one byte, and the
107 * large latency of reading or writing a large block.
108 *
109 * Note that although blocks up to 16MB are supported, the recordsize
110 * property can not be set larger than zfs_max_recordsize (default 1MB).
111 * See the comment near zfs_max_recordsize in dsl_dataset.c for details.
112 *
113 * Note that although the LSIZE field of the blkptr_t can store sizes up
114 * to 32MB, the dnode's dn_datablkszsec can only store sizes up to
115 * 32MB - 512 bytes.  Therefore, we limit SPA_MAXBLOCKSIZE to 16MB.
116 */
117#define	SPA_MINBLOCKSHIFT	9
118#define	SPA_OLD_MAXBLOCKSHIFT	17
119#define	SPA_MAXBLOCKSHIFT	24
120#define	SPA_MINBLOCKSIZE	(1ULL << SPA_MINBLOCKSHIFT)
121#define	SPA_OLD_MAXBLOCKSIZE	(1ULL << SPA_OLD_MAXBLOCKSHIFT)
122#define	SPA_MAXBLOCKSIZE	(1ULL << SPA_MAXBLOCKSHIFT)
123
124/*
125 * Size of block to hold the configuration data (a packed nvlist)
126 */
127#define	SPA_CONFIG_BLOCKSIZE	(1ULL << 14)
128
129/*
130 * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
131 * The ASIZE encoding should be at least 64 times larger (6 more bits)
132 * to support up to 4-way RAID-Z mirror mode with worst-case gang block
133 * overhead, three DVAs per bp, plus one more bit in case we do anything
134 * else that expands the ASIZE.
135 */
136#define	SPA_LSIZEBITS		16	/* LSIZE up to 32M (2^16 * 512)	*/
137#define	SPA_PSIZEBITS		16	/* PSIZE up to 32M (2^16 * 512)	*/
138#define	SPA_ASIZEBITS		24	/* ASIZE up to 64 times larger	*/
139
140#define	SPA_COMPRESSBITS	7
141#define	SPA_VDEVBITS		24
142
143/*
144 * All SPA data is represented by 128-bit data virtual addresses (DVAs).
145 * The members of the dva_t should be considered opaque outside the SPA.
146 */
147typedef struct dva {
148	uint64_t	dva_word[2];
149} dva_t;
150
151/*
152 * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
153 */
154typedef struct zio_cksum {
155	uint64_t	zc_word[4];
156} zio_cksum_t;
157
158/*
159 * Some checksums/hashes need a 256-bit initialization salt. This salt is kept
160 * secret and is suitable for use in MAC algorithms as the key.
161 */
162typedef struct zio_cksum_salt {
163	uint8_t		zcs_bytes[32];
164} zio_cksum_salt_t;
165
166/*
167 * Each block is described by its DVAs, time of birth, checksum, etc.
168 * The word-by-word, bit-by-bit layout of the blkptr is as follows:
169 *
170 *	64	56	48	40	32	24	16	8	0
171 *	+-------+-------+-------+-------+-------+-------+-------+-------+
172 * 0	|  pad  |	  vdev1         | GRID  |	  ASIZE		|
173 *	+-------+-------+-------+-------+-------+-------+-------+-------+
174 * 1	|G|			 offset1				|
175 *	+-------+-------+-------+-------+-------+-------+-------+-------+
176 * 2	|  pad  |	  vdev2         | GRID  |	  ASIZE		|
177 *	+-------+-------+-------+-------+-------+-------+-------+-------+
178 * 3	|G|			 offset2				|
179 *	+-------+-------+-------+-------+-------+-------+-------+-------+
180 * 4	|  pad  |	  vdev3         | GRID  |	  ASIZE		|
181 *	+-------+-------+-------+-------+-------+-------+-------+-------+
182 * 5	|G|			 offset3				|
183 *	+-------+-------+-------+-------+-------+-------+-------+-------+
184 * 6	|BDX|lvl| type	| cksum |E| comp|    PSIZE	|     LSIZE	|
185 *	+-------+-------+-------+-------+-------+-------+-------+-------+
186 * 7	|			padding					|
187 *	+-------+-------+-------+-------+-------+-------+-------+-------+
188 * 8	|			padding					|
189 *	+-------+-------+-------+-------+-------+-------+-------+-------+
190 * 9	|			physical birth txg			|
191 *	+-------+-------+-------+-------+-------+-------+-------+-------+
192 * a	|			logical birth txg			|
193 *	+-------+-------+-------+-------+-------+-------+-------+-------+
194 * b	|			fill count				|
195 *	+-------+-------+-------+-------+-------+-------+-------+-------+
196 * c	|			checksum[0]				|
197 *	+-------+-------+-------+-------+-------+-------+-------+-------+
198 * d	|			checksum[1]				|
199 *	+-------+-------+-------+-------+-------+-------+-------+-------+
200 * e	|			checksum[2]				|
201 *	+-------+-------+-------+-------+-------+-------+-------+-------+
202 * f	|			checksum[3]				|
203 *	+-------+-------+-------+-------+-------+-------+-------+-------+
204 *
205 * Legend:
206 *
207 * vdev		virtual device ID
208 * offset	offset into virtual device
209 * LSIZE	logical size
210 * PSIZE	physical size (after compression)
211 * ASIZE	allocated size (including RAID-Z parity and gang block headers)
212 * GRID		RAID-Z layout information (reserved for future use)
213 * cksum	checksum function
214 * comp		compression function
215 * G		gang block indicator
216 * B		byteorder (endianness)
217 * D		dedup
218 * X		encryption (on version 30, which is not supported)
219 * E		blkptr_t contains embedded data (see below)
220 * lvl		level of indirection
221 * type		DMU object type
222 * phys birth	txg when dva[0] was written; zero if same as logical birth txg
223 *              note that typically all the dva's would be written in this
224 *              txg, but they could be different if they were moved by
225 *              device removal.
226 * log. birth	transaction group in which the block was logically born
227 * fill count	number of non-zero blocks under this bp
228 * checksum[4]	256-bit checksum of the data this bp describes
229 */
230
231/*
232 * "Embedded" blkptr_t's don't actually point to a block, instead they
233 * have a data payload embedded in the blkptr_t itself.  See the comment
234 * in blkptr.c for more details.
235 *
236 * The blkptr_t is laid out as follows:
237 *
238 *	64	56	48	40	32	24	16	8	0
239 *	+-------+-------+-------+-------+-------+-------+-------+-------+
240 * 0	|      payload                                                  |
241 * 1	|      payload                                                  |
242 * 2	|      payload                                                  |
243 * 3	|      payload                                                  |
244 * 4	|      payload                                                  |
245 * 5	|      payload                                                  |
246 *	+-------+-------+-------+-------+-------+-------+-------+-------+
247 * 6	|BDX|lvl| type	| etype |E| comp| PSIZE|              LSIZE	|
248 *	+-------+-------+-------+-------+-------+-------+-------+-------+
249 * 7	|      payload                                                  |
250 * 8	|      payload                                                  |
251 * 9	|      payload                                                  |
252 *	+-------+-------+-------+-------+-------+-------+-------+-------+
253 * a	|			logical birth txg			|
254 *	+-------+-------+-------+-------+-------+-------+-------+-------+
255 * b	|      payload                                                  |
256 * c	|      payload                                                  |
257 * d	|      payload                                                  |
258 * e	|      payload                                                  |
259 * f	|      payload                                                  |
260 *	+-------+-------+-------+-------+-------+-------+-------+-------+
261 *
262 * Legend:
263 *
264 * payload		contains the embedded data
265 * B (byteorder)	byteorder (endianness)
266 * D (dedup)		padding (set to zero)
267 * X			encryption (set to zero; see above)
268 * E (embedded)		set to one
269 * lvl			indirection level
270 * type			DMU object type
271 * etype		how to interpret embedded data (BP_EMBEDDED_TYPE_*)
272 * comp			compression function of payload
273 * PSIZE		size of payload after compression, in bytes
274 * LSIZE		logical size of payload, in bytes
275 *			note that 25 bits is enough to store the largest
276 *			"normal" BP's LSIZE (2^16 * 2^9) in bytes
277 * log. birth		transaction group in which the block was logically born
278 *
279 * Note that LSIZE and PSIZE are stored in bytes, whereas for non-embedded
280 * bp's they are stored in units of SPA_MINBLOCKSHIFT.
281 * Generally, the generic BP_GET_*() macros can be used on embedded BP's.
282 * The B, D, X, lvl, type, and comp fields are stored the same as with normal
283 * BP's so the BP_SET_* macros can be used with them.  etype, PSIZE, LSIZE must
284 * be set with the BPE_SET_* macros.  BP_SET_EMBEDDED() should be called before
285 * other macros, as they assert that they are only used on BP's of the correct
286 * "embedded-ness".
287 */
288
289#define	BPE_GET_ETYPE(bp)	\
290	(ASSERT(BP_IS_EMBEDDED(bp)), \
291	BF64_GET((bp)->blk_prop, 40, 8))
292#define	BPE_SET_ETYPE(bp, t)	do { \
293	ASSERT(BP_IS_EMBEDDED(bp)); \
294	BF64_SET((bp)->blk_prop, 40, 8, t); \
295_NOTE(CONSTCOND) } while (0)
296
297#define	BPE_GET_LSIZE(bp)	\
298	(ASSERT(BP_IS_EMBEDDED(bp)), \
299	BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1))
300#define	BPE_SET_LSIZE(bp, x)	do { \
301	ASSERT(BP_IS_EMBEDDED(bp)); \
302	BF64_SET_SB((bp)->blk_prop, 0, 25, 0, 1, x); \
303_NOTE(CONSTCOND) } while (0)
304
305#define	BPE_GET_PSIZE(bp)	\
306	(ASSERT(BP_IS_EMBEDDED(bp)), \
307	BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1))
308#define	BPE_SET_PSIZE(bp, x)	do { \
309	ASSERT(BP_IS_EMBEDDED(bp)); \
310	BF64_SET_SB((bp)->blk_prop, 25, 7, 0, 1, x); \
311_NOTE(CONSTCOND) } while (0)
312
313typedef enum bp_embedded_type {
314	BP_EMBEDDED_TYPE_DATA,
315	BP_EMBEDDED_TYPE_RESERVED, /* Reserved for an unintegrated feature. */
316	NUM_BP_EMBEDDED_TYPES = BP_EMBEDDED_TYPE_RESERVED
317} bp_embedded_type_t;
318
319#define	BPE_NUM_WORDS 14
320#define	BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t))
321#define	BPE_IS_PAYLOADWORD(bp, wp) \
322	((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth)
323
324#define	SPA_BLKPTRSHIFT	7		/* blkptr_t is 128 bytes	*/
325#define	SPA_DVAS_PER_BP	3		/* Number of DVAs in a bp	*/
326#define	SPA_SYNC_MIN_VDEVS 3		/* min vdevs to update during sync */
327
328/*
329 * A block is a hole when it has either 1) never been written to, or
330 * 2) is zero-filled. In both cases, ZFS can return all zeroes for all reads
331 * without physically allocating disk space. Holes are represented in the
332 * blkptr_t structure by zeroed blk_dva. Correct checking for holes is
333 * done through the BP_IS_HOLE macro. For holes, the logical size, level,
334 * DMU object type, and birth times are all also stored for holes that
335 * were written to at some point (i.e. were punched after having been filled).
336 */
337typedef struct blkptr {
338	dva_t		blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */
339	uint64_t	blk_prop;	/* size, compression, type, etc	    */
340	uint64_t	blk_pad[2];	/* Extra space for the future	    */
341	uint64_t	blk_phys_birth;	/* txg when block was allocated	    */
342	uint64_t	blk_birth;	/* transaction group at birth	    */
343	uint64_t	blk_fill;	/* fill count			    */
344	zio_cksum_t	blk_cksum;	/* 256-bit checksum		    */
345} blkptr_t;
346
347/*
348 * Macros to get and set fields in a bp or DVA.
349 */
350#define	DVA_GET_ASIZE(dva)	\
351	BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0)
352#define	DVA_SET_ASIZE(dva, x)	\
353	BF64_SET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, \
354	SPA_MINBLOCKSHIFT, 0, x)
355
356#define	DVA_GET_GRID(dva)	BF64_GET((dva)->dva_word[0], 24, 8)
357#define	DVA_SET_GRID(dva, x)	BF64_SET((dva)->dva_word[0], 24, 8, x)
358
359#define	DVA_GET_VDEV(dva)	BF64_GET((dva)->dva_word[0], 32, SPA_VDEVBITS)
360#define	DVA_SET_VDEV(dva, x)	\
361	BF64_SET((dva)->dva_word[0], 32, SPA_VDEVBITS, x)
362
363#define	DVA_GET_OFFSET(dva)	\
364	BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0)
365#define	DVA_SET_OFFSET(dva, x)	\
366	BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x)
367
368#define	DVA_GET_GANG(dva)	BF64_GET((dva)->dva_word[1], 63, 1)
369#define	DVA_SET_GANG(dva, x)	BF64_SET((dva)->dva_word[1], 63, 1, x)
370
371#define	BP_GET_LSIZE(bp)	\
372	(BP_IS_EMBEDDED(bp) ?	\
373	(BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA ? BPE_GET_LSIZE(bp) : 0): \
374	BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1))
375#define	BP_SET_LSIZE(bp, x)	do { \
376	ASSERT(!BP_IS_EMBEDDED(bp)); \
377	BF64_SET_SB((bp)->blk_prop, \
378	    0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \
379_NOTE(CONSTCOND) } while (0)
380
381#define	BP_GET_PSIZE(bp)	\
382	(BP_IS_EMBEDDED(bp) ? 0 : \
383	BF64_GET_SB((bp)->blk_prop, 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1))
384#define	BP_SET_PSIZE(bp, x)	do { \
385	ASSERT(!BP_IS_EMBEDDED(bp)); \
386	BF64_SET_SB((bp)->blk_prop, \
387	    16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \
388_NOTE(CONSTCOND) } while (0)
389
390#define	BP_GET_COMPRESS(bp)		\
391	BF64_GET((bp)->blk_prop, 32, SPA_COMPRESSBITS)
392#define	BP_SET_COMPRESS(bp, x)		\
393	BF64_SET((bp)->blk_prop, 32, SPA_COMPRESSBITS, x)
394
395#define	BP_IS_EMBEDDED(bp)		BF64_GET((bp)->blk_prop, 39, 1)
396#define	BP_SET_EMBEDDED(bp, x)		BF64_SET((bp)->blk_prop, 39, 1, x)
397
398#define	BP_GET_CHECKSUM(bp)		\
399	(BP_IS_EMBEDDED(bp) ? ZIO_CHECKSUM_OFF : \
400	BF64_GET((bp)->blk_prop, 40, 8))
401#define	BP_SET_CHECKSUM(bp, x)		do { \
402	ASSERT(!BP_IS_EMBEDDED(bp)); \
403	BF64_SET((bp)->blk_prop, 40, 8, x); \
404_NOTE(CONSTCOND) } while (0)
405
406#define	BP_GET_TYPE(bp)			BF64_GET((bp)->blk_prop, 48, 8)
407#define	BP_SET_TYPE(bp, x)		BF64_SET((bp)->blk_prop, 48, 8, x)
408
409#define	BP_GET_LEVEL(bp)		BF64_GET((bp)->blk_prop, 56, 5)
410#define	BP_SET_LEVEL(bp, x)		BF64_SET((bp)->blk_prop, 56, 5, x)
411
412#define	BP_GET_DEDUP(bp)		BF64_GET((bp)->blk_prop, 62, 1)
413#define	BP_SET_DEDUP(bp, x)		BF64_SET((bp)->blk_prop, 62, 1, x)
414
415#define	BP_GET_BYTEORDER(bp)		BF64_GET((bp)->blk_prop, 63, 1)
416#define	BP_SET_BYTEORDER(bp, x)		BF64_SET((bp)->blk_prop, 63, 1, x)
417
418#define	BP_PHYSICAL_BIRTH(bp)		\
419	(BP_IS_EMBEDDED(bp) ? 0 : \
420	(bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)
421
422#define	BP_SET_BIRTH(bp, logical, physical)	\
423{						\
424	ASSERT(!BP_IS_EMBEDDED(bp));		\
425	(bp)->blk_birth = (logical);		\
426	(bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \
427}
428
429#define	BP_GET_FILL(bp) (BP_IS_EMBEDDED(bp) ? 1 : (bp)->blk_fill)
430
431#define	BP_IS_METADATA(bp)	\
432	(BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp)))
433
434#define	BP_GET_ASIZE(bp)	\
435	(BP_IS_EMBEDDED(bp) ? 0 : \
436	DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
437	DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
438	DVA_GET_ASIZE(&(bp)->blk_dva[2]))
439
440#define	BP_GET_UCSIZE(bp)	\
441	(BP_IS_METADATA(bp) ? BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp))
442
443#define	BP_GET_NDVAS(bp)	\
444	(BP_IS_EMBEDDED(bp) ? 0 : \
445	!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
446	!!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
447	!!DVA_GET_ASIZE(&(bp)->blk_dva[2]))
448
449#define	BP_COUNT_GANG(bp)	\
450	(BP_IS_EMBEDDED(bp) ? 0 : \
451	(DVA_GET_GANG(&(bp)->blk_dva[0]) + \
452	DVA_GET_GANG(&(bp)->blk_dva[1]) + \
453	DVA_GET_GANG(&(bp)->blk_dva[2])))
454
455#define	DVA_EQUAL(dva1, dva2)	\
456	((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
457	(dva1)->dva_word[0] == (dva2)->dva_word[0])
458
459#define	BP_EQUAL(bp1, bp2)	\
460	(BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) &&	\
461	(bp1)->blk_birth == (bp2)->blk_birth &&			\
462	DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) &&	\
463	DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) &&	\
464	DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2]))
465
466#define	ZIO_CHECKSUM_EQUAL(zc1, zc2) \
467	(0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
468	((zc1).zc_word[1] - (zc2).zc_word[1]) | \
469	((zc1).zc_word[2] - (zc2).zc_word[2]) | \
470	((zc1).zc_word[3] - (zc2).zc_word[3])))
471
472#define	ZIO_CHECKSUM_IS_ZERO(zc) \
473	(0 == ((zc)->zc_word[0] | (zc)->zc_word[1] | \
474	(zc)->zc_word[2] | (zc)->zc_word[3]))
475
476#define	ZIO_CHECKSUM_BSWAP(zcp)					\
477{								\
478	(zcp)->zc_word[0] = BSWAP_64((zcp)->zc_word[0]);	\
479	(zcp)->zc_word[1] = BSWAP_64((zcp)->zc_word[1]);	\
480	(zcp)->zc_word[2] = BSWAP_64((zcp)->zc_word[2]);	\
481	(zcp)->zc_word[3] = BSWAP_64((zcp)->zc_word[3]);	\
482}
483
484
485#define	DVA_IS_VALID(dva)	(DVA_GET_ASIZE(dva) != 0)
486
487#define	ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3)	\
488{						\
489	(zcp)->zc_word[0] = w0;			\
490	(zcp)->zc_word[1] = w1;			\
491	(zcp)->zc_word[2] = w2;			\
492	(zcp)->zc_word[3] = w3;			\
493}
494
495#define	BP_IDENTITY(bp)		(ASSERT(!BP_IS_EMBEDDED(bp)), &(bp)->blk_dva[0])
496#define	BP_IS_GANG(bp)		\
497	(BP_IS_EMBEDDED(bp) ? B_FALSE : DVA_GET_GANG(BP_IDENTITY(bp)))
498#define	DVA_IS_EMPTY(dva)	((dva)->dva_word[0] == 0ULL &&	\
499				(dva)->dva_word[1] == 0ULL)
500#define	BP_IS_HOLE(bp) \
501	(!BP_IS_EMBEDDED(bp) && DVA_IS_EMPTY(BP_IDENTITY(bp)))
502
503/* BP_IS_RAIDZ(bp) assumes no block compression */
504#define	BP_IS_RAIDZ(bp)		(DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \
505				BP_GET_PSIZE(bp))
506
507#define	BP_ZERO(bp)				\
508{						\
509	(bp)->blk_dva[0].dva_word[0] = 0;	\
510	(bp)->blk_dva[0].dva_word[1] = 0;	\
511	(bp)->blk_dva[1].dva_word[0] = 0;	\
512	(bp)->blk_dva[1].dva_word[1] = 0;	\
513	(bp)->blk_dva[2].dva_word[0] = 0;	\
514	(bp)->blk_dva[2].dva_word[1] = 0;	\
515	(bp)->blk_prop = 0;			\
516	(bp)->blk_pad[0] = 0;			\
517	(bp)->blk_pad[1] = 0;			\
518	(bp)->blk_phys_birth = 0;		\
519	(bp)->blk_birth = 0;			\
520	(bp)->blk_fill = 0;			\
521	ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0);	\
522}
523
524#ifdef _BIG_ENDIAN
525#define	ZFS_HOST_BYTEORDER	(0ULL)
526#else
527#define	ZFS_HOST_BYTEORDER	(1ULL)
528#endif
529
530#define	BP_SHOULD_BYTESWAP(bp)	(BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER)
531
532#define	BP_SPRINTF_LEN	320
533
534/*
535 * This macro allows code sharing between zfs, libzpool, and mdb.
536 * 'func' is either snprintf() or mdb_snprintf().
537 * 'ws' (whitespace) can be ' ' for single-line format, '\n' for multi-line.
538 */
539#define	SNPRINTF_BLKPTR(func, ws, buf, size, bp, type, checksum, compress) \
540{									\
541	static const char *copyname[] =					\
542	    { "zero", "single", "double", "triple" };			\
543	int len = 0;							\
544	int copies = 0;							\
545									\
546	if (bp == NULL) {						\
547		len += func(buf + len, size - len, "<NULL>");		\
548	} else if (BP_IS_HOLE(bp)) {					\
549		len += func(buf + len, size - len,			\
550		    "HOLE [L%llu %s] "					\
551		    "size=%llxL birth=%lluL",				\
552		    (u_longlong_t)BP_GET_LEVEL(bp),			\
553		    type,						\
554		    (u_longlong_t)BP_GET_LSIZE(bp),			\
555		    (u_longlong_t)bp->blk_birth);			\
556	} else if (BP_IS_EMBEDDED(bp)) {				\
557		len = func(buf + len, size - len,			\
558		    "EMBEDDED [L%llu %s] et=%u %s "			\
559		    "size=%llxL/%llxP birth=%lluL",			\
560		    (u_longlong_t)BP_GET_LEVEL(bp),			\
561		    type,						\
562		    (int)BPE_GET_ETYPE(bp),				\
563		    compress,						\
564		    (u_longlong_t)BPE_GET_LSIZE(bp),			\
565		    (u_longlong_t)BPE_GET_PSIZE(bp),			\
566		    (u_longlong_t)bp->blk_birth);			\
567	} else {							\
568		for (int d = 0; d < BP_GET_NDVAS(bp); d++) {		\
569			const dva_t *dva = &bp->blk_dva[d];		\
570			if (DVA_IS_VALID(dva))				\
571				copies++;				\
572			len += func(buf + len, size - len,		\
573			    "DVA[%d]=<%llu:%llx:%llx>%c", d,		\
574			    (u_longlong_t)DVA_GET_VDEV(dva),		\
575			    (u_longlong_t)DVA_GET_OFFSET(dva),		\
576			    (u_longlong_t)DVA_GET_ASIZE(dva),		\
577			    ws);					\
578		}							\
579		if (BP_IS_GANG(bp) &&					\
580		    DVA_GET_ASIZE(&bp->blk_dva[2]) <=			\
581		    DVA_GET_ASIZE(&bp->blk_dva[1]) / 2)			\
582			copies--;					\
583		len += func(buf + len, size - len,			\
584		    "[L%llu %s] %s %s %s %s %s %s%c"			\
585		    "size=%llxL/%llxP birth=%lluL/%lluP fill=%llu%c"	\
586		    "cksum=%llx:%llx:%llx:%llx",			\
587		    (u_longlong_t)BP_GET_LEVEL(bp),			\
588		    type,						\
589		    checksum,						\
590		    compress,						\
591		    BP_GET_BYTEORDER(bp) == 0 ? "BE" : "LE",		\
592		    BP_IS_GANG(bp) ? "gang" : "contiguous",		\
593		    BP_GET_DEDUP(bp) ? "dedup" : "unique",		\
594		    copyname[copies],					\
595		    ws,							\
596		    (u_longlong_t)BP_GET_LSIZE(bp),			\
597		    (u_longlong_t)BP_GET_PSIZE(bp),			\
598		    (u_longlong_t)bp->blk_birth,			\
599		    (u_longlong_t)BP_PHYSICAL_BIRTH(bp),		\
600		    (u_longlong_t)BP_GET_FILL(bp),			\
601		    ws,							\
602		    (u_longlong_t)bp->blk_cksum.zc_word[0],		\
603		    (u_longlong_t)bp->blk_cksum.zc_word[1],		\
604		    (u_longlong_t)bp->blk_cksum.zc_word[2],		\
605		    (u_longlong_t)bp->blk_cksum.zc_word[3]);		\
606	}								\
607	ASSERT(len < size);						\
608}
609
610#define	BP_GET_BUFC_TYPE(bp)						\
611	(BP_IS_METADATA(bp) ? ARC_BUFC_METADATA : ARC_BUFC_DATA)
612
613typedef enum spa_import_type {
614	SPA_IMPORT_EXISTING,
615	SPA_IMPORT_ASSEMBLE
616} spa_import_type_t;
617
618/* state manipulation functions */
619extern int spa_open(const char *pool, spa_t **, void *tag);
620extern int spa_open_rewind(const char *pool, spa_t **, void *tag,
621    nvlist_t *policy, nvlist_t **config);
622extern int spa_get_stats(const char *pool, nvlist_t **config, char *altroot,
623    size_t buflen);
624extern int spa_create(const char *pool, nvlist_t *config, nvlist_t *props,
625    nvlist_t *zplprops);
626extern int spa_import_rootpool(char *devpath, char *devid);
627extern int spa_import(const char *pool, nvlist_t *config, nvlist_t *props,
628    uint64_t flags);
629extern nvlist_t *spa_tryimport(nvlist_t *tryconfig);
630extern int spa_destroy(char *pool);
631extern int spa_checkpoint(const char *pool);
632extern int spa_checkpoint_discard(const char *pool);
633extern int spa_export(char *pool, nvlist_t **oldconfig, boolean_t force,
634    boolean_t hardforce);
635extern int spa_reset(char *pool);
636extern void spa_async_request(spa_t *spa, int flag);
637extern void spa_async_unrequest(spa_t *spa, int flag);
638extern void spa_async_suspend(spa_t *spa);
639extern void spa_async_resume(spa_t *spa);
640extern spa_t *spa_inject_addref(char *pool);
641extern void spa_inject_delref(spa_t *spa);
642extern void spa_scan_stat_init(spa_t *spa);
643extern int spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps);
644
645#define	SPA_ASYNC_CONFIG_UPDATE	0x01
646#define	SPA_ASYNC_REMOVE	0x02
647#define	SPA_ASYNC_PROBE		0x04
648#define	SPA_ASYNC_RESILVER_DONE	0x08
649#define	SPA_ASYNC_RESILVER	0x10
650#define	SPA_ASYNC_AUTOEXPAND	0x20
651#define	SPA_ASYNC_REMOVE_DONE	0x40
652#define	SPA_ASYNC_REMOVE_STOP	0x80
653#define	SPA_ASYNC_INITIALIZE_RESTART	0x100
654
655/*
656 * Controls the behavior of spa_vdev_remove().
657 */
658#define	SPA_REMOVE_UNSPARE	0x01
659#define	SPA_REMOVE_DONE		0x02
660
661/* device manipulation */
662extern int spa_vdev_add(spa_t *spa, nvlist_t *nvroot);
663extern int spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot,
664    int replacing);
665extern int spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid,
666    int replace_done);
667extern int spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare);
668extern boolean_t spa_vdev_remove_active(spa_t *spa);
669extern int spa_vdev_initialize(spa_t *spa, uint64_t guid, uint64_t cmd_type);
670extern int spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath);
671extern int spa_vdev_setfru(spa_t *spa, uint64_t guid, const char *newfru);
672extern int spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
673    nvlist_t *props, boolean_t exp);
674
675/* spare state (which is global across all pools) */
676extern void spa_spare_add(vdev_t *vd);
677extern void spa_spare_remove(vdev_t *vd);
678extern boolean_t spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt);
679extern void spa_spare_activate(vdev_t *vd);
680
681/* L2ARC state (which is global across all pools) */
682extern void spa_l2cache_add(vdev_t *vd);
683extern void spa_l2cache_remove(vdev_t *vd);
684extern boolean_t spa_l2cache_exists(uint64_t guid, uint64_t *pool);
685extern void spa_l2cache_activate(vdev_t *vd);
686extern void spa_l2cache_drop(spa_t *spa);
687
688/* scanning */
689extern int spa_scan(spa_t *spa, pool_scan_func_t func);
690extern int spa_scan_stop(spa_t *spa);
691extern int spa_scrub_pause_resume(spa_t *spa, pool_scrub_cmd_t flag);
692
693/* spa syncing */
694extern void spa_sync(spa_t *spa, uint64_t txg); /* only for DMU use */
695extern void spa_sync_allpools(void);
696
697/* spa namespace global mutex */
698extern kmutex_t spa_namespace_lock;
699
700/*
701 * SPA configuration functions in spa_config.c
702 */
703
704#define	SPA_CONFIG_UPDATE_POOL	0
705#define	SPA_CONFIG_UPDATE_VDEVS	1
706
707extern void spa_write_cachefile(spa_t *, boolean_t, boolean_t);
708extern void spa_config_load(void);
709extern nvlist_t *spa_all_configs(uint64_t *);
710extern void spa_config_set(spa_t *spa, nvlist_t *config);
711extern nvlist_t *spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg,
712    int getstats);
713extern void spa_config_update(spa_t *spa, int what);
714
715/*
716 * Miscellaneous SPA routines in spa_misc.c
717 */
718
719/* Namespace manipulation */
720extern spa_t *spa_lookup(const char *name);
721extern spa_t *spa_add(const char *name, nvlist_t *config, const char *altroot);
722extern void spa_remove(spa_t *spa);
723extern spa_t *spa_next(spa_t *prev);
724
725/* Refcount functions */
726extern void spa_open_ref(spa_t *spa, void *tag);
727extern void spa_close(spa_t *spa, void *tag);
728extern void spa_async_close(spa_t *spa, void *tag);
729extern boolean_t spa_refcount_zero(spa_t *spa);
730
731#define	SCL_NONE	0x00
732#define	SCL_CONFIG	0x01
733#define	SCL_STATE	0x02
734#define	SCL_L2ARC	0x04		/* hack until L2ARC 2.0 */
735#define	SCL_ALLOC	0x08
736#define	SCL_ZIO		0x10
737#define	SCL_FREE	0x20
738#define	SCL_VDEV	0x40
739#define	SCL_LOCKS	7
740#define	SCL_ALL		((1 << SCL_LOCKS) - 1)
741#define	SCL_STATE_ALL	(SCL_STATE | SCL_L2ARC | SCL_ZIO)
742
743/* Pool configuration locks */
744extern int spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw);
745extern void spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw);
746extern void spa_config_exit(spa_t *spa, int locks, void *tag);
747extern int spa_config_held(spa_t *spa, int locks, krw_t rw);
748
749/* Pool vdev add/remove lock */
750extern uint64_t spa_vdev_enter(spa_t *spa);
751extern uint64_t spa_vdev_config_enter(spa_t *spa);
752extern void spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg,
753    int error, char *tag);
754extern int spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error);
755
756/* Pool vdev state change lock */
757extern void spa_vdev_state_enter(spa_t *spa, int oplock);
758extern int spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error);
759
760/* Log state */
761typedef enum spa_log_state {
762	SPA_LOG_UNKNOWN = 0,	/* unknown log state */
763	SPA_LOG_MISSING,	/* missing log(s) */
764	SPA_LOG_CLEAR,		/* clear the log(s) */
765	SPA_LOG_GOOD,		/* log(s) are good */
766} spa_log_state_t;
767
768extern spa_log_state_t spa_get_log_state(spa_t *spa);
769extern void spa_set_log_state(spa_t *spa, spa_log_state_t state);
770extern int spa_reset_logs(spa_t *spa);
771
772/* Log claim callback */
773extern void spa_claim_notify(zio_t *zio);
774
775/* Accessor functions */
776extern boolean_t spa_shutting_down(spa_t *spa);
777extern struct dsl_pool *spa_get_dsl(spa_t *spa);
778extern boolean_t spa_is_initializing(spa_t *spa);
779extern boolean_t spa_indirect_vdevs_loaded(spa_t *spa);
780extern blkptr_t *spa_get_rootblkptr(spa_t *spa);
781extern void spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp);
782extern void spa_altroot(spa_t *, char *, size_t);
783extern int spa_sync_pass(spa_t *spa);
784extern char *spa_name(spa_t *spa);
785extern uint64_t spa_guid(spa_t *spa);
786extern uint64_t spa_load_guid(spa_t *spa);
787extern uint64_t spa_last_synced_txg(spa_t *spa);
788extern uint64_t spa_first_txg(spa_t *spa);
789extern uint64_t spa_syncing_txg(spa_t *spa);
790extern uint64_t spa_final_dirty_txg(spa_t *spa);
791extern uint64_t spa_version(spa_t *spa);
792extern pool_state_t spa_state(spa_t *spa);
793extern spa_load_state_t spa_load_state(spa_t *spa);
794extern uint64_t spa_freeze_txg(spa_t *spa);
795extern uint64_t spa_get_worst_case_asize(spa_t *spa, uint64_t lsize);
796extern uint64_t spa_get_dspace(spa_t *spa);
797extern uint64_t spa_get_checkpoint_space(spa_t *spa);
798extern uint64_t spa_get_slop_space(spa_t *spa);
799extern void spa_update_dspace(spa_t *spa);
800extern uint64_t spa_version(spa_t *spa);
801extern boolean_t spa_deflate(spa_t *spa);
802extern metaslab_class_t *spa_normal_class(spa_t *spa);
803extern metaslab_class_t *spa_log_class(spa_t *spa);
804extern void spa_evicting_os_register(spa_t *, objset_t *os);
805extern void spa_evicting_os_deregister(spa_t *, objset_t *os);
806extern void spa_evicting_os_wait(spa_t *spa);
807extern int spa_max_replication(spa_t *spa);
808extern int spa_prev_software_version(spa_t *spa);
809extern int spa_busy(void);
810extern uint8_t spa_get_failmode(spa_t *spa);
811extern boolean_t spa_suspended(spa_t *spa);
812extern uint64_t spa_bootfs(spa_t *spa);
813extern uint64_t spa_delegation(spa_t *spa);
814extern objset_t *spa_meta_objset(spa_t *spa);
815extern uint64_t spa_deadman_synctime(spa_t *spa);
816
817/* Miscellaneous support routines */
818extern void spa_load_failed(spa_t *spa, const char *fmt, ...);
819extern void spa_load_note(spa_t *spa, const char *fmt, ...);
820extern void spa_activate_mos_feature(spa_t *spa, const char *feature,
821    dmu_tx_t *tx);
822extern void spa_deactivate_mos_feature(spa_t *spa, const char *feature);
823extern int spa_rename(const char *oldname, const char *newname);
824extern spa_t *spa_by_guid(uint64_t pool_guid, uint64_t device_guid);
825extern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid);
826extern char *spa_strdup(const char *);
827extern void spa_strfree(char *);
828extern uint64_t spa_get_random(uint64_t range);
829extern uint64_t spa_generate_guid(spa_t *spa);
830extern void snprintf_blkptr(char *buf, size_t buflen, const blkptr_t *bp);
831extern void spa_freeze(spa_t *spa);
832extern int spa_change_guid(spa_t *spa);
833extern void spa_upgrade(spa_t *spa, uint64_t version);
834extern void spa_evict_all(void);
835extern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid,
836    boolean_t l2cache);
837extern boolean_t spa_has_spare(spa_t *, uint64_t guid);
838extern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva);
839extern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp);
840extern uint64_t bp_get_dsize(spa_t *spa, const blkptr_t *bp);
841extern boolean_t spa_has_slogs(spa_t *spa);
842extern boolean_t spa_is_root(spa_t *spa);
843extern boolean_t spa_writeable(spa_t *spa);
844extern boolean_t spa_has_pending_synctask(spa_t *spa);
845extern int spa_maxblocksize(spa_t *spa);
846extern boolean_t spa_has_checkpoint(spa_t *spa);
847extern boolean_t spa_importing_readonly_checkpoint(spa_t *spa);
848extern boolean_t spa_suspend_async_destroy(spa_t *spa);
849extern uint64_t spa_min_claim_txg(spa_t *spa);
850extern void zfs_blkptr_verify(spa_t *spa, const blkptr_t *bp);
851extern boolean_t zfs_dva_valid(spa_t *spa, const dva_t *dva,
852    const blkptr_t *bp);
853typedef void (*spa_remap_cb_t)(uint64_t vdev, uint64_t offset, uint64_t size,
854    void *arg);
855extern boolean_t spa_remap_blkptr(spa_t *spa, blkptr_t *bp,
856    spa_remap_cb_t callback, void *arg);
857extern uint64_t spa_get_last_removal_txg(spa_t *spa);
858extern boolean_t spa_trust_config(spa_t *spa);
859extern uint64_t spa_missing_tvds_allowed(spa_t *spa);
860extern void spa_set_missing_tvds(spa_t *spa, uint64_t missing);
861extern boolean_t spa_top_vdevs_spacemap_addressable(spa_t *spa);
862
863extern int spa_mode(spa_t *spa);
864extern uint64_t zfs_strtonum(const char *str, char **nptr);
865
866extern char *spa_his_ievent_table[];
867
868extern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx);
869extern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read,
870    char *his_buf);
871extern int spa_history_log(spa_t *spa, const char *his_buf);
872extern int spa_history_log_nvl(spa_t *spa, nvlist_t *nvl);
873extern void spa_history_log_version(spa_t *spa, const char *operation);
874extern void spa_history_log_internal(spa_t *spa, const char *operation,
875    dmu_tx_t *tx, const char *fmt, ...);
876extern void spa_history_log_internal_ds(struct dsl_dataset *ds, const char *op,
877    dmu_tx_t *tx, const char *fmt, ...);
878extern void spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation,
879    dmu_tx_t *tx, const char *fmt, ...);
880
881/* error handling */
882struct zbookmark_phys;
883extern void spa_log_error(spa_t *spa, zio_t *zio);
884extern void zfs_ereport_post(const char *class, spa_t *spa, vdev_t *vd,
885    zio_t *zio, uint64_t stateoroffset, uint64_t length);
886extern void zfs_post_remove(spa_t *spa, vdev_t *vd);
887extern void zfs_post_state_change(spa_t *spa, vdev_t *vd);
888extern void zfs_post_autoreplace(spa_t *spa, vdev_t *vd);
889extern uint64_t spa_get_errlog_size(spa_t *spa);
890extern int spa_get_errlog(spa_t *spa, void *uaddr, size_t *count);
891extern void spa_errlog_rotate(spa_t *spa);
892extern void spa_errlog_drain(spa_t *spa);
893extern void spa_errlog_sync(spa_t *spa, uint64_t txg);
894extern void spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub);
895
896/* vdev cache */
897extern void vdev_cache_stat_init(void);
898extern void vdev_cache_stat_fini(void);
899
900/* Initialization and termination */
901extern void spa_init(int flags);
902extern void spa_fini(void);
903extern void spa_boot_init(void);
904
905/* properties */
906extern int spa_prop_set(spa_t *spa, nvlist_t *nvp);
907extern int spa_prop_get(spa_t *spa, nvlist_t **nvp);
908extern void spa_prop_clear_bootfs(spa_t *spa, uint64_t obj, dmu_tx_t *tx);
909extern void spa_configfile_set(spa_t *, nvlist_t *, boolean_t);
910
911/* asynchronous event notification */
912extern void spa_event_notify(spa_t *spa, vdev_t *vdev, nvlist_t *hist_nvl,
913    const char *name);
914extern sysevent_t *spa_event_create(spa_t *spa, vdev_t *vd, nvlist_t *hist_nvl,
915    const char *name);
916extern void spa_event_post(sysevent_t *ev);
917extern void spa_event_discard(sysevent_t *ev);
918
919#ifdef ZFS_DEBUG
920#define	dprintf_bp(bp, fmt, ...) do {				\
921	if (zfs_flags & ZFS_DEBUG_DPRINTF) {			\
922	char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP);	\
923	snprintf_blkptr(__blkbuf, BP_SPRINTF_LEN, (bp));	\
924	dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf);		\
925	kmem_free(__blkbuf, BP_SPRINTF_LEN);			\
926	} \
927_NOTE(CONSTCOND) } while (0)
928#else
929#define	dprintf_bp(bp, fmt, ...)
930#endif
931
932extern int spa_mode_global;			/* mode, e.g. FREAD | FWRITE */
933
934#ifdef	__cplusplus
935}
936#endif
937
938#endif	/* _SYS_SPA_H */
939