1fa9e4066Sahrens /*
2fa9e4066Sahrens * CDDL HEADER START
3fa9e4066Sahrens *
4fa9e4066Sahrens * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock * You may not use this file except in compliance with the License.
7fa9e4066Sahrens *
8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens * See the License for the specific language governing permissions
11fa9e4066Sahrens * and limitations under the License.
12fa9e4066Sahrens *
13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens *
19fa9e4066Sahrens * CDDL HEADER END
20fa9e4066Sahrens */
21ad135b5dSChristopher Siden
22fa9e4066Sahrens /*
2306e0070dSMark Shellenbaum * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2446e1baa6SMatthew Ahrens * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
25bc9014e6SJustin Gibbs * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
26fa9e4066Sahrens */
27fa9e4066Sahrens
28fa9e4066Sahrens #include <sys/zfs_context.h>
29fa9e4066Sahrens #include <sys/dbuf.h>
30fa9e4066Sahrens #include <sys/dnode.h>
31fa9e4066Sahrens #include <sys/dmu.h>
32fa9e4066Sahrens #include <sys/dmu_tx.h>
33fa9e4066Sahrens #include <sys/dmu_objset.h>
34fa9e4066Sahrens #include <sys/dsl_dataset.h>
35fa9e4066Sahrens #include <sys/spa.h>
36bf16b11eSMatthew Ahrens #include <sys/range_tree.h>
3743466aaeSMax Grossman #include <sys/zfeature.h>
38fa9e4066Sahrens
39fa9e4066Sahrens static void
dnode_increase_indirection(dnode_t * dn,dmu_tx_t * tx)40fa9e4066Sahrens dnode_increase_indirection(dnode_t *dn, dmu_tx_t *tx)
41fa9e4066Sahrens {
42fa9e4066Sahrens dmu_buf_impl_t *db;
43c717a561Smaybee int txgoff = tx->tx_txg & TXG_MASK;
44c717a561Smaybee int nblkptr = dn->dn_phys->dn_nblkptr;
45c717a561Smaybee int old_toplvl = dn->dn_phys->dn_nlevels - 1;
46c717a561Smaybee int new_level = dn->dn_next_nlevels[txgoff];
47fa9e4066Sahrens int i;
48fa9e4066Sahrens
49c717a561Smaybee rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
50c717a561Smaybee
51c717a561Smaybee /* this dnode can't be paged out because it's dirty */
52fa9e4066Sahrens ASSERT(dn->dn_phys->dn_type != DMU_OT_NONE);
53fa9e4066Sahrens ASSERT(RW_WRITE_HELD(&dn->dn_struct_rwlock));
54c717a561Smaybee ASSERT(new_level > 1 && dn->dn_phys->dn_nlevels > 0);
55fa9e4066Sahrens
56fa9e4066Sahrens db = dbuf_hold_level(dn, dn->dn_phys->dn_nlevels, 0, FTAG);
57ea8dc4b6Seschrock ASSERT(db != NULL);
58fa9e4066Sahrens
59c717a561Smaybee dn->dn_phys->dn_nlevels = new_level;
60f82bfe17Sgw25295 dprintf("os=%p obj=%llu, increase to %d\n", dn->dn_objset,
61f82bfe17Sgw25295 dn->dn_object, dn->dn_phys->dn_nlevels);
62fa9e4066Sahrens
63c717a561Smaybee /* check for existing blkptrs in the dnode */
64c717a561Smaybee for (i = 0; i < nblkptr; i++)
65c717a561Smaybee if (!BP_IS_HOLE(&dn->dn_phys->dn_blkptr[i]))
66c717a561Smaybee break;
67c717a561Smaybee if (i != nblkptr) {
68c717a561Smaybee /* transfer dnode's block pointers to new indirect block */
69c717a561Smaybee (void) dbuf_read(db, NULL, DB_RF_MUST_SUCCEED|DB_RF_HAVESTRUCT);
70c717a561Smaybee ASSERT(db->db.db_data);
71c717a561Smaybee ASSERT(arc_released(db->db_buf));
72c717a561Smaybee ASSERT3U(sizeof (blkptr_t) * nblkptr, <=, db->db.db_size);
73c717a561Smaybee bcopy(dn->dn_phys->dn_blkptr, db->db.db_data,
74c717a561Smaybee sizeof (blkptr_t) * nblkptr);
75c717a561Smaybee arc_buf_freeze(db->db_buf);
76c717a561Smaybee }
77c717a561Smaybee
78fa9e4066Sahrens /* set dbuf's parent pointers to new indirect buf */
79c717a561Smaybee for (i = 0; i < nblkptr; i++) {
80e57a022bSJustin T. Gibbs dmu_buf_impl_t *child =
81e57a022bSJustin T. Gibbs dbuf_find(dn->dn_objset, dn->dn_object, old_toplvl, i);
82c717a561Smaybee
83fa9e4066Sahrens if (child == NULL)
84fa9e4066Sahrens continue;
85744947dcSTom Erickson #ifdef DEBUG
86744947dcSTom Erickson DB_DNODE_ENTER(child);
87744947dcSTom Erickson ASSERT3P(DB_DNODE(child), ==, dn);
88744947dcSTom Erickson DB_DNODE_EXIT(child);
89744947dcSTom Erickson #endif /* DEBUG */
90c717a561Smaybee if (child->db_parent && child->db_parent != dn->dn_dbuf) {
91c717a561Smaybee ASSERT(child->db_parent->db_level == db->db_level);
92c717a561Smaybee ASSERT(child->db_blkptr !=
93c717a561Smaybee &dn->dn_phys->dn_blkptr[child->db_blkid]);
94fa9e4066Sahrens mutex_exit(&child->db_mtx);
95fa9e4066Sahrens continue;
96fa9e4066Sahrens }
97c717a561Smaybee ASSERT(child->db_parent == NULL ||
98c717a561Smaybee child->db_parent == dn->dn_dbuf);
99fa9e4066Sahrens
100fa9e4066Sahrens child->db_parent = db;
101fa9e4066Sahrens dbuf_add_ref(db, child);
102c717a561Smaybee if (db->db.db_data)
103c717a561Smaybee child->db_blkptr = (blkptr_t *)db->db.db_data + i;
104c717a561Smaybee else
105fa9e4066Sahrens child->db_blkptr = NULL;
106fa9e4066Sahrens dprintf_dbuf_bp(child, child->db_blkptr,
107fa9e4066Sahrens "changed db_blkptr to new indirect %s", "");
108fa9e4066Sahrens
109fa9e4066Sahrens mutex_exit(&child->db_mtx);
110fa9e4066Sahrens }
111fa9e4066Sahrens
112c717a561Smaybee bzero(dn->dn_phys->dn_blkptr, sizeof (blkptr_t) * nblkptr);
113fa9e4066Sahrens
114ea8dc4b6Seschrock dbuf_rele(db, FTAG);
115c717a561Smaybee
116c717a561Smaybee rw_exit(&dn->dn_struct_rwlock);
117fa9e4066Sahrens }
118fa9e4066Sahrens
11943466aaeSMax Grossman static void
free_blocks(dnode_t * dn,blkptr_t * bp,int num,dmu_tx_t * tx)120fa9e4066Sahrens free_blocks(dnode_t *dn, blkptr_t *bp, int num, dmu_tx_t *tx)
121fa9e4066Sahrens {
122cdb0ab79Smaybee dsl_dataset_t *ds = dn->dn_objset->os_dsl_dataset;
123fa9e4066Sahrens uint64_t bytesfreed = 0;
124fa9e4066Sahrens
125cdb0ab79Smaybee dprintf("ds=%p obj=%llx num=%d\n", ds, dn->dn_object, num);
126fa9e4066Sahrens
12743466aaeSMax Grossman for (int i = 0; i < num; i++, bp++) {
128fa9e4066Sahrens if (BP_IS_HOLE(bp))
129fa9e4066Sahrens continue;
130fa9e4066Sahrens
131b24ab676SJeff Bonwick bytesfreed += dsl_dataset_block_kill(ds, bp, tx, B_FALSE);
13299653d4eSeschrock ASSERT3U(bytesfreed, <=, DN_USED_BYTES(dn->dn_phys));
13343466aaeSMax Grossman
13443466aaeSMax Grossman /*
13543466aaeSMax Grossman * Save some useful information on the holes being
13643466aaeSMax Grossman * punched, including logical size, type, and indirection
13743466aaeSMax Grossman * level. Retaining birth time enables detection of when
13843466aaeSMax Grossman * holes are punched for reducing the number of free
13943466aaeSMax Grossman * records transmitted during a zfs send.
14043466aaeSMax Grossman */
14143466aaeSMax Grossman
14243466aaeSMax Grossman uint64_t lsize = BP_GET_LSIZE(bp);
14343466aaeSMax Grossman dmu_object_type_t type = BP_GET_TYPE(bp);
14443466aaeSMax Grossman uint64_t lvl = BP_GET_LEVEL(bp);
14543466aaeSMax Grossman
146c717a561Smaybee bzero(bp, sizeof (blkptr_t));
14743466aaeSMax Grossman
14843466aaeSMax Grossman if (spa_feature_is_active(dn->dn_objset->os_spa,
14943466aaeSMax Grossman SPA_FEATURE_HOLE_BIRTH)) {
15043466aaeSMax Grossman BP_SET_LSIZE(bp, lsize);
15143466aaeSMax Grossman BP_SET_TYPE(bp, type);
15243466aaeSMax Grossman BP_SET_LEVEL(bp, lvl);
15343466aaeSMax Grossman BP_SET_BIRTH(bp, dmu_tx_get_txg(tx), 0);
15443466aaeSMax Grossman }
155fa9e4066Sahrens }
156fa9e4066Sahrens dnode_diduse_space(dn, -bytesfreed);
157fa9e4066Sahrens }
158fa9e4066Sahrens
1599c9dc39aSek110237 #ifdef ZFS_DEBUG
160fa9e4066Sahrens static void
free_verify(dmu_buf_impl_t * db,uint64_t start,uint64_t end,dmu_tx_t * tx)161fa9e4066Sahrens free_verify(dmu_buf_impl_t *db, uint64_t start, uint64_t end, dmu_tx_t *tx)
162fa9e4066Sahrens {
163fa9e4066Sahrens int off, num;
164fa9e4066Sahrens int i, err, epbs;
165fa9e4066Sahrens uint64_t txg = tx->tx_txg;
166744947dcSTom Erickson dnode_t *dn;
167fa9e4066Sahrens
168744947dcSTom Erickson DB_DNODE_ENTER(db);
169744947dcSTom Erickson dn = DB_DNODE(db);
170744947dcSTom Erickson epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
171fa9e4066Sahrens off = start - (db->db_blkid * 1<<epbs);
172fa9e4066Sahrens num = end - start + 1;
173fa9e4066Sahrens
174fa9e4066Sahrens ASSERT3U(off, >=, 0);
175fa9e4066Sahrens ASSERT3U(num, >=, 0);
176fa9e4066Sahrens ASSERT3U(db->db_level, >, 0);
177744947dcSTom Erickson ASSERT3U(db->db.db_size, ==, 1 << dn->dn_phys->dn_indblkshift);
178fa9e4066Sahrens ASSERT3U(off+num, <=, db->db.db_size >> SPA_BLKPTRSHIFT);
179fa9e4066Sahrens ASSERT(db->db_blkptr != NULL);
180fa9e4066Sahrens
181fa9e4066Sahrens for (i = off; i < off+num; i++) {
182fa9e4066Sahrens uint64_t *buf;
183fa9e4066Sahrens dmu_buf_impl_t *child;
184c717a561Smaybee dbuf_dirty_record_t *dr;
185c717a561Smaybee int j;
186fa9e4066Sahrens
187fa9e4066Sahrens ASSERT(db->db_level == 1);
188fa9e4066Sahrens
189744947dcSTom Erickson rw_enter(&dn->dn_struct_rwlock, RW_READER);
190744947dcSTom Erickson err = dbuf_hold_impl(dn, db->db_level-1,
191a2cdcdd2SPaul Dagnelie (db->db_blkid << epbs) + i, TRUE, FALSE, FTAG, &child);
192744947dcSTom Erickson rw_exit(&dn->dn_struct_rwlock);
193fa9e4066Sahrens if (err == ENOENT)
194fa9e4066Sahrens continue;
195fa9e4066Sahrens ASSERT(err == 0);
196fa9e4066Sahrens ASSERT(child->db_level == 0);
197c717a561Smaybee dr = child->db_last_dirty;
198c717a561Smaybee while (dr && dr->dr_txg > txg)
199c717a561Smaybee dr = dr->dr_next;
200c717a561Smaybee ASSERT(dr == NULL || dr->dr_txg == txg);
201fa9e4066Sahrens
202c717a561Smaybee /* data_old better be zeroed */
203c717a561Smaybee if (dr) {
204c717a561Smaybee buf = dr->dt.dl.dr_data->b_data;
205fa9e4066Sahrens for (j = 0; j < child->db.db_size >> 3; j++) {
206fa9e4066Sahrens if (buf[j] != 0) {
207fa9e4066Sahrens panic("freed data not zero: "
208fa9e4066Sahrens "child=%p i=%d off=%d num=%d\n",
209903a11ebSrh87107 (void *)child, i, off, num);
210fa9e4066Sahrens }
211fa9e4066Sahrens }
212fa9e4066Sahrens }
213fa9e4066Sahrens
214fa9e4066Sahrens /*
215fa9e4066Sahrens * db_data better be zeroed unless it's dirty in a
216fa9e4066Sahrens * future txg.
217fa9e4066Sahrens */
218fa9e4066Sahrens mutex_enter(&child->db_mtx);
219fa9e4066Sahrens buf = child->db.db_data;
220fa9e4066Sahrens if (buf != NULL && child->db_state != DB_FILL &&
221c717a561Smaybee child->db_last_dirty == NULL) {
222fa9e4066Sahrens for (j = 0; j < child->db.db_size >> 3; j++) {
223fa9e4066Sahrens if (buf[j] != 0) {
224fa9e4066Sahrens panic("freed data not zero: "
225fa9e4066Sahrens "child=%p i=%d off=%d num=%d\n",
226903a11ebSrh87107 (void *)child, i, off, num);
227fa9e4066Sahrens }
228fa9e4066Sahrens }
229fa9e4066Sahrens }
230fa9e4066Sahrens mutex_exit(&child->db_mtx);
231fa9e4066Sahrens
232ea8dc4b6Seschrock dbuf_rele(child, FTAG);
233fa9e4066Sahrens }
234744947dcSTom Erickson DB_DNODE_EXIT(db);
235fa9e4066Sahrens }
2369c9dc39aSek110237 #endif
237fa9e4066Sahrens
23843466aaeSMax Grossman static void
free_children(dmu_buf_impl_t * db,uint64_t blkid,uint64_t nblks,dmu_tx_t * tx)23943466aaeSMax Grossman free_children(dmu_buf_impl_t *db, uint64_t blkid, uint64_t nblks,
240fa9e4066Sahrens dmu_tx_t *tx)
241fa9e4066Sahrens {
242744947dcSTom Erickson dnode_t *dn;
243fa9e4066Sahrens blkptr_t *bp;
244fa9e4066Sahrens dmu_buf_impl_t *subdb;
245fa9e4066Sahrens uint64_t start, end, dbstart, dbend, i;
24643466aaeSMax Grossman int epbs, shift;
247fa9e4066Sahrens
248cdb0ab79Smaybee /*
249cdb0ab79Smaybee * There is a small possibility that this block will not be cached:
250cdb0ab79Smaybee * 1 - if level > 1 and there are no children with level <= 1
25143466aaeSMax Grossman * 2 - if this block was evicted since we read it from
25243466aaeSMax Grossman * dmu_tx_hold_free().
253cdb0ab79Smaybee */
254cdb0ab79Smaybee if (db->db_state != DB_CACHED)
255ea8dc4b6Seschrock (void) dbuf_read(db, NULL, DB_RF_MUST_SUCCEED);
256cdb0ab79Smaybee
2573f9d6ad7SLin Ling dbuf_release_bp(db);
25843466aaeSMax Grossman bp = db->db.db_data;
259fa9e4066Sahrens
260744947dcSTom Erickson DB_DNODE_ENTER(db);
261744947dcSTom Erickson dn = DB_DNODE(db);
262744947dcSTom Erickson epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
263fa9e4066Sahrens shift = (db->db_level - 1) * epbs;
264fa9e4066Sahrens dbstart = db->db_blkid << epbs;
265fa9e4066Sahrens start = blkid >> shift;
266fa9e4066Sahrens if (dbstart < start) {
267fa9e4066Sahrens bp += start - dbstart;
268fa9e4066Sahrens } else {
269fa9e4066Sahrens start = dbstart;
270fa9e4066Sahrens }
271fa9e4066Sahrens dbend = ((db->db_blkid + 1) << epbs) - 1;
272fa9e4066Sahrens end = (blkid + nblks - 1) >> shift;
273fa9e4066Sahrens if (dbend <= end)
274fa9e4066Sahrens end = dbend;
27543466aaeSMax Grossman
276fa9e4066Sahrens ASSERT3U(start, <=, end);
277fa9e4066Sahrens
278fa9e4066Sahrens if (db->db_level == 1) {
2799c9dc39aSek110237 FREE_VERIFY(db, start, end, tx);
28043466aaeSMax Grossman free_blocks(dn, bp, end-start+1, tx);
28143466aaeSMax Grossman } else {
282fa9e4066Sahrens for (i = start; i <= end; i++, bp++) {
283fa9e4066Sahrens if (BP_IS_HOLE(bp))
284fa9e4066Sahrens continue;
285fa9e4066Sahrens rw_enter(&dn->dn_struct_rwlock, RW_READER);
28643466aaeSMax Grossman VERIFY0(dbuf_hold_impl(dn, db->db_level - 1,
287a2cdcdd2SPaul Dagnelie i, TRUE, FALSE, FTAG, &subdb));
288fa9e4066Sahrens rw_exit(&dn->dn_struct_rwlock);
28943466aaeSMax Grossman ASSERT3P(bp, ==, subdb->db_blkptr);
290fa9e4066Sahrens
29143466aaeSMax Grossman free_children(subdb, blkid, nblks, tx);
292ea8dc4b6Seschrock dbuf_rele(subdb, FTAG);
293fa9e4066Sahrens }
29443466aaeSMax Grossman }
29543466aaeSMax Grossman
29643466aaeSMax Grossman /* If this whole block is free, free ourself too. */
29743466aaeSMax Grossman for (i = 0, bp = db->db.db_data; i < 1 << epbs; i++, bp++) {
29843466aaeSMax Grossman if (!BP_IS_HOLE(bp))
29943466aaeSMax Grossman break;
30043466aaeSMax Grossman }
30143466aaeSMax Grossman if (i == 1 << epbs) {
30243466aaeSMax Grossman /* didn't find any non-holes */
30343466aaeSMax Grossman bzero(db->db.db_data, db->db.db_size);
30443466aaeSMax Grossman free_blocks(dn, db->db_blkptr, 1, tx);
30543466aaeSMax Grossman } else {
30643466aaeSMax Grossman /*
30743466aaeSMax Grossman * Partial block free; must be marked dirty so that it
30843466aaeSMax Grossman * will be written out.
30943466aaeSMax Grossman */
31043466aaeSMax Grossman ASSERT(db->db_dirtycnt > 0);
31143466aaeSMax Grossman }
31243466aaeSMax Grossman
313744947dcSTom Erickson DB_DNODE_EXIT(db);
3146b4acc8bSahrens arc_buf_freeze(db->db_buf);
315fa9e4066Sahrens }
316fa9e4066Sahrens
317fa9e4066Sahrens /*
318f7170741SWill Andrews * Traverse the indicated range of the provided file
319fa9e4066Sahrens * and "free" all the blocks contained there.
320fa9e4066Sahrens */
321fa9e4066Sahrens static void
dnode_sync_free_range_impl(dnode_t * dn,uint64_t blkid,uint64_t nblks,dmu_tx_t * tx)322bf16b11eSMatthew Ahrens dnode_sync_free_range_impl(dnode_t *dn, uint64_t blkid, uint64_t nblks,
32343466aaeSMax Grossman dmu_tx_t *tx)
324fa9e4066Sahrens {
325fa9e4066Sahrens blkptr_t *bp = dn->dn_phys->dn_blkptr;
326fa9e4066Sahrens int dnlevel = dn->dn_phys->dn_nlevels;
32743466aaeSMax Grossman boolean_t trunc = B_FALSE;
328fa9e4066Sahrens
329fa9e4066Sahrens if (blkid > dn->dn_phys->dn_maxblkid)
330fa9e4066Sahrens return;
331fa9e4066Sahrens
332fa9e4066Sahrens ASSERT(dn->dn_phys->dn_maxblkid < UINT64_MAX);
33343466aaeSMax Grossman if (blkid + nblks > dn->dn_phys->dn_maxblkid) {
334fa9e4066Sahrens nblks = dn->dn_phys->dn_maxblkid - blkid + 1;
33543466aaeSMax Grossman trunc = B_TRUE;
33643466aaeSMax Grossman }
337fa9e4066Sahrens
338fa9e4066Sahrens /* There are no indirect blocks in the object */
339fa9e4066Sahrens if (dnlevel == 1) {
340fa9e4066Sahrens if (blkid >= dn->dn_phys->dn_nblkptr) {
341fa9e4066Sahrens /* this range was never made persistent */
342fa9e4066Sahrens return;
343fa9e4066Sahrens }
344fa9e4066Sahrens ASSERT3U(blkid + nblks, <=, dn->dn_phys->dn_nblkptr);
34543466aaeSMax Grossman free_blocks(dn, bp + blkid, nblks, tx);
34643466aaeSMax Grossman } else {
34743466aaeSMax Grossman int shift = (dnlevel - 1) *
34843466aaeSMax Grossman (dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT);
34943466aaeSMax Grossman int start = blkid >> shift;
35043466aaeSMax Grossman int end = (blkid + nblks - 1) >> shift;
35143466aaeSMax Grossman dmu_buf_impl_t *db;
352fa9e4066Sahrens
353fa9e4066Sahrens ASSERT(start < dn->dn_phys->dn_nblkptr);
354fa9e4066Sahrens bp += start;
35543466aaeSMax Grossman for (int i = start; i <= end; i++, bp++) {
356fa9e4066Sahrens if (BP_IS_HOLE(bp))
357fa9e4066Sahrens continue;
358fa9e4066Sahrens rw_enter(&dn->dn_struct_rwlock, RW_READER);
35943466aaeSMax Grossman VERIFY0(dbuf_hold_impl(dn, dnlevel - 1, i,
360a2cdcdd2SPaul Dagnelie TRUE, FALSE, FTAG, &db));
361fa9e4066Sahrens rw_exit(&dn->dn_struct_rwlock);
362fa9e4066Sahrens
36343466aaeSMax Grossman free_children(db, blkid, nblks, tx);
364ea8dc4b6Seschrock dbuf_rele(db, FTAG);
365fa9e4066Sahrens }
36643466aaeSMax Grossman }
36743466aaeSMax Grossman
368fa9e4066Sahrens if (trunc) {
36943466aaeSMax Grossman dn->dn_phys->dn_maxblkid = blkid == 0 ? 0 : blkid - 1;
37043466aaeSMax Grossman
371fa9e4066Sahrens uint64_t off = (dn->dn_phys->dn_maxblkid + 1) *
372fa9e4066Sahrens (dn->dn_phys->dn_datablkszsec << SPA_MINBLOCKSHIFT);
373fa9e4066Sahrens ASSERT(off < dn->dn_phys->dn_maxblkid ||
374fa9e4066Sahrens dn->dn_phys->dn_maxblkid == 0 ||
375cdb0ab79Smaybee dnode_next_offset(dn, 0, &off, 1, 1, 0) != 0);
376fa9e4066Sahrens }
377fa9e4066Sahrens }
378fa9e4066Sahrens
379bf16b11eSMatthew Ahrens typedef struct dnode_sync_free_range_arg {
380bf16b11eSMatthew Ahrens dnode_t *dsfra_dnode;
381bf16b11eSMatthew Ahrens dmu_tx_t *dsfra_tx;
382bf16b11eSMatthew Ahrens } dnode_sync_free_range_arg_t;
383bf16b11eSMatthew Ahrens
384bf16b11eSMatthew Ahrens static void
dnode_sync_free_range(void * arg,uint64_t blkid,uint64_t nblks)385bf16b11eSMatthew Ahrens dnode_sync_free_range(void *arg, uint64_t blkid, uint64_t nblks)
386bf16b11eSMatthew Ahrens {
387bf16b11eSMatthew Ahrens dnode_sync_free_range_arg_t *dsfra = arg;
388bf16b11eSMatthew Ahrens dnode_t *dn = dsfra->dsfra_dnode;
389bf16b11eSMatthew Ahrens
390bf16b11eSMatthew Ahrens mutex_exit(&dn->dn_mtx);
391bf16b11eSMatthew Ahrens dnode_sync_free_range_impl(dn, blkid, nblks, dsfra->dsfra_tx);
392bf16b11eSMatthew Ahrens mutex_enter(&dn->dn_mtx);
393bf16b11eSMatthew Ahrens }
394bf16b11eSMatthew Ahrens
395ea8dc4b6Seschrock /*
396f7170741SWill Andrews * Try to kick all the dnode's dbufs out of the cache...
397ea8dc4b6Seschrock */
3981934e92fSmaybee void
dnode_evict_dbufs(dnode_t * dn)3991934e92fSmaybee dnode_evict_dbufs(dnode_t *dn)
400ea8dc4b6Seschrock {
401bc9014e6SJustin Gibbs dmu_buf_impl_t db_marker;
4020f6d88adSAlex Reece dmu_buf_impl_t *db, *db_next;
403c543ec06Sahrens
404ea8dc4b6Seschrock mutex_enter(&dn->dn_dbufs_mtx);
4050f6d88adSAlex Reece for (db = avl_first(&dn->dn_dbufs); db != NULL; db = db_next) {
406bc9014e6SJustin Gibbs
407744947dcSTom Erickson #ifdef DEBUG
408744947dcSTom Erickson DB_DNODE_ENTER(db);
409744947dcSTom Erickson ASSERT3P(DB_DNODE(db), ==, dn);
410744947dcSTom Erickson DB_DNODE_EXIT(db);
411744947dcSTom Erickson #endif /* DEBUG */
412c543ec06Sahrens
413ea8dc4b6Seschrock mutex_enter(&db->db_mtx);
414bc9014e6SJustin Gibbs if (db->db_state != DB_EVICTING &&
415bc9014e6SJustin Gibbs refcount_is_zero(&db->db_holds)) {
416bc9014e6SJustin Gibbs db_marker.db_level = db->db_level;
417bc9014e6SJustin Gibbs db_marker.db_blkid = db->db_blkid;
418bc9014e6SJustin Gibbs db_marker.db_state = DB_SEARCH;
419bc9014e6SJustin Gibbs avl_insert_here(&dn->dn_dbufs, &db_marker, db,
420bc9014e6SJustin Gibbs AVL_BEFORE);
421bc9014e6SJustin Gibbs
422bc9014e6SJustin Gibbs dbuf_clear(db);
423bc9014e6SJustin Gibbs
424bc9014e6SJustin Gibbs db_next = AVL_NEXT(&dn->dn_dbufs, &db_marker);
425bc9014e6SJustin Gibbs avl_remove(&dn->dn_dbufs, &db_marker);
426c543ec06Sahrens } else {
427*d2058105SJustin T. Gibbs db->db_pending_evict = TRUE;
428ea8dc4b6Seschrock mutex_exit(&db->db_mtx);
429bc9014e6SJustin Gibbs db_next = AVL_NEXT(&dn->dn_dbufs, db);
430ea8dc4b6Seschrock }
431ea8dc4b6Seschrock }
432ea8dc4b6Seschrock mutex_exit(&dn->dn_dbufs_mtx);
433c543ec06Sahrens
434cd485b49SJustin T. Gibbs dnode_evict_bonus(dn);
435cd485b49SJustin T. Gibbs }
436cd485b49SJustin T. Gibbs
437cd485b49SJustin T. Gibbs void
dnode_evict_bonus(dnode_t * dn)438cd485b49SJustin T. Gibbs dnode_evict_bonus(dnode_t *dn)
439cd485b49SJustin T. Gibbs {
440ea8dc4b6Seschrock rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
441*d2058105SJustin T. Gibbs if (dn->dn_bonus != NULL) {
442*d2058105SJustin T. Gibbs if (refcount_is_zero(&dn->dn_bonus->db_holds)) {
443ea8dc4b6Seschrock mutex_enter(&dn->dn_bonus->db_mtx);
444ea8dc4b6Seschrock dbuf_evict(dn->dn_bonus);
445ea8dc4b6Seschrock dn->dn_bonus = NULL;
446*d2058105SJustin T. Gibbs } else {
447*d2058105SJustin T. Gibbs dn->dn_bonus->db_pending_evict = TRUE;
448*d2058105SJustin T. Gibbs }
449ea8dc4b6Seschrock }
450ea8dc4b6Seschrock rw_exit(&dn->dn_struct_rwlock);
451ea8dc4b6Seschrock }
452ea8dc4b6Seschrock
453c717a561Smaybee static void
dnode_undirty_dbufs(list_t * list)454c717a561Smaybee dnode_undirty_dbufs(list_t *list)
455c717a561Smaybee {
456c717a561Smaybee dbuf_dirty_record_t *dr;
457c717a561Smaybee
458c717a561Smaybee while (dr = list_head(list)) {
459c717a561Smaybee dmu_buf_impl_t *db = dr->dr_dbuf;
460c717a561Smaybee uint64_t txg = dr->dr_txg;
461c717a561Smaybee
462b24ab676SJeff Bonwick if (db->db_level != 0)
463b24ab676SJeff Bonwick dnode_undirty_dbufs(&dr->dt.di.dr_children);
464b24ab676SJeff Bonwick
465c717a561Smaybee mutex_enter(&db->db_mtx);
466c717a561Smaybee /* XXX - use dbuf_undirty()? */
467c717a561Smaybee list_remove(list, dr);
468c717a561Smaybee ASSERT(db->db_last_dirty == dr);
469c717a561Smaybee db->db_last_dirty = NULL;
470c717a561Smaybee db->db_dirtycnt -= 1;
471c717a561Smaybee if (db->db_level == 0) {
4720a586ceaSMark Shellenbaum ASSERT(db->db_blkid == DMU_BONUS_BLKID ||
473c717a561Smaybee dr->dt.dl.dr_data == db->db_buf);
474c717a561Smaybee dbuf_unoverride(dr);
475d2b3cbbdSJorgen Lundman } else {
476d2b3cbbdSJorgen Lundman mutex_destroy(&dr->dt.di.dr_mtx);
477d2b3cbbdSJorgen Lundman list_destroy(&dr->dt.di.dr_children);
478c717a561Smaybee }
479c717a561Smaybee kmem_free(dr, sizeof (dbuf_dirty_record_t));
480b24ab676SJeff Bonwick dbuf_rele_and_unlock(db, (void *)(uintptr_t)txg);
481c717a561Smaybee }
482c717a561Smaybee }
483c717a561Smaybee
484c717a561Smaybee static void
dnode_sync_free(dnode_t * dn,dmu_tx_t * tx)485fa9e4066Sahrens dnode_sync_free(dnode_t *dn, dmu_tx_t *tx)
486fa9e4066Sahrens {
487fa9e4066Sahrens int txgoff = tx->tx_txg & TXG_MASK;
488fa9e4066Sahrens
489fa9e4066Sahrens ASSERT(dmu_tx_is_syncing(tx));
490fa9e4066Sahrens
491cdb0ab79Smaybee /*
492cdb0ab79Smaybee * Our contents should have been freed in dnode_sync() by the
493cdb0ab79Smaybee * free range record inserted by the caller of dnode_free().
494cdb0ab79Smaybee */
495fb09f5aaSMadhav Suresh ASSERT0(DN_USED_BYTES(dn->dn_phys));
496cdb0ab79Smaybee ASSERT(BP_IS_HOLE(dn->dn_phys->dn_blkptr));
497cdb0ab79Smaybee
498c717a561Smaybee dnode_undirty_dbufs(&dn->dn_dirty_records[txgoff]);
4991934e92fSmaybee dnode_evict_dbufs(dn);
500ea8dc4b6Seschrock
501ea8dc4b6Seschrock /*
502ea8dc4b6Seschrock * XXX - It would be nice to assert this, but we may still
503ea8dc4b6Seschrock * have residual holds from async evictions from the arc...
504ea8dc4b6Seschrock *
50555434c77Sek110237 * zfs_obj_to_path() also depends on this being
50655434c77Sek110237 * commented out.
50755434c77Sek110237 *
508ea8dc4b6Seschrock * ASSERT3U(refcount_count(&dn->dn_holds), ==, 1);
509ea8dc4b6Seschrock */
510fa9e4066Sahrens
511fa9e4066Sahrens /* Undirty next bits */
512fa9e4066Sahrens dn->dn_next_nlevels[txgoff] = 0;
513fa9e4066Sahrens dn->dn_next_indblkshift[txgoff] = 0;
514c543ec06Sahrens dn->dn_next_blksz[txgoff] = 0;
515fa9e4066Sahrens
516fa9e4066Sahrens /* ASSERT(blkptrs are zero); */
517fa9e4066Sahrens ASSERT(dn->dn_phys->dn_type != DMU_OT_NONE);
518fa9e4066Sahrens ASSERT(dn->dn_type != DMU_OT_NONE);
519fa9e4066Sahrens
520fa9e4066Sahrens ASSERT(dn->dn_free_txg > 0);
521fa9e4066Sahrens if (dn->dn_allocated_txg != dn->dn_free_txg)
52243466aaeSMax Grossman dmu_buf_will_dirty(&dn->dn_dbuf->db, tx);
523fa9e4066Sahrens bzero(dn->dn_phys, sizeof (dnode_phys_t));
524fa9e4066Sahrens
525fa9e4066Sahrens mutex_enter(&dn->dn_mtx);
526fa9e4066Sahrens dn->dn_type = DMU_OT_NONE;
527fa9e4066Sahrens dn->dn_maxblkid = 0;
528fa9e4066Sahrens dn->dn_allocated_txg = 0;
529758f6e0bSgw25295 dn->dn_free_txg = 0;
5300a586ceaSMark Shellenbaum dn->dn_have_spill = B_FALSE;
531fa9e4066Sahrens mutex_exit(&dn->dn_mtx);
532fa9e4066Sahrens
533ea8dc4b6Seschrock ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT);
534fa9e4066Sahrens
535fa9e4066Sahrens dnode_rele(dn, (void *)(uintptr_t)tx->tx_txg);
536fa9e4066Sahrens /*
537fa9e4066Sahrens * Now that we've released our hold, the dnode may
538fa9e4066Sahrens * be evicted, so we musn't access it.
539fa9e4066Sahrens */
540fa9e4066Sahrens }
541fa9e4066Sahrens
542fa9e4066Sahrens /*
543c717a561Smaybee * Write out the dnode's dirty buffers.
544fa9e4066Sahrens */
545c717a561Smaybee void
dnode_sync(dnode_t * dn,dmu_tx_t * tx)546c717a561Smaybee dnode_sync(dnode_t *dn, dmu_tx_t *tx)
547fa9e4066Sahrens {
548fa9e4066Sahrens dnode_phys_t *dnp = dn->dn_phys;
549c717a561Smaybee int txgoff = tx->tx_txg & TXG_MASK;
550c717a561Smaybee list_t *list = &dn->dn_dirty_records[txgoff];
55114843421SMatthew Ahrens static const dnode_phys_t zerodn = { 0 };
5520a586ceaSMark Shellenbaum boolean_t kill_spill = B_FALSE;
553fa9e4066Sahrens
554fa9e4066Sahrens ASSERT(dmu_tx_is_syncing(tx));
555fa9e4066Sahrens ASSERT(dnp->dn_type != DMU_OT_NONE || dn->dn_allocated_txg);
55614843421SMatthew Ahrens ASSERT(dnp->dn_type != DMU_OT_NONE ||
55714843421SMatthew Ahrens bcmp(dnp, &zerodn, DNODE_SIZE) == 0);
5589c9dc39aSek110237 DNODE_VERIFY(dn);
559c543ec06Sahrens
560c717a561Smaybee ASSERT(dn->dn_dbuf == NULL || arc_released(dn->dn_dbuf->db_buf));
561fa9e4066Sahrens
56214843421SMatthew Ahrens if (dmu_objset_userused_enabled(dn->dn_objset) &&
56314843421SMatthew Ahrens !DMU_OBJECT_IS_SPECIAL(dn->dn_object)) {
5640a586ceaSMark Shellenbaum mutex_enter(&dn->dn_mtx);
5650a586ceaSMark Shellenbaum dn->dn_oldused = DN_USED_BYTES(dn->dn_phys);
5660a586ceaSMark Shellenbaum dn->dn_oldflags = dn->dn_phys->dn_flags;
56714843421SMatthew Ahrens dn->dn_phys->dn_flags |= DNODE_FLAG_USERUSED_ACCOUNTED;
5680a586ceaSMark Shellenbaum mutex_exit(&dn->dn_mtx);
56906e0070dSMark Shellenbaum dmu_objset_userquota_get_ids(dn, B_FALSE, tx);
57014843421SMatthew Ahrens } else {
57114843421SMatthew Ahrens /* Once we account for it, we should always account for it. */
57214843421SMatthew Ahrens ASSERT(!(dn->dn_phys->dn_flags &
57314843421SMatthew Ahrens DNODE_FLAG_USERUSED_ACCOUNTED));
57414843421SMatthew Ahrens }
57514843421SMatthew Ahrens
576fa9e4066Sahrens mutex_enter(&dn->dn_mtx);
577fa9e4066Sahrens if (dn->dn_allocated_txg == tx->tx_txg) {
578fa9e4066Sahrens /* The dnode is newly allocated or reallocated */
579fa9e4066Sahrens if (dnp->dn_type == DMU_OT_NONE) {
580fa9e4066Sahrens /* this is a first alloc, not a realloc */
581fa9e4066Sahrens dnp->dn_nlevels = 1;
582da03de99SMark Maybee dnp->dn_nblkptr = dn->dn_nblkptr;
583fa9e4066Sahrens }
584fa9e4066Sahrens
585fa9e4066Sahrens dnp->dn_type = dn->dn_type;
586fa9e4066Sahrens dnp->dn_bonustype = dn->dn_bonustype;
587fa9e4066Sahrens dnp->dn_bonuslen = dn->dn_bonuslen;
588fa9e4066Sahrens }
589c717a561Smaybee ASSERT(dnp->dn_nlevels > 1 ||
590f676ed34Sahrens BP_IS_HOLE(&dnp->dn_blkptr[0]) ||
5915d7b4d43SMatthew Ahrens BP_IS_EMBEDDED(&dnp->dn_blkptr[0]) ||
592f676ed34Sahrens BP_GET_LSIZE(&dnp->dn_blkptr[0]) ==
593f676ed34Sahrens dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
5945d7b4d43SMatthew Ahrens ASSERT(dnp->dn_nlevels < 2 ||
5955d7b4d43SMatthew Ahrens BP_IS_HOLE(&dnp->dn_blkptr[0]) ||
5965d7b4d43SMatthew Ahrens BP_GET_LSIZE(&dnp->dn_blkptr[0]) == 1 << dnp->dn_indblkshift);
597f676ed34Sahrens
5982acef22dSMatthew Ahrens if (dn->dn_next_type[txgoff] != 0) {
5992acef22dSMatthew Ahrens dnp->dn_type = dn->dn_type;
6002acef22dSMatthew Ahrens dn->dn_next_type[txgoff] = 0;
6012acef22dSMatthew Ahrens }
6022acef22dSMatthew Ahrens
6032acef22dSMatthew Ahrens if (dn->dn_next_blksz[txgoff] != 0) {
604c543ec06Sahrens ASSERT(P2PHASE(dn->dn_next_blksz[txgoff],
605fa9e4066Sahrens SPA_MINBLOCKSIZE) == 0);
606f676ed34Sahrens ASSERT(BP_IS_HOLE(&dnp->dn_blkptr[0]) ||
607cdb0ab79Smaybee dn->dn_maxblkid == 0 || list_head(list) != NULL ||
608347a31bcSahrens dn->dn_next_blksz[txgoff] >> SPA_MINBLOCKSHIFT ==
609bf16b11eSMatthew Ahrens dnp->dn_datablkszsec ||
610bf16b11eSMatthew Ahrens range_tree_space(dn->dn_free_ranges[txgoff]) != 0);
611fa9e4066Sahrens dnp->dn_datablkszsec =
612c543ec06Sahrens dn->dn_next_blksz[txgoff] >> SPA_MINBLOCKSHIFT;
613c543ec06Sahrens dn->dn_next_blksz[txgoff] = 0;
614fa9e4066Sahrens }
615fa9e4066Sahrens
6162acef22dSMatthew Ahrens if (dn->dn_next_bonuslen[txgoff] != 0) {
6171934e92fSmaybee if (dn->dn_next_bonuslen[txgoff] == DN_ZERO_BONUSLEN)
6181934e92fSmaybee dnp->dn_bonuslen = 0;
6191934e92fSmaybee else
6201934e92fSmaybee dnp->dn_bonuslen = dn->dn_next_bonuslen[txgoff];
6211934e92fSmaybee ASSERT(dnp->dn_bonuslen <= DN_MAX_BONUSLEN);
6221934e92fSmaybee dn->dn_next_bonuslen[txgoff] = 0;
6231934e92fSmaybee }
6241934e92fSmaybee
6252acef22dSMatthew Ahrens if (dn->dn_next_bonustype[txgoff] != 0) {
626ad135b5dSChristopher Siden ASSERT(DMU_OT_IS_VALID(dn->dn_next_bonustype[txgoff]));
6270a586ceaSMark Shellenbaum dnp->dn_bonustype = dn->dn_next_bonustype[txgoff];
6280a586ceaSMark Shellenbaum dn->dn_next_bonustype[txgoff] = 0;
6290a586ceaSMark Shellenbaum }
6300a586ceaSMark Shellenbaum
63143466aaeSMax Grossman boolean_t freeing_dnode = dn->dn_free_txg > 0 &&
63243466aaeSMax Grossman dn->dn_free_txg <= tx->tx_txg;
63343466aaeSMax Grossman
6340a586ceaSMark Shellenbaum /*
635e6518318SMatthew Ahrens * Remove the spill block if we have been explicitly asked to
636e6518318SMatthew Ahrens * remove it, or if the object is being removed.
6370a586ceaSMark Shellenbaum */
638e6518318SMatthew Ahrens if (dn->dn_rm_spillblk[txgoff] || freeing_dnode) {
639e6518318SMatthew Ahrens if (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR)
6400a586ceaSMark Shellenbaum kill_spill = B_TRUE;
6410a586ceaSMark Shellenbaum dn->dn_rm_spillblk[txgoff] = 0;
6420a586ceaSMark Shellenbaum }
6430a586ceaSMark Shellenbaum
6442acef22dSMatthew Ahrens if (dn->dn_next_indblkshift[txgoff] != 0) {
645fa9e4066Sahrens ASSERT(dnp->dn_nlevels == 1);
646fa9e4066Sahrens dnp->dn_indblkshift = dn->dn_next_indblkshift[txgoff];
647fa9e4066Sahrens dn->dn_next_indblkshift[txgoff] = 0;
648fa9e4066Sahrens }
649fa9e4066Sahrens
650fa9e4066Sahrens /*
651fa9e4066Sahrens * Just take the live (open-context) values for checksum and compress.
652fa9e4066Sahrens * Strictly speaking it's a future leak, but nothing bad happens if we
653fa9e4066Sahrens * start using the new checksum or compress algorithm a little early.
654fa9e4066Sahrens */
655fa9e4066Sahrens dnp->dn_checksum = dn->dn_checksum;
656fa9e4066Sahrens dnp->dn_compress = dn->dn_compress;
657fa9e4066Sahrens
658fa9e4066Sahrens mutex_exit(&dn->dn_mtx);
659fa9e4066Sahrens
6600a586ceaSMark Shellenbaum if (kill_spill) {
66143466aaeSMax Grossman free_blocks(dn, &dn->dn_phys->dn_spill, 1, tx);
6620a586ceaSMark Shellenbaum mutex_enter(&dn->dn_mtx);
6630a586ceaSMark Shellenbaum dnp->dn_flags &= ~DNODE_FLAG_SPILL_BLKPTR;
6640a586ceaSMark Shellenbaum mutex_exit(&dn->dn_mtx);
6650a586ceaSMark Shellenbaum }
6660a586ceaSMark Shellenbaum
667fa9e4066Sahrens /* process all the "freed" ranges in the file */
668bf16b11eSMatthew Ahrens if (dn->dn_free_ranges[txgoff] != NULL) {
669bf16b11eSMatthew Ahrens dnode_sync_free_range_arg_t dsfra;
670bf16b11eSMatthew Ahrens dsfra.dsfra_dnode = dn;
671bf16b11eSMatthew Ahrens dsfra.dsfra_tx = tx;
672fa9e4066Sahrens mutex_enter(&dn->dn_mtx);
673bf16b11eSMatthew Ahrens range_tree_vacate(dn->dn_free_ranges[txgoff],
674bf16b11eSMatthew Ahrens dnode_sync_free_range, &dsfra);
675bf16b11eSMatthew Ahrens range_tree_destroy(dn->dn_free_ranges[txgoff]);
676bf16b11eSMatthew Ahrens dn->dn_free_ranges[txgoff] = NULL;
677fa9e4066Sahrens mutex_exit(&dn->dn_mtx);
678cdb0ab79Smaybee }
679cdb0ab79Smaybee
68043466aaeSMax Grossman if (freeing_dnode) {
681c717a561Smaybee dnode_sync_free(dn, tx);
682c717a561Smaybee return;
683fa9e4066Sahrens }
684fa9e4066Sahrens
685e503a685SGeorge Wilson if (dn->dn_next_nlevels[txgoff]) {
686e503a685SGeorge Wilson dnode_increase_indirection(dn, tx);
687e503a685SGeorge Wilson dn->dn_next_nlevels[txgoff] = 0;
688e503a685SGeorge Wilson }
689e503a685SGeorge Wilson
690da03de99SMark Maybee if (dn->dn_next_nblkptr[txgoff]) {
691da03de99SMark Maybee /* this should only happen on a realloc */
692da03de99SMark Maybee ASSERT(dn->dn_allocated_txg == tx->tx_txg);
693da03de99SMark Maybee if (dn->dn_next_nblkptr[txgoff] > dnp->dn_nblkptr) {
694da03de99SMark Maybee /* zero the new blkptrs we are gaining */
695da03de99SMark Maybee bzero(dnp->dn_blkptr + dnp->dn_nblkptr,
696da03de99SMark Maybee sizeof (blkptr_t) *
697da03de99SMark Maybee (dn->dn_next_nblkptr[txgoff] - dnp->dn_nblkptr));
698da03de99SMark Maybee #ifdef ZFS_DEBUG
699da03de99SMark Maybee } else {
700da03de99SMark Maybee int i;
701da03de99SMark Maybee ASSERT(dn->dn_next_nblkptr[txgoff] < dnp->dn_nblkptr);
702da03de99SMark Maybee /* the blkptrs we are losing better be unallocated */
703da03de99SMark Maybee for (i = dn->dn_next_nblkptr[txgoff];
704da03de99SMark Maybee i < dnp->dn_nblkptr; i++)
705da03de99SMark Maybee ASSERT(BP_IS_HOLE(&dnp->dn_blkptr[i]));
706da03de99SMark Maybee #endif
707da03de99SMark Maybee }
708da03de99SMark Maybee mutex_enter(&dn->dn_mtx);
709da03de99SMark Maybee dnp->dn_nblkptr = dn->dn_next_nblkptr[txgoff];
710da03de99SMark Maybee dn->dn_next_nblkptr[txgoff] = 0;
711da03de99SMark Maybee mutex_exit(&dn->dn_mtx);
712da03de99SMark Maybee }
713da03de99SMark Maybee
71446e1baa6SMatthew Ahrens dbuf_sync_list(list, dn->dn_phys->dn_nlevels - 1, tx);
715f676ed34Sahrens
71614843421SMatthew Ahrens if (!DMU_OBJECT_IS_SPECIAL(dn->dn_object)) {
717c717a561Smaybee ASSERT3P(list_head(list), ==, NULL);
718fa9e4066Sahrens dnode_rele(dn, (void *)(uintptr_t)tx->tx_txg);
719fa9e4066Sahrens }
720fa9e4066Sahrens
721fa9e4066Sahrens /*
722c717a561Smaybee * Although we have dropped our reference to the dnode, it
723c717a561Smaybee * can't be evicted until its written, and we haven't yet
724c717a561Smaybee * initiated the IO for the dnode's dbuf.
725fa9e4066Sahrens */
726fa9e4066Sahrens }
727