Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/bptree.c
+++ new/usr/src/uts/common/fs/zfs/bptree.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
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
24 24 * Copyright (c) 2014 Integros [integros.com]
25 25 */
26 26
27 27 #include <sys/arc.h>
28 28 #include <sys/bptree.h>
29 29 #include <sys/dmu.h>
30 30 #include <sys/dmu_objset.h>
31 31 #include <sys/dmu_tx.h>
32 32 #include <sys/dmu_traverse.h>
33 33 #include <sys/dsl_dataset.h>
34 34 #include <sys/dsl_dir.h>
35 35 #include <sys/dsl_pool.h>
36 36 #include <sys/dnode.h>
37 37 #include <sys/refcount.h>
38 38 #include <sys/spa.h>
39 39
40 40 /*
41 41 * A bptree is a queue of root block pointers from destroyed datasets. When a
42 42 * dataset is destroyed its root block pointer is put on the end of the pool's
43 43 * bptree queue so the dataset's blocks can be freed asynchronously by
44 44 * dsl_scan_sync. This allows the delete operation to finish without traversing
45 45 * all the dataset's blocks.
46 46 *
47 47 * Note that while bt_begin and bt_end are only ever incremented in this code,
48 48 * they are effectively reset to 0 every time the entire bptree is freed because
49 49 * the bptree's object is destroyed and re-created.
50 50 */
51 51
52 52 struct bptree_args {
53 53 bptree_phys_t *ba_phys; /* data in bonus buffer, dirtied if freeing */
54 54 boolean_t ba_free; /* true if freeing during traversal */
55 55
56 56 bptree_itor_t *ba_func; /* function to call for each blockpointer */
57 57 void *ba_arg; /* caller supplied argument to ba_func */
58 58 dmu_tx_t *ba_tx; /* caller supplied tx, NULL if not freeing */
59 59 } bptree_args_t;
60 60
61 61 uint64_t
62 62 bptree_alloc(objset_t *os, dmu_tx_t *tx)
63 63 {
64 64 uint64_t obj;
65 65 dmu_buf_t *db;
66 66 bptree_phys_t *bt;
67 67
68 68 obj = dmu_object_alloc(os, DMU_OTN_UINT64_METADATA,
69 69 SPA_OLD_MAXBLOCKSIZE, DMU_OTN_UINT64_METADATA,
70 70 sizeof (bptree_phys_t), tx);
71 71
72 72 /*
73 73 * Bonus buffer contents are already initialized to 0, but for
74 74 * readability we make it explicit.
75 75 */
76 76 VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db));
77 77 dmu_buf_will_dirty(db, tx);
78 78 bt = db->db_data;
79 79 bt->bt_begin = 0;
80 80 bt->bt_end = 0;
81 81 bt->bt_bytes = 0;
82 82 bt->bt_comp = 0;
83 83 bt->bt_uncomp = 0;
84 84 dmu_buf_rele(db, FTAG);
85 85
86 86 return (obj);
87 87 }
88 88
89 89 int
90 90 bptree_free(objset_t *os, uint64_t obj, dmu_tx_t *tx)
91 91 {
92 92 dmu_buf_t *db;
93 93 bptree_phys_t *bt;
94 94
95 95 VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db));
96 96 bt = db->db_data;
97 97 ASSERT3U(bt->bt_begin, ==, bt->bt_end);
98 98 ASSERT0(bt->bt_bytes);
99 99 ASSERT0(bt->bt_comp);
100 100 ASSERT0(bt->bt_uncomp);
101 101 dmu_buf_rele(db, FTAG);
102 102
103 103 return (dmu_object_free(os, obj, tx));
104 104 }
105 105
106 106 boolean_t
107 107 bptree_is_empty(objset_t *os, uint64_t obj)
108 108 {
109 109 dmu_buf_t *db;
110 110 bptree_phys_t *bt;
111 111 boolean_t rv;
112 112
113 113 VERIFY0(dmu_bonus_hold(os, obj, FTAG, &db));
114 114 bt = db->db_data;
115 115 rv = (bt->bt_begin == bt->bt_end);
↓ open down ↓ |
115 lines elided |
↑ open up ↑ |
116 116 dmu_buf_rele(db, FTAG);
117 117 return (rv);
118 118 }
119 119
120 120 void
121 121 bptree_add(objset_t *os, uint64_t obj, blkptr_t *bp, uint64_t birth_txg,
122 122 uint64_t bytes, uint64_t comp, uint64_t uncomp, dmu_tx_t *tx)
123 123 {
124 124 dmu_buf_t *db;
125 125 bptree_phys_t *bt;
126 - bptree_entry_phys_t bte = { 0 };
126 + bptree_entry_phys_t bte = { .be_birth_txg = 0 };
127 127
128 128 /*
129 129 * bptree objects are in the pool mos, therefore they can only be
130 130 * modified in syncing context. Furthermore, this is only modified
131 131 * by the sync thread, so no locking is necessary.
132 132 */
133 133 ASSERT(dmu_tx_is_syncing(tx));
134 134
135 135 VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db));
136 136 bt = db->db_data;
137 137
138 138 bte.be_birth_txg = birth_txg;
139 139 bte.be_bp = *bp;
140 140 dmu_write(os, obj, bt->bt_end * sizeof (bte), sizeof (bte), &bte, tx);
141 141
142 142 dmu_buf_will_dirty(db, tx);
143 143 bt->bt_end++;
144 144 bt->bt_bytes += bytes;
145 145 bt->bt_comp += comp;
146 146 bt->bt_uncomp += uncomp;
147 147 dmu_buf_rele(db, FTAG);
148 148 }
149 149
150 150 /* ARGSUSED */
151 151 static int
152 152 bptree_visit_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
153 153 const zbookmark_phys_t *zb, const dnode_phys_t *dnp, void *arg)
154 154 {
155 155 int err;
156 156 struct bptree_args *ba = arg;
157 157
158 158 if (bp == NULL || BP_IS_HOLE(bp))
159 159 return (0);
160 160
161 161 err = ba->ba_func(ba->ba_arg, bp, ba->ba_tx);
162 162 if (err == 0 && ba->ba_free) {
163 163 ba->ba_phys->bt_bytes -= bp_get_dsize_sync(spa, bp);
164 164 ba->ba_phys->bt_comp -= BP_GET_PSIZE(bp);
165 165 ba->ba_phys->bt_uncomp -= BP_GET_UCSIZE(bp);
166 166 }
167 167 return (err);
168 168 }
169 169
170 170 /*
171 171 * If "free" is set:
172 172 * - It is assumed that "func" will be freeing the block pointers.
173 173 * - If "func" returns nonzero, the bookmark will be remembered and
174 174 * iteration will be restarted from this point on next invocation.
175 175 * - If an i/o error is encountered (e.g. "func" returns EIO or ECKSUM),
176 176 * bptree_iterate will remember the bookmark, continue traversing
177 177 * any additional entries, and return 0.
178 178 *
179 179 * If "free" is not set, traversal will stop and return an error if
180 180 * an i/o error is encountered.
181 181 *
182 182 * In either case, if zfs_free_leak_on_eio is set, i/o errors will be
183 183 * ignored and traversal will continue (i.e. TRAVERSE_HARD will be passed to
184 184 * traverse_dataset_destroyed()).
185 185 */
186 186 int
187 187 bptree_iterate(objset_t *os, uint64_t obj, boolean_t free, bptree_itor_t func,
188 188 void *arg, dmu_tx_t *tx)
189 189 {
190 190 boolean_t ioerr = B_FALSE;
191 191 int err;
192 192 uint64_t i;
193 193 dmu_buf_t *db;
194 194 struct bptree_args ba;
195 195
196 196 ASSERT(!free || dmu_tx_is_syncing(tx));
197 197
198 198 err = dmu_bonus_hold(os, obj, FTAG, &db);
199 199 if (err != 0)
200 200 return (err);
201 201
202 202 if (free)
203 203 dmu_buf_will_dirty(db, tx);
204 204
205 205 ba.ba_phys = db->db_data;
206 206 ba.ba_free = free;
207 207 ba.ba_func = func;
208 208 ba.ba_arg = arg;
209 209 ba.ba_tx = tx;
210 210
211 211 err = 0;
212 212 for (i = ba.ba_phys->bt_begin; i < ba.ba_phys->bt_end; i++) {
213 213 bptree_entry_phys_t bte;
214 214 int flags = TRAVERSE_PREFETCH_METADATA | TRAVERSE_POST;
215 215
216 216 err = dmu_read(os, obj, i * sizeof (bte), sizeof (bte),
217 217 &bte, DMU_READ_NO_PREFETCH);
218 218 if (err != 0)
219 219 break;
220 220
221 221 if (zfs_free_leak_on_eio)
222 222 flags |= TRAVERSE_HARD;
223 223 zfs_dbgmsg("bptree index %lld: traversing from min_txg=%lld "
224 224 "bookmark %lld/%lld/%lld/%lld",
225 225 (longlong_t)i,
226 226 (longlong_t)bte.be_birth_txg,
227 227 (longlong_t)bte.be_zb.zb_objset,
228 228 (longlong_t)bte.be_zb.zb_object,
229 229 (longlong_t)bte.be_zb.zb_level,
230 230 (longlong_t)bte.be_zb.zb_blkid);
231 231 err = traverse_dataset_destroyed(os->os_spa, &bte.be_bp,
232 232 bte.be_birth_txg, &bte.be_zb, flags,
233 233 bptree_visit_cb, &ba);
234 234 if (free) {
235 235 /*
236 236 * The callback has freed the visited block pointers.
237 237 * Record our traversal progress on disk, either by
238 238 * updating this record's bookmark, or by logically
239 239 * removing this record by advancing bt_begin.
240 240 */
241 241 if (err != 0) {
242 242 /* save bookmark for future resume */
243 243 ASSERT3U(bte.be_zb.zb_objset, ==,
244 244 ZB_DESTROYED_OBJSET);
245 245 ASSERT0(bte.be_zb.zb_level);
246 246 dmu_write(os, obj, i * sizeof (bte),
247 247 sizeof (bte), &bte, tx);
248 248 if (err == EIO || err == ECKSUM ||
249 249 err == ENXIO) {
250 250 /*
251 251 * Skip the rest of this tree and
252 252 * continue on to the next entry.
253 253 */
254 254 err = 0;
255 255 ioerr = B_TRUE;
256 256 } else {
257 257 break;
258 258 }
259 259 } else if (ioerr) {
260 260 /*
261 261 * This entry is finished, but there were
262 262 * i/o errors on previous entries, so we
263 263 * can't adjust bt_begin. Set this entry's
264 264 * be_birth_txg such that it will be
265 265 * treated as a no-op in future traversals.
266 266 */
267 267 bte.be_birth_txg = UINT64_MAX;
268 268 dmu_write(os, obj, i * sizeof (bte),
269 269 sizeof (bte), &bte, tx);
270 270 }
271 271
272 272 if (!ioerr) {
273 273 ba.ba_phys->bt_begin++;
274 274 (void) dmu_free_range(os, obj,
275 275 i * sizeof (bte), sizeof (bte), tx);
276 276 }
277 277 } else if (err != 0) {
278 278 break;
279 279 }
280 280 }
281 281
282 282 ASSERT(!free || err != 0 || ioerr ||
283 283 ba.ba_phys->bt_begin == ba.ba_phys->bt_end);
284 284
285 285 /* if all blocks are free there should be no used space */
286 286 if (ba.ba_phys->bt_begin == ba.ba_phys->bt_end) {
287 287 if (zfs_free_leak_on_eio) {
288 288 ba.ba_phys->bt_bytes = 0;
289 289 ba.ba_phys->bt_comp = 0;
290 290 ba.ba_phys->bt_uncomp = 0;
291 291 }
292 292
293 293 ASSERT0(ba.ba_phys->bt_bytes);
294 294 ASSERT0(ba.ba_phys->bt_comp);
295 295 ASSERT0(ba.ba_phys->bt_uncomp);
296 296 }
297 297
298 298 dmu_buf_rele(db, FTAG);
299 299
300 300 return (err);
301 301 }
↓ open down ↓ |
165 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX