annotate usr/src/uts/common/fs/zfs/dnode.c @ 11958:575ffe1e978d

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