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;
123 dprintf("ds=%p obj=%llx num=%d\n", ds
, dn
->dn_object
, num
);
125 for (int i
= 0; i
< num
; i
++, bp
++) {
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 uint64_t lsize
= BP_GET_LSIZE(bp
);
141 dmu_object_type_t type
= BP_GET_TYPE(bp
);
142 uint64_t 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
, 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
, B_TRUE
, 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
;
351 ASSERT(start
< dn
->dn_phys
->dn_nblkptr
);
353 for (int i
= start
; i
<= end
; i
++, bp
++) {
356 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
357 VERIFY0(dbuf_hold_impl(dn
, dnlevel
- 1, i
,
359 rw_exit(&dn
->dn_struct_rwlock
);
361 free_children(db
, blkid
, nblks
, tx
);
367 dn
->dn_phys
->dn_maxblkid
= blkid
== 0 ? 0 : blkid
- 1;
369 uint64_t off
= (dn
->dn_phys
->dn_maxblkid
+ 1) *
370 (dn
->dn_phys
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
);
371 ASSERT(off
< dn
->dn_phys
->dn_maxblkid
||
372 dn
->dn_phys
->dn_maxblkid
== 0 ||
373 dnode_next_offset(dn
, 0, &off
, 1, 1, 0) != 0);
377 typedef struct dnode_sync_free_range_arg
{
378 dnode_t
*dsfra_dnode
;
380 } dnode_sync_free_range_arg_t
;
383 dnode_sync_free_range(void *arg
, uint64_t blkid
, uint64_t nblks
)
385 dnode_sync_free_range_arg_t
*dsfra
= arg
;
386 dnode_t
*dn
= dsfra
->dsfra_dnode
;
388 mutex_exit(&dn
->dn_mtx
);
389 dnode_sync_free_range_impl(dn
, blkid
, nblks
, dsfra
->dsfra_tx
);
390 mutex_enter(&dn
->dn_mtx
);
394 * Try to kick all the dnode's dbufs out of the cache...
397 dnode_evict_dbufs(dnode_t
*dn
)
403 dmu_buf_impl_t
*db
, marker
;
404 int evicting
= FALSE
;
407 mutex_enter(&dn
->dn_dbufs_mtx
);
408 list_insert_tail(&dn
->dn_dbufs
, &marker
);
409 db
= list_head(&dn
->dn_dbufs
);
410 for (; db
!= &marker
; db
= list_head(&dn
->dn_dbufs
)) {
411 list_remove(&dn
->dn_dbufs
, db
);
412 list_insert_tail(&dn
->dn_dbufs
, db
);
415 ASSERT3P(DB_DNODE(db
), ==, dn
);
419 mutex_enter(&db
->db_mtx
);
420 if (db
->db_state
== DB_EVICTING
) {
423 mutex_exit(&db
->db_mtx
);
424 } else if (refcount_is_zero(&db
->db_holds
)) {
426 dbuf_clear(db
); /* exits db_mtx for us */
428 mutex_exit(&db
->db_mtx
);
432 list_remove(&dn
->dn_dbufs
, &marker
);
434 * NB: we need to drop dn_dbufs_mtx between passes so
435 * that any DB_EVICTING dbufs can make progress.
436 * Ideally, we would have some cv we could wait on, but
437 * since we don't, just wait a bit to give the other
438 * thread a chance to run.
440 mutex_exit(&dn
->dn_dbufs_mtx
);
444 ASSERT(pass
< 100); /* sanity check */
447 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
448 if (dn
->dn_bonus
&& refcount_is_zero(&dn
->dn_bonus
->db_holds
)) {
449 mutex_enter(&dn
->dn_bonus
->db_mtx
);
450 dbuf_evict(dn
->dn_bonus
);
453 rw_exit(&dn
->dn_struct_rwlock
);
457 dnode_undirty_dbufs(list_t
*list
)
459 dbuf_dirty_record_t
*dr
;
461 while (dr
= list_head(list
)) {
462 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
463 uint64_t txg
= dr
->dr_txg
;
465 if (db
->db_level
!= 0)
466 dnode_undirty_dbufs(&dr
->dt
.di
.dr_children
);
468 mutex_enter(&db
->db_mtx
);
469 /* XXX - use dbuf_undirty()? */
470 list_remove(list
, dr
);
471 ASSERT(db
->db_last_dirty
== dr
);
472 db
->db_last_dirty
= NULL
;
473 db
->db_dirtycnt
-= 1;
474 if (db
->db_level
== 0) {
475 ASSERT(db
->db_blkid
== DMU_BONUS_BLKID
||
476 dr
->dt
.dl
.dr_data
== db
->db_buf
);
479 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
480 dbuf_rele_and_unlock(db
, (void *)(uintptr_t)txg
);
485 dnode_sync_free(dnode_t
*dn
, dmu_tx_t
*tx
)
487 int txgoff
= tx
->tx_txg
& TXG_MASK
;
489 ASSERT(dmu_tx_is_syncing(tx
));
492 * Our contents should have been freed in dnode_sync() by the
493 * free range record inserted by the caller of dnode_free().
495 ASSERT0(DN_USED_BYTES(dn
->dn_phys
));
496 ASSERT(BP_IS_HOLE(dn
->dn_phys
->dn_blkptr
));
498 dnode_undirty_dbufs(&dn
->dn_dirty_records
[txgoff
]);
499 dnode_evict_dbufs(dn
);
500 ASSERT3P(list_head(&dn
->dn_dbufs
), ==, NULL
);
501 ASSERT3P(dn
->dn_bonus
, ==, NULL
);
504 * XXX - It would be nice to assert this, but we may still
505 * have residual holds from async evictions from the arc...
507 * zfs_obj_to_path() also depends on this being
510 * ASSERT3U(refcount_count(&dn->dn_holds), ==, 1);
513 /* Undirty next bits */
514 dn
->dn_next_nlevels
[txgoff
] = 0;
515 dn
->dn_next_indblkshift
[txgoff
] = 0;
516 dn
->dn_next_blksz
[txgoff
] = 0;
518 /* ASSERT(blkptrs are zero); */
519 ASSERT(dn
->dn_phys
->dn_type
!= DMU_OT_NONE
);
520 ASSERT(dn
->dn_type
!= DMU_OT_NONE
);
522 ASSERT(dn
->dn_free_txg
> 0);
523 if (dn
->dn_allocated_txg
!= dn
->dn_free_txg
)
524 dmu_buf_will_dirty(&dn
->dn_dbuf
->db
, tx
);
525 bzero(dn
->dn_phys
, sizeof (dnode_phys_t
));
527 mutex_enter(&dn
->dn_mtx
);
528 dn
->dn_type
= DMU_OT_NONE
;
530 dn
->dn_allocated_txg
= 0;
532 dn
->dn_have_spill
= B_FALSE
;
533 mutex_exit(&dn
->dn_mtx
);
535 ASSERT(dn
->dn_object
!= DMU_META_DNODE_OBJECT
);
537 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
539 * Now that we've released our hold, the dnode may
540 * be evicted, so we musn't access it.
545 * Write out the dnode's dirty buffers.
548 dnode_sync(dnode_t
*dn
, dmu_tx_t
*tx
)
550 dnode_phys_t
*dnp
= dn
->dn_phys
;
551 int txgoff
= tx
->tx_txg
& TXG_MASK
;
552 list_t
*list
= &dn
->dn_dirty_records
[txgoff
];
553 static const dnode_phys_t zerodn
= { 0 };
554 boolean_t kill_spill
= B_FALSE
;
556 ASSERT(dmu_tx_is_syncing(tx
));
557 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
|| dn
->dn_allocated_txg
);
558 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
||
559 bcmp(dnp
, &zerodn
, DNODE_SIZE
) == 0);
562 ASSERT(dn
->dn_dbuf
== NULL
|| arc_released(dn
->dn_dbuf
->db_buf
));
564 if (dmu_objset_userused_enabled(dn
->dn_objset
) &&
565 !DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
566 mutex_enter(&dn
->dn_mtx
);
567 dn
->dn_oldused
= DN_USED_BYTES(dn
->dn_phys
);
568 dn
->dn_oldflags
= dn
->dn_phys
->dn_flags
;
569 dn
->dn_phys
->dn_flags
|= DNODE_FLAG_USERUSED_ACCOUNTED
;
570 mutex_exit(&dn
->dn_mtx
);
571 dmu_objset_userquota_get_ids(dn
, B_FALSE
, tx
);
573 /* Once we account for it, we should always account for it. */
574 ASSERT(!(dn
->dn_phys
->dn_flags
&
575 DNODE_FLAG_USERUSED_ACCOUNTED
));
578 mutex_enter(&dn
->dn_mtx
);
579 if (dn
->dn_allocated_txg
== tx
->tx_txg
) {
580 /* The dnode is newly allocated or reallocated */
581 if (dnp
->dn_type
== DMU_OT_NONE
) {
582 /* this is a first alloc, not a realloc */
584 dnp
->dn_nblkptr
= dn
->dn_nblkptr
;
587 dnp
->dn_type
= dn
->dn_type
;
588 dnp
->dn_bonustype
= dn
->dn_bonustype
;
589 dnp
->dn_bonuslen
= dn
->dn_bonuslen
;
591 ASSERT(dnp
->dn_nlevels
> 1 ||
592 BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
593 BP_IS_EMBEDDED(&dnp
->dn_blkptr
[0]) ||
594 BP_GET_LSIZE(&dnp
->dn_blkptr
[0]) ==
595 dnp
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
);
596 ASSERT(dnp
->dn_nlevels
< 2 ||
597 BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
598 BP_GET_LSIZE(&dnp
->dn_blkptr
[0]) == 1 << dnp
->dn_indblkshift
);
600 if (dn
->dn_next_type
[txgoff
] != 0) {
601 dnp
->dn_type
= dn
->dn_type
;
602 dn
->dn_next_type
[txgoff
] = 0;
605 if (dn
->dn_next_blksz
[txgoff
] != 0) {
606 ASSERT(P2PHASE(dn
->dn_next_blksz
[txgoff
],
607 SPA_MINBLOCKSIZE
) == 0);
608 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
609 dn
->dn_maxblkid
== 0 || list_head(list
) != NULL
||
610 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
==
611 dnp
->dn_datablkszsec
||
612 range_tree_space(dn
->dn_free_ranges
[txgoff
]) != 0);
613 dnp
->dn_datablkszsec
=
614 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
;
615 dn
->dn_next_blksz
[txgoff
] = 0;
618 if (dn
->dn_next_bonuslen
[txgoff
] != 0) {
619 if (dn
->dn_next_bonuslen
[txgoff
] == DN_ZERO_BONUSLEN
)
620 dnp
->dn_bonuslen
= 0;
622 dnp
->dn_bonuslen
= dn
->dn_next_bonuslen
[txgoff
];
623 ASSERT(dnp
->dn_bonuslen
<= DN_MAX_BONUSLEN
);
624 dn
->dn_next_bonuslen
[txgoff
] = 0;
627 if (dn
->dn_next_bonustype
[txgoff
] != 0) {
628 ASSERT(DMU_OT_IS_VALID(dn
->dn_next_bonustype
[txgoff
]));
629 dnp
->dn_bonustype
= dn
->dn_next_bonustype
[txgoff
];
630 dn
->dn_next_bonustype
[txgoff
] = 0;
633 boolean_t freeing_dnode
= dn
->dn_free_txg
> 0 &&
634 dn
->dn_free_txg
<= tx
->tx_txg
;
637 * We will either remove a spill block when a file is being removed
638 * or we have been asked to remove it.
640 if (dn
->dn_rm_spillblk
[txgoff
] ||
641 ((dnp
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
) && freeing_dnode
)) {
642 if ((dnp
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
))
644 dn
->dn_rm_spillblk
[txgoff
] = 0;
647 if (dn
->dn_next_indblkshift
[txgoff
] != 0) {
648 ASSERT(dnp
->dn_nlevels
== 1);
649 dnp
->dn_indblkshift
= dn
->dn_next_indblkshift
[txgoff
];
650 dn
->dn_next_indblkshift
[txgoff
] = 0;
654 * Just take the live (open-context) values for checksum and compress.
655 * Strictly speaking it's a future leak, but nothing bad happens if we
656 * start using the new checksum or compress algorithm a little early.
658 dnp
->dn_checksum
= dn
->dn_checksum
;
659 dnp
->dn_compress
= dn
->dn_compress
;
661 mutex_exit(&dn
->dn_mtx
);
664 free_blocks(dn
, &dn
->dn_phys
->dn_spill
, 1, tx
);
665 mutex_enter(&dn
->dn_mtx
);
666 dnp
->dn_flags
&= ~DNODE_FLAG_SPILL_BLKPTR
;
667 mutex_exit(&dn
->dn_mtx
);
670 /* process all the "freed" ranges in the file */
671 if (dn
->dn_free_ranges
[txgoff
] != NULL
) {
672 dnode_sync_free_range_arg_t dsfra
;
673 dsfra
.dsfra_dnode
= dn
;
675 mutex_enter(&dn
->dn_mtx
);
676 range_tree_vacate(dn
->dn_free_ranges
[txgoff
],
677 dnode_sync_free_range
, &dsfra
);
678 range_tree_destroy(dn
->dn_free_ranges
[txgoff
]);
679 dn
->dn_free_ranges
[txgoff
] = NULL
;
680 mutex_exit(&dn
->dn_mtx
);
684 dnode_sync_free(dn
, tx
);
688 if (dn
->dn_next_nblkptr
[txgoff
]) {
689 /* this should only happen on a realloc */
690 ASSERT(dn
->dn_allocated_txg
== tx
->tx_txg
);
691 if (dn
->dn_next_nblkptr
[txgoff
] > dnp
->dn_nblkptr
) {
692 /* zero the new blkptrs we are gaining */
693 bzero(dnp
->dn_blkptr
+ dnp
->dn_nblkptr
,
695 (dn
->dn_next_nblkptr
[txgoff
] - dnp
->dn_nblkptr
));
699 ASSERT(dn
->dn_next_nblkptr
[txgoff
] < dnp
->dn_nblkptr
);
700 /* the blkptrs we are losing better be unallocated */
701 for (i
= dn
->dn_next_nblkptr
[txgoff
];
702 i
< dnp
->dn_nblkptr
; i
++)
703 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[i
]));
706 mutex_enter(&dn
->dn_mtx
);
707 dnp
->dn_nblkptr
= dn
->dn_next_nblkptr
[txgoff
];
708 dn
->dn_next_nblkptr
[txgoff
] = 0;
709 mutex_exit(&dn
->dn_mtx
);
712 if (dn
->dn_next_nlevels
[txgoff
]) {
713 dnode_increase_indirection(dn
, tx
);
714 dn
->dn_next_nlevels
[txgoff
] = 0;
717 dbuf_sync_list(list
, tx
);
719 if (!DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
720 ASSERT3P(list_head(list
), ==, NULL
);
721 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
725 * Although we have dropped our reference to the dnode, it
726 * can't be evicted until its written, and we haven't yet
727 * initiated the IO for the dnode's dbuf.