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, 2016 by Delphix. All rights reserved.
25 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
28 #include <sys/zfs_context.h>
30 #include <sys/dnode.h>
32 #include <sys/dmu_tx.h>
33 #include <sys/dmu_objset.h>
34 #include <sys/dsl_dataset.h>
36 #include <sys/range_tree.h>
37 #include <sys/zfeature.h>
40 dnode_increase_indirection(dnode_t
*dn
, dmu_tx_t
*tx
)
43 int txgoff
= tx
->tx_txg
& TXG_MASK
;
44 int nblkptr
= dn
->dn_phys
->dn_nblkptr
;
45 int old_toplvl
= dn
->dn_phys
->dn_nlevels
- 1;
46 int new_level
= dn
->dn_next_nlevels
[txgoff
];
49 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
51 /* this dnode can't be paged out because it's dirty */
52 ASSERT(dn
->dn_phys
->dn_type
!= DMU_OT_NONE
);
53 ASSERT(RW_WRITE_HELD(&dn
->dn_struct_rwlock
));
54 ASSERT(new_level
> 1 && dn
->dn_phys
->dn_nlevels
> 0);
56 db
= dbuf_hold_level(dn
, dn
->dn_phys
->dn_nlevels
, 0, FTAG
);
59 dn
->dn_phys
->dn_nlevels
= new_level
;
60 dprintf("os=%p obj=%llu, increase to %d\n", dn
->dn_objset
,
61 dn
->dn_object
, dn
->dn_phys
->dn_nlevels
);
63 /* transfer dnode's block pointers to new indirect block */
64 (void) dbuf_read(db
, NULL
, DB_RF_MUST_SUCCEED
|DB_RF_HAVESTRUCT
);
65 ASSERT(db
->db
.db_data
);
66 ASSERT(arc_released(db
->db_buf
));
67 ASSERT3U(sizeof (blkptr_t
) * nblkptr
, <=, db
->db
.db_size
);
68 bcopy(dn
->dn_phys
->dn_blkptr
, db
->db
.db_data
,
69 sizeof (blkptr_t
) * nblkptr
);
70 arc_buf_freeze(db
->db_buf
);
72 /* set dbuf's parent pointers to new indirect buf */
73 for (i
= 0; i
< nblkptr
; i
++) {
74 dmu_buf_impl_t
*child
=
75 dbuf_find(dn
->dn_objset
, dn
->dn_object
, old_toplvl
, i
);
80 DB_DNODE_ENTER(child
);
81 ASSERT3P(DB_DNODE(child
), ==, dn
);
84 if (child
->db_parent
&& child
->db_parent
!= dn
->dn_dbuf
) {
85 ASSERT(child
->db_parent
->db_level
== db
->db_level
);
86 ASSERT(child
->db_blkptr
!=
87 &dn
->dn_phys
->dn_blkptr
[child
->db_blkid
]);
88 mutex_exit(&child
->db_mtx
);
91 ASSERT(child
->db_parent
== NULL
||
92 child
->db_parent
== dn
->dn_dbuf
);
94 child
->db_parent
= db
;
95 dbuf_add_ref(db
, child
);
97 child
->db_blkptr
= (blkptr_t
*)db
->db
.db_data
+ i
;
99 child
->db_blkptr
= NULL
;
100 dprintf_dbuf_bp(child
, child
->db_blkptr
,
101 "changed db_blkptr to new indirect %s", "");
103 mutex_exit(&child
->db_mtx
);
106 bzero(dn
->dn_phys
->dn_blkptr
, sizeof (blkptr_t
) * nblkptr
);
110 rw_exit(&dn
->dn_struct_rwlock
);
114 free_blocks(dnode_t
*dn
, blkptr_t
*bp
, int num
, dmu_tx_t
*tx
)
116 dsl_dataset_t
*ds
= dn
->dn_objset
->os_dsl_dataset
;
117 uint64_t bytesfreed
= 0;
120 dprintf("ds=%p obj=%llx num=%d\n", ds
, dn
->dn_object
, num
);
122 for (i
= 0; i
< num
; i
++, bp
++) {
124 dmu_object_type_t type
;
129 bytesfreed
+= dsl_dataset_block_kill(ds
, bp
, tx
, B_FALSE
);
130 ASSERT3U(bytesfreed
, <=, DN_USED_BYTES(dn
->dn_phys
));
133 * Save some useful information on the holes being
134 * punched, including logical size, type, and indirection
135 * level. Retaining birth time enables detection of when
136 * holes are punched for reducing the number of free
137 * records transmitted during a zfs send.
140 lsize
= BP_GET_LSIZE(bp
);
141 type
= BP_GET_TYPE(bp
);
142 lvl
= BP_GET_LEVEL(bp
);
144 bzero(bp
, sizeof (blkptr_t
));
146 if (spa_feature_is_active(dn
->dn_objset
->os_spa
,
147 SPA_FEATURE_HOLE_BIRTH
)) {
148 BP_SET_LSIZE(bp
, lsize
);
149 BP_SET_TYPE(bp
, type
);
150 BP_SET_LEVEL(bp
, lvl
);
151 BP_SET_BIRTH(bp
, dmu_tx_get_txg(tx
), 0);
154 dnode_diduse_space(dn
, -bytesfreed
);
159 free_verify(dmu_buf_impl_t
*db
, uint64_t start
, uint64_t end
, dmu_tx_t
*tx
)
163 uint64_t txg
= tx
->tx_txg
;
168 epbs
= dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
169 off
= start
- (db
->db_blkid
* 1<<epbs
);
170 num
= end
- start
+ 1;
172 ASSERT3U(off
, >=, 0);
173 ASSERT3U(num
, >=, 0);
174 ASSERT3U(db
->db_level
, >, 0);
175 ASSERT3U(db
->db
.db_size
, ==, 1 << dn
->dn_phys
->dn_indblkshift
);
176 ASSERT3U(off
+num
, <=, db
->db
.db_size
>> SPA_BLKPTRSHIFT
);
177 ASSERT(db
->db_blkptr
!= NULL
);
179 for (i
= off
; i
< off
+num
; i
++) {
181 dmu_buf_impl_t
*child
;
182 dbuf_dirty_record_t
*dr
;
185 ASSERT(db
->db_level
== 1);
187 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
188 err
= dbuf_hold_impl(dn
, db
->db_level
-1,
189 (db
->db_blkid
<< epbs
) + i
, TRUE
, FALSE
, FTAG
, &child
);
190 rw_exit(&dn
->dn_struct_rwlock
);
194 ASSERT(child
->db_level
== 0);
195 dr
= child
->db_last_dirty
;
196 while (dr
&& dr
->dr_txg
> txg
)
198 ASSERT(dr
== NULL
|| dr
->dr_txg
== txg
);
200 /* data_old better be zeroed */
202 buf
= dr
->dt
.dl
.dr_data
->b_data
;
203 for (j
= 0; j
< child
->db
.db_size
>> 3; j
++) {
205 panic("freed data not zero: "
206 "child=%p i=%d off=%d num=%d\n",
207 (void *)child
, i
, off
, num
);
213 * db_data better be zeroed unless it's dirty in a
216 mutex_enter(&child
->db_mtx
);
217 buf
= child
->db
.db_data
;
218 if (buf
!= NULL
&& child
->db_state
!= DB_FILL
&&
219 child
->db_last_dirty
== NULL
) {
220 for (j
= 0; j
< child
->db
.db_size
>> 3; j
++) {
222 panic("freed data not zero: "
223 "child=%p i=%d off=%d num=%d\n",
224 (void *)child
, i
, off
, num
);
228 mutex_exit(&child
->db_mtx
);
230 dbuf_rele(child
, FTAG
);
237 free_children(dmu_buf_impl_t
*db
, uint64_t blkid
, uint64_t nblks
,
242 dmu_buf_impl_t
*subdb
;
243 uint64_t start
, end
, dbstart
, dbend
, i
;
247 * There is a small possibility that this block will not be cached:
248 * 1 - if level > 1 and there are no children with level <= 1
249 * 2 - if this block was evicted since we read it from
250 * dmu_tx_hold_free().
252 if (db
->db_state
!= DB_CACHED
)
253 (void) dbuf_read(db
, NULL
, DB_RF_MUST_SUCCEED
);
260 epbs
= dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
261 shift
= (db
->db_level
- 1) * epbs
;
262 dbstart
= db
->db_blkid
<< epbs
;
263 start
= blkid
>> shift
;
264 if (dbstart
< start
) {
265 bp
+= start
- dbstart
;
269 dbend
= ((db
->db_blkid
+ 1) << epbs
) - 1;
270 end
= (blkid
+ nblks
- 1) >> shift
;
274 ASSERT3U(start
, <=, end
);
276 if (db
->db_level
== 1) {
277 FREE_VERIFY(db
, start
, end
, tx
);
278 free_blocks(dn
, bp
, end
-start
+1, tx
);
280 for (i
= start
; i
<= end
; i
++, bp
++) {
283 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
284 VERIFY0(dbuf_hold_impl(dn
, db
->db_level
- 1,
285 i
, TRUE
, FALSE
, FTAG
, &subdb
));
286 rw_exit(&dn
->dn_struct_rwlock
);
287 ASSERT3P(bp
, ==, subdb
->db_blkptr
);
289 free_children(subdb
, blkid
, nblks
, tx
);
290 dbuf_rele(subdb
, FTAG
);
294 /* If this whole block is free, free ourself too. */
295 for (i
= 0, bp
= db
->db
.db_data
; i
< 1 << epbs
; i
++, bp
++) {
299 if (i
== 1 << epbs
) {
300 /* didn't find any non-holes */
301 bzero(db
->db
.db_data
, db
->db
.db_size
);
302 free_blocks(dn
, db
->db_blkptr
, 1, tx
);
305 * Partial block free; must be marked dirty so that it
306 * will be written out.
308 ASSERT(db
->db_dirtycnt
> 0);
312 arc_buf_freeze(db
->db_buf
);
316 * Traverse the indicated range of the provided file
317 * and "free" all the blocks contained there.
320 dnode_sync_free_range_impl(dnode_t
*dn
, uint64_t blkid
, uint64_t nblks
,
323 blkptr_t
*bp
= dn
->dn_phys
->dn_blkptr
;
324 int dnlevel
= dn
->dn_phys
->dn_nlevels
;
325 boolean_t trunc
= B_FALSE
;
327 if (blkid
> dn
->dn_phys
->dn_maxblkid
)
330 ASSERT(dn
->dn_phys
->dn_maxblkid
< UINT64_MAX
);
331 if (blkid
+ nblks
> dn
->dn_phys
->dn_maxblkid
) {
332 nblks
= dn
->dn_phys
->dn_maxblkid
- blkid
+ 1;
336 /* There are no indirect blocks in the object */
338 if (blkid
>= dn
->dn_phys
->dn_nblkptr
) {
339 /* this range was never made persistent */
342 ASSERT3U(blkid
+ nblks
, <=, dn
->dn_phys
->dn_nblkptr
);
343 free_blocks(dn
, bp
+ blkid
, nblks
, tx
);
345 int shift
= (dnlevel
- 1) *
346 (dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
);
347 int start
= blkid
>> shift
;
348 int end
= (blkid
+ nblks
- 1) >> shift
;
352 ASSERT(start
< dn
->dn_phys
->dn_nblkptr
);
354 for (i
= start
; i
<= end
; i
++, bp
++) {
357 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
358 VERIFY0(dbuf_hold_impl(dn
, dnlevel
- 1, i
,
359 TRUE
, FALSE
, FTAG
, &db
));
360 rw_exit(&dn
->dn_struct_rwlock
);
362 free_children(db
, blkid
, nblks
, tx
);
368 ASSERTV(uint64_t off
);
369 dn
->dn_phys
->dn_maxblkid
= blkid
== 0 ? 0 : blkid
- 1;
371 ASSERTV(off
= (dn
->dn_phys
->dn_maxblkid
+ 1) *
372 (dn
->dn_phys
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
));
373 ASSERT(off
< dn
->dn_phys
->dn_maxblkid
||
374 dn
->dn_phys
->dn_maxblkid
== 0 ||
375 dnode_next_offset(dn
, 0, &off
, 1, 1, 0) != 0);
379 typedef struct dnode_sync_free_range_arg
{
380 dnode_t
*dsfra_dnode
;
382 } dnode_sync_free_range_arg_t
;
385 dnode_sync_free_range(void *arg
, uint64_t blkid
, uint64_t nblks
)
387 dnode_sync_free_range_arg_t
*dsfra
= arg
;
388 dnode_t
*dn
= dsfra
->dsfra_dnode
;
390 mutex_exit(&dn
->dn_mtx
);
391 dnode_sync_free_range_impl(dn
, blkid
, nblks
, dsfra
->dsfra_tx
);
392 mutex_enter(&dn
->dn_mtx
);
396 * Try to kick all the dnode's dbufs out of the cache...
399 dnode_evict_dbufs(dnode_t
*dn
)
401 dmu_buf_impl_t
*db_marker
;
402 dmu_buf_impl_t
*db
, *db_next
;
404 db_marker
= kmem_alloc(sizeof (dmu_buf_impl_t
), KM_SLEEP
);
406 mutex_enter(&dn
->dn_dbufs_mtx
);
407 for (db
= avl_first(&dn
->dn_dbufs
); db
!= NULL
; db
= db_next
) {
411 ASSERT3P(DB_DNODE(db
), ==, dn
);
415 mutex_enter(&db
->db_mtx
);
416 if (db
->db_state
!= DB_EVICTING
&&
417 refcount_is_zero(&db
->db_holds
)) {
418 db_marker
->db_level
= db
->db_level
;
419 db_marker
->db_blkid
= db
->db_blkid
;
420 db_marker
->db_state
= DB_SEARCH
;
421 avl_insert_here(&dn
->dn_dbufs
, db_marker
, db
,
426 db_next
= AVL_NEXT(&dn
->dn_dbufs
, db_marker
);
427 avl_remove(&dn
->dn_dbufs
, db_marker
);
429 db
->db_pending_evict
= TRUE
;
430 mutex_exit(&db
->db_mtx
);
431 db_next
= AVL_NEXT(&dn
->dn_dbufs
, db
);
434 mutex_exit(&dn
->dn_dbufs_mtx
);
436 kmem_free(db_marker
, sizeof (dmu_buf_impl_t
));
438 dnode_evict_bonus(dn
);
442 dnode_evict_bonus(dnode_t
*dn
)
444 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
445 if (dn
->dn_bonus
!= NULL
) {
446 if (refcount_is_zero(&dn
->dn_bonus
->db_holds
)) {
447 mutex_enter(&dn
->dn_bonus
->db_mtx
);
448 dbuf_destroy(dn
->dn_bonus
);
451 dn
->dn_bonus
->db_pending_evict
= TRUE
;
454 rw_exit(&dn
->dn_struct_rwlock
);
458 dnode_undirty_dbufs(list_t
*list
)
460 dbuf_dirty_record_t
*dr
;
462 while ((dr
= list_head(list
))) {
463 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
464 uint64_t txg
= dr
->dr_txg
;
466 if (db
->db_level
!= 0)
467 dnode_undirty_dbufs(&dr
->dt
.di
.dr_children
);
469 mutex_enter(&db
->db_mtx
);
470 /* XXX - use dbuf_undirty()? */
471 list_remove(list
, dr
);
472 ASSERT(db
->db_last_dirty
== dr
);
473 db
->db_last_dirty
= NULL
;
474 db
->db_dirtycnt
-= 1;
475 if (db
->db_level
== 0) {
476 ASSERT(db
->db_blkid
== DMU_BONUS_BLKID
||
477 dr
->dt
.dl
.dr_data
== db
->db_buf
);
480 mutex_destroy(&dr
->dt
.di
.dr_mtx
);
481 list_destroy(&dr
->dt
.di
.dr_children
);
483 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
484 dbuf_rele_and_unlock(db
, (void *)(uintptr_t)txg
);
489 dnode_sync_free(dnode_t
*dn
, dmu_tx_t
*tx
)
491 int txgoff
= tx
->tx_txg
& TXG_MASK
;
493 ASSERT(dmu_tx_is_syncing(tx
));
496 * Our contents should have been freed in dnode_sync() by the
497 * free range record inserted by the caller of dnode_free().
499 ASSERT0(DN_USED_BYTES(dn
->dn_phys
));
500 ASSERT(BP_IS_HOLE(dn
->dn_phys
->dn_blkptr
));
502 dnode_undirty_dbufs(&dn
->dn_dirty_records
[txgoff
]);
503 dnode_evict_dbufs(dn
);
506 * XXX - It would be nice to assert this, but we may still
507 * have residual holds from async evictions from the arc...
509 * zfs_obj_to_path() also depends on this being
512 * ASSERT3U(refcount_count(&dn->dn_holds), ==, 1);
515 /* Undirty next bits */
516 dn
->dn_next_nlevels
[txgoff
] = 0;
517 dn
->dn_next_indblkshift
[txgoff
] = 0;
518 dn
->dn_next_blksz
[txgoff
] = 0;
520 /* ASSERT(blkptrs are zero); */
521 ASSERT(dn
->dn_phys
->dn_type
!= DMU_OT_NONE
);
522 ASSERT(dn
->dn_type
!= DMU_OT_NONE
);
524 ASSERT(dn
->dn_free_txg
> 0);
525 if (dn
->dn_allocated_txg
!= dn
->dn_free_txg
)
526 dmu_buf_will_dirty(&dn
->dn_dbuf
->db
, tx
);
527 bzero(dn
->dn_phys
, sizeof (dnode_phys_t
) * dn
->dn_num_slots
);
529 mutex_enter(&dn
->dn_mtx
);
530 dn
->dn_type
= DMU_OT_NONE
;
532 dn
->dn_allocated_txg
= 0;
534 dn
->dn_have_spill
= B_FALSE
;
535 mutex_exit(&dn
->dn_mtx
);
537 ASSERT(dn
->dn_object
!= DMU_META_DNODE_OBJECT
);
539 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
541 * Now that we've released our hold, the dnode may
542 * be evicted, so we musn't access it.
547 * Write out the dnode's dirty buffers.
550 dnode_sync(dnode_t
*dn
, dmu_tx_t
*tx
)
552 dnode_phys_t
*dnp
= dn
->dn_phys
;
553 int txgoff
= tx
->tx_txg
& TXG_MASK
;
554 list_t
*list
= &dn
->dn_dirty_records
[txgoff
];
555 boolean_t kill_spill
= B_FALSE
;
556 boolean_t freeing_dnode
;
557 ASSERTV(static const dnode_phys_t zerodn
= { 0 });
559 ASSERT(dmu_tx_is_syncing(tx
));
560 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
|| dn
->dn_allocated_txg
);
561 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
||
562 bcmp(dnp
, &zerodn
, DNODE_MIN_SIZE
) == 0);
565 ASSERT(dn
->dn_dbuf
== NULL
|| arc_released(dn
->dn_dbuf
->db_buf
));
567 if (dmu_objset_userused_enabled(dn
->dn_objset
) &&
568 !DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
569 mutex_enter(&dn
->dn_mtx
);
570 dn
->dn_oldused
= DN_USED_BYTES(dn
->dn_phys
);
571 dn
->dn_oldflags
= dn
->dn_phys
->dn_flags
;
572 dn
->dn_phys
->dn_flags
|= DNODE_FLAG_USERUSED_ACCOUNTED
;
573 mutex_exit(&dn
->dn_mtx
);
574 dmu_objset_userquota_get_ids(dn
, B_FALSE
, tx
);
576 /* Once we account for it, we should always account for it. */
577 ASSERT(!(dn
->dn_phys
->dn_flags
&
578 DNODE_FLAG_USERUSED_ACCOUNTED
));
581 mutex_enter(&dn
->dn_mtx
);
582 if (dn
->dn_allocated_txg
== tx
->tx_txg
) {
583 /* The dnode is newly allocated or reallocated */
584 if (dnp
->dn_type
== DMU_OT_NONE
) {
585 /* this is a first alloc, not a realloc */
587 dnp
->dn_nblkptr
= dn
->dn_nblkptr
;
590 dnp
->dn_type
= dn
->dn_type
;
591 dnp
->dn_bonustype
= dn
->dn_bonustype
;
592 dnp
->dn_bonuslen
= dn
->dn_bonuslen
;
595 dnp
->dn_extra_slots
= dn
->dn_num_slots
- 1;
597 ASSERT(dnp
->dn_nlevels
> 1 ||
598 BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
599 BP_IS_EMBEDDED(&dnp
->dn_blkptr
[0]) ||
600 BP_GET_LSIZE(&dnp
->dn_blkptr
[0]) ==
601 dnp
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
);
602 ASSERT(dnp
->dn_nlevels
< 2 ||
603 BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
604 BP_GET_LSIZE(&dnp
->dn_blkptr
[0]) == 1 << dnp
->dn_indblkshift
);
606 if (dn
->dn_next_type
[txgoff
] != 0) {
607 dnp
->dn_type
= dn
->dn_type
;
608 dn
->dn_next_type
[txgoff
] = 0;
611 if (dn
->dn_next_blksz
[txgoff
] != 0) {
612 ASSERT(P2PHASE(dn
->dn_next_blksz
[txgoff
],
613 SPA_MINBLOCKSIZE
) == 0);
614 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
615 dn
->dn_maxblkid
== 0 || list_head(list
) != NULL
||
616 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
==
617 dnp
->dn_datablkszsec
||
618 range_tree_space(dn
->dn_free_ranges
[txgoff
]) != 0);
619 dnp
->dn_datablkszsec
=
620 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
;
621 dn
->dn_next_blksz
[txgoff
] = 0;
624 if (dn
->dn_next_bonuslen
[txgoff
] != 0) {
625 if (dn
->dn_next_bonuslen
[txgoff
] == DN_ZERO_BONUSLEN
)
626 dnp
->dn_bonuslen
= 0;
628 dnp
->dn_bonuslen
= dn
->dn_next_bonuslen
[txgoff
];
629 ASSERT(dnp
->dn_bonuslen
<=
630 DN_SLOTS_TO_BONUSLEN(dnp
->dn_extra_slots
+ 1));
631 dn
->dn_next_bonuslen
[txgoff
] = 0;
634 if (dn
->dn_next_bonustype
[txgoff
] != 0) {
635 ASSERT(DMU_OT_IS_VALID(dn
->dn_next_bonustype
[txgoff
]));
636 dnp
->dn_bonustype
= dn
->dn_next_bonustype
[txgoff
];
637 dn
->dn_next_bonustype
[txgoff
] = 0;
640 freeing_dnode
= dn
->dn_free_txg
> 0 && dn
->dn_free_txg
<= tx
->tx_txg
;
643 * Remove the spill block if we have been explicitly asked to
644 * remove it, or if the object is being removed.
646 if (dn
->dn_rm_spillblk
[txgoff
] || freeing_dnode
) {
647 if (dnp
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
)
649 dn
->dn_rm_spillblk
[txgoff
] = 0;
652 if (dn
->dn_next_indblkshift
[txgoff
] != 0) {
653 ASSERT(dnp
->dn_nlevels
== 1);
654 dnp
->dn_indblkshift
= dn
->dn_next_indblkshift
[txgoff
];
655 dn
->dn_next_indblkshift
[txgoff
] = 0;
659 * Just take the live (open-context) values for checksum and compress.
660 * Strictly speaking it's a future leak, but nothing bad happens if we
661 * start using the new checksum or compress algorithm a little early.
663 dnp
->dn_checksum
= dn
->dn_checksum
;
664 dnp
->dn_compress
= dn
->dn_compress
;
666 mutex_exit(&dn
->dn_mtx
);
669 free_blocks(dn
, DN_SPILL_BLKPTR(dn
->dn_phys
), 1, tx
);
670 mutex_enter(&dn
->dn_mtx
);
671 dnp
->dn_flags
&= ~DNODE_FLAG_SPILL_BLKPTR
;
672 mutex_exit(&dn
->dn_mtx
);
675 /* process all the "freed" ranges in the file */
676 if (dn
->dn_free_ranges
[txgoff
] != NULL
) {
677 dnode_sync_free_range_arg_t dsfra
;
678 dsfra
.dsfra_dnode
= dn
;
680 mutex_enter(&dn
->dn_mtx
);
681 range_tree_vacate(dn
->dn_free_ranges
[txgoff
],
682 dnode_sync_free_range
, &dsfra
);
683 range_tree_destroy(dn
->dn_free_ranges
[txgoff
]);
684 dn
->dn_free_ranges
[txgoff
] = NULL
;
685 mutex_exit(&dn
->dn_mtx
);
689 dn
->dn_objset
->os_freed_dnodes
++;
690 dnode_sync_free(dn
, tx
);
694 if (dn
->dn_num_slots
> DNODE_MIN_SLOTS
) {
695 dsl_dataset_t
*ds
= dn
->dn_objset
->os_dsl_dataset
;
696 mutex_enter(&ds
->ds_lock
);
697 ds
->ds_feature_activation_needed
[SPA_FEATURE_LARGE_DNODE
] =
699 mutex_exit(&ds
->ds_lock
);
702 if (dn
->dn_next_nlevels
[txgoff
]) {
703 dnode_increase_indirection(dn
, tx
);
704 dn
->dn_next_nlevels
[txgoff
] = 0;
707 if (dn
->dn_next_nblkptr
[txgoff
]) {
708 /* this should only happen on a realloc */
709 ASSERT(dn
->dn_allocated_txg
== tx
->tx_txg
);
710 if (dn
->dn_next_nblkptr
[txgoff
] > dnp
->dn_nblkptr
) {
711 /* zero the new blkptrs we are gaining */
712 bzero(dnp
->dn_blkptr
+ dnp
->dn_nblkptr
,
714 (dn
->dn_next_nblkptr
[txgoff
] - dnp
->dn_nblkptr
));
718 ASSERT(dn
->dn_next_nblkptr
[txgoff
] < dnp
->dn_nblkptr
);
719 /* the blkptrs we are losing better be unallocated */
720 for (i
= 0; i
< dnp
->dn_nblkptr
; i
++) {
721 if (i
>= dn
->dn_next_nblkptr
[txgoff
])
722 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[i
]));
726 mutex_enter(&dn
->dn_mtx
);
727 dnp
->dn_nblkptr
= dn
->dn_next_nblkptr
[txgoff
];
728 dn
->dn_next_nblkptr
[txgoff
] = 0;
729 mutex_exit(&dn
->dn_mtx
);
732 dbuf_sync_list(list
, dn
->dn_phys
->dn_nlevels
- 1, tx
);
734 if (!DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
735 ASSERT3P(list_head(list
), ==, NULL
);
736 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
740 * Although we have dropped our reference to the dnode, it
741 * can't be evicted until its written, and we haven't yet
742 * initiated the IO for the dnode's dbuf.