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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/zfs_context.h>
27 #include <sys/dnode.h>
29 #include <sys/dmu_tx.h>
30 #include <sys/dmu_objset.h>
31 #include <sys/dsl_dataset.h>
35 dnode_increase_indirection(dnode_t
*dn
, dmu_tx_t
*tx
)
38 int txgoff
= tx
->tx_txg
& TXG_MASK
;
39 int nblkptr
= dn
->dn_phys
->dn_nblkptr
;
40 int old_toplvl
= dn
->dn_phys
->dn_nlevels
- 1;
41 int new_level
= dn
->dn_next_nlevels
[txgoff
];
44 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
46 /* this dnode can't be paged out because it's dirty */
47 ASSERT(dn
->dn_phys
->dn_type
!= DMU_OT_NONE
);
48 ASSERT(RW_WRITE_HELD(&dn
->dn_struct_rwlock
));
49 ASSERT(new_level
> 1 && dn
->dn_phys
->dn_nlevels
> 0);
51 db
= dbuf_hold_level(dn
, dn
->dn_phys
->dn_nlevels
, 0, FTAG
);
54 dn
->dn_phys
->dn_nlevels
= new_level
;
55 dprintf("os=%p obj=%llu, increase to %d\n", dn
->dn_objset
,
56 dn
->dn_object
, dn
->dn_phys
->dn_nlevels
);
58 /* check for existing blkptrs in the dnode */
59 for (i
= 0; i
< nblkptr
; i
++)
60 if (!BP_IS_HOLE(&dn
->dn_phys
->dn_blkptr
[i
]))
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
);
73 /* set dbuf's parent pointers to new indirect buf */
74 for (i
= 0; i
< nblkptr
; i
++) {
75 dmu_buf_impl_t
*child
= dbuf_find(dn
, 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;
118 int i
, blocks_freed
= 0;
120 dprintf("ds=%p obj=%llx num=%d\n", ds
, dn
->dn_object
, num
);
122 for (i
= 0; i
< num
; i
++, bp
++) {
126 bytesfreed
+= dsl_dataset_block_kill(ds
, bp
, tx
, B_FALSE
);
127 ASSERT3U(bytesfreed
, <=, DN_USED_BYTES(dn
->dn_phys
));
128 bzero(bp
, sizeof (blkptr_t
));
131 dnode_diduse_space(dn
, -bytesfreed
);
132 return (blocks_freed
);
137 free_verify(dmu_buf_impl_t
*db
, uint64_t start
, uint64_t end
, dmu_tx_t
*tx
)
141 uint64_t txg
= tx
->tx_txg
;
146 epbs
= dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
147 off
= start
- (db
->db_blkid
* 1<<epbs
);
148 num
= end
- start
+ 1;
150 ASSERT3U(off
, >=, 0);
151 ASSERT3U(num
, >=, 0);
152 ASSERT3U(db
->db_level
, >, 0);
153 ASSERT3U(db
->db
.db_size
, ==, 1 << dn
->dn_phys
->dn_indblkshift
);
154 ASSERT3U(off
+num
, <=, db
->db
.db_size
>> SPA_BLKPTRSHIFT
);
155 ASSERT(db
->db_blkptr
!= NULL
);
157 for (i
= off
; i
< off
+num
; i
++) {
159 dmu_buf_impl_t
*child
;
160 dbuf_dirty_record_t
*dr
;
163 ASSERT(db
->db_level
== 1);
165 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
166 err
= dbuf_hold_impl(dn
, db
->db_level
-1,
167 (db
->db_blkid
<< epbs
) + i
, TRUE
, FTAG
, &child
);
168 rw_exit(&dn
->dn_struct_rwlock
);
172 ASSERT(child
->db_level
== 0);
173 dr
= child
->db_last_dirty
;
174 while (dr
&& dr
->dr_txg
> txg
)
176 ASSERT(dr
== NULL
|| dr
->dr_txg
== txg
);
178 /* data_old better be zeroed */
180 buf
= dr
->dt
.dl
.dr_data
->b_data
;
181 for (j
= 0; j
< child
->db
.db_size
>> 3; j
++) {
183 panic("freed data not zero: "
184 "child=%p i=%d off=%d num=%d\n",
185 (void *)child
, i
, off
, num
);
191 * db_data better be zeroed unless it's dirty in a
194 mutex_enter(&child
->db_mtx
);
195 buf
= child
->db
.db_data
;
196 if (buf
!= NULL
&& child
->db_state
!= DB_FILL
&&
197 child
->db_last_dirty
== NULL
) {
198 for (j
= 0; j
< child
->db
.db_size
>> 3; j
++) {
200 panic("freed data not zero: "
201 "child=%p i=%d off=%d num=%d\n",
202 (void *)child
, i
, off
, num
);
206 mutex_exit(&child
->db_mtx
);
208 dbuf_rele(child
, FTAG
);
217 free_children(dmu_buf_impl_t
*db
, uint64_t blkid
, uint64_t nblks
, int trunc
,
222 dmu_buf_impl_t
*subdb
;
223 uint64_t start
, end
, dbstart
, dbend
, i
;
224 int epbs
, shift
, err
;
226 int blocks_freed
= 0;
229 * There is a small possibility that this block will not be cached:
230 * 1 - if level > 1 and there are no children with level <= 1
231 * 2 - if we didn't get a dirty hold (because this block had just
232 * finished being written -- and so had no holds), and then this
233 * block got evicted before we got here.
235 if (db
->db_state
!= DB_CACHED
)
236 (void) dbuf_read(db
, NULL
, DB_RF_MUST_SUCCEED
);
239 bp
= (blkptr_t
*)db
->db
.db_data
;
243 epbs
= dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
244 shift
= (db
->db_level
- 1) * epbs
;
245 dbstart
= db
->db_blkid
<< epbs
;
246 start
= blkid
>> shift
;
247 if (dbstart
< start
) {
248 bp
+= start
- dbstart
;
253 dbend
= ((db
->db_blkid
+ 1) << epbs
) - 1;
254 end
= (blkid
+ nblks
- 1) >> shift
;
259 ASSERT3U(start
, <=, end
);
261 if (db
->db_level
== 1) {
262 FREE_VERIFY(db
, start
, end
, tx
);
263 blocks_freed
= free_blocks(dn
, bp
, end
-start
+1, tx
);
264 arc_buf_freeze(db
->db_buf
);
265 ASSERT(all
|| blocks_freed
== 0 || db
->db_last_dirty
);
267 return (all
? ALL
: blocks_freed
);
270 for (i
= start
; i
<= end
; i
++, bp
++) {
273 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
274 err
= dbuf_hold_impl(dn
, db
->db_level
-1, i
, TRUE
, FTAG
, &subdb
);
275 ASSERT3U(err
, ==, 0);
276 rw_exit(&dn
->dn_struct_rwlock
);
278 if (free_children(subdb
, blkid
, nblks
, trunc
, tx
) == ALL
) {
279 ASSERT3P(subdb
->db_blkptr
, ==, bp
);
280 blocks_freed
+= free_blocks(dn
, bp
, 1, tx
);
284 dbuf_rele(subdb
, FTAG
);
287 arc_buf_freeze(db
->db_buf
);
290 for (i
= start
; i
<= end
; i
++, bp
++) {
291 if (i
== start
&& blkid
!= 0)
293 else if (i
== end
&& !trunc
)
295 ASSERT3U(bp
->blk_birth
, ==, 0);
298 ASSERT(all
|| blocks_freed
== 0 || db
->db_last_dirty
);
299 return (all
? ALL
: blocks_freed
);
303 * free_range: Traverse the indicated range of the provided file
304 * and "free" all the blocks contained there.
307 dnode_sync_free_range(dnode_t
*dn
, uint64_t blkid
, uint64_t nblks
, dmu_tx_t
*tx
)
309 blkptr_t
*bp
= dn
->dn_phys
->dn_blkptr
;
311 int trunc
, start
, end
, shift
, i
, err
;
312 int dnlevel
= dn
->dn_phys
->dn_nlevels
;
314 if (blkid
> dn
->dn_phys
->dn_maxblkid
)
317 ASSERT(dn
->dn_phys
->dn_maxblkid
< UINT64_MAX
);
318 trunc
= blkid
+ nblks
> dn
->dn_phys
->dn_maxblkid
;
320 nblks
= dn
->dn_phys
->dn_maxblkid
- blkid
+ 1;
322 /* There are no indirect blocks in the object */
324 if (blkid
>= dn
->dn_phys
->dn_nblkptr
) {
325 /* this range was never made persistent */
328 ASSERT3U(blkid
+ nblks
, <=, dn
->dn_phys
->dn_nblkptr
);
329 (void) free_blocks(dn
, bp
+ blkid
, nblks
, tx
);
331 ASSERTV(uint64_t off
= (dn
->dn_phys
->dn_maxblkid
+ 1) *
332 (dn
->dn_phys
->dn_datablkszsec
<<SPA_MINBLOCKSHIFT
));
333 dn
->dn_phys
->dn_maxblkid
= (blkid
? blkid
- 1 : 0);
334 ASSERT(off
< dn
->dn_phys
->dn_maxblkid
||
335 dn
->dn_phys
->dn_maxblkid
== 0 ||
336 dnode_next_offset(dn
, 0, &off
, 1, 1, 0) != 0);
341 shift
= (dnlevel
- 1) * (dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
);
342 start
= blkid
>> shift
;
343 ASSERT(start
< dn
->dn_phys
->dn_nblkptr
);
344 end
= (blkid
+ nblks
- 1) >> shift
;
346 for (i
= start
; i
<= end
; i
++, bp
++) {
349 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
350 err
= dbuf_hold_impl(dn
, dnlevel
-1, i
, TRUE
, FTAG
, &db
);
351 ASSERT3U(err
, ==, 0);
352 rw_exit(&dn
->dn_struct_rwlock
);
354 if (free_children(db
, blkid
, nblks
, trunc
, tx
) == ALL
) {
355 ASSERT3P(db
->db_blkptr
, ==, bp
);
356 (void) free_blocks(dn
, bp
, 1, tx
);
361 ASSERTV(uint64_t off
= (dn
->dn_phys
->dn_maxblkid
+ 1) *
362 (dn
->dn_phys
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
));
363 dn
->dn_phys
->dn_maxblkid
= (blkid
? blkid
- 1 : 0);
364 ASSERT(off
< dn
->dn_phys
->dn_maxblkid
||
365 dn
->dn_phys
->dn_maxblkid
== 0 ||
366 dnode_next_offset(dn
, 0, &off
, 1, 1, 0) != 0);
371 * Try to kick all the dnodes dbufs out of the cache...
374 dnode_evict_dbufs(dnode_t
*dn
)
380 dmu_buf_impl_t
*db
, marker
;
381 int evicting
= FALSE
;
384 mutex_enter(&dn
->dn_dbufs_mtx
);
385 list_insert_tail(&dn
->dn_dbufs
, &marker
);
386 db
= list_head(&dn
->dn_dbufs
);
387 for (; db
!= &marker
; db
= list_head(&dn
->dn_dbufs
)) {
388 list_remove(&dn
->dn_dbufs
, db
);
389 list_insert_tail(&dn
->dn_dbufs
, db
);
392 ASSERT3P(DB_DNODE(db
), ==, dn
);
396 mutex_enter(&db
->db_mtx
);
397 if (db
->db_state
== DB_EVICTING
) {
400 mutex_exit(&db
->db_mtx
);
401 } else if (refcount_is_zero(&db
->db_holds
)) {
403 dbuf_clear(db
); /* exits db_mtx for us */
405 mutex_exit(&db
->db_mtx
);
409 list_remove(&dn
->dn_dbufs
, &marker
);
411 * NB: we need to drop dn_dbufs_mtx between passes so
412 * that any DB_EVICTING dbufs can make progress.
413 * Ideally, we would have some cv we could wait on, but
414 * since we don't, just wait a bit to give the other
415 * thread a chance to run.
417 mutex_exit(&dn
->dn_dbufs_mtx
);
421 if ((pass
% 100) == 0)
422 dprintf("Exceeded %d passes evicting dbufs\n", pass
);
426 dprintf("Required %d passes to evict dbufs\n", pass
);
428 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
429 if (dn
->dn_bonus
&& refcount_is_zero(&dn
->dn_bonus
->db_holds
)) {
430 mutex_enter(&dn
->dn_bonus
->db_mtx
);
431 dbuf_evict(dn
->dn_bonus
);
434 rw_exit(&dn
->dn_struct_rwlock
);
438 dnode_undirty_dbufs(list_t
*list
)
440 dbuf_dirty_record_t
*dr
;
442 while ((dr
= list_head(list
))) {
443 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
444 uint64_t txg
= dr
->dr_txg
;
446 if (db
->db_level
!= 0)
447 dnode_undirty_dbufs(&dr
->dt
.di
.dr_children
);
449 mutex_enter(&db
->db_mtx
);
450 /* XXX - use dbuf_undirty()? */
451 list_remove(list
, dr
);
452 ASSERT(db
->db_last_dirty
== dr
);
453 db
->db_last_dirty
= NULL
;
454 db
->db_dirtycnt
-= 1;
455 if (db
->db_level
== 0) {
456 ASSERT(db
->db_blkid
== DMU_BONUS_BLKID
||
457 dr
->dt
.dl
.dr_data
== db
->db_buf
);
460 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
461 dbuf_rele_and_unlock(db
, (void *)(uintptr_t)txg
);
466 dnode_sync_free(dnode_t
*dn
, dmu_tx_t
*tx
)
468 int txgoff
= tx
->tx_txg
& TXG_MASK
;
470 ASSERT(dmu_tx_is_syncing(tx
));
473 * Our contents should have been freed in dnode_sync() by the
474 * free range record inserted by the caller of dnode_free().
476 ASSERT3U(DN_USED_BYTES(dn
->dn_phys
), ==, 0);
477 ASSERT(BP_IS_HOLE(dn
->dn_phys
->dn_blkptr
));
479 dnode_undirty_dbufs(&dn
->dn_dirty_records
[txgoff
]);
480 dnode_evict_dbufs(dn
);
481 ASSERT3P(list_head(&dn
->dn_dbufs
), ==, NULL
);
484 * XXX - It would be nice to assert this, but we may still
485 * have residual holds from async evictions from the arc...
487 * zfs_obj_to_path() also depends on this being
490 * ASSERT3U(refcount_count(&dn->dn_holds), ==, 1);
493 /* Undirty next bits */
494 dn
->dn_next_nlevels
[txgoff
] = 0;
495 dn
->dn_next_indblkshift
[txgoff
] = 0;
496 dn
->dn_next_blksz
[txgoff
] = 0;
498 /* ASSERT(blkptrs are zero); */
499 ASSERT(dn
->dn_phys
->dn_type
!= DMU_OT_NONE
);
500 ASSERT(dn
->dn_type
!= DMU_OT_NONE
);
502 ASSERT(dn
->dn_free_txg
> 0);
503 if (dn
->dn_allocated_txg
!= dn
->dn_free_txg
)
504 dbuf_will_dirty(dn
->dn_dbuf
, tx
);
505 bzero(dn
->dn_phys
, sizeof (dnode_phys_t
));
507 mutex_enter(&dn
->dn_mtx
);
508 dn
->dn_type
= DMU_OT_NONE
;
510 dn
->dn_allocated_txg
= 0;
512 dn
->dn_have_spill
= B_FALSE
;
513 mutex_exit(&dn
->dn_mtx
);
515 ASSERT(dn
->dn_object
!= DMU_META_DNODE_OBJECT
);
517 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
519 * Now that we've released our hold, the dnode may
520 * be evicted, so we musn't access it.
525 * Write out the dnode's dirty buffers.
528 dnode_sync(dnode_t
*dn
, dmu_tx_t
*tx
)
531 dnode_phys_t
*dnp
= dn
->dn_phys
;
532 int txgoff
= tx
->tx_txg
& TXG_MASK
;
533 list_t
*list
= &dn
->dn_dirty_records
[txgoff
];
534 boolean_t kill_spill
= B_FALSE
;
535 ASSERTV(static const dnode_phys_t zerodn
= { 0 });
537 ASSERT(dmu_tx_is_syncing(tx
));
538 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
|| dn
->dn_allocated_txg
);
539 ASSERT(dnp
->dn_type
!= DMU_OT_NONE
||
540 bcmp(dnp
, &zerodn
, DNODE_SIZE
) == 0);
543 ASSERT(dn
->dn_dbuf
== NULL
|| arc_released(dn
->dn_dbuf
->db_buf
));
545 if (dmu_objset_userused_enabled(dn
->dn_objset
) &&
546 !DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
547 mutex_enter(&dn
->dn_mtx
);
548 dn
->dn_oldused
= DN_USED_BYTES(dn
->dn_phys
);
549 dn
->dn_oldflags
= dn
->dn_phys
->dn_flags
;
550 dn
->dn_phys
->dn_flags
|= DNODE_FLAG_USERUSED_ACCOUNTED
;
551 mutex_exit(&dn
->dn_mtx
);
552 dmu_objset_userquota_get_ids(dn
, B_FALSE
, tx
);
554 /* Once we account for it, we should always account for it. */
555 ASSERT(!(dn
->dn_phys
->dn_flags
&
556 DNODE_FLAG_USERUSED_ACCOUNTED
));
559 mutex_enter(&dn
->dn_mtx
);
560 if (dn
->dn_allocated_txg
== tx
->tx_txg
) {
561 /* The dnode is newly allocated or reallocated */
562 if (dnp
->dn_type
== DMU_OT_NONE
) {
563 /* this is a first alloc, not a realloc */
565 dnp
->dn_nblkptr
= dn
->dn_nblkptr
;
568 dnp
->dn_type
= dn
->dn_type
;
569 dnp
->dn_bonustype
= dn
->dn_bonustype
;
570 dnp
->dn_bonuslen
= dn
->dn_bonuslen
;
573 ASSERT(dnp
->dn_nlevels
> 1 ||
574 BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
575 BP_GET_LSIZE(&dnp
->dn_blkptr
[0]) ==
576 dnp
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
);
578 if (dn
->dn_next_blksz
[txgoff
]) {
579 ASSERT(P2PHASE(dn
->dn_next_blksz
[txgoff
],
580 SPA_MINBLOCKSIZE
) == 0);
581 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[0]) ||
582 dn
->dn_maxblkid
== 0 || list_head(list
) != NULL
||
583 avl_last(&dn
->dn_ranges
[txgoff
]) ||
584 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
==
585 dnp
->dn_datablkszsec
);
586 dnp
->dn_datablkszsec
=
587 dn
->dn_next_blksz
[txgoff
] >> SPA_MINBLOCKSHIFT
;
588 dn
->dn_next_blksz
[txgoff
] = 0;
591 if (dn
->dn_next_bonuslen
[txgoff
]) {
592 if (dn
->dn_next_bonuslen
[txgoff
] == DN_ZERO_BONUSLEN
)
593 dnp
->dn_bonuslen
= 0;
595 dnp
->dn_bonuslen
= dn
->dn_next_bonuslen
[txgoff
];
596 ASSERT(dnp
->dn_bonuslen
<= DN_MAX_BONUSLEN
);
597 dn
->dn_next_bonuslen
[txgoff
] = 0;
600 if (dn
->dn_next_bonustype
[txgoff
]) {
601 ASSERT(dn
->dn_next_bonustype
[txgoff
] < DMU_OT_NUMTYPES
);
602 dnp
->dn_bonustype
= dn
->dn_next_bonustype
[txgoff
];
603 dn
->dn_next_bonustype
[txgoff
] = 0;
607 * We will either remove a spill block when a file is being removed
608 * or we have been asked to remove it.
610 if (dn
->dn_rm_spillblk
[txgoff
] ||
611 ((dnp
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
) &&
612 dn
->dn_free_txg
> 0 && dn
->dn_free_txg
<= tx
->tx_txg
)) {
613 if ((dnp
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
))
615 dn
->dn_rm_spillblk
[txgoff
] = 0;
618 if (dn
->dn_next_indblkshift
[txgoff
]) {
619 ASSERT(dnp
->dn_nlevels
== 1);
620 dnp
->dn_indblkshift
= dn
->dn_next_indblkshift
[txgoff
];
621 dn
->dn_next_indblkshift
[txgoff
] = 0;
625 * Just take the live (open-context) values for checksum and compress.
626 * Strictly speaking it's a future leak, but nothing bad happens if we
627 * start using the new checksum or compress algorithm a little early.
629 dnp
->dn_checksum
= dn
->dn_checksum
;
630 dnp
->dn_compress
= dn
->dn_compress
;
632 mutex_exit(&dn
->dn_mtx
);
635 (void) free_blocks(dn
, &dn
->dn_phys
->dn_spill
, 1, tx
);
636 mutex_enter(&dn
->dn_mtx
);
637 dnp
->dn_flags
&= ~DNODE_FLAG_SPILL_BLKPTR
;
638 mutex_exit(&dn
->dn_mtx
);
641 /* process all the "freed" ranges in the file */
642 while ((rp
= avl_last(&dn
->dn_ranges
[txgoff
]))) {
643 dnode_sync_free_range(dn
, rp
->fr_blkid
, rp
->fr_nblks
, tx
);
644 /* grab the mutex so we don't race with dnode_block_freed() */
645 mutex_enter(&dn
->dn_mtx
);
646 avl_remove(&dn
->dn_ranges
[txgoff
], rp
);
647 mutex_exit(&dn
->dn_mtx
);
648 kmem_free(rp
, sizeof (free_range_t
));
651 if (dn
->dn_free_txg
> 0 && dn
->dn_free_txg
<= tx
->tx_txg
) {
652 dnode_sync_free(dn
, tx
);
656 if (dn
->dn_next_nblkptr
[txgoff
]) {
657 /* this should only happen on a realloc */
658 ASSERT(dn
->dn_allocated_txg
== tx
->tx_txg
);
659 if (dn
->dn_next_nblkptr
[txgoff
] > dnp
->dn_nblkptr
) {
660 /* zero the new blkptrs we are gaining */
661 bzero(dnp
->dn_blkptr
+ dnp
->dn_nblkptr
,
663 (dn
->dn_next_nblkptr
[txgoff
] - dnp
->dn_nblkptr
));
667 ASSERT(dn
->dn_next_nblkptr
[txgoff
] < dnp
->dn_nblkptr
);
668 /* the blkptrs we are losing better be unallocated */
669 for (i
= dn
->dn_next_nblkptr
[txgoff
];
670 i
< dnp
->dn_nblkptr
; i
++)
671 ASSERT(BP_IS_HOLE(&dnp
->dn_blkptr
[i
]));
674 mutex_enter(&dn
->dn_mtx
);
675 dnp
->dn_nblkptr
= dn
->dn_next_nblkptr
[txgoff
];
676 dn
->dn_next_nblkptr
[txgoff
] = 0;
677 mutex_exit(&dn
->dn_mtx
);
680 if (dn
->dn_next_nlevels
[txgoff
]) {
681 dnode_increase_indirection(dn
, tx
);
682 dn
->dn_next_nlevels
[txgoff
] = 0;
685 dbuf_sync_list(list
, tx
);
687 if (!DMU_OBJECT_IS_SPECIAL(dn
->dn_object
)) {
688 ASSERT3P(list_head(list
), ==, NULL
);
689 dnode_rele(dn
, (void *)(uintptr_t)tx
->tx_txg
);
693 * Although we have dropped our reference to the dnode, it
694 * can't be evicted until its written, and we haven't yet
695 * initiated the IO for the dnode's dbuf.