annotate usr/src/uts/common/fs/zfs/dnode.c @ 12178:93ec1371f750

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