Print this page
4171 clean up spa_feature_*() interfaces
4172 implement extensible_dataset feature for use by other zpool features
Reviewed by: Max Grossman <max.grossman@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/dmu_object.c
+++ new/usr/src/uts/common/fs/zfs/dmu_object.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 24 */
25 25
26 26 #include <sys/dmu.h>
27 27 #include <sys/dmu_objset.h>
28 28 #include <sys/dmu_tx.h>
29 29 #include <sys/dnode.h>
30 +#include <sys/zap.h>
31 +#include <sys/zfeature.h>
30 32
31 33 uint64_t
32 34 dmu_object_alloc(objset_t *os, dmu_object_type_t ot, int blocksize,
33 35 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
34 36 {
35 37 uint64_t object;
36 38 uint64_t L2_dnode_count = DNODES_PER_BLOCK <<
37 39 (DMU_META_DNODE(os)->dn_indblkshift - SPA_BLKPTRSHIFT);
38 40 dnode_t *dn = NULL;
39 41 int restarted = B_FALSE;
40 42
41 43 mutex_enter(&os->os_obj_lock);
42 44 for (;;) {
43 45 object = os->os_obj_next;
44 46 /*
45 47 * Each time we polish off an L2 bp worth of dnodes
46 48 * (2^13 objects), move to another L2 bp that's still
47 49 * reasonably sparse (at most 1/4 full). Look from the
48 50 * beginning once, but after that keep looking from here.
49 51 * If we can't find one, just keep going from here.
50 52 */
51 53 if (P2PHASE(object, L2_dnode_count) == 0) {
52 54 uint64_t offset = restarted ? object << DNODE_SHIFT : 0;
53 55 int error = dnode_next_offset(DMU_META_DNODE(os),
54 56 DNODE_FIND_HOLE,
55 57 &offset, 2, DNODES_PER_BLOCK >> 2, 0);
56 58 restarted = B_TRUE;
57 59 if (error == 0)
58 60 object = offset >> DNODE_SHIFT;
59 61 }
60 62 os->os_obj_next = ++object;
61 63
62 64 /*
63 65 * XXX We should check for an i/o error here and return
64 66 * up to our caller. Actually we should pre-read it in
65 67 * dmu_tx_assign(), but there is currently no mechanism
66 68 * to do so.
67 69 */
68 70 (void) dnode_hold_impl(os, object, DNODE_MUST_BE_FREE,
69 71 FTAG, &dn);
70 72 if (dn)
71 73 break;
72 74
73 75 if (dmu_object_next(os, &object, B_TRUE, 0) == 0)
74 76 os->os_obj_next = object - 1;
75 77 }
76 78
77 79 dnode_allocate(dn, ot, blocksize, 0, bonustype, bonuslen, tx);
78 80 dnode_rele(dn, FTAG);
79 81
80 82 mutex_exit(&os->os_obj_lock);
81 83
82 84 dmu_tx_add_new_object(tx, os, object);
83 85 return (object);
84 86 }
85 87
86 88 int
87 89 dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot,
88 90 int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
89 91 {
90 92 dnode_t *dn;
91 93 int err;
92 94
93 95 if (object == DMU_META_DNODE_OBJECT && !dmu_tx_private_ok(tx))
94 96 return (SET_ERROR(EBADF));
95 97
96 98 err = dnode_hold_impl(os, object, DNODE_MUST_BE_FREE, FTAG, &dn);
97 99 if (err)
98 100 return (err);
99 101 dnode_allocate(dn, ot, blocksize, 0, bonustype, bonuslen, tx);
100 102 dnode_rele(dn, FTAG);
101 103
102 104 dmu_tx_add_new_object(tx, os, object);
103 105 return (0);
104 106 }
105 107
106 108 int
107 109 dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot,
108 110 int blocksize, dmu_object_type_t bonustype, int bonuslen)
109 111 {
110 112 dnode_t *dn;
111 113 dmu_tx_t *tx;
112 114 int nblkptr;
113 115 int err;
114 116
115 117 if (object == DMU_META_DNODE_OBJECT)
116 118 return (SET_ERROR(EBADF));
117 119
118 120 err = dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED,
119 121 FTAG, &dn);
120 122 if (err)
121 123 return (err);
122 124
123 125 if (dn->dn_type == ot && dn->dn_datablksz == blocksize &&
124 126 dn->dn_bonustype == bonustype && dn->dn_bonuslen == bonuslen) {
125 127 /* nothing is changing, this is a noop */
126 128 dnode_rele(dn, FTAG);
127 129 return (0);
128 130 }
129 131
130 132 if (bonustype == DMU_OT_SA) {
131 133 nblkptr = 1;
132 134 } else {
133 135 nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT);
134 136 }
135 137
136 138 /*
137 139 * If we are losing blkptrs or changing the block size this must
138 140 * be a new file instance. We must clear out the previous file
139 141 * contents before we can change this type of metadata in the dnode.
140 142 */
141 143 if (dn->dn_nblkptr > nblkptr || dn->dn_datablksz != blocksize) {
142 144 err = dmu_free_long_range(os, object, 0, DMU_OBJECT_END);
143 145 if (err)
144 146 goto out;
145 147 }
146 148
147 149 tx = dmu_tx_create(os);
148 150 dmu_tx_hold_bonus(tx, object);
149 151 err = dmu_tx_assign(tx, TXG_WAIT);
150 152 if (err) {
151 153 dmu_tx_abort(tx);
152 154 goto out;
153 155 }
154 156
155 157 dnode_reallocate(dn, ot, blocksize, bonustype, bonuslen, tx);
156 158
157 159 dmu_tx_commit(tx);
158 160 out:
159 161 dnode_rele(dn, FTAG);
160 162
161 163 return (err);
162 164 }
163 165
164 166 int
165 167 dmu_object_free(objset_t *os, uint64_t object, dmu_tx_t *tx)
166 168 {
167 169 dnode_t *dn;
168 170 int err;
169 171
170 172 ASSERT(object != DMU_META_DNODE_OBJECT || dmu_tx_private_ok(tx));
171 173
172 174 err = dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED,
173 175 FTAG, &dn);
174 176 if (err)
175 177 return (err);
176 178
177 179 ASSERT(dn->dn_type != DMU_OT_NONE);
178 180 dnode_free_range(dn, 0, DMU_OBJECT_END, tx);
179 181 dnode_free(dn, tx);
180 182 dnode_rele(dn, FTAG);
181 183
182 184 return (0);
183 185 }
184 186
185 187 int
186 188 dmu_object_next(objset_t *os, uint64_t *objectp, boolean_t hole, uint64_t txg)
↓ open down ↓ |
147 lines elided |
↑ open up ↑ |
187 189 {
188 190 uint64_t offset = (*objectp + 1) << DNODE_SHIFT;
189 191 int error;
190 192
191 193 error = dnode_next_offset(DMU_META_DNODE(os),
192 194 (hole ? DNODE_FIND_HOLE : 0), &offset, 0, DNODES_PER_BLOCK, txg);
193 195
194 196 *objectp = offset >> DNODE_SHIFT;
195 197
196 198 return (error);
199 +}
200 +
201 +/*
202 + * Turn this object from old_type into DMU_OTN_ZAP_METADATA, and bump the
203 + * refcount on SPA_FEATURE_EXTENSIBLE_DATASET.
204 + *
205 + * Only for use from syncing context, on MOS objects.
206 + */
207 +void
208 +dmu_object_zapify(objset_t *mos, uint64_t object, dmu_object_type_t old_type,
209 + dmu_tx_t *tx)
210 +{
211 + dnode_t *dn;
212 +
213 + ASSERT(dmu_tx_is_syncing(tx));
214 +
215 + VERIFY0(dnode_hold(mos, object, FTAG, &dn));
216 + if (dn->dn_type == DMU_OTN_ZAP_METADATA) {
217 + dnode_rele(dn, FTAG);
218 + return;
219 + }
220 + ASSERT3U(dn->dn_type, ==, old_type);
221 + ASSERT0(dn->dn_maxblkid);
222 + dn->dn_next_type[tx->tx_txg & TXG_MASK] = dn->dn_type =
223 + DMU_OTN_ZAP_METADATA;
224 + dnode_setdirty(dn, tx);
225 + dnode_rele(dn, FTAG);
226 +
227 + mzap_create_impl(mos, object, 0, 0, tx);
228 +
229 + spa_feature_incr(dmu_objset_spa(mos),
230 + SPA_FEATURE_EXTENSIBLE_DATASET, tx);
231 +}
232 +
233 +void
234 +dmu_object_free_zapified(objset_t *mos, uint64_t object, dmu_tx_t *tx)
235 +{
236 + dnode_t *dn;
237 + dmu_object_type_t t;
238 +
239 + ASSERT(dmu_tx_is_syncing(tx));
240 +
241 + VERIFY0(dnode_hold(mos, object, FTAG, &dn));
242 + t = dn->dn_type;
243 + dnode_rele(dn, FTAG);
244 +
245 + if (t == DMU_OTN_ZAP_METADATA) {
246 + spa_feature_decr(dmu_objset_spa(mos),
247 + SPA_FEATURE_EXTENSIBLE_DATASET, tx);
248 + }
249 + VERIFY0(dmu_object_free(mos, object, tx));
197 250 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX