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