4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/zfs_context.h>
28 #include <sys/dnode.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>
37 #include <sys/dmu_zfetch.h>
39 static int free_range_compar(const void *node1, const void *node2);
41 static kmem_cache_t *dnode_cache;
43 static dnode_phys_t dnode_phys_zero;
45 int zfs_default_bs = SPA_MINBLOCKSHIFT;
46 int zfs_default_ibs = DN_MAX_INDBLKSHIFT;
50 dnode_cons(void *arg, void *unused, int kmflag)
54 bzero(dn, sizeof (dnode_t));
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 cv_init(&dn->dn_notxholds, NULL, CV_DEFAULT, NULL);
61 refcount_create(&dn->dn_holds);
62 refcount_create(&dn->dn_tx_holds);
64 for (i = 0; i < TXG_SIZE; i++) {
65 avl_create(&dn->dn_ranges[i], free_range_compar,
66 sizeof (free_range_t),
67 offsetof(struct free_range, fr_node));
68 list_create(&dn->dn_dirty_records[i],
69 sizeof (dbuf_dirty_record_t),
70 offsetof(dbuf_dirty_record_t, dr_dirty_node));
73 list_create(&dn->dn_dbufs, sizeof (dmu_buf_impl_t),
74 offsetof(dmu_buf_impl_t, db_link));
81 dnode_dest(void *arg, void *unused)
86 rw_destroy(&dn->dn_struct_rwlock);
87 mutex_destroy(&dn->dn_mtx);
88 mutex_destroy(&dn->dn_dbufs_mtx);
89 cv_destroy(&dn->dn_notxholds);
90 refcount_destroy(&dn->dn_holds);
91 refcount_destroy(&dn->dn_tx_holds);
93 for (i = 0; i < TXG_SIZE; i++) {
94 avl_destroy(&dn->dn_ranges[i]);
95 list_destroy(&dn->dn_dirty_records[i]);
98 list_destroy(&dn->dn_dbufs);
104 dnode_cache = kmem_cache_create("dnode_t",
106 0, dnode_cons, dnode_dest, NULL, NULL, NULL, 0);
112 kmem_cache_destroy(dnode_cache);
118 dnode_verify(dnode_t *dn)
120 int drop_struct_lock = FALSE;
123 ASSERT(dn->dn_objset);
125 ASSERT(dn->dn_phys->dn_type < DMU_OT_NUMTYPES);
127 if (!(zfs_flags & ZFS_DEBUG_DNODE_VERIFY))
130 if (!RW_WRITE_HELD(&dn->dn_struct_rwlock)) {
131 rw_enter(&dn->dn_struct_rwlock, RW_READER);
132 drop_struct_lock = TRUE;
134 if (dn->dn_phys->dn_type != DMU_OT_NONE || dn->dn_allocated_txg != 0) {
136 ASSERT3U(dn->dn_indblkshift, >=, 0);
137 ASSERT3U(dn->dn_indblkshift, <=, SPA_MAXBLOCKSHIFT);
138 if (dn->dn_datablkshift) {
139 ASSERT3U(dn->dn_datablkshift, >=, SPA_MINBLOCKSHIFT);
140 ASSERT3U(dn->dn_datablkshift, <=, SPA_MAXBLOCKSHIFT);
141 ASSERT3U(1<<dn->dn_datablkshift, ==, dn->dn_datablksz);
143 ASSERT3U(dn->dn_nlevels, <=, 30);
144 ASSERT3U(dn->dn_type, <=, DMU_OT_NUMTYPES);
145 ASSERT3U(dn->dn_nblkptr, >=, 1);
146 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR);
147 ASSERT3U(dn->dn_bonuslen, <=, DN_MAX_BONUSLEN);
148 ASSERT3U(dn->dn_datablksz, ==,
149 dn->dn_datablkszsec << SPA_MINBLOCKSHIFT);
150 ASSERT3U(ISP2(dn->dn_datablksz), ==, dn->dn_datablkshift != 0);
151 ASSERT3U((dn->dn_nblkptr - 1) * sizeof (blkptr_t) +
152 dn->dn_bonuslen, <=, DN_MAX_BONUSLEN);
153 for (i = 0; i < TXG_SIZE; i++) {
154 ASSERT3U(dn->dn_next_nlevels[i], <=, dn->dn_nlevels);
157 if (dn->dn_phys->dn_type != DMU_OT_NONE)
158 ASSERT3U(dn->dn_phys->dn_nlevels, <=, dn->dn_nlevels);
159 ASSERT(dn->dn_object == DMU_META_DNODE_OBJECT || dn->dn_dbuf != NULL);
160 if (dn->dn_dbuf != NULL) {
161 ASSERT3P(dn->dn_phys, ==,
162 (dnode_phys_t *)dn->dn_dbuf->db.db_data +
163 (dn->dn_object % (dn->dn_dbuf->db.db_size >> DNODE_SHIFT)));
165 if (drop_struct_lock)
166 rw_exit(&dn->dn_struct_rwlock);
171 dnode_byteswap(dnode_phys_t *dnp)
173 uint64_t *buf64 = (void*)&dnp->dn_blkptr;
176 if (dnp->dn_type == DMU_OT_NONE) {
177 bzero(dnp, sizeof (dnode_phys_t));
181 dnp->dn_datablkszsec = BSWAP_16(dnp->dn_datablkszsec);
182 dnp->dn_bonuslen = BSWAP_16(dnp->dn_bonuslen);
183 dnp->dn_maxblkid = BSWAP_64(dnp->dn_maxblkid);
184 dnp->dn_used = BSWAP_64(dnp->dn_used);
187 * dn_nblkptr is only one byte, so it's OK to read it in either
188 * byte order. We can't read dn_bouslen.
190 ASSERT(dnp->dn_indblkshift <= SPA_MAXBLOCKSHIFT);
191 ASSERT(dnp->dn_nblkptr <= DN_MAX_NBLKPTR);
192 for (i = 0; i < dnp->dn_nblkptr * sizeof (blkptr_t)/8; i++)
193 buf64[i] = BSWAP_64(buf64[i]);
196 * OK to check dn_bonuslen for zero, because it won't matter if
197 * we have the wrong byte order. This is necessary because the
198 * dnode dnode is smaller than a regular dnode.
200 if (dnp->dn_bonuslen != 0) {
202 * Note that the bonus length calculated here may be
203 * longer than the actual bonus buffer. This is because
204 * we always put the bonus buffer after the last block
205 * pointer (instead of packing it against the end of the
208 int off = (dnp->dn_nblkptr-1) * sizeof (blkptr_t);
209 size_t len = DN_MAX_BONUSLEN - off;
210 ASSERT3U(dnp->dn_bonustype, <, DMU_OT_NUMTYPES);
211 dmu_ot[dnp->dn_bonustype].ot_byteswap(dnp->dn_bonus + off, len);
216 dnode_buf_byteswap(void *vbuf, size_t size)
218 dnode_phys_t *buf = vbuf;
221 ASSERT3U(sizeof (dnode_phys_t), ==, (1<<DNODE_SHIFT));
222 ASSERT((size & (sizeof (dnode_phys_t)-1)) == 0);
224 size >>= DNODE_SHIFT;
225 for (i = 0; i < size; i++) {
232 free_range_compar(const void *node1, const void *node2)
234 const free_range_t *rp1 = node1;
235 const free_range_t *rp2 = node2;
237 if (rp1->fr_blkid < rp2->fr_blkid)
239 else if (rp1->fr_blkid > rp2->fr_blkid)
245 dnode_setbonuslen(dnode_t *dn, int newsize, dmu_tx_t *tx)
247 ASSERT3U(refcount_count(&dn->dn_holds), >=, 1);
249 dnode_setdirty(dn, tx);
250 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
251 ASSERT3U(newsize, <=, DN_MAX_BONUSLEN -
252 (dn->dn_nblkptr-1) * sizeof (blkptr_t));
253 dn->dn_bonuslen = newsize;
255 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = DN_ZERO_BONUSLEN;
257 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = dn->dn_bonuslen;
258 rw_exit(&dn->dn_struct_rwlock);
262 dnode_setdblksz(dnode_t *dn, int size)
264 ASSERT3U(P2PHASE(size, SPA_MINBLOCKSIZE), ==, 0);
265 ASSERT3U(size, <=, SPA_MAXBLOCKSIZE);
266 ASSERT3U(size, >=, SPA_MINBLOCKSIZE);
267 ASSERT3U(size >> SPA_MINBLOCKSHIFT, <,
268 1<<(sizeof (dn->dn_phys->dn_datablkszsec) * 8));
269 dn->dn_datablksz = size;
270 dn->dn_datablkszsec = size >> SPA_MINBLOCKSHIFT;
271 dn->dn_datablkshift = ISP2(size) ? highbit(size - 1) : 0;
275 dnode_create(objset_impl_t *os, dnode_phys_t *dnp, dmu_buf_impl_t *db,
278 dnode_t *dn = kmem_cache_alloc(dnode_cache, KM_SLEEP);
281 dn->dn_object = object;
285 if (dnp->dn_datablkszsec)
286 dnode_setdblksz(dn, dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
287 dn->dn_indblkshift = dnp->dn_indblkshift;
288 dn->dn_nlevels = dnp->dn_nlevels;
289 dn->dn_type = dnp->dn_type;
290 dn->dn_nblkptr = dnp->dn_nblkptr;
291 dn->dn_checksum = dnp->dn_checksum;
292 dn->dn_compress = dnp->dn_compress;
293 dn->dn_bonustype = dnp->dn_bonustype;
294 dn->dn_bonuslen = dnp->dn_bonuslen;
295 dn->dn_maxblkid = dnp->dn_maxblkid;
297 dmu_zfetch_init(&dn->dn_zfetch, dn);
299 ASSERT(dn->dn_phys->dn_type < DMU_OT_NUMTYPES);
300 mutex_enter(&os->os_lock);
301 list_insert_head(&os->os_dnodes, dn);
302 mutex_exit(&os->os_lock);
304 arc_space_consume(sizeof (dnode_t), ARC_SPACE_OTHER);
309 dnode_destroy(dnode_t *dn)
311 objset_impl_t *os = dn->dn_objset;
316 for (i = 0; i < TXG_SIZE; i++) {
317 ASSERT(!list_link_active(&dn->dn_dirty_link[i]));
318 ASSERT(NULL == list_head(&dn->dn_dirty_records[i]));
319 ASSERT(0 == avl_numnodes(&dn->dn_ranges[i]));
321 ASSERT(NULL == list_head(&dn->dn_dbufs));
324 mutex_enter(&os->os_lock);
325 list_remove(&os->os_dnodes, dn);
326 mutex_exit(&os->os_lock);
328 if (dn->dn_dirtyctx_firstset) {
329 kmem_free(dn->dn_dirtyctx_firstset, 1);
330 dn->dn_dirtyctx_firstset = NULL;
332 dmu_zfetch_rele(&dn->dn_zfetch);
334 mutex_enter(&dn->dn_bonus->db_mtx);
335 dbuf_evict(dn->dn_bonus);
338 kmem_cache_free(dnode_cache, dn);
339 arc_space_return(sizeof (dnode_t), ARC_SPACE_OTHER);
343 dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs,
344 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
349 blocksize = 1 << zfs_default_bs;
350 else if (blocksize > SPA_MAXBLOCKSIZE)
351 blocksize = SPA_MAXBLOCKSIZE;
353 blocksize = P2ROUNDUP(blocksize, SPA_MINBLOCKSIZE);
356 ibs = zfs_default_ibs;
358 ibs = MIN(MAX(ibs, DN_MIN_INDBLKSHIFT), DN_MAX_INDBLKSHIFT);
360 dprintf("os=%p obj=%llu txg=%llu blocksize=%d ibs=%d\n", dn->dn_objset,
361 dn->dn_object, tx->tx_txg, blocksize, ibs);
363 ASSERT(dn->dn_type == DMU_OT_NONE);
364 ASSERT(bcmp(dn->dn_phys, &dnode_phys_zero, sizeof (dnode_phys_t)) == 0);
365 ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE);
366 ASSERT(ot != DMU_OT_NONE);
367 ASSERT3U(ot, <, DMU_OT_NUMTYPES);
368 ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) ||
369 (bonustype != DMU_OT_NONE && bonuslen != 0));
370 ASSERT3U(bonustype, <, DMU_OT_NUMTYPES);
371 ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN);
372 ASSERT(dn->dn_type == DMU_OT_NONE);
373 ASSERT3U(dn->dn_maxblkid, ==, 0);
374 ASSERT3U(dn->dn_allocated_txg, ==, 0);
375 ASSERT3U(dn->dn_assigned_txg, ==, 0);
376 ASSERT(refcount_is_zero(&dn->dn_tx_holds));
377 ASSERT3U(refcount_count(&dn->dn_holds), <=, 1);
378 ASSERT3P(list_head(&dn->dn_dbufs), ==, NULL);
380 for (i = 0; i < TXG_SIZE; i++) {
381 ASSERT3U(dn->dn_next_nlevels[i], ==, 0);
382 ASSERT3U(dn->dn_next_indblkshift[i], ==, 0);
383 ASSERT3U(dn->dn_next_bonuslen[i], ==, 0);
384 ASSERT3U(dn->dn_next_blksz[i], ==, 0);
385 ASSERT(!list_link_active(&dn->dn_dirty_link[i]));
386 ASSERT3P(list_head(&dn->dn_dirty_records[i]), ==, NULL);
387 ASSERT3U(avl_numnodes(&dn->dn_ranges[i]), ==, 0);
391 dnode_setdblksz(dn, blocksize);
392 dn->dn_indblkshift = ibs;
394 dn->dn_nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT);
395 dn->dn_bonustype = bonustype;
396 dn->dn_bonuslen = bonuslen;
397 dn->dn_checksum = ZIO_CHECKSUM_INHERIT;
398 dn->dn_compress = ZIO_COMPRESS_INHERIT;
402 if (dn->dn_dirtyctx_firstset) {
403 kmem_free(dn->dn_dirtyctx_firstset, 1);
404 dn->dn_dirtyctx_firstset = NULL;
407 dn->dn_allocated_txg = tx->tx_txg;
409 dnode_setdirty(dn, tx);
410 dn->dn_next_indblkshift[tx->tx_txg & TXG_MASK] = ibs;
411 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = dn->dn_bonuslen;
412 dn->dn_next_blksz[tx->tx_txg & TXG_MASK] = dn->dn_datablksz;
416 dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize,
417 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
421 ASSERT3U(blocksize, >=, SPA_MINBLOCKSIZE);
422 ASSERT3U(blocksize, <=, SPA_MAXBLOCKSIZE);
423 ASSERT3U(blocksize % SPA_MINBLOCKSIZE, ==, 0);
424 ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT || dmu_tx_private_ok(tx));
425 ASSERT(tx->tx_txg != 0);
426 ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) ||
427 (bonustype != DMU_OT_NONE && bonuslen != 0));
428 ASSERT3U(bonustype, <, DMU_OT_NUMTYPES);
429 ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN);
431 /* clean up any unreferenced dbufs */
432 dnode_evict_dbufs(dn);
434 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
435 dnode_setdirty(dn, tx);
436 if (dn->dn_datablksz != blocksize) {
437 /* change blocksize */
438 ASSERT(dn->dn_maxblkid == 0 &&
439 (BP_IS_HOLE(&dn->dn_phys->dn_blkptr[0]) ||
440 dnode_block_freed(dn, 0)));
441 dnode_setdblksz(dn, blocksize);
442 dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = blocksize;
444 if (dn->dn_bonuslen != bonuslen)
445 dn->dn_next_bonuslen[tx->tx_txg&TXG_MASK] = bonuslen;
446 nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT);
447 if (dn->dn_nblkptr != nblkptr)
448 dn->dn_next_nblkptr[tx->tx_txg&TXG_MASK] = nblkptr;
449 rw_exit(&dn->dn_struct_rwlock);
454 /* change bonus size and type */
455 mutex_enter(&dn->dn_mtx);
456 dn->dn_bonustype = bonustype;
457 dn->dn_bonuslen = bonuslen;
458 dn->dn_nblkptr = nblkptr;
459 dn->dn_checksum = ZIO_CHECKSUM_INHERIT;
460 dn->dn_compress = ZIO_COMPRESS_INHERIT;
461 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR);
463 /* fix up the bonus db_size */
465 dn->dn_bonus->db.db_size =
466 DN_MAX_BONUSLEN - (dn->dn_nblkptr-1) * sizeof (blkptr_t);
467 ASSERT(dn->dn_bonuslen <= dn->dn_bonus->db.db_size);
470 dn->dn_allocated_txg = tx->tx_txg;
471 mutex_exit(&dn->dn_mtx);
475 dnode_special_close(dnode_t *dn)
478 * Wait for final references to the dnode to clear. This can
479 * only happen if the arc is asyncronously evicting state that
480 * has a hold on this dnode while we are trying to evict this
483 while (refcount_count(&dn->dn_holds) > 0)
489 dnode_special_open(objset_impl_t *os, dnode_phys_t *dnp, uint64_t object)
491 dnode_t *dn = dnode_create(os, dnp, NULL, object);
497 dnode_buf_pageout(dmu_buf_t *db, void *arg)
499 dnode_t **children_dnodes = arg;
501 int epb = db->db_size >> DNODE_SHIFT;
503 for (i = 0; i < epb; i++) {
504 dnode_t *dn = children_dnodes[i];
511 * If there are holds on this dnode, then there should
512 * be holds on the dnode's containing dbuf as well; thus
513 * it wouldn't be eligable for eviction and this function
514 * would not have been called.
516 ASSERT(refcount_is_zero(&dn->dn_holds));
517 ASSERT(list_head(&dn->dn_dbufs) == NULL);
518 ASSERT(refcount_is_zero(&dn->dn_tx_holds));
520 for (n = 0; n < TXG_SIZE; n++)
521 ASSERT(!list_link_active(&dn->dn_dirty_link[n]));
523 children_dnodes[i] = NULL;
526 kmem_free(children_dnodes, epb * sizeof (dnode_t *));
531 * EINVAL - invalid object number.
533 * succeeds even for free dnodes.
536 dnode_hold_impl(objset_impl_t *os, uint64_t object, int flag,
537 void *tag, dnode_t **dnp)
540 int drop_struct_lock = FALSE;
545 dnode_t **children_dnodes;
548 * If you are holding the spa config lock as writer, you shouldn't
549 * be asking the DMU to do *anything*.
551 ASSERT(spa_config_held(os->os_spa, SCL_ALL, RW_WRITER) == 0);
553 if (object == 0 || object >= DN_MAX_OBJECT)
556 mdn = os->os_meta_dnode;
560 if (!RW_WRITE_HELD(&mdn->dn_struct_rwlock)) {
561 rw_enter(&mdn->dn_struct_rwlock, RW_READER);
562 drop_struct_lock = TRUE;
565 blk = dbuf_whichblock(mdn, object * sizeof (dnode_phys_t));
567 db = dbuf_hold(mdn, blk, FTAG);
568 if (drop_struct_lock)
569 rw_exit(&mdn->dn_struct_rwlock);
572 err = dbuf_read(db, NULL, DB_RF_CANFAIL);
578 ASSERT3U(db->db.db_size, >=, 1<<DNODE_SHIFT);
579 epb = db->db.db_size >> DNODE_SHIFT;
581 idx = object & (epb-1);
583 children_dnodes = dmu_buf_get_user(&db->db);
584 if (children_dnodes == NULL) {
586 children_dnodes = kmem_zalloc(epb * sizeof (dnode_t *),
588 if (winner = dmu_buf_set_user(&db->db, children_dnodes, NULL,
589 dnode_buf_pageout)) {
590 kmem_free(children_dnodes, epb * sizeof (dnode_t *));
591 children_dnodes = winner;
595 if ((dn = children_dnodes[idx]) == NULL) {
596 dnode_phys_t *dnp = (dnode_phys_t *)db->db.db_data+idx;
599 dn = dnode_create(os, dnp, db, object);
600 winner = atomic_cas_ptr(&children_dnodes[idx], NULL, dn);
601 if (winner != NULL) {
607 mutex_enter(&dn->dn_mtx);
609 if (dn->dn_free_txg ||
610 ((flag & DNODE_MUST_BE_ALLOCATED) && type == DMU_OT_NONE) ||
611 ((flag & DNODE_MUST_BE_FREE) && type != DMU_OT_NONE)) {
612 mutex_exit(&dn->dn_mtx);
614 return (type == DMU_OT_NONE ? ENOENT : EEXIST);
616 mutex_exit(&dn->dn_mtx);
618 if (refcount_add(&dn->dn_holds, tag) == 1)
619 dbuf_add_ref(db, dn);
622 ASSERT3P(dn->dn_dbuf, ==, db);
623 ASSERT3U(dn->dn_object, ==, object);
631 * Return held dnode if the object is allocated, NULL if not.
634 dnode_hold(objset_impl_t *os, uint64_t object, void *tag, dnode_t **dnp)
636 return (dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED, tag, dnp));
640 * Can only add a reference if there is already at least one
641 * reference on the dnode. Returns FALSE if unable to add a
645 dnode_add_ref(dnode_t *dn, void *tag)
647 mutex_enter(&dn->dn_mtx);
648 if (refcount_is_zero(&dn->dn_holds)) {
649 mutex_exit(&dn->dn_mtx);
652 VERIFY(1 < refcount_add(&dn->dn_holds, tag));
653 mutex_exit(&dn->dn_mtx);
658 dnode_rele(dnode_t *dn, void *tag)
662 mutex_enter(&dn->dn_mtx);
663 refs = refcount_remove(&dn->dn_holds, tag);
664 mutex_exit(&dn->dn_mtx);
665 /* NOTE: the DNODE_DNODE does not have a dn_dbuf */
666 if (refs == 0 && dn->dn_dbuf)
667 dbuf_rele(dn->dn_dbuf, dn);
671 dnode_setdirty(dnode_t *dn, dmu_tx_t *tx)
673 objset_impl_t *os = dn->dn_objset;
674 uint64_t txg = tx->tx_txg;
676 if (dn->dn_object == DMU_META_DNODE_OBJECT)
682 mutex_enter(&dn->dn_mtx);
683 ASSERT(dn->dn_phys->dn_type || dn->dn_allocated_txg);
684 /* ASSERT(dn->dn_free_txg == 0 || dn->dn_free_txg >= txg); */
685 mutex_exit(&dn->dn_mtx);
688 mutex_enter(&os->os_lock);
691 * If we are already marked dirty, we're done.
693 if (list_link_active(&dn->dn_dirty_link[txg & TXG_MASK])) {
694 mutex_exit(&os->os_lock);
698 ASSERT(!refcount_is_zero(&dn->dn_holds) || list_head(&dn->dn_dbufs));
699 ASSERT(dn->dn_datablksz != 0);
700 ASSERT3U(dn->dn_next_bonuslen[txg&TXG_MASK], ==, 0);
701 ASSERT3U(dn->dn_next_blksz[txg&TXG_MASK], ==, 0);
703 dprintf_ds(os->os_dsl_dataset, "obj=%llu txg=%llu\n",
706 if (dn->dn_free_txg > 0 && dn->dn_free_txg <= txg) {
707 list_insert_tail(&os->os_free_dnodes[txg&TXG_MASK], dn);
709 list_insert_tail(&os->os_dirty_dnodes[txg&TXG_MASK], dn);
712 mutex_exit(&os->os_lock);
715 * The dnode maintains a hold on its containing dbuf as
716 * long as there are holds on it. Each instantiated child
717 * dbuf maintaines a hold on the dnode. When the last child
718 * drops its hold, the dnode will drop its hold on the
719 * containing dbuf. We add a "dirty hold" here so that the
720 * dnode will hang around after we finish processing its
723 VERIFY(dnode_add_ref(dn, (void *)(uintptr_t)tx->tx_txg));
725 (void) dbuf_dirty(dn->dn_dbuf, tx);
727 dsl_dataset_dirty(os->os_dsl_dataset, tx);
731 dnode_free(dnode_t *dn, dmu_tx_t *tx)
733 int txgoff = tx->tx_txg & TXG_MASK;
735 dprintf("dn=%p txg=%llu\n", dn, tx->tx_txg);
737 /* we should be the only holder... hopefully */
738 /* ASSERT3U(refcount_count(&dn->dn_holds), ==, 1); */
740 mutex_enter(&dn->dn_mtx);
741 if (dn->dn_type == DMU_OT_NONE || dn->dn_free_txg) {
742 mutex_exit(&dn->dn_mtx);
745 dn->dn_free_txg = tx->tx_txg;
746 mutex_exit(&dn->dn_mtx);
749 * If the dnode is already dirty, it needs to be moved from
750 * the dirty list to the free list.
752 mutex_enter(&dn->dn_objset->os_lock);
753 if (list_link_active(&dn->dn_dirty_link[txgoff])) {
754 list_remove(&dn->dn_objset->os_dirty_dnodes[txgoff], dn);
755 list_insert_tail(&dn->dn_objset->os_free_dnodes[txgoff], dn);
756 mutex_exit(&dn->dn_objset->os_lock);
758 mutex_exit(&dn->dn_objset->os_lock);
759 dnode_setdirty(dn, tx);
764 * Try to change the block size for the indicated dnode. This can only
765 * succeed if there are no blocks allocated or dirty beyond first block
768 dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx)
770 dmu_buf_impl_t *db, *db_next;
774 size = SPA_MINBLOCKSIZE;
775 if (size > SPA_MAXBLOCKSIZE)
776 size = SPA_MAXBLOCKSIZE;
778 size = P2ROUNDUP(size, SPA_MINBLOCKSIZE);
780 if (ibs == dn->dn_indblkshift)
783 if (size >> SPA_MINBLOCKSHIFT == dn->dn_datablkszsec && ibs == 0)
786 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
788 /* Check for any allocated blocks beyond the first */
789 if (dn->dn_phys->dn_maxblkid != 0)
792 mutex_enter(&dn->dn_dbufs_mtx);
793 for (db = list_head(&dn->dn_dbufs); db; db = db_next) {
794 db_next = list_next(&dn->dn_dbufs, db);
796 if (db->db_blkid != 0 && db->db_blkid != DB_BONUS_BLKID) {
797 mutex_exit(&dn->dn_dbufs_mtx);
801 mutex_exit(&dn->dn_dbufs_mtx);
803 if (ibs && dn->dn_nlevels != 1)
806 /* resize the old block */
807 err = dbuf_hold_impl(dn, 0, 0, TRUE, FTAG, &db);
809 dbuf_new_size(db, size, tx);
810 else if (err != ENOENT)
813 dnode_setdblksz(dn, size);
814 dnode_setdirty(dn, tx);
815 dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = size;
817 dn->dn_indblkshift = ibs;
818 dn->dn_next_indblkshift[tx->tx_txg&TXG_MASK] = ibs;
820 /* rele after we have fixed the blocksize in the dnode */
824 rw_exit(&dn->dn_struct_rwlock);
828 rw_exit(&dn->dn_struct_rwlock);
832 /* read-holding callers must not rely on the lock being continuously held */
834 dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t have_read)
836 uint64_t txgoff = tx->tx_txg & TXG_MASK;
837 int epbs, new_nlevels;
840 ASSERT(blkid != DB_BONUS_BLKID);
843 RW_READ_HELD(&dn->dn_struct_rwlock) :
844 RW_WRITE_HELD(&dn->dn_struct_rwlock));
847 * if we have a read-lock, check to see if we need to do any work
848 * before upgrading to a write-lock.
851 if (blkid <= dn->dn_maxblkid)
854 if (!rw_tryupgrade(&dn->dn_struct_rwlock)) {
855 rw_exit(&dn->dn_struct_rwlock);
856 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
860 if (blkid <= dn->dn_maxblkid)
863 dn->dn_maxblkid = blkid;
866 * Compute the number of levels necessary to support the new maxblkid.
869 epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT;
870 for (sz = dn->dn_nblkptr;
871 sz <= blkid && sz >= dn->dn_nblkptr; sz <<= epbs)
874 if (new_nlevels > dn->dn_nlevels) {
875 int old_nlevels = dn->dn_nlevels;
878 dbuf_dirty_record_t *new, *dr, *dr_next;
880 dn->dn_nlevels = new_nlevels;
882 ASSERT3U(new_nlevels, >, dn->dn_next_nlevels[txgoff]);
883 dn->dn_next_nlevels[txgoff] = new_nlevels;
885 /* dirty the left indirects */
886 db = dbuf_hold_level(dn, old_nlevels, 0, FTAG);
887 new = dbuf_dirty(db, tx);
890 /* transfer the dirty records to the new indirect */
891 mutex_enter(&dn->dn_mtx);
892 mutex_enter(&new->dt.di.dr_mtx);
893 list = &dn->dn_dirty_records[txgoff];
894 for (dr = list_head(list); dr; dr = dr_next) {
895 dr_next = list_next(&dn->dn_dirty_records[txgoff], dr);
896 if (dr->dr_dbuf->db_level != new_nlevels-1 &&
897 dr->dr_dbuf->db_blkid != DB_BONUS_BLKID) {
898 ASSERT(dr->dr_dbuf->db_level == old_nlevels-1);
899 list_remove(&dn->dn_dirty_records[txgoff], dr);
900 list_insert_tail(&new->dt.di.dr_children, dr);
904 mutex_exit(&new->dt.di.dr_mtx);
905 mutex_exit(&dn->dn_mtx);
910 rw_downgrade(&dn->dn_struct_rwlock);
914 dnode_clear_range(dnode_t *dn, uint64_t blkid, uint64_t nblks, dmu_tx_t *tx)
916 avl_tree_t *tree = &dn->dn_ranges[tx->tx_txg&TXG_MASK];
919 free_range_t rp_tofind;
920 uint64_t endblk = blkid + nblks;
922 ASSERT(MUTEX_HELD(&dn->dn_mtx));
923 ASSERT(nblks <= UINT64_MAX - blkid); /* no overflow */
925 dprintf_dnode(dn, "blkid=%llu nblks=%llu txg=%llu\n",
926 blkid, nblks, tx->tx_txg);
927 rp_tofind.fr_blkid = blkid;
928 rp = avl_find(tree, &rp_tofind, &where);
930 rp = avl_nearest(tree, where, AVL_BEFORE);
932 rp = avl_nearest(tree, where, AVL_AFTER);
934 while (rp && (rp->fr_blkid <= blkid + nblks)) {
935 uint64_t fr_endblk = rp->fr_blkid + rp->fr_nblks;
936 free_range_t *nrp = AVL_NEXT(tree, rp);
938 if (blkid <= rp->fr_blkid && endblk >= fr_endblk) {
939 /* clear this entire range */
940 avl_remove(tree, rp);
941 kmem_free(rp, sizeof (free_range_t));
942 } else if (blkid <= rp->fr_blkid &&
943 endblk > rp->fr_blkid && endblk < fr_endblk) {
944 /* clear the beginning of this range */
945 rp->fr_blkid = endblk;
946 rp->fr_nblks = fr_endblk - endblk;
947 } else if (blkid > rp->fr_blkid && blkid < fr_endblk &&
948 endblk >= fr_endblk) {
949 /* clear the end of this range */
950 rp->fr_nblks = blkid - rp->fr_blkid;
951 } else if (blkid > rp->fr_blkid && endblk < fr_endblk) {
952 /* clear a chunk out of this range */
953 free_range_t *new_rp =
954 kmem_alloc(sizeof (free_range_t), KM_SLEEP);
956 new_rp->fr_blkid = endblk;
957 new_rp->fr_nblks = fr_endblk - endblk;
958 avl_insert_here(tree, new_rp, rp, AVL_AFTER);
959 rp->fr_nblks = blkid - rp->fr_blkid;
961 /* there may be no overlap */
967 dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx)
970 uint64_t blkoff, blkid, nblks;
971 int blksz, blkshift, head, tail;
975 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
976 blksz = dn->dn_datablksz;
977 blkshift = dn->dn_datablkshift;
978 epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT;
981 len = UINT64_MAX - off;
986 * First, block align the region to free:
989 head = P2NPHASE(off, blksz);
990 blkoff = P2PHASE(off, blksz);
991 if ((off >> blkshift) > dn->dn_maxblkid)
994 ASSERT(dn->dn_maxblkid == 0);
995 if (off == 0 && len >= blksz) {
996 /* Freeing the whole block; fast-track this request */
1000 } else if (off >= blksz) {
1001 /* Freeing past end-of-data */
1004 /* Freeing part of the block. */
1006 ASSERT3U(head, >, 0);
1010 /* zero out any partial block data at the start of the range */
1012 ASSERT3U(blkoff + head, ==, blksz);
1015 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, off), TRUE,
1019 /* don't dirty if it isn't on disk and isn't dirty */
1020 if (db->db_last_dirty ||
1021 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) {
1022 rw_exit(&dn->dn_struct_rwlock);
1023 dbuf_will_dirty(db, tx);
1024 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
1025 data = db->db.db_data;
1026 bzero(data + blkoff, head);
1028 dbuf_rele(db, FTAG);
1034 /* If the range was less than one block, we're done */
1038 /* If the remaining range is past end of file, we're done */
1039 if ((off >> blkshift) > dn->dn_maxblkid)
1042 ASSERT(ISP2(blksz));
1046 tail = P2PHASE(len, blksz);
1048 ASSERT3U(P2PHASE(off, blksz), ==, 0);
1049 /* zero out any partial block data at the end of the range */
1053 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, off+len),
1054 TRUE, FTAG, &db) == 0) {
1055 /* don't dirty if not on disk and not dirty */
1056 if (db->db_last_dirty ||
1057 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) {
1058 rw_exit(&dn->dn_struct_rwlock);
1059 dbuf_will_dirty(db, tx);
1060 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
1061 bzero(db->db.db_data, tail);
1063 dbuf_rele(db, FTAG);
1068 /* If the range did not include a full block, we are done */
1072 ASSERT(IS_P2ALIGNED(off, blksz));
1073 ASSERT(trunc || IS_P2ALIGNED(len, blksz));
1074 blkid = off >> blkshift;
1075 nblks = len >> blkshift;
1080 * Read in and mark all the level-1 indirects dirty,
1081 * so that they will stay in memory until syncing phase.
1082 * Always dirty the first and last indirect to make sure
1083 * we dirty all the partial indirects.
1085 if (dn->dn_nlevels > 1) {
1086 uint64_t i, first, last;
1087 int shift = epbs + dn->dn_datablkshift;
1089 first = blkid >> epbs;
1090 if (db = dbuf_hold_level(dn, 1, first, FTAG)) {
1091 dbuf_will_dirty(db, tx);
1092 dbuf_rele(db, FTAG);
1095 last = dn->dn_maxblkid >> epbs;
1097 last = (blkid + nblks - 1) >> epbs;
1098 if (last > first && (db = dbuf_hold_level(dn, 1, last, FTAG))) {
1099 dbuf_will_dirty(db, tx);
1100 dbuf_rele(db, FTAG);
1102 for (i = first + 1; i < last; i++) {
1103 uint64_t ibyte = i << shift;
1106 err = dnode_next_offset(dn,
1107 DNODE_FIND_HAVELOCK, &ibyte, 1, 1, 0);
1109 if (err == ESRCH || i >= last)
1112 db = dbuf_hold_level(dn, 1, i, FTAG);
1114 dbuf_will_dirty(db, tx);
1115 dbuf_rele(db, FTAG);
1121 * Add this range to the dnode range list.
1122 * We will finish up this free operation in the syncing phase.
1124 mutex_enter(&dn->dn_mtx);
1125 dnode_clear_range(dn, blkid, nblks, tx);
1127 free_range_t *rp, *found;
1129 avl_tree_t *tree = &dn->dn_ranges[tx->tx_txg&TXG_MASK];
1131 /* Add new range to dn_ranges */
1132 rp = kmem_alloc(sizeof (free_range_t), KM_SLEEP);
1133 rp->fr_blkid = blkid;
1134 rp->fr_nblks = nblks;
1135 found = avl_find(tree, rp, &where);
1136 ASSERT(found == NULL);
1137 avl_insert(tree, rp, where);
1138 dprintf_dnode(dn, "blkid=%llu nblks=%llu txg=%llu\n",
1139 blkid, nblks, tx->tx_txg);
1141 mutex_exit(&dn->dn_mtx);
1143 dbuf_free_range(dn, blkid, blkid + nblks - 1, tx);
1144 dnode_setdirty(dn, tx);
1146 if (trunc && dn->dn_maxblkid >= (off >> blkshift))
1147 dn->dn_maxblkid = (off >> blkshift ? (off >> blkshift) - 1 : 0);
1149 rw_exit(&dn->dn_struct_rwlock);
1152 /* return TRUE if this blkid was freed in a recent txg, or FALSE if it wasn't */
1154 dnode_block_freed(dnode_t *dn, uint64_t blkid)
1156 free_range_t range_tofind;
1157 void *dp = spa_get_dsl(dn->dn_objset->os_spa);
1160 if (blkid == DB_BONUS_BLKID)
1164 * If we're in the process of opening the pool, dp will not be
1165 * set yet, but there shouldn't be anything dirty.
1170 if (dn->dn_free_txg)
1173 range_tofind.fr_blkid = blkid;
1174 mutex_enter(&dn->dn_mtx);
1175 for (i = 0; i < TXG_SIZE; i++) {
1176 free_range_t *range_found;
1179 range_found = avl_find(&dn->dn_ranges[i], &range_tofind, &idx);
1181 ASSERT(range_found->fr_nblks > 0);
1184 range_found = avl_nearest(&dn->dn_ranges[i], idx, AVL_BEFORE);
1186 range_found->fr_blkid + range_found->fr_nblks > blkid)
1189 mutex_exit(&dn->dn_mtx);
1190 return (i < TXG_SIZE);
1193 /* call from syncing context when we actually write/free space for this dnode */
1195 dnode_diduse_space(dnode_t *dn, int64_t delta)
1198 dprintf_dnode(dn, "dn=%p dnp=%p used=%llu delta=%lld\n",
1200 (u_longlong_t)dn->dn_phys->dn_used,
1203 mutex_enter(&dn->dn_mtx);
1204 space = DN_USED_BYTES(dn->dn_phys);
1206 ASSERT3U(space + delta, >=, space); /* no overflow */
1208 ASSERT3U(space, >=, -delta); /* no underflow */
1211 if (spa_version(dn->dn_objset->os_spa) < SPA_VERSION_DNODE_BYTES) {
1212 ASSERT((dn->dn_phys->dn_flags & DNODE_FLAG_USED_BYTES) == 0);
1213 ASSERT3U(P2PHASE(space, 1<<DEV_BSHIFT), ==, 0);
1214 dn->dn_phys->dn_used = space >> DEV_BSHIFT;
1216 dn->dn_phys->dn_used = space;
1217 dn->dn_phys->dn_flags |= DNODE_FLAG_USED_BYTES;
1219 mutex_exit(&dn->dn_mtx);
1223 * Call when we think we're going to write/free space in open context.
1224 * Be conservative (ie. OK to write less than this or free more than
1225 * this, but don't write more or free less).
1228 dnode_willuse_space(dnode_t *dn, int64_t space, dmu_tx_t *tx)
1230 objset_impl_t *os = dn->dn_objset;
1231 dsl_dataset_t *ds = os->os_dsl_dataset;
1234 space = spa_get_asize(os->os_spa, space);
1237 dsl_dir_willuse_space(ds->ds_dir, space, tx);
1239 dmu_tx_willuse_space(tx, space);
1243 * This function scans a block at the indicated "level" looking for
1244 * a hole or data (depending on 'flags'). If level > 0, then we are
1245 * scanning an indirect block looking at its pointers. If level == 0,
1246 * then we are looking at a block of dnodes. If we don't find what we
1247 * are looking for in the block, we return ESRCH. Otherwise, return
1248 * with *offset pointing to the beginning (if searching forwards) or
1249 * end (if searching backwards) of the range covered by the block
1250 * pointer we matched on (or dnode).
1252 * The basic search algorithm used below by dnode_next_offset() is to
1253 * use this function to search up the block tree (widen the search) until
1254 * we find something (i.e., we don't return ESRCH) and then search back
1255 * down the tree (narrow the search) until we reach our original search
1259 dnode_next_offset_level(dnode_t *dn, int flags, uint64_t *offset,
1260 int lvl, uint64_t blkfill, uint64_t txg)
1262 dmu_buf_impl_t *db = NULL;
1264 uint64_t epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
1265 uint64_t epb = 1ULL << epbs;
1266 uint64_t minfill, maxfill;
1268 int i, inc, error, span;
1270 dprintf("probing object %llu offset %llx level %d of %u\n",
1271 dn->dn_object, *offset, lvl, dn->dn_phys->dn_nlevels);
1273 hole = flags & DNODE_FIND_HOLE;
1274 inc = (flags & DNODE_FIND_BACKWARDS) ? -1 : 1;
1275 ASSERT(txg == 0 || !hole);
1277 if (lvl == dn->dn_phys->dn_nlevels) {
1279 epb = dn->dn_phys->dn_nblkptr;
1280 data = dn->dn_phys->dn_blkptr;
1282 uint64_t blkid = dbuf_whichblock(dn, *offset) >> (epbs * lvl);
1283 error = dbuf_hold_impl(dn, lvl, blkid, TRUE, FTAG, &db);
1285 if (error != ENOENT)
1290 * This can only happen when we are searching up
1291 * the block tree for data. We don't really need to
1292 * adjust the offset, as we will just end up looking
1293 * at the pointer to this block in its parent, and its
1294 * going to be unallocated, so we will skip over it.
1298 error = dbuf_read(db, NULL, DB_RF_CANFAIL | DB_RF_HAVESTRUCT);
1300 dbuf_rele(db, FTAG);
1303 data = db->db.db_data;
1307 (db->db_blkptr == NULL || db->db_blkptr->blk_birth <= txg)) {
1309 * This can only happen when we are searching up the tree
1310 * and these conditions mean that we need to keep climbing.
1313 } else if (lvl == 0) {
1314 dnode_phys_t *dnp = data;
1316 ASSERT(dn->dn_type == DMU_OT_DNODE);
1318 for (i = (*offset >> span) & (blkfill - 1);
1319 i >= 0 && i < blkfill; i += inc) {
1320 boolean_t newcontents = B_TRUE;
1323 newcontents = B_FALSE;
1324 for (j = 0; j < dnp[i].dn_nblkptr; j++) {
1325 if (dnp[i].dn_blkptr[j].blk_birth > txg)
1326 newcontents = B_TRUE;
1329 if (!dnp[i].dn_type == hole && newcontents)
1331 *offset += (1ULL << span) * inc;
1333 if (i < 0 || i == blkfill)
1336 blkptr_t *bp = data;
1337 uint64_t start = *offset;
1338 span = (lvl - 1) * epbs + dn->dn_datablkshift;
1340 maxfill = blkfill << ((lvl - 1) * epbs);
1347 *offset = *offset >> span;
1348 for (i = BF64_GET(*offset, 0, epbs);
1349 i >= 0 && i < epb; i += inc) {
1350 if (bp[i].blk_fill >= minfill &&
1351 bp[i].blk_fill <= maxfill &&
1352 (hole || bp[i].blk_birth > txg))
1354 if (inc > 0 || *offset > 0)
1357 *offset = *offset << span;
1359 /* traversing backwards; position offset at the end */
1360 ASSERT3U(*offset, <=, start);
1361 *offset = MIN(*offset + (1ULL << span) - 1, start);
1362 } else if (*offset < start) {
1365 if (i < 0 || i >= epb)
1370 dbuf_rele(db, FTAG);
1376 * Find the next hole, data, or sparse region at or after *offset.
1377 * The value 'blkfill' tells us how many items we expect to find
1378 * in an L0 data block; this value is 1 for normal objects,
1379 * DNODES_PER_BLOCK for the meta dnode, and some fraction of
1380 * DNODES_PER_BLOCK when searching for sparse regions thereof.
1384 * dnode_next_offset(dn, flags, offset, 1, 1, 0);
1385 * Finds the next/previous hole/data in a file.
1386 * Used in dmu_offset_next().
1388 * dnode_next_offset(mdn, flags, offset, 0, DNODES_PER_BLOCK, txg);
1389 * Finds the next free/allocated dnode an objset's meta-dnode.
1390 * Only finds objects that have new contents since txg (ie.
1391 * bonus buffer changes and content removal are ignored).
1392 * Used in dmu_object_next().
1394 * dnode_next_offset(mdn, DNODE_FIND_HOLE, offset, 2, DNODES_PER_BLOCK >> 2, 0);
1395 * Finds the next L2 meta-dnode bp that's at most 1/4 full.
1396 * Used in dmu_object_alloc().
1399 dnode_next_offset(dnode_t *dn, int flags, uint64_t *offset,
1400 int minlvl, uint64_t blkfill, uint64_t txg)
1402 uint64_t initial_offset = *offset;
1406 if (!(flags & DNODE_FIND_HAVELOCK))
1407 rw_enter(&dn->dn_struct_rwlock, RW_READER);
1409 if (dn->dn_phys->dn_nlevels == 0) {
1414 if (dn->dn_datablkshift == 0) {
1415 if (*offset < dn->dn_datablksz) {
1416 if (flags & DNODE_FIND_HOLE)
1417 *offset = dn->dn_datablksz;
1424 maxlvl = dn->dn_phys->dn_nlevels;
1426 for (lvl = minlvl; lvl <= maxlvl; lvl++) {
1427 error = dnode_next_offset_level(dn,
1428 flags, offset, lvl, blkfill, txg);
1433 while (error == 0 && --lvl >= minlvl) {
1434 error = dnode_next_offset_level(dn,
1435 flags, offset, lvl, blkfill, txg);
1438 if (error == 0 && (flags & DNODE_FIND_BACKWARDS ?
1439 initial_offset < *offset : initial_offset > *offset))
1442 if (!(flags & DNODE_FIND_HAVELOCK))
1443 rw_exit(&dn->dn_struct_rwlock);