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