annotate usr/src/uts/common/fs/zfs/dnode.c @ 7754:b80e4842ad54

6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling 6667208 zfs/zpool commands on failed pool should not hang 6430480 grabbing config lock as writer during I/O load can take excessively long
author Jeff Bonwick <Jeff.Bonwick@Sun.COM>
date Mon, 29 Sep 2008 18:13:58 -0700
parents f69ff8507427
children d7abf7c1f1c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
3 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
4 * The contents of this file are subject to the terms of the
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 1402
diff changeset
5 * Common Development and Distribution License (the "License").
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 1402
diff changeset
6 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
7 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
9 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
10 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
11 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
12 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
13 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
15 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
16 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
17 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
18 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
19 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
20 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
21 /*
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
23 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
24 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
26 #include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
27 #include <sys/dbuf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
28 #include <sys/dnode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
29 #include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
30 #include <sys/dmu_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
31 #include <sys/dmu_tx.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
32 #include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
33 #include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
34 #include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
35 #include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
36 #include <sys/zio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
37 #include <sys/dmu_zfetch.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
38
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
39 static int free_range_compar(const void *node1, const void *node2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
40
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
41 static kmem_cache_t *dnode_cache;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
42
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
43 static dnode_phys_t dnode_phys_zero;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
44
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
45 int zfs_default_bs = SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
46 int zfs_default_ibs = DN_MAX_INDBLKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
47
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
48 /* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
49 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
50 dnode_cons(void *arg, void *unused, int kmflag)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
51 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
52 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
53 dnode_t *dn = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
54 bzero(dn, sizeof (dnode_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
55
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
56 rw_init(&dn->dn_struct_rwlock, NULL, RW_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
57 mutex_init(&dn->dn_mtx, NULL, MUTEX_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
58 mutex_init(&dn->dn_dbufs_mtx, NULL, MUTEX_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
59 refcount_create(&dn->dn_holds);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
60 refcount_create(&dn->dn_tx_holds);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
61
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
62 for (i = 0; i < TXG_SIZE; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
63 avl_create(&dn->dn_ranges[i], free_range_compar,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
64 sizeof (free_range_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
65 offsetof(struct free_range, fr_node));
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
66 list_create(&dn->dn_dirty_records[i],
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
67 sizeof (dbuf_dirty_record_t),
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
68 offsetof(dbuf_dirty_record_t, dr_dirty_node));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
69 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
70
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
71 list_create(&dn->dn_dbufs, sizeof (dmu_buf_impl_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
72 offsetof(dmu_buf_impl_t, db_link));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
73
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
74 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
75 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
76
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
77 /* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
78 static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
79 dnode_dest(void *arg, void *unused)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
80 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
81 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
82 dnode_t *dn = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
83
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
84 rw_destroy(&dn->dn_struct_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
85 mutex_destroy(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
86 mutex_destroy(&dn->dn_dbufs_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
87 refcount_destroy(&dn->dn_holds);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
88 refcount_destroy(&dn->dn_tx_holds);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
89
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
90 for (i = 0; i < TXG_SIZE; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
91 avl_destroy(&dn->dn_ranges[i]);
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
92 list_destroy(&dn->dn_dirty_records[i]);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
93 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
94
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
95 list_destroy(&dn->dn_dbufs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
96 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
97
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
98 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
99 dnode_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
100 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
101 dnode_cache = kmem_cache_create("dnode_t",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
102 sizeof (dnode_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
103 0, dnode_cons, dnode_dest, NULL, NULL, NULL, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
104 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
105
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
106 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
107 dnode_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
108 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
109 kmem_cache_destroy(dnode_cache);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
110 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
111
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
112
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
113 #ifdef ZFS_DEBUG
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
114 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
115 dnode_verify(dnode_t *dn)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
116 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
117 int drop_struct_lock = FALSE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
118
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
119 ASSERT(dn->dn_phys);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
120 ASSERT(dn->dn_objset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
122 ASSERT(dn->dn_phys->dn_type < DMU_OT_NUMTYPES);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
123
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
124 if (!(zfs_flags & ZFS_DEBUG_DNODE_VERIFY))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
125 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
126
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
127 if (!RW_WRITE_HELD(&dn->dn_struct_rwlock)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
128 rw_enter(&dn->dn_struct_rwlock, RW_READER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
129 drop_struct_lock = TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
130 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
131 if (dn->dn_phys->dn_type != DMU_OT_NONE || dn->dn_allocated_txg != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
132 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
133 ASSERT3U(dn->dn_indblkshift, >=, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
134 ASSERT3U(dn->dn_indblkshift, <=, SPA_MAXBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
135 if (dn->dn_datablkshift) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
136 ASSERT3U(dn->dn_datablkshift, >=, SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
137 ASSERT3U(dn->dn_datablkshift, <=, SPA_MAXBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
138 ASSERT3U(1<<dn->dn_datablkshift, ==, dn->dn_datablksz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
139 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
140 ASSERT3U(dn->dn_nlevels, <=, 30);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
141 ASSERT3U(dn->dn_type, <=, DMU_OT_NUMTYPES);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
142 ASSERT3U(dn->dn_nblkptr, >=, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
143 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
144 ASSERT3U(dn->dn_bonuslen, <=, DN_MAX_BONUSLEN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
145 ASSERT3U(dn->dn_datablksz, ==,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
146 dn->dn_datablkszsec << SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
147 ASSERT3U(ISP2(dn->dn_datablksz), ==, dn->dn_datablkshift != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
148 ASSERT3U((dn->dn_nblkptr - 1) * sizeof (blkptr_t) +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
149 dn->dn_bonuslen, <=, DN_MAX_BONUSLEN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
150 for (i = 0; i < TXG_SIZE; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
151 ASSERT3U(dn->dn_next_nlevels[i], <=, dn->dn_nlevels);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
152 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
153 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
154 if (dn->dn_phys->dn_type != DMU_OT_NONE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
155 ASSERT3U(dn->dn_phys->dn_nlevels, <=, dn->dn_nlevels);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
156 ASSERT(dn->dn_object == DMU_META_DNODE_OBJECT || dn->dn_dbuf != NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
157 if (dn->dn_dbuf != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
158 ASSERT3P(dn->dn_phys, ==,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
159 (dnode_phys_t *)dn->dn_dbuf->db.db_data +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
160 (dn->dn_object % (dn->dn_dbuf->db.db_size >> DNODE_SHIFT)));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
161 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
162 if (drop_struct_lock)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
163 rw_exit(&dn->dn_struct_rwlock);
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
164 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
165 #endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
166
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
167 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
168 dnode_byteswap(dnode_phys_t *dnp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
169 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
170 uint64_t *buf64 = (void*)&dnp->dn_blkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
171 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
172
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
173 if (dnp->dn_type == DMU_OT_NONE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
174 bzero(dnp, sizeof (dnode_phys_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
175 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
176 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
177
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
178 dnp->dn_datablkszsec = BSWAP_16(dnp->dn_datablkszsec);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
179 dnp->dn_bonuslen = BSWAP_16(dnp->dn_bonuslen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
180 dnp->dn_maxblkid = BSWAP_64(dnp->dn_maxblkid);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
181 dnp->dn_used = BSWAP_64(dnp->dn_used);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
182
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
183 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
184 * dn_nblkptr is only one byte, so it's OK to read it in either
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
185 * byte order. We can't read dn_bouslen.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
186 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
187 ASSERT(dnp->dn_indblkshift <= SPA_MAXBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
188 ASSERT(dnp->dn_nblkptr <= DN_MAX_NBLKPTR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
189 for (i = 0; i < dnp->dn_nblkptr * sizeof (blkptr_t)/8; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
190 buf64[i] = BSWAP_64(buf64[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
191
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
192 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
193 * OK to check dn_bonuslen for zero, because it won't matter if
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
194 * we have the wrong byte order. This is necessary because the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
195 * dnode dnode is smaller than a regular dnode.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
196 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
197 if (dnp->dn_bonuslen != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
198 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
199 * Note that the bonus length calculated here may be
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
200 * longer than the actual bonus buffer. This is because
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
201 * we always put the bonus buffer after the last block
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
202 * pointer (instead of packing it against the end of the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
203 * dnode buffer).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
204 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
205 int off = (dnp->dn_nblkptr-1) * sizeof (blkptr_t);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
206 size_t len = DN_MAX_BONUSLEN - off;
3882
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3547
diff changeset
207 ASSERT3U(dnp->dn_bonustype, <, DMU_OT_NUMTYPES);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
208 dmu_ot[dnp->dn_bonustype].ot_byteswap(dnp->dn_bonus + off, len);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
209 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
210 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
212 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
213 dnode_buf_byteswap(void *vbuf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
214 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
215 dnode_phys_t *buf = vbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
216 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
217
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
218 ASSERT3U(sizeof (dnode_phys_t), ==, (1<<DNODE_SHIFT));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
219 ASSERT((size & (sizeof (dnode_phys_t)-1)) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
220
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
221 size >>= DNODE_SHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
222 for (i = 0; i < size; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
223 dnode_byteswap(buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
224 buf++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
225 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
226 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
227
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
228 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
229 free_range_compar(const void *node1, const void *node2)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
230 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
231 const free_range_t *rp1 = node1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
232 const free_range_t *rp2 = node2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
233
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
234 if (rp1->fr_blkid < rp2->fr_blkid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
235 return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
236 else if (rp1->fr_blkid > rp2->fr_blkid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
237 return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
238 else return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
239 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
240
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
241 void
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
242 dnode_setbonuslen(dnode_t *dn, int newsize, dmu_tx_t *tx)
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
243 {
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
244 ASSERT3U(refcount_count(&dn->dn_holds), >=, 1);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
245
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
246 dnode_setdirty(dn, tx);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
247 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
248 ASSERT3U(newsize, <=, DN_MAX_BONUSLEN -
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
249 (dn->dn_nblkptr-1) * sizeof (blkptr_t));
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
250 dn->dn_bonuslen = newsize;
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
251 if (newsize == 0)
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
252 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = DN_ZERO_BONUSLEN;
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
253 else
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
254 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = dn->dn_bonuslen;
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
255 rw_exit(&dn->dn_struct_rwlock);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
256 }
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
257
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
258 static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
259 dnode_setdblksz(dnode_t *dn, int size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
260 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
261 ASSERT3U(P2PHASE(size, SPA_MINBLOCKSIZE), ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
262 ASSERT3U(size, <=, SPA_MAXBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
263 ASSERT3U(size, >=, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
264 ASSERT3U(size >> SPA_MINBLOCKSHIFT, <,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
265 1<<(sizeof (dn->dn_phys->dn_datablkszsec) * 8));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
266 dn->dn_datablksz = size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
267 dn->dn_datablkszsec = size >> SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
268 dn->dn_datablkshift = ISP2(size) ? highbit(size - 1) : 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
269 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
270
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
271 static dnode_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
272 dnode_create(objset_impl_t *os, dnode_phys_t *dnp, dmu_buf_impl_t *db,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
273 uint64_t object)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
274 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
275 dnode_t *dn = kmem_cache_alloc(dnode_cache, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
276 (void) dnode_cons(dn, NULL, 0); /* XXX */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
277
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
278 dn->dn_objset = os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
279 dn->dn_object = object;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
280 dn->dn_dbuf = db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
281 dn->dn_phys = dnp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
282
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
283 if (dnp->dn_datablkszsec)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
284 dnode_setdblksz(dn, dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
285 dn->dn_indblkshift = dnp->dn_indblkshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
286 dn->dn_nlevels = dnp->dn_nlevels;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
287 dn->dn_type = dnp->dn_type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
288 dn->dn_nblkptr = dnp->dn_nblkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
289 dn->dn_checksum = dnp->dn_checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
290 dn->dn_compress = dnp->dn_compress;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
291 dn->dn_bonustype = dnp->dn_bonustype;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
292 dn->dn_bonuslen = dnp->dn_bonuslen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
293 dn->dn_maxblkid = dnp->dn_maxblkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
294
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
295 dmu_zfetch_init(&dn->dn_zfetch, dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
296
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
297 ASSERT(dn->dn_phys->dn_type < DMU_OT_NUMTYPES);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
298 mutex_enter(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
299 list_insert_head(&os->os_dnodes, dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
300 mutex_exit(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
301
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3882
diff changeset
302 arc_space_consume(sizeof (dnode_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
303 return (dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
304 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
305
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
306 static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
307 dnode_destroy(dnode_t *dn)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
308 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
309 objset_impl_t *os = dn->dn_objset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
310
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2445
diff changeset
311 #ifdef ZFS_DEBUG
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2445
diff changeset
312 int i;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2445
diff changeset
313
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2445
diff changeset
314 for (i = 0; i < TXG_SIZE; i++) {
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2445
diff changeset
315 ASSERT(!list_link_active(&dn->dn_dirty_link[i]));
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
316 ASSERT(NULL == list_head(&dn->dn_dirty_records[i]));
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2445
diff changeset
317 ASSERT(0 == avl_numnodes(&dn->dn_ranges[i]));
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2445
diff changeset
318 }
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2445
diff changeset
319 ASSERT(NULL == list_head(&dn->dn_dbufs));
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2445
diff changeset
320 #endif
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2445
diff changeset
321
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
322 mutex_enter(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
323 list_remove(&os->os_dnodes, dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
324 mutex_exit(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
325
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
326 if (dn->dn_dirtyctx_firstset) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
327 kmem_free(dn->dn_dirtyctx_firstset, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
328 dn->dn_dirtyctx_firstset = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
329 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
330 dmu_zfetch_rele(&dn->dn_zfetch);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
331 if (dn->dn_bonus) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
332 mutex_enter(&dn->dn_bonus->db_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
333 dbuf_evict(dn->dn_bonus);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
334 dn->dn_bonus = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
335 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
336 kmem_cache_free(dnode_cache, dn);
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3882
diff changeset
337 arc_space_return(sizeof (dnode_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
338 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
339
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
340 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
341 dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs,
1599
b2940ec637b4 6397222 corrupt microzap object
ahrens
parents: 1596
diff changeset
342 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
343 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
344 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
345
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
346 if (blocksize == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
347 blocksize = 1 << zfs_default_bs;
1402
bfaffef2800c 6382360 dnode_setblksz assertion failed
ahrens
parents: 873
diff changeset
348 else if (blocksize > SPA_MAXBLOCKSIZE)
bfaffef2800c 6382360 dnode_setblksz assertion failed
ahrens
parents: 873
diff changeset
349 blocksize = SPA_MAXBLOCKSIZE;
bfaffef2800c 6382360 dnode_setblksz assertion failed
ahrens
parents: 873
diff changeset
350 else
bfaffef2800c 6382360 dnode_setblksz assertion failed
ahrens
parents: 873
diff changeset
351 blocksize = P2ROUNDUP(blocksize, SPA_MINBLOCKSIZE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
352
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
353 if (ibs == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
354 ibs = zfs_default_ibs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
355
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
356 ibs = MIN(MAX(ibs, DN_MIN_INDBLKSHIFT), DN_MAX_INDBLKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
357
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
358 dprintf("os=%p obj=%llu txg=%llu blocksize=%d ibs=%d\n", dn->dn_objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
359 dn->dn_object, tx->tx_txg, blocksize, ibs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
360
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
361 ASSERT(dn->dn_type == DMU_OT_NONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
362 ASSERT(bcmp(dn->dn_phys, &dnode_phys_zero, sizeof (dnode_phys_t)) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
363 ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
364 ASSERT(ot != DMU_OT_NONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
365 ASSERT3U(ot, <, DMU_OT_NUMTYPES);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
366 ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
367 (bonustype != DMU_OT_NONE && bonuslen != 0));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
368 ASSERT3U(bonustype, <, DMU_OT_NUMTYPES);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
369 ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
370 ASSERT(dn->dn_type == DMU_OT_NONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
371 ASSERT3U(dn->dn_maxblkid, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
372 ASSERT3U(dn->dn_allocated_txg, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
373 ASSERT3U(dn->dn_assigned_txg, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
374 ASSERT(refcount_is_zero(&dn->dn_tx_holds));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
375 ASSERT3U(refcount_count(&dn->dn_holds), <=, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
376 ASSERT3P(list_head(&dn->dn_dbufs), ==, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
377
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
378 for (i = 0; i < TXG_SIZE; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
379 ASSERT3U(dn->dn_next_nlevels[i], ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
380 ASSERT3U(dn->dn_next_indblkshift[i], ==, 0);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
381 ASSERT3U(dn->dn_next_bonuslen[i], ==, 0);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
382 ASSERT3U(dn->dn_next_blksz[i], ==, 0);
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
383 ASSERT(!list_link_active(&dn->dn_dirty_link[i]));
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
384 ASSERT3P(list_head(&dn->dn_dirty_records[i]), ==, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
385 ASSERT3U(avl_numnodes(&dn->dn_ranges[i]), ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
386 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
387
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
388 dn->dn_type = ot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
389 dnode_setdblksz(dn, blocksize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
390 dn->dn_indblkshift = ibs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
391 dn->dn_nlevels = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
392 dn->dn_nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
393 dn->dn_bonustype = bonustype;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
394 dn->dn_bonuslen = bonuslen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
395 dn->dn_checksum = ZIO_CHECKSUM_INHERIT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
396 dn->dn_compress = ZIO_COMPRESS_INHERIT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
397 dn->dn_dirtyctx = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
398
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
399 dn->dn_free_txg = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
400 if (dn->dn_dirtyctx_firstset) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
401 kmem_free(dn->dn_dirtyctx_firstset, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
402 dn->dn_dirtyctx_firstset = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
403 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
404
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
405 dn->dn_allocated_txg = tx->tx_txg;
1599
b2940ec637b4 6397222 corrupt microzap object
ahrens
parents: 1596
diff changeset
406
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
407 dnode_setdirty(dn, tx);
1599
b2940ec637b4 6397222 corrupt microzap object
ahrens
parents: 1596
diff changeset
408 dn->dn_next_indblkshift[tx->tx_txg & TXG_MASK] = ibs;
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
409 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = dn->dn_bonuslen;
1599
b2940ec637b4 6397222 corrupt microzap object
ahrens
parents: 1596
diff changeset
410 dn->dn_next_blksz[tx->tx_txg & TXG_MASK] = dn->dn_datablksz;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
411 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
412
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
413 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
414 dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
415 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
416 {
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
417 int i, old_nblkptr;
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 3025
diff changeset
418 dmu_buf_impl_t *db = NULL;
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
419
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
420 ASSERT3U(blocksize, >=, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
421 ASSERT3U(blocksize, <=, SPA_MAXBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
422 ASSERT3U(blocksize % SPA_MINBLOCKSIZE, ==, 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
423 ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT || dmu_tx_private_ok(tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
424 ASSERT(tx->tx_txg != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
425 ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
426 (bonustype != DMU_OT_NONE && bonuslen != 0));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
427 ASSERT3U(bonustype, <, DMU_OT_NUMTYPES);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
428 ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
429
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
430 for (i = 0; i < TXG_SIZE; i++)
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
431 ASSERT(!list_link_active(&dn->dn_dirty_link[i]));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
432
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
433 /* clean up any unreferenced dbufs */
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
434 dnode_evict_dbufs(dn);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
435 ASSERT3P(list_head(&dn->dn_dbufs), ==, NULL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
436
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
437 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
438 * XXX I should really have a generation number to tell if we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
439 * need to do this...
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
440 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
441 if (blocksize != dn->dn_datablksz ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
442 dn->dn_bonustype != bonustype || dn->dn_bonuslen != bonuslen) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
443 /* free all old data */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
444 dnode_free_range(dn, 0, -1ULL, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
445 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
446
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
447 /* change blocksize */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
448 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 3025
diff changeset
449 if (blocksize != dn->dn_datablksz &&
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 3025
diff changeset
450 (!BP_IS_HOLE(&dn->dn_phys->dn_blkptr[0]) ||
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 3025
diff changeset
451 list_head(&dn->dn_dbufs) != NULL)) {
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 3025
diff changeset
452 db = dbuf_hold(dn, 0, FTAG);
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 3025
diff changeset
453 dbuf_new_size(db, blocksize, tx);
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 3025
diff changeset
454 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
455 dnode_setdblksz(dn, blocksize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
456 dnode_setdirty(dn, tx);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
457 dn->dn_next_bonuslen[tx->tx_txg&TXG_MASK] = bonuslen;
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
458 dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = blocksize;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
459 rw_exit(&dn->dn_struct_rwlock);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
460 if (db)
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 3025
diff changeset
461 dbuf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
462
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
463 /* change type */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
464 dn->dn_type = ot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
465
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
466 /* change bonus size and type */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
467 mutex_enter(&dn->dn_mtx);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
468 old_nblkptr = dn->dn_nblkptr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
469 dn->dn_bonustype = bonustype;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
470 dn->dn_bonuslen = bonuslen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
471 dn->dn_nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
472 dn->dn_checksum = ZIO_CHECKSUM_INHERIT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
473 dn->dn_compress = ZIO_COMPRESS_INHERIT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
474 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
475
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
476 /* XXX - for now, we can't make nblkptr smaller */
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
477 ASSERT3U(dn->dn_nblkptr, >=, old_nblkptr);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
478
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
479 /* fix up the bonus db_size if dn_nblkptr has changed */
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
480 if (dn->dn_bonus && dn->dn_bonuslen != old_nblkptr) {
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
481 dn->dn_bonus->db.db_size =
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
482 DN_MAX_BONUSLEN - (dn->dn_nblkptr-1) * sizeof (blkptr_t);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
483 ASSERT(dn->dn_bonuslen <= dn->dn_bonus->db.db_size);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
484 }
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 3025
diff changeset
485
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
486 dn->dn_allocated_txg = tx->tx_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
487 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
488 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
489
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
490 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
491 dnode_special_close(dnode_t *dn)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
492 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
493 /*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
494 * Wait for final references to the dnode to clear. This can
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
495 * only happen if the arc is asyncronously evicting state that
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
496 * has a hold on this dnode while we are trying to evict this
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
497 * dnode.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
498 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
499 while (refcount_count(&dn->dn_holds) > 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
500 delay(1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
501 dnode_destroy(dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
502 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
503
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
504 dnode_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
505 dnode_special_open(objset_impl_t *os, dnode_phys_t *dnp, uint64_t object)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
506 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
507 dnode_t *dn = dnode_create(os, dnp, NULL, object);
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
508 DNODE_VERIFY(dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
509 return (dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
510 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
511
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
512 static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
513 dnode_buf_pageout(dmu_buf_t *db, void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
514 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
515 dnode_t **children_dnodes = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
516 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
517 int epb = db->db_size >> DNODE_SHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
518
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
519 for (i = 0; i < epb; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
520 dnode_t *dn = children_dnodes[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
521 int n;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
522
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
523 if (dn == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
524 continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
525 #ifdef ZFS_DEBUG
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
526 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
527 * If there are holds on this dnode, then there should
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
528 * be holds on the dnode's containing dbuf as well; thus
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
529 * it wouldn't be eligable for eviction and this function
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
530 * would not have been called.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
531 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
532 ASSERT(refcount_is_zero(&dn->dn_holds));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
533 ASSERT(list_head(&dn->dn_dbufs) == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
534 ASSERT(refcount_is_zero(&dn->dn_tx_holds));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
535
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
536 for (n = 0; n < TXG_SIZE; n++)
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
537 ASSERT(!list_link_active(&dn->dn_dirty_link[n]));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
538 #endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
539 children_dnodes[i] = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
540 dnode_destroy(dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
541 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
542 kmem_free(children_dnodes, epb * sizeof (dnode_t *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
543 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
544
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
545 /*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
546 * errors:
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
547 * EINVAL - invalid object number.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
548 * EIO - i/o error.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
549 * succeeds even for free dnodes.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
550 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
551 int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
552 dnode_hold_impl(objset_impl_t *os, uint64_t object, int flag,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
553 void *tag, dnode_t **dnp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
554 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
555 int epb, idx, err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
556 int drop_struct_lock = FALSE;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
557 int type;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
558 uint64_t blk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
559 dnode_t *mdn, *dn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
560 dmu_buf_impl_t *db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
561 dnode_t **children_dnodes;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
562
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7385
diff changeset
563 /*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7385
diff changeset
564 * If you are holding the spa config lock as writer, you shouldn't
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7385
diff changeset
565 * be asking the DMU to do *anything*.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7385
diff changeset
566 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7385
diff changeset
567 ASSERT(spa_config_held(os->os_spa, SCL_ALL, RW_WRITER) == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7385
diff changeset
568
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
569 if (object == 0 || object >= DN_MAX_OBJECT)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
570 return (EINVAL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
571
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
572 mdn = os->os_meta_dnode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
573
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
574 DNODE_VERIFY(mdn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
575
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
576 if (!RW_WRITE_HELD(&mdn->dn_struct_rwlock)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
577 rw_enter(&mdn->dn_struct_rwlock, RW_READER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
578 drop_struct_lock = TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
579 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
580
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
581 blk = dbuf_whichblock(mdn, object * sizeof (dnode_phys_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
582
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
583 db = dbuf_hold(mdn, blk, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
584 if (drop_struct_lock)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
585 rw_exit(&mdn->dn_struct_rwlock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
586 if (db == NULL)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
587 return (EIO);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
588 err = dbuf_read(db, NULL, DB_RF_CANFAIL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
589 if (err) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
590 dbuf_rele(db, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
591 return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
592 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
593
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
594 ASSERT3U(db->db.db_size, >=, 1<<DNODE_SHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
595 epb = db->db.db_size >> DNODE_SHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
596
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
597 idx = object & (epb-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
598
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
599 children_dnodes = dmu_buf_get_user(&db->db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
600 if (children_dnodes == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
601 dnode_t **winner;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
602 children_dnodes = kmem_zalloc(epb * sizeof (dnode_t *),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
603 KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
604 if (winner = dmu_buf_set_user(&db->db, children_dnodes, NULL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
605 dnode_buf_pageout)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
606 kmem_free(children_dnodes, epb * sizeof (dnode_t *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
607 children_dnodes = winner;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
608 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
609 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
610
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
611 if ((dn = children_dnodes[idx]) == NULL) {
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3882
diff changeset
612 dnode_phys_t *dnp = (dnode_phys_t *)db->db.db_data+idx;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
613 dnode_t *winner;
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3882
diff changeset
614
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3882
diff changeset
615 dn = dnode_create(os, dnp, db, object);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
616 winner = atomic_cas_ptr(&children_dnodes[idx], NULL, dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
617 if (winner != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
618 dnode_destroy(dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
619 dn = winner;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
620 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
621 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
622
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
623 mutex_enter(&dn->dn_mtx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
624 type = dn->dn_type;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
625 if (dn->dn_free_txg ||
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
626 ((flag & DNODE_MUST_BE_ALLOCATED) && type == DMU_OT_NONE) ||
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
627 ((flag & DNODE_MUST_BE_FREE) && type != DMU_OT_NONE)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
628 mutex_exit(&dn->dn_mtx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
629 dbuf_rele(db, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
630 return (type == DMU_OT_NONE ? ENOENT : EEXIST);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
631 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
632 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
633
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
634 if (refcount_add(&dn->dn_holds, tag) == 1)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
635 dbuf_add_ref(db, dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
636
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
637 DNODE_VERIFY(dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
638 ASSERT3P(dn->dn_dbuf, ==, db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
639 ASSERT3U(dn->dn_object, ==, object);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
640 dbuf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
641
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
642 *dnp = dn;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
643 return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
644 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
645
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
646 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
647 * Return held dnode if the object is allocated, NULL if not.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
648 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
649 int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
650 dnode_hold(objset_impl_t *os, uint64_t object, void *tag, dnode_t **dnp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
651 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
652 return (dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED, tag, dnp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
653 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
654
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
655 /*
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
656 * Can only add a reference if there is already at least one
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
657 * reference on the dnode. Returns FALSE if unable to add a
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
658 * new reference.
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
659 */
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
660 boolean_t
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
661 dnode_add_ref(dnode_t *dn, void *tag)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
662 {
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
663 mutex_enter(&dn->dn_mtx);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
664 if (refcount_is_zero(&dn->dn_holds)) {
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
665 mutex_exit(&dn->dn_mtx);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
666 return (FALSE);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
667 }
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
668 VERIFY(1 < refcount_add(&dn->dn_holds, tag));
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
669 mutex_exit(&dn->dn_mtx);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
670 return (TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
671 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
672
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
673 void
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
674 dnode_rele(dnode_t *dn, void *tag)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
675 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
676 uint64_t refs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
677
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
678 mutex_enter(&dn->dn_mtx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
679 refs = refcount_remove(&dn->dn_holds, tag);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
680 mutex_exit(&dn->dn_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
681 /* NOTE: the DNODE_DNODE does not have a dn_dbuf */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
682 if (refs == 0 && dn->dn_dbuf)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
683 dbuf_rele(dn->dn_dbuf, dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
684 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
685
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
686 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
687 dnode_setdirty(dnode_t *dn, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
688 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
689 objset_impl_t *os = dn->dn_objset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
690 uint64_t txg = tx->tx_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
691
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
692 if (dn->dn_object == DMU_META_DNODE_OBJECT)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
693 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
694
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
695 DNODE_VERIFY(dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
696
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
697 #ifdef ZFS_DEBUG
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
698 mutex_enter(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
699 ASSERT(dn->dn_phys->dn_type || dn->dn_allocated_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
700 /* ASSERT(dn->dn_free_txg == 0 || dn->dn_free_txg >= txg); */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
701 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
702 #endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
703
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
704 mutex_enter(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
705
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
706 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
707 * If we are already marked dirty, we're done.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
708 */
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
709 if (list_link_active(&dn->dn_dirty_link[txg & TXG_MASK])) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
710 mutex_exit(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
711 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
712 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
713
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
714 ASSERT(!refcount_is_zero(&dn->dn_holds) || list_head(&dn->dn_dbufs));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
715 ASSERT(dn->dn_datablksz != 0);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
716 ASSERT3U(dn->dn_next_bonuslen[txg&TXG_MASK], ==, 0);
1599
b2940ec637b4 6397222 corrupt microzap object
ahrens
parents: 1596
diff changeset
717 ASSERT3U(dn->dn_next_blksz[txg&TXG_MASK], ==, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
718
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
719 dprintf_ds(os->os_dsl_dataset, "obj=%llu txg=%llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
720 dn->dn_object, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
721
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
722 if (dn->dn_free_txg > 0 && dn->dn_free_txg <= txg) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
723 list_insert_tail(&os->os_free_dnodes[txg&TXG_MASK], dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
724 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
725 list_insert_tail(&os->os_dirty_dnodes[txg&TXG_MASK], dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
726 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
727
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
728 mutex_exit(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
729
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
730 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
731 * The dnode maintains a hold on its containing dbuf as
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
732 * long as there are holds on it. Each instantiated child
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
733 * dbuf maintaines a hold on the dnode. When the last child
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
734 * drops its hold, the dnode will drop its hold on the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
735 * containing dbuf. We add a "dirty hold" here so that the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
736 * dnode will hang around after we finish processing its
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
737 * children.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
738 */
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
739 VERIFY(dnode_add_ref(dn, (void *)(uintptr_t)tx->tx_txg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
740
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
741 (void) dbuf_dirty(dn->dn_dbuf, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
742
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
743 dsl_dataset_dirty(os->os_dsl_dataset, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
744 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
745
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
746 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
747 dnode_free(dnode_t *dn, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
748 {
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
749 int txgoff = tx->tx_txg & TXG_MASK;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
750
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
751 dprintf("dn=%p txg=%llu\n", dn, tx->tx_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
752
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
753 /* we should be the only holder... hopefully */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
754 /* ASSERT3U(refcount_count(&dn->dn_holds), ==, 1); */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
755
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
756 mutex_enter(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
757 if (dn->dn_type == DMU_OT_NONE || dn->dn_free_txg) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
758 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
759 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
760 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
761 dn->dn_free_txg = tx->tx_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
762 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
763
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
764 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
765 * If the dnode is already dirty, it needs to be moved from
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
766 * the dirty list to the free list.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
767 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
768 mutex_enter(&dn->dn_objset->os_lock);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
769 if (list_link_active(&dn->dn_dirty_link[txgoff])) {
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
770 list_remove(&dn->dn_objset->os_dirty_dnodes[txgoff], dn);
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
771 list_insert_tail(&dn->dn_objset->os_free_dnodes[txgoff], dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
772 mutex_exit(&dn->dn_objset->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
773 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
774 mutex_exit(&dn->dn_objset->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
775 dnode_setdirty(dn, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
776 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
777 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
778
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
779 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
780 * Try to change the block size for the indicated dnode. This can only
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
781 * succeed if there are no blocks allocated or dirty beyond first block
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
782 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
783 int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
784 dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
785 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
786 dmu_buf_impl_t *db, *db_next;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
787 int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
788
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
789 if (size == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
790 size = SPA_MINBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
791 if (size > SPA_MAXBLOCKSIZE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
792 size = SPA_MAXBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
793 else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
794 size = P2ROUNDUP(size, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
795
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
796 if (ibs == dn->dn_indblkshift)
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
797 ibs = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
798
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
799 if (size >> SPA_MINBLOCKSHIFT == dn->dn_datablkszsec && ibs == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
800 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
801
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
802 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
803
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
804 /* Check for any allocated blocks beyond the first */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
805 if (dn->dn_phys->dn_maxblkid != 0)
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
806 goto fail;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
807
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
808 mutex_enter(&dn->dn_dbufs_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
809 for (db = list_head(&dn->dn_dbufs); db; db = db_next) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
810 db_next = list_next(&dn->dn_dbufs, db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
811
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
812 if (db->db_blkid != 0 && db->db_blkid != DB_BONUS_BLKID) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
813 mutex_exit(&dn->dn_dbufs_mtx);
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
814 goto fail;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
815 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
816 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
817 mutex_exit(&dn->dn_dbufs_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
818
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
819 if (ibs && dn->dn_nlevels != 1)
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
820 goto fail;
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
821
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
822 /* resize the old block */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
823 err = dbuf_hold_impl(dn, 0, 0, TRUE, FTAG, &db);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
824 if (err == 0)
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
825 dbuf_new_size(db, size, tx);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
826 else if (err != ENOENT)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
827 goto fail;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
828
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
829 dnode_setdblksz(dn, size);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
830 dnode_setdirty(dn, tx);
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
831 dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = size;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
832 if (ibs) {
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
833 dn->dn_indblkshift = ibs;
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
834 dn->dn_next_indblkshift[tx->tx_txg&TXG_MASK] = ibs;
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
835 }
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
836 /* rele after we have fixed the blocksize in the dnode */
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
837 if (db)
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
838 dbuf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
839
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
840 rw_exit(&dn->dn_struct_rwlock);
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
841 return (0);
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
842
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
843 fail:
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
844 rw_exit(&dn->dn_struct_rwlock);
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
845 return (ENOTSUP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
846 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
847
7332
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
848 /* read-holding callers must not rely on the lock being continuously held */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
849 void
7332
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
850 dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t have_read)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
851 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
852 uint64_t txgoff = tx->tx_txg & TXG_MASK;
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
853 int epbs, new_nlevels;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
854 uint64_t sz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
855
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
856 ASSERT(blkid != DB_BONUS_BLKID);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
857
7332
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
858 ASSERT(have_read ?
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
859 RW_READ_HELD(&dn->dn_struct_rwlock) :
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
860 RW_WRITE_HELD(&dn->dn_struct_rwlock));
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
861
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
862 /*
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
863 * if we have a read-lock, check to see if we need to do any work
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
864 * before upgrading to a write-lock.
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
865 */
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
866 if (have_read) {
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
867 if (blkid <= dn->dn_maxblkid)
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
868 return;
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
869
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
870 if (!rw_tryupgrade(&dn->dn_struct_rwlock)) {
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
871 rw_exit(&dn->dn_struct_rwlock);
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
872 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
873 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
874 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
875
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
876 if (blkid <= dn->dn_maxblkid)
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
877 goto out;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
878
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
879 dn->dn_maxblkid = blkid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
880
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
881 /*
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
882 * Compute the number of levels necessary to support the new maxblkid.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
883 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
884 new_nlevels = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
885 epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT;
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
886 for (sz = dn->dn_nblkptr;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
887 sz <= blkid && sz >= dn->dn_nblkptr; sz <<= epbs)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
888 new_nlevels++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
889
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
890 if (new_nlevels > dn->dn_nlevels) {
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
891 int old_nlevels = dn->dn_nlevels;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
892 dmu_buf_impl_t *db;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
893 list_t *list;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
894 dbuf_dirty_record_t *new, *dr, *dr_next;
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
895
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
896 dn->dn_nlevels = new_nlevels;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
897
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
898 ASSERT3U(new_nlevels, >, dn->dn_next_nlevels[txgoff]);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
899 dn->dn_next_nlevels[txgoff] = new_nlevels;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
900
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
901 /* dirty the left indirects */
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
902 db = dbuf_hold_level(dn, old_nlevels, 0, FTAG);
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
903 new = dbuf_dirty(db, tx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
904 dbuf_rele(db, FTAG);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
905
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
906 /* transfer the dirty records to the new indirect */
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
907 mutex_enter(&dn->dn_mtx);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
908 mutex_enter(&new->dt.di.dr_mtx);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
909 list = &dn->dn_dirty_records[txgoff];
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
910 for (dr = list_head(list); dr; dr = dr_next) {
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
911 dr_next = list_next(&dn->dn_dirty_records[txgoff], dr);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
912 if (dr->dr_dbuf->db_level != new_nlevels-1 &&
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
913 dr->dr_dbuf->db_blkid != DB_BONUS_BLKID) {
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
914 ASSERT(dr->dr_dbuf->db_level == old_nlevels-1);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
915 list_remove(&dn->dn_dirty_records[txgoff], dr);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
916 list_insert_tail(&new->dt.di.dr_children, dr);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
917 dr->dr_parent = new;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
918 }
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
919 }
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
920 mutex_exit(&new->dt.di.dr_mtx);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
921 mutex_exit(&dn->dn_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
922 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
923
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
924 out:
7332
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
925 if (have_read)
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
926 rw_downgrade(&dn->dn_struct_rwlock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
927 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
928
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
929 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
930 dnode_clear_range(dnode_t *dn, uint64_t blkid, uint64_t nblks, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
931 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
932 avl_tree_t *tree = &dn->dn_ranges[tx->tx_txg&TXG_MASK];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
933 avl_index_t where;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
934 free_range_t *rp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
935 free_range_t rp_tofind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
936 uint64_t endblk = blkid + nblks;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
937
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
938 ASSERT(MUTEX_HELD(&dn->dn_mtx));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
939 ASSERT(nblks <= UINT64_MAX - blkid); /* no overflow */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
940
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
941 dprintf_dnode(dn, "blkid=%llu nblks=%llu txg=%llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
942 blkid, nblks, tx->tx_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
943 rp_tofind.fr_blkid = blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
944 rp = avl_find(tree, &rp_tofind, &where);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
945 if (rp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
946 rp = avl_nearest(tree, where, AVL_BEFORE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
947 if (rp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
948 rp = avl_nearest(tree, where, AVL_AFTER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
949
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
950 while (rp && (rp->fr_blkid <= blkid + nblks)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
951 uint64_t fr_endblk = rp->fr_blkid + rp->fr_nblks;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
952 free_range_t *nrp = AVL_NEXT(tree, rp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
953
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
954 if (blkid <= rp->fr_blkid && endblk >= fr_endblk) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
955 /* clear this entire range */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
956 avl_remove(tree, rp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
957 kmem_free(rp, sizeof (free_range_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
958 } else if (blkid <= rp->fr_blkid &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
959 endblk > rp->fr_blkid && endblk < fr_endblk) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
960 /* clear the beginning of this range */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
961 rp->fr_blkid = endblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
962 rp->fr_nblks = fr_endblk - endblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
963 } else if (blkid > rp->fr_blkid && blkid < fr_endblk &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
964 endblk >= fr_endblk) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
965 /* clear the end of this range */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
966 rp->fr_nblks = blkid - rp->fr_blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
967 } else if (blkid > rp->fr_blkid && endblk < fr_endblk) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
968 /* clear a chunk out of this range */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
969 free_range_t *new_rp =
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
970 kmem_alloc(sizeof (free_range_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
971
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
972 new_rp->fr_blkid = endblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
973 new_rp->fr_nblks = fr_endblk - endblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
974 avl_insert_here(tree, new_rp, rp, AVL_AFTER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
975 rp->fr_nblks = blkid - rp->fr_blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
976 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
977 /* there may be no overlap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
978 rp = nrp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
979 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
980 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
981
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
982 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
983 dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
984 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
985 dmu_buf_impl_t *db;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
986 uint64_t blkoff, blkid, nblks;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
987 int blksz, blkshift, head, tail;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
988 int trunc = FALSE;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
989 int epbs;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
990
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
991 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
992 blksz = dn->dn_datablksz;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
993 blkshift = dn->dn_datablkshift;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
994 epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
995
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
996 if (len == -1ULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
997 len = UINT64_MAX - off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
998 trunc = TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
999 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1000
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1001 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1002 * First, block align the region to free:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1003 */
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1004 if (ISP2(blksz)) {
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1005 head = P2NPHASE(off, blksz);
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1006 blkoff = P2PHASE(off, blksz);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1007 if ((off >> blkshift) > dn->dn_maxblkid)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1008 goto out;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1009 } else {
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1010 ASSERT(dn->dn_maxblkid == 0);
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1011 if (off == 0 && len >= blksz) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1012 /* Freeing the whole block; fast-track this request */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1013 blkid = 0;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1014 nblks = 1;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1015 goto done;
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1016 } else if (off >= blksz) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1017 /* Freeing past end-of-data */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1018 goto out;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1019 } else {
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1020 /* Freeing part of the block. */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1021 head = blksz - off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1022 ASSERT3U(head, >, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1023 }
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1024 blkoff = off;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1025 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1026 /* zero out any partial block data at the start of the range */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1027 if (head) {
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1028 ASSERT3U(blkoff + head, ==, blksz);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1029 if (len < head)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1030 head = len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1031 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, off), TRUE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1032 FTAG, &db) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1033 caddr_t data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1034
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1035 /* don't dirty if it isn't on disk and isn't dirty */
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1036 if (db->db_last_dirty ||
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1037 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1038 rw_exit(&dn->dn_struct_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1039 dbuf_will_dirty(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1040 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1041 data = db->db.db_data;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1042 bzero(data + blkoff, head);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1043 }
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1044 dbuf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1045 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1046 off += head;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1047 len -= head;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1048 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1049
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1050 /* If the range was less than one block, we're done */
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1051 if (len == 0)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1052 goto out;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1053
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1054 /* If the remaining range is past end of file, we're done */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1055 if ((off >> blkshift) > dn->dn_maxblkid)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1056 goto out;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1057
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1058 ASSERT(ISP2(blksz));
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1059 if (trunc)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1060 tail = 0;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1061 else
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1062 tail = P2PHASE(len, blksz);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1063
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1064 ASSERT3U(P2PHASE(off, blksz), ==, 0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1065 /* zero out any partial block data at the end of the range */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1066 if (tail) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1067 if (len < tail)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1068 tail = len;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1069 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, off+len),
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1070 TRUE, FTAG, &db) == 0) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1071 /* don't dirty if not on disk and not dirty */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1072 if (db->db_last_dirty ||
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1073 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1074 rw_exit(&dn->dn_struct_rwlock);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1075 dbuf_will_dirty(db, tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1076 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1077 bzero(db->db.db_data, tail);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1078 }
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1079 dbuf_rele(db, FTAG);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1080 }
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1081 len -= tail;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1082 }
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1083
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1084 /* If the range did not include a full block, we are done */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1085 if (len == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1086 goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1087
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1088 ASSERT(IS_P2ALIGNED(off, blksz));
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1089 ASSERT(trunc || IS_P2ALIGNED(len, blksz));
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1090 blkid = off >> blkshift;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1091 nblks = len >> blkshift;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1092 if (trunc)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1093 nblks += 1;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1094
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1095 /*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1096 * Read in and mark all the level-1 indirects dirty,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1097 * so that they will stay in memory until syncing phase.
7049
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1098 * Always dirty the first and last indirect to make sure
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1099 * we dirty all the partial indirects.
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1100 */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1101 if (dn->dn_nlevels > 1) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1102 uint64_t i, first, last;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1103 int shift = epbs + dn->dn_datablkshift;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1104
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1105 first = blkid >> epbs;
7049
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1106 if (db = dbuf_hold_level(dn, 1, first, FTAG)) {
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1107 dbuf_will_dirty(db, tx);
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1108 dbuf_rele(db, FTAG);
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1109 }
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1110 if (trunc)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1111 last = dn->dn_maxblkid >> epbs;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1112 else
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1113 last = (blkid + nblks - 1) >> epbs;
7049
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1114 if (last > first && (db = dbuf_hold_level(dn, 1, last, FTAG))) {
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1115 dbuf_will_dirty(db, tx);
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1116 dbuf_rele(db, FTAG);
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1117 }
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1118 for (i = first + 1; i < last; i++) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1119 uint64_t ibyte = i << shift;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1120 int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1121
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1122 err = dnode_next_offset(dn,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1123 DNODE_FIND_HAVELOCK, &ibyte, 1, 1, 0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1124 i = ibyte >> shift;
7049
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1125 if (err == ESRCH || i >= last)
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1126 break;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1127 ASSERT(err == 0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1128 db = dbuf_hold_level(dn, 1, i, FTAG);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1129 if (db) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1130 dbuf_will_dirty(db, tx);
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1131 dbuf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1132 }
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1133 }
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1134 }
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1135 done:
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1136 /*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1137 * Add this range to the dnode range list.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1138 * We will finish up this free operation in the syncing phase.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1139 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1140 mutex_enter(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1141 dnode_clear_range(dn, blkid, nblks, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1142 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1143 free_range_t *rp, *found;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1144 avl_index_t where;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1145 avl_tree_t *tree = &dn->dn_ranges[tx->tx_txg&TXG_MASK];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1146
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1147 /* Add new range to dn_ranges */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1148 rp = kmem_alloc(sizeof (free_range_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1149 rp->fr_blkid = blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1150 rp->fr_nblks = nblks;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1151 found = avl_find(tree, rp, &where);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1152 ASSERT(found == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1153 avl_insert(tree, rp, where);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1154 dprintf_dnode(dn, "blkid=%llu nblks=%llu txg=%llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1155 blkid, nblks, tx->tx_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1156 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1157 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1158
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1159 dbuf_free_range(dn, blkid, blkid + nblks - 1, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1160 dnode_setdirty(dn, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1161 out:
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1162 if (trunc && dn->dn_maxblkid >= (off >> blkshift))
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1163 dn->dn_maxblkid = (off >> blkshift ? (off >> blkshift) - 1 : 0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1164
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1165 rw_exit(&dn->dn_struct_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1166 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1167
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1168 /* return TRUE if this blkid was freed in a recent txg, or FALSE if it wasn't */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1169 uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1170 dnode_block_freed(dnode_t *dn, uint64_t blkid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1171 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1172 free_range_t range_tofind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1173 void *dp = spa_get_dsl(dn->dn_objset->os_spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1174 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1175
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1176 if (blkid == DB_BONUS_BLKID)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1177 return (FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1178
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1179 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1180 * If we're in the process of opening the pool, dp will not be
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1181 * set yet, but there shouldn't be anything dirty.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1182 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1183 if (dp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1184 return (FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1185
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1186 if (dn->dn_free_txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1187 return (TRUE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1188
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1189 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1190 * If dn_datablkshift is not set, then there's only a single
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1191 * block, in which case there will never be a free range so it
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1192 * won't matter.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1193 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1194 range_tofind.fr_blkid = blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1195 mutex_enter(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1196 for (i = 0; i < TXG_SIZE; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1197 free_range_t *range_found;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1198 avl_index_t idx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1199
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1200 range_found = avl_find(&dn->dn_ranges[i], &range_tofind, &idx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1201 if (range_found) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1202 ASSERT(range_found->fr_nblks > 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1203 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1204 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1205 range_found = avl_nearest(&dn->dn_ranges[i], idx, AVL_BEFORE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1206 if (range_found &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1207 range_found->fr_blkid + range_found->fr_nblks > blkid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1208 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1209 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1210 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1211 return (i < TXG_SIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1212 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1213
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1214 /* call from syncing context when we actually write/free space for this dnode */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1215 void
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1216 dnode_diduse_space(dnode_t *dn, int64_t delta)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1217 {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1218 uint64_t space;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1219 dprintf_dnode(dn, "dn=%p dnp=%p used=%llu delta=%lld\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1220 dn, dn->dn_phys,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1221 (u_longlong_t)dn->dn_phys->dn_used,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1222 (longlong_t)delta);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1223
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1224 mutex_enter(&dn->dn_mtx);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1225 space = DN_USED_BYTES(dn->dn_phys);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1226 if (delta > 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1227 ASSERT3U(space + delta, >=, space); /* no overflow */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1228 } else {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1229 ASSERT3U(space, >=, -delta); /* no underflow */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1230 }
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1231 space += delta;
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4309
diff changeset
1232 if (spa_version(dn->dn_objset->os_spa) < SPA_VERSION_DNODE_BYTES) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1233 ASSERT((dn->dn_phys->dn_flags & DNODE_FLAG_USED_BYTES) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1234 ASSERT3U(P2PHASE(space, 1<<DEV_BSHIFT), ==, 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1235 dn->dn_phys->dn_used = space >> DEV_BSHIFT;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1236 } else {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1237 dn->dn_phys->dn_used = space;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1238 dn->dn_phys->dn_flags |= DNODE_FLAG_USED_BYTES;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1239 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1240 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1241 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1242
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1243 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1244 * Call when we think we're going to write/free space in open context.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1245 * Be conservative (ie. OK to write less than this or free more than
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1246 * this, but don't write more or free less).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1247 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1248 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1249 dnode_willuse_space(dnode_t *dn, int64_t space, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1250 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1251 objset_impl_t *os = dn->dn_objset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1252 dsl_dataset_t *ds = os->os_dsl_dataset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1253
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1254 if (space > 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1255 space = spa_get_asize(os->os_spa, space);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1256
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1257 if (ds)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1258 dsl_dir_willuse_space(ds->ds_dir, space, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1259
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1260 dmu_tx_willuse_space(tx, space);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1261 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1262
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1263 static int
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1264 dnode_next_offset_level(dnode_t *dn, int flags, uint64_t *offset,
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1265 int lvl, uint64_t blkfill, uint64_t txg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1266 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1267 dmu_buf_impl_t *db = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1268 void *data = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1269 uint64_t epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1270 uint64_t epb = 1ULL << epbs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1271 uint64_t minfill, maxfill;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1272 boolean_t hole;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1273 int i, inc, error, span;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1274
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1275 dprintf("probing object %llu offset %llx level %d of %u\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1276 dn->dn_object, *offset, lvl, dn->dn_phys->dn_nlevels);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1277
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1278 hole = flags & DNODE_FIND_HOLE;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1279 inc = (flags & DNODE_FIND_BACKWARDS) ? -1 : 1;
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1280 ASSERT(txg == 0 || !hole);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1281
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1282 if (lvl == dn->dn_phys->dn_nlevels) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1283 error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1284 epb = dn->dn_phys->dn_nblkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1285 data = dn->dn_phys->dn_blkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1286 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1287 uint64_t blkid = dbuf_whichblock(dn, *offset) >> (epbs * lvl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1288 error = dbuf_hold_impl(dn, lvl, blkid, TRUE, FTAG, &db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1289 if (error) {
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1290 if (error != ENOENT)
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1291 return (error);
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1292 if (hole)
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1293 return (0);
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1294 /*
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1295 * This can only happen when we are searching up
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1296 * the block tree for data. We don't really need to
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1297 * adjust the offset, as we will just end up looking
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1298 * at the pointer to this block in its parent, and its
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1299 * going to be unallocated, so we will skip over it.
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1300 */
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1301 return (ESRCH);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1302 }
1793
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1303 error = dbuf_read(db, NULL, DB_RF_CANFAIL | DB_RF_HAVESTRUCT);
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1304 if (error) {
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1305 dbuf_rele(db, FTAG);
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1306 return (error);
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1307 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1308 data = db->db.db_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1309 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1310
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1311 if (db && txg &&
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1312 (db->db_blkptr == NULL || db->db_blkptr->blk_birth <= txg)) {
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1313 /*
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1314 * This can only happen when we are searching up the tree
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1315 * and these conditions mean that we need to keep climbing.
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1316 */
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1317 error = ESRCH;
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1318 } else if (lvl == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1319 dnode_phys_t *dnp = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1320 span = DNODE_SHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1321 ASSERT(dn->dn_type == DMU_OT_DNODE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1322
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1323 for (i = (*offset >> span) & (blkfill - 1);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1324 i >= 0 && i < blkfill; i += inc) {
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1325 boolean_t newcontents = B_TRUE;
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1326 if (txg) {
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1327 int j;
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1328 newcontents = B_FALSE;
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1329 for (j = 0; j < dnp[i].dn_nblkptr; j++) {
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1330 if (dnp[i].dn_blkptr[j].blk_birth > txg)
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1331 newcontents = B_TRUE;
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1332 }
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1333 }
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1334 if (!dnp[i].dn_type == hole && newcontents)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1335 break;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1336 *offset += (1ULL << span) * inc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1337 }
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1338 if (i < 0 || i == blkfill)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1339 error = ESRCH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1340 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1341 blkptr_t *bp = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1342 span = (lvl - 1) * epbs + dn->dn_datablkshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1343 minfill = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1344 maxfill = blkfill << ((lvl - 1) * epbs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1345
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1346 if (hole)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1347 maxfill--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1348 else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1349 minfill++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1350
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1351 for (i = (*offset >> span) & ((1ULL << epbs) - 1);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1352 i >= 0 && i < epb; i += inc) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1353 if (bp[i].blk_fill >= minfill &&
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1354 bp[i].blk_fill <= maxfill &&
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1355 (hole || bp[i].blk_birth > txg))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1356 break;
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1357 if (inc < 0 && *offset < (1ULL << span))
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1358 *offset = 0;
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1359 else
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1360 *offset += (1ULL << span) * inc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1361 }
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1362 if (i < 0 || i == epb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1363 error = ESRCH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1364 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1365
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1366 if (db)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1367 dbuf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1368
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1369 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1370 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1371
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1372 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1373 * Find the next hole, data, or sparse region at or after *offset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1374 * The value 'blkfill' tells us how many items we expect to find
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1375 * in an L0 data block; this value is 1 for normal objects,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1376 * DNODES_PER_BLOCK for the meta dnode, and some fraction of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1377 * DNODES_PER_BLOCK when searching for sparse regions thereof.
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1378 *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1379 * Examples:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1380 *
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1381 * dnode_next_offset(dn, flags, offset, 1, 1, 0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1382 * Finds the next/previous hole/data in a file.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1383 * Used in dmu_offset_next().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1384 *
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1385 * dnode_next_offset(mdn, flags, offset, 0, DNODES_PER_BLOCK, txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1386 * Finds the next free/allocated dnode an objset's meta-dnode.
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1387 * Only finds objects that have new contents since txg (ie.
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1388 * bonus buffer changes and content removal are ignored).
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1389 * Used in dmu_object_next().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1390 *
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1391 * dnode_next_offset(mdn, DNODE_FIND_HOLE, offset, 2, DNODES_PER_BLOCK >> 2, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1392 * Finds the next L2 meta-dnode bp that's at most 1/4 full.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1393 * Used in dmu_object_alloc().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1394 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1395 int
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1396 dnode_next_offset(dnode_t *dn, int flags, uint64_t *offset,
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1397 int minlvl, uint64_t blkfill, uint64_t txg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1398 {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1399 uint64_t initial_offset = *offset;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1400 int lvl, maxlvl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1401 int error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1402
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1403 if (!(flags & DNODE_FIND_HAVELOCK))
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1404 rw_enter(&dn->dn_struct_rwlock, RW_READER);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1405
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1406 if (dn->dn_phys->dn_nlevels == 0) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1407 error = ESRCH;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1408 goto out;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1409 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1410
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1411 if (dn->dn_datablkshift == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1412 if (*offset < dn->dn_datablksz) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1413 if (flags & DNODE_FIND_HOLE)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1414 *offset = dn->dn_datablksz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1415 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1416 error = ESRCH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1417 }
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1418 goto out;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1419 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1420
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1421 maxlvl = dn->dn_phys->dn_nlevels;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1422
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1423 for (lvl = minlvl; lvl <= maxlvl; lvl++) {
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1424 error = dnode_next_offset_level(dn,
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1425 flags, offset, lvl, blkfill, txg);
1793
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1426 if (error != ESRCH)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1427 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1428 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1429
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1430 while (error == 0 && --lvl >= minlvl) {
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1431 error = dnode_next_offset_level(dn,
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1432 flags, offset, lvl, blkfill, txg);
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1433 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1434
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1435 if (error == 0 && (flags & DNODE_FIND_BACKWARDS ?
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1436 initial_offset < *offset : initial_offset > *offset))
1793
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1437 error = ESRCH;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1438 out:
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1439 if (!(flags & DNODE_FIND_HAVELOCK))
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1440 rw_exit(&dn->dn_struct_rwlock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1441
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1442 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1443 }