ia64/xen-unstable

view tools/libfsimage/zfs/zfs-include/spa.h @ 19648:f0e2df69a8eb

x86 hvm: Allow cross-vendor migration

Intercept #UD and emulate SYSCALL/SYSENTER/SYSEXIT as necessary.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 26 15:01:36 2009 +0100 (2009-05-26)
parents 64f790e90d3d
children
line source
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
21 * Use is subject to license terms.
22 */
24 #ifndef _SYS_SPA_H
25 #define _SYS_SPA_H
27 /*
28 * General-purpose 32-bit and 64-bit bitfield encodings.
29 */
30 #define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len))
31 #define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len))
32 #define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low))
33 #define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low))
35 #define BF32_GET(x, low, len) BF32_DECODE(x, low, len)
36 #define BF64_GET(x, low, len) BF64_DECODE(x, low, len)
38 #define BF32_SET(x, low, len, val) \
39 ((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len))
40 #define BF64_SET(x, low, len, val) \
41 ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len))
43 #define BF32_GET_SB(x, low, len, shift, bias) \
44 ((BF32_GET(x, low, len) + (bias)) << (shift))
45 #define BF64_GET_SB(x, low, len, shift, bias) \
46 ((BF64_GET(x, low, len) + (bias)) << (shift))
48 #define BF32_SET_SB(x, low, len, shift, bias, val) \
49 BF32_SET(x, low, len, ((val) >> (shift)) - (bias))
50 #define BF64_SET_SB(x, low, len, shift, bias, val) \
51 BF64_SET(x, low, len, ((val) >> (shift)) - (bias))
53 /*
54 * We currently support nine block sizes, from 512 bytes to 128K.
55 * We could go higher, but the benefits are near-zero and the cost
56 * of COWing a giant block to modify one byte would become excessive.
57 */
58 #define SPA_MINBLOCKSHIFT 9
59 #define SPA_MAXBLOCKSHIFT 17
60 #define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT)
61 #define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT)
63 #define SPA_BLOCKSIZES (SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)
65 /*
66 * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
67 * The ASIZE encoding should be at least 64 times larger (6 more bits)
68 * to support up to 4-way RAID-Z mirror mode with worst-case gang block
69 * overhead, three DVAs per bp, plus one more bit in case we do anything
70 * else that expands the ASIZE.
71 */
72 #define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */
73 #define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */
74 #define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */
76 /*
77 * All SPA data is represented by 128-bit data virtual addresses (DVAs).
78 * The members of the dva_t should be considered opaque outside the SPA.
79 */
80 typedef struct dva {
81 uint64_t dva_word[2];
82 } dva_t;
84 /*
85 * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
86 */
87 typedef struct zio_cksum {
88 uint64_t zc_word[4];
89 } zio_cksum_t;
91 /*
92 * Each block is described by its DVAs, time of birth, checksum, etc.
93 * The word-by-word, bit-by-bit layout of the blkptr is as follows:
94 *
95 * 64 56 48 40 32 24 16 8 0
96 * +-------+-------+-------+-------+-------+-------+-------+-------+
97 * 0 | vdev1 | GRID | ASIZE |
98 * +-------+-------+-------+-------+-------+-------+-------+-------+
99 * 1 |G| offset1 |
100 * +-------+-------+-------+-------+-------+-------+-------+-------+
101 * 2 | vdev2 | GRID | ASIZE |
102 * +-------+-------+-------+-------+-------+-------+-------+-------+
103 * 3 |G| offset2 |
104 * +-------+-------+-------+-------+-------+-------+-------+-------+
105 * 4 | vdev3 | GRID | ASIZE |
106 * +-------+-------+-------+-------+-------+-------+-------+-------+
107 * 5 |G| offset3 |
108 * +-------+-------+-------+-------+-------+-------+-------+-------+
109 * 6 |E| lvl | type | cksum | comp | PSIZE | LSIZE |
110 * +-------+-------+-------+-------+-------+-------+-------+-------+
111 * 7 | padding |
112 * +-------+-------+-------+-------+-------+-------+-------+-------+
113 * 8 | padding |
114 * +-------+-------+-------+-------+-------+-------+-------+-------+
115 * 9 | padding |
116 * +-------+-------+-------+-------+-------+-------+-------+-------+
117 * a | birth txg |
118 * +-------+-------+-------+-------+-------+-------+-------+-------+
119 * b | fill count |
120 * +-------+-------+-------+-------+-------+-------+-------+-------+
121 * c | checksum[0] |
122 * +-------+-------+-------+-------+-------+-------+-------+-------+
123 * d | checksum[1] |
124 * +-------+-------+-------+-------+-------+-------+-------+-------+
125 * e | checksum[2] |
126 * +-------+-------+-------+-------+-------+-------+-------+-------+
127 * f | checksum[3] |
128 * +-------+-------+-------+-------+-------+-------+-------+-------+
129 *
130 * Legend:
131 *
132 * vdev virtual device ID
133 * offset offset into virtual device
134 * LSIZE logical size
135 * PSIZE physical size (after compression)
136 * ASIZE allocated size (including RAID-Z parity and gang block headers)
137 * GRID RAID-Z layout information (reserved for future use)
138 * cksum checksum function
139 * comp compression function
140 * G gang block indicator
141 * E endianness
142 * type DMU object type
143 * lvl level of indirection
144 * birth txg transaction group in which the block was born
145 * fill count number of non-zero blocks under this bp
146 * checksum[4] 256-bit checksum of the data this bp describes
147 */
148 typedef struct blkptr {
149 dva_t blk_dva[3]; /* 128-bit Data Virtual Address */
150 uint64_t blk_prop; /* size, compression, type, etc */
151 uint64_t blk_pad[3]; /* Extra space for the future */
152 uint64_t blk_birth; /* transaction group at birth */
153 uint64_t blk_fill; /* fill count */
154 zio_cksum_t blk_cksum; /* 256-bit checksum */
155 } blkptr_t;
157 #define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */
158 #define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */
160 /*
161 * Macros to get and set fields in a bp or DVA.
162 */
163 #define DVA_GET_ASIZE(dva) \
164 BF64_GET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0)
165 #define DVA_SET_ASIZE(dva, x) \
166 BF64_SET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0, x)
168 #define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8)
169 #define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x)
171 #define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, 32)
172 #define DVA_SET_VDEV(dva, x) BF64_SET((dva)->dva_word[0], 32, 32, x)
174 #define DVA_GET_OFFSET(dva) \
175 BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0)
176 #define DVA_SET_OFFSET(dva, x) \
177 BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x)
179 #define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1)
180 #define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x)
182 #define BP_GET_LSIZE(bp) \
183 (BP_IS_HOLE(bp) ? 0 : \
184 BF64_GET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1))
185 #define BP_SET_LSIZE(bp, x) \
186 BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
188 #define BP_GET_PSIZE(bp) \
189 BF64_GET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1)
190 #define BP_SET_PSIZE(bp, x) \
191 BF64_SET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1, x)
193 #define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 8)
194 #define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 8, x)
196 #define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8)
197 #define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x)
199 #define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8)
200 #define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x)
202 #define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5)
203 #define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x)
205 #define BP_GET_BYTEORDER(bp) (0 - BF64_GET((bp)->blk_prop, 63, 1))
206 #define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x)
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]))
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));
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]))
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]))
226 #define DVA_EQUAL(dva1, dva2) \
227 ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
228 (dva1)->dva_word[0] == (dva2)->dva_word[0])
230 #define ZIO_CHECKSUM_EQUAL(zc1, zc2) \
231 (0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
232 ((zc1).zc_word[1] - (zc2).zc_word[1]) | \
233 ((zc1).zc_word[2] - (zc2).zc_word[2]) | \
234 ((zc1).zc_word[3] - (zc2).zc_word[3])))
237 #define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0)
239 #define ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3) \
240 { \
241 (zcp)->zc_word[0] = w0; \
242 (zcp)->zc_word[1] = w1; \
243 (zcp)->zc_word[2] = w2; \
244 (zcp)->zc_word[3] = w3; \
245 }
247 #define BP_IDENTITY(bp) (&(bp)->blk_dva[0])
248 #define BP_IS_GANG(bp) DVA_GET_GANG(BP_IDENTITY(bp))
249 #define BP_IS_HOLE(bp) ((bp)->blk_birth == 0)
250 #define BP_IS_OLDER(bp, txg) (!BP_IS_HOLE(bp) && (bp)->blk_birth < (txg))
252 #define BP_ZERO(bp) \
253 { \
254 (bp)->blk_dva[0].dva_word[0] = 0; \
255 (bp)->blk_dva[0].dva_word[1] = 0; \
256 (bp)->blk_dva[1].dva_word[0] = 0; \
257 (bp)->blk_dva[1].dva_word[1] = 0; \
258 (bp)->blk_dva[2].dva_word[0] = 0; \
259 (bp)->blk_dva[2].dva_word[1] = 0; \
260 (bp)->blk_prop = 0; \
261 (bp)->blk_pad[0] = 0; \
262 (bp)->blk_pad[1] = 0; \
263 (bp)->blk_pad[2] = 0; \
264 (bp)->blk_birth = 0; \
265 (bp)->blk_fill = 0; \
266 ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \
267 }
269 /*
270 * Note: the byteorder is either 0 or -1, both of which are palindromes.
271 * This simplifies the endianness handling a bit.
272 */
273 #ifdef _BIG_ENDIAN
274 #define ZFS_HOST_BYTEORDER (0ULL)
275 #else
276 #define ZFS_HOST_BYTEORDER (-1ULL)
277 #endif
279 #define BP_SHOULD_BYTESWAP(bp) (BP_GET_BYTEORDER(bp) != ZFS_HOST_BYTEORDER)
281 #define BP_SPRINTF_LEN 320
283 #endif /* _SYS_SPA_H */