author | Jeff Bonwick <Jeff.Bonwick@Sun.COM> |
Sun, 01 Nov 2009 14:14:46 -0800 | |
changeset 10922 | e2081f502306 |
parent 10612 | 89423355fa6f |
child 11022 | 63ab26072e41 |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
5 |
* Common Development and Distribution License (the "License"). |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
6 |
* You may not use this file except in compliance with the License. |
789 | 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 |
/* |
|
9643
ffd8e7765f02
6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7046
diff
changeset
|
22 |
* Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
/* |
|
27 |
* This file contains the top half of the zfs directory structure |
|
28 |
* implementation. The bottom half is in zap_leaf.c. |
|
29 |
* |
|
30 |
* The zdir is an extendable hash data structure. There is a table of |
|
31 |
* pointers to buckets (zap_t->zd_data->zd_leafs). The buckets are |
|
32 |
* each a constant size and hold a variable number of directory entries. |
|
33 |
* The buckets (aka "leaf nodes") are implemented in zap_leaf.c. |
|
34 |
* |
|
35 |
* The pointer table holds a power of 2 number of pointers. |
|
36 |
* (1<<zap_t->zd_data->zd_phys->zd_prefix_len). The bucket pointed to |
|
37 |
* by the pointer at index i in the table holds entries whose hash value |
|
38 |
* has a zd_prefix_len - bit prefix |
|
39 |
*/ |
|
40 |
||
41 |
#include <sys/spa.h> |
|
42 |
#include <sys/dmu.h> |
|
43 |
#include <sys/zfs_context.h> |
|
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5497
diff
changeset
|
44 |
#include <sys/zfs_znode.h> |
9643
ffd8e7765f02
6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7046
diff
changeset
|
45 |
#include <sys/fs/zfs.h> |
789 | 46 |
#include <sys/zap.h> |
1544 | 47 |
#include <sys/refcount.h> |
789 | 48 |
#include <sys/zap_impl.h> |
49 |
#include <sys/zap_leaf.h> |
|
50 |
||
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
51 |
int fzap_default_block_shift = 14; /* 16k blocksize */ |
789 | 52 |
|
53 |
static void zap_leaf_pageout(dmu_buf_t *db, void *vl); |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
54 |
static uint64_t zap_allocate_blocks(zap_t *zap, int nblocks); |
789 | 55 |
|
56 |
||
57 |
void |
|
58 |
fzap_byteswap(void *vbuf, size_t size) |
|
59 |
{ |
|
60 |
uint64_t block_type; |
|
61 |
||
62 |
block_type = *(uint64_t *)vbuf; |
|
63 |
||
2856 | 64 |
if (block_type == ZBT_LEAF || block_type == BSWAP_64(ZBT_LEAF)) |
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
65 |
zap_leaf_byteswap(vbuf, size); |
2856 | 66 |
else { |
789 | 67 |
/* it's a ptrtbl block */ |
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
68 |
byteswap_uint64_array(vbuf, size); |
789 | 69 |
} |
70 |
} |
|
71 |
||
72 |
void |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
73 |
fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags) |
789 | 74 |
{ |
75 |
dmu_buf_t *db; |
|
76 |
zap_leaf_t *l; |
|
77 |
int i; |
|
78 |
zap_phys_t *zp; |
|
79 |
||
80 |
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); |
|
81 |
zap->zap_ismicro = FALSE; |
|
82 |
||
83 |
(void) dmu_buf_update_user(zap->zap_dbuf, zap, zap, |
|
2641 | 84 |
&zap->zap_f.zap_phys, zap_evict); |
789 | 85 |
|
86 |
mutex_init(&zap->zap_f.zap_num_entries_mtx, 0, 0, 0); |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
87 |
zap->zap_f.zap_block_shift = highbit(zap->zap_dbuf->db_size) - 1; |
789 | 88 |
|
89 |
zp = zap->zap_f.zap_phys; |
|
90 |
/* |
|
91 |
* explicitly zero it since it might be coming from an |
|
92 |
* initialized microzap |
|
93 |
*/ |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
94 |
bzero(zap->zap_dbuf->db_data, zap->zap_dbuf->db_size); |
789 | 95 |
zp->zap_block_type = ZBT_HEADER; |
96 |
zp->zap_magic = ZAP_MAGIC; |
|
97 |
||
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
98 |
zp->zap_ptrtbl.zt_shift = ZAP_EMBEDDED_PTRTBL_SHIFT(zap); |
789 | 99 |
|
100 |
zp->zap_freeblk = 2; /* block 1 will be the first leaf */ |
|
101 |
zp->zap_num_leafs = 1; |
|
102 |
zp->zap_num_entries = 0; |
|
103 |
zp->zap_salt = zap->zap_salt; |
|
5331 | 104 |
zp->zap_normflags = zap->zap_normflags; |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
105 |
zp->zap_flags = flags; |
789 | 106 |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
107 |
/* block 1 will be the first leaf */ |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
108 |
for (i = 0; i < (1<<zp->zap_ptrtbl.zt_shift); i++) |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
109 |
ZAP_EMBEDDED_PTRTBL_ENT(zap, i) = 1; |
789 | 110 |
|
111 |
/* |
|
112 |
* set up block 1 - the first leaf |
|
113 |
*/ |
|
1544 | 114 |
VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object, |
115 |
1<<FZAP_BLOCK_SHIFT(zap), FTAG, &db)); |
|
789 | 116 |
dmu_buf_will_dirty(db, tx); |
117 |
||
118 |
l = kmem_zalloc(sizeof (zap_leaf_t), KM_SLEEP); |
|
119 |
l->l_dbuf = db; |
|
120 |
l->l_phys = db->db_data; |
|
121 |
||
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5497
diff
changeset
|
122 |
zap_leaf_init(l, zp->zap_normflags != 0); |
789 | 123 |
|
124 |
kmem_free(l, sizeof (zap_leaf_t)); |
|
1544 | 125 |
dmu_buf_rele(db, FTAG); |
789 | 126 |
} |
127 |
||
128 |
static int |
|
129 |
zap_tryupgradedir(zap_t *zap, dmu_tx_t *tx) |
|
130 |
{ |
|
131 |
if (RW_WRITE_HELD(&zap->zap_rwlock)) |
|
132 |
return (1); |
|
133 |
if (rw_tryupgrade(&zap->zap_rwlock)) { |
|
134 |
dmu_buf_will_dirty(zap->zap_dbuf, tx); |
|
135 |
return (1); |
|
136 |
} |
|
137 |
return (0); |
|
138 |
} |
|
139 |
||
140 |
/* |
|
141 |
* Generic routines for dealing with the pointer & cookie tables. |
|
142 |
*/ |
|
143 |
||
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
144 |
static int |
789 | 145 |
zap_table_grow(zap_t *zap, zap_table_phys_t *tbl, |
146 |
void (*transfer_func)(const uint64_t *src, uint64_t *dst, int n), |
|
147 |
dmu_tx_t *tx) |
|
148 |
{ |
|
149 |
uint64_t b, newblk; |
|
150 |
dmu_buf_t *db_old, *db_new; |
|
1544 | 151 |
int err; |
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
152 |
int bs = FZAP_BLOCK_SHIFT(zap); |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
153 |
int hepb = 1<<(bs-4); |
789 | 154 |
/* hepb = half the number of entries in a block */ |
155 |
||
156 |
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); |
|
157 |
ASSERT(tbl->zt_blk != 0); |
|
158 |
ASSERT(tbl->zt_numblks > 0); |
|
159 |
||
160 |
if (tbl->zt_nextblk != 0) { |
|
161 |
newblk = tbl->zt_nextblk; |
|
162 |
} else { |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
163 |
newblk = zap_allocate_blocks(zap, tbl->zt_numblks * 2); |
789 | 164 |
tbl->zt_nextblk = newblk; |
165 |
ASSERT3U(tbl->zt_blks_copied, ==, 0); |
|
166 |
dmu_prefetch(zap->zap_objset, zap->zap_object, |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
167 |
tbl->zt_blk << bs, tbl->zt_numblks << bs); |
789 | 168 |
} |
169 |
||
170 |
/* |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
171 |
* Copy the ptrtbl from the old to new location. |
789 | 172 |
*/ |
173 |
||
174 |
b = tbl->zt_blks_copied; |
|
1544 | 175 |
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, |
176 |
(tbl->zt_blk + b) << bs, FTAG, &db_old); |
|
177 |
if (err) |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
178 |
return (err); |
789 | 179 |
|
180 |
/* first half of entries in old[b] go to new[2*b+0] */ |
|
1544 | 181 |
VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object, |
182 |
(newblk + 2*b+0) << bs, FTAG, &db_new)); |
|
789 | 183 |
dmu_buf_will_dirty(db_new, tx); |
184 |
transfer_func(db_old->db_data, db_new->db_data, hepb); |
|
1544 | 185 |
dmu_buf_rele(db_new, FTAG); |
789 | 186 |
|
187 |
/* second half of entries in old[b] go to new[2*b+1] */ |
|
1544 | 188 |
VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object, |
189 |
(newblk + 2*b+1) << bs, FTAG, &db_new)); |
|
789 | 190 |
dmu_buf_will_dirty(db_new, tx); |
191 |
transfer_func((uint64_t *)db_old->db_data + hepb, |
|
192 |
db_new->db_data, hepb); |
|
1544 | 193 |
dmu_buf_rele(db_new, FTAG); |
789 | 194 |
|
1544 | 195 |
dmu_buf_rele(db_old, FTAG); |
789 | 196 |
|
197 |
tbl->zt_blks_copied++; |
|
198 |
||
199 |
dprintf("copied block %llu of %llu\n", |
|
200 |
tbl->zt_blks_copied, tbl->zt_numblks); |
|
201 |
||
202 |
if (tbl->zt_blks_copied == tbl->zt_numblks) { |
|
1544 | 203 |
(void) dmu_free_range(zap->zap_objset, zap->zap_object, |
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
204 |
tbl->zt_blk << bs, tbl->zt_numblks << bs, tx); |
789 | 205 |
|
206 |
tbl->zt_blk = newblk; |
|
207 |
tbl->zt_numblks *= 2; |
|
208 |
tbl->zt_shift++; |
|
209 |
tbl->zt_nextblk = 0; |
|
210 |
tbl->zt_blks_copied = 0; |
|
211 |
||
212 |
dprintf("finished; numblocks now %llu (%lluk entries)\n", |
|
213 |
tbl->zt_numblks, 1<<(tbl->zt_shift-10)); |
|
214 |
} |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
215 |
|
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
216 |
return (0); |
789 | 217 |
} |
218 |
||
1544 | 219 |
static int |
789 | 220 |
zap_table_store(zap_t *zap, zap_table_phys_t *tbl, uint64_t idx, uint64_t val, |
221 |
dmu_tx_t *tx) |
|
222 |
{ |
|
1544 | 223 |
int err; |
224 |
uint64_t blk, off; |
|
225 |
int bs = FZAP_BLOCK_SHIFT(zap); |
|
789 | 226 |
dmu_buf_t *db; |
227 |
||
228 |
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock)); |
|
229 |
ASSERT(tbl->zt_blk != 0); |
|
230 |
||
231 |
dprintf("storing %llx at index %llx\n", val, idx); |
|
232 |
||
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
233 |
blk = idx >> (bs-3); |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
234 |
off = idx & ((1<<(bs-3))-1); |
789 | 235 |
|
1544 | 236 |
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, |
237 |
(tbl->zt_blk + blk) << bs, FTAG, &db); |
|
238 |
if (err) |
|
239 |
return (err); |
|
789 | 240 |
dmu_buf_will_dirty(db, tx); |
241 |
||
242 |
if (tbl->zt_nextblk != 0) { |
|
1544 | 243 |
uint64_t idx2 = idx * 2; |
244 |
uint64_t blk2 = idx2 >> (bs-3); |
|
245 |
uint64_t off2 = idx2 & ((1<<(bs-3))-1); |
|
246 |
dmu_buf_t *db2; |
|
789 | 247 |
|
1544 | 248 |
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, |
249 |
(tbl->zt_nextblk + blk2) << bs, FTAG, &db2); |
|
250 |
if (err) { |
|
251 |
dmu_buf_rele(db, FTAG); |
|
252 |
return (err); |
|
253 |
} |
|
254 |
dmu_buf_will_dirty(db2, tx); |
|
255 |
((uint64_t *)db2->db_data)[off2] = val; |
|
256 |
((uint64_t *)db2->db_data)[off2+1] = val; |
|
257 |
dmu_buf_rele(db2, FTAG); |
|
789 | 258 |
} |
259 |
||
1544 | 260 |
((uint64_t *)db->db_data)[off] = val; |
261 |
dmu_buf_rele(db, FTAG); |
|
262 |
||
263 |
return (0); |
|
789 | 264 |
} |
265 |
||
1544 | 266 |
static int |
267 |
zap_table_load(zap_t *zap, zap_table_phys_t *tbl, uint64_t idx, uint64_t *valp) |
|
789 | 268 |
{ |
1544 | 269 |
uint64_t blk, off; |
270 |
int err; |
|
789 | 271 |
dmu_buf_t *db; |
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
272 |
int bs = FZAP_BLOCK_SHIFT(zap); |
789 | 273 |
|
274 |
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock)); |
|
275 |
||
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
276 |
blk = idx >> (bs-3); |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
277 |
off = idx & ((1<<(bs-3))-1); |
789 | 278 |
|
1544 | 279 |
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, |
280 |
(tbl->zt_blk + blk) << bs, FTAG, &db); |
|
281 |
if (err) |
|
282 |
return (err); |
|
283 |
*valp = ((uint64_t *)db->db_data)[off]; |
|
284 |
dmu_buf_rele(db, FTAG); |
|
285 |
||
286 |
if (tbl->zt_nextblk != 0) { |
|
287 |
/* |
|
288 |
* read the nextblk for the sake of i/o error checking, |
|
289 |
* so that zap_table_load() will catch errors for |
|
290 |
* zap_table_store. |
|
291 |
*/ |
|
292 |
blk = (idx*2) >> (bs-3); |
|
293 |
||
294 |
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, |
|
295 |
(tbl->zt_nextblk + blk) << bs, FTAG, &db); |
|
296 |
dmu_buf_rele(db, FTAG); |
|
297 |
} |
|
298 |
return (err); |
|
789 | 299 |
} |
300 |
||
301 |
/* |
|
302 |
* Routines for growing the ptrtbl. |
|
303 |
*/ |
|
304 |
||
305 |
static void |
|
306 |
zap_ptrtbl_transfer(const uint64_t *src, uint64_t *dst, int n) |
|
307 |
{ |
|
308 |
int i; |
|
309 |
for (i = 0; i < n; i++) { |
|
310 |
uint64_t lb = src[i]; |
|
311 |
dst[2*i+0] = lb; |
|
312 |
dst[2*i+1] = lb; |
|
313 |
} |
|
314 |
} |
|
315 |
||
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
316 |
static int |
789 | 317 |
zap_grow_ptrtbl(zap_t *zap, dmu_tx_t *tx) |
318 |
{ |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
319 |
/* |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
320 |
* The pointer table should never use more hash bits than we |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
321 |
* have (otherwise we'd be using useless zero bits to index it). |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
322 |
* If we are within 2 bits of running out, stop growing, since |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
323 |
* this is already an aberrant condition. |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
324 |
*/ |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
325 |
if (zap->zap_f.zap_phys->zap_ptrtbl.zt_shift >= zap_hashbits(zap) - 2) |
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
326 |
return (ENOSPC); |
789 | 327 |
|
328 |
if (zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks == 0) { |
|
329 |
/* |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
330 |
* We are outgrowing the "embedded" ptrtbl (the one |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
331 |
* stored in the header block). Give it its own entire |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
332 |
* block, which will double the size of the ptrtbl. |
789 | 333 |
*/ |
334 |
uint64_t newblk; |
|
335 |
dmu_buf_t *db_new; |
|
1544 | 336 |
int err; |
789 | 337 |
|
338 |
ASSERT3U(zap->zap_f.zap_phys->zap_ptrtbl.zt_shift, ==, |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
339 |
ZAP_EMBEDDED_PTRTBL_SHIFT(zap)); |
789 | 340 |
ASSERT3U(zap->zap_f.zap_phys->zap_ptrtbl.zt_blk, ==, 0); |
341 |
||
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
342 |
newblk = zap_allocate_blocks(zap, 1); |
1544 | 343 |
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, |
344 |
newblk << FZAP_BLOCK_SHIFT(zap), FTAG, &db_new); |
|
345 |
if (err) |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
346 |
return (err); |
789 | 347 |
dmu_buf_will_dirty(db_new, tx); |
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
348 |
zap_ptrtbl_transfer(&ZAP_EMBEDDED_PTRTBL_ENT(zap, 0), |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
349 |
db_new->db_data, 1 << ZAP_EMBEDDED_PTRTBL_SHIFT(zap)); |
1544 | 350 |
dmu_buf_rele(db_new, FTAG); |
789 | 351 |
|
352 |
zap->zap_f.zap_phys->zap_ptrtbl.zt_blk = newblk; |
|
353 |
zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks = 1; |
|
354 |
zap->zap_f.zap_phys->zap_ptrtbl.zt_shift++; |
|
355 |
||
356 |
ASSERT3U(1ULL << zap->zap_f.zap_phys->zap_ptrtbl.zt_shift, ==, |
|
357 |
zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks << |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
358 |
(FZAP_BLOCK_SHIFT(zap)-3)); |
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
359 |
|
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
360 |
return (0); |
789 | 361 |
} else { |
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
362 |
return (zap_table_grow(zap, &zap->zap_f.zap_phys->zap_ptrtbl, |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
363 |
zap_ptrtbl_transfer, tx)); |
789 | 364 |
} |
365 |
} |
|
366 |
||
367 |
static void |
|
368 |
zap_increment_num_entries(zap_t *zap, int delta, dmu_tx_t *tx) |
|
369 |
{ |
|
370 |
dmu_buf_will_dirty(zap->zap_dbuf, tx); |
|
371 |
mutex_enter(&zap->zap_f.zap_num_entries_mtx); |
|
372 |
ASSERT(delta > 0 || zap->zap_f.zap_phys->zap_num_entries >= -delta); |
|
373 |
zap->zap_f.zap_phys->zap_num_entries += delta; |
|
374 |
mutex_exit(&zap->zap_f.zap_num_entries_mtx); |
|
375 |
} |
|
376 |
||
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
377 |
static uint64_t |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
378 |
zap_allocate_blocks(zap_t *zap, int nblocks) |
789 | 379 |
{ |
380 |
uint64_t newblk; |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
381 |
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
382 |
newblk = zap->zap_f.zap_phys->zap_freeblk; |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
383 |
zap->zap_f.zap_phys->zap_freeblk += nblocks; |
789 | 384 |
return (newblk); |
385 |
} |
|
386 |
||
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
387 |
static zap_leaf_t * |
789 | 388 |
zap_create_leaf(zap_t *zap, dmu_tx_t *tx) |
389 |
{ |
|
390 |
void *winner; |
|
391 |
zap_leaf_t *l = kmem_alloc(sizeof (zap_leaf_t), KM_SLEEP); |
|
392 |
||
393 |
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); |
|
394 |
||
395 |
rw_init(&l->l_rwlock, 0, 0, 0); |
|
396 |
rw_enter(&l->l_rwlock, RW_WRITER); |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
397 |
l->l_blkid = zap_allocate_blocks(zap, 1); |
789 | 398 |
l->l_dbuf = NULL; |
399 |
l->l_phys = NULL; |
|
400 |
||
1544 | 401 |
VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object, |
402 |
l->l_blkid << FZAP_BLOCK_SHIFT(zap), NULL, &l->l_dbuf)); |
|
789 | 403 |
winner = dmu_buf_set_user(l->l_dbuf, l, &l->l_phys, zap_leaf_pageout); |
404 |
ASSERT(winner == NULL); |
|
405 |
dmu_buf_will_dirty(l->l_dbuf, tx); |
|
406 |
||
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5497
diff
changeset
|
407 |
zap_leaf_init(l, zap->zap_normflags != 0); |
789 | 408 |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
409 |
zap->zap_f.zap_phys->zap_num_leafs++; |
789 | 410 |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
411 |
return (l); |
789 | 412 |
} |
413 |
||
414 |
int |
|
415 |
fzap_count(zap_t *zap, uint64_t *count) |
|
416 |
{ |
|
417 |
ASSERT(!zap->zap_ismicro); |
|
418 |
mutex_enter(&zap->zap_f.zap_num_entries_mtx); /* unnecessary */ |
|
419 |
*count = zap->zap_f.zap_phys->zap_num_entries; |
|
420 |
mutex_exit(&zap->zap_f.zap_num_entries_mtx); |
|
421 |
return (0); |
|
422 |
} |
|
423 |
||
424 |
/* |
|
425 |
* Routines for obtaining zap_leaf_t's |
|
426 |
*/ |
|
427 |
||
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
428 |
void |
789 | 429 |
zap_put_leaf(zap_leaf_t *l) |
430 |
{ |
|
431 |
rw_exit(&l->l_rwlock); |
|
1544 | 432 |
dmu_buf_rele(l->l_dbuf, NULL); |
789 | 433 |
} |
434 |
||
435 |
_NOTE(ARGSUSED(0)) |
|
436 |
static void |
|
437 |
zap_leaf_pageout(dmu_buf_t *db, void *vl) |
|
438 |
{ |
|
439 |
zap_leaf_t *l = vl; |
|
440 |
||
441 |
rw_destroy(&l->l_rwlock); |
|
442 |
kmem_free(l, sizeof (zap_leaf_t)); |
|
443 |
} |
|
444 |
||
445 |
static zap_leaf_t * |
|
446 |
zap_open_leaf(uint64_t blkid, dmu_buf_t *db) |
|
447 |
{ |
|
448 |
zap_leaf_t *l, *winner; |
|
449 |
||
450 |
ASSERT(blkid != 0); |
|
451 |
||
452 |
l = kmem_alloc(sizeof (zap_leaf_t), KM_SLEEP); |
|
453 |
rw_init(&l->l_rwlock, 0, 0, 0); |
|
454 |
rw_enter(&l->l_rwlock, RW_WRITER); |
|
455 |
l->l_blkid = blkid; |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
456 |
l->l_bs = highbit(db->db_size)-1; |
789 | 457 |
l->l_dbuf = db; |
458 |
l->l_phys = NULL; |
|
459 |
||
460 |
winner = dmu_buf_set_user(db, l, &l->l_phys, zap_leaf_pageout); |
|
461 |
||
462 |
rw_exit(&l->l_rwlock); |
|
463 |
if (winner != NULL) { |
|
464 |
/* someone else set it first */ |
|
465 |
zap_leaf_pageout(NULL, l); |
|
466 |
l = winner; |
|
467 |
} |
|
468 |
||
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
469 |
/* |
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
470 |
* lhr_pad was previously used for the next leaf in the leaf |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
471 |
* chain. There should be no chained leafs (as we have removed |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
472 |
* support for them). |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
473 |
*/ |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
474 |
ASSERT3U(l->l_phys->l_hdr.lh_pad1, ==, 0); |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
475 |
|
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
476 |
/* |
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
477 |
* There should be more hash entries than there can be |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
478 |
* chunks to put in the hash table |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
479 |
*/ |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
480 |
ASSERT3U(ZAP_LEAF_HASH_NUMENTRIES(l), >, ZAP_LEAF_NUMCHUNKS(l) / 3); |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
481 |
|
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
482 |
/* The chunks should begin at the end of the hash table */ |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
483 |
ASSERT3P(&ZAP_LEAF_CHUNK(l, 0), ==, |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
484 |
&l->l_phys->l_hash[ZAP_LEAF_HASH_NUMENTRIES(l)]); |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
485 |
|
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
486 |
/* The chunks should end at the end of the block */ |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
487 |
ASSERT3U((uintptr_t)&ZAP_LEAF_CHUNK(l, ZAP_LEAF_NUMCHUNKS(l)) - |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
488 |
(uintptr_t)l->l_phys, ==, l->l_dbuf->db_size); |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
489 |
|
789 | 490 |
return (l); |
491 |
} |
|
492 |
||
1544 | 493 |
static int |
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
494 |
zap_get_leaf_byblk(zap_t *zap, uint64_t blkid, dmu_tx_t *tx, krw_t lt, |
1544 | 495 |
zap_leaf_t **lp) |
789 | 496 |
{ |
497 |
dmu_buf_t *db; |
|
498 |
zap_leaf_t *l; |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
499 |
int bs = FZAP_BLOCK_SHIFT(zap); |
1544 | 500 |
int err; |
789 | 501 |
|
502 |
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock)); |
|
503 |
||
1544 | 504 |
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, |
505 |
blkid << bs, NULL, &db); |
|
506 |
if (err) |
|
507 |
return (err); |
|
789 | 508 |
|
509 |
ASSERT3U(db->db_object, ==, zap->zap_object); |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
510 |
ASSERT3U(db->db_offset, ==, blkid << bs); |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
511 |
ASSERT3U(db->db_size, ==, 1 << bs); |
789 | 512 |
ASSERT(blkid != 0); |
513 |
||
514 |
l = dmu_buf_get_user(db); |
|
515 |
||
516 |
if (l == NULL) |
|
517 |
l = zap_open_leaf(blkid, db); |
|
518 |
||
519 |
rw_enter(&l->l_rwlock, lt); |
|
520 |
/* |
|
521 |
* Must lock before dirtying, otherwise l->l_phys could change, |
|
522 |
* causing ASSERT below to fail. |
|
523 |
*/ |
|
524 |
if (lt == RW_WRITER) |
|
525 |
dmu_buf_will_dirty(db, tx); |
|
526 |
ASSERT3U(l->l_blkid, ==, blkid); |
|
527 |
ASSERT3P(l->l_dbuf, ==, db); |
|
528 |
ASSERT3P(l->l_phys, ==, l->l_dbuf->db_data); |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
529 |
ASSERT3U(l->l_phys->l_hdr.lh_block_type, ==, ZBT_LEAF); |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
530 |
ASSERT3U(l->l_phys->l_hdr.lh_magic, ==, ZAP_LEAF_MAGIC); |
789 | 531 |
|
1544 | 532 |
*lp = l; |
533 |
return (0); |
|
789 | 534 |
} |
535 |
||
1544 | 536 |
static int |
537 |
zap_idx_to_blk(zap_t *zap, uint64_t idx, uint64_t *valp) |
|
789 | 538 |
{ |
539 |
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock)); |
|
540 |
||
541 |
if (zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks == 0) { |
|
542 |
ASSERT3U(idx, <, |
|
543 |
(1ULL << zap->zap_f.zap_phys->zap_ptrtbl.zt_shift)); |
|
1544 | 544 |
*valp = ZAP_EMBEDDED_PTRTBL_ENT(zap, idx); |
545 |
return (0); |
|
789 | 546 |
} else { |
547 |
return (zap_table_load(zap, &zap->zap_f.zap_phys->zap_ptrtbl, |
|
1544 | 548 |
idx, valp)); |
789 | 549 |
} |
550 |
} |
|
551 |
||
1544 | 552 |
static int |
789 | 553 |
zap_set_idx_to_blk(zap_t *zap, uint64_t idx, uint64_t blk, dmu_tx_t *tx) |
554 |
{ |
|
555 |
ASSERT(tx != NULL); |
|
556 |
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); |
|
557 |
||
558 |
if (zap->zap_f.zap_phys->zap_ptrtbl.zt_blk == 0) { |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
559 |
ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) = blk; |
1544 | 560 |
return (0); |
789 | 561 |
} else { |
1544 | 562 |
return (zap_table_store(zap, &zap->zap_f.zap_phys->zap_ptrtbl, |
563 |
idx, blk, tx)); |
|
789 | 564 |
} |
565 |
} |
|
566 |
||
1544 | 567 |
static int |
568 |
zap_deref_leaf(zap_t *zap, uint64_t h, dmu_tx_t *tx, krw_t lt, zap_leaf_t **lp) |
|
789 | 569 |
{ |
1544 | 570 |
uint64_t idx, blk; |
571 |
int err; |
|
789 | 572 |
|
573 |
ASSERT(zap->zap_dbuf == NULL || |
|
574 |
zap->zap_f.zap_phys == zap->zap_dbuf->db_data); |
|
575 |
ASSERT3U(zap->zap_f.zap_phys->zap_magic, ==, ZAP_MAGIC); |
|
576 |
idx = ZAP_HASH_IDX(h, zap->zap_f.zap_phys->zap_ptrtbl.zt_shift); |
|
1544 | 577 |
err = zap_idx_to_blk(zap, idx, &blk); |
578 |
if (err != 0) |
|
579 |
return (err); |
|
580 |
err = zap_get_leaf_byblk(zap, blk, tx, lt, lp); |
|
789 | 581 |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
582 |
ASSERT(err || ZAP_HASH_IDX(h, (*lp)->l_phys->l_hdr.lh_prefix_len) == |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
583 |
(*lp)->l_phys->l_hdr.lh_prefix); |
1544 | 584 |
return (err); |
789 | 585 |
} |
586 |
||
1544 | 587 |
static int |
5497 | 588 |
zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx, zap_leaf_t **lp) |
789 | 589 |
{ |
5497 | 590 |
zap_t *zap = zn->zn_zap; |
591 |
uint64_t hash = zn->zn_hash; |
|
789 | 592 |
zap_leaf_t *nl; |
593 |
int prefix_diff, i, err; |
|
594 |
uint64_t sibling; |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
595 |
int old_prefix_len = l->l_phys->l_hdr.lh_prefix_len; |
789 | 596 |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
597 |
ASSERT3U(old_prefix_len, <=, zap->zap_f.zap_phys->zap_ptrtbl.zt_shift); |
789 | 598 |
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock)); |
599 |
||
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
600 |
ASSERT3U(ZAP_HASH_IDX(hash, old_prefix_len), ==, |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
601 |
l->l_phys->l_hdr.lh_prefix); |
789 | 602 |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
603 |
if (zap_tryupgradedir(zap, tx) == 0 || |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
604 |
old_prefix_len == zap->zap_f.zap_phys->zap_ptrtbl.zt_shift) { |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
605 |
/* We failed to upgrade, or need to grow the pointer table */ |
789 | 606 |
objset_t *os = zap->zap_objset; |
607 |
uint64_t object = zap->zap_object; |
|
608 |
||
609 |
zap_put_leaf(l); |
|
610 |
zap_unlockdir(zap); |
|
5384
8eba72d775e9
6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents:
5331
diff
changeset
|
611 |
err = zap_lockdir(os, object, tx, RW_WRITER, |
5497 | 612 |
FALSE, FALSE, &zn->zn_zap); |
613 |
zap = zn->zn_zap; |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
614 |
if (err) |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
615 |
return (err); |
789 | 616 |
ASSERT(!zap->zap_ismicro); |
617 |
||
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
618 |
while (old_prefix_len == |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
619 |
zap->zap_f.zap_phys->zap_ptrtbl.zt_shift) { |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
620 |
err = zap_grow_ptrtbl(zap, tx); |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
621 |
if (err) |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
622 |
return (err); |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
623 |
} |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
624 |
|
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
625 |
err = zap_deref_leaf(zap, hash, tx, RW_WRITER, &l); |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
626 |
if (err) |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
627 |
return (err); |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
628 |
|
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
629 |
if (l->l_phys->l_hdr.lh_prefix_len != old_prefix_len) { |
789 | 630 |
/* it split while our locks were down */ |
1544 | 631 |
*lp = l; |
632 |
return (0); |
|
633 |
} |
|
789 | 634 |
} |
635 |
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
636 |
ASSERT3U(old_prefix_len, <, zap->zap_f.zap_phys->zap_ptrtbl.zt_shift); |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
637 |
ASSERT3U(ZAP_HASH_IDX(hash, old_prefix_len), ==, |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
638 |
l->l_phys->l_hdr.lh_prefix); |
789 | 639 |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
640 |
prefix_diff = zap->zap_f.zap_phys->zap_ptrtbl.zt_shift - |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
641 |
(old_prefix_len + 1); |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
642 |
sibling = (ZAP_HASH_IDX(hash, old_prefix_len + 1) | 1) << prefix_diff; |
1544 | 643 |
|
644 |
/* check for i/o errors before doing zap_leaf_split */ |
|
789 | 645 |
for (i = 0; i < (1ULL<<prefix_diff); i++) { |
1544 | 646 |
uint64_t blk; |
647 |
err = zap_idx_to_blk(zap, sibling+i, &blk); |
|
648 |
if (err) |
|
649 |
return (err); |
|
650 |
ASSERT3U(blk, ==, l->l_blkid); |
|
651 |
} |
|
652 |
||
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
653 |
nl = zap_create_leaf(zap, tx); |
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5497
diff
changeset
|
654 |
zap_leaf_split(l, nl, zap->zap_normflags != 0); |
1544 | 655 |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
656 |
/* set sibling pointers */ |
1544 | 657 |
for (i = 0; i < (1ULL<<prefix_diff); i++) { |
658 |
err = zap_set_idx_to_blk(zap, sibling+i, nl->l_blkid, tx); |
|
659 |
ASSERT3U(err, ==, 0); /* we checked for i/o errors above */ |
|
789 | 660 |
} |
661 |
||
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
662 |
if (hash & (1ULL << (64 - l->l_phys->l_hdr.lh_prefix_len))) { |
789 | 663 |
/* we want the sibling */ |
664 |
zap_put_leaf(l); |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
665 |
*lp = nl; |
789 | 666 |
} else { |
667 |
zap_put_leaf(nl); |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
668 |
*lp = l; |
789 | 669 |
} |
670 |
||
1544 | 671 |
return (0); |
789 | 672 |
} |
673 |
||
674 |
static void |
|
5497 | 675 |
zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx) |
789 | 676 |
{ |
5497 | 677 |
zap_t *zap = zn->zn_zap; |
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
678 |
int shift = zap->zap_f.zap_phys->zap_ptrtbl.zt_shift; |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
679 |
int leaffull = (l->l_phys->l_hdr.lh_prefix_len == shift && |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
680 |
l->l_phys->l_hdr.lh_nfree < ZAP_LEAF_LOW_WATER); |
789 | 681 |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
682 |
zap_put_leaf(l); |
789 | 683 |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
684 |
if (leaffull || zap->zap_f.zap_phys->zap_ptrtbl.zt_nextblk) { |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
685 |
int err; |
789 | 686 |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
687 |
/* |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
688 |
* We are in the middle of growing the pointer table, or |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
689 |
* this leaf will soon make us grow it. |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
690 |
*/ |
789 | 691 |
if (zap_tryupgradedir(zap, tx) == 0) { |
692 |
objset_t *os = zap->zap_objset; |
|
693 |
uint64_t zapobj = zap->zap_object; |
|
694 |
||
695 |
zap_unlockdir(zap); |
|
696 |
err = zap_lockdir(os, zapobj, tx, |
|
5497 | 697 |
RW_WRITER, FALSE, FALSE, &zn->zn_zap); |
698 |
zap = zn->zn_zap; |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
699 |
if (err) |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
700 |
return; |
789 | 701 |
} |
702 |
||
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
703 |
/* could have finished growing while our locks were down */ |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
704 |
if (zap->zap_f.zap_phys->zap_ptrtbl.zt_shift == shift) |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
705 |
(void) zap_grow_ptrtbl(zap, tx); |
789 | 706 |
} |
707 |
} |
|
708 |
||
709 |
||
710 |
static int |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
711 |
fzap_checksize(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers) |
789 | 712 |
{ |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
713 |
if (zn->zn_key_orig_len > ZAP_MAXNAMELEN) |
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
714 |
return (E2BIG); |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
715 |
|
789 | 716 |
/* Only integer sizes supported by C */ |
717 |
switch (integer_size) { |
|
718 |
case 1: |
|
719 |
case 2: |
|
720 |
case 4: |
|
721 |
case 8: |
|
722 |
break; |
|
723 |
default: |
|
724 |
return (EINVAL); |
|
725 |
} |
|
726 |
||
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
727 |
if (integer_size * num_integers > ZAP_MAXVALUELEN) |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
728 |
return (E2BIG); |
789 | 729 |
|
730 |
return (0); |
|
731 |
} |
|
732 |
||
733 |
/* |
|
5331 | 734 |
* Routines for manipulating attributes. |
789 | 735 |
*/ |
736 |
int |
|
5331 | 737 |
fzap_lookup(zap_name_t *zn, |
738 |
uint64_t integer_size, uint64_t num_integers, void *buf, |
|
739 |
char *realname, int rn_len, boolean_t *ncp) |
|
789 | 740 |
{ |
741 |
zap_leaf_t *l; |
|
742 |
int err; |
|
743 |
zap_entry_handle_t zeh; |
|
744 |
||
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
745 |
err = fzap_checksize(zn, integer_size, num_integers); |
789 | 746 |
if (err != 0) |
747 |
return (err); |
|
748 |
||
5331 | 749 |
err = zap_deref_leaf(zn->zn_zap, zn->zn_hash, NULL, RW_READER, &l); |
1544 | 750 |
if (err != 0) |
751 |
return (err); |
|
5331 | 752 |
err = zap_leaf_lookup(l, zn, &zeh); |
753 |
if (err == 0) { |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
754 |
err = zap_entry_read(&zeh, integer_size, num_integers, buf); |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
755 |
(void) zap_entry_read_name(zn->zn_zap, &zeh, rn_len, realname); |
5331 | 756 |
if (ncp) { |
757 |
*ncp = zap_entry_normalization_conflict(&zeh, |
|
758 |
zn, NULL, zn->zn_zap); |
|
759 |
} |
|
760 |
} |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
761 |
|
789 | 762 |
zap_put_leaf(l); |
763 |
return (err); |
|
764 |
} |
|
765 |
||
766 |
int |
|
5331 | 767 |
fzap_add_cd(zap_name_t *zn, |
789 | 768 |
uint64_t integer_size, uint64_t num_integers, |
1544 | 769 |
const void *val, uint32_t cd, dmu_tx_t *tx) |
789 | 770 |
{ |
771 |
zap_leaf_t *l; |
|
772 |
int err; |
|
773 |
zap_entry_handle_t zeh; |
|
5331 | 774 |
zap_t *zap = zn->zn_zap; |
789 | 775 |
|
776 |
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock)); |
|
777 |
ASSERT(!zap->zap_ismicro); |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
778 |
ASSERT(fzap_checksize(zn, integer_size, num_integers) == 0); |
789 | 779 |
|
5331 | 780 |
err = zap_deref_leaf(zap, zn->zn_hash, tx, RW_WRITER, &l); |
1544 | 781 |
if (err != 0) |
782 |
return (err); |
|
789 | 783 |
retry: |
5331 | 784 |
err = zap_leaf_lookup(l, zn, &zeh); |
789 | 785 |
if (err == 0) { |
786 |
err = EEXIST; |
|
787 |
goto out; |
|
788 |
} |
|
1544 | 789 |
if (err != ENOENT) |
790 |
goto out; |
|
789 | 791 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
792 |
err = zap_entry_create(l, zn, cd, |
789 | 793 |
integer_size, num_integers, val, &zeh); |
794 |
||
795 |
if (err == 0) { |
|
796 |
zap_increment_num_entries(zap, 1, tx); |
|
797 |
} else if (err == EAGAIN) { |
|
5497 | 798 |
err = zap_expand_leaf(zn, l, tx, &l); |
799 |
zap = zn->zn_zap; /* zap_expand_leaf() may change zap */ |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
800 |
if (err == 0) |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
801 |
goto retry; |
789 | 802 |
} |
803 |
||
804 |
out: |
|
5497 | 805 |
if (zap != NULL) |
806 |
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tx); |
|
789 | 807 |
return (err); |
808 |
} |
|
809 |
||
810 |
int |
|
5331 | 811 |
fzap_add(zap_name_t *zn, |
789 | 812 |
uint64_t integer_size, uint64_t num_integers, |
813 |
const void *val, dmu_tx_t *tx) |
|
814 |
{ |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
815 |
int err = fzap_checksize(zn, integer_size, num_integers); |
789 | 816 |
if (err != 0) |
817 |
return (err); |
|
818 |
||
5331 | 819 |
return (fzap_add_cd(zn, integer_size, num_integers, |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
820 |
val, ZAP_NEED_CD, tx)); |
789 | 821 |
} |
822 |
||
823 |
int |
|
5331 | 824 |
fzap_update(zap_name_t *zn, |
789 | 825 |
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx) |
826 |
{ |
|
827 |
zap_leaf_t *l; |
|
828 |
int err, create; |
|
829 |
zap_entry_handle_t zeh; |
|
5331 | 830 |
zap_t *zap = zn->zn_zap; |
789 | 831 |
|
832 |
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock)); |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
833 |
err = fzap_checksize(zn, integer_size, num_integers); |
789 | 834 |
if (err != 0) |
835 |
return (err); |
|
836 |
||
5331 | 837 |
err = zap_deref_leaf(zap, zn->zn_hash, tx, RW_WRITER, &l); |
1544 | 838 |
if (err != 0) |
839 |
return (err); |
|
789 | 840 |
retry: |
5331 | 841 |
err = zap_leaf_lookup(l, zn, &zeh); |
789 | 842 |
create = (err == ENOENT); |
843 |
ASSERT(err == 0 || err == ENOENT); |
|
844 |
||
845 |
if (create) { |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
846 |
err = zap_entry_create(l, zn, ZAP_NEED_CD, |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
847 |
integer_size, num_integers, val, &zeh); |
789 | 848 |
if (err == 0) |
849 |
zap_increment_num_entries(zap, 1, tx); |
|
850 |
} else { |
|
851 |
err = zap_entry_update(&zeh, integer_size, num_integers, val); |
|
852 |
} |
|
853 |
||
854 |
if (err == EAGAIN) { |
|
5497 | 855 |
err = zap_expand_leaf(zn, l, tx, &l); |
856 |
zap = zn->zn_zap; /* zap_expand_leaf() may change zap */ |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
857 |
if (err == 0) |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
858 |
goto retry; |
789 | 859 |
} |
860 |
||
5497 | 861 |
if (zap != NULL) |
862 |
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tx); |
|
789 | 863 |
return (err); |
864 |
} |
|
865 |
||
866 |
int |
|
5331 | 867 |
fzap_length(zap_name_t *zn, |
789 | 868 |
uint64_t *integer_size, uint64_t *num_integers) |
869 |
{ |
|
870 |
zap_leaf_t *l; |
|
871 |
int err; |
|
872 |
zap_entry_handle_t zeh; |
|
873 |
||
5331 | 874 |
err = zap_deref_leaf(zn->zn_zap, zn->zn_hash, NULL, RW_READER, &l); |
1544 | 875 |
if (err != 0) |
876 |
return (err); |
|
5331 | 877 |
err = zap_leaf_lookup(l, zn, &zeh); |
789 | 878 |
if (err != 0) |
879 |
goto out; |
|
880 |
||
881 |
if (integer_size) |
|
882 |
*integer_size = zeh.zeh_integer_size; |
|
883 |
if (num_integers) |
|
884 |
*num_integers = zeh.zeh_num_integers; |
|
885 |
out: |
|
886 |
zap_put_leaf(l); |
|
887 |
return (err); |
|
888 |
} |
|
889 |
||
890 |
int |
|
5331 | 891 |
fzap_remove(zap_name_t *zn, dmu_tx_t *tx) |
789 | 892 |
{ |
893 |
zap_leaf_t *l; |
|
894 |
int err; |
|
895 |
zap_entry_handle_t zeh; |
|
896 |
||
5331 | 897 |
err = zap_deref_leaf(zn->zn_zap, zn->zn_hash, tx, RW_WRITER, &l); |
1544 | 898 |
if (err != 0) |
899 |
return (err); |
|
5331 | 900 |
err = zap_leaf_lookup(l, zn, &zeh); |
789 | 901 |
if (err == 0) { |
902 |
zap_entry_remove(&zeh); |
|
5331 | 903 |
zap_increment_num_entries(zn->zn_zap, -1, tx); |
789 | 904 |
} |
905 |
zap_put_leaf(l); |
|
906 |
return (err); |
|
907 |
} |
|
908 |
||
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
909 |
/* |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
910 |
* Helper functions for consumers. |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
911 |
*/ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
912 |
|
789 | 913 |
int |
4577 | 914 |
zap_value_search(objset_t *os, uint64_t zapobj, uint64_t value, uint64_t mask, |
915 |
char *name) |
|
789 | 916 |
{ |
917 |
zap_cursor_t zc; |
|
918 |
zap_attribute_t *za; |
|
919 |
int err; |
|
920 |
||
4577 | 921 |
if (mask == 0) |
922 |
mask = -1ULL; |
|
923 |
||
789 | 924 |
za = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP); |
925 |
for (zap_cursor_init(&zc, os, zapobj); |
|
926 |
(err = zap_cursor_retrieve(&zc, za)) == 0; |
|
927 |
zap_cursor_advance(&zc)) { |
|
4577 | 928 |
if ((za->za_first_integer & mask) == (value & mask)) { |
789 | 929 |
(void) strcpy(name, za->za_name); |
930 |
break; |
|
931 |
} |
|
932 |
} |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
933 |
zap_cursor_fini(&zc); |
789 | 934 |
kmem_free(za, sizeof (zap_attribute_t)); |
935 |
return (err); |
|
936 |
} |
|
937 |
||
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
938 |
int |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
939 |
zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
940 |
{ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
941 |
zap_cursor_t zc; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
942 |
zap_attribute_t za; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
943 |
int err; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
944 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
945 |
for (zap_cursor_init(&zc, os, fromobj); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
946 |
zap_cursor_retrieve(&zc, &za) == 0; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
947 |
(void) zap_cursor_advance(&zc)) { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
948 |
if (za.za_integer_length != 8 || za.za_num_integers != 1) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
949 |
return (EINVAL); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
950 |
err = zap_add(os, intoobj, za.za_name, |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
951 |
8, 1, &za.za_first_integer, tx); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
952 |
if (err) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
953 |
return (err); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
954 |
} |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
955 |
zap_cursor_fini(&zc); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
956 |
return (0); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
957 |
} |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
958 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
959 |
int |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
960 |
zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
961 |
{ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
962 |
char name[20]; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
963 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
964 |
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)value); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
965 |
return (zap_add(os, obj, name, 8, 1, &value, tx)); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
966 |
} |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
967 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
968 |
int |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
969 |
zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
970 |
{ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
971 |
char name[20]; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
972 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
973 |
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)value); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
974 |
return (zap_remove(os, obj, name, tx)); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
975 |
} |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
976 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
977 |
int |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
978 |
zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
979 |
{ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
980 |
char name[20]; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
981 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
982 |
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)value); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
983 |
return (zap_lookup(os, obj, name, 8, 1, &value)); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
5498
diff
changeset
|
984 |
} |
789 | 985 |
|
10407
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
986 |
int |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
987 |
zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta, |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
988 |
dmu_tx_t *tx) |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
989 |
{ |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
990 |
char name[20]; |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
991 |
uint64_t value = 0; |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
992 |
int err; |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
993 |
|
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
994 |
if (delta == 0) |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
995 |
return (0); |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
996 |
|
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
997 |
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)key); |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
998 |
err = zap_lookup(os, obj, name, 8, 1, &value); |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
999 |
if (err != 0 && err != ENOENT) |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
1000 |
return (err); |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
1001 |
value += delta; |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
1002 |
if (value == 0) |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
1003 |
err = zap_remove(os, obj, name, tx); |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
1004 |
else |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
1005 |
err = zap_update(os, obj, name, 8, 1, &value, tx); |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
1006 |
return (err); |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
1007 |
} |
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
1008 |
|
34e10c4af053
6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9653
diff
changeset
|
1009 |
|
789 | 1010 |
/* |
1011 |
* Routines for iterating over the attributes. |
|
1012 |
*/ |
|
1013 |
||
1014 |
int |
|
1015 |
fzap_cursor_retrieve(zap_t *zap, zap_cursor_t *zc, zap_attribute_t *za) |
|
1016 |
{ |
|
1017 |
int err = ENOENT; |
|
1018 |
zap_entry_handle_t zeh; |
|
1019 |
zap_leaf_t *l; |
|
1020 |
||
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
1021 |
/* memset(za, 0xba, sizeof (zap_attribute_t)); */ |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
1022 |
|
789 | 1023 |
/* retrieve the next entry at or after zc_hash/zc_cd */ |
1024 |
/* if no entry, return ENOENT */ |
|
1025 |
||
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1026 |
if (zc->zc_leaf && |
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
1027 |
(ZAP_HASH_IDX(zc->zc_hash, |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
1028 |
zc->zc_leaf->l_phys->l_hdr.lh_prefix_len) != |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
1029 |
zc->zc_leaf->l_phys->l_hdr.lh_prefix)) { |
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1030 |
rw_enter(&zc->zc_leaf->l_rwlock, RW_READER); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1031 |
zap_put_leaf(zc->zc_leaf); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1032 |
zc->zc_leaf = NULL; |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1033 |
} |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1034 |
|
789 | 1035 |
again: |
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1036 |
if (zc->zc_leaf == NULL) { |
1544 | 1037 |
err = zap_deref_leaf(zap, zc->zc_hash, NULL, RW_READER, |
1038 |
&zc->zc_leaf); |
|
1039 |
if (err != 0) |
|
1040 |
return (err); |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1041 |
} else { |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1042 |
rw_enter(&zc->zc_leaf->l_rwlock, RW_READER); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1043 |
} |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1044 |
l = zc->zc_leaf; |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1045 |
|
789 | 1046 |
err = zap_leaf_lookup_closest(l, zc->zc_hash, zc->zc_cd, &zeh); |
1047 |
||
1048 |
if (err == ENOENT) { |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
1049 |
uint64_t nocare = |
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
1050 |
(1ULL << (64 - l->l_phys->l_hdr.lh_prefix_len)) - 1; |
789 | 1051 |
zc->zc_hash = (zc->zc_hash & ~nocare) + nocare + 1; |
1052 |
zc->zc_cd = 0; |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
1053 |
if (l->l_phys->l_hdr.lh_prefix_len == 0 || zc->zc_hash == 0) { |
789 | 1054 |
zc->zc_hash = -1ULL; |
1055 |
} else { |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1056 |
zap_put_leaf(zc->zc_leaf); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1057 |
zc->zc_leaf = NULL; |
789 | 1058 |
goto again; |
1059 |
} |
|
1060 |
} |
|
1061 |
||
1062 |
if (err == 0) { |
|
1063 |
zc->zc_hash = zeh.zeh_hash; |
|
1064 |
zc->zc_cd = zeh.zeh_cd; |
|
1065 |
za->za_integer_length = zeh.zeh_integer_size; |
|
1066 |
za->za_num_integers = zeh.zeh_num_integers; |
|
1067 |
if (zeh.zeh_num_integers == 0) { |
|
1068 |
za->za_first_integer = 0; |
|
1069 |
} else { |
|
1070 |
err = zap_entry_read(&zeh, 8, 1, &za->za_first_integer); |
|
1071 |
ASSERT(err == 0 || err == EOVERFLOW); |
|
1072 |
} |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
1073 |
err = zap_entry_read_name(zap, &zeh, |
789 | 1074 |
sizeof (za->za_name), za->za_name); |
1075 |
ASSERT(err == 0); |
|
5331 | 1076 |
|
1077 |
za->za_normalization_conflict = |
|
1078 |
zap_entry_normalization_conflict(&zeh, |
|
1079 |
NULL, za->za_name, zap); |
|
789 | 1080 |
} |
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1081 |
rw_exit(&zc->zc_leaf->l_rwlock); |
789 | 1082 |
return (err); |
1083 |
} |
|
1084 |
||
1085 |
||
1086 |
static void |
|
1087 |
zap_stats_ptrtbl(zap_t *zap, uint64_t *tbl, int len, zap_stats_t *zs) |
|
1088 |
{ |
|
1544 | 1089 |
int i, err; |
789 | 1090 |
uint64_t lastblk = 0; |
1091 |
||
1092 |
/* |
|
1093 |
* NB: if a leaf has more pointers than an entire ptrtbl block |
|
1094 |
* can hold, then it'll be accounted for more than once, since |
|
1095 |
* we won't have lastblk. |
|
1096 |
*/ |
|
1097 |
for (i = 0; i < len; i++) { |
|
1098 |
zap_leaf_t *l; |
|
1099 |
||
1100 |
if (tbl[i] == lastblk) |
|
1101 |
continue; |
|
1102 |
lastblk = tbl[i]; |
|
1103 |
||
1544 | 1104 |
err = zap_get_leaf_byblk(zap, tbl[i], NULL, RW_READER, &l); |
1105 |
if (err == 0) { |
|
1578
1fd8ab638fc0
6389897 remove zap leaf chaining code as it is never used
ahrens
parents:
1544
diff
changeset
|
1106 |
zap_leaf_stats(zap, l, zs); |
1544 | 1107 |
zap_put_leaf(l); |
1108 |
} |
|
789 | 1109 |
} |
1110 |
} |
|
1111 |
||
10612
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1112 |
int |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1113 |
fzap_cursor_move_to_key(zap_cursor_t *zc, zap_name_t *zn) |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1114 |
{ |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1115 |
int err; |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1116 |
zap_leaf_t *l; |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1117 |
zap_entry_handle_t zeh; |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1118 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
1119 |
if (zn->zn_key_orig_len > ZAP_MAXNAMELEN) |
10612
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1120 |
return (E2BIG); |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1121 |
|
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1122 |
err = zap_deref_leaf(zc->zc_zap, zn->zn_hash, NULL, RW_READER, &l); |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1123 |
if (err != 0) |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1124 |
return (err); |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1125 |
|
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1126 |
err = zap_leaf_lookup(l, zn, &zeh); |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1127 |
if (err != 0) |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1128 |
return (err); |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1129 |
|
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1130 |
zc->zc_leaf = l; |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1131 |
zc->zc_hash = zeh.zeh_hash; |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1132 |
zc->zc_cd = zeh.zeh_cd; |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1133 |
|
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1134 |
return (err); |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1135 |
} |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10431
diff
changeset
|
1136 |
|
789 | 1137 |
void |
1138 |
fzap_get_stats(zap_t *zap, zap_stats_t *zs) |
|
1139 |
{ |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
1140 |
int bs = FZAP_BLOCK_SHIFT(zap); |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
1141 |
zs->zs_blocksize = 1ULL << bs; |
1632
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1142 |
|
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1143 |
/* |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1144 |
* Set zap_phys_t fields |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1145 |
*/ |
789 | 1146 |
zs->zs_num_leafs = zap->zap_f.zap_phys->zap_num_leafs; |
1147 |
zs->zs_num_entries = zap->zap_f.zap_phys->zap_num_entries; |
|
1148 |
zs->zs_num_blocks = zap->zap_f.zap_phys->zap_freeblk; |
|
1632
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1149 |
zs->zs_block_type = zap->zap_f.zap_phys->zap_block_type; |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1150 |
zs->zs_magic = zap->zap_f.zap_phys->zap_magic; |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1151 |
zs->zs_salt = zap->zap_f.zap_phys->zap_salt; |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1152 |
|
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1153 |
/* |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1154 |
* Set zap_ptrtbl fields |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1155 |
*/ |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1156 |
zs->zs_ptrtbl_len = 1ULL << zap->zap_f.zap_phys->zap_ptrtbl.zt_shift; |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1157 |
zs->zs_ptrtbl_nextblk = zap->zap_f.zap_phys->zap_ptrtbl.zt_nextblk; |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1158 |
zs->zs_ptrtbl_blks_copied = |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1159 |
zap->zap_f.zap_phys->zap_ptrtbl.zt_blks_copied; |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1160 |
zs->zs_ptrtbl_zt_blk = zap->zap_f.zap_phys->zap_ptrtbl.zt_blk; |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1161 |
zs->zs_ptrtbl_zt_numblks = zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks; |
7d486ebd46b7
6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents:
1578
diff
changeset
|
1162 |
zs->zs_ptrtbl_zt_shift = zap->zap_f.zap_phys->zap_ptrtbl.zt_shift; |
789 | 1163 |
|
1164 |
if (zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks == 0) { |
|
1165 |
/* the ptrtbl is entirely in the header block. */ |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
1166 |
zap_stats_ptrtbl(zap, &ZAP_EMBEDDED_PTRTBL_ENT(zap, 0), |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
1167 |
1 << ZAP_EMBEDDED_PTRTBL_SHIFT(zap), zs); |
789 | 1168 |
} else { |
1169 |
int b; |
|
1170 |
||
1171 |
dmu_prefetch(zap->zap_objset, zap->zap_object, |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
1172 |
zap->zap_f.zap_phys->zap_ptrtbl.zt_blk << bs, |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
1173 |
zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks << bs); |
789 | 1174 |
|
1175 |
for (b = 0; b < zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks; |
|
1176 |
b++) { |
|
1177 |
dmu_buf_t *db; |
|
1544 | 1178 |
int err; |
789 | 1179 |
|
1544 | 1180 |
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, |
1181 |
(zap->zap_f.zap_phys->zap_ptrtbl.zt_blk + b) << bs, |
|
1182 |
FTAG, &db); |
|
1183 |
if (err == 0) { |
|
1184 |
zap_stats_ptrtbl(zap, db->db_data, |
|
1185 |
1<<(bs-3), zs); |
|
1186 |
dmu_buf_rele(db, FTAG); |
|
1187 |
} |
|
789 | 1188 |
} |
1189 |
} |
|
1190 |
} |
|
9653
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1191 |
|
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1192 |
int |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1193 |
fzap_count_write(zap_name_t *zn, int add, uint64_t *towrite, |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1194 |
uint64_t *tooverwrite) |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1195 |
{ |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1196 |
zap_t *zap = zn->zn_zap; |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1197 |
zap_leaf_t *l; |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1198 |
int err; |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1199 |
|
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1200 |
/* |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1201 |
* Account for the header block of the fatzap. |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1202 |
*/ |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1203 |
if (!add && dmu_buf_freeable(zap->zap_dbuf)) { |
10431
a4572ce3df84
6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
10407
diff
changeset
|
1204 |
*tooverwrite += zap->zap_dbuf->db_size; |
9653
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1205 |
} else { |
10431
a4572ce3df84
6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
10407
diff
changeset
|
1206 |
*towrite += zap->zap_dbuf->db_size; |
9653
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1207 |
} |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1208 |
|
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1209 |
/* |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1210 |
* Account for the pointer table blocks. |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1211 |
* If we are adding we need to account for the following cases : |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1212 |
* - If the pointer table is embedded, this operation could force an |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1213 |
* external pointer table. |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1214 |
* - If this already has an external pointer table this operation |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1215 |
* could extend the table. |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1216 |
*/ |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1217 |
if (add) { |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1218 |
if (zap->zap_f.zap_phys->zap_ptrtbl.zt_blk == 0) |
10431
a4572ce3df84
6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
10407
diff
changeset
|
1219 |
*towrite += zap->zap_dbuf->db_size; |
9653
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1220 |
else |
10431
a4572ce3df84
6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
10407
diff
changeset
|
1221 |
*towrite += (zap->zap_dbuf->db_size * 3); |
9653
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1222 |
} |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1223 |
|
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1224 |
/* |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1225 |
* Now, check if the block containing leaf is freeable |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1226 |
* and account accordingly. |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1227 |
*/ |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1228 |
err = zap_deref_leaf(zap, zn->zn_hash, NULL, RW_READER, &l); |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1229 |
if (err != 0) { |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1230 |
return (err); |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1231 |
} |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1232 |
|
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1233 |
if (!add && dmu_buf_freeable(l->l_dbuf)) { |
10431
a4572ce3df84
6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
10407
diff
changeset
|
1234 |
*tooverwrite += l->l_dbuf->db_size; |
9653
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1235 |
} else { |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1236 |
/* |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1237 |
* If this an add operation, the leaf block could split. |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1238 |
* Hence, we need to account for an additional leaf block. |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1239 |
*/ |
10431
a4572ce3df84
6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
10407
diff
changeset
|
1240 |
*towrite += (add ? 2 : 1) * l->l_dbuf->db_size; |
9653
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1241 |
} |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1242 |
|
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1243 |
zap_put_leaf(l); |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1244 |
return (0); |
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9643
diff
changeset
|
1245 |
} |