Mercurial > illumos > illumos-gate
annotate usr/src/uts/common/fs/zfs/dnode.c @ 7754:b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
6667208 zfs/zpool commands on failed pool should not hang
6430480 grabbing config lock as writer during I/O load can take excessively long
author | Jeff Bonwick <Jeff.Bonwick@Sun.COM> |
---|---|
date | Mon, 29 Sep 2008 18:13:58 -0700 |
parents | f69ff8507427 |
children | d7abf7c1f1c1 |
rev | line source |
---|---|
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:
1402
diff
changeset
|
5 * Common Development and Distribution License (the "License"). |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
1402
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 /* | |
6992 | 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
789 | 23 * Use is subject to license terms. |
24 */ | |
25 | |
26 #include <sys/zfs_context.h> | |
27 #include <sys/dbuf.h> | |
28 #include <sys/dnode.h> | |
29 #include <sys/dmu.h> | |
30 #include <sys/dmu_impl.h> | |
31 #include <sys/dmu_tx.h> | |
32 #include <sys/dmu_objset.h> | |
33 #include <sys/dsl_dir.h> | |
34 #include <sys/dsl_dataset.h> | |
35 #include <sys/spa.h> | |
36 #include <sys/zio.h> | |
37 #include <sys/dmu_zfetch.h> | |
38 | |
39 static int free_range_compar(const void *node1, const void *node2); | |
40 | |
41 static kmem_cache_t *dnode_cache; | |
42 | |
43 static dnode_phys_t dnode_phys_zero; | |
44 | |
45 int zfs_default_bs = SPA_MINBLOCKSHIFT; | |
46 int zfs_default_ibs = DN_MAX_INDBLKSHIFT; | |
47 | |
48 /* ARGSUSED */ | |
49 static int | |
50 dnode_cons(void *arg, void *unused, int kmflag) | |
51 { | |
52 int i; | |
53 dnode_t *dn = arg; | |
54 bzero(dn, sizeof (dnode_t)); | |
55 | |
56 rw_init(&dn->dn_struct_rwlock, NULL, RW_DEFAULT, NULL); | |
57 mutex_init(&dn->dn_mtx, NULL, MUTEX_DEFAULT, NULL); | |
58 mutex_init(&dn->dn_dbufs_mtx, NULL, MUTEX_DEFAULT, NULL); | |
59 refcount_create(&dn->dn_holds); | |
60 refcount_create(&dn->dn_tx_holds); | |
61 | |
62 for (i = 0; i < TXG_SIZE; i++) { | |
63 avl_create(&dn->dn_ranges[i], free_range_compar, | |
64 sizeof (free_range_t), | |
65 offsetof(struct free_range, fr_node)); | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
66 list_create(&dn->dn_dirty_records[i], |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
67 sizeof (dbuf_dirty_record_t), |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
68 offsetof(dbuf_dirty_record_t, dr_dirty_node)); |
789 | 69 } |
70 | |
71 list_create(&dn->dn_dbufs, sizeof (dmu_buf_impl_t), | |
72 offsetof(dmu_buf_impl_t, db_link)); | |
73 | |
74 return (0); | |
75 } | |
76 | |
77 /* ARGSUSED */ | |
78 static void | |
79 dnode_dest(void *arg, void *unused) | |
80 { | |
81 int i; | |
82 dnode_t *dn = arg; | |
83 | |
84 rw_destroy(&dn->dn_struct_rwlock); | |
85 mutex_destroy(&dn->dn_mtx); | |
86 mutex_destroy(&dn->dn_dbufs_mtx); | |
87 refcount_destroy(&dn->dn_holds); | |
88 refcount_destroy(&dn->dn_tx_holds); | |
89 | |
90 for (i = 0; i < TXG_SIZE; i++) { | |
91 avl_destroy(&dn->dn_ranges[i]); | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
92 list_destroy(&dn->dn_dirty_records[i]); |
789 | 93 } |
94 | |
95 list_destroy(&dn->dn_dbufs); | |
96 } | |
97 | |
98 void | |
99 dnode_init(void) | |
100 { | |
101 dnode_cache = kmem_cache_create("dnode_t", | |
102 sizeof (dnode_t), | |
103 0, dnode_cons, dnode_dest, NULL, NULL, NULL, 0); | |
104 } | |
105 | |
106 void | |
107 dnode_fini(void) | |
108 { | |
109 kmem_cache_destroy(dnode_cache); | |
110 } | |
111 | |
112 | |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
113 #ifdef ZFS_DEBUG |
789 | 114 void |
115 dnode_verify(dnode_t *dn) | |
116 { | |
117 int drop_struct_lock = FALSE; | |
118 | |
119 ASSERT(dn->dn_phys); | |
120 ASSERT(dn->dn_objset); | |
121 | |
122 ASSERT(dn->dn_phys->dn_type < DMU_OT_NUMTYPES); | |
123 | |
124 if (!(zfs_flags & ZFS_DEBUG_DNODE_VERIFY)) | |
125 return; | |
126 | |
127 if (!RW_WRITE_HELD(&dn->dn_struct_rwlock)) { | |
128 rw_enter(&dn->dn_struct_rwlock, RW_READER); | |
129 drop_struct_lock = TRUE; | |
130 } | |
131 if (dn->dn_phys->dn_type != DMU_OT_NONE || dn->dn_allocated_txg != 0) { | |
132 int i; | |
133 ASSERT3U(dn->dn_indblkshift, >=, 0); | |
134 ASSERT3U(dn->dn_indblkshift, <=, SPA_MAXBLOCKSHIFT); | |
135 if (dn->dn_datablkshift) { | |
136 ASSERT3U(dn->dn_datablkshift, >=, SPA_MINBLOCKSHIFT); | |
137 ASSERT3U(dn->dn_datablkshift, <=, SPA_MAXBLOCKSHIFT); | |
138 ASSERT3U(1<<dn->dn_datablkshift, ==, dn->dn_datablksz); | |
139 } | |
140 ASSERT3U(dn->dn_nlevels, <=, 30); | |
141 ASSERT3U(dn->dn_type, <=, DMU_OT_NUMTYPES); | |
142 ASSERT3U(dn->dn_nblkptr, >=, 1); | |
143 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR); | |
144 ASSERT3U(dn->dn_bonuslen, <=, DN_MAX_BONUSLEN); | |
145 ASSERT3U(dn->dn_datablksz, ==, | |
146 dn->dn_datablkszsec << SPA_MINBLOCKSHIFT); | |
147 ASSERT3U(ISP2(dn->dn_datablksz), ==, dn->dn_datablkshift != 0); | |
148 ASSERT3U((dn->dn_nblkptr - 1) * sizeof (blkptr_t) + | |
149 dn->dn_bonuslen, <=, DN_MAX_BONUSLEN); | |
150 for (i = 0; i < TXG_SIZE; i++) { | |
151 ASSERT3U(dn->dn_next_nlevels[i], <=, dn->dn_nlevels); | |
152 } | |
153 } | |
154 if (dn->dn_phys->dn_type != DMU_OT_NONE) | |
155 ASSERT3U(dn->dn_phys->dn_nlevels, <=, dn->dn_nlevels); | |
1544 | 156 ASSERT(dn->dn_object == DMU_META_DNODE_OBJECT || dn->dn_dbuf != NULL); |
789 | 157 if (dn->dn_dbuf != NULL) { |
158 ASSERT3P(dn->dn_phys, ==, | |
159 (dnode_phys_t *)dn->dn_dbuf->db.db_data + | |
160 (dn->dn_object % (dn->dn_dbuf->db.db_size >> DNODE_SHIFT))); | |
161 } | |
162 if (drop_struct_lock) | |
163 rw_exit(&dn->dn_struct_rwlock); | |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
164 } |
789 | 165 #endif |
166 | |
167 void | |
168 dnode_byteswap(dnode_phys_t *dnp) | |
169 { | |
170 uint64_t *buf64 = (void*)&dnp->dn_blkptr; | |
171 int i; | |
172 | |
173 if (dnp->dn_type == DMU_OT_NONE) { | |
174 bzero(dnp, sizeof (dnode_phys_t)); | |
175 return; | |
176 } | |
177 | |
178 dnp->dn_datablkszsec = BSWAP_16(dnp->dn_datablkszsec); | |
179 dnp->dn_bonuslen = BSWAP_16(dnp->dn_bonuslen); | |
180 dnp->dn_maxblkid = BSWAP_64(dnp->dn_maxblkid); | |
2082 | 181 dnp->dn_used = BSWAP_64(dnp->dn_used); |
789 | 182 |
183 /* | |
184 * dn_nblkptr is only one byte, so it's OK to read it in either | |
185 * byte order. We can't read dn_bouslen. | |
186 */ | |
187 ASSERT(dnp->dn_indblkshift <= SPA_MAXBLOCKSHIFT); | |
188 ASSERT(dnp->dn_nblkptr <= DN_MAX_NBLKPTR); | |
189 for (i = 0; i < dnp->dn_nblkptr * sizeof (blkptr_t)/8; i++) | |
190 buf64[i] = BSWAP_64(buf64[i]); | |
191 | |
192 /* | |
193 * OK to check dn_bonuslen for zero, because it won't matter if | |
194 * we have the wrong byte order. This is necessary because the | |
195 * dnode dnode is smaller than a regular dnode. | |
196 */ | |
197 if (dnp->dn_bonuslen != 0) { | |
198 /* | |
199 * Note that the bonus length calculated here may be | |
200 * longer than the actual bonus buffer. This is because | |
201 * we always put the bonus buffer after the last block | |
202 * pointer (instead of packing it against the end of the | |
203 * dnode buffer). | |
204 */ | |
205 int off = (dnp->dn_nblkptr-1) * sizeof (blkptr_t); | |
206 size_t len = DN_MAX_BONUSLEN - off; | |
3882 | 207 ASSERT3U(dnp->dn_bonustype, <, DMU_OT_NUMTYPES); |
789 | 208 dmu_ot[dnp->dn_bonustype].ot_byteswap(dnp->dn_bonus + off, len); |
209 } | |
210 } | |
211 | |
212 void | |
213 dnode_buf_byteswap(void *vbuf, size_t size) | |
214 { | |
215 dnode_phys_t *buf = vbuf; | |
216 int i; | |
217 | |
218 ASSERT3U(sizeof (dnode_phys_t), ==, (1<<DNODE_SHIFT)); | |
219 ASSERT((size & (sizeof (dnode_phys_t)-1)) == 0); | |
220 | |
221 size >>= DNODE_SHIFT; | |
222 for (i = 0; i < size; i++) { | |
223 dnode_byteswap(buf); | |
224 buf++; | |
225 } | |
226 } | |
227 | |
228 static int | |
229 free_range_compar(const void *node1, const void *node2) | |
230 { | |
231 const free_range_t *rp1 = node1; | |
232 const free_range_t *rp2 = node2; | |
233 | |
234 if (rp1->fr_blkid < rp2->fr_blkid) | |
235 return (-1); | |
236 else if (rp1->fr_blkid > rp2->fr_blkid) | |
237 return (1); | |
238 else return (0); | |
239 } | |
240 | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
241 void |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
242 dnode_setbonuslen(dnode_t *dn, int newsize, dmu_tx_t *tx) |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
243 { |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
244 ASSERT3U(refcount_count(&dn->dn_holds), >=, 1); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
245 |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
246 dnode_setdirty(dn, tx); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
247 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
248 ASSERT3U(newsize, <=, DN_MAX_BONUSLEN - |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
249 (dn->dn_nblkptr-1) * sizeof (blkptr_t)); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
250 dn->dn_bonuslen = newsize; |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
251 if (newsize == 0) |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
252 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = DN_ZERO_BONUSLEN; |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
253 else |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
254 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = dn->dn_bonuslen; |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
255 rw_exit(&dn->dn_struct_rwlock); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
256 } |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
257 |
789 | 258 static void |
259 dnode_setdblksz(dnode_t *dn, int size) | |
260 { | |
261 ASSERT3U(P2PHASE(size, SPA_MINBLOCKSIZE), ==, 0); | |
262 ASSERT3U(size, <=, SPA_MAXBLOCKSIZE); | |
263 ASSERT3U(size, >=, SPA_MINBLOCKSIZE); | |
264 ASSERT3U(size >> SPA_MINBLOCKSHIFT, <, | |
265 1<<(sizeof (dn->dn_phys->dn_datablkszsec) * 8)); | |
266 dn->dn_datablksz = size; | |
267 dn->dn_datablkszsec = size >> SPA_MINBLOCKSHIFT; | |
268 dn->dn_datablkshift = ISP2(size) ? highbit(size - 1) : 0; | |
269 } | |
270 | |
271 static dnode_t * | |
272 dnode_create(objset_impl_t *os, dnode_phys_t *dnp, dmu_buf_impl_t *db, | |
273 uint64_t object) | |
274 { | |
275 dnode_t *dn = kmem_cache_alloc(dnode_cache, KM_SLEEP); | |
276 (void) dnode_cons(dn, NULL, 0); /* XXX */ | |
277 | |
278 dn->dn_objset = os; | |
279 dn->dn_object = object; | |
280 dn->dn_dbuf = db; | |
281 dn->dn_phys = dnp; | |
282 | |
283 if (dnp->dn_datablkszsec) | |
284 dnode_setdblksz(dn, dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT); | |
285 dn->dn_indblkshift = dnp->dn_indblkshift; | |
286 dn->dn_nlevels = dnp->dn_nlevels; | |
287 dn->dn_type = dnp->dn_type; | |
288 dn->dn_nblkptr = dnp->dn_nblkptr; | |
289 dn->dn_checksum = dnp->dn_checksum; | |
290 dn->dn_compress = dnp->dn_compress; | |
291 dn->dn_bonustype = dnp->dn_bonustype; | |
292 dn->dn_bonuslen = dnp->dn_bonuslen; | |
293 dn->dn_maxblkid = dnp->dn_maxblkid; | |
294 | |
295 dmu_zfetch_init(&dn->dn_zfetch, dn); | |
296 | |
297 ASSERT(dn->dn_phys->dn_type < DMU_OT_NUMTYPES); | |
298 mutex_enter(&os->os_lock); | |
299 list_insert_head(&os->os_dnodes, dn); | |
300 mutex_exit(&os->os_lock); | |
301 | |
4309
3dfde0f4662d
6542676 ARC needs to track meta-data memory overhead
maybee
parents:
3882
diff
changeset
|
302 arc_space_consume(sizeof (dnode_t)); |
789 | 303 return (dn); |
304 } | |
305 | |
306 static void | |
307 dnode_destroy(dnode_t *dn) | |
308 { | |
309 objset_impl_t *os = dn->dn_objset; | |
310 | |
2885 | 311 #ifdef ZFS_DEBUG |
312 int i; | |
313 | |
314 for (i = 0; i < TXG_SIZE; i++) { | |
315 ASSERT(!list_link_active(&dn->dn_dirty_link[i])); | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
316 ASSERT(NULL == list_head(&dn->dn_dirty_records[i])); |
2885 | 317 ASSERT(0 == avl_numnodes(&dn->dn_ranges[i])); |
318 } | |
319 ASSERT(NULL == list_head(&dn->dn_dbufs)); | |
320 #endif | |
321 | |
789 | 322 mutex_enter(&os->os_lock); |
323 list_remove(&os->os_dnodes, dn); | |
324 mutex_exit(&os->os_lock); | |
325 | |
326 if (dn->dn_dirtyctx_firstset) { | |
327 kmem_free(dn->dn_dirtyctx_firstset, 1); | |
328 dn->dn_dirtyctx_firstset = NULL; | |
329 } | |
330 dmu_zfetch_rele(&dn->dn_zfetch); | |
1544 | 331 if (dn->dn_bonus) { |
332 mutex_enter(&dn->dn_bonus->db_mtx); | |
333 dbuf_evict(dn->dn_bonus); | |
334 dn->dn_bonus = NULL; | |
335 } | |
789 | 336 kmem_cache_free(dnode_cache, dn); |
4309
3dfde0f4662d
6542676 ARC needs to track meta-data memory overhead
maybee
parents:
3882
diff
changeset
|
337 arc_space_return(sizeof (dnode_t)); |
789 | 338 } |
339 | |
340 void | |
341 dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs, | |
1599 | 342 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx) |
789 | 343 { |
344 int i; | |
345 | |
346 if (blocksize == 0) | |
347 blocksize = 1 << zfs_default_bs; | |
1402 | 348 else if (blocksize > SPA_MAXBLOCKSIZE) |
349 blocksize = SPA_MAXBLOCKSIZE; | |
350 else | |
351 blocksize = P2ROUNDUP(blocksize, SPA_MINBLOCKSIZE); | |
789 | 352 |
353 if (ibs == 0) | |
354 ibs = zfs_default_ibs; | |
355 | |
356 ibs = MIN(MAX(ibs, DN_MIN_INDBLKSHIFT), DN_MAX_INDBLKSHIFT); | |
357 | |
358 dprintf("os=%p obj=%llu txg=%llu blocksize=%d ibs=%d\n", dn->dn_objset, | |
359 dn->dn_object, tx->tx_txg, blocksize, ibs); | |
360 | |
361 ASSERT(dn->dn_type == DMU_OT_NONE); | |
362 ASSERT(bcmp(dn->dn_phys, &dnode_phys_zero, sizeof (dnode_phys_t)) == 0); | |
363 ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE); | |
364 ASSERT(ot != DMU_OT_NONE); | |
365 ASSERT3U(ot, <, DMU_OT_NUMTYPES); | |
366 ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) || | |
367 (bonustype != DMU_OT_NONE && bonuslen != 0)); | |
368 ASSERT3U(bonustype, <, DMU_OT_NUMTYPES); | |
369 ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN); | |
370 ASSERT(dn->dn_type == DMU_OT_NONE); | |
371 ASSERT3U(dn->dn_maxblkid, ==, 0); | |
372 ASSERT3U(dn->dn_allocated_txg, ==, 0); | |
373 ASSERT3U(dn->dn_assigned_txg, ==, 0); | |
374 ASSERT(refcount_is_zero(&dn->dn_tx_holds)); | |
375 ASSERT3U(refcount_count(&dn->dn_holds), <=, 1); | |
376 ASSERT3P(list_head(&dn->dn_dbufs), ==, NULL); | |
377 | |
378 for (i = 0; i < TXG_SIZE; i++) { | |
379 ASSERT3U(dn->dn_next_nlevels[i], ==, 0); | |
380 ASSERT3U(dn->dn_next_indblkshift[i], ==, 0); | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
381 ASSERT3U(dn->dn_next_bonuslen[i], ==, 0); |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
382 ASSERT3U(dn->dn_next_blksz[i], ==, 0); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
383 ASSERT(!list_link_active(&dn->dn_dirty_link[i])); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
384 ASSERT3P(list_head(&dn->dn_dirty_records[i]), ==, NULL); |
789 | 385 ASSERT3U(avl_numnodes(&dn->dn_ranges[i]), ==, 0); |
386 } | |
387 | |
388 dn->dn_type = ot; | |
389 dnode_setdblksz(dn, blocksize); | |
390 dn->dn_indblkshift = ibs; | |
391 dn->dn_nlevels = 1; | |
392 dn->dn_nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT); | |
393 dn->dn_bonustype = bonustype; | |
394 dn->dn_bonuslen = bonuslen; | |
395 dn->dn_checksum = ZIO_CHECKSUM_INHERIT; | |
396 dn->dn_compress = ZIO_COMPRESS_INHERIT; | |
397 dn->dn_dirtyctx = 0; | |
398 | |
399 dn->dn_free_txg = 0; | |
400 if (dn->dn_dirtyctx_firstset) { | |
401 kmem_free(dn->dn_dirtyctx_firstset, 1); | |
402 dn->dn_dirtyctx_firstset = NULL; | |
403 } | |
404 | |
405 dn->dn_allocated_txg = tx->tx_txg; | |
1599 | 406 |
789 | 407 dnode_setdirty(dn, tx); |
1599 | 408 dn->dn_next_indblkshift[tx->tx_txg & TXG_MASK] = ibs; |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
409 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = dn->dn_bonuslen; |
1599 | 410 dn->dn_next_blksz[tx->tx_txg & TXG_MASK] = dn->dn_datablksz; |
789 | 411 } |
412 | |
413 void | |
414 dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, | |
415 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx) | |
416 { | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
417 int i, old_nblkptr; |
3087 | 418 dmu_buf_impl_t *db = NULL; |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
419 |
789 | 420 ASSERT3U(blocksize, >=, SPA_MINBLOCKSIZE); |
421 ASSERT3U(blocksize, <=, SPA_MAXBLOCKSIZE); | |
422 ASSERT3U(blocksize % SPA_MINBLOCKSIZE, ==, 0); | |
1544 | 423 ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT || dmu_tx_private_ok(tx)); |
789 | 424 ASSERT(tx->tx_txg != 0); |
425 ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) || | |
426 (bonustype != DMU_OT_NONE && bonuslen != 0)); | |
427 ASSERT3U(bonustype, <, DMU_OT_NUMTYPES); | |
428 ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN); | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
429 |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
430 for (i = 0; i < TXG_SIZE; i++) |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
431 ASSERT(!list_link_active(&dn->dn_dirty_link[i])); |
789 | 432 |
1544 | 433 /* clean up any unreferenced dbufs */ |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
434 dnode_evict_dbufs(dn); |
1544 | 435 ASSERT3P(list_head(&dn->dn_dbufs), ==, NULL); |
436 | |
789 | 437 /* |
438 * XXX I should really have a generation number to tell if we | |
439 * need to do this... | |
440 */ | |
441 if (blocksize != dn->dn_datablksz || | |
442 dn->dn_bonustype != bonustype || dn->dn_bonuslen != bonuslen) { | |
443 /* free all old data */ | |
444 dnode_free_range(dn, 0, -1ULL, tx); | |
445 } | |
446 | |
447 /* change blocksize */ | |
448 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); | |
3087 | 449 if (blocksize != dn->dn_datablksz && |
450 (!BP_IS_HOLE(&dn->dn_phys->dn_blkptr[0]) || | |
451 list_head(&dn->dn_dbufs) != NULL)) { | |
452 db = dbuf_hold(dn, 0, FTAG); | |
453 dbuf_new_size(db, blocksize, tx); | |
454 } | |
789 | 455 dnode_setdblksz(dn, blocksize); |
456 dnode_setdirty(dn, tx); | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
457 dn->dn_next_bonuslen[tx->tx_txg&TXG_MASK] = bonuslen; |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
458 dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = blocksize; |
789 | 459 rw_exit(&dn->dn_struct_rwlock); |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
460 if (db) |
3087 | 461 dbuf_rele(db, FTAG); |
789 | 462 |
463 /* change type */ | |
464 dn->dn_type = ot; | |
465 | |
466 /* change bonus size and type */ | |
467 mutex_enter(&dn->dn_mtx); | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
468 old_nblkptr = dn->dn_nblkptr; |
789 | 469 dn->dn_bonustype = bonustype; |
470 dn->dn_bonuslen = bonuslen; | |
471 dn->dn_nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT); | |
472 dn->dn_checksum = ZIO_CHECKSUM_INHERIT; | |
473 dn->dn_compress = ZIO_COMPRESS_INHERIT; | |
474 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR); | |
475 | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
476 /* XXX - for now, we can't make nblkptr smaller */ |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
477 ASSERT3U(dn->dn_nblkptr, >=, old_nblkptr); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
478 |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
479 /* fix up the bonus db_size if dn_nblkptr has changed */ |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
480 if (dn->dn_bonus && dn->dn_bonuslen != old_nblkptr) { |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
481 dn->dn_bonus->db.db_size = |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
482 DN_MAX_BONUSLEN - (dn->dn_nblkptr-1) * sizeof (blkptr_t); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
483 ASSERT(dn->dn_bonuslen <= dn->dn_bonus->db.db_size); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
484 } |
3087 | 485 |
789 | 486 dn->dn_allocated_txg = tx->tx_txg; |
487 mutex_exit(&dn->dn_mtx); | |
488 } | |
489 | |
490 void | |
491 dnode_special_close(dnode_t *dn) | |
492 { | |
1544 | 493 /* |
494 * Wait for final references to the dnode to clear. This can | |
495 * only happen if the arc is asyncronously evicting state that | |
496 * has a hold on this dnode while we are trying to evict this | |
497 * dnode. | |
498 */ | |
499 while (refcount_count(&dn->dn_holds) > 0) | |
500 delay(1); | |
789 | 501 dnode_destroy(dn); |
502 } | |
503 | |
504 dnode_t * | |
505 dnode_special_open(objset_impl_t *os, dnode_phys_t *dnp, uint64_t object) | |
506 { | |
507 dnode_t *dn = dnode_create(os, dnp, NULL, object); | |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
508 DNODE_VERIFY(dn); |
789 | 509 return (dn); |
510 } | |
511 | |
512 static void | |
513 dnode_buf_pageout(dmu_buf_t *db, void *arg) | |
514 { | |
515 dnode_t **children_dnodes = arg; | |
516 int i; | |
517 int epb = db->db_size >> DNODE_SHIFT; | |
518 | |
519 for (i = 0; i < epb; i++) { | |
520 dnode_t *dn = children_dnodes[i]; | |
521 int n; | |
522 | |
523 if (dn == NULL) | |
524 continue; | |
525 #ifdef ZFS_DEBUG | |
526 /* | |
527 * If there are holds on this dnode, then there should | |
528 * be holds on the dnode's containing dbuf as well; thus | |
529 * it wouldn't be eligable for eviction and this function | |
530 * would not have been called. | |
531 */ | |
532 ASSERT(refcount_is_zero(&dn->dn_holds)); | |
533 ASSERT(list_head(&dn->dn_dbufs) == NULL); | |
534 ASSERT(refcount_is_zero(&dn->dn_tx_holds)); | |
535 | |
536 for (n = 0; n < TXG_SIZE; n++) | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
537 ASSERT(!list_link_active(&dn->dn_dirty_link[n])); |
789 | 538 #endif |
539 children_dnodes[i] = NULL; | |
540 dnode_destroy(dn); | |
541 } | |
542 kmem_free(children_dnodes, epb * sizeof (dnode_t *)); | |
543 } | |
544 | |
545 /* | |
1544 | 546 * errors: |
547 * EINVAL - invalid object number. | |
548 * EIO - i/o error. | |
549 * succeeds even for free dnodes. | |
789 | 550 */ |
1544 | 551 int |
552 dnode_hold_impl(objset_impl_t *os, uint64_t object, int flag, | |
553 void *tag, dnode_t **dnp) | |
789 | 554 { |
1544 | 555 int epb, idx, err; |
789 | 556 int drop_struct_lock = FALSE; |
1544 | 557 int type; |
789 | 558 uint64_t blk; |
559 dnode_t *mdn, *dn; | |
560 dmu_buf_impl_t *db; | |
561 dnode_t **children_dnodes; | |
562 | |
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7385
diff
changeset
|
563 /* |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7385
diff
changeset
|
564 * If you are holding the spa config lock as writer, you shouldn't |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7385
diff
changeset
|
565 * be asking the DMU to do *anything*. |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7385
diff
changeset
|
566 */ |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7385
diff
changeset
|
567 ASSERT(spa_config_held(os->os_spa, SCL_ALL, RW_WRITER) == 0); |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7385
diff
changeset
|
568 |
789 | 569 if (object == 0 || object >= DN_MAX_OBJECT) |
1544 | 570 return (EINVAL); |
789 | 571 |
572 mdn = os->os_meta_dnode; | |
573 | |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
574 DNODE_VERIFY(mdn); |
789 | 575 |
576 if (!RW_WRITE_HELD(&mdn->dn_struct_rwlock)) { | |
577 rw_enter(&mdn->dn_struct_rwlock, RW_READER); | |
578 drop_struct_lock = TRUE; | |
579 } | |
580 | |
581 blk = dbuf_whichblock(mdn, object * sizeof (dnode_phys_t)); | |
582 | |
1544 | 583 db = dbuf_hold(mdn, blk, FTAG); |
789 | 584 if (drop_struct_lock) |
585 rw_exit(&mdn->dn_struct_rwlock); | |
1544 | 586 if (db == NULL) |
587 return (EIO); | |
588 err = dbuf_read(db, NULL, DB_RF_CANFAIL); | |
589 if (err) { | |
590 dbuf_rele(db, FTAG); | |
591 return (err); | |
592 } | |
789 | 593 |
594 ASSERT3U(db->db.db_size, >=, 1<<DNODE_SHIFT); | |
595 epb = db->db.db_size >> DNODE_SHIFT; | |
596 | |
597 idx = object & (epb-1); | |
598 | |
599 children_dnodes = dmu_buf_get_user(&db->db); | |
600 if (children_dnodes == NULL) { | |
601 dnode_t **winner; | |
602 children_dnodes = kmem_zalloc(epb * sizeof (dnode_t *), | |
603 KM_SLEEP); | |
604 if (winner = dmu_buf_set_user(&db->db, children_dnodes, NULL, | |
605 dnode_buf_pageout)) { | |
606 kmem_free(children_dnodes, epb * sizeof (dnode_t *)); | |
607 children_dnodes = winner; | |
608 } | |
609 } | |
610 | |
611 if ((dn = children_dnodes[idx]) == NULL) { | |
4309
3dfde0f4662d
6542676 ARC needs to track meta-data memory overhead
maybee
parents:
3882
diff
changeset
|
612 dnode_phys_t *dnp = (dnode_phys_t *)db->db.db_data+idx; |
789 | 613 dnode_t *winner; |
4309
3dfde0f4662d
6542676 ARC needs to track meta-data memory overhead
maybee
parents:
3882
diff
changeset
|
614 |
3dfde0f4662d
6542676 ARC needs to track meta-data memory overhead
maybee
parents:
3882
diff
changeset
|
615 dn = dnode_create(os, dnp, db, object); |
789 | 616 winner = atomic_cas_ptr(&children_dnodes[idx], NULL, dn); |
617 if (winner != NULL) { | |
618 dnode_destroy(dn); | |
619 dn = winner; | |
620 } | |
621 } | |
622 | |
623 mutex_enter(&dn->dn_mtx); | |
1544 | 624 type = dn->dn_type; |
789 | 625 if (dn->dn_free_txg || |
1544 | 626 ((flag & DNODE_MUST_BE_ALLOCATED) && type == DMU_OT_NONE) || |
627 ((flag & DNODE_MUST_BE_FREE) && type != DMU_OT_NONE)) { | |
789 | 628 mutex_exit(&dn->dn_mtx); |
1544 | 629 dbuf_rele(db, FTAG); |
630 return (type == DMU_OT_NONE ? ENOENT : EEXIST); | |
789 | 631 } |
632 mutex_exit(&dn->dn_mtx); | |
633 | |
1544 | 634 if (refcount_add(&dn->dn_holds, tag) == 1) |
789 | 635 dbuf_add_ref(db, dn); |
636 | |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
637 DNODE_VERIFY(dn); |
789 | 638 ASSERT3P(dn->dn_dbuf, ==, db); |
639 ASSERT3U(dn->dn_object, ==, object); | |
1544 | 640 dbuf_rele(db, FTAG); |
789 | 641 |
1544 | 642 *dnp = dn; |
643 return (0); | |
789 | 644 } |
645 | |
646 /* | |
647 * Return held dnode if the object is allocated, NULL if not. | |
648 */ | |
1544 | 649 int |
650 dnode_hold(objset_impl_t *os, uint64_t object, void *tag, dnode_t **dnp) | |
789 | 651 { |
1544 | 652 return (dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED, tag, dnp)); |
789 | 653 } |
654 | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
655 /* |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
656 * Can only add a reference if there is already at least one |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
657 * reference on the dnode. Returns FALSE if unable to add a |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
658 * new reference. |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
659 */ |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
660 boolean_t |
1544 | 661 dnode_add_ref(dnode_t *dn, void *tag) |
789 | 662 { |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
663 mutex_enter(&dn->dn_mtx); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
664 if (refcount_is_zero(&dn->dn_holds)) { |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
665 mutex_exit(&dn->dn_mtx); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
666 return (FALSE); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
667 } |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
668 VERIFY(1 < refcount_add(&dn->dn_holds, tag)); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
669 mutex_exit(&dn->dn_mtx); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
670 return (TRUE); |
789 | 671 } |
672 | |
673 void | |
1544 | 674 dnode_rele(dnode_t *dn, void *tag) |
789 | 675 { |
676 uint64_t refs; | |
677 | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
678 mutex_enter(&dn->dn_mtx); |
1544 | 679 refs = refcount_remove(&dn->dn_holds, tag); |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
680 mutex_exit(&dn->dn_mtx); |
789 | 681 /* NOTE: the DNODE_DNODE does not have a dn_dbuf */ |
682 if (refs == 0 && dn->dn_dbuf) | |
1544 | 683 dbuf_rele(dn->dn_dbuf, dn); |
789 | 684 } |
685 | |
686 void | |
687 dnode_setdirty(dnode_t *dn, dmu_tx_t *tx) | |
688 { | |
689 objset_impl_t *os = dn->dn_objset; | |
690 uint64_t txg = tx->tx_txg; | |
691 | |
1544 | 692 if (dn->dn_object == DMU_META_DNODE_OBJECT) |
789 | 693 return; |
694 | |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
695 DNODE_VERIFY(dn); |
789 | 696 |
697 #ifdef ZFS_DEBUG | |
698 mutex_enter(&dn->dn_mtx); | |
699 ASSERT(dn->dn_phys->dn_type || dn->dn_allocated_txg); | |
700 /* ASSERT(dn->dn_free_txg == 0 || dn->dn_free_txg >= txg); */ | |
701 mutex_exit(&dn->dn_mtx); | |
702 #endif | |
703 | |
704 mutex_enter(&os->os_lock); | |
705 | |
706 /* | |
707 * If we are already marked dirty, we're done. | |
708 */ | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
709 if (list_link_active(&dn->dn_dirty_link[txg & TXG_MASK])) { |
789 | 710 mutex_exit(&os->os_lock); |
711 return; | |
712 } | |
713 | |
714 ASSERT(!refcount_is_zero(&dn->dn_holds) || list_head(&dn->dn_dbufs)); | |
715 ASSERT(dn->dn_datablksz != 0); | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
716 ASSERT3U(dn->dn_next_bonuslen[txg&TXG_MASK], ==, 0); |
1599 | 717 ASSERT3U(dn->dn_next_blksz[txg&TXG_MASK], ==, 0); |
789 | 718 |
719 dprintf_ds(os->os_dsl_dataset, "obj=%llu txg=%llu\n", | |
720 dn->dn_object, txg); | |
721 | |
722 if (dn->dn_free_txg > 0 && dn->dn_free_txg <= txg) { | |
723 list_insert_tail(&os->os_free_dnodes[txg&TXG_MASK], dn); | |
724 } else { | |
725 list_insert_tail(&os->os_dirty_dnodes[txg&TXG_MASK], dn); | |
726 } | |
727 | |
728 mutex_exit(&os->os_lock); | |
729 | |
730 /* | |
731 * The dnode maintains a hold on its containing dbuf as | |
732 * long as there are holds on it. Each instantiated child | |
733 * dbuf maintaines a hold on the dnode. When the last child | |
734 * drops its hold, the dnode will drop its hold on the | |
735 * containing dbuf. We add a "dirty hold" here so that the | |
736 * dnode will hang around after we finish processing its | |
737 * children. | |
738 */ | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
739 VERIFY(dnode_add_ref(dn, (void *)(uintptr_t)tx->tx_txg)); |
789 | 740 |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
741 (void) dbuf_dirty(dn->dn_dbuf, tx); |
789 | 742 |
743 dsl_dataset_dirty(os->os_dsl_dataset, tx); | |
744 } | |
745 | |
746 void | |
747 dnode_free(dnode_t *dn, dmu_tx_t *tx) | |
748 { | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
749 int txgoff = tx->tx_txg & TXG_MASK; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
750 |
789 | 751 dprintf("dn=%p txg=%llu\n", dn, tx->tx_txg); |
752 | |
753 /* we should be the only holder... hopefully */ | |
754 /* ASSERT3U(refcount_count(&dn->dn_holds), ==, 1); */ | |
755 | |
756 mutex_enter(&dn->dn_mtx); | |
757 if (dn->dn_type == DMU_OT_NONE || dn->dn_free_txg) { | |
758 mutex_exit(&dn->dn_mtx); | |
759 return; | |
760 } | |
761 dn->dn_free_txg = tx->tx_txg; | |
762 mutex_exit(&dn->dn_mtx); | |
763 | |
764 /* | |
765 * If the dnode is already dirty, it needs to be moved from | |
766 * the dirty list to the free list. | |
767 */ | |
768 mutex_enter(&dn->dn_objset->os_lock); | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
769 if (list_link_active(&dn->dn_dirty_link[txgoff])) { |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
770 list_remove(&dn->dn_objset->os_dirty_dnodes[txgoff], dn); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
771 list_insert_tail(&dn->dn_objset->os_free_dnodes[txgoff], dn); |
789 | 772 mutex_exit(&dn->dn_objset->os_lock); |
773 } else { | |
774 mutex_exit(&dn->dn_objset->os_lock); | |
775 dnode_setdirty(dn, tx); | |
776 } | |
777 } | |
778 | |
779 /* | |
780 * Try to change the block size for the indicated dnode. This can only | |
781 * succeed if there are no blocks allocated or dirty beyond first block | |
782 */ | |
783 int | |
784 dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx) | |
785 { | |
786 dmu_buf_impl_t *db, *db_next; | |
6992 | 787 int err; |
789 | 788 |
789 if (size == 0) | |
790 size = SPA_MINBLOCKSIZE; | |
791 if (size > SPA_MAXBLOCKSIZE) | |
792 size = SPA_MAXBLOCKSIZE; | |
793 else | |
794 size = P2ROUNDUP(size, SPA_MINBLOCKSIZE); | |
795 | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
796 if (ibs == dn->dn_indblkshift) |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
797 ibs = 0; |
789 | 798 |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
799 if (size >> SPA_MINBLOCKSHIFT == dn->dn_datablkszsec && ibs == 0) |
789 | 800 return (0); |
801 | |
802 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); | |
803 | |
804 /* Check for any allocated blocks beyond the first */ | |
805 if (dn->dn_phys->dn_maxblkid != 0) | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
806 goto fail; |
789 | 807 |
808 mutex_enter(&dn->dn_dbufs_mtx); | |
809 for (db = list_head(&dn->dn_dbufs); db; db = db_next) { | |
810 db_next = list_next(&dn->dn_dbufs, db); | |
811 | |
6992 | 812 if (db->db_blkid != 0 && db->db_blkid != DB_BONUS_BLKID) { |
789 | 813 mutex_exit(&dn->dn_dbufs_mtx); |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
814 goto fail; |
789 | 815 } |
816 } | |
817 mutex_exit(&dn->dn_dbufs_mtx); | |
818 | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
819 if (ibs && dn->dn_nlevels != 1) |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
820 goto fail; |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
821 |
6992 | 822 /* resize the old block */ |
823 err = dbuf_hold_impl(dn, 0, 0, TRUE, FTAG, &db); | |
824 if (err == 0) | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
825 dbuf_new_size(db, size, tx); |
6992 | 826 else if (err != ENOENT) |
827 goto fail; | |
789 | 828 |
829 dnode_setdblksz(dn, size); | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
830 dnode_setdirty(dn, tx); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
831 dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = size; |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
832 if (ibs) { |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
833 dn->dn_indblkshift = ibs; |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
834 dn->dn_next_indblkshift[tx->tx_txg&TXG_MASK] = ibs; |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
835 } |
6992 | 836 /* rele after we have fixed the blocksize in the dnode */ |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
837 if (db) |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
838 dbuf_rele(db, FTAG); |
789 | 839 |
840 rw_exit(&dn->dn_struct_rwlock); | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
841 return (0); |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
842 |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
843 fail: |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
844 rw_exit(&dn->dn_struct_rwlock); |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
845 return (ENOTSUP); |
789 | 846 } |
847 | |
7332
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
848 /* read-holding callers must not rely on the lock being continuously held */ |
789 | 849 void |
7332
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
850 dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t have_read) |
789 | 851 { |
852 uint64_t txgoff = tx->tx_txg & TXG_MASK; | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
853 int epbs, new_nlevels; |
789 | 854 uint64_t sz; |
855 | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
856 ASSERT(blkid != DB_BONUS_BLKID); |
789 | 857 |
7332
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
858 ASSERT(have_read ? |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
859 RW_READ_HELD(&dn->dn_struct_rwlock) : |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
860 RW_WRITE_HELD(&dn->dn_struct_rwlock)); |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
861 |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
862 /* |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
863 * if we have a read-lock, check to see if we need to do any work |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
864 * before upgrading to a write-lock. |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
865 */ |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
866 if (have_read) { |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
867 if (blkid <= dn->dn_maxblkid) |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
868 return; |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
869 |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
870 if (!rw_tryupgrade(&dn->dn_struct_rwlock)) { |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
871 rw_exit(&dn->dn_struct_rwlock); |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
872 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
873 } |
789 | 874 } |
875 | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
876 if (blkid <= dn->dn_maxblkid) |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
877 goto out; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
878 |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
879 dn->dn_maxblkid = blkid; |
789 | 880 |
881 /* | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
882 * Compute the number of levels necessary to support the new maxblkid. |
789 | 883 */ |
884 new_nlevels = 1; | |
885 epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT; | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
886 for (sz = dn->dn_nblkptr; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
887 sz <= blkid && sz >= dn->dn_nblkptr; sz <<= epbs) |
789 | 888 new_nlevels++; |
889 | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
890 if (new_nlevels > dn->dn_nlevels) { |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
891 int old_nlevels = dn->dn_nlevels; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
892 dmu_buf_impl_t *db; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
893 list_t *list; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
894 dbuf_dirty_record_t *new, *dr, *dr_next; |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
895 |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
896 dn->dn_nlevels = new_nlevels; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
897 |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
898 ASSERT3U(new_nlevels, >, dn->dn_next_nlevels[txgoff]); |
789 | 899 dn->dn_next_nlevels[txgoff] = new_nlevels; |
900 | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
901 /* dirty the left indirects */ |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
902 db = dbuf_hold_level(dn, old_nlevels, 0, FTAG); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
903 new = dbuf_dirty(db, tx); |
1544 | 904 dbuf_rele(db, FTAG); |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
905 |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
906 /* transfer the dirty records to the new indirect */ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
907 mutex_enter(&dn->dn_mtx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
908 mutex_enter(&new->dt.di.dr_mtx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
909 list = &dn->dn_dirty_records[txgoff]; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
910 for (dr = list_head(list); dr; dr = dr_next) { |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
911 dr_next = list_next(&dn->dn_dirty_records[txgoff], dr); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
912 if (dr->dr_dbuf->db_level != new_nlevels-1 && |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
913 dr->dr_dbuf->db_blkid != DB_BONUS_BLKID) { |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
914 ASSERT(dr->dr_dbuf->db_level == old_nlevels-1); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
915 list_remove(&dn->dn_dirty_records[txgoff], dr); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
916 list_insert_tail(&new->dt.di.dr_children, dr); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
917 dr->dr_parent = new; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
918 } |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
919 } |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
920 mutex_exit(&new->dt.di.dr_mtx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
921 mutex_exit(&dn->dn_mtx); |
789 | 922 } |
923 | |
924 out: | |
7332
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
925 if (have_read) |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
926 rw_downgrade(&dn->dn_struct_rwlock); |
789 | 927 } |
928 | |
929 void | |
930 dnode_clear_range(dnode_t *dn, uint64_t blkid, uint64_t nblks, dmu_tx_t *tx) | |
931 { | |
932 avl_tree_t *tree = &dn->dn_ranges[tx->tx_txg&TXG_MASK]; | |
933 avl_index_t where; | |
934 free_range_t *rp; | |
935 free_range_t rp_tofind; | |
936 uint64_t endblk = blkid + nblks; | |
937 | |
938 ASSERT(MUTEX_HELD(&dn->dn_mtx)); | |
939 ASSERT(nblks <= UINT64_MAX - blkid); /* no overflow */ | |
940 | |
941 dprintf_dnode(dn, "blkid=%llu nblks=%llu txg=%llu\n", | |
942 blkid, nblks, tx->tx_txg); | |
943 rp_tofind.fr_blkid = blkid; | |
944 rp = avl_find(tree, &rp_tofind, &where); | |
945 if (rp == NULL) | |
946 rp = avl_nearest(tree, where, AVL_BEFORE); | |
947 if (rp == NULL) | |
948 rp = avl_nearest(tree, where, AVL_AFTER); | |
949 | |
950 while (rp && (rp->fr_blkid <= blkid + nblks)) { | |
951 uint64_t fr_endblk = rp->fr_blkid + rp->fr_nblks; | |
952 free_range_t *nrp = AVL_NEXT(tree, rp); | |
953 | |
954 if (blkid <= rp->fr_blkid && endblk >= fr_endblk) { | |
955 /* clear this entire range */ | |
956 avl_remove(tree, rp); | |
957 kmem_free(rp, sizeof (free_range_t)); | |
958 } else if (blkid <= rp->fr_blkid && | |
959 endblk > rp->fr_blkid && endblk < fr_endblk) { | |
960 /* clear the beginning of this range */ | |
961 rp->fr_blkid = endblk; | |
962 rp->fr_nblks = fr_endblk - endblk; | |
963 } else if (blkid > rp->fr_blkid && blkid < fr_endblk && | |
964 endblk >= fr_endblk) { | |
965 /* clear the end of this range */ | |
966 rp->fr_nblks = blkid - rp->fr_blkid; | |
967 } else if (blkid > rp->fr_blkid && endblk < fr_endblk) { | |
968 /* clear a chunk out of this range */ | |
969 free_range_t *new_rp = | |
970 kmem_alloc(sizeof (free_range_t), KM_SLEEP); | |
971 | |
972 new_rp->fr_blkid = endblk; | |
973 new_rp->fr_nblks = fr_endblk - endblk; | |
974 avl_insert_here(tree, new_rp, rp, AVL_AFTER); | |
975 rp->fr_nblks = blkid - rp->fr_blkid; | |
976 } | |
977 /* there may be no overlap */ | |
978 rp = nrp; | |
979 } | |
980 } | |
981 | |
982 void | |
983 dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx) | |
984 { | |
985 dmu_buf_impl_t *db; | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
986 uint64_t blkoff, blkid, nblks; |
6992 | 987 int blksz, blkshift, head, tail; |
789 | 988 int trunc = FALSE; |
6992 | 989 int epbs; |
789 | 990 |
991 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); | |
992 blksz = dn->dn_datablksz; | |
6992 | 993 blkshift = dn->dn_datablkshift; |
994 epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT; | |
789 | 995 |
996 if (len == -1ULL) { | |
997 len = UINT64_MAX - off; | |
998 trunc = TRUE; | |
999 } | |
1000 | |
1001 /* | |
1002 * First, block align the region to free: | |
1003 */ | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1004 if (ISP2(blksz)) { |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1005 head = P2NPHASE(off, blksz); |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1006 blkoff = P2PHASE(off, blksz); |
6992 | 1007 if ((off >> blkshift) > dn->dn_maxblkid) |
1008 goto out; | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1009 } else { |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1010 ASSERT(dn->dn_maxblkid == 0); |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1011 if (off == 0 && len >= blksz) { |
6992 | 1012 /* Freeing the whole block; fast-track this request */ |
1013 blkid = 0; | |
1014 nblks = 1; | |
1015 goto done; | |
7385
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1016 } else if (off >= blksz) { |
6992 | 1017 /* Freeing past end-of-data */ |
1018 goto out; | |
789 | 1019 } else { |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1020 /* Freeing part of the block. */ |
789 | 1021 head = blksz - off; |
1022 ASSERT3U(head, >, 0); | |
1023 } | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1024 blkoff = off; |
789 | 1025 } |
1026 /* zero out any partial block data at the start of the range */ | |
1027 if (head) { | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1028 ASSERT3U(blkoff + head, ==, blksz); |
789 | 1029 if (len < head) |
1030 head = len; | |
1031 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, off), TRUE, | |
1032 FTAG, &db) == 0) { | |
1033 caddr_t data; | |
1034 | |
1035 /* don't dirty if it isn't on disk and isn't dirty */ | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1036 if (db->db_last_dirty || |
789 | 1037 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) { |
1038 rw_exit(&dn->dn_struct_rwlock); | |
1039 dbuf_will_dirty(db, tx); | |
1040 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); | |
1041 data = db->db.db_data; | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1042 bzero(data + blkoff, head); |
789 | 1043 } |
1544 | 1044 dbuf_rele(db, FTAG); |
789 | 1045 } |
1046 off += head; | |
1047 len -= head; | |
1048 } | |
1049 | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1050 /* If the range was less than one block, we're done */ |
6992 | 1051 if (len == 0) |
1052 goto out; | |
1053 | |
1054 /* If the remaining range is past end of file, we're done */ | |
1055 if ((off >> blkshift) > dn->dn_maxblkid) | |
1056 goto out; | |
1057 | |
7385
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1058 ASSERT(ISP2(blksz)); |
6992 | 1059 if (trunc) |
1060 tail = 0; | |
1061 else | |
1062 tail = P2PHASE(len, blksz); | |
1063 | |
1064 ASSERT3U(P2PHASE(off, blksz), ==, 0); | |
1065 /* zero out any partial block data at the end of the range */ | |
1066 if (tail) { | |
1067 if (len < tail) | |
1068 tail = len; | |
1069 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, off+len), | |
1070 TRUE, FTAG, &db) == 0) { | |
1071 /* don't dirty if not on disk and not dirty */ | |
1072 if (db->db_last_dirty || | |
1073 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) { | |
1074 rw_exit(&dn->dn_struct_rwlock); | |
1075 dbuf_will_dirty(db, tx); | |
1076 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); | |
1077 bzero(db->db.db_data, tail); | |
1078 } | |
1079 dbuf_rele(db, FTAG); | |
1080 } | |
1081 len -= tail; | |
1082 } | |
1083 | |
1084 /* If the range did not include a full block, we are done */ | |
1085 if (len == 0) | |
789 | 1086 goto out; |
1087 | |
6992 | 1088 ASSERT(IS_P2ALIGNED(off, blksz)); |
1089 ASSERT(trunc || IS_P2ALIGNED(len, blksz)); | |
1090 blkid = off >> blkshift; | |
1091 nblks = len >> blkshift; | |
1092 if (trunc) | |
1093 nblks += 1; | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1094 |
6992 | 1095 /* |
1096 * Read in and mark all the level-1 indirects dirty, | |
1097 * so that they will stay in memory until syncing phase. | |
7049
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1098 * Always dirty the first and last indirect to make sure |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1099 * we dirty all the partial indirects. |
6992 | 1100 */ |
1101 if (dn->dn_nlevels > 1) { | |
1102 uint64_t i, first, last; | |
1103 int shift = epbs + dn->dn_datablkshift; | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1104 |
6992 | 1105 first = blkid >> epbs; |
7049
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1106 if (db = dbuf_hold_level(dn, 1, first, FTAG)) { |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1107 dbuf_will_dirty(db, tx); |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1108 dbuf_rele(db, FTAG); |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1109 } |
6992 | 1110 if (trunc) |
1111 last = dn->dn_maxblkid >> epbs; | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1112 else |
6992 | 1113 last = (blkid + nblks - 1) >> epbs; |
7049
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1114 if (last > first && (db = dbuf_hold_level(dn, 1, last, FTAG))) { |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1115 dbuf_will_dirty(db, tx); |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1116 dbuf_rele(db, FTAG); |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1117 } |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1118 for (i = first + 1; i < last; i++) { |
6992 | 1119 uint64_t ibyte = i << shift; |
1120 int err; | |
789 | 1121 |
6992 | 1122 err = dnode_next_offset(dn, |
1123 DNODE_FIND_HAVELOCK, &ibyte, 1, 1, 0); | |
1124 i = ibyte >> shift; | |
7049
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1125 if (err == ESRCH || i >= last) |
6992 | 1126 break; |
1127 ASSERT(err == 0); | |
1128 db = dbuf_hold_level(dn, 1, i, FTAG); | |
1129 if (db) { | |
1130 dbuf_will_dirty(db, tx); | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1131 dbuf_rele(db, FTAG); |
789 | 1132 } |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1133 } |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1134 } |
6992 | 1135 done: |
1136 /* | |
1137 * Add this range to the dnode range list. | |
1138 * We will finish up this free operation in the syncing phase. | |
1139 */ | |
789 | 1140 mutex_enter(&dn->dn_mtx); |
1141 dnode_clear_range(dn, blkid, nblks, tx); | |
1142 { | |
1143 free_range_t *rp, *found; | |
1144 avl_index_t where; | |
1145 avl_tree_t *tree = &dn->dn_ranges[tx->tx_txg&TXG_MASK]; | |
1146 | |
1147 /* Add new range to dn_ranges */ | |
1148 rp = kmem_alloc(sizeof (free_range_t), KM_SLEEP); | |
1149 rp->fr_blkid = blkid; | |
1150 rp->fr_nblks = nblks; | |
1151 found = avl_find(tree, rp, &where); | |
1152 ASSERT(found == NULL); | |
1153 avl_insert(tree, rp, where); | |
1154 dprintf_dnode(dn, "blkid=%llu nblks=%llu txg=%llu\n", | |
1155 blkid, nblks, tx->tx_txg); | |
1156 } | |
1157 mutex_exit(&dn->dn_mtx); | |
1158 | |
6992 | 1159 dbuf_free_range(dn, blkid, blkid + nblks - 1, tx); |
789 | 1160 dnode_setdirty(dn, tx); |
1161 out: | |
6992 | 1162 if (trunc && dn->dn_maxblkid >= (off >> blkshift)) |
1163 dn->dn_maxblkid = (off >> blkshift ? (off >> blkshift) - 1 : 0); | |
1164 | |
789 | 1165 rw_exit(&dn->dn_struct_rwlock); |
1166 } | |
1167 | |
1168 /* return TRUE if this blkid was freed in a recent txg, or FALSE if it wasn't */ | |
1169 uint64_t | |
1170 dnode_block_freed(dnode_t *dn, uint64_t blkid) | |
1171 { | |
1172 free_range_t range_tofind; | |
1173 void *dp = spa_get_dsl(dn->dn_objset->os_spa); | |
1174 int i; | |
1175 | |
1176 if (blkid == DB_BONUS_BLKID) | |
1177 return (FALSE); | |
1178 | |
1179 /* | |
1180 * If we're in the process of opening the pool, dp will not be | |
1181 * set yet, but there shouldn't be anything dirty. | |
1182 */ | |
1183 if (dp == NULL) | |
1184 return (FALSE); | |
1185 | |
1186 if (dn->dn_free_txg) | |
1187 return (TRUE); | |
1188 | |
1189 /* | |
1190 * If dn_datablkshift is not set, then there's only a single | |
1191 * block, in which case there will never be a free range so it | |
1192 * won't matter. | |
1193 */ | |
1194 range_tofind.fr_blkid = blkid; | |
1195 mutex_enter(&dn->dn_mtx); | |
1196 for (i = 0; i < TXG_SIZE; i++) { | |
1197 free_range_t *range_found; | |
1198 avl_index_t idx; | |
1199 | |
1200 range_found = avl_find(&dn->dn_ranges[i], &range_tofind, &idx); | |
1201 if (range_found) { | |
1202 ASSERT(range_found->fr_nblks > 0); | |
1203 break; | |
1204 } | |
1205 range_found = avl_nearest(&dn->dn_ranges[i], idx, AVL_BEFORE); | |
1206 if (range_found && | |
1207 range_found->fr_blkid + range_found->fr_nblks > blkid) | |
1208 break; | |
1209 } | |
1210 mutex_exit(&dn->dn_mtx); | |
1211 return (i < TXG_SIZE); | |
1212 } | |
1213 | |
1214 /* call from syncing context when we actually write/free space for this dnode */ | |
1215 void | |
2082 | 1216 dnode_diduse_space(dnode_t *dn, int64_t delta) |
789 | 1217 { |
2082 | 1218 uint64_t space; |
1219 dprintf_dnode(dn, "dn=%p dnp=%p used=%llu delta=%lld\n", | |
789 | 1220 dn, dn->dn_phys, |
2082 | 1221 (u_longlong_t)dn->dn_phys->dn_used, |
1222 (longlong_t)delta); | |
789 | 1223 |
1224 mutex_enter(&dn->dn_mtx); | |
2082 | 1225 space = DN_USED_BYTES(dn->dn_phys); |
1226 if (delta > 0) { | |
1227 ASSERT3U(space + delta, >=, space); /* no overflow */ | |
789 | 1228 } else { |
2082 | 1229 ASSERT3U(space, >=, -delta); /* no underflow */ |
1230 } | |
1231 space += delta; | |
4577 | 1232 if (spa_version(dn->dn_objset->os_spa) < SPA_VERSION_DNODE_BYTES) { |
2082 | 1233 ASSERT((dn->dn_phys->dn_flags & DNODE_FLAG_USED_BYTES) == 0); |
1234 ASSERT3U(P2PHASE(space, 1<<DEV_BSHIFT), ==, 0); | |
1235 dn->dn_phys->dn_used = space >> DEV_BSHIFT; | |
1236 } else { | |
1237 dn->dn_phys->dn_used = space; | |
1238 dn->dn_phys->dn_flags |= DNODE_FLAG_USED_BYTES; | |
789 | 1239 } |
1240 mutex_exit(&dn->dn_mtx); | |
1241 } | |
1242 | |
1243 /* | |
1244 * Call when we think we're going to write/free space in open context. | |
1245 * Be conservative (ie. OK to write less than this or free more than | |
1246 * this, but don't write more or free less). | |
1247 */ | |
1248 void | |
1249 dnode_willuse_space(dnode_t *dn, int64_t space, dmu_tx_t *tx) | |
1250 { | |
1251 objset_impl_t *os = dn->dn_objset; | |
1252 dsl_dataset_t *ds = os->os_dsl_dataset; | |
1253 | |
1254 if (space > 0) | |
1255 space = spa_get_asize(os->os_spa, space); | |
1256 | |
1257 if (ds) | |
1258 dsl_dir_willuse_space(ds->ds_dir, space, tx); | |
1259 | |
1260 dmu_tx_willuse_space(tx, space); | |
1261 } | |
1262 | |
1263 static int | |
6992 | 1264 dnode_next_offset_level(dnode_t *dn, int flags, uint64_t *offset, |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1265 int lvl, uint64_t blkfill, uint64_t txg) |
789 | 1266 { |
1267 dmu_buf_impl_t *db = NULL; | |
1268 void *data = NULL; | |
1269 uint64_t epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT; | |
1270 uint64_t epb = 1ULL << epbs; | |
1271 uint64_t minfill, maxfill; | |
6992 | 1272 boolean_t hole; |
1273 int i, inc, error, span; | |
789 | 1274 |
1275 dprintf("probing object %llu offset %llx level %d of %u\n", | |
1276 dn->dn_object, *offset, lvl, dn->dn_phys->dn_nlevels); | |
1277 | |
6992 | 1278 hole = flags & DNODE_FIND_HOLE; |
1279 inc = (flags & DNODE_FIND_BACKWARDS) ? -1 : 1; | |
7385
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1280 ASSERT(txg == 0 || !hole); |
6992 | 1281 |
789 | 1282 if (lvl == dn->dn_phys->dn_nlevels) { |
1283 error = 0; | |
1284 epb = dn->dn_phys->dn_nblkptr; | |
1285 data = dn->dn_phys->dn_blkptr; | |
1286 } else { | |
1287 uint64_t blkid = dbuf_whichblock(dn, *offset) >> (epbs * lvl); | |
1288 error = dbuf_hold_impl(dn, lvl, blkid, TRUE, FTAG, &db); | |
1289 if (error) { | |
7385
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1290 if (error != ENOENT) |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1291 return (error); |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1292 if (hole) |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1293 return (0); |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1294 /* |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1295 * This can only happen when we are searching up |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1296 * the block tree for data. We don't really need to |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1297 * adjust the offset, as we will just end up looking |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1298 * at the pointer to this block in its parent, and its |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1299 * going to be unallocated, so we will skip over it. |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1300 */ |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1301 return (ESRCH); |
789 | 1302 } |
1793
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1303 error = dbuf_read(db, NULL, DB_RF_CANFAIL | DB_RF_HAVESTRUCT); |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1304 if (error) { |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1305 dbuf_rele(db, FTAG); |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1306 return (error); |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1307 } |
789 | 1308 data = db->db.db_data; |
1309 } | |
1310 | |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1311 if (db && txg && |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1312 (db->db_blkptr == NULL || db->db_blkptr->blk_birth <= txg)) { |
7385
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1313 /* |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1314 * This can only happen when we are searching up the tree |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1315 * and these conditions mean that we need to keep climbing. |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1316 */ |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1317 error = ESRCH; |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1318 } else if (lvl == 0) { |
789 | 1319 dnode_phys_t *dnp = data; |
1320 span = DNODE_SHIFT; | |
1321 ASSERT(dn->dn_type == DMU_OT_DNODE); | |
1322 | |
6992 | 1323 for (i = (*offset >> span) & (blkfill - 1); |
1324 i >= 0 && i < blkfill; i += inc) { | |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1325 boolean_t newcontents = B_TRUE; |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1326 if (txg) { |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1327 int j; |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1328 newcontents = B_FALSE; |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1329 for (j = 0; j < dnp[i].dn_nblkptr; j++) { |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1330 if (dnp[i].dn_blkptr[j].blk_birth > txg) |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1331 newcontents = B_TRUE; |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1332 } |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1333 } |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1334 if (!dnp[i].dn_type == hole && newcontents) |
789 | 1335 break; |
6992 | 1336 *offset += (1ULL << span) * inc; |
789 | 1337 } |
6992 | 1338 if (i < 0 || i == blkfill) |
789 | 1339 error = ESRCH; |
1340 } else { | |
1341 blkptr_t *bp = data; | |
1342 span = (lvl - 1) * epbs + dn->dn_datablkshift; | |
1343 minfill = 0; | |
1344 maxfill = blkfill << ((lvl - 1) * epbs); | |
1345 | |
1346 if (hole) | |
1347 maxfill--; | |
1348 else | |
1349 minfill++; | |
1350 | |
1351 for (i = (*offset >> span) & ((1ULL << epbs) - 1); | |
6992 | 1352 i >= 0 && i < epb; i += inc) { |
789 | 1353 if (bp[i].blk_fill >= minfill && |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1354 bp[i].blk_fill <= maxfill && |
7385
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1355 (hole || bp[i].blk_birth > txg)) |
789 | 1356 break; |
7385
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1357 if (inc < 0 && *offset < (1ULL << span)) |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1358 *offset = 0; |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1359 else |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1360 *offset += (1ULL << span) * inc; |
789 | 1361 } |
6992 | 1362 if (i < 0 || i == epb) |
789 | 1363 error = ESRCH; |
1364 } | |
1365 | |
1366 if (db) | |
1544 | 1367 dbuf_rele(db, FTAG); |
789 | 1368 |
1369 return (error); | |
1370 } | |
1371 | |
1372 /* | |
1373 * Find the next hole, data, or sparse region at or after *offset. | |
1374 * The value 'blkfill' tells us how many items we expect to find | |
1375 * in an L0 data block; this value is 1 for normal objects, | |
1376 * DNODES_PER_BLOCK for the meta dnode, and some fraction of | |
1377 * DNODES_PER_BLOCK when searching for sparse regions thereof. | |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1378 * |
789 | 1379 * Examples: |
1380 * | |
6992 | 1381 * dnode_next_offset(dn, flags, offset, 1, 1, 0); |
1382 * Finds the next/previous hole/data in a file. | |
789 | 1383 * Used in dmu_offset_next(). |
1384 * | |
6992 | 1385 * dnode_next_offset(mdn, flags, offset, 0, DNODES_PER_BLOCK, txg); |
789 | 1386 * Finds the next free/allocated dnode an objset's meta-dnode. |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1387 * Only finds objects that have new contents since txg (ie. |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1388 * bonus buffer changes and content removal are ignored). |
789 | 1389 * Used in dmu_object_next(). |
1390 * | |
6992 | 1391 * dnode_next_offset(mdn, DNODE_FIND_HOLE, offset, 2, DNODES_PER_BLOCK >> 2, 0); |
789 | 1392 * Finds the next L2 meta-dnode bp that's at most 1/4 full. |
1393 * Used in dmu_object_alloc(). | |
1394 */ | |
1395 int | |
6992 | 1396 dnode_next_offset(dnode_t *dn, int flags, uint64_t *offset, |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1397 int minlvl, uint64_t blkfill, uint64_t txg) |
789 | 1398 { |
6992 | 1399 uint64_t initial_offset = *offset; |
789 | 1400 int lvl, maxlvl; |
1401 int error = 0; | |
1402 | |
6992 | 1403 if (!(flags & DNODE_FIND_HAVELOCK)) |
1404 rw_enter(&dn->dn_struct_rwlock, RW_READER); | |
789 | 1405 |
1406 if (dn->dn_phys->dn_nlevels == 0) { | |
6992 | 1407 error = ESRCH; |
1408 goto out; | |
789 | 1409 } |
1410 | |
1411 if (dn->dn_datablkshift == 0) { | |
1412 if (*offset < dn->dn_datablksz) { | |
6992 | 1413 if (flags & DNODE_FIND_HOLE) |
789 | 1414 *offset = dn->dn_datablksz; |
1415 } else { | |
1416 error = ESRCH; | |
1417 } | |
6992 | 1418 goto out; |
789 | 1419 } |
1420 | |
1421 maxlvl = dn->dn_phys->dn_nlevels; | |
1422 | |
1423 for (lvl = minlvl; lvl <= maxlvl; lvl++) { | |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1424 error = dnode_next_offset_level(dn, |
6992 | 1425 flags, offset, lvl, blkfill, txg); |
1793
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1426 if (error != ESRCH) |
789 | 1427 break; |
1428 } | |
1429 | |
6992 | 1430 while (error == 0 && --lvl >= minlvl) { |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1431 error = dnode_next_offset_level(dn, |
6992 | 1432 flags, offset, lvl, blkfill, txg); |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1433 } |
789 | 1434 |
6992 | 1435 if (error == 0 && (flags & DNODE_FIND_BACKWARDS ? |
1436 initial_offset < *offset : initial_offset > *offset)) | |
1793
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1437 error = ESRCH; |
6992 | 1438 out: |
1439 if (!(flags & DNODE_FIND_HAVELOCK)) | |
1440 rw_exit(&dn->dn_struct_rwlock); | |
789 | 1441 |
1442 return (error); | |
1443 } |