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