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]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
27 #include <sys/zfs_context.h>
29 #include <sys/dnode.h>
31 #include <sys/dmu_tx.h>
32 #include <sys/dmu_objset.h>
33 #include <sys/dsl_dataset.h>
35 #include <sys/range_tree.h>
36 #include <sys/zfeature.h>
39 dnode_increase_indirection(dnode_t
*dn
, dmu_tx_t
*tx
)
42 int txgoff
= tx
->tx_txg
& TXG_MASK
;
43 int nblkptr
= dn
->dn_phys
->dn_nblkptr
;
44 int old_toplvl
= dn
->dn_phys
->dn_nlevels
- 1;
45 int new_level
= dn
->dn_next_nlevels
[txgoff
];
48 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
50 /* this dnode can't be paged out because it's dirty */
51 ASSERT(dn
->dn_phys
->dn_type
!= DMU_OT_NONE
);
52 ASSERT(RW_WRITE_HELD(&dn
->dn_struct_rwlock
));
53 ASSERT(new_level
> 1 && dn
->dn_phys
->dn_nlevels
> 0);
55 db
= dbuf_hold_level(dn
, dn
->dn_phys
->dn_nlevels
, 0, FTAG
);
58 dn
->dn_phys
->dn_nlevels
= new_level
;
59 dprintf("os=%p obj=%llu, increase to %d\n", dn
->dn_objset
,
60 dn
->dn_object
, dn
->dn_phys
->dn_nlevels
);
62 /* check for existing blkptrs in the dnode */
63 for (i
= 0; i
< nblkptr
; i
++)
64 if (!BP_IS_HOLE(&dn
->dn_phys
->dn_blkptr
[i
]))
67 /* transfer dnode's block pointers to new indirect block */
68 (void) dbuf_read(db
, NULL
, DB_RF_MUST_SUCCEED
|DB_RF_HAVESTRUCT
);
69 ASSERT(db
->db
.db_data
);
70 ASSERT(arc_released(db
->db_buf
));
71 ASSERT3U(sizeof (blkptr_t
) * nblkptr
, <=, db
->db
.db_size
);
72 bcopy(dn
->dn_phys
->dn_blkptr
, db
->db
.db_data
,
73 sizeof (blkptr_t
) * nblkptr
);
74 arc_buf_freeze(db
->db_buf
);
77 /* set dbuf's parent pointers to new indirect buf */
78 for (i
= 0; i
< nblkptr
; i
++) {
79 dmu_buf_impl_t
*child
= dbuf_find(dn
, old_toplvl
, i
);
84 DB_DNODE_ENTER(child
);
85 ASSERT3P(DB_DNODE(child
), ==, dn
);
88 if (child
->db_parent
&& child
->db_parent
!= dn
->dn_dbuf
) {
89 ASSERT(child
->db_parent
->db_level
== db
->db_level
);
90 ASSERT(child
->db_blkptr
!=
91 &dn
->dn_phys
->dn_blkptr
[child
->db_blkid
]);
92 mutex_exit(&child
->db_mtx
);
95 ASSERT(child
->db_parent
== NULL
||
96 child
->db_parent
== dn
->dn_dbuf
);
98 child
->db_parent
= db
;
99 dbuf_add_ref(db
, child
);
101 child
->db_blkptr
= (blkptr_t
*)db
->db
.db_data
+ i
;
103 child
->db_blkptr
= NULL
;
104 dprintf_dbuf_bp(child
, child
->db_blkptr
,
105 "changed db_blkptr to new indirect %s", "");
107 mutex_exit(&child
->db_mtx
);
110 bzero(dn
->dn_phys
->dn_blkptr
, sizeof (blkptr_t
) * nblkptr
);
114 rw_exit(&dn
->dn_struct_rwlock
);
118 free_blocks(dnode_t
*dn
, blkptr_t
*bp
, int num
, dmu_tx_t
*tx
)
120 dsl_dataset_t
*ds
= dn
->dn_objset
->os_dsl_dataset
;
121 uint64_t bytesfreed
= 0;
124 dprintf("ds=%p obj=%llx num=%d\n", ds
, dn
->dn_object
, num
);
126 for (i
= 0; i
< num
; i
++, bp
++) {
128 dmu_object_type_t type
;
133 bytesfreed
+= dsl_dataset_block_kill(ds
, bp
, tx
, B_FALSE
);
134 ASSERT3U(bytesfreed
, <=, DN_USED_BYTES(dn
->dn_phys
));
137 * Save some useful information on the holes being
138 * punched, including logical size, type, and indirection
139 * level. Retaining birth time enables detection of when
140 * holes are punched for reducing the number of free
141 * records transmitted during a zfs send.
144 lsize
= BP_GET_LSIZE(bp
);
145 type
= BP_GET_TYPE(bp
);
146 lvl
= BP_GET_LEVEL(bp
);
148 bzero(bp
, sizeof (blkptr_t
));
150 if (spa_feature_is_active(dn
->dn_objset
->os_spa
,
151 SPA_FEATURE_HOLE_BIRTH
)) {
152 BP_SET_LSIZE(bp
, lsize
);
153 BP_SET_TYPE(bp
, type
);
154 BP_SET_LEVEL(bp
, lvl
);
155 BP_SET_BIRTH(bp
, dmu_tx_get_txg(tx
), 0);
158 dnode_diduse_space(dn
, -bytesfreed
);
163 free_verify(dmu_buf_impl_t
*db
, uint64_t start
, uint64_t end
, dmu_tx_t
*tx
)
167 uint64_t txg
= tx
->tx_txg
;
172 epbs
= dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
173 off
= start
- (db
->db_blkid
* 1<<epbs
);
174 num
= end
- start
+ 1;
176 ASSERT3U(off
, >=, 0);
177 ASSERT3U(num
, >=, 0);
178 ASSERT3U(db
->db_level
, >, 0);
179 ASSERT3U(db
->db
.db_size
, ==, 1 << dn
->dn_phys
->dn_indblkshift
);
180 ASSERT3U(off
+num
, <=, db
->db
.db_size
>> SPA_BLKPTRSHIFT
);
181 ASSERT(db
->db_blkptr
!= NULL
);
183 for (i
= off
; i
< off
+num
; i
++) {
185 dmu_buf_impl_t
*child
;
186 dbuf_dirty_record_t
*dr
;
189 ASSERT(db
->db_level
== 1);
191 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
192 err
= dbuf_hold_impl(dn
, db
->db_level
-1,
193 (db
->db_blkid
<< epbs
) + i
, TRUE
, FTAG
, &child
);
194 rw_exit(&dn
->dn_struct_rwlock
);
198 ASSERT(child
->db_level
== 0);
199 dr
= child
->db_last_dirty
;
200 while (dr
&& dr
->dr_txg
> txg
)
202 ASSERT(dr
== NULL
|| dr
->dr_txg
== txg
);
204 /* data_old better be zeroed */
206 buf
= dr
->dt
.dl
.dr_data
->b_data
;
207 for (j
= 0; j
< child
->db
.db_size
>> 3; j
++) {
209 panic("freed data not zero: "
210 "child=%p i=%d off=%d num=%d\n",
211 (void *)child
, i
, off
, num
);
217 * db_data better be zeroed unless it's dirty in a
220 mutex_enter(&child
->db_mtx
);
221 buf
= child
->db
.db_data
;
222 if (buf
!= NULL
&& child
->db_state
!= DB_FILL
&&
223 child
->db_last_dirty
== NULL
) {
224 for (j
= 0; j
< child
->db
.db_size
>> 3; j
++) {
226 panic("freed data not zero: "
227 "child=%p i=%d off=%d num=%d\n",
228 (void *)child
, i
, off
, num
);
232 mutex_exit(&child
->db_mtx
);
234 dbuf_rele(child
, FTAG
);
241 free_children(dmu_buf_impl_t
*db
, uint64_t blkid
, uint64_t nblks
,
246 dmu_buf_impl_t
*subdb
;
247 uint64_t start
, end
, dbstart
, dbend
, i
;
251 * There is a small possibility that this block will not be cached:
252 * 1 - if level > 1 and there are no children with level <= 1
253 * 2 - if this block was evicted since we read it from
254 * dmu_tx_hold_free().
256 if (db
->db_state
!= DB_CACHED
)
257 (void) dbuf_read(db
, NULL
, DB_RF_MUST_SUCCEED
);
264 epbs
= dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
265 shift
= (db
->db_level
- 1) * epbs
;
266 dbstart
= db
->db_blkid
<< epbs
;
267 start
= blkid
>> shift
;
268 if (dbstart
< start
) {
269 bp
+= start
- dbstart
;
273 dbend
= ((db
->db_blkid
+ 1) << epbs
) - 1;
274 end
= (blkid
+ nblks
- 1) >> shift
;
278 ASSERT3U(start
, <=, end
);
280 if (db
->db_level
== 1) {
281 FREE_VERIFY(db
, start
, end
, tx
);
282 free_blocks(dn
, bp
, end
-start
+1, tx
);
284 for (i
= start
; i
<= end
; i
++, bp
++) {
287 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
288 VERIFY0(dbuf_hold_impl(dn
, db
->db_level
- 1,
289 i
, B_TRUE
, FTAG
, &subdb
));
290 rw_exit(&dn
->dn_struct_rwlock
);
291 ASSERT3P(bp
, ==, subdb
->db_blkptr
);
293 free_children(subdb
, blkid
, nblks
, tx
);
294 dbuf_rele(subdb
, FTAG
);
298 /* If this whole block is free, free ourself too. */
299 for (i
= 0, bp
= db
->db
.db_data
; i
< 1 << epbs
; i
++, bp
++) {
303 if (i
== 1 << epbs
) {
304 /* didn't find any non-holes */
305 bzero(db
->db
.db_data
, db
->db
.db_size
);
306 free_blocks(dn
, db
->db_blkptr
, 1, tx
);
309 * Partial block free; must be marked dirty so that it
310 * will be written out.
312 ASSERT(db
->db_dirtycnt
> 0);
316 arc_buf_freeze(db
->db_buf
);
320 * Traverse the indicated range of the provided file
321 * and "free" all the blocks contained there.
324 dnode_sync_free_range_impl(dnode_t
*dn
, uint64_t blkid
, uint64_t nblks
,
327 blkptr_t
*bp
= dn
->dn_phys
->dn_blkptr
;
328 int dnlevel
= dn
->dn_phys
->dn_nlevels
;
329 boolean_t trunc
= B_FALSE
;
331 if (blkid
> dn
->dn_phys
->dn_maxblkid
)
334 ASSERT(dn
->dn_phys
->dn_maxblkid
< UINT64_MAX
);
335 if (blkid
+ nblks
> dn
->dn_phys
->dn_maxblkid
) {
336 nblks
= dn
->dn_phys
->dn_maxblkid
- blkid
+ 1;
340 /* There are no indirect blocks in the object */
342 if (blkid
>= dn
->dn_phys
->dn_nblkptr
) {
343 /* this range was never made persistent */
346 ASSERT3U(blkid
+ nblks
, <=, dn
->dn_phys
->dn_nblkptr
);
347 free_blocks(dn
, bp
+ blkid
, nblks
, tx
);
349 int shift
= (dnlevel
- 1) *
350 (dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
);
351 int start
= blkid
>> shift
;
352 int end
= (blkid
+ nblks
- 1) >> shift
;
356 ASSERT(start
< dn
->dn_phys
->dn_nblkptr
);
358 for (i
= start
; i
<= end
; i
++, bp
++) {
361 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
362 VERIFY0(dbuf_hold_impl(dn
, dnlevel
- 1, i
,
364 rw_exit(&dn
->dn_struct_rwlock
);
366 free_children(db
, blkid
, nblks
, tx
);
372 ASSERTV(uint64_t off
);
373 dn
->dn_phys
->dn_maxblkid
= blkid
== 0 ? 0 : blkid
- 1;
375 ASSERTV(off
= (dn
->dn_phys
->dn_maxblkid
+ 1) *
376 (dn
->dn_phys
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
));
377 ASSERT(off
< dn
->dn_phys
->dn_maxblkid
||
378 dn
->dn_phys
->dn_maxblkid
== 0 ||
379 dnode_next_offset(dn
, 0, &off
, 1, 1, 0) != 0);
383 typedef struct dnode_sync_free_range_arg
{
384 dnode_t
*dsfra_dnode
;
386 } dnode_sync_free_range_arg_t
;
389 dnode_sync_free_range(void *arg
, uint64_t blkid
, uint64_t nblks
)
391 dnode_sync_free_range_arg_t
*dsfra
= arg
;
392 dnode_t
*dn
= dsfra
->dsfra_dnode
;
394 mutex_exit(&dn
->dn_mtx
);
395 dnode_sync_free_range_impl(dn
, blkid
, nblks
, dsfra
->dsfra_tx
);
396 mutex_enter(&dn
->dn_mtx
);
400 * Try to kick all the dnode's dbufs out of the cache...
403 dnode_evict_dbufs(dnode_t
*dn
)
409 dmu_buf_impl_t
*db
, marker
;
410 int evicting
= FALSE
;
413 mutex_enter(&dn
->dn_dbufs_mtx
);
414 list_insert_tail(&dn
->dn_dbufs
, &marker
);
415 db
= list_head(&dn
->dn_dbufs
);
416 for (; db
!= &marker
; db
= list_head(&dn
->dn_dbufs
)) {
417 list_remove(&dn
->dn_dbufs
, db
);
418 list_insert_tail(&dn
->dn_dbufs
, db
);
421 ASSERT3P(DB_DNODE(db
), ==, dn
);
425 mutex_enter(&db
->db_mtx
);
426 if (db
->db_state
== DB_EVICTING
) {
429 mutex_exit(&db
->db_mtx
);
430 } else if (refcount_is_zero(&db
->db_holds
)) {
432 dbuf_clear(db
); /* exits db_mtx for us */
434 mutex_exit(&db
->db_mtx
);
438 list_remove(&dn
->dn_dbufs
, &marker
);
440 * NB: we need to drop dn_dbufs_mtx between passes so
441 * that any DB_EVICTING dbufs can make progress.
442 * Ideally, we would have some cv we could wait on, but
443 * since we don't, just wait a bit to give the other
444 * thread a chance to run.
446 mutex_exit(&dn
->dn_dbufs_mtx
);
450 if ((pass
% 100) == 0)
451 dprintf("Exceeded %d passes evicting dbufs\n", pass
);
455 dprintf("Required %d passes to evict dbufs\n", pass
);
457 dnode_evict_bonus(dn
);
461 dnode_evict_bonus(dnode_t
*dn
)
463 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
464 if (dn
->dn_bonus
&& refcount_is_zero(&dn
->dn_bonus
->db_holds
)) {
465 mutex_enter(&dn
->dn_bonus
->db_mtx
);
466 dbuf_evict(dn
->dn_bonus
);
469 rw_exit(&dn
->dn_struct_rwlock
);
473 dnode_undirty_dbufs(list_t
*list
)
475 dbuf_dirty_record_t
*dr
;
477 while ((dr
= list_head(list
))) {
478 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
479 uint64_t txg
= dr
->dr_txg
;
481 if (db
->db_level
!= 0)
482 dnode_undirty_dbufs(&dr
->dt
.di
.dr_children
);
484 mutex_enter(&db
->db_mtx
);
485 /* XXX - use dbuf_undirty()? */
486 list_remove(list
, dr
);
487 ASSERT(db
->db_last_dirty
== dr
);
488 db
->db_last_dirty
= NULL
;
489 db
->db_dirtycnt
-= 1;
490 if (db
->db_level
== 0) {
491 ASSERT(db
->db_blkid
== DMU_BONUS_BLKID
||
492 dr
->dt
.dl
.dr_data
== db
->db_buf
);
495 mutex_destroy(&dr
->dt
.di
.dr_mtx
);
496 list_destroy(&dr
->dt
.di
.dr_children
);
498 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
499 dbuf_rele_and_unlock(db
, (void *)(uintptr_t)txg
);
504 dnode_sync_free(dnode_t
*dn
, dmu_tx_t
*tx
)
506 int txgoff
= tx
->tx_txg
& TXG_MASK
;
508 ASSERT(dmu_tx_is_syncing(tx
));
511 * Our contents should have been freed in dnode_sync() by the
512 * free range record inserted by the caller of dnode_free().
514 ASSERT0(DN_USED_BYTES(dn
->dn_phys
));
515 ASSERT(BP_IS_HOLE(dn
->dn_phys
->dn_blkptr
));
517 dnode_undirty_dbufs(&dn
->dn_dirty_records
[txgoff
]);
518 dnode_evict_dbufs(dn
);
519 ASSERT3P(list_head(&dn
->dn_dbufs
), ==, NULL
);
520 ASSERT3P(dn
->dn_bonus
, ==, NULL
);
523 * XXX - It would be nice to assert this, but we may still
524 * have residual holds from async evictions from the arc...
526 * zfs_obj_to_path() also depends on this being
529 * ASSERT3U(refcount_count(&dn->dn_holds), ==, 1);
532 /* Undirty next bits */
533 dn
->dn_next_nlevels
[txgoff
] = 0;
534 dn
->dn_next_indblkshift
[txgoff
] = 0;
535 dn
->dn_next_blksz
[txgoff
] = 0;
537 /* ASSERT(blkptrs are zero); */
538 ASSERT(dn
->dn_phys
->dn_type
!= DMU_OT_NONE
);
539 ASSERT(dn
->dn_type
!= DMU_OT_NONE
);
541 ASSERT(dn
->dn_free_txg
> 0);
542 if (dn
->dn_allocated_txg
!= dn
->dn_free_txg
)
543 dmu_buf_will_dirty(&dn
->dn_dbuf
->db
, tx
);
544 bzero(dn
->dn_phys
, sizeof (dnode_phys_t
));
546 mutex_enter(&dn
->dn_mtx
);
547 dn
->dn_type
= DMU_OT_NONE
;
549 dn
->dn_allocated_txg
= 0;
551 dn
->dn_have_spill
= B_FALSE
;
552 mutex_exit(&dn
->dn_mtx
);
554 ASSERT(dn
->dn_object
!= DMU_META_DNODE_OBJECT
);
556 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
558 * Now that we've released our hold, the dnode may
559 * be evicted, so we musn't access it.
564 * Write out the dnode's dirty buffers.
567 dnode_sync(dnode_t
*dn
, dmu_tx_t
*tx
)
569 dnode_phys_t
*dnp
= dn
->dn_phys
;
570 int txgoff
= tx
->tx_txg
& TXG_MASK
;
571 list_t
*list
= &dn
->dn_dirty_records
[txgoff
];
572 boolean_t kill_spill
= B_FALSE
;
573 boolean_t freeing_dnode
;
574 ASSERTV(static const dnode_phys_t zerodn
= { 0 });
576 ASSERT(dmu_tx_is_syncing(tx
));
577 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
|| dn
->dn_allocated_txg
);
578 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
||
579 bcmp(dnp
, &zerodn
, DNODE_SIZE
) == 0);
582 ASSERT(dn
->dn_dbuf
== NULL
|| arc_released(dn
->dn_dbuf
->db_buf
));
584 if (dmu_objset_userused_enabled(dn
->dn_objset
) &&
585 !DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
586 mutex_enter(&dn
->dn_mtx
);
587 dn
->dn_oldused
= DN_USED_BYTES(dn
->dn_phys
);
588 dn
->dn_oldflags
= dn
->dn_phys
->dn_flags
;
589 dn
->dn_phys
->dn_flags
|= DNODE_FLAG_USERUSED_ACCOUNTED
;
590 mutex_exit(&dn
->dn_mtx
);
591 dmu_objset_userquota_get_ids(dn
, B_FALSE
, tx
);
593 /* Once we account for it, we should always account for it. */
594 ASSERT(!(dn
->dn_phys
->dn_flags
&
595 DNODE_FLAG_USERUSED_ACCOUNTED
));
598 mutex_enter(&dn
->dn_mtx
);
599 if (dn
->dn_allocated_txg
== tx
->tx_txg
) {
600 /* The dnode is newly allocated or reallocated */
601 if (dnp
->dn_type
== DMU_OT_NONE
) {
602 /* this is a first alloc, not a realloc */
604 dnp
->dn_nblkptr
= dn
->dn_nblkptr
;
607 dnp
->dn_type
= dn
->dn_type
;
608 dnp
->dn_bonustype
= dn
->dn_bonustype
;
609 dnp
->dn_bonuslen
= dn
->dn_bonuslen
;
611 ASSERT(dnp
->dn_nlevels
> 1 ||
612 BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
613 BP_IS_EMBEDDED(&dnp
->dn_blkptr
[0]) ||
614 BP_GET_LSIZE(&dnp
->dn_blkptr
[0]) ==
615 dnp
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
);
616 ASSERT(dnp
->dn_nlevels
< 2 ||
617 BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
618 BP_GET_LSIZE(&dnp
->dn_blkptr
[0]) == 1 << dnp
->dn_indblkshift
);
620 if (dn
->dn_next_type
[txgoff
] != 0) {
621 dnp
->dn_type
= dn
->dn_type
;
622 dn
->dn_next_type
[txgoff
] = 0;
625 if (dn
->dn_next_blksz
[txgoff
] != 0) {
626 ASSERT(P2PHASE(dn
->dn_next_blksz
[txgoff
],
627 SPA_MINBLOCKSIZE
) == 0);
628 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
629 dn
->dn_maxblkid
== 0 || list_head(list
) != NULL
||
630 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
==
631 dnp
->dn_datablkszsec
||
632 range_tree_space(dn
->dn_free_ranges
[txgoff
]) != 0);
633 dnp
->dn_datablkszsec
=
634 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
;
635 dn
->dn_next_blksz
[txgoff
] = 0;
638 if (dn
->dn_next_bonuslen
[txgoff
] != 0) {
639 if (dn
->dn_next_bonuslen
[txgoff
] == DN_ZERO_BONUSLEN
)
640 dnp
->dn_bonuslen
= 0;
642 dnp
->dn_bonuslen
= dn
->dn_next_bonuslen
[txgoff
];
643 ASSERT(dnp
->dn_bonuslen
<= DN_MAX_BONUSLEN
);
644 dn
->dn_next_bonuslen
[txgoff
] = 0;
647 if (dn
->dn_next_bonustype
[txgoff
] != 0) {
648 ASSERT(DMU_OT_IS_VALID(dn
->dn_next_bonustype
[txgoff
]));
649 dnp
->dn_bonustype
= dn
->dn_next_bonustype
[txgoff
];
650 dn
->dn_next_bonustype
[txgoff
] = 0;
653 freeing_dnode
= dn
->dn_free_txg
> 0 && dn
->dn_free_txg
<= tx
->tx_txg
;
656 * We will either remove a spill block when a file is being removed
657 * or we have been asked to remove it.
659 if (dn
->dn_rm_spillblk
[txgoff
] ||
660 ((dnp
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
) && freeing_dnode
)) {
661 if ((dnp
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
))
663 dn
->dn_rm_spillblk
[txgoff
] = 0;
666 if (dn
->dn_next_indblkshift
[txgoff
] != 0) {
667 ASSERT(dnp
->dn_nlevels
== 1);
668 dnp
->dn_indblkshift
= dn
->dn_next_indblkshift
[txgoff
];
669 dn
->dn_next_indblkshift
[txgoff
] = 0;
673 * Just take the live (open-context) values for checksum and compress.
674 * Strictly speaking it's a future leak, but nothing bad happens if we
675 * start using the new checksum or compress algorithm a little early.
677 dnp
->dn_checksum
= dn
->dn_checksum
;
678 dnp
->dn_compress
= dn
->dn_compress
;
680 mutex_exit(&dn
->dn_mtx
);
683 free_blocks(dn
, &dn
->dn_phys
->dn_spill
, 1, tx
);
684 mutex_enter(&dn
->dn_mtx
);
685 dnp
->dn_flags
&= ~DNODE_FLAG_SPILL_BLKPTR
;
686 mutex_exit(&dn
->dn_mtx
);
689 /* process all the "freed" ranges in the file */
690 if (dn
->dn_free_ranges
[txgoff
] != NULL
) {
691 dnode_sync_free_range_arg_t dsfra
;
692 dsfra
.dsfra_dnode
= dn
;
694 mutex_enter(&dn
->dn_mtx
);
695 range_tree_vacate(dn
->dn_free_ranges
[txgoff
],
696 dnode_sync_free_range
, &dsfra
);
697 range_tree_destroy(dn
->dn_free_ranges
[txgoff
]);
698 dn
->dn_free_ranges
[txgoff
] = NULL
;
699 mutex_exit(&dn
->dn_mtx
);
703 dnode_sync_free(dn
, tx
);
707 if (dn
->dn_next_nlevels
[txgoff
]) {
708 dnode_increase_indirection(dn
, tx
);
709 dn
->dn_next_nlevels
[txgoff
] = 0;
712 if (dn
->dn_next_nblkptr
[txgoff
]) {
713 /* this should only happen on a realloc */
714 ASSERT(dn
->dn_allocated_txg
== tx
->tx_txg
);
715 if (dn
->dn_next_nblkptr
[txgoff
] > dnp
->dn_nblkptr
) {
716 /* zero the new blkptrs we are gaining */
717 bzero(dnp
->dn_blkptr
+ dnp
->dn_nblkptr
,
719 (dn
->dn_next_nblkptr
[txgoff
] - dnp
->dn_nblkptr
));
723 ASSERT(dn
->dn_next_nblkptr
[txgoff
] < dnp
->dn_nblkptr
);
724 /* the blkptrs we are losing better be unallocated */
725 for (i
= 0; i
< dnp
->dn_nblkptr
; i
++) {
726 if (i
>= dn
->dn_next_nblkptr
[txgoff
])
727 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[i
]));
731 mutex_enter(&dn
->dn_mtx
);
732 dnp
->dn_nblkptr
= dn
->dn_next_nblkptr
[txgoff
];
733 dn
->dn_next_nblkptr
[txgoff
] = 0;
734 mutex_exit(&dn
->dn_mtx
);
737 dbuf_sync_list(list
, tx
);
739 if (!DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
740 ASSERT3P(list_head(list
), ==, NULL
);
741 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
745 * Although we have dropped our reference to the dnode, it
746 * can't be evicted until its written, and we haven't yet
747 * initiated the IO for the dnode's dbuf.