1
2
3
4
5
6
7
8
9
10#ifndef ZFS_SPA_HEADER
11#define ZFS_SPA_HEADER 1
12
13
14
15
16
17#define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len))
18#define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len))
19#define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low))
20#define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low))
21
22#define BF32_GET(x, low, len) BF32_DECODE(x, low, len)
23#define BF64_GET(x, low, len) BF64_DECODE(x, low, len)
24
25#define BF32_SET(x, low, len, val) \
26 ((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len))
27#define BF64_SET(x, low, len, val) \
28 ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len))
29
30#define BF32_GET_SB(x, low, len, shift, bias) \
31 ((BF32_GET(x, low, len) + (bias)) << (shift))
32#define BF64_GET_SB(x, low, len, shift, bias) \
33 ((BF64_GET(x, low, len) + (bias)) << (shift))
34
35#define BF32_SET_SB(x, low, len, shift, bias, val) \
36 BF32_SET(x, low, len, ((val) >> (shift)) - (bias))
37#define BF64_SET_SB(x, low, len, shift, bias, val) \
38 BF64_SET(x, low, len, ((val) >> (shift)) - (bias))
39
40
41
42
43
44
45#define SPA_MINBLOCKSHIFT 9
46#define SPA_MAXBLOCKSHIFT 17
47#define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT)
48#define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT)
49
50#define SPA_BLOCKSIZES (SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)
51
52
53
54
55#define SPA_CONFIG_BLOCKSIZE (1 << 14)
56
57
58
59
60
61
62
63
64#define SPA_LSIZEBITS 16
65#define SPA_PSIZEBITS 16
66#define SPA_ASIZEBITS 24
67
68
69
70
71
72typedef struct dva {
73 uint64_t dva_word[2];
74} dva_t;
75
76
77
78
79typedef struct zio_cksum {
80 uint64_t zc_word[4];
81} zio_cksum_t;
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143#define SPA_BLKPTRSHIFT 7
144#define SPA_DVAS_PER_BP 3
145
146typedef struct blkptr {
147 dva_t blk_dva[SPA_DVAS_PER_BP];
148 uint64_t blk_prop;
149 uint64_t blk_pad[2];
150 uint64_t blk_phys_birth;
151 uint64_t blk_birth;
152 uint64_t blk_fill;
153 zio_cksum_t blk_cksum;
154} blkptr_t;
155
156
157
158
159#define DVA_GET_ASIZE(dva) \
160 BF64_GET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0)
161#define DVA_SET_ASIZE(dva, x) \
162 BF64_SET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0, x)
163
164#define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8)
165#define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x)
166
167#define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, 32)
168#define DVA_SET_VDEV(dva, x) BF64_SET((dva)->dva_word[0], 32, 32, x)
169
170#define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1)
171#define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x)
172
173#define BP_GET_LSIZE(bp) \
174 BF64_GET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1)
175#define BP_SET_LSIZE(bp, x) \
176 BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
177
178#define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 8)
179#define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 8, x)
180
181#define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8)
182#define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x)
183
184#define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8)
185#define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x)
186
187#define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5)
188#define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x)
189
190#define BP_GET_PROP_BIT_61(bp) BF64_GET((bp)->blk_prop, 61, 1)
191#define BP_SET_PROP_BIT_61(bp, x) BF64_SET((bp)->blk_prop, 61, 1, x)
192
193#define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1)
194#define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x)
195
196#define BP_GET_BYTEORDER(bp) (0 - BF64_GET((bp)->blk_prop, 63, 1))
197#define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x)
198
199#define BP_PHYSICAL_BIRTH(bp) \
200 ((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)
201
202#define BP_SET_BIRTH(bp, logical, physical) \
203 { \
204 (bp)->blk_birth = (logical); \
205 (bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \
206 }
207
208#define BP_GET_ASIZE(bp) \
209 (DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
210 DVA_GET_ASIZE(&(bp)->blk_dva[2]))
211
212#define BP_GET_UCSIZE(bp) \
213 ((BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) ? \
214 BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp));
215
216#define BP_GET_NDVAS(bp) \
217 (!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
218 !!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
219 !!DVA_GET_ASIZE(&(bp)->blk_dva[2]))
220
221#define BP_COUNT_GANG(bp) \
222 (DVA_GET_GANG(&(bp)->blk_dva[0]) + \
223 DVA_GET_GANG(&(bp)->blk_dva[1]) + \
224 DVA_GET_GANG(&(bp)->blk_dva[2]))
225
226#define DVA_EQUAL(dva1, dva2) \
227 ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
228 (dva1)->dva_word[0] == (dva2)->dva_word[0])
229
230#define BP_EQUAL(bp1, bp2) \
231 (BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) && \
232 DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) && \
233 DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) && \
234 DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2]))
235
236#define ZIO_CHECKSUM_EQUAL(zc1, zc2) \
237 (0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
238 ((zc1).zc_word[1] - (zc2).zc_word[1]) | \
239 ((zc1).zc_word[2] - (zc2).zc_word[2]) | \
240 ((zc1).zc_word[3] - (zc2).zc_word[3])))
241
242#define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0)
243
244#define ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3) \
245 { \
246 (zcp)->zc_word[0] = w0; \
247 (zcp)->zc_word[1] = w1; \
248 (zcp)->zc_word[2] = w2; \
249 (zcp)->zc_word[3] = w3; \
250 }
251
252#define BP_IDENTITY(bp) (&(bp)->blk_dva[0])
253#define BP_IS_GANG(bp) DVA_GET_GANG(BP_IDENTITY(bp))
254#define BP_IS_HOLE(bp) ((bp)->blk_birth == 0)
255
256
257#define BP_IS_RAIDZ(bp) (DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \
258 BP_GET_PSIZE(bp))
259
260#define BP_ZERO(bp) \
261 { \
262 (bp)->blk_dva[0].dva_word[0] = 0; \
263 (bp)->blk_dva[0].dva_word[1] = 0; \
264 (bp)->blk_dva[1].dva_word[0] = 0; \
265 (bp)->blk_dva[1].dva_word[1] = 0; \
266 (bp)->blk_dva[2].dva_word[0] = 0; \
267 (bp)->blk_dva[2].dva_word[1] = 0; \
268 (bp)->blk_prop = 0; \
269 (bp)->blk_pad[0] = 0; \
270 (bp)->blk_pad[1] = 0; \
271 (bp)->blk_phys_birth = 0; \
272 (bp)->blk_birth = 0; \
273 (bp)->blk_fill = 0; \
274 ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \
275 }
276
277#define BP_SPRINTF_LEN 320
278
279#endif
280