author | Christopher Siden <chris.siden@delphix.com> |
Mon, 21 May 2012 12:11:39 -0700 | |
changeset 13700 | 2889e2596bd6 |
parent 13421 | a4721c685d96 |
child 13921 | 9d721847e469 |
permissions | -rw-r--r-- |
3912 | 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 |
*/ |
|
13700
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
19 |
|
3912 | 20 |
/* |
11670
1d964fb5d948
6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10056
diff
changeset
|
21 |
* Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
3912 | 22 |
* Use is subject to license terms. |
23 |
*/ |
|
13700
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
24 |
|
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
25 |
/* |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
26 |
* Copyright (c) 2012 by Delphix. All rights reserved. |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
27 |
*/ |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
28 |
|
3912 | 29 |
#ifndef _FSYS_ZFS_H |
30 |
#define _FSYS_ZFS_H |
|
31 |
||
32 |
#ifdef FSYS_ZFS |
|
33 |
||
12012
32b94791f957
6938228 Needs to be easier to sync zfs boot support in grub with libfsimage/pygrub
Mark Johnson <mark.r.johnson@oracle.com>
parents:
11935
diff
changeset
|
34 |
#ifndef FSIMAGE |
3912 | 35 |
typedef unsigned long long uint64_t; |
36 |
typedef unsigned int uint32_t; |
|
37 |
typedef unsigned short uint16_t; |
|
38 |
typedef unsigned char uint8_t; |
|
39 |
typedef unsigned char uchar_t; |
|
40 |
||
41 |
#if defined(_LP64) || defined(_I32LPx) |
|
42 |
typedef unsigned long size_t; |
|
43 |
#else |
|
44 |
typedef unsigned int size_t; |
|
45 |
#endif |
|
12012
32b94791f957
6938228 Needs to be easier to sync zfs boot support in grub with libfsimage/pygrub
Mark Johnson <mark.r.johnson@oracle.com>
parents:
11935
diff
changeset
|
46 |
#else |
32b94791f957
6938228 Needs to be easier to sync zfs boot support in grub with libfsimage/pygrub
Mark Johnson <mark.r.johnson@oracle.com>
parents:
11935
diff
changeset
|
47 |
#include "fsi_zfs.h" |
32b94791f957
6938228 Needs to be easier to sync zfs boot support in grub with libfsimage/pygrub
Mark Johnson <mark.r.johnson@oracle.com>
parents:
11935
diff
changeset
|
48 |
#endif /* !FSIMAGE */ |
3912 | 49 |
|
50 |
#include <zfs-include/zfs.h> |
|
51 |
#include <zfs-include/dmu.h> |
|
52 |
#include <zfs-include/spa.h> |
|
53 |
#include <zfs-include/zio.h> |
|
54 |
#include <zfs-include/zio_checksum.h> |
|
55 |
#include <zfs-include/vdev_impl.h> |
|
56 |
#include <zfs-include/zap_impl.h> |
|
57 |
#include <zfs-include/zap_leaf.h> |
|
58 |
#include <zfs-include/uberblock_impl.h> |
|
59 |
#include <zfs-include/dnode.h> |
|
60 |
#include <zfs-include/dsl_dir.h> |
|
61 |
#include <zfs-include/zfs_acl.h> |
|
62 |
#include <zfs-include/zfs_znode.h> |
|
63 |
#include <zfs-include/dsl_dataset.h> |
|
64 |
#include <zfs-include/zil.h> |
|
65 |
#include <zfs-include/dmu_objset.h> |
|
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11670
diff
changeset
|
66 |
#include <zfs-include/sa_impl.h> |
3912 | 67 |
|
68 |
/* |
|
69 |
* Global Memory addresses to store MOS and DNODE data |
|
70 |
*/ |
|
5084 | 71 |
#define MOS ((dnode_phys_t *)\ |
5085
937feae7206d
6584697 Can't boot Xen / Solaris dom0 if root is using ZFS (fix cstyle)
johnlev
parents:
5084
diff
changeset
|
72 |
(RAW_ADDR((mbi.mem_upper << 10) + 0x100000) - ZFS_SCRATCH_SIZE)) |
4725
0452c60b6e69
6541114 GRUB/ZFS fails to load files from a default compressed (lzjb) root
lling
parents:
3912
diff
changeset
|
73 |
#define DNODE (MOS+1) /* move sizeof(dnode_phys_t) bytes */ |
0452c60b6e69
6541114 GRUB/ZFS fails to load files from a default compressed (lzjb) root
lling
parents:
3912
diff
changeset
|
74 |
#define ZFS_SCRATCH ((char *)(DNODE+1)) |
3912 | 75 |
|
76 |
/* |
|
77 |
* Verify dnode type. |
|
78 |
* Can only be used in functions returning non-0 for failure. |
|
79 |
*/ |
|
80 |
#define VERIFY_DN_TYPE(dnp, type) \ |
|
81 |
if (type && (dnp)->dn_type != type) { \ |
|
82 |
return (ERR_FSYS_CORRUPT); \ |
|
83 |
} |
|
84 |
||
85 |
/* |
|
86 |
* Verify object set type. |
|
87 |
* Can only be used in functions returning 0 for failure. |
|
88 |
*/ |
|
89 |
#define VERIFY_OS_TYPE(osp, type) \ |
|
90 |
if (type && (osp)->os_type != type) { \ |
|
91 |
errnum = ERR_FSYS_CORRUPT; \ |
|
92 |
return (0); \ |
|
93 |
} |
|
94 |
||
95 |
#define ZPOOL_PROP_BOOTFS "bootfs" |
|
96 |
||
97 |
/* General macros */ |
|
98 |
#define BSWAP_8(x) ((x) & 0xff) |
|
99 |
#define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8)) |
|
100 |
#define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16)) |
|
101 |
#define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32)) |
|
102 |
#define P2ROUNDUP(x, align) (-(-(x) & -(align))) |
|
103 |
||
104 |
typedef struct uberblock uberblock_t; |
|
105 |
||
106 |
/* |
|
107 |
* Macros to get fields in a bp or DVA. |
|
108 |
*/ |
|
109 |
#define P2PHASE(x, align) ((x) & ((align) - 1)) |
|
110 |
#define DVA_OFFSET_TO_PHYS_SECTOR(offset) \ |
|
111 |
((offset + VDEV_LABEL_START_SIZE) >> SPA_MINBLOCKSHIFT) |
|
112 |
||
113 |
/* |
|
10056
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
114 |
* return x rounded down to an align boundary |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
115 |
* eg, P2ALIGN(1200, 1024) == 1024 (1*align) |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
116 |
* eg, P2ALIGN(1024, 1024) == 1024 (1*align) |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
117 |
* eg, P2ALIGN(0x1234, 0x100) == 0x1200 (0x12*align) |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
118 |
* eg, P2ALIGN(0x5600, 0x100) == 0x5600 (0x56*align) |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
119 |
*/ |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
120 |
#define P2ALIGN(x, align) ((x) & -(align)) |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
121 |
|
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
122 |
/* |
3912 | 123 |
* For nvlist manipulation. (from nvpair.h) |
124 |
*/ |
|
125 |
#define NV_ENCODE_NATIVE 0 |
|
126 |
#define NV_ENCODE_XDR 1 |
|
127 |
#define HOST_ENDIAN 1 /* for x86 machine */ |
|
13700
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
128 |
typedef enum { |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
129 |
DATA_TYPE_UNKNOWN = 0, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
130 |
DATA_TYPE_BOOLEAN, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
131 |
DATA_TYPE_BYTE, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
132 |
DATA_TYPE_INT16, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
133 |
DATA_TYPE_UINT16, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
134 |
DATA_TYPE_INT32, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
135 |
DATA_TYPE_UINT32, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
136 |
DATA_TYPE_INT64, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
137 |
DATA_TYPE_UINT64, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
138 |
DATA_TYPE_STRING, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
139 |
DATA_TYPE_BYTE_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
140 |
DATA_TYPE_INT16_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
141 |
DATA_TYPE_UINT16_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
142 |
DATA_TYPE_INT32_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
143 |
DATA_TYPE_UINT32_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
144 |
DATA_TYPE_INT64_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
145 |
DATA_TYPE_UINT64_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
146 |
DATA_TYPE_STRING_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
147 |
DATA_TYPE_HRTIME, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
148 |
DATA_TYPE_NVLIST, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
149 |
DATA_TYPE_NVLIST_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
150 |
DATA_TYPE_BOOLEAN_VALUE, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
151 |
DATA_TYPE_INT8, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
152 |
DATA_TYPE_UINT8, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
153 |
DATA_TYPE_BOOLEAN_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
154 |
DATA_TYPE_INT8_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
155 |
DATA_TYPE_UINT8_ARRAY, |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
156 |
DATA_TYPE_DOUBLE |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13421
diff
changeset
|
157 |
} data_type_t; |
3912 | 158 |
|
159 |
/* |
|
160 |
* Decompression Entry - lzjb |
|
161 |
*/ |
|
162 |
#ifndef NBBY |
|
163 |
#define NBBY 8 |
|
164 |
#endif |
|
165 |
||
166 |
typedef int zfs_decomp_func_t(void *s_start, void *d_start, size_t s_len, |
|
167 |
size_t d_len); |
|
168 |
typedef struct decomp_entry { |
|
169 |
char *name; |
|
170 |
zfs_decomp_func_t *decomp_func; |
|
171 |
} decomp_entry_t; |
|
172 |
||
173 |
/* |
|
174 |
* FAT ZAP data structures |
|
175 |
*/ |
|
176 |
#define ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */ |
|
177 |
#define ZAP_HASH_IDX(hash, n) (((n) == 0) ? 0 : ((hash) >> (64 - (n)))) |
|
178 |
#define CHAIN_END 0xffff /* end of the chunk chain */ |
|
179 |
||
180 |
/* |
|
181 |
* The amount of space within the chunk available for the array is: |
|
182 |
* chunk size - space for type (1) - space for next pointer (2) |
|
183 |
*/ |
|
184 |
#define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3) |
|
185 |
||
186 |
#define ZAP_LEAF_HASH_SHIFT(bs) (bs - 5) |
|
187 |
#define ZAP_LEAF_HASH_NUMENTRIES(bs) (1 << ZAP_LEAF_HASH_SHIFT(bs)) |
|
188 |
#define LEAF_HASH(bs, h) \ |
|
189 |
((ZAP_LEAF_HASH_NUMENTRIES(bs)-1) & \ |
|
190 |
((h) >> (64 - ZAP_LEAF_HASH_SHIFT(bs)-l->l_hdr.lh_prefix_len))) |
|
191 |
||
192 |
/* |
|
193 |
* The amount of space available for chunks is: |
|
194 |
* block size shift - hash entry size (2) * number of hash |
|
195 |
* entries - header space (2*chunksize) |
|
196 |
*/ |
|
197 |
#define ZAP_LEAF_NUMCHUNKS(bs) \ |
|
198 |
(((1<<bs) - 2*ZAP_LEAF_HASH_NUMENTRIES(bs)) / \ |
|
199 |
ZAP_LEAF_CHUNKSIZE - 2) |
|
200 |
||
201 |
/* |
|
202 |
* The chunks start immediately after the hash table. The end of the |
|
203 |
* hash table is at l_hash + HASH_NUMENTRIES, which we simply cast to a |
|
204 |
* chunk_t. |
|
205 |
*/ |
|
206 |
#define ZAP_LEAF_CHUNK(l, bs, idx) \ |
|
207 |
((zap_leaf_chunk_t *)(l->l_hash + ZAP_LEAF_HASH_NUMENTRIES(bs)))[idx] |
|
208 |
#define ZAP_LEAF_ENTRY(l, bs, idx) (&ZAP_LEAF_CHUNK(l, bs, idx).l_entry) |
|
209 |
||
210 |
extern void fletcher_2_native(const void *, uint64_t, zio_cksum_t *); |
|
211 |
extern void fletcher_2_byteswap(const void *, uint64_t, zio_cksum_t *); |
|
212 |
extern void fletcher_4_native(const void *, uint64_t, zio_cksum_t *); |
|
213 |
extern void fletcher_4_byteswap(const void *, uint64_t, zio_cksum_t *); |
|
214 |
extern void zio_checksum_SHA256(const void *, uint64_t, zio_cksum_t *); |
|
215 |
extern int lzjb_decompress(void *, void *, size_t, size_t); |
|
216 |
||
217 |
#endif /* FSYS_ZFS */ |
|
218 |
||
219 |
#endif /* !_FSYS_ZFS_H */ |