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