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 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
458 if (dn
->dn_bonus
&& refcount_is_zero(&dn
->dn_bonus
->db_holds
)) {
459 mutex_enter(&dn
->dn_bonus
->db_mtx
);
460 dbuf_evict(dn
->dn_bonus
);
463 rw_exit(&dn
->dn_struct_rwlock
);
467 dnode_undirty_dbufs(list_t
*list
)
469 dbuf_dirty_record_t
*dr
;
471 while ((dr
= list_head(list
))) {
472 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
473 uint64_t txg
= dr
->dr_txg
;
475 if (db
->db_level
!= 0)
476 dnode_undirty_dbufs(&dr
->dt
.di
.dr_children
);
478 mutex_enter(&db
->db_mtx
);
479 /* XXX - use dbuf_undirty()? */
480 list_remove(list
, dr
);
481 ASSERT(db
->db_last_dirty
== dr
);
482 db
->db_last_dirty
= NULL
;
483 db
->db_dirtycnt
-= 1;
484 if (db
->db_level
== 0) {
485 ASSERT(db
->db_blkid
== DMU_BONUS_BLKID
||
486 dr
->dt
.dl
.dr_data
== db
->db_buf
);
489 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
490 dbuf_rele_and_unlock(db
, (void *)(uintptr_t)txg
);
495 dnode_sync_free(dnode_t
*dn
, dmu_tx_t
*tx
)
497 int txgoff
= tx
->tx_txg
& TXG_MASK
;
499 ASSERT(dmu_tx_is_syncing(tx
));
502 * Our contents should have been freed in dnode_sync() by the
503 * free range record inserted by the caller of dnode_free().
505 ASSERT0(DN_USED_BYTES(dn
->dn_phys
));
506 ASSERT(BP_IS_HOLE(dn
->dn_phys
->dn_blkptr
));
508 dnode_undirty_dbufs(&dn
->dn_dirty_records
[txgoff
]);
509 dnode_evict_dbufs(dn
);
510 ASSERT3P(list_head(&dn
->dn_dbufs
), ==, NULL
);
511 ASSERT3P(dn
->dn_bonus
, ==, NULL
);
514 * XXX - It would be nice to assert this, but we may still
515 * have residual holds from async evictions from the arc...
517 * zfs_obj_to_path() also depends on this being
520 * ASSERT3U(refcount_count(&dn->dn_holds), ==, 1);
523 /* Undirty next bits */
524 dn
->dn_next_nlevels
[txgoff
] = 0;
525 dn
->dn_next_indblkshift
[txgoff
] = 0;
526 dn
->dn_next_blksz
[txgoff
] = 0;
528 /* ASSERT(blkptrs are zero); */
529 ASSERT(dn
->dn_phys
->dn_type
!= DMU_OT_NONE
);
530 ASSERT(dn
->dn_type
!= DMU_OT_NONE
);
532 ASSERT(dn
->dn_free_txg
> 0);
533 if (dn
->dn_allocated_txg
!= dn
->dn_free_txg
)
534 dmu_buf_will_dirty(&dn
->dn_dbuf
->db
, tx
);
535 bzero(dn
->dn_phys
, sizeof (dnode_phys_t
));
537 mutex_enter(&dn
->dn_mtx
);
538 dn
->dn_type
= DMU_OT_NONE
;
540 dn
->dn_allocated_txg
= 0;
542 dn
->dn_have_spill
= B_FALSE
;
543 mutex_exit(&dn
->dn_mtx
);
545 ASSERT(dn
->dn_object
!= DMU_META_DNODE_OBJECT
);
547 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
549 * Now that we've released our hold, the dnode may
550 * be evicted, so we musn't access it.
555 * Write out the dnode's dirty buffers.
558 dnode_sync(dnode_t
*dn
, dmu_tx_t
*tx
)
560 dnode_phys_t
*dnp
= dn
->dn_phys
;
561 int txgoff
= tx
->tx_txg
& TXG_MASK
;
562 list_t
*list
= &dn
->dn_dirty_records
[txgoff
];
563 boolean_t kill_spill
= B_FALSE
;
564 boolean_t freeing_dnode
;
565 ASSERTV(static const dnode_phys_t zerodn
= { 0 });
567 ASSERT(dmu_tx_is_syncing(tx
));
568 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
|| dn
->dn_allocated_txg
);
569 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
||
570 bcmp(dnp
, &zerodn
, DNODE_SIZE
) == 0);
573 ASSERT(dn
->dn_dbuf
== NULL
|| arc_released(dn
->dn_dbuf
->db_buf
));
575 if (dmu_objset_userused_enabled(dn
->dn_objset
) &&
576 !DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
577 mutex_enter(&dn
->dn_mtx
);
578 dn
->dn_oldused
= DN_USED_BYTES(dn
->dn_phys
);
579 dn
->dn_oldflags
= dn
->dn_phys
->dn_flags
;
580 dn
->dn_phys
->dn_flags
|= DNODE_FLAG_USERUSED_ACCOUNTED
;
581 mutex_exit(&dn
->dn_mtx
);
582 dmu_objset_userquota_get_ids(dn
, B_FALSE
, tx
);
584 /* Once we account for it, we should always account for it. */
585 ASSERT(!(dn
->dn_phys
->dn_flags
&
586 DNODE_FLAG_USERUSED_ACCOUNTED
));
589 mutex_enter(&dn
->dn_mtx
);
590 if (dn
->dn_allocated_txg
== tx
->tx_txg
) {
591 /* The dnode is newly allocated or reallocated */
592 if (dnp
->dn_type
== DMU_OT_NONE
) {
593 /* this is a first alloc, not a realloc */
595 dnp
->dn_nblkptr
= dn
->dn_nblkptr
;
598 dnp
->dn_type
= dn
->dn_type
;
599 dnp
->dn_bonustype
= dn
->dn_bonustype
;
600 dnp
->dn_bonuslen
= dn
->dn_bonuslen
;
602 ASSERT(dnp
->dn_nlevels
> 1 ||
603 BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
604 BP_IS_EMBEDDED(&dnp
->dn_blkptr
[0]) ||
605 BP_GET_LSIZE(&dnp
->dn_blkptr
[0]) ==
606 dnp
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
);
607 ASSERT(dnp
->dn_nlevels
< 2 ||
608 BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
609 BP_GET_LSIZE(&dnp
->dn_blkptr
[0]) == 1 << dnp
->dn_indblkshift
);
611 if (dn
->dn_next_type
[txgoff
] != 0) {
612 dnp
->dn_type
= dn
->dn_type
;
613 dn
->dn_next_type
[txgoff
] = 0;
616 if (dn
->dn_next_blksz
[txgoff
] != 0) {
617 ASSERT(P2PHASE(dn
->dn_next_blksz
[txgoff
],
618 SPA_MINBLOCKSIZE
) == 0);
619 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
620 dn
->dn_maxblkid
== 0 || list_head(list
) != NULL
||
621 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
==
622 dnp
->dn_datablkszsec
||
623 range_tree_space(dn
->dn_free_ranges
[txgoff
]) != 0);
624 dnp
->dn_datablkszsec
=
625 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
;
626 dn
->dn_next_blksz
[txgoff
] = 0;
629 if (dn
->dn_next_bonuslen
[txgoff
] != 0) {
630 if (dn
->dn_next_bonuslen
[txgoff
] == DN_ZERO_BONUSLEN
)
631 dnp
->dn_bonuslen
= 0;
633 dnp
->dn_bonuslen
= dn
->dn_next_bonuslen
[txgoff
];
634 ASSERT(dnp
->dn_bonuslen
<= DN_MAX_BONUSLEN
);
635 dn
->dn_next_bonuslen
[txgoff
] = 0;
638 if (dn
->dn_next_bonustype
[txgoff
] != 0) {
639 ASSERT(DMU_OT_IS_VALID(dn
->dn_next_bonustype
[txgoff
]));
640 dnp
->dn_bonustype
= dn
->dn_next_bonustype
[txgoff
];
641 dn
->dn_next_bonustype
[txgoff
] = 0;
644 freeing_dnode
= dn
->dn_free_txg
> 0 && dn
->dn_free_txg
<= tx
->tx_txg
;
647 * We will either remove a spill block when a file is being removed
648 * or we have been asked to remove it.
650 if (dn
->dn_rm_spillblk
[txgoff
] ||
651 ((dnp
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
) && freeing_dnode
)) {
652 if ((dnp
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
))
654 dn
->dn_rm_spillblk
[txgoff
] = 0;
657 if (dn
->dn_next_indblkshift
[txgoff
] != 0) {
658 ASSERT(dnp
->dn_nlevels
== 1);
659 dnp
->dn_indblkshift
= dn
->dn_next_indblkshift
[txgoff
];
660 dn
->dn_next_indblkshift
[txgoff
] = 0;
664 * Just take the live (open-context) values for checksum and compress.
665 * Strictly speaking it's a future leak, but nothing bad happens if we
666 * start using the new checksum or compress algorithm a little early.
668 dnp
->dn_checksum
= dn
->dn_checksum
;
669 dnp
->dn_compress
= dn
->dn_compress
;
671 mutex_exit(&dn
->dn_mtx
);
674 free_blocks(dn
, &dn
->dn_phys
->dn_spill
, 1, tx
);
675 mutex_enter(&dn
->dn_mtx
);
676 dnp
->dn_flags
&= ~DNODE_FLAG_SPILL_BLKPTR
;
677 mutex_exit(&dn
->dn_mtx
);
680 /* process all the "freed" ranges in the file */
681 if (dn
->dn_free_ranges
[txgoff
] != NULL
) {
682 dnode_sync_free_range_arg_t dsfra
;
683 dsfra
.dsfra_dnode
= dn
;
685 mutex_enter(&dn
->dn_mtx
);
686 range_tree_vacate(dn
->dn_free_ranges
[txgoff
],
687 dnode_sync_free_range
, &dsfra
);
688 range_tree_destroy(dn
->dn_free_ranges
[txgoff
]);
689 dn
->dn_free_ranges
[txgoff
] = NULL
;
690 mutex_exit(&dn
->dn_mtx
);
694 dnode_sync_free(dn
, tx
);
698 if (dn
->dn_next_nblkptr
[txgoff
]) {
699 /* this should only happen on a realloc */
700 ASSERT(dn
->dn_allocated_txg
== tx
->tx_txg
);
701 if (dn
->dn_next_nblkptr
[txgoff
] > dnp
->dn_nblkptr
) {
702 /* zero the new blkptrs we are gaining */
703 bzero(dnp
->dn_blkptr
+ dnp
->dn_nblkptr
,
705 (dn
->dn_next_nblkptr
[txgoff
] - dnp
->dn_nblkptr
));
709 ASSERT(dn
->dn_next_nblkptr
[txgoff
] < dnp
->dn_nblkptr
);
710 /* the blkptrs we are losing better be unallocated */
711 for (i
= 0; i
< dnp
->dn_nblkptr
; i
++) {
712 if (i
>= dn
->dn_next_nblkptr
[txgoff
])
713 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[i
]));
717 mutex_enter(&dn
->dn_mtx
);
718 dnp
->dn_nblkptr
= dn
->dn_next_nblkptr
[txgoff
];
719 dn
->dn_next_nblkptr
[txgoff
] = 0;
720 mutex_exit(&dn
->dn_mtx
);
723 if (dn
->dn_next_nlevels
[txgoff
]) {
724 dnode_increase_indirection(dn
, tx
);
725 dn
->dn_next_nlevels
[txgoff
] = 0;
728 dbuf_sync_list(list
, tx
);
730 if (!DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
731 ASSERT3P(list_head(list
), ==, NULL
);
732 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
736 * Although we have dropped our reference to the dnode, it
737 * can't be evicted until its written, and we haven't yet
738 * initiated the IO for the dnode's dbuf.