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