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_traverse.c
+++ new/usr/src/uts/common/fs/zfs/dmu_traverse.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 * 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/zfs_context.h>
27 27 #include <sys/dmu_objset.h>
28 28 #include <sys/dmu_traverse.h>
29 29 #include <sys/dsl_dataset.h>
30 30 #include <sys/dsl_dir.h>
31 31 #include <sys/dsl_pool.h>
32 32 #include <sys/dnode.h>
33 33 #include <sys/spa.h>
34 34 #include <sys/zio.h>
35 35 #include <sys/dmu_impl.h>
36 36 #include <sys/sa.h>
37 37 #include <sys/sa_impl.h>
38 38 #include <sys/callb.h>
39 39
40 40 int zfs_pd_blks_max = 100;
41 41
42 42 typedef struct prefetch_data {
43 43 kmutex_t pd_mtx;
44 44 kcondvar_t pd_cv;
45 45 int pd_blks_max;
46 46 int pd_blks_fetched;
47 47 int pd_flags;
48 48 boolean_t pd_cancel;
49 49 boolean_t pd_exited;
50 50 } prefetch_data_t;
51 51
52 52 typedef struct traverse_data {
53 53 spa_t *td_spa;
54 54 uint64_t td_objset;
55 55 blkptr_t *td_rootbp;
56 56 uint64_t td_min_txg;
57 57 zbookmark_t *td_resume;
58 58 int td_flags;
59 59 prefetch_data_t *td_pfd;
60 60 blkptr_cb_t *td_func;
61 61 void *td_arg;
62 62 } traverse_data_t;
63 63
64 64 static int traverse_dnode(traverse_data_t *td, const dnode_phys_t *dnp,
65 65 uint64_t objset, uint64_t object);
66 66 static void prefetch_dnode_metadata(traverse_data_t *td, const dnode_phys_t *,
67 67 uint64_t objset, uint64_t object);
68 68
69 69 static int
70 70 traverse_zil_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
71 71 {
72 72 traverse_data_t *td = arg;
73 73 zbookmark_t zb;
74 74
75 75 if (bp->blk_birth == 0)
76 76 return (0);
77 77
78 78 if (claim_txg == 0 && bp->blk_birth >= spa_first_txg(td->td_spa))
79 79 return (0);
80 80
81 81 SET_BOOKMARK(&zb, td->td_objset, ZB_ZIL_OBJECT, ZB_ZIL_LEVEL,
82 82 bp->blk_cksum.zc_word[ZIL_ZC_SEQ]);
83 83
84 84 (void) td->td_func(td->td_spa, zilog, bp, &zb, NULL, td->td_arg);
85 85
86 86 return (0);
87 87 }
88 88
89 89 static int
90 90 traverse_zil_record(zilog_t *zilog, lr_t *lrc, void *arg, uint64_t claim_txg)
91 91 {
92 92 traverse_data_t *td = arg;
93 93
94 94 if (lrc->lrc_txtype == TX_WRITE) {
95 95 lr_write_t *lr = (lr_write_t *)lrc;
96 96 blkptr_t *bp = &lr->lr_blkptr;
97 97 zbookmark_t zb;
98 98
99 99 if (bp->blk_birth == 0)
100 100 return (0);
101 101
102 102 if (claim_txg == 0 || bp->blk_birth < claim_txg)
103 103 return (0);
104 104
105 105 SET_BOOKMARK(&zb, td->td_objset, lr->lr_foid,
106 106 ZB_ZIL_LEVEL, lr->lr_offset / BP_GET_LSIZE(bp));
107 107
108 108 (void) td->td_func(td->td_spa, zilog, bp, &zb, NULL,
109 109 td->td_arg);
110 110 }
111 111 return (0);
112 112 }
113 113
114 114 static void
115 115 traverse_zil(traverse_data_t *td, zil_header_t *zh)
116 116 {
117 117 uint64_t claim_txg = zh->zh_claim_txg;
118 118 zilog_t *zilog;
119 119
120 120 /*
121 121 * We only want to visit blocks that have been claimed but not yet
122 122 * replayed; plus, in read-only mode, blocks that are already stable.
123 123 */
124 124 if (claim_txg == 0 && spa_writeable(td->td_spa))
125 125 return;
126 126
127 127 zilog = zil_alloc(spa_get_dsl(td->td_spa)->dp_meta_objset, zh);
128 128
129 129 (void) zil_parse(zilog, traverse_zil_block, traverse_zil_record, td,
130 130 claim_txg);
131 131
132 132 zil_free(zilog);
133 133 }
134 134
135 135 typedef enum resume_skip {
136 136 RESUME_SKIP_ALL,
137 137 RESUME_SKIP_NONE,
138 138 RESUME_SKIP_CHILDREN
139 139 } resume_skip_t;
140 140
141 141 /*
142 142 * Returns RESUME_SKIP_ALL if td indicates that we are resuming a traversal and
143 143 * the block indicated by zb does not need to be visited at all. Returns
144 144 * RESUME_SKIP_CHILDREN if we are resuming a post traversal and we reach the
145 145 * resume point. This indicates that this block should be visited but not its
146 146 * children (since they must have been visited in a previous traversal).
147 147 * Otherwise returns RESUME_SKIP_NONE.
148 148 */
149 149 static resume_skip_t
150 150 resume_skip_check(traverse_data_t *td, const dnode_phys_t *dnp,
151 151 const zbookmark_t *zb)
152 152 {
153 153 if (td->td_resume != NULL && !ZB_IS_ZERO(td->td_resume)) {
154 154 /*
155 155 * If we already visited this bp & everything below,
156 156 * don't bother doing it again.
157 157 */
158 158 if (zbookmark_is_before(dnp, zb, td->td_resume))
159 159 return (RESUME_SKIP_ALL);
160 160
161 161 /*
162 162 * If we found the block we're trying to resume from, zero
163 163 * the bookmark out to indicate that we have resumed.
164 164 */
165 165 ASSERT3U(zb->zb_object, <=, td->td_resume->zb_object);
166 166 if (bcmp(zb, td->td_resume, sizeof (*zb)) == 0) {
167 167 bzero(td->td_resume, sizeof (*zb));
168 168 if (td->td_flags & TRAVERSE_POST)
169 169 return (RESUME_SKIP_CHILDREN);
170 170 }
171 171 }
172 172 return (RESUME_SKIP_NONE);
173 173 }
174 174
175 175 static void
176 176 traverse_pause(traverse_data_t *td, const zbookmark_t *zb)
177 177 {
178 178 ASSERT(td->td_resume != NULL);
179 179 ASSERT0(zb->zb_level);
180 180 bcopy(zb, td->td_resume, sizeof (*td->td_resume));
181 181 }
182 182
183 183 static void
184 184 traverse_prefetch_metadata(traverse_data_t *td,
185 185 const blkptr_t *bp, const zbookmark_t *zb)
186 186 {
187 187 uint32_t flags = ARC_NOWAIT | ARC_PREFETCH;
188 188
189 189 if (!(td->td_flags & TRAVERSE_PREFETCH_METADATA))
190 190 return;
191 191 /*
192 192 * If we are in the process of resuming, don't prefetch, because
193 193 * some children will not be needed (and in fact may have already
194 194 * been freed).
195 195 */
196 196 if (td->td_resume != NULL && !ZB_IS_ZERO(td->td_resume))
197 197 return;
198 198 if (BP_IS_HOLE(bp) || bp->blk_birth <= td->td_min_txg)
199 199 return;
200 200 if (BP_GET_LEVEL(bp) == 0 && BP_GET_TYPE(bp) != DMU_OT_DNODE)
201 201 return;
202 202
203 203 (void) arc_read(NULL, td->td_spa, bp, NULL, NULL,
204 204 ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, zb);
205 205 }
206 206
207 207 static int
208 208 traverse_visitbp(traverse_data_t *td, const dnode_phys_t *dnp,
209 209 const blkptr_t *bp, const zbookmark_t *zb)
210 210 {
211 211 zbookmark_t czb;
212 212 int err = 0, lasterr = 0;
213 213 arc_buf_t *buf = NULL;
214 214 prefetch_data_t *pd = td->td_pfd;
215 215 boolean_t hard = td->td_flags & TRAVERSE_HARD;
216 216 boolean_t pause = B_FALSE;
217 217
218 218 switch (resume_skip_check(td, dnp, zb)) {
219 219 case RESUME_SKIP_ALL:
220 220 return (0);
221 221 case RESUME_SKIP_CHILDREN:
222 222 goto post;
223 223 case RESUME_SKIP_NONE:
224 224 break;
225 225 default:
226 226 ASSERT(0);
227 227 }
228 228
229 229 if (BP_IS_HOLE(bp)) {
230 230 err = td->td_func(td->td_spa, NULL, NULL, zb, dnp, td->td_arg);
231 231 return (err);
232 232 }
233 233
234 234 if (bp->blk_birth <= td->td_min_txg)
235 235 return (0);
236 236
237 237 if (pd && !pd->pd_exited &&
238 238 ((pd->pd_flags & TRAVERSE_PREFETCH_DATA) ||
239 239 BP_GET_TYPE(bp) == DMU_OT_DNODE || BP_GET_LEVEL(bp) > 0)) {
240 240 mutex_enter(&pd->pd_mtx);
241 241 ASSERT(pd->pd_blks_fetched >= 0);
242 242 while (pd->pd_blks_fetched == 0 && !pd->pd_exited)
243 243 cv_wait(&pd->pd_cv, &pd->pd_mtx);
244 244 pd->pd_blks_fetched--;
245 245 cv_broadcast(&pd->pd_cv);
246 246 mutex_exit(&pd->pd_mtx);
247 247 }
248 248
249 249 if (td->td_flags & TRAVERSE_PRE) {
250 250 err = td->td_func(td->td_spa, NULL, bp, zb, dnp,
251 251 td->td_arg);
252 252 if (err == TRAVERSE_VISIT_NO_CHILDREN)
253 253 return (0);
254 254 if (err == ERESTART)
255 255 pause = B_TRUE; /* handle pausing at a common point */
256 256 if (err != 0)
257 257 goto post;
258 258 }
259 259
260 260 if (BP_GET_LEVEL(bp) > 0) {
261 261 uint32_t flags = ARC_WAIT;
262 262 int i;
263 263 blkptr_t *cbp;
264 264 int epb = BP_GET_LSIZE(bp) >> SPA_BLKPTRSHIFT;
265 265
266 266 err = arc_read(NULL, td->td_spa, bp, arc_getbuf_func, &buf,
267 267 ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, zb);
268 268 if (err != 0)
269 269 return (err);
270 270 cbp = buf->b_data;
271 271
272 272 for (i = 0; i < epb; i++) {
273 273 SET_BOOKMARK(&czb, zb->zb_objset, zb->zb_object,
274 274 zb->zb_level - 1,
275 275 zb->zb_blkid * epb + i);
276 276 traverse_prefetch_metadata(td, &cbp[i], &czb);
277 277 }
278 278
279 279 /* recursively visitbp() blocks below this */
280 280 for (i = 0; i < epb; i++) {
281 281 SET_BOOKMARK(&czb, zb->zb_objset, zb->zb_object,
282 282 zb->zb_level - 1,
283 283 zb->zb_blkid * epb + i);
284 284 err = traverse_visitbp(td, dnp, &cbp[i], &czb);
285 285 if (err != 0) {
286 286 if (!hard)
287 287 break;
288 288 lasterr = err;
289 289 }
290 290 }
291 291 } else if (BP_GET_TYPE(bp) == DMU_OT_DNODE) {
292 292 uint32_t flags = ARC_WAIT;
293 293 int i;
294 294 int epb = BP_GET_LSIZE(bp) >> DNODE_SHIFT;
295 295
296 296 err = arc_read(NULL, td->td_spa, bp, arc_getbuf_func, &buf,
297 297 ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, zb);
298 298 if (err != 0)
299 299 return (err);
300 300 dnp = buf->b_data;
301 301
302 302 for (i = 0; i < epb; i++) {
303 303 prefetch_dnode_metadata(td, &dnp[i], zb->zb_objset,
304 304 zb->zb_blkid * epb + i);
305 305 }
306 306
307 307 /* recursively visitbp() blocks below this */
308 308 for (i = 0; i < epb; i++) {
309 309 err = traverse_dnode(td, &dnp[i], zb->zb_objset,
310 310 zb->zb_blkid * epb + i);
311 311 if (err != 0) {
312 312 if (!hard)
313 313 break;
314 314 lasterr = err;
315 315 }
316 316 }
317 317 } else if (BP_GET_TYPE(bp) == DMU_OT_OBJSET) {
318 318 uint32_t flags = ARC_WAIT;
319 319 objset_phys_t *osp;
320 320 dnode_phys_t *dnp;
321 321
322 322 err = arc_read(NULL, td->td_spa, bp, arc_getbuf_func, &buf,
323 323 ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, zb);
324 324 if (err != 0)
325 325 return (err);
326 326
327 327 osp = buf->b_data;
328 328 dnp = &osp->os_meta_dnode;
329 329 prefetch_dnode_metadata(td, dnp, zb->zb_objset,
330 330 DMU_META_DNODE_OBJECT);
331 331 if (arc_buf_size(buf) >= sizeof (objset_phys_t)) {
332 332 prefetch_dnode_metadata(td, &osp->os_userused_dnode,
333 333 zb->zb_objset, DMU_USERUSED_OBJECT);
334 334 prefetch_dnode_metadata(td, &osp->os_groupused_dnode,
335 335 zb->zb_objset, DMU_USERUSED_OBJECT);
336 336 }
337 337
338 338 err = traverse_dnode(td, dnp, zb->zb_objset,
339 339 DMU_META_DNODE_OBJECT);
340 340 if (err && hard) {
341 341 lasterr = err;
342 342 err = 0;
343 343 }
344 344 if (err == 0 && arc_buf_size(buf) >= sizeof (objset_phys_t)) {
345 345 dnp = &osp->os_userused_dnode;
346 346 err = traverse_dnode(td, dnp, zb->zb_objset,
347 347 DMU_USERUSED_OBJECT);
348 348 }
349 349 if (err && hard) {
350 350 lasterr = err;
351 351 err = 0;
352 352 }
353 353 if (err == 0 && arc_buf_size(buf) >= sizeof (objset_phys_t)) {
354 354 dnp = &osp->os_groupused_dnode;
355 355 err = traverse_dnode(td, dnp, zb->zb_objset,
356 356 DMU_GROUPUSED_OBJECT);
357 357 }
358 358 }
359 359
360 360 if (buf)
361 361 (void) arc_buf_remove_ref(buf, &buf);
362 362
363 363 post:
364 364 if (err == 0 && lasterr == 0 && (td->td_flags & TRAVERSE_POST)) {
365 365 err = td->td_func(td->td_spa, NULL, bp, zb, dnp, td->td_arg);
366 366 if (err == ERESTART)
367 367 pause = B_TRUE;
368 368 }
369 369
370 370 if (pause && td->td_resume != NULL) {
371 371 ASSERT3U(err, ==, ERESTART);
372 372 ASSERT(!hard);
373 373 traverse_pause(td, zb);
374 374 }
375 375
376 376 return (err != 0 ? err : lasterr);
377 377 }
378 378
379 379 static void
380 380 prefetch_dnode_metadata(traverse_data_t *td, const dnode_phys_t *dnp,
381 381 uint64_t objset, uint64_t object)
382 382 {
383 383 int j;
384 384 zbookmark_t czb;
385 385
386 386 for (j = 0; j < dnp->dn_nblkptr; j++) {
387 387 SET_BOOKMARK(&czb, objset, object, dnp->dn_nlevels - 1, j);
388 388 traverse_prefetch_metadata(td, &dnp->dn_blkptr[j], &czb);
389 389 }
390 390
391 391 if (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) {
392 392 SET_BOOKMARK(&czb, objset, object, 0, DMU_SPILL_BLKID);
393 393 traverse_prefetch_metadata(td, &dnp->dn_spill, &czb);
394 394 }
395 395 }
396 396
397 397 static int
398 398 traverse_dnode(traverse_data_t *td, const dnode_phys_t *dnp,
399 399 uint64_t objset, uint64_t object)
400 400 {
401 401 int j, err = 0, lasterr = 0;
402 402 zbookmark_t czb;
403 403 boolean_t hard = (td->td_flags & TRAVERSE_HARD);
404 404
405 405 for (j = 0; j < dnp->dn_nblkptr; j++) {
406 406 SET_BOOKMARK(&czb, objset, object, dnp->dn_nlevels - 1, j);
407 407 err = traverse_visitbp(td, dnp, &dnp->dn_blkptr[j], &czb);
408 408 if (err != 0) {
409 409 if (!hard)
410 410 break;
411 411 lasterr = err;
412 412 }
413 413 }
414 414
415 415 if (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) {
416 416 SET_BOOKMARK(&czb, objset, object, 0, DMU_SPILL_BLKID);
417 417 err = traverse_visitbp(td, dnp, &dnp->dn_spill, &czb);
418 418 if (err != 0) {
419 419 if (!hard)
420 420 return (err);
421 421 lasterr = err;
422 422 }
423 423 }
424 424 return (err != 0 ? err : lasterr);
425 425 }
426 426
427 427 /* ARGSUSED */
428 428 static int
429 429 traverse_prefetcher(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
430 430 const zbookmark_t *zb, const dnode_phys_t *dnp, void *arg)
431 431 {
432 432 prefetch_data_t *pfd = arg;
433 433 uint32_t aflags = ARC_NOWAIT | ARC_PREFETCH;
434 434
435 435 ASSERT(pfd->pd_blks_fetched >= 0);
436 436 if (pfd->pd_cancel)
437 437 return (SET_ERROR(EINTR));
438 438
439 439 if (bp == NULL || !((pfd->pd_flags & TRAVERSE_PREFETCH_DATA) ||
440 440 BP_GET_TYPE(bp) == DMU_OT_DNODE || BP_GET_LEVEL(bp) > 0) ||
441 441 BP_GET_TYPE(bp) == DMU_OT_INTENT_LOG)
442 442 return (0);
443 443
444 444 mutex_enter(&pfd->pd_mtx);
445 445 while (!pfd->pd_cancel && pfd->pd_blks_fetched >= pfd->pd_blks_max)
446 446 cv_wait(&pfd->pd_cv, &pfd->pd_mtx);
447 447 pfd->pd_blks_fetched++;
448 448 cv_broadcast(&pfd->pd_cv);
449 449 mutex_exit(&pfd->pd_mtx);
450 450
451 451 (void) arc_read(NULL, spa, bp, NULL, NULL, ZIO_PRIORITY_ASYNC_READ,
452 452 ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE, &aflags, zb);
453 453
454 454 return (0);
455 455 }
456 456
457 457 static void
458 458 traverse_prefetch_thread(void *arg)
459 459 {
460 460 traverse_data_t *td_main = arg;
461 461 traverse_data_t td = *td_main;
462 462 zbookmark_t czb;
463 463
464 464 td.td_func = traverse_prefetcher;
465 465 td.td_arg = td_main->td_pfd;
466 466 td.td_pfd = NULL;
467 467
468 468 SET_BOOKMARK(&czb, td.td_objset,
469 469 ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
470 470 (void) traverse_visitbp(&td, NULL, td.td_rootbp, &czb);
471 471
472 472 mutex_enter(&td_main->td_pfd->pd_mtx);
473 473 td_main->td_pfd->pd_exited = B_TRUE;
474 474 cv_broadcast(&td_main->td_pfd->pd_cv);
475 475 mutex_exit(&td_main->td_pfd->pd_mtx);
476 476 }
477 477
478 478 /*
479 479 * NB: dataset must not be changing on-disk (eg, is a snapshot or we are
480 480 * in syncing context).
481 481 */
482 482 static int
483 483 traverse_impl(spa_t *spa, dsl_dataset_t *ds, uint64_t objset, blkptr_t *rootbp,
484 484 uint64_t txg_start, zbookmark_t *resume, int flags,
485 485 blkptr_cb_t func, void *arg)
486 486 {
487 487 traverse_data_t td;
488 488 prefetch_data_t pd = { 0 };
489 489 zbookmark_t czb;
490 490 int err;
491 491
492 492 ASSERT(ds == NULL || objset == ds->ds_object);
493 493 ASSERT(!(flags & TRAVERSE_PRE) || !(flags & TRAVERSE_POST));
494 494
495 495 /*
496 496 * The data prefetching mechanism (the prefetch thread) is incompatible
497 497 * with resuming from a bookmark.
498 498 */
499 499 ASSERT(resume == NULL || !(flags & TRAVERSE_PREFETCH_DATA));
500 500
501 501 td.td_spa = spa;
502 502 td.td_objset = objset;
503 503 td.td_rootbp = rootbp;
504 504 td.td_min_txg = txg_start;
505 505 td.td_resume = resume;
506 506 td.td_func = func;
507 507 td.td_arg = arg;
508 508 td.td_pfd = &pd;
509 509 td.td_flags = flags;
510 510
511 511 pd.pd_blks_max = zfs_pd_blks_max;
512 512 pd.pd_flags = flags;
513 513 mutex_init(&pd.pd_mtx, NULL, MUTEX_DEFAULT, NULL);
514 514 cv_init(&pd.pd_cv, NULL, CV_DEFAULT, NULL);
515 515
516 516 /* See comment on ZIL traversal in dsl_scan_visitds. */
517 517 if (ds != NULL && !dsl_dataset_is_snapshot(ds) && !BP_IS_HOLE(rootbp)) {
518 518 uint32_t flags = ARC_WAIT;
519 519 objset_phys_t *osp;
520 520 arc_buf_t *buf;
521 521
522 522 err = arc_read(NULL, td.td_spa, rootbp,
523 523 arc_getbuf_func, &buf,
524 524 ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, NULL);
525 525 if (err != 0)
526 526 return (err);
527 527
528 528 osp = buf->b_data;
529 529 traverse_zil(&td, &osp->os_zil_header);
530 530 (void) arc_buf_remove_ref(buf, &buf);
531 531 }
532 532
533 533 if (!(flags & TRAVERSE_PREFETCH_DATA) ||
534 534 0 == taskq_dispatch(system_taskq, traverse_prefetch_thread,
535 535 &td, TQ_NOQUEUE))
536 536 pd.pd_exited = B_TRUE;
537 537
538 538 SET_BOOKMARK(&czb, td.td_objset,
539 539 ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
540 540 err = traverse_visitbp(&td, NULL, rootbp, &czb);
541 541
542 542 mutex_enter(&pd.pd_mtx);
543 543 pd.pd_cancel = B_TRUE;
544 544 cv_broadcast(&pd.pd_cv);
545 545 while (!pd.pd_exited)
546 546 cv_wait(&pd.pd_cv, &pd.pd_mtx);
547 547 mutex_exit(&pd.pd_mtx);
548 548
549 549 mutex_destroy(&pd.pd_mtx);
550 550 cv_destroy(&pd.pd_cv);
551 551
552 552 return (err);
553 553 }
554 554
555 555 /*
556 556 * NB: dataset must not be changing on-disk (eg, is a snapshot or we are
557 557 * in syncing context).
558 558 */
559 559 int
560 560 traverse_dataset(dsl_dataset_t *ds, uint64_t txg_start, int flags,
561 561 blkptr_cb_t func, void *arg)
562 562 {
563 563 return (traverse_impl(ds->ds_dir->dd_pool->dp_spa, ds, ds->ds_object,
564 564 &ds->ds_phys->ds_bp, txg_start, NULL, flags, func, arg));
565 565 }
566 566
567 567 int
568 568 traverse_dataset_destroyed(spa_t *spa, blkptr_t *blkptr,
569 569 uint64_t txg_start, zbookmark_t *resume, int flags,
570 570 blkptr_cb_t func, void *arg)
571 571 {
572 572 return (traverse_impl(spa, NULL, ZB_DESTROYED_OBJSET,
573 573 blkptr, txg_start, resume, flags, func, arg));
574 574 }
575 575
576 576 /*
577 577 * NB: pool must not be changing on-disk (eg, from zdb or sync context).
578 578 */
579 579 int
580 580 traverse_pool(spa_t *spa, uint64_t txg_start, int flags,
581 581 blkptr_cb_t func, void *arg)
582 582 {
583 583 int err, lasterr = 0;
584 584 uint64_t obj;
585 585 dsl_pool_t *dp = spa_get_dsl(spa);
586 586 objset_t *mos = dp->dp_meta_objset;
587 587 boolean_t hard = (flags & TRAVERSE_HARD);
588 588
589 589 /* visit the MOS */
590 590 err = traverse_impl(spa, NULL, 0, spa_get_rootblkptr(spa),
591 591 txg_start, NULL, flags, func, arg);
592 592 if (err != 0)
593 593 return (err);
594 594
595 595 /* visit each dataset */
596 596 for (obj = 1; err == 0 || (err != ESRCH && hard);
597 597 err = dmu_object_next(mos, &obj, FALSE, txg_start)) {
↓ open down ↓ |
597 lines elided |
↑ open up ↑ |
598 598 dmu_object_info_t doi;
599 599
600 600 err = dmu_object_info(mos, obj, &doi);
601 601 if (err != 0) {
602 602 if (!hard)
603 603 return (err);
604 604 lasterr = err;
605 605 continue;
606 606 }
607 607
608 - if (doi.doi_type == DMU_OT_DSL_DATASET) {
608 + if (doi.doi_bonus_type == DMU_OT_DSL_DATASET) {
609 609 dsl_dataset_t *ds;
610 610 uint64_t txg = txg_start;
611 611
612 612 dsl_pool_config_enter(dp, FTAG);
613 613 err = dsl_dataset_hold_obj(dp, obj, FTAG, &ds);
614 614 dsl_pool_config_exit(dp, FTAG);
615 615 if (err != 0) {
616 616 if (!hard)
617 617 return (err);
618 618 lasterr = err;
619 619 continue;
620 620 }
621 621 if (ds->ds_phys->ds_prev_snap_txg > txg)
622 622 txg = ds->ds_phys->ds_prev_snap_txg;
623 623 err = traverse_dataset(ds, txg, flags, func, arg);
624 624 dsl_dataset_rele(ds, FTAG);
625 625 if (err != 0) {
626 626 if (!hard)
627 627 return (err);
628 628 lasterr = err;
629 629 }
630 630 }
631 631 }
632 632 if (err == ESRCH)
633 633 err = 0;
634 634 return (err != 0 ? err : lasterr);
635 635 }
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX