Mercurial > illumos > illumos-gate
annotate usr/src/uts/common/fs/zfs/dnode.c @ 12684:397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
6583724 dnode_create should not call kmem_cache_constructor directly
6374545 disk write cache flush code overloads buf_t.b_list pointer
author | Tom Erickson <Tom.Erickson@Sun.COM> |
---|---|
date | Thu, 24 Jun 2010 11:35:31 -0700 |
parents | b118bbd65be9 |
children | 2889e2596bd6 |
rev | line source |
---|---|
789 | 1 /* |
2 * CDDL HEADER START | |
3 * | |
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 | 7 * |
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 * or http://www.opensolaris.org/os/licensing. | |
10 * See the License for the specific language governing permissions | |
11 * and limitations under the License. | |
12 * | |
13 * When distributing Covered Code, include this CDDL HEADER in each | |
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 * If applicable, add the following below this CDDL HEADER, with the | |
16 * fields enclosed by brackets "[]" replaced with your own identifying | |
17 * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 * | |
19 * CDDL HEADER END | |
20 */ | |
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 | 23 */ |
24 | |
25 #include <sys/zfs_context.h> | |
26 #include <sys/dbuf.h> | |
27 #include <sys/dnode.h> | |
28 #include <sys/dmu.h> | |
29 #include <sys/dmu_impl.h> | |
30 #include <sys/dmu_tx.h> | |
31 #include <sys/dmu_objset.h> | |
32 #include <sys/dsl_dir.h> | |
33 #include <sys/dsl_dataset.h> | |
34 #include <sys/spa.h> | |
35 #include <sys/zio.h> | |
36 #include <sys/dmu_zfetch.h> | |
37 | |
38 static int free_range_compar(const void *node1, const void *node2); | |
39 | |
40 static kmem_cache_t *dnode_cache; | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
41 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
42 * Define DNODE_STATS to turn on statistic gathering. By default, it is only |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
43 * turned on when DEBUG is also defined. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
44 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
45 #ifdef DEBUG |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
46 #define DNODE_STATS |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
47 #endif /* DEBUG */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
48 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
49 #ifdef DNODE_STATS |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
50 #define DNODE_STAT_ADD(stat) ((stat)++) |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
51 #else |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
52 #define DNODE_STAT_ADD(stat) /* nothing */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
53 #endif /* DNODE_STATS */ |
789 | 54 |
55 static dnode_phys_t dnode_phys_zero; | |
56 | |
57 int zfs_default_bs = SPA_MINBLOCKSHIFT; | |
58 int zfs_default_ibs = DN_MAX_INDBLKSHIFT; | |
59 | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
60 static kmem_cbrc_t dnode_move(void *, void *, size_t, void *); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
61 |
789 | 62 /* ARGSUSED */ |
63 static int | |
64 dnode_cons(void *arg, void *unused, int kmflag) | |
65 { | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
66 dnode_t *dn = arg; |
789 | 67 int i; |
68 | |
69 rw_init(&dn->dn_struct_rwlock, NULL, RW_DEFAULT, NULL); | |
70 mutex_init(&dn->dn_mtx, NULL, MUTEX_DEFAULT, NULL); | |
71 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
|
72 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
|
73 |
789 | 74 refcount_create(&dn->dn_holds); |
75 refcount_create(&dn->dn_tx_holds); | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
76 list_link_init(&dn->dn_link); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
77 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
78 bzero(&dn->dn_next_nblkptr[0], sizeof (dn->dn_next_nblkptr)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
79 bzero(&dn->dn_next_nlevels[0], sizeof (dn->dn_next_nlevels)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
80 bzero(&dn->dn_next_indblkshift[0], sizeof (dn->dn_next_indblkshift)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
81 bzero(&dn->dn_next_bonustype[0], sizeof (dn->dn_next_bonustype)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
82 bzero(&dn->dn_rm_spillblk[0], sizeof (dn->dn_rm_spillblk)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
83 bzero(&dn->dn_next_bonuslen[0], sizeof (dn->dn_next_bonuslen)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
84 bzero(&dn->dn_next_blksz[0], sizeof (dn->dn_next_blksz)); |
789 | 85 |
86 for (i = 0; i < TXG_SIZE; i++) { | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
87 list_link_init(&dn->dn_dirty_link[i]); |
789 | 88 avl_create(&dn->dn_ranges[i], free_range_compar, |
89 sizeof (free_range_t), | |
90 offsetof(struct free_range, fr_node)); | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
91 list_create(&dn->dn_dirty_records[i], |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
92 sizeof (dbuf_dirty_record_t), |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
93 offsetof(dbuf_dirty_record_t, dr_dirty_node)); |
789 | 94 } |
95 | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
96 dn->dn_allocated_txg = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
97 dn->dn_free_txg = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
98 dn->dn_assigned_txg = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
99 dn->dn_dirtyctx = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
100 dn->dn_dirtyctx_firstset = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
101 dn->dn_bonus = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
102 dn->dn_have_spill = B_FALSE; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
103 dn->dn_zio = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
104 dn->dn_oldused = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
105 dn->dn_oldflags = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
106 dn->dn_olduid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
107 dn->dn_oldgid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
108 dn->dn_newuid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
109 dn->dn_newgid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
110 dn->dn_id_flags = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
111 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
112 dn->dn_dbufs_count = 0; |
789 | 113 list_create(&dn->dn_dbufs, sizeof (dmu_buf_impl_t), |
114 offsetof(dmu_buf_impl_t, db_link)); | |
115 | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
116 dn->dn_moved = 0; |
789 | 117 return (0); |
118 } | |
119 | |
120 /* ARGSUSED */ | |
121 static void | |
122 dnode_dest(void *arg, void *unused) | |
123 { | |
124 int i; | |
125 dnode_t *dn = arg; | |
126 | |
127 rw_destroy(&dn->dn_struct_rwlock); | |
128 mutex_destroy(&dn->dn_mtx); | |
129 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
|
130 cv_destroy(&dn->dn_notxholds); |
789 | 131 refcount_destroy(&dn->dn_holds); |
132 refcount_destroy(&dn->dn_tx_holds); | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
133 ASSERT(!list_link_active(&dn->dn_link)); |
789 | 134 |
135 for (i = 0; i < TXG_SIZE; i++) { | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
136 ASSERT(!list_link_active(&dn->dn_dirty_link[i])); |
789 | 137 avl_destroy(&dn->dn_ranges[i]); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
138 list_destroy(&dn->dn_dirty_records[i]); |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
139 ASSERT3U(dn->dn_next_nblkptr[i], ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
140 ASSERT3U(dn->dn_next_nlevels[i], ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
141 ASSERT3U(dn->dn_next_indblkshift[i], ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
142 ASSERT3U(dn->dn_next_bonustype[i], ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
143 ASSERT3U(dn->dn_rm_spillblk[i], ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
144 ASSERT3U(dn->dn_next_bonuslen[i], ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
145 ASSERT3U(dn->dn_next_blksz[i], ==, 0); |
789 | 146 } |
147 | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
148 ASSERT3U(dn->dn_allocated_txg, ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
149 ASSERT3U(dn->dn_free_txg, ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
150 ASSERT3U(dn->dn_assigned_txg, ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
151 ASSERT3U(dn->dn_dirtyctx, ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
152 ASSERT3P(dn->dn_dirtyctx_firstset, ==, NULL); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
153 ASSERT3P(dn->dn_bonus, ==, NULL); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
154 ASSERT(!dn->dn_have_spill); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
155 ASSERT3P(dn->dn_zio, ==, NULL); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
156 ASSERT3U(dn->dn_oldused, ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
157 ASSERT3U(dn->dn_oldflags, ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
158 ASSERT3U(dn->dn_olduid, ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
159 ASSERT3U(dn->dn_oldgid, ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
160 ASSERT3U(dn->dn_newuid, ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
161 ASSERT3U(dn->dn_newgid, ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
162 ASSERT3U(dn->dn_id_flags, ==, 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
163 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
164 ASSERT3U(dn->dn_dbufs_count, ==, 0); |
789 | 165 list_destroy(&dn->dn_dbufs); |
166 } | |
167 | |
168 void | |
169 dnode_init(void) | |
170 { | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
171 ASSERT(dnode_cache == NULL); |
789 | 172 dnode_cache = kmem_cache_create("dnode_t", |
173 sizeof (dnode_t), | |
174 0, dnode_cons, dnode_dest, NULL, NULL, NULL, 0); | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
175 kmem_cache_set_move(dnode_cache, dnode_move); |
789 | 176 } |
177 | |
178 void | |
179 dnode_fini(void) | |
180 { | |
181 kmem_cache_destroy(dnode_cache); | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
182 dnode_cache = NULL; |
789 | 183 } |
184 | |
185 | |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
186 #ifdef ZFS_DEBUG |
789 | 187 void |
188 dnode_verify(dnode_t *dn) | |
189 { | |
190 int drop_struct_lock = FALSE; | |
191 | |
192 ASSERT(dn->dn_phys); | |
193 ASSERT(dn->dn_objset); | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
194 ASSERT(dn->dn_handle->dnh_dnode == dn); |
789 | 195 |
196 ASSERT(dn->dn_phys->dn_type < DMU_OT_NUMTYPES); | |
197 | |
198 if (!(zfs_flags & ZFS_DEBUG_DNODE_VERIFY)) | |
199 return; | |
200 | |
201 if (!RW_WRITE_HELD(&dn->dn_struct_rwlock)) { | |
202 rw_enter(&dn->dn_struct_rwlock, RW_READER); | |
203 drop_struct_lock = TRUE; | |
204 } | |
205 if (dn->dn_phys->dn_type != DMU_OT_NONE || dn->dn_allocated_txg != 0) { | |
206 int i; | |
207 ASSERT3U(dn->dn_indblkshift, >=, 0); | |
208 ASSERT3U(dn->dn_indblkshift, <=, SPA_MAXBLOCKSHIFT); | |
209 if (dn->dn_datablkshift) { | |
210 ASSERT3U(dn->dn_datablkshift, >=, SPA_MINBLOCKSHIFT); | |
211 ASSERT3U(dn->dn_datablkshift, <=, SPA_MAXBLOCKSHIFT); | |
212 ASSERT3U(1<<dn->dn_datablkshift, ==, dn->dn_datablksz); | |
213 } | |
214 ASSERT3U(dn->dn_nlevels, <=, 30); | |
215 ASSERT3U(dn->dn_type, <=, DMU_OT_NUMTYPES); | |
216 ASSERT3U(dn->dn_nblkptr, >=, 1); | |
217 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR); | |
218 ASSERT3U(dn->dn_bonuslen, <=, DN_MAX_BONUSLEN); | |
219 ASSERT3U(dn->dn_datablksz, ==, | |
220 dn->dn_datablkszsec << SPA_MINBLOCKSHIFT); | |
221 ASSERT3U(ISP2(dn->dn_datablksz), ==, dn->dn_datablkshift != 0); | |
222 ASSERT3U((dn->dn_nblkptr - 1) * sizeof (blkptr_t) + | |
223 dn->dn_bonuslen, <=, DN_MAX_BONUSLEN); | |
224 for (i = 0; i < TXG_SIZE; i++) { | |
225 ASSERT3U(dn->dn_next_nlevels[i], <=, dn->dn_nlevels); | |
226 } | |
227 } | |
228 if (dn->dn_phys->dn_type != DMU_OT_NONE) | |
229 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
|
230 ASSERT(DMU_OBJECT_IS_SPECIAL(dn->dn_object) || dn->dn_dbuf != NULL); |
789 | 231 if (dn->dn_dbuf != NULL) { |
232 ASSERT3P(dn->dn_phys, ==, | |
233 (dnode_phys_t *)dn->dn_dbuf->db.db_data + | |
234 (dn->dn_object % (dn->dn_dbuf->db.db_size >> DNODE_SHIFT))); | |
235 } | |
236 if (drop_struct_lock) | |
237 rw_exit(&dn->dn_struct_rwlock); | |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
238 } |
789 | 239 #endif |
240 | |
241 void | |
242 dnode_byteswap(dnode_phys_t *dnp) | |
243 { | |
244 uint64_t *buf64 = (void*)&dnp->dn_blkptr; | |
245 int i; | |
246 | |
247 if (dnp->dn_type == DMU_OT_NONE) { | |
248 bzero(dnp, sizeof (dnode_phys_t)); | |
249 return; | |
250 } | |
251 | |
252 dnp->dn_datablkszsec = BSWAP_16(dnp->dn_datablkszsec); | |
253 dnp->dn_bonuslen = BSWAP_16(dnp->dn_bonuslen); | |
254 dnp->dn_maxblkid = BSWAP_64(dnp->dn_maxblkid); | |
2082 | 255 dnp->dn_used = BSWAP_64(dnp->dn_used); |
789 | 256 |
257 /* | |
258 * dn_nblkptr is only one byte, so it's OK to read it in either | |
259 * byte order. We can't read dn_bouslen. | |
260 */ | |
261 ASSERT(dnp->dn_indblkshift <= SPA_MAXBLOCKSHIFT); | |
262 ASSERT(dnp->dn_nblkptr <= DN_MAX_NBLKPTR); | |
263 for (i = 0; i < dnp->dn_nblkptr * sizeof (blkptr_t)/8; i++) | |
264 buf64[i] = BSWAP_64(buf64[i]); | |
265 | |
266 /* | |
267 * OK to check dn_bonuslen for zero, because it won't matter if | |
268 * we have the wrong byte order. This is necessary because the | |
269 * dnode dnode is smaller than a regular dnode. | |
270 */ | |
271 if (dnp->dn_bonuslen != 0) { | |
272 /* | |
273 * Note that the bonus length calculated here may be | |
274 * longer than the actual bonus buffer. This is because | |
275 * we always put the bonus buffer after the last block | |
276 * pointer (instead of packing it against the end of the | |
277 * dnode buffer). | |
278 */ | |
279 int off = (dnp->dn_nblkptr-1) * sizeof (blkptr_t); | |
280 size_t len = DN_MAX_BONUSLEN - off; | |
3882 | 281 ASSERT3U(dnp->dn_bonustype, <, DMU_OT_NUMTYPES); |
789 | 282 dmu_ot[dnp->dn_bonustype].ot_byteswap(dnp->dn_bonus + off, len); |
283 } | |
11935
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 /* 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
|
286 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
|
287 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
|
288 |
789 | 289 } |
290 | |
291 void | |
292 dnode_buf_byteswap(void *vbuf, size_t size) | |
293 { | |
294 dnode_phys_t *buf = vbuf; | |
295 int i; | |
296 | |
297 ASSERT3U(sizeof (dnode_phys_t), ==, (1<<DNODE_SHIFT)); | |
298 ASSERT((size & (sizeof (dnode_phys_t)-1)) == 0); | |
299 | |
300 size >>= DNODE_SHIFT; | |
301 for (i = 0; i < size; i++) { | |
302 dnode_byteswap(buf); | |
303 buf++; | |
304 } | |
305 } | |
306 | |
307 static int | |
308 free_range_compar(const void *node1, const void *node2) | |
309 { | |
310 const free_range_t *rp1 = node1; | |
311 const free_range_t *rp2 = node2; | |
312 | |
313 if (rp1->fr_blkid < rp2->fr_blkid) | |
314 return (-1); | |
315 else if (rp1->fr_blkid > rp2->fr_blkid) | |
316 return (1); | |
317 else return (0); | |
318 } | |
319 | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
320 void |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
321 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
|
322 { |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
323 ASSERT3U(refcount_count(&dn->dn_holds), >=, 1); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
324 |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
325 dnode_setdirty(dn, tx); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
326 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
327 ASSERT3U(newsize, <=, DN_MAX_BONUSLEN - |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
328 (dn->dn_nblkptr-1) * sizeof (blkptr_t)); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
329 dn->dn_bonuslen = newsize; |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
330 if (newsize == 0) |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
331 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
|
332 else |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
333 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
|
334 rw_exit(&dn->dn_struct_rwlock); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
335 } |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
336 |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
337 void |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
338 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
|
339 { |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
340 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
|
341 dnode_setdirty(dn, tx); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
342 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
|
343 dn->dn_bonustype = newtype; |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
344 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
|
345 rw_exit(&dn->dn_struct_rwlock); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
346 } |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
347 |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
348 void |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
349 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
|
350 { |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
351 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
|
352 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
|
353 dnode_setdirty(dn, tx); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
354 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
|
355 dn->dn_have_spill = B_FALSE; |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
356 } |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
357 |
789 | 358 static void |
359 dnode_setdblksz(dnode_t *dn, int size) | |
360 { | |
361 ASSERT3U(P2PHASE(size, SPA_MINBLOCKSIZE), ==, 0); | |
362 ASSERT3U(size, <=, SPA_MAXBLOCKSIZE); | |
363 ASSERT3U(size, >=, SPA_MINBLOCKSIZE); | |
364 ASSERT3U(size >> SPA_MINBLOCKSHIFT, <, | |
365 1<<(sizeof (dn->dn_phys->dn_datablkszsec) * 8)); | |
366 dn->dn_datablksz = size; | |
367 dn->dn_datablkszsec = size >> SPA_MINBLOCKSHIFT; | |
368 dn->dn_datablkshift = ISP2(size) ? highbit(size - 1) : 0; | |
369 } | |
370 | |
371 static dnode_t * | |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9950
diff
changeset
|
372 dnode_create(objset_t *os, dnode_phys_t *dnp, dmu_buf_impl_t *db, |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
373 uint64_t object, dnode_handle_t *dnh) |
789 | 374 { |
375 dnode_t *dn = kmem_cache_alloc(dnode_cache, KM_SLEEP); | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
376 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
377 ASSERT(!POINTER_IS_VALID(dn->dn_objset)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
378 dn->dn_moved = 0; |
789 | 379 |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
380 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
381 * Defer setting dn_objset until the dnode is ready to be a candidate |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
382 * for the dnode_move() callback. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
383 */ |
789 | 384 dn->dn_object = object; |
385 dn->dn_dbuf = db; | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
386 dn->dn_handle = dnh; |
789 | 387 dn->dn_phys = dnp; |
388 | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
389 if (dnp->dn_datablkszsec) { |
789 | 390 dnode_setdblksz(dn, dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT); |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
391 } else { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
392 dn->dn_datablksz = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
393 dn->dn_datablkszsec = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
394 dn->dn_datablkshift = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
395 } |
789 | 396 dn->dn_indblkshift = dnp->dn_indblkshift; |
397 dn->dn_nlevels = dnp->dn_nlevels; | |
398 dn->dn_type = dnp->dn_type; | |
399 dn->dn_nblkptr = dnp->dn_nblkptr; | |
400 dn->dn_checksum = dnp->dn_checksum; | |
401 dn->dn_compress = dnp->dn_compress; | |
402 dn->dn_bonustype = dnp->dn_bonustype; | |
403 dn->dn_bonuslen = dnp->dn_bonuslen; | |
404 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
|
405 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
|
406 dn->dn_id_flags = 0; |
789 | 407 |
408 dmu_zfetch_init(&dn->dn_zfetch, dn); | |
409 | |
410 ASSERT(dn->dn_phys->dn_type < DMU_OT_NUMTYPES); | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
411 |
789 | 412 mutex_enter(&os->os_lock); |
413 list_insert_head(&os->os_dnodes, dn); | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
414 membar_producer(); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
415 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
416 * Everything else must be valid before assigning dn_objset makes the |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
417 * dnode eligible for dnode_move(). |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
418 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
419 dn->dn_objset = os; |
789 | 420 mutex_exit(&os->os_lock); |
421 | |
8582
df9361868dbe
6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents:
8214
diff
changeset
|
422 arc_space_consume(sizeof (dnode_t), ARC_SPACE_OTHER); |
789 | 423 return (dn); |
424 } | |
425 | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
426 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
427 * Caller must be holding the dnode handle, which is released upon return. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
428 */ |
789 | 429 static void |
430 dnode_destroy(dnode_t *dn) | |
431 { | |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9950
diff
changeset
|
432 objset_t *os = dn->dn_objset; |
789 | 433 |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
434 ASSERT((dn->dn_id_flags & DN_ID_NEW_EXIST) == 0); |
2885 | 435 |
789 | 436 mutex_enter(&os->os_lock); |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
437 POINTER_INVALIDATE(&dn->dn_objset); |
789 | 438 list_remove(&os->os_dnodes, dn); |
439 mutex_exit(&os->os_lock); | |
440 | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
441 /* the dnode can no longer move, so we can release the handle */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
442 zrl_remove(&dn->dn_handle->dnh_zrlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
443 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
444 dn->dn_allocated_txg = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
445 dn->dn_free_txg = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
446 dn->dn_assigned_txg = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
447 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
448 dn->dn_dirtyctx = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
449 if (dn->dn_dirtyctx_firstset != NULL) { |
789 | 450 kmem_free(dn->dn_dirtyctx_firstset, 1); |
451 dn->dn_dirtyctx_firstset = NULL; | |
452 } | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
453 if (dn->dn_bonus != NULL) { |
1544 | 454 mutex_enter(&dn->dn_bonus->db_mtx); |
455 dbuf_evict(dn->dn_bonus); | |
456 dn->dn_bonus = NULL; | |
457 } | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
458 dn->dn_zio = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
459 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
460 dn->dn_have_spill = B_FALSE; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
461 dn->dn_oldused = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
462 dn->dn_oldflags = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
463 dn->dn_olduid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
464 dn->dn_oldgid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
465 dn->dn_newuid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
466 dn->dn_newgid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
467 dn->dn_id_flags = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
468 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
469 dmu_zfetch_rele(&dn->dn_zfetch); |
789 | 470 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
|
471 arc_space_return(sizeof (dnode_t), ARC_SPACE_OTHER); |
789 | 472 } |
473 | |
474 void | |
475 dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs, | |
1599 | 476 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx) |
789 | 477 { |
478 int i; | |
479 | |
480 if (blocksize == 0) | |
481 blocksize = 1 << zfs_default_bs; | |
1402 | 482 else if (blocksize > SPA_MAXBLOCKSIZE) |
483 blocksize = SPA_MAXBLOCKSIZE; | |
484 else | |
485 blocksize = P2ROUNDUP(blocksize, SPA_MINBLOCKSIZE); | |
789 | 486 |
487 if (ibs == 0) | |
488 ibs = zfs_default_ibs; | |
489 | |
490 ibs = MIN(MAX(ibs, DN_MIN_INDBLKSHIFT), DN_MAX_INDBLKSHIFT); | |
491 | |
492 dprintf("os=%p obj=%llu txg=%llu blocksize=%d ibs=%d\n", dn->dn_objset, | |
493 dn->dn_object, tx->tx_txg, blocksize, ibs); | |
494 | |
495 ASSERT(dn->dn_type == DMU_OT_NONE); | |
496 ASSERT(bcmp(dn->dn_phys, &dnode_phys_zero, sizeof (dnode_phys_t)) == 0); | |
497 ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE); | |
498 ASSERT(ot != DMU_OT_NONE); | |
499 ASSERT3U(ot, <, DMU_OT_NUMTYPES); | |
500 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
|
501 (bonustype == DMU_OT_SA && bonuslen == 0) || |
789 | 502 (bonustype != DMU_OT_NONE && bonuslen != 0)); |
503 ASSERT3U(bonustype, <, DMU_OT_NUMTYPES); | |
504 ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN); | |
505 ASSERT(dn->dn_type == DMU_OT_NONE); | |
506 ASSERT3U(dn->dn_maxblkid, ==, 0); | |
507 ASSERT3U(dn->dn_allocated_txg, ==, 0); | |
508 ASSERT3U(dn->dn_assigned_txg, ==, 0); | |
509 ASSERT(refcount_is_zero(&dn->dn_tx_holds)); | |
510 ASSERT3U(refcount_count(&dn->dn_holds), <=, 1); | |
511 ASSERT3P(list_head(&dn->dn_dbufs), ==, NULL); | |
512 | |
513 for (i = 0; i < TXG_SIZE; i++) { | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
514 ASSERT3U(dn->dn_next_nblkptr[i], ==, 0); |
789 | 515 ASSERT3U(dn->dn_next_nlevels[i], ==, 0); |
516 ASSERT3U(dn->dn_next_indblkshift[i], ==, 0); | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
517 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
|
518 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
|
519 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
|
520 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
|
521 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
|
522 ASSERT3P(list_head(&dn->dn_dirty_records[i]), ==, NULL); |
789 | 523 ASSERT3U(avl_numnodes(&dn->dn_ranges[i]), ==, 0); |
524 } | |
525 | |
526 dn->dn_type = ot; | |
527 dnode_setdblksz(dn, blocksize); | |
528 dn->dn_indblkshift = ibs; | |
529 dn->dn_nlevels = 1; | |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
530 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
|
531 dn->dn_nblkptr = 1; |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
532 else |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
533 dn->dn_nblkptr = 1 + |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
534 ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT); |
789 | 535 dn->dn_bonustype = bonustype; |
536 dn->dn_bonuslen = bonuslen; | |
537 dn->dn_checksum = ZIO_CHECKSUM_INHERIT; | |
538 dn->dn_compress = ZIO_COMPRESS_INHERIT; | |
539 dn->dn_dirtyctx = 0; | |
540 | |
541 dn->dn_free_txg = 0; | |
542 if (dn->dn_dirtyctx_firstset) { | |
543 kmem_free(dn->dn_dirtyctx_firstset, 1); | |
544 dn->dn_dirtyctx_firstset = NULL; | |
545 } | |
546 | |
547 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
|
548 dn->dn_id_flags = 0; |
1599 | 549 |
789 | 550 dnode_setdirty(dn, tx); |
1599 | 551 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
|
552 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
|
553 dn->dn_next_bonustype[tx->tx_txg & TXG_MASK] = dn->dn_bonustype; |
1599 | 554 dn->dn_next_blksz[tx->tx_txg & TXG_MASK] = dn->dn_datablksz; |
789 | 555 } |
556 | |
557 void | |
558 dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, | |
559 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx) | |
560 { | |
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
561 int nblkptr; |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
562 |
789 | 563 ASSERT3U(blocksize, >=, SPA_MINBLOCKSIZE); |
564 ASSERT3U(blocksize, <=, SPA_MAXBLOCKSIZE); | |
565 ASSERT3U(blocksize % SPA_MINBLOCKSIZE, ==, 0); | |
1544 | 566 ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT || dmu_tx_private_ok(tx)); |
789 | 567 ASSERT(tx->tx_txg != 0); |
568 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
|
569 (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
|
570 (bonustype == DMU_OT_SA && bonuslen == 0)); |
789 | 571 ASSERT3U(bonustype, <, DMU_OT_NUMTYPES); |
572 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
|
573 |
1544 | 574 /* clean up any unreferenced dbufs */ |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
575 dnode_evict_dbufs(dn); |
1544 | 576 |
12432
222dd376dd6c
6952522 elpaso panics: assertion failed: refcount_is_zero(&dn->dn_holds), file: ../../common/fs/zfs/dnode.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
12411
diff
changeset
|
577 dn->dn_id_flags = 0; |
222dd376dd6c
6952522 elpaso panics: assertion failed: refcount_is_zero(&dn->dn_holds), file: ../../common/fs/zfs/dnode.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
12411
diff
changeset
|
578 |
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
579 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
|
580 dnode_setdirty(dn, tx); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
581 if (dn->dn_datablksz != blocksize) { |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
582 /* change blocksize */ |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
583 ASSERT(dn->dn_maxblkid == 0 && |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
584 (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
|
585 dnode_block_freed(dn, 0))); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
586 dnode_setdblksz(dn, blocksize); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
587 dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = blocksize; |
789 | 588 } |
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
589 if (dn->dn_bonuslen != bonuslen) |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
590 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
|
591 |
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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 if (dn->dn_bonustype != bonustype) |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 dnode_rm_spill(dn, tx); |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
603 } |
789 | 604 rw_exit(&dn->dn_struct_rwlock); |
605 | |
606 /* change type */ | |
607 dn->dn_type = ot; | |
608 | |
609 /* change bonus size and type */ | |
610 mutex_enter(&dn->dn_mtx); | |
611 dn->dn_bonustype = bonustype; | |
612 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
|
613 dn->dn_nblkptr = nblkptr; |
789 | 614 dn->dn_checksum = ZIO_CHECKSUM_INHERIT; |
615 dn->dn_compress = ZIO_COMPRESS_INHERIT; | |
616 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR); | |
617 | |
8644
10534c530688
6793373 assertion failed in dnode_reallocate: dn_nblkptr >= old_nblkptr
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8582
diff
changeset
|
618 /* 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
|
619 if (dn->dn_bonus) { |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
620 dn->dn_bonus->db.db_size = |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
621 DN_MAX_BONUSLEN - (dn->dn_nblkptr-1) * sizeof (blkptr_t); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
622 ASSERT(dn->dn_bonuslen <= dn->dn_bonus->db.db_size); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
623 } |
3087 | 624 |
789 | 625 dn->dn_allocated_txg = tx->tx_txg; |
626 mutex_exit(&dn->dn_mtx); | |
627 } | |
628 | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
629 #ifdef DNODE_STATS |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
630 static struct { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
631 uint64_t dms_dnode_invalid; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
632 uint64_t dms_dnode_recheck1; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
633 uint64_t dms_dnode_recheck2; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
634 uint64_t dms_dnode_special; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
635 uint64_t dms_dnode_handle; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
636 uint64_t dms_dnode_rwlock; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
637 uint64_t dms_dnode_active; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
638 } dnode_move_stats; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
639 #endif /* DNODE_STATS */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
640 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
641 static void |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
642 dnode_move_impl(dnode_t *odn, dnode_t *ndn) |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
643 { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
644 int i; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
645 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
646 ASSERT(!RW_LOCK_HELD(&odn->dn_struct_rwlock)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
647 ASSERT(MUTEX_NOT_HELD(&odn->dn_mtx)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
648 ASSERT(MUTEX_NOT_HELD(&odn->dn_dbufs_mtx)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
649 ASSERT(!RW_LOCK_HELD(&odn->dn_zfetch.zf_rwlock)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
650 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
651 /* Copy fields. */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
652 ndn->dn_objset = odn->dn_objset; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
653 ndn->dn_object = odn->dn_object; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
654 ndn->dn_dbuf = odn->dn_dbuf; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
655 ndn->dn_handle = odn->dn_handle; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
656 ndn->dn_phys = odn->dn_phys; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
657 ndn->dn_type = odn->dn_type; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
658 ndn->dn_bonuslen = odn->dn_bonuslen; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
659 ndn->dn_bonustype = odn->dn_bonustype; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
660 ndn->dn_nblkptr = odn->dn_nblkptr; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
661 ndn->dn_checksum = odn->dn_checksum; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
662 ndn->dn_compress = odn->dn_compress; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
663 ndn->dn_nlevels = odn->dn_nlevels; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
664 ndn->dn_indblkshift = odn->dn_indblkshift; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
665 ndn->dn_datablkshift = odn->dn_datablkshift; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
666 ndn->dn_datablkszsec = odn->dn_datablkszsec; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
667 ndn->dn_datablksz = odn->dn_datablksz; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
668 ndn->dn_maxblkid = odn->dn_maxblkid; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
669 bcopy(&odn->dn_next_nblkptr[0], &ndn->dn_next_nblkptr[0], |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
670 sizeof (odn->dn_next_nblkptr)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
671 bcopy(&odn->dn_next_nlevels[0], &ndn->dn_next_nlevels[0], |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
672 sizeof (odn->dn_next_nlevels)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
673 bcopy(&odn->dn_next_indblkshift[0], &ndn->dn_next_indblkshift[0], |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
674 sizeof (odn->dn_next_indblkshift)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
675 bcopy(&odn->dn_next_bonustype[0], &ndn->dn_next_bonustype[0], |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
676 sizeof (odn->dn_next_bonustype)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
677 bcopy(&odn->dn_rm_spillblk[0], &ndn->dn_rm_spillblk[0], |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
678 sizeof (odn->dn_rm_spillblk)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
679 bcopy(&odn->dn_next_bonuslen[0], &ndn->dn_next_bonuslen[0], |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
680 sizeof (odn->dn_next_bonuslen)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
681 bcopy(&odn->dn_next_blksz[0], &ndn->dn_next_blksz[0], |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
682 sizeof (odn->dn_next_blksz)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
683 for (i = 0; i < TXG_SIZE; i++) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
684 list_move_tail(&ndn->dn_dirty_records[i], |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
685 &odn->dn_dirty_records[i]); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
686 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
687 bcopy(&odn->dn_ranges[0], &ndn->dn_ranges[0], sizeof (odn->dn_ranges)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
688 ndn->dn_allocated_txg = odn->dn_allocated_txg; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
689 ndn->dn_free_txg = odn->dn_free_txg; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
690 ndn->dn_assigned_txg = odn->dn_assigned_txg; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
691 ndn->dn_dirtyctx = odn->dn_dirtyctx; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
692 ndn->dn_dirtyctx_firstset = odn->dn_dirtyctx_firstset; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
693 ASSERT(refcount_count(&odn->dn_tx_holds) == 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
694 refcount_transfer(&ndn->dn_holds, &odn->dn_holds); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
695 ASSERT(list_is_empty(&ndn->dn_dbufs)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
696 list_move_tail(&ndn->dn_dbufs, &odn->dn_dbufs); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
697 ndn->dn_dbufs_count = odn->dn_dbufs_count; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
698 ndn->dn_bonus = odn->dn_bonus; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
699 ndn->dn_have_spill = odn->dn_have_spill; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
700 ndn->dn_zio = odn->dn_zio; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
701 ndn->dn_oldused = odn->dn_oldused; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
702 ndn->dn_oldflags = odn->dn_oldflags; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
703 ndn->dn_olduid = odn->dn_olduid; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
704 ndn->dn_oldgid = odn->dn_oldgid; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
705 ndn->dn_newuid = odn->dn_newuid; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
706 ndn->dn_newgid = odn->dn_newgid; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
707 ndn->dn_id_flags = odn->dn_id_flags; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
708 dmu_zfetch_init(&ndn->dn_zfetch, NULL); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
709 list_move_tail(&ndn->dn_zfetch.zf_stream, &odn->dn_zfetch.zf_stream); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
710 ndn->dn_zfetch.zf_dnode = odn->dn_zfetch.zf_dnode; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
711 ndn->dn_zfetch.zf_stream_cnt = odn->dn_zfetch.zf_stream_cnt; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
712 ndn->dn_zfetch.zf_alloc_fail = odn->dn_zfetch.zf_alloc_fail; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
713 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
714 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
715 * Update back pointers. Updating the handle fixes the back pointer of |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
716 * every descendant dbuf as well as the bonus dbuf. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
717 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
718 ASSERT(ndn->dn_handle->dnh_dnode == odn); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
719 ndn->dn_handle->dnh_dnode = ndn; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
720 if (ndn->dn_zfetch.zf_dnode == odn) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
721 ndn->dn_zfetch.zf_dnode = ndn; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
722 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
723 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
724 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
725 * Invalidate the original dnode by clearing all of its back pointers. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
726 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
727 odn->dn_dbuf = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
728 odn->dn_handle = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
729 list_create(&odn->dn_dbufs, sizeof (dmu_buf_impl_t), |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
730 offsetof(dmu_buf_impl_t, db_link)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
731 odn->dn_dbufs_count = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
732 odn->dn_bonus = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
733 odn->dn_zfetch.zf_dnode = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
734 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
735 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
736 * Set the low bit of the objset pointer to ensure that dnode_move() |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
737 * recognizes the dnode as invalid in any subsequent callback. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
738 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
739 POINTER_INVALIDATE(&odn->dn_objset); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
740 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
741 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
742 * Satisfy the destructor. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
743 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
744 for (i = 0; i < TXG_SIZE; i++) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
745 list_create(&odn->dn_dirty_records[i], |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
746 sizeof (dbuf_dirty_record_t), |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
747 offsetof(dbuf_dirty_record_t, dr_dirty_node)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
748 odn->dn_ranges[i].avl_root = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
749 odn->dn_ranges[i].avl_numnodes = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
750 odn->dn_next_nlevels[i] = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
751 odn->dn_next_indblkshift[i] = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
752 odn->dn_next_bonustype[i] = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
753 odn->dn_rm_spillblk[i] = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
754 odn->dn_next_bonuslen[i] = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
755 odn->dn_next_blksz[i] = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
756 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
757 odn->dn_allocated_txg = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
758 odn->dn_free_txg = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
759 odn->dn_assigned_txg = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
760 odn->dn_dirtyctx = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
761 odn->dn_dirtyctx_firstset = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
762 odn->dn_have_spill = B_FALSE; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
763 odn->dn_zio = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
764 odn->dn_oldused = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
765 odn->dn_oldflags = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
766 odn->dn_olduid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
767 odn->dn_oldgid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
768 odn->dn_newuid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
769 odn->dn_newgid = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
770 odn->dn_id_flags = 0; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
771 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
772 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
773 * Mark the dnode. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
774 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
775 ndn->dn_moved = 1; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
776 odn->dn_moved = (uint8_t)-1; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
777 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
778 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
779 #ifdef _KERNEL |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
780 /*ARGSUSED*/ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
781 static kmem_cbrc_t |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
782 dnode_move(void *buf, void *newbuf, size_t size, void *arg) |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
783 { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
784 dnode_t *odn = buf, *ndn = newbuf; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
785 objset_t *os; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
786 int64_t refcount; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
787 uint32_t dbufs; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
788 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
789 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
790 * The dnode is on the objset's list of known dnodes if the objset |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
791 * pointer is valid. We set the low bit of the objset pointer when |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
792 * freeing the dnode to invalidate it, and the memory patterns written |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
793 * by kmem (baddcafe and deadbeef) set at least one of the two low bits. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
794 * A newly created dnode sets the objset pointer last of all to indicate |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
795 * that the dnode is known and in a valid state to be moved by this |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
796 * function. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
797 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
798 os = odn->dn_objset; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
799 if (!POINTER_IS_VALID(os)) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
800 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_invalid); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
801 return (KMEM_CBRC_DONT_KNOW); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
802 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
803 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
804 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
805 * Ensure that the objset does not go away during the move. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
806 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
807 rw_enter(&os_lock, RW_WRITER); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
808 if (os != odn->dn_objset) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
809 rw_exit(&os_lock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
810 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_recheck1); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
811 return (KMEM_CBRC_DONT_KNOW); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
812 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
813 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
814 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
815 * If the dnode is still valid, then so is the objset. We know that no |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
816 * valid objset can be freed while we hold os_lock, so we can safely |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
817 * ensure that the objset remains in use. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
818 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
819 mutex_enter(&os->os_lock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
820 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
821 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
822 * Recheck the objset pointer in case the dnode was removed just before |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
823 * acquiring the lock. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
824 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
825 if (os != odn->dn_objset) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
826 mutex_exit(&os->os_lock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
827 rw_exit(&os_lock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
828 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_recheck2); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
829 return (KMEM_CBRC_DONT_KNOW); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
830 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
831 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
832 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
833 * At this point we know that as long as we hold os->os_lock, the dnode |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
834 * cannot be freed and fields within the dnode can be safely accessed. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
835 * The objset listing this dnode cannot go away as long as this dnode is |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
836 * on its list. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
837 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
838 rw_exit(&os_lock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
839 if (DMU_OBJECT_IS_SPECIAL(odn->dn_object)) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
840 mutex_exit(&os->os_lock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
841 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_special); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
842 return (KMEM_CBRC_NO); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
843 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
844 ASSERT(odn->dn_dbuf != NULL); /* only "special" dnodes have no parent */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
845 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
846 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
847 * Lock the dnode handle to prevent the dnode from obtaining any new |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
848 * holds. This also prevents the descendant dbufs and the bonus dbuf |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
849 * from accessing the dnode, so that we can discount their holds. The |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
850 * handle is safe to access because we know that while the dnode cannot |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
851 * go away, neither can its handle. Once we hold dnh_zrlock, we can |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
852 * safely move any dnode referenced only by dbufs. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
853 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
854 if (!zrl_tryenter(&odn->dn_handle->dnh_zrlock)) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
855 mutex_exit(&os->os_lock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
856 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_handle); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
857 return (KMEM_CBRC_LATER); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
858 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
859 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
860 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
861 * Ensure a consistent view of the dnode's holds and the dnode's dbufs. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
862 * We need to guarantee that there is a hold for every dbuf in order to |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
863 * determine whether the dnode is actively referenced. Falsely matching |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
864 * a dbuf to an active hold would lead to an unsafe move. It's possible |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
865 * that a thread already having an active dnode hold is about to add a |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
866 * dbuf, and we can't compare hold and dbuf counts while the add is in |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
867 * progress. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
868 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
869 if (!rw_tryenter(&odn->dn_struct_rwlock, RW_WRITER)) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
870 zrl_exit(&odn->dn_handle->dnh_zrlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
871 mutex_exit(&os->os_lock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
872 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_rwlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
873 return (KMEM_CBRC_LATER); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
874 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
875 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
876 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
877 * A dbuf may be removed (evicted) without an active dnode hold. In that |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
878 * case, the dbuf count is decremented under the handle lock before the |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
879 * dbuf's hold is released. This order ensures that if we count the hold |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
880 * after the dbuf is removed but before its hold is released, we will |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
881 * treat the unmatched hold as active and exit safely. If we count the |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
882 * hold before the dbuf is removed, the hold is discounted, and the |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
883 * removal is blocked until the move completes. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
884 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
885 refcount = refcount_count(&odn->dn_holds); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
886 ASSERT(refcount >= 0); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
887 dbufs = odn->dn_dbufs_count; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
888 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
889 /* We can't have more dbufs than dnode holds. */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
890 ASSERT3U(dbufs, <=, refcount); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
891 DTRACE_PROBE3(dnode__move, dnode_t *, odn, int64_t, refcount, |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
892 uint32_t, dbufs); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
893 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
894 if (refcount > dbufs) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
895 rw_exit(&odn->dn_struct_rwlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
896 zrl_exit(&odn->dn_handle->dnh_zrlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
897 mutex_exit(&os->os_lock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
898 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_active); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
899 return (KMEM_CBRC_LATER); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
900 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
901 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
902 rw_exit(&odn->dn_struct_rwlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
903 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
904 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
905 * At this point we know that anyone with a hold on the dnode is not |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
906 * actively referencing it. The dnode is known and in a valid state to |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
907 * move. We're holding the locks needed to execute the critical section. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
908 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
909 dnode_move_impl(odn, ndn); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
910 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
911 list_link_replace(&odn->dn_link, &ndn->dn_link); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
912 /* If the dnode was safe to move, the refcount cannot have changed. */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
913 ASSERT(refcount == refcount_count(&ndn->dn_holds)); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
914 ASSERT(dbufs == ndn->dn_dbufs_count); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
915 zrl_exit(&ndn->dn_handle->dnh_zrlock); /* handle has moved */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
916 mutex_exit(&os->os_lock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
917 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
918 return (KMEM_CBRC_YES); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
919 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
920 #endif /* _KERNEL */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
921 |
789 | 922 void |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
923 dnode_special_close(dnode_handle_t *dnh) |
789 | 924 { |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
925 dnode_t *dn = dnh->dnh_dnode; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
926 |
1544 | 927 /* |
928 * Wait for final references to the dnode to clear. This can | |
929 * only happen if the arc is asyncronously evicting state that | |
930 * has a hold on this dnode while we are trying to evict this | |
931 * dnode. | |
932 */ | |
933 while (refcount_count(&dn->dn_holds) > 0) | |
934 delay(1); | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
935 zrl_add(&dnh->dnh_zrlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
936 dnode_destroy(dn); /* implicit zrl_remove() */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
937 zrl_destroy(&dnh->dnh_zrlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
938 dnh->dnh_dnode = NULL; |
789 | 939 } |
940 | |
941 dnode_t * | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
942 dnode_special_open(objset_t *os, dnode_phys_t *dnp, uint64_t object, |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
943 dnode_handle_t *dnh) |
789 | 944 { |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
945 dnode_t *dn = dnode_create(os, dnp, NULL, object, dnh); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
946 dnh->dnh_dnode = dn; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
947 zrl_init(&dnh->dnh_zrlock); |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
948 DNODE_VERIFY(dn); |
789 | 949 return (dn); |
950 } | |
951 | |
952 static void | |
953 dnode_buf_pageout(dmu_buf_t *db, void *arg) | |
954 { | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
955 dnode_children_t *children_dnodes = arg; |
789 | 956 int i; |
957 int epb = db->db_size >> DNODE_SHIFT; | |
958 | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
959 ASSERT(epb == children_dnodes->dnc_count); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
960 |
789 | 961 for (i = 0; i < epb; i++) { |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
962 dnode_handle_t *dnh = &children_dnodes->dnc_children[i]; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
963 dnode_t *dn; |
789 | 964 |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
965 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
966 * The dnode handle lock guards against the dnode moving to |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
967 * another valid address, so there is no need here to guard |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
968 * against changes to or from NULL. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
969 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
970 if (dnh->dnh_dnode == NULL) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
971 zrl_destroy(&dnh->dnh_zrlock); |
789 | 972 continue; |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
973 } |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
974 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
975 zrl_add(&dnh->dnh_zrlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
976 dn = dnh->dnh_dnode; |
789 | 977 /* |
978 * If there are holds on this dnode, then there should | |
979 * be holds on the dnode's containing dbuf as well; thus | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
980 * it wouldn't be eligible for eviction and this function |
789 | 981 * would not have been called. |
982 */ | |
983 ASSERT(refcount_is_zero(&dn->dn_holds)); | |
984 ASSERT(refcount_is_zero(&dn->dn_tx_holds)); | |
985 | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
986 dnode_destroy(dn); /* implicit zrl_remove() */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
987 zrl_destroy(&dnh->dnh_zrlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
988 dnh->dnh_dnode = NULL; |
789 | 989 } |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
990 kmem_free(children_dnodes, sizeof (dnode_children_t) + |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
991 (epb - 1) * sizeof (dnode_handle_t)); |
789 | 992 } |
993 | |
994 /* | |
1544 | 995 * errors: |
996 * EINVAL - invalid object number. | |
997 * EIO - i/o error. | |
998 * succeeds even for free dnodes. | |
789 | 999 */ |
1544 | 1000 int |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9950
diff
changeset
|
1001 dnode_hold_impl(objset_t *os, uint64_t object, int flag, |
1544 | 1002 void *tag, dnode_t **dnp) |
789 | 1003 { |
1544 | 1004 int epb, idx, err; |
789 | 1005 int drop_struct_lock = FALSE; |
1544 | 1006 int type; |
789 | 1007 uint64_t blk; |
1008 dnode_t *mdn, *dn; | |
1009 dmu_buf_impl_t *db; | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1010 dnode_children_t *children_dnodes; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1011 dnode_handle_t *dnh; |
789 | 1012 |
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
|
1013 /* |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7385
diff
changeset
|
1014 * 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
|
1015 * 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
|
1016 * 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
|
1017 * 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
|
1018 */ |
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
|
1019 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
|
1020 (spa_is_root(os->os_spa) && |
12586
b118bbd65be9
6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents:
12432
diff
changeset
|
1021 spa_config_held(os->os_spa, SCL_STATE, 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
|
1022 |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1023 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
|
1024 dn = (object == DMU_USERUSED_OBJECT) ? |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1025 DMU_USERUSED_DNODE(os) : DMU_GROUPUSED_DNODE(os); |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1026 if (dn == NULL) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1027 return (ENOENT); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1028 type = dn->dn_type; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1029 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
|
1030 return (ENOENT); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1031 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
|
1032 return (EEXIST); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1033 DNODE_VERIFY(dn); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1034 (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
|
1035 *dnp = dn; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1036 return (0); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1037 } |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1038 |
789 | 1039 if (object == 0 || object >= DN_MAX_OBJECT) |
1544 | 1040 return (EINVAL); |
789 | 1041 |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1042 mdn = DMU_META_DNODE(os); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1043 ASSERT(mdn->dn_object == DMU_META_DNODE_OBJECT); |
789 | 1044 |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
1045 DNODE_VERIFY(mdn); |
789 | 1046 |
1047 if (!RW_WRITE_HELD(&mdn->dn_struct_rwlock)) { | |
1048 rw_enter(&mdn->dn_struct_rwlock, RW_READER); | |
1049 drop_struct_lock = TRUE; | |
1050 } | |
1051 | |
1052 blk = dbuf_whichblock(mdn, object * sizeof (dnode_phys_t)); | |
1053 | |
1544 | 1054 db = dbuf_hold(mdn, blk, FTAG); |
789 | 1055 if (drop_struct_lock) |
1056 rw_exit(&mdn->dn_struct_rwlock); | |
1544 | 1057 if (db == NULL) |
1058 return (EIO); | |
1059 err = dbuf_read(db, NULL, DB_RF_CANFAIL); | |
1060 if (err) { | |
1061 dbuf_rele(db, FTAG); | |
1062 return (err); | |
1063 } | |
789 | 1064 |
1065 ASSERT3U(db->db.db_size, >=, 1<<DNODE_SHIFT); | |
1066 epb = db->db.db_size >> DNODE_SHIFT; | |
1067 | |
1068 idx = object & (epb-1); | |
1069 | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1070 ASSERT(DB_DNODE(db)->dn_type == DMU_OT_DNODE); |
789 | 1071 children_dnodes = dmu_buf_get_user(&db->db); |
1072 if (children_dnodes == NULL) { | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1073 int i; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1074 dnode_children_t *winner; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1075 children_dnodes = kmem_alloc(sizeof (dnode_children_t) + |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1076 (epb - 1) * sizeof (dnode_handle_t), KM_SLEEP); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1077 children_dnodes->dnc_count = epb; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1078 dnh = &children_dnodes->dnc_children[0]; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1079 for (i = 0; i < epb; i++) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1080 zrl_init(&dnh[i].dnh_zrlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1081 dnh[i].dnh_dnode = NULL; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1082 } |
789 | 1083 if (winner = dmu_buf_set_user(&db->db, children_dnodes, NULL, |
1084 dnode_buf_pageout)) { | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1085 kmem_free(children_dnodes, sizeof (dnode_children_t) + |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1086 (epb - 1) * sizeof (dnode_handle_t)); |
789 | 1087 children_dnodes = winner; |
1088 } | |
1089 } | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1090 ASSERT(children_dnodes->dnc_count == epb); |
789 | 1091 |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1092 dnh = &children_dnodes->dnc_children[idx]; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1093 zrl_add(&dnh->dnh_zrlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1094 if ((dn = dnh->dnh_dnode) == NULL) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1095 dnode_phys_t *phys = (dnode_phys_t *)db->db.db_data+idx; |
789 | 1096 dnode_t *winner; |
4309
3dfde0f4662d
6542676 ARC needs to track meta-data memory overhead
maybee
parents:
3882
diff
changeset
|
1097 |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1098 dn = dnode_create(os, phys, db, object, dnh); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1099 winner = atomic_cas_ptr(&dnh->dnh_dnode, NULL, dn); |
789 | 1100 if (winner != NULL) { |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1101 zrl_add(&dnh->dnh_zrlock); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1102 dnode_destroy(dn); /* implicit zrl_remove() */ |
789 | 1103 dn = winner; |
1104 } | |
1105 } | |
1106 | |
1107 mutex_enter(&dn->dn_mtx); | |
1544 | 1108 type = dn->dn_type; |
789 | 1109 if (dn->dn_free_txg || |
1544 | 1110 ((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
|
1111 ((flag & DNODE_MUST_BE_FREE) && |
12432
222dd376dd6c
6952522 elpaso panics: assertion failed: refcount_is_zero(&dn->dn_holds), file: ../../common/fs/zfs/dnode.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
12411
diff
changeset
|
1112 (type != DMU_OT_NONE || !refcount_is_zero(&dn->dn_holds)))) { |
789 | 1113 mutex_exit(&dn->dn_mtx); |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1114 zrl_remove(&dnh->dnh_zrlock); |
1544 | 1115 dbuf_rele(db, FTAG); |
1116 return (type == DMU_OT_NONE ? ENOENT : EEXIST); | |
789 | 1117 } |
1118 mutex_exit(&dn->dn_mtx); | |
1119 | |
1544 | 1120 if (refcount_add(&dn->dn_holds, tag) == 1) |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1121 dbuf_add_ref(db, dnh); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1122 /* Now we can rely on the hold to prevent the dnode from moving. */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1123 zrl_remove(&dnh->dnh_zrlock); |
789 | 1124 |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
1125 DNODE_VERIFY(dn); |
789 | 1126 ASSERT3P(dn->dn_dbuf, ==, db); |
1127 ASSERT3U(dn->dn_object, ==, object); | |
1544 | 1128 dbuf_rele(db, FTAG); |
789 | 1129 |
1544 | 1130 *dnp = dn; |
1131 return (0); | |
789 | 1132 } |
1133 | |
1134 /* | |
1135 * Return held dnode if the object is allocated, NULL if not. | |
1136 */ | |
1544 | 1137 int |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9950
diff
changeset
|
1138 dnode_hold(objset_t *os, uint64_t object, void *tag, dnode_t **dnp) |
789 | 1139 { |
1544 | 1140 return (dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED, tag, dnp)); |
789 | 1141 } |
1142 | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1143 /* |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1144 * 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
|
1145 * 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
|
1146 * new reference. |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1147 */ |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1148 boolean_t |
1544 | 1149 dnode_add_ref(dnode_t *dn, void *tag) |
789 | 1150 { |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1151 mutex_enter(&dn->dn_mtx); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1152 if (refcount_is_zero(&dn->dn_holds)) { |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1153 mutex_exit(&dn->dn_mtx); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1154 return (FALSE); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1155 } |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1156 VERIFY(1 < refcount_add(&dn->dn_holds, tag)); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1157 mutex_exit(&dn->dn_mtx); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1158 return (TRUE); |
789 | 1159 } |
1160 | |
1161 void | |
1544 | 1162 dnode_rele(dnode_t *dn, void *tag) |
789 | 1163 { |
1164 uint64_t refs; | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1165 /* Get while the hold prevents the dnode from moving. */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1166 dmu_buf_impl_t *db = dn->dn_dbuf; |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1167 dnode_handle_t *dnh = dn->dn_handle; |
789 | 1168 |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1169 mutex_enter(&dn->dn_mtx); |
1544 | 1170 refs = refcount_remove(&dn->dn_holds, tag); |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1171 mutex_exit(&dn->dn_mtx); |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1172 |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1173 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1174 * It's unsafe to release the last hold on a dnode by dnode_rele() or |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1175 * indirectly by dbuf_rele() while relying on the dnode handle to |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1176 * prevent the dnode from moving, since releasing the last hold could |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1177 * result in the dnode's parent dbuf evicting its dnode handles. For |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1178 * that reason anyone calling dnode_rele() or dbuf_rele() without some |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1179 * other direct or indirect hold on the dnode must first drop the dnode |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1180 * handle. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1181 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1182 ASSERT(refs > 0 || dnh->dnh_zrlock.zr_owner != curthread); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1183 |
789 | 1184 /* NOTE: the DNODE_DNODE does not have a dn_dbuf */ |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1185 if (refs == 0 && db != NULL) { |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1186 /* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1187 * Another thread could add a hold to the dnode handle in |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1188 * dnode_hold_impl() while holding the parent dbuf. Since the |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1189 * hold on the parent dbuf prevents the handle from being |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1190 * destroyed, the hold on the handle is OK. We can't yet assert |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1191 * that the handle has zero references, but that will be |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1192 * asserted anyway when the handle gets destroyed. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1193 */ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1194 dbuf_rele(db, dnh); |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1195 } |
789 | 1196 } |
1197 | |
1198 void | |
1199 dnode_setdirty(dnode_t *dn, dmu_tx_t *tx) | |
1200 { | |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9950
diff
changeset
|
1201 objset_t *os = dn->dn_objset; |
789 | 1202 uint64_t txg = tx->tx_txg; |
1203 | |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1204 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
|
1205 dsl_dataset_dirty(os->os_dsl_dataset, tx); |
789 | 1206 return; |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1207 } |
789 | 1208 |
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
1209 DNODE_VERIFY(dn); |
789 | 1210 |
1211 #ifdef ZFS_DEBUG | |
1212 mutex_enter(&dn->dn_mtx); | |
1213 ASSERT(dn->dn_phys->dn_type || dn->dn_allocated_txg); | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1214 ASSERT(dn->dn_free_txg == 0 || dn->dn_free_txg >= txg); |
789 | 1215 mutex_exit(&dn->dn_mtx); |
1216 #endif | |
1217 | |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1218 /* |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1219 * Determine old uid/gid when necessary |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1220 */ |
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
|
1221 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
|
1222 |
789 | 1223 mutex_enter(&os->os_lock); |
1224 | |
1225 /* | |
1226 * If we are already marked dirty, we're done. | |
1227 */ | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1228 if (list_link_active(&dn->dn_dirty_link[txg & TXG_MASK])) { |
789 | 1229 mutex_exit(&os->os_lock); |
1230 return; | |
1231 } | |
1232 | |
1233 ASSERT(!refcount_is_zero(&dn->dn_holds) || list_head(&dn->dn_dbufs)); | |
1234 ASSERT(dn->dn_datablksz != 0); | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1235 ASSERT3U(dn->dn_next_bonuslen[txg&TXG_MASK], ==, 0); |
1599 | 1236 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
|
1237 ASSERT3U(dn->dn_next_bonustype[txg&TXG_MASK], ==, 0); |
789 | 1238 |
1239 dprintf_ds(os->os_dsl_dataset, "obj=%llu txg=%llu\n", | |
1240 dn->dn_object, txg); | |
1241 | |
1242 if (dn->dn_free_txg > 0 && dn->dn_free_txg <= txg) { | |
1243 list_insert_tail(&os->os_free_dnodes[txg&TXG_MASK], dn); | |
1244 } else { | |
1245 list_insert_tail(&os->os_dirty_dnodes[txg&TXG_MASK], dn); | |
1246 } | |
1247 | |
1248 mutex_exit(&os->os_lock); | |
1249 | |
1250 /* | |
1251 * The dnode maintains a hold on its containing dbuf as | |
1252 * long as there are holds on it. Each instantiated child | |
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12586
diff
changeset
|
1253 * dbuf maintains a hold on the dnode. When the last child |
789 | 1254 * drops its hold, the dnode will drop its hold on the |
1255 * containing dbuf. We add a "dirty hold" here so that the | |
1256 * dnode will hang around after we finish processing its | |
1257 * children. | |
1258 */ | |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4577
diff
changeset
|
1259 VERIFY(dnode_add_ref(dn, (void *)(uintptr_t)tx->tx_txg)); |
789 | 1260 |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1261 (void) dbuf_dirty(dn->dn_dbuf, tx); |
789 | 1262 |
1263 dsl_dataset_dirty(os->os_dsl_dataset, tx); | |
1264 } | |
1265 | |
1266 void | |
1267 dnode_free(dnode_t *dn, dmu_tx_t *tx) | |
1268 { | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1269 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
|
1270 |
789 | 1271 dprintf("dn=%p txg=%llu\n", dn, tx->tx_txg); |
1272 | |
1273 /* we should be the only holder... hopefully */ | |
1274 /* ASSERT3U(refcount_count(&dn->dn_holds), ==, 1); */ | |
1275 | |
1276 mutex_enter(&dn->dn_mtx); | |
1277 if (dn->dn_type == DMU_OT_NONE || dn->dn_free_txg) { | |
1278 mutex_exit(&dn->dn_mtx); | |
1279 return; | |
1280 } | |
1281 dn->dn_free_txg = tx->tx_txg; | |
1282 mutex_exit(&dn->dn_mtx); | |
1283 | |
1284 /* | |
1285 * If the dnode is already dirty, it needs to be moved from | |
1286 * the dirty list to the free list. | |
1287 */ | |
1288 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
|
1289 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
|
1290 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
|
1291 list_insert_tail(&dn->dn_objset->os_free_dnodes[txgoff], dn); |
789 | 1292 mutex_exit(&dn->dn_objset->os_lock); |
1293 } else { | |
1294 mutex_exit(&dn->dn_objset->os_lock); | |
1295 dnode_setdirty(dn, tx); | |
1296 } | |
1297 } | |
1298 | |
1299 /* | |
1300 * Try to change the block size for the indicated dnode. This can only | |
1301 * succeed if there are no blocks allocated or dirty beyond first block | |
1302 */ | |
1303 int | |
1304 dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx) | |
1305 { | |
1306 dmu_buf_impl_t *db, *db_next; | |
6992 | 1307 int err; |
789 | 1308 |
1309 if (size == 0) | |
1310 size = SPA_MINBLOCKSIZE; | |
1311 if (size > SPA_MAXBLOCKSIZE) | |
1312 size = SPA_MAXBLOCKSIZE; | |
1313 else | |
1314 size = P2ROUNDUP(size, SPA_MINBLOCKSIZE); | |
1315 | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1316 if (ibs == dn->dn_indblkshift) |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1317 ibs = 0; |
789 | 1318 |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1319 if (size >> SPA_MINBLOCKSHIFT == dn->dn_datablkszsec && ibs == 0) |
789 | 1320 return (0); |
1321 | |
1322 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); | |
1323 | |
1324 /* Check for any allocated blocks beyond the first */ | |
1325 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
|
1326 goto fail; |
789 | 1327 |
1328 mutex_enter(&dn->dn_dbufs_mtx); | |
1329 for (db = list_head(&dn->dn_dbufs); db; db = db_next) { | |
1330 db_next = list_next(&dn->dn_dbufs, db); | |
1331 | |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1332 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
|
1333 db->db_blkid != DMU_SPILL_BLKID) { |
789 | 1334 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
|
1335 goto fail; |
789 | 1336 } |
1337 } | |
1338 mutex_exit(&dn->dn_dbufs_mtx); | |
1339 | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1340 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
|
1341 goto fail; |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1342 |
6992 | 1343 /* resize the old block */ |
1344 err = dbuf_hold_impl(dn, 0, 0, TRUE, FTAG, &db); | |
1345 if (err == 0) | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1346 dbuf_new_size(db, size, tx); |
6992 | 1347 else if (err != ENOENT) |
1348 goto fail; | |
789 | 1349 |
1350 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
|
1351 dnode_setdirty(dn, tx); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1352 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
|
1353 if (ibs) { |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1354 dn->dn_indblkshift = ibs; |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1355 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
|
1356 } |
6992 | 1357 /* 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
|
1358 if (db) |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1359 dbuf_rele(db, FTAG); |
789 | 1360 |
1361 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
|
1362 return (0); |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1363 |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1364 fail: |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1365 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
|
1366 return (ENOTSUP); |
789 | 1367 } |
1368 | |
7332
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1369 /* read-holding callers must not rely on the lock being continuously held */ |
789 | 1370 void |
7332
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1371 dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t have_read) |
789 | 1372 { |
1373 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
|
1374 int epbs, new_nlevels; |
789 | 1375 uint64_t sz; |
1376 | |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1377 ASSERT(blkid != DMU_BONUS_BLKID); |
789 | 1378 |
7332
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1379 ASSERT(have_read ? |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1380 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
|
1381 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
|
1382 |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1383 /* |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1384 * 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
|
1385 * 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
|
1386 */ |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1387 if (have_read) { |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1388 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
|
1389 return; |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1390 |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1391 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
|
1392 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
|
1393 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
|
1394 } |
789 | 1395 } |
1396 | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1397 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
|
1398 goto out; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1399 |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1400 dn->dn_maxblkid = blkid; |
789 | 1401 |
1402 /* | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1403 * Compute the number of levels necessary to support the new maxblkid. |
789 | 1404 */ |
1405 new_nlevels = 1; | |
1406 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
|
1407 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
|
1408 sz <= blkid && sz >= dn->dn_nblkptr; sz <<= epbs) |
789 | 1409 new_nlevels++; |
1410 | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1411 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
|
1412 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
|
1413 dmu_buf_impl_t *db; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1414 list_t *list; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1415 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
|
1416 |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1417 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
|
1418 |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
1419 ASSERT3U(new_nlevels, >, dn->dn_next_nlevels[txgoff]); |
789 | 1420 dn->dn_next_nlevels[txgoff] = new_nlevels; |
1421 | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1422 /* 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
|
1423 db = dbuf_hold_level(dn, old_nlevels, 0, FTAG); |
12411
3e9af067a727
6911391 panic in dmu_tx_count_write()
John Harres <John.Harres@Sun.COM>
parents:
12178
diff
changeset
|
1424 ASSERT(db != NULL); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1425 new = dbuf_dirty(db, tx); |
1544 | 1426 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
|
1427 |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1428 /* transfer the dirty records to the new indirect */ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1429 mutex_enter(&dn->dn_mtx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1430 mutex_enter(&new->dt.di.dr_mtx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1431 list = &dn->dn_dirty_records[txgoff]; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1432 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
|
1433 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
|
1434 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
|
1435 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
|
1436 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
|
1437 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
|
1438 list_remove(&dn->dn_dirty_records[txgoff], dr); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1439 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
|
1440 dr->dr_parent = new; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1441 } |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1442 } |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1443 mutex_exit(&new->dt.di.dr_mtx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3087
diff
changeset
|
1444 mutex_exit(&dn->dn_mtx); |
789 | 1445 } |
1446 | |
1447 out: | |
7332
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1448 if (have_read) |
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
7049
diff
changeset
|
1449 rw_downgrade(&dn->dn_struct_rwlock); |
789 | 1450 } |
1451 | |
1452 void | |
1453 dnode_clear_range(dnode_t *dn, uint64_t blkid, uint64_t nblks, dmu_tx_t *tx) | |
1454 { | |
1455 avl_tree_t *tree = &dn->dn_ranges[tx->tx_txg&TXG_MASK]; | |
1456 avl_index_t where; | |
1457 free_range_t *rp; | |
1458 free_range_t rp_tofind; | |
1459 uint64_t endblk = blkid + nblks; | |
1460 | |
1461 ASSERT(MUTEX_HELD(&dn->dn_mtx)); | |
1462 ASSERT(nblks <= UINT64_MAX - blkid); /* no overflow */ | |
1463 | |
1464 dprintf_dnode(dn, "blkid=%llu nblks=%llu txg=%llu\n", | |
1465 blkid, nblks, tx->tx_txg); | |
1466 rp_tofind.fr_blkid = blkid; | |
1467 rp = avl_find(tree, &rp_tofind, &where); | |
1468 if (rp == NULL) | |
1469 rp = avl_nearest(tree, where, AVL_BEFORE); | |
1470 if (rp == NULL) | |
1471 rp = avl_nearest(tree, where, AVL_AFTER); | |
1472 | |
1473 while (rp && (rp->fr_blkid <= blkid + nblks)) { | |
1474 uint64_t fr_endblk = rp->fr_blkid + rp->fr_nblks; | |
1475 free_range_t *nrp = AVL_NEXT(tree, rp); | |
1476 | |
1477 if (blkid <= rp->fr_blkid && endblk >= fr_endblk) { | |
1478 /* clear this entire range */ | |
1479 avl_remove(tree, rp); | |
1480 kmem_free(rp, sizeof (free_range_t)); | |
1481 } else if (blkid <= rp->fr_blkid && | |
1482 endblk > rp->fr_blkid && endblk < fr_endblk) { | |
1483 /* clear the beginning of this range */ | |
1484 rp->fr_blkid = endblk; | |
1485 rp->fr_nblks = fr_endblk - endblk; | |
1486 } else if (blkid > rp->fr_blkid && blkid < fr_endblk && | |
1487 endblk >= fr_endblk) { | |
1488 /* clear the end of this range */ | |
1489 rp->fr_nblks = blkid - rp->fr_blkid; | |
1490 } else if (blkid > rp->fr_blkid && endblk < fr_endblk) { | |
1491 /* clear a chunk out of this range */ | |
1492 free_range_t *new_rp = | |
1493 kmem_alloc(sizeof (free_range_t), KM_SLEEP); | |
1494 | |
1495 new_rp->fr_blkid = endblk; | |
1496 new_rp->fr_nblks = fr_endblk - endblk; | |
1497 avl_insert_here(tree, new_rp, rp, AVL_AFTER); | |
1498 rp->fr_nblks = blkid - rp->fr_blkid; | |
1499 } | |
1500 /* there may be no overlap */ | |
1501 rp = nrp; | |
1502 } | |
1503 } | |
1504 | |
1505 void | |
1506 dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx) | |
1507 { | |
1508 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
|
1509 uint64_t blkoff, blkid, nblks; |
6992 | 1510 int blksz, blkshift, head, tail; |
789 | 1511 int trunc = FALSE; |
6992 | 1512 int epbs; |
789 | 1513 |
1514 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); | |
1515 blksz = dn->dn_datablksz; | |
6992 | 1516 blkshift = dn->dn_datablkshift; |
1517 epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT; | |
789 | 1518 |
1519 if (len == -1ULL) { | |
1520 len = UINT64_MAX - off; | |
1521 trunc = TRUE; | |
1522 } | |
1523 | |
1524 /* | |
1525 * First, block align the region to free: | |
1526 */ | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1527 if (ISP2(blksz)) { |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1528 head = P2NPHASE(off, blksz); |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1529 blkoff = P2PHASE(off, blksz); |
6992 | 1530 if ((off >> blkshift) > dn->dn_maxblkid) |
1531 goto out; | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1532 } else { |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1533 ASSERT(dn->dn_maxblkid == 0); |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1534 if (off == 0 && len >= blksz) { |
6992 | 1535 /* Freeing the whole block; fast-track this request */ |
1536 blkid = 0; | |
1537 nblks = 1; | |
1538 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
|
1539 } else if (off >= blksz) { |
6992 | 1540 /* Freeing past end-of-data */ |
1541 goto out; | |
789 | 1542 } else { |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1543 /* Freeing part of the block. */ |
789 | 1544 head = blksz - off; |
1545 ASSERT3U(head, >, 0); | |
1546 } | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1547 blkoff = off; |
789 | 1548 } |
1549 /* zero out any partial block data at the start of the range */ | |
1550 if (head) { | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1551 ASSERT3U(blkoff + head, ==, blksz); |
789 | 1552 if (len < head) |
1553 head = len; | |
1554 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, off), TRUE, | |
1555 FTAG, &db) == 0) { | |
1556 caddr_t data; | |
1557 | |
1558 /* 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
|
1559 if (db->db_last_dirty || |
789 | 1560 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) { |
1561 rw_exit(&dn->dn_struct_rwlock); | |
1562 dbuf_will_dirty(db, tx); | |
1563 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); | |
1564 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
|
1565 bzero(data + blkoff, head); |
789 | 1566 } |
1544 | 1567 dbuf_rele(db, FTAG); |
789 | 1568 } |
1569 off += head; | |
1570 len -= head; | |
1571 } | |
1572 | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1573 /* If the range was less than one block, we're done */ |
6992 | 1574 if (len == 0) |
1575 goto out; | |
1576 | |
1577 /* If the remaining range is past end of file, we're done */ | |
1578 if ((off >> blkshift) > dn->dn_maxblkid) | |
1579 goto out; | |
1580 | |
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
|
1581 ASSERT(ISP2(blksz)); |
6992 | 1582 if (trunc) |
1583 tail = 0; | |
1584 else | |
1585 tail = P2PHASE(len, blksz); | |
1586 | |
1587 ASSERT3U(P2PHASE(off, blksz), ==, 0); | |
1588 /* zero out any partial block data at the end of the range */ | |
1589 if (tail) { | |
1590 if (len < tail) | |
1591 tail = len; | |
1592 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, off+len), | |
1593 TRUE, FTAG, &db) == 0) { | |
1594 /* don't dirty if not on disk and not dirty */ | |
1595 if (db->db_last_dirty || | |
1596 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) { | |
1597 rw_exit(&dn->dn_struct_rwlock); | |
1598 dbuf_will_dirty(db, tx); | |
1599 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); | |
1600 bzero(db->db.db_data, tail); | |
1601 } | |
1602 dbuf_rele(db, FTAG); | |
1603 } | |
1604 len -= tail; | |
1605 } | |
1606 | |
1607 /* If the range did not include a full block, we are done */ | |
1608 if (len == 0) | |
789 | 1609 goto out; |
1610 | |
6992 | 1611 ASSERT(IS_P2ALIGNED(off, blksz)); |
1612 ASSERT(trunc || IS_P2ALIGNED(len, blksz)); | |
1613 blkid = off >> blkshift; | |
1614 nblks = len >> blkshift; | |
1615 if (trunc) | |
1616 nblks += 1; | |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1617 |
6992 | 1618 /* |
1619 * Read in and mark all the level-1 indirects dirty, | |
1620 * 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
|
1621 * 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
|
1622 * we dirty all the partial indirects. |
6992 | 1623 */ |
1624 if (dn->dn_nlevels > 1) { | |
1625 uint64_t i, first, last; | |
1626 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
|
1627 |
6992 | 1628 first = blkid >> epbs; |
7049
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1629 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
|
1630 dbuf_will_dirty(db, tx); |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1631 dbuf_rele(db, FTAG); |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1632 } |
6992 | 1633 if (trunc) |
1634 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
|
1635 else |
6992 | 1636 last = (blkid + nblks - 1) >> epbs; |
7049
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1637 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
|
1638 dbuf_will_dirty(db, tx); |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1639 dbuf_rele(db, FTAG); |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1640 } |
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1641 for (i = first + 1; i < last; i++) { |
6992 | 1642 uint64_t ibyte = i << shift; |
1643 int err; | |
789 | 1644 |
6992 | 1645 err = dnode_next_offset(dn, |
1646 DNODE_FIND_HAVELOCK, &ibyte, 1, 1, 0); | |
1647 i = ibyte >> shift; | |
7049
d0b1e2eb4ab5
6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents:
6992
diff
changeset
|
1648 if (err == ESRCH || i >= last) |
6992 | 1649 break; |
1650 ASSERT(err == 0); | |
1651 db = dbuf_hold_level(dn, 1, i, FTAG); | |
1652 if (db) { | |
1653 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
|
1654 dbuf_rele(db, FTAG); |
789 | 1655 } |
2445
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1656 } |
45c1310316ff
6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents:
2082
diff
changeset
|
1657 } |
6992 | 1658 done: |
1659 /* | |
1660 * Add this range to the dnode range list. | |
1661 * We will finish up this free operation in the syncing phase. | |
1662 */ | |
789 | 1663 mutex_enter(&dn->dn_mtx); |
1664 dnode_clear_range(dn, blkid, nblks, tx); | |
1665 { | |
1666 free_range_t *rp, *found; | |
1667 avl_index_t where; | |
1668 avl_tree_t *tree = &dn->dn_ranges[tx->tx_txg&TXG_MASK]; | |
1669 | |
1670 /* Add new range to dn_ranges */ | |
1671 rp = kmem_alloc(sizeof (free_range_t), KM_SLEEP); | |
1672 rp->fr_blkid = blkid; | |
1673 rp->fr_nblks = nblks; | |
1674 found = avl_find(tree, rp, &where); | |
1675 ASSERT(found == NULL); | |
1676 avl_insert(tree, rp, where); | |
1677 dprintf_dnode(dn, "blkid=%llu nblks=%llu txg=%llu\n", | |
1678 blkid, nblks, tx->tx_txg); | |
1679 } | |
1680 mutex_exit(&dn->dn_mtx); | |
1681 | |
6992 | 1682 dbuf_free_range(dn, blkid, blkid + nblks - 1, tx); |
789 | 1683 dnode_setdirty(dn, tx); |
1684 out: | |
6992 | 1685 if (trunc && dn->dn_maxblkid >= (off >> blkshift)) |
1686 dn->dn_maxblkid = (off >> blkshift ? (off >> blkshift) - 1 : 0); | |
1687 | |
789 | 1688 rw_exit(&dn->dn_struct_rwlock); |
1689 } | |
1690 | |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1691 static boolean_t |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1692 dnode_spill_freed(dnode_t *dn) |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1693 { |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1694 int i; |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1695 |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1696 mutex_enter(&dn->dn_mtx); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1697 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
|
1698 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
|
1699 break; |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1700 } |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1701 mutex_exit(&dn->dn_mtx); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1702 return (i < TXG_SIZE); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1703 } |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1704 |
789 | 1705 /* return TRUE if this blkid was freed in a recent txg, or FALSE if it wasn't */ |
1706 uint64_t | |
1707 dnode_block_freed(dnode_t *dn, uint64_t blkid) | |
1708 { | |
1709 free_range_t range_tofind; | |
1710 void *dp = spa_get_dsl(dn->dn_objset->os_spa); | |
1711 int i; | |
1712 | |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1713 if (blkid == DMU_BONUS_BLKID) |
789 | 1714 return (FALSE); |
1715 | |
1716 /* | |
1717 * If we're in the process of opening the pool, dp will not be | |
1718 * set yet, but there shouldn't be anything dirty. | |
1719 */ | |
1720 if (dp == NULL) | |
1721 return (FALSE); | |
1722 | |
1723 if (dn->dn_free_txg) | |
1724 return (TRUE); | |
1725 | |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1726 if (blkid == DMU_SPILL_BLKID) |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1727 return (dnode_spill_freed(dn)); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
10298
diff
changeset
|
1728 |
789 | 1729 range_tofind.fr_blkid = blkid; |
1730 mutex_enter(&dn->dn_mtx); | |
1731 for (i = 0; i < TXG_SIZE; i++) { | |
1732 free_range_t *range_found; | |
1733 avl_index_t idx; | |
1734 | |
1735 range_found = avl_find(&dn->dn_ranges[i], &range_tofind, &idx); | |
1736 if (range_found) { | |
1737 ASSERT(range_found->fr_nblks > 0); | |
1738 break; | |
1739 } | |
1740 range_found = avl_nearest(&dn->dn_ranges[i], idx, AVL_BEFORE); | |
1741 if (range_found && | |
1742 range_found->fr_blkid + range_found->fr_nblks > blkid) | |
1743 break; | |
1744 } | |
1745 mutex_exit(&dn->dn_mtx); | |
1746 return (i < TXG_SIZE); | |
1747 } | |
1748 | |
1749 /* call from syncing context when we actually write/free space for this dnode */ | |
1750 void | |
2082 | 1751 dnode_diduse_space(dnode_t *dn, int64_t delta) |
789 | 1752 { |
2082 | 1753 uint64_t space; |
1754 dprintf_dnode(dn, "dn=%p dnp=%p used=%llu delta=%lld\n", | |
789 | 1755 dn, dn->dn_phys, |
2082 | 1756 (u_longlong_t)dn->dn_phys->dn_used, |
1757 (longlong_t)delta); | |
789 | 1758 |
1759 mutex_enter(&dn->dn_mtx); | |
2082 | 1760 space = DN_USED_BYTES(dn->dn_phys); |
1761 if (delta > 0) { | |
1762 ASSERT3U(space + delta, >=, space); /* no overflow */ | |
789 | 1763 } else { |
2082 | 1764 ASSERT3U(space, >=, -delta); /* no underflow */ |
1765 } | |
1766 space += delta; | |
4577 | 1767 if (spa_version(dn->dn_objset->os_spa) < SPA_VERSION_DNODE_BYTES) { |
2082 | 1768 ASSERT((dn->dn_phys->dn_flags & DNODE_FLAG_USED_BYTES) == 0); |
1769 ASSERT3U(P2PHASE(space, 1<<DEV_BSHIFT), ==, 0); | |
1770 dn->dn_phys->dn_used = space >> DEV_BSHIFT; | |
1771 } else { | |
1772 dn->dn_phys->dn_used = space; | |
1773 dn->dn_phys->dn_flags |= DNODE_FLAG_USED_BYTES; | |
789 | 1774 } |
1775 mutex_exit(&dn->dn_mtx); | |
1776 } | |
1777 | |
1778 /* | |
1779 * Call when we think we're going to write/free space in open context. | |
1780 * Be conservative (ie. OK to write less than this or free more than | |
1781 * this, but don't write more or free less). | |
1782 */ | |
1783 void | |
1784 dnode_willuse_space(dnode_t *dn, int64_t space, dmu_tx_t *tx) | |
1785 { | |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9950
diff
changeset
|
1786 objset_t *os = dn->dn_objset; |
789 | 1787 dsl_dataset_t *ds = os->os_dsl_dataset; |
1788 | |
1789 if (space > 0) | |
1790 space = spa_get_asize(os->os_spa, space); | |
1791 | |
1792 if (ds) | |
1793 dsl_dir_willuse_space(ds->ds_dir, space, tx); | |
1794 | |
1795 dmu_tx_willuse_space(tx, space); | |
1796 } | |
1797 | |
9950
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1798 /* |
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1799 * 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
|
1800 * 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
|
1801 * 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
|
1802 * 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
|
1803 * 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
|
1804 * 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
|
1805 * 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
|
1806 * 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
|
1807 * |
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1808 * 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
|
1809 * 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
|
1810 * 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
|
1811 * 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
|
1812 * level. |
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1813 */ |
789 | 1814 static int |
6992 | 1815 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
|
1816 int lvl, uint64_t blkfill, uint64_t txg) |
789 | 1817 { |
1818 dmu_buf_impl_t *db = NULL; | |
1819 void *data = NULL; | |
1820 uint64_t epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT; | |
1821 uint64_t epb = 1ULL << epbs; | |
1822 uint64_t minfill, maxfill; | |
6992 | 1823 boolean_t hole; |
1824 int i, inc, error, span; | |
789 | 1825 |
1826 dprintf("probing object %llu offset %llx level %d of %u\n", | |
1827 dn->dn_object, *offset, lvl, dn->dn_phys->dn_nlevels); | |
1828 | |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
1829 hole = ((flags & DNODE_FIND_HOLE) != 0); |
6992 | 1830 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
|
1831 ASSERT(txg == 0 || !hole); |
6992 | 1832 |
789 | 1833 if (lvl == dn->dn_phys->dn_nlevels) { |
1834 error = 0; | |
1835 epb = dn->dn_phys->dn_nblkptr; | |
1836 data = dn->dn_phys->dn_blkptr; | |
1837 } else { | |
1838 uint64_t blkid = dbuf_whichblock(dn, *offset) >> (epbs * lvl); | |
1839 error = dbuf_hold_impl(dn, lvl, blkid, TRUE, FTAG, &db); | |
1840 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
|
1841 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
|
1842 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
|
1843 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
|
1844 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
|
1845 /* |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1846 * 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
|
1847 * 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
|
1848 * 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
|
1849 * 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
|
1850 * 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
|
1851 */ |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1852 return (ESRCH); |
789 | 1853 } |
1793
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1854 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
|
1855 if (error) { |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1856 dbuf_rele(db, FTAG); |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1857 return (error); |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1858 } |
789 | 1859 data = db->db.db_data; |
1860 } | |
1861 | |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1862 if (db && txg && |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1863 (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
|
1864 /* |
f69ff8507427
6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
1865 * 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
|
1866 * 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
|
1867 */ |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1868 error = ESRCH; |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1869 } else if (lvl == 0) { |
789 | 1870 dnode_phys_t *dnp = data; |
1871 span = DNODE_SHIFT; | |
1872 ASSERT(dn->dn_type == DMU_OT_DNODE); | |
1873 | |
6992 | 1874 for (i = (*offset >> span) & (blkfill - 1); |
1875 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
|
1876 if ((dnp[i].dn_type == DMU_OT_NONE) == hole) |
789 | 1877 break; |
6992 | 1878 *offset += (1ULL << span) * inc; |
789 | 1879 } |
6992 | 1880 if (i < 0 || i == blkfill) |
789 | 1881 error = ESRCH; |
1882 } else { | |
1883 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
|
1884 uint64_t start = *offset; |
789 | 1885 span = (lvl - 1) * epbs + dn->dn_datablkshift; |
1886 minfill = 0; | |
1887 maxfill = blkfill << ((lvl - 1) * epbs); | |
1888 | |
1889 if (hole) | |
1890 maxfill--; | |
1891 else | |
1892 minfill++; | |
1893 | |
9950
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1894 *offset = *offset >> span; |
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1895 for (i = BF64_GET(*offset, 0, epbs); |
6992 | 1896 i >= 0 && i < epb; i += inc) { |
789 | 1897 if (bp[i].blk_fill >= minfill && |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1898 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
|
1899 (hole || bp[i].blk_birth > txg)) |
789 | 1900 break; |
9950
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1901 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
|
1902 *offset += inc; |
789 | 1903 } |
9950
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1904 *offset = *offset << span; |
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1905 if (inc < 0) { |
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1906 /* 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
|
1907 ASSERT3U(*offset, <=, start); |
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1908 *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
|
1909 } else if (*offset < start) { |
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1910 *offset = start; |
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1911 } |
78fc41aa9bc5
6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
9409
diff
changeset
|
1912 if (i < 0 || i >= epb) |
789 | 1913 error = ESRCH; |
1914 } | |
1915 | |
1916 if (db) | |
1544 | 1917 dbuf_rele(db, FTAG); |
789 | 1918 |
1919 return (error); | |
1920 } | |
1921 | |
1922 /* | |
1923 * Find the next hole, data, or sparse region at or after *offset. | |
1924 * The value 'blkfill' tells us how many items we expect to find | |
1925 * in an L0 data block; this value is 1 for normal objects, | |
1926 * DNODES_PER_BLOCK for the meta dnode, and some fraction of | |
1927 * 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
|
1928 * |
789 | 1929 * Examples: |
1930 * | |
6992 | 1931 * dnode_next_offset(dn, flags, offset, 1, 1, 0); |
1932 * Finds the next/previous hole/data in a file. | |
789 | 1933 * Used in dmu_offset_next(). |
1934 * | |
6992 | 1935 * dnode_next_offset(mdn, flags, offset, 0, DNODES_PER_BLOCK, txg); |
789 | 1936 * 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
|
1937 * 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
|
1938 * bonus buffer changes and content removal are ignored). |
789 | 1939 * Used in dmu_object_next(). |
1940 * | |
6992 | 1941 * dnode_next_offset(mdn, DNODE_FIND_HOLE, offset, 2, DNODES_PER_BLOCK >> 2, 0); |
789 | 1942 * Finds the next L2 meta-dnode bp that's at most 1/4 full. |
1943 * Used in dmu_object_alloc(). | |
1944 */ | |
1945 int | |
6992 | 1946 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
|
1947 int minlvl, uint64_t blkfill, uint64_t txg) |
789 | 1948 { |
6992 | 1949 uint64_t initial_offset = *offset; |
789 | 1950 int lvl, maxlvl; |
1951 int error = 0; | |
1952 | |
6992 | 1953 if (!(flags & DNODE_FIND_HAVELOCK)) |
1954 rw_enter(&dn->dn_struct_rwlock, RW_READER); | |
789 | 1955 |
1956 if (dn->dn_phys->dn_nlevels == 0) { | |
6992 | 1957 error = ESRCH; |
1958 goto out; | |
789 | 1959 } |
1960 | |
1961 if (dn->dn_datablkshift == 0) { | |
1962 if (*offset < dn->dn_datablksz) { | |
6992 | 1963 if (flags & DNODE_FIND_HOLE) |
789 | 1964 *offset = dn->dn_datablksz; |
1965 } else { | |
1966 error = ESRCH; | |
1967 } | |
6992 | 1968 goto out; |
789 | 1969 } |
1970 | |
1971 maxlvl = dn->dn_phys->dn_nlevels; | |
1972 | |
1973 for (lvl = minlvl; lvl <= maxlvl; lvl++) { | |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1974 error = dnode_next_offset_level(dn, |
6992 | 1975 flags, offset, lvl, blkfill, txg); |
1793
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1976 if (error != ESRCH) |
789 | 1977 break; |
1978 } | |
1979 | |
6992 | 1980 while (error == 0 && --lvl >= minlvl) { |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1981 error = dnode_next_offset_level(dn, |
6992 | 1982 flags, offset, lvl, blkfill, txg); |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
1983 } |
789 | 1984 |
6992 | 1985 if (error == 0 && (flags & DNODE_FIND_BACKWARDS ? |
1986 initial_offset < *offset : initial_offset > *offset)) | |
1793
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1646
diff
changeset
|
1987 error = ESRCH; |
6992 | 1988 out: |
1989 if (!(flags & DNODE_FIND_HAVELOCK)) | |
1990 rw_exit(&dn->dn_struct_rwlock); | |
789 | 1991 |
1992 return (error); | |
1993 } |