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_tx.h>
31 #include <sys/dmu_objset.h>
32 #include <sys/dsl_dataset.h>
36 dnode_increase_indirection(dnode_t
*dn
, dmu_tx_t
*tx
)
39 int txgoff
= tx
->tx_txg
& TXG_MASK
;
40 int nblkptr
= dn
->dn_phys
->dn_nblkptr
;
41 int old_toplvl
= dn
->dn_phys
->dn_nlevels
- 1;
42 int new_level
= dn
->dn_next_nlevels
[txgoff
];
45 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
47 /* this dnode can't be paged out because it's dirty */
48 ASSERT(dn
->dn_phys
->dn_type
!= DMU_OT_NONE
);
49 ASSERT(RW_WRITE_HELD(&dn
->dn_struct_rwlock
));
50 ASSERT(new_level
> 1 && dn
->dn_phys
->dn_nlevels
> 0);
52 db
= dbuf_hold_level(dn
, dn
->dn_phys
->dn_nlevels
, 0, FTAG
);
55 dn
->dn_phys
->dn_nlevels
= new_level
;
56 dprintf("os=%p obj=%llu, increase to %d\n", dn
->dn_objset
,
57 dn
->dn_object
, dn
->dn_phys
->dn_nlevels
);
59 /* check for existing blkptrs in the dnode */
60 for (i
= 0; i
< nblkptr
; i
++)
61 if (!BP_IS_HOLE(&dn
->dn_phys
->dn_blkptr
[i
]))
64 /* transfer dnode's block pointers to new indirect block */
65 (void) dbuf_read(db
, NULL
, DB_RF_MUST_SUCCEED
|DB_RF_HAVESTRUCT
);
66 ASSERT(db
->db
.db_data
);
67 ASSERT(arc_released(db
->db_buf
));
68 ASSERT3U(sizeof (blkptr_t
) * nblkptr
, <=, db
->db
.db_size
);
69 bcopy(dn
->dn_phys
->dn_blkptr
, db
->db
.db_data
,
70 sizeof (blkptr_t
) * nblkptr
);
71 arc_buf_freeze(db
->db_buf
);
74 /* set dbuf's parent pointers to new indirect buf */
75 for (i
= 0; i
< nblkptr
; i
++) {
76 dmu_buf_impl_t
*child
= dbuf_find(dn
, old_toplvl
, i
);
80 ASSERT3P(child
->db_dnode
, ==, dn
);
81 if (child
->db_parent
&& child
->db_parent
!= dn
->dn_dbuf
) {
82 ASSERT(child
->db_parent
->db_level
== db
->db_level
);
83 ASSERT(child
->db_blkptr
!=
84 &dn
->dn_phys
->dn_blkptr
[child
->db_blkid
]);
85 mutex_exit(&child
->db_mtx
);
88 ASSERT(child
->db_parent
== NULL
||
89 child
->db_parent
== dn
->dn_dbuf
);
91 child
->db_parent
= db
;
92 dbuf_add_ref(db
, child
);
94 child
->db_blkptr
= (blkptr_t
*)db
->db
.db_data
+ i
;
96 child
->db_blkptr
= NULL
;
97 dprintf_dbuf_bp(child
, child
->db_blkptr
,
98 "changed db_blkptr to new indirect %s", "");
100 mutex_exit(&child
->db_mtx
);
103 bzero(dn
->dn_phys
->dn_blkptr
, sizeof (blkptr_t
) * nblkptr
);
107 rw_exit(&dn
->dn_struct_rwlock
);
111 free_blocks(dnode_t
*dn
, blkptr_t
*bp
, int num
, dmu_tx_t
*tx
)
113 dsl_dataset_t
*ds
= dn
->dn_objset
->os_dsl_dataset
;
114 uint64_t bytesfreed
= 0;
115 int i
, blocks_freed
= 0;
117 dprintf("ds=%p obj=%llx num=%d\n", ds
, dn
->dn_object
, num
);
119 for (i
= 0; i
< num
; i
++, bp
++) {
123 bytesfreed
+= dsl_dataset_block_kill(ds
, bp
, dn
->dn_zio
, tx
);
124 ASSERT3U(bytesfreed
, <=, DN_USED_BYTES(dn
->dn_phys
));
125 bzero(bp
, sizeof (blkptr_t
));
128 dnode_diduse_space(dn
, -bytesfreed
);
129 return (blocks_freed
);
134 free_verify(dmu_buf_impl_t
*db
, uint64_t start
, uint64_t end
, dmu_tx_t
*tx
)
138 uint64_t txg
= tx
->tx_txg
;
140 epbs
= db
->db_dnode
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
141 off
= start
- (db
->db_blkid
* 1<<epbs
);
142 num
= end
- start
+ 1;
144 ASSERT3U(off
, >=, 0);
145 ASSERT3U(num
, >=, 0);
146 ASSERT3U(db
->db_level
, >, 0);
147 ASSERT3U(db
->db
.db_size
, ==, 1<<db
->db_dnode
->dn_phys
->dn_indblkshift
);
148 ASSERT3U(off
+num
, <=, db
->db
.db_size
>> SPA_BLKPTRSHIFT
);
149 ASSERT(db
->db_blkptr
!= NULL
);
151 for (i
= off
; i
< off
+num
; i
++) {
153 dmu_buf_impl_t
*child
;
154 dbuf_dirty_record_t
*dr
;
157 ASSERT(db
->db_level
== 1);
159 rw_enter(&db
->db_dnode
->dn_struct_rwlock
, RW_READER
);
160 err
= dbuf_hold_impl(db
->db_dnode
, db
->db_level
-1,
161 (db
->db_blkid
<< epbs
) + i
, TRUE
, FTAG
, &child
);
162 rw_exit(&db
->db_dnode
->dn_struct_rwlock
);
166 ASSERT(child
->db_level
== 0);
167 dr
= child
->db_last_dirty
;
168 while (dr
&& dr
->dr_txg
> txg
)
170 ASSERT(dr
== NULL
|| dr
->dr_txg
== txg
);
172 /* data_old better be zeroed */
174 buf
= dr
->dt
.dl
.dr_data
->b_data
;
175 for (j
= 0; j
< child
->db
.db_size
>> 3; j
++) {
177 panic("freed data not zero: "
178 "child=%p i=%d off=%d num=%d\n",
179 (void *)child
, i
, off
, num
);
185 * db_data better be zeroed unless it's dirty in a
188 mutex_enter(&child
->db_mtx
);
189 buf
= child
->db
.db_data
;
190 if (buf
!= NULL
&& child
->db_state
!= DB_FILL
&&
191 child
->db_last_dirty
== NULL
) {
192 for (j
= 0; j
< child
->db
.db_size
>> 3; j
++) {
194 panic("freed data not zero: "
195 "child=%p i=%d off=%d num=%d\n",
196 (void *)child
, i
, off
, num
);
200 mutex_exit(&child
->db_mtx
);
202 dbuf_rele(child
, FTAG
);
210 free_children(dmu_buf_impl_t
*db
, uint64_t blkid
, uint64_t nblks
, int trunc
,
213 dnode_t
*dn
= db
->db_dnode
;
215 dmu_buf_impl_t
*subdb
;
216 uint64_t start
, end
, dbstart
, dbend
, i
;
217 int epbs
, shift
, err
;
219 int blocks_freed
= 0;
222 * There is a small possibility that this block will not be cached:
223 * 1 - if level > 1 and there are no children with level <= 1
224 * 2 - if we didn't get a dirty hold (because this block had just
225 * finished being written -- and so had no holds), and then this
226 * block got evicted before we got here.
228 if (db
->db_state
!= DB_CACHED
)
229 (void) dbuf_read(db
, NULL
, DB_RF_MUST_SUCCEED
);
231 arc_release(db
->db_buf
, db
);
232 bp
= (blkptr_t
*)db
->db
.db_data
;
234 epbs
= db
->db_dnode
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
235 shift
= (db
->db_level
- 1) * epbs
;
236 dbstart
= db
->db_blkid
<< epbs
;
237 start
= blkid
>> shift
;
238 if (dbstart
< start
) {
239 bp
+= start
- dbstart
;
244 dbend
= ((db
->db_blkid
+ 1) << epbs
) - 1;
245 end
= (blkid
+ nblks
- 1) >> shift
;
250 ASSERT3U(start
, <=, end
);
252 if (db
->db_level
== 1) {
253 FREE_VERIFY(db
, start
, end
, tx
);
254 blocks_freed
= free_blocks(dn
, bp
, end
-start
+1, tx
);
255 arc_buf_freeze(db
->db_buf
);
256 ASSERT(all
|| blocks_freed
== 0 || db
->db_last_dirty
);
257 return (all
? ALL
: blocks_freed
);
260 for (i
= start
; i
<= end
; i
++, bp
++) {
263 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
264 err
= dbuf_hold_impl(dn
, db
->db_level
-1, i
, TRUE
, FTAG
, &subdb
);
265 ASSERT3U(err
, ==, 0);
266 rw_exit(&dn
->dn_struct_rwlock
);
268 if (free_children(subdb
, blkid
, nblks
, trunc
, tx
) == ALL
) {
269 ASSERT3P(subdb
->db_blkptr
, ==, bp
);
270 blocks_freed
+= free_blocks(dn
, bp
, 1, tx
);
274 dbuf_rele(subdb
, FTAG
);
276 arc_buf_freeze(db
->db_buf
);
279 for (i
= start
; i
<= end
; i
++, bp
++) {
280 if (i
== start
&& blkid
!= 0)
282 else if (i
== end
&& !trunc
)
284 ASSERT3U(bp
->blk_birth
, ==, 0);
287 ASSERT(all
|| blocks_freed
== 0 || db
->db_last_dirty
);
288 return (all
? ALL
: blocks_freed
);
292 * free_range: Traverse the indicated range of the provided file
293 * and "free" all the blocks contained there.
296 dnode_sync_free_range(dnode_t
*dn
, uint64_t blkid
, uint64_t nblks
, dmu_tx_t
*tx
)
298 blkptr_t
*bp
= dn
->dn_phys
->dn_blkptr
;
300 int trunc
, start
, end
, shift
, i
, err
;
301 int dnlevel
= dn
->dn_phys
->dn_nlevels
;
303 if (blkid
> dn
->dn_phys
->dn_maxblkid
)
306 ASSERT(dn
->dn_phys
->dn_maxblkid
< UINT64_MAX
);
307 trunc
= blkid
+ nblks
> dn
->dn_phys
->dn_maxblkid
;
309 nblks
= dn
->dn_phys
->dn_maxblkid
- blkid
+ 1;
311 /* There are no indirect blocks in the object */
313 if (blkid
>= dn
->dn_phys
->dn_nblkptr
) {
314 /* this range was never made persistent */
317 ASSERT3U(blkid
+ nblks
, <=, dn
->dn_phys
->dn_nblkptr
);
318 (void) free_blocks(dn
, bp
+ blkid
, nblks
, tx
);
320 uint64_t off
= (dn
->dn_phys
->dn_maxblkid
+ 1) *
321 (dn
->dn_phys
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
);
322 dn
->dn_phys
->dn_maxblkid
= (blkid
? blkid
- 1 : 0);
323 ASSERT(off
< dn
->dn_phys
->dn_maxblkid
||
324 dn
->dn_phys
->dn_maxblkid
== 0 ||
325 dnode_next_offset(dn
, 0, &off
, 1, 1, 0) != 0);
330 shift
= (dnlevel
- 1) * (dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
);
331 start
= blkid
>> shift
;
332 ASSERT(start
< dn
->dn_phys
->dn_nblkptr
);
333 end
= (blkid
+ nblks
- 1) >> shift
;
335 for (i
= start
; i
<= end
; i
++, bp
++) {
338 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
339 err
= dbuf_hold_impl(dn
, dnlevel
-1, i
, TRUE
, FTAG
, &db
);
340 ASSERT3U(err
, ==, 0);
341 rw_exit(&dn
->dn_struct_rwlock
);
343 if (free_children(db
, blkid
, nblks
, trunc
, tx
) == ALL
) {
344 ASSERT3P(db
->db_blkptr
, ==, bp
);
345 (void) free_blocks(dn
, bp
, 1, tx
);
350 uint64_t off
= (dn
->dn_phys
->dn_maxblkid
+ 1) *
351 (dn
->dn_phys
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
);
352 dn
->dn_phys
->dn_maxblkid
= (blkid
? blkid
- 1 : 0);
353 ASSERT(off
< dn
->dn_phys
->dn_maxblkid
||
354 dn
->dn_phys
->dn_maxblkid
== 0 ||
355 dnode_next_offset(dn
, 0, &off
, 1, 1, 0) != 0);
360 * Try to kick all the dnodes dbufs out of the cache...
363 dnode_evict_dbufs(dnode_t
*dn
)
369 dmu_buf_impl_t
*db
, marker
;
370 int evicting
= FALSE
;
373 mutex_enter(&dn
->dn_dbufs_mtx
);
374 list_insert_tail(&dn
->dn_dbufs
, &marker
);
375 db
= list_head(&dn
->dn_dbufs
);
376 for (; db
!= &marker
; db
= list_head(&dn
->dn_dbufs
)) {
377 list_remove(&dn
->dn_dbufs
, db
);
378 list_insert_tail(&dn
->dn_dbufs
, db
);
379 ASSERT3P(db
->db_dnode
, ==, dn
);
381 mutex_enter(&db
->db_mtx
);
382 if (db
->db_state
== DB_EVICTING
) {
385 mutex_exit(&db
->db_mtx
);
386 } else if (refcount_is_zero(&db
->db_holds
)) {
388 dbuf_clear(db
); /* exits db_mtx for us */
390 mutex_exit(&db
->db_mtx
);
394 list_remove(&dn
->dn_dbufs
, &marker
);
396 * NB: we need to drop dn_dbufs_mtx between passes so
397 * that any DB_EVICTING dbufs can make progress.
398 * Ideally, we would have some cv we could wait on, but
399 * since we don't, just wait a bit to give the other
400 * thread a chance to run.
402 mutex_exit(&dn
->dn_dbufs_mtx
);
406 ASSERT(pass
< 100); /* sanity check */
409 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
410 if (dn
->dn_bonus
&& refcount_is_zero(&dn
->dn_bonus
->db_holds
)) {
411 mutex_enter(&dn
->dn_bonus
->db_mtx
);
412 dbuf_evict(dn
->dn_bonus
);
415 rw_exit(&dn
->dn_struct_rwlock
);
419 dnode_undirty_dbufs(list_t
*list
)
421 dbuf_dirty_record_t
*dr
;
423 while (dr
= list_head(list
)) {
424 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
425 uint64_t txg
= dr
->dr_txg
;
427 mutex_enter(&db
->db_mtx
);
428 /* XXX - use dbuf_undirty()? */
429 list_remove(list
, dr
);
430 ASSERT(db
->db_last_dirty
== dr
);
431 db
->db_last_dirty
= NULL
;
432 db
->db_dirtycnt
-= 1;
433 if (db
->db_level
== 0) {
434 ASSERT(db
->db_blkid
== DB_BONUS_BLKID
||
435 dr
->dt
.dl
.dr_data
== db
->db_buf
);
437 mutex_exit(&db
->db_mtx
);
439 mutex_exit(&db
->db_mtx
);
440 dnode_undirty_dbufs(&dr
->dt
.di
.dr_children
);
442 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
443 dbuf_rele(db
, (void *)(uintptr_t)txg
);
448 dnode_sync_free(dnode_t
*dn
, dmu_tx_t
*tx
)
450 int txgoff
= tx
->tx_txg
& TXG_MASK
;
452 ASSERT(dmu_tx_is_syncing(tx
));
455 * Our contents should have been freed in dnode_sync() by the
456 * free range record inserted by the caller of dnode_free().
458 ASSERT3U(DN_USED_BYTES(dn
->dn_phys
), ==, 0);
459 ASSERT(BP_IS_HOLE(dn
->dn_phys
->dn_blkptr
));
461 dnode_undirty_dbufs(&dn
->dn_dirty_records
[txgoff
]);
462 dnode_evict_dbufs(dn
);
463 ASSERT3P(list_head(&dn
->dn_dbufs
), ==, NULL
);
466 * XXX - It would be nice to assert this, but we may still
467 * have residual holds from async evictions from the arc...
469 * zfs_obj_to_path() also depends on this being
472 * ASSERT3U(refcount_count(&dn->dn_holds), ==, 1);
475 /* Undirty next bits */
476 dn
->dn_next_nlevels
[txgoff
] = 0;
477 dn
->dn_next_indblkshift
[txgoff
] = 0;
478 dn
->dn_next_blksz
[txgoff
] = 0;
480 /* ASSERT(blkptrs are zero); */
481 ASSERT(dn
->dn_phys
->dn_type
!= DMU_OT_NONE
);
482 ASSERT(dn
->dn_type
!= DMU_OT_NONE
);
484 ASSERT(dn
->dn_free_txg
> 0);
485 if (dn
->dn_allocated_txg
!= dn
->dn_free_txg
)
486 dbuf_will_dirty(dn
->dn_dbuf
, tx
);
487 bzero(dn
->dn_phys
, sizeof (dnode_phys_t
));
489 mutex_enter(&dn
->dn_mtx
);
490 dn
->dn_type
= DMU_OT_NONE
;
492 dn
->dn_allocated_txg
= 0;
494 mutex_exit(&dn
->dn_mtx
);
496 ASSERT(dn
->dn_object
!= DMU_META_DNODE_OBJECT
);
498 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
500 * Now that we've released our hold, the dnode may
501 * be evicted, so we musn't access it.
506 * Write out the dnode's dirty buffers.
509 dnode_sync(dnode_t
*dn
, dmu_tx_t
*tx
)
512 dnode_phys_t
*dnp
= dn
->dn_phys
;
513 int txgoff
= tx
->tx_txg
& TXG_MASK
;
514 list_t
*list
= &dn
->dn_dirty_records
[txgoff
];
515 static const dnode_phys_t zerodn
= { 0 };
517 ASSERT(dmu_tx_is_syncing(tx
));
518 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
|| dn
->dn_allocated_txg
);
519 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
||
520 bcmp(dnp
, &zerodn
, DNODE_SIZE
) == 0);
523 ASSERT(dn
->dn_dbuf
== NULL
|| arc_released(dn
->dn_dbuf
->db_buf
));
525 if (dmu_objset_userused_enabled(dn
->dn_objset
) &&
526 !DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
527 ASSERT(dn
->dn_oldphys
== NULL
);
528 dn
->dn_oldphys
= zio_buf_alloc(sizeof (dnode_phys_t
));
529 *dn
->dn_oldphys
= *dn
->dn_phys
; /* struct assignment */
530 dn
->dn_phys
->dn_flags
|= DNODE_FLAG_USERUSED_ACCOUNTED
;
532 /* Once we account for it, we should always account for it. */
533 ASSERT(!(dn
->dn_phys
->dn_flags
&
534 DNODE_FLAG_USERUSED_ACCOUNTED
));
537 mutex_enter(&dn
->dn_mtx
);
538 if (dn
->dn_allocated_txg
== tx
->tx_txg
) {
539 /* The dnode is newly allocated or reallocated */
540 if (dnp
->dn_type
== DMU_OT_NONE
) {
541 /* this is a first alloc, not a realloc */
543 dnp
->dn_nblkptr
= dn
->dn_nblkptr
;
546 dnp
->dn_type
= dn
->dn_type
;
547 dnp
->dn_bonustype
= dn
->dn_bonustype
;
548 dnp
->dn_bonuslen
= dn
->dn_bonuslen
;
551 ASSERT(dnp
->dn_nlevels
> 1 ||
552 BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
553 BP_GET_LSIZE(&dnp
->dn_blkptr
[0]) ==
554 dnp
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
);
556 if (dn
->dn_next_blksz
[txgoff
]) {
557 ASSERT(P2PHASE(dn
->dn_next_blksz
[txgoff
],
558 SPA_MINBLOCKSIZE
) == 0);
559 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
560 dn
->dn_maxblkid
== 0 || list_head(list
) != NULL
||
561 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
==
562 dnp
->dn_datablkszsec
);
563 dnp
->dn_datablkszsec
=
564 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
;
565 dn
->dn_next_blksz
[txgoff
] = 0;
568 if (dn
->dn_next_bonuslen
[txgoff
]) {
569 if (dn
->dn_next_bonuslen
[txgoff
] == DN_ZERO_BONUSLEN
)
570 dnp
->dn_bonuslen
= 0;
572 dnp
->dn_bonuslen
= dn
->dn_next_bonuslen
[txgoff
];
573 ASSERT(dnp
->dn_bonuslen
<= DN_MAX_BONUSLEN
);
574 dn
->dn_next_bonuslen
[txgoff
] = 0;
577 if (dn
->dn_next_indblkshift
[txgoff
]) {
578 ASSERT(dnp
->dn_nlevels
== 1);
579 dnp
->dn_indblkshift
= dn
->dn_next_indblkshift
[txgoff
];
580 dn
->dn_next_indblkshift
[txgoff
] = 0;
584 * Just take the live (open-context) values for checksum and compress.
585 * Strictly speaking it's a future leak, but nothing bad happens if we
586 * start using the new checksum or compress algorithm a little early.
588 dnp
->dn_checksum
= dn
->dn_checksum
;
589 dnp
->dn_compress
= dn
->dn_compress
;
591 mutex_exit(&dn
->dn_mtx
);
593 /* process all the "freed" ranges in the file */
594 while (rp
= avl_last(&dn
->dn_ranges
[txgoff
])) {
595 dnode_sync_free_range(dn
, rp
->fr_blkid
, rp
->fr_nblks
, tx
);
596 /* grab the mutex so we don't race with dnode_block_freed() */
597 mutex_enter(&dn
->dn_mtx
);
598 avl_remove(&dn
->dn_ranges
[txgoff
], rp
);
599 mutex_exit(&dn
->dn_mtx
);
600 kmem_free(rp
, sizeof (free_range_t
));
603 if (dn
->dn_free_txg
> 0 && dn
->dn_free_txg
<= tx
->tx_txg
) {
604 dnode_sync_free(dn
, tx
);
608 if (dn
->dn_next_nblkptr
[txgoff
]) {
609 /* this should only happen on a realloc */
610 ASSERT(dn
->dn_allocated_txg
== tx
->tx_txg
);
611 if (dn
->dn_next_nblkptr
[txgoff
] > dnp
->dn_nblkptr
) {
612 /* zero the new blkptrs we are gaining */
613 bzero(dnp
->dn_blkptr
+ dnp
->dn_nblkptr
,
615 (dn
->dn_next_nblkptr
[txgoff
] - dnp
->dn_nblkptr
));
619 ASSERT(dn
->dn_next_nblkptr
[txgoff
] < dnp
->dn_nblkptr
);
620 /* the blkptrs we are losing better be unallocated */
621 for (i
= dn
->dn_next_nblkptr
[txgoff
];
622 i
< dnp
->dn_nblkptr
; i
++)
623 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[i
]));
626 mutex_enter(&dn
->dn_mtx
);
627 dnp
->dn_nblkptr
= dn
->dn_next_nblkptr
[txgoff
];
628 dn
->dn_next_nblkptr
[txgoff
] = 0;
629 mutex_exit(&dn
->dn_mtx
);
632 if (dn
->dn_next_nlevels
[txgoff
]) {
633 dnode_increase_indirection(dn
, tx
);
634 dn
->dn_next_nlevels
[txgoff
] = 0;
637 dbuf_sync_list(list
, tx
);
639 if (!DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
640 ASSERT3P(list_head(list
), ==, NULL
);
641 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
645 * Although we have dropped our reference to the dnode, it
646 * can't be evicted until its written, and we haven't yet
647 * initiated the IO for the dnode's dbuf.