Print this page
2619 asynchronous destruction of ZFS file systems
2747 SPA versioning with zfs feature flags
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <gwilson@delphix.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Dan Kruchinin <dan.kruchinin@gmail.com>
Approved by: Dan McDonald <danmcd@nexenta.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/zfs/dsl_scan.c
+++ new/usr/src/uts/common/fs/zfs/dsl_scan.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 *
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 + * Copyright (c) 2012 by Delphix. All rights reserved.
23 24 */
24 25
25 26 #include <sys/dsl_scan.h>
26 27 #include <sys/dsl_pool.h>
27 28 #include <sys/dsl_dataset.h>
28 29 #include <sys/dsl_prop.h>
29 30 #include <sys/dsl_dir.h>
30 31 #include <sys/dsl_synctask.h>
31 32 #include <sys/dnode.h>
32 33 #include <sys/dmu_tx.h>
33 34 #include <sys/dmu_objset.h>
34 35 #include <sys/arc.h>
35 36 #include <sys/zap.h>
36 37 #include <sys/zio.h>
|
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
37 38 #include <sys/zfs_context.h>
38 39 #include <sys/fs/zfs.h>
39 40 #include <sys/zfs_znode.h>
40 41 #include <sys/spa_impl.h>
41 42 #include <sys/vdev_impl.h>
42 43 #include <sys/zil_impl.h>
43 44 #include <sys/zio_checksum.h>
44 45 #include <sys/ddt.h>
45 46 #include <sys/sa.h>
46 47 #include <sys/sa_impl.h>
48 +#include <sys/zfeature.h>
47 49 #ifdef _KERNEL
48 50 #include <sys/zfs_vfsops.h>
49 51 #endif
50 52
51 53 typedef int (scan_cb_t)(dsl_pool_t *, const blkptr_t *, const zbookmark_t *);
52 54
53 55 static scan_cb_t dsl_scan_defrag_cb;
54 56 static scan_cb_t dsl_scan_scrub_cb;
55 57 static scan_cb_t dsl_scan_remove_cb;
56 58 static dsl_syncfunc_t dsl_scan_cancel_sync;
57 59 static void dsl_scan_sync_state(dsl_scan_t *, dmu_tx_t *tx);
58 60
59 61 int zfs_top_maxinflight = 32; /* maximum I/Os per top-level */
60 62 int zfs_resilver_delay = 2; /* number of ticks to delay resilver */
61 63 int zfs_scrub_delay = 4; /* number of ticks to delay scrub */
62 64 int zfs_scan_idle = 50; /* idle window in clock ticks */
63 65
64 66 int zfs_scan_min_time_ms = 1000; /* min millisecs to scrub per txg */
65 67 int zfs_free_min_time_ms = 1000; /* min millisecs to free per txg */
66 68 int zfs_resilver_min_time_ms = 3000; /* min millisecs to resilver per txg */
67 69 boolean_t zfs_no_scrub_io = B_FALSE; /* set to disable scrub i/o */
68 70 boolean_t zfs_no_scrub_prefetch = B_FALSE; /* set to disable srub prefetching */
69 71 enum ddt_class zfs_scrub_ddt_class_max = DDT_CLASS_DUPLICATE;
70 72 int dsl_scan_delay_completion = B_FALSE; /* set to delay scan completion */
71 73
72 74 #define DSL_SCAN_IS_SCRUB_RESILVER(scn) \
73 75 ((scn)->scn_phys.scn_func == POOL_SCAN_SCRUB || \
74 76 (scn)->scn_phys.scn_func == POOL_SCAN_RESILVER)
75 77
76 78 extern int zfs_txg_timeout;
77 79
78 80 /* the order has to match pool_scan_type */
79 81 static scan_cb_t *scan_funcs[POOL_SCAN_FUNCS] = {
80 82 NULL,
81 83 dsl_scan_scrub_cb, /* POOL_SCAN_SCRUB */
82 84 dsl_scan_scrub_cb, /* POOL_SCAN_RESILVER */
83 85 };
84 86
85 87 int
86 88 dsl_scan_init(dsl_pool_t *dp, uint64_t txg)
87 89 {
88 90 int err;
89 91 dsl_scan_t *scn;
90 92 spa_t *spa = dp->dp_spa;
91 93 uint64_t f;
92 94
93 95 scn = dp->dp_scan = kmem_zalloc(sizeof (dsl_scan_t), KM_SLEEP);
94 96 scn->scn_dp = dp;
95 97
96 98 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
97 99 "scrub_func", sizeof (uint64_t), 1, &f);
98 100 if (err == 0) {
99 101 /*
100 102 * There was an old-style scrub in progress. Restart a
101 103 * new-style scrub from the beginning.
102 104 */
103 105 scn->scn_restart_txg = txg;
104 106 zfs_dbgmsg("old-style scrub was in progress; "
105 107 "restarting new-style scrub in txg %llu",
106 108 scn->scn_restart_txg);
107 109
108 110 /*
109 111 * Load the queue obj from the old location so that it
110 112 * can be freed by dsl_scan_done().
111 113 */
112 114 (void) zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
113 115 "scrub_queue", sizeof (uint64_t), 1,
114 116 &scn->scn_phys.scn_queue_obj);
115 117 } else {
116 118 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
117 119 DMU_POOL_SCAN, sizeof (uint64_t), SCAN_PHYS_NUMINTS,
118 120 &scn->scn_phys);
119 121 if (err == ENOENT)
120 122 return (0);
121 123 else if (err)
122 124 return (err);
123 125
124 126 if (scn->scn_phys.scn_state == DSS_SCANNING &&
125 127 spa_prev_software_version(dp->dp_spa) < SPA_VERSION_SCAN) {
126 128 /*
127 129 * A new-type scrub was in progress on an old
128 130 * pool, and the pool was accessed by old
129 131 * software. Restart from the beginning, since
130 132 * the old software may have changed the pool in
131 133 * the meantime.
132 134 */
133 135 scn->scn_restart_txg = txg;
134 136 zfs_dbgmsg("new-style scrub was modified "
135 137 "by old software; restarting in txg %llu",
136 138 scn->scn_restart_txg);
137 139 }
138 140 }
139 141
140 142 spa_scan_stat_init(spa);
141 143 return (0);
142 144 }
143 145
144 146 void
145 147 dsl_scan_fini(dsl_pool_t *dp)
146 148 {
147 149 if (dp->dp_scan) {
148 150 kmem_free(dp->dp_scan, sizeof (dsl_scan_t));
149 151 dp->dp_scan = NULL;
150 152 }
151 153 }
152 154
153 155 /* ARGSUSED */
154 156 static int
155 157 dsl_scan_setup_check(void *arg1, void *arg2, dmu_tx_t *tx)
156 158 {
157 159 dsl_scan_t *scn = arg1;
158 160
159 161 if (scn->scn_phys.scn_state == DSS_SCANNING)
160 162 return (EBUSY);
161 163
162 164 return (0);
163 165 }
164 166
165 167 /* ARGSUSED */
166 168 static void
167 169 dsl_scan_setup_sync(void *arg1, void *arg2, dmu_tx_t *tx)
168 170 {
169 171 dsl_scan_t *scn = arg1;
170 172 pool_scan_func_t *funcp = arg2;
171 173 dmu_object_type_t ot = 0;
172 174 dsl_pool_t *dp = scn->scn_dp;
173 175 spa_t *spa = dp->dp_spa;
174 176
175 177 ASSERT(scn->scn_phys.scn_state != DSS_SCANNING);
176 178 ASSERT(*funcp > POOL_SCAN_NONE && *funcp < POOL_SCAN_FUNCS);
177 179 bzero(&scn->scn_phys, sizeof (scn->scn_phys));
178 180 scn->scn_phys.scn_func = *funcp;
179 181 scn->scn_phys.scn_state = DSS_SCANNING;
180 182 scn->scn_phys.scn_min_txg = 0;
181 183 scn->scn_phys.scn_max_txg = tx->tx_txg;
182 184 scn->scn_phys.scn_ddt_class_max = DDT_CLASSES - 1; /* the entire DDT */
183 185 scn->scn_phys.scn_start_time = gethrestime_sec();
184 186 scn->scn_phys.scn_errors = 0;
185 187 scn->scn_phys.scn_to_examine = spa->spa_root_vdev->vdev_stat.vs_alloc;
186 188 scn->scn_restart_txg = 0;
187 189 spa_scan_stat_init(spa);
188 190
189 191 if (DSL_SCAN_IS_SCRUB_RESILVER(scn)) {
190 192 scn->scn_phys.scn_ddt_class_max = zfs_scrub_ddt_class_max;
191 193
192 194 /* rewrite all disk labels */
193 195 vdev_config_dirty(spa->spa_root_vdev);
194 196
195 197 if (vdev_resilver_needed(spa->spa_root_vdev,
196 198 &scn->scn_phys.scn_min_txg, &scn->scn_phys.scn_max_txg)) {
197 199 spa_event_notify(spa, NULL, ESC_ZFS_RESILVER_START);
198 200 } else {
199 201 spa_event_notify(spa, NULL, ESC_ZFS_SCRUB_START);
200 202 }
201 203
202 204 spa->spa_scrub_started = B_TRUE;
203 205 /*
204 206 * If this is an incremental scrub, limit the DDT scrub phase
205 207 * to just the auto-ditto class (for correctness); the rest
206 208 * of the scrub should go faster using top-down pruning.
207 209 */
208 210 if (scn->scn_phys.scn_min_txg > TXG_INITIAL)
209 211 scn->scn_phys.scn_ddt_class_max = DDT_CLASS_DITTO;
210 212
211 213 }
212 214
213 215 /* back to the generic stuff */
214 216
215 217 if (dp->dp_blkstats == NULL) {
216 218 dp->dp_blkstats =
217 219 kmem_alloc(sizeof (zfs_all_blkstats_t), KM_SLEEP);
218 220 }
219 221 bzero(dp->dp_blkstats, sizeof (zfs_all_blkstats_t));
220 222
221 223 if (spa_version(spa) < SPA_VERSION_DSL_SCRUB)
222 224 ot = DMU_OT_ZAP_OTHER;
223 225
224 226 scn->scn_phys.scn_queue_obj = zap_create(dp->dp_meta_objset,
225 227 ot ? ot : DMU_OT_SCAN_QUEUE, DMU_OT_NONE, 0, tx);
226 228
227 229 dsl_scan_sync_state(scn, tx);
228 230
229 231 spa_history_log_internal(LOG_POOL_SCAN, spa, tx,
230 232 "func=%u mintxg=%llu maxtxg=%llu",
231 233 *funcp, scn->scn_phys.scn_min_txg, scn->scn_phys.scn_max_txg);
232 234 }
233 235
234 236 /* ARGSUSED */
235 237 static void
236 238 dsl_scan_done(dsl_scan_t *scn, boolean_t complete, dmu_tx_t *tx)
237 239 {
238 240 static const char *old_names[] = {
239 241 "scrub_bookmark",
240 242 "scrub_ddt_bookmark",
241 243 "scrub_ddt_class_max",
242 244 "scrub_queue",
243 245 "scrub_min_txg",
244 246 "scrub_max_txg",
245 247 "scrub_func",
246 248 "scrub_errors",
247 249 NULL
248 250 };
249 251
250 252 dsl_pool_t *dp = scn->scn_dp;
251 253 spa_t *spa = dp->dp_spa;
252 254 int i;
253 255
254 256 /* Remove any remnants of an old-style scrub. */
255 257 for (i = 0; old_names[i]; i++) {
256 258 (void) zap_remove(dp->dp_meta_objset,
257 259 DMU_POOL_DIRECTORY_OBJECT, old_names[i], tx);
258 260 }
259 261
260 262 if (scn->scn_phys.scn_queue_obj != 0) {
261 263 VERIFY(0 == dmu_object_free(dp->dp_meta_objset,
262 264 scn->scn_phys.scn_queue_obj, tx));
263 265 scn->scn_phys.scn_queue_obj = 0;
264 266 }
265 267
266 268 /*
267 269 * If we were "restarted" from a stopped state, don't bother
268 270 * with anything else.
269 271 */
270 272 if (scn->scn_phys.scn_state != DSS_SCANNING)
271 273 return;
272 274
273 275 if (complete)
274 276 scn->scn_phys.scn_state = DSS_FINISHED;
275 277 else
276 278 scn->scn_phys.scn_state = DSS_CANCELED;
277 279
278 280 spa_history_log_internal(LOG_POOL_SCAN_DONE, spa, tx,
279 281 "complete=%u", complete);
280 282
281 283 if (DSL_SCAN_IS_SCRUB_RESILVER(scn)) {
282 284 mutex_enter(&spa->spa_scrub_lock);
283 285 while (spa->spa_scrub_inflight > 0) {
284 286 cv_wait(&spa->spa_scrub_io_cv,
285 287 &spa->spa_scrub_lock);
286 288 }
287 289 mutex_exit(&spa->spa_scrub_lock);
288 290 spa->spa_scrub_started = B_FALSE;
289 291 spa->spa_scrub_active = B_FALSE;
290 292
291 293 /*
292 294 * If the scrub/resilver completed, update all DTLs to
293 295 * reflect this. Whether it succeeded or not, vacate
294 296 * all temporary scrub DTLs.
295 297 */
296 298 vdev_dtl_reassess(spa->spa_root_vdev, tx->tx_txg,
297 299 complete ? scn->scn_phys.scn_max_txg : 0, B_TRUE);
298 300 if (complete) {
299 301 spa_event_notify(spa, NULL, scn->scn_phys.scn_min_txg ?
300 302 ESC_ZFS_RESILVER_FINISH : ESC_ZFS_SCRUB_FINISH);
301 303 }
302 304 spa_errlog_rotate(spa);
303 305
304 306 /*
305 307 * We may have finished replacing a device.
306 308 * Let the async thread assess this and handle the detach.
307 309 */
308 310 spa_async_request(spa, SPA_ASYNC_RESILVER_DONE);
309 311 }
310 312
311 313 scn->scn_phys.scn_end_time = gethrestime_sec();
312 314 }
313 315
314 316 /* ARGSUSED */
315 317 static int
316 318 dsl_scan_cancel_check(void *arg1, void *arg2, dmu_tx_t *tx)
317 319 {
318 320 dsl_scan_t *scn = arg1;
319 321
320 322 if (scn->scn_phys.scn_state != DSS_SCANNING)
321 323 return (ENOENT);
322 324 return (0);
323 325 }
324 326
325 327 /* ARGSUSED */
326 328 static void
327 329 dsl_scan_cancel_sync(void *arg1, void *arg2, dmu_tx_t *tx)
328 330 {
329 331 dsl_scan_t *scn = arg1;
330 332
331 333 dsl_scan_done(scn, B_FALSE, tx);
332 334 dsl_scan_sync_state(scn, tx);
333 335 }
334 336
335 337 int
336 338 dsl_scan_cancel(dsl_pool_t *dp)
337 339 {
338 340 boolean_t complete = B_FALSE;
339 341 int err;
340 342
341 343 err = dsl_sync_task_do(dp, dsl_scan_cancel_check,
342 344 dsl_scan_cancel_sync, dp->dp_scan, &complete, 3);
343 345 return (err);
344 346 }
345 347
346 348 static void dsl_scan_visitbp(blkptr_t *bp,
347 349 const zbookmark_t *zb, dnode_phys_t *dnp, arc_buf_t *pbuf,
348 350 dsl_dataset_t *ds, dsl_scan_t *scn, dmu_objset_type_t ostype,
349 351 dmu_tx_t *tx);
350 352 static void dsl_scan_visitdnode(dsl_scan_t *, dsl_dataset_t *ds,
351 353 dmu_objset_type_t ostype,
352 354 dnode_phys_t *dnp, arc_buf_t *buf, uint64_t object, dmu_tx_t *tx);
353 355
354 356 void
355 357 dsl_free(dsl_pool_t *dp, uint64_t txg, const blkptr_t *bp)
356 358 {
357 359 zio_free(dp->dp_spa, txg, bp);
358 360 }
359 361
360 362 void
361 363 dsl_free_sync(zio_t *pio, dsl_pool_t *dp, uint64_t txg, const blkptr_t *bpp)
362 364 {
363 365 ASSERT(dsl_pool_sync_context(dp));
364 366 zio_nowait(zio_free_sync(pio, dp->dp_spa, txg, bpp, pio->io_flags));
365 367 }
366 368
367 369 int
368 370 dsl_read(zio_t *pio, spa_t *spa, const blkptr_t *bpp, arc_buf_t *pbuf,
369 371 arc_done_func_t *done, void *private, int priority, int zio_flags,
370 372 uint32_t *arc_flags, const zbookmark_t *zb)
371 373 {
372 374 return (arc_read(pio, spa, bpp, pbuf, done, private,
373 375 priority, zio_flags, arc_flags, zb));
374 376 }
|
↓ open down ↓ |
318 lines elided |
↑ open up ↑ |
375 377
376 378 int
377 379 dsl_read_nolock(zio_t *pio, spa_t *spa, const blkptr_t *bpp,
378 380 arc_done_func_t *done, void *private, int priority, int zio_flags,
379 381 uint32_t *arc_flags, const zbookmark_t *zb)
380 382 {
381 383 return (arc_read_nolock(pio, spa, bpp, done, private,
382 384 priority, zio_flags, arc_flags, zb));
383 385 }
384 386
385 -static boolean_t
386 -bookmark_is_zero(const zbookmark_t *zb)
387 -{
388 - return (zb->zb_objset == 0 && zb->zb_object == 0 &&
389 - zb->zb_level == 0 && zb->zb_blkid == 0);
390 -}
391 -
392 -/* dnp is the dnode for zb1->zb_object */
393 -static boolean_t
394 -bookmark_is_before(const dnode_phys_t *dnp, const zbookmark_t *zb1,
395 - const zbookmark_t *zb2)
396 -{
397 - uint64_t zb1nextL0, zb2thisobj;
398 -
399 - ASSERT(zb1->zb_objset == zb2->zb_objset);
400 - ASSERT(zb2->zb_level == 0);
401 -
402 - /*
403 - * A bookmark in the deadlist is considered to be after
404 - * everything else.
405 - */
406 - if (zb2->zb_object == DMU_DEADLIST_OBJECT)
407 - return (B_TRUE);
408 -
409 - /* The objset_phys_t isn't before anything. */
410 - if (dnp == NULL)
411 - return (B_FALSE);
412 -
413 - zb1nextL0 = (zb1->zb_blkid + 1) <<
414 - ((zb1->zb_level) * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT));
415 -
416 - zb2thisobj = zb2->zb_object ? zb2->zb_object :
417 - zb2->zb_blkid << (DNODE_BLOCK_SHIFT - DNODE_SHIFT);
418 -
419 - if (zb1->zb_object == DMU_META_DNODE_OBJECT) {
420 - uint64_t nextobj = zb1nextL0 *
421 - (dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT) >> DNODE_SHIFT;
422 - return (nextobj <= zb2thisobj);
423 - }
424 -
425 - if (zb1->zb_object < zb2thisobj)
426 - return (B_TRUE);
427 - if (zb1->zb_object > zb2thisobj)
428 - return (B_FALSE);
429 - if (zb2->zb_object == DMU_META_DNODE_OBJECT)
430 - return (B_FALSE);
431 - return (zb1nextL0 <= zb2->zb_blkid);
432 -}
433 -
434 387 static uint64_t
435 388 dsl_scan_ds_maxtxg(dsl_dataset_t *ds)
436 389 {
437 390 uint64_t smt = ds->ds_dir->dd_pool->dp_scan->scn_phys.scn_max_txg;
438 391 if (dsl_dataset_is_snapshot(ds))
439 392 return (MIN(smt, ds->ds_phys->ds_creation_txg));
440 393 return (smt);
441 394 }
442 395
443 396 static void
444 397 dsl_scan_sync_state(dsl_scan_t *scn, dmu_tx_t *tx)
445 398 {
446 399 VERIFY(0 == zap_update(scn->scn_dp->dp_meta_objset,
447 400 DMU_POOL_DIRECTORY_OBJECT,
448 401 DMU_POOL_SCAN, sizeof (uint64_t), SCAN_PHYS_NUMINTS,
449 402 &scn->scn_phys, tx));
450 403 }
451 404
452 405 static boolean_t
453 406 dsl_scan_check_pause(dsl_scan_t *scn, const zbookmark_t *zb)
454 407 {
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
455 408 uint64_t elapsed_nanosecs;
456 409 int mintime;
457 410
458 411 /* we never skip user/group accounting objects */
459 412 if (zb && (int64_t)zb->zb_object < 0)
460 413 return (B_FALSE);
461 414
462 415 if (scn->scn_pausing)
463 416 return (B_TRUE); /* we're already pausing */
464 417
465 - if (!bookmark_is_zero(&scn->scn_phys.scn_bookmark))
418 + if (!ZB_IS_ZERO(&scn->scn_phys.scn_bookmark))
466 419 return (B_FALSE); /* we're resuming */
467 420
468 421 /* We only know how to resume from level-0 blocks. */
469 422 if (zb && zb->zb_level != 0)
470 423 return (B_FALSE);
471 424
472 425 mintime = (scn->scn_phys.scn_func == POOL_SCAN_RESILVER) ?
473 426 zfs_resilver_min_time_ms : zfs_scan_min_time_ms;
474 427 elapsed_nanosecs = gethrtime() - scn->scn_sync_start_time;
475 428 if (elapsed_nanosecs / NANOSEC > zfs_txg_timeout ||
476 429 (elapsed_nanosecs / MICROSEC > mintime &&
477 430 txg_sync_waiting(scn->scn_dp)) ||
478 431 spa_shutting_down(scn->scn_dp->dp_spa)) {
479 432 if (zb) {
480 433 dprintf("pausing at bookmark %llx/%llx/%llx/%llx\n",
481 434 (longlong_t)zb->zb_objset,
482 435 (longlong_t)zb->zb_object,
483 436 (longlong_t)zb->zb_level,
484 437 (longlong_t)zb->zb_blkid);
485 438 scn->scn_phys.scn_bookmark = *zb;
486 439 }
487 440 dprintf("pausing at DDT bookmark %llx/%llx/%llx/%llx\n",
488 441 (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_class,
489 442 (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_type,
490 443 (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_checksum,
491 444 (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_cursor);
492 445 scn->scn_pausing = B_TRUE;
493 446 return (B_TRUE);
494 447 }
495 448 return (B_FALSE);
496 449 }
497 450
498 451 typedef struct zil_scan_arg {
499 452 dsl_pool_t *zsa_dp;
500 453 zil_header_t *zsa_zh;
501 454 } zil_scan_arg_t;
502 455
503 456 /* ARGSUSED */
504 457 static int
505 458 dsl_scan_zil_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
506 459 {
507 460 zil_scan_arg_t *zsa = arg;
508 461 dsl_pool_t *dp = zsa->zsa_dp;
509 462 dsl_scan_t *scn = dp->dp_scan;
510 463 zil_header_t *zh = zsa->zsa_zh;
511 464 zbookmark_t zb;
512 465
513 466 if (bp->blk_birth <= scn->scn_phys.scn_cur_min_txg)
514 467 return (0);
515 468
516 469 /*
517 470 * One block ("stubby") can be allocated a long time ago; we
518 471 * want to visit that one because it has been allocated
519 472 * (on-disk) even if it hasn't been claimed (even though for
520 473 * scrub there's nothing to do to it).
521 474 */
522 475 if (claim_txg == 0 && bp->blk_birth >= spa_first_txg(dp->dp_spa))
523 476 return (0);
524 477
525 478 SET_BOOKMARK(&zb, zh->zh_log.blk_cksum.zc_word[ZIL_ZC_OBJSET],
526 479 ZB_ZIL_OBJECT, ZB_ZIL_LEVEL, bp->blk_cksum.zc_word[ZIL_ZC_SEQ]);
527 480
528 481 VERIFY(0 == scan_funcs[scn->scn_phys.scn_func](dp, bp, &zb));
529 482 return (0);
530 483 }
531 484
532 485 /* ARGSUSED */
533 486 static int
534 487 dsl_scan_zil_record(zilog_t *zilog, lr_t *lrc, void *arg, uint64_t claim_txg)
535 488 {
536 489 if (lrc->lrc_txtype == TX_WRITE) {
537 490 zil_scan_arg_t *zsa = arg;
538 491 dsl_pool_t *dp = zsa->zsa_dp;
539 492 dsl_scan_t *scn = dp->dp_scan;
540 493 zil_header_t *zh = zsa->zsa_zh;
541 494 lr_write_t *lr = (lr_write_t *)lrc;
542 495 blkptr_t *bp = &lr->lr_blkptr;
543 496 zbookmark_t zb;
544 497
545 498 if (bp->blk_birth <= scn->scn_phys.scn_cur_min_txg)
546 499 return (0);
547 500
548 501 /*
549 502 * birth can be < claim_txg if this record's txg is
550 503 * already txg sync'ed (but this log block contains
551 504 * other records that are not synced)
552 505 */
553 506 if (claim_txg == 0 || bp->blk_birth < claim_txg)
554 507 return (0);
555 508
556 509 SET_BOOKMARK(&zb, zh->zh_log.blk_cksum.zc_word[ZIL_ZC_OBJSET],
557 510 lr->lr_foid, ZB_ZIL_LEVEL,
558 511 lr->lr_offset / BP_GET_LSIZE(bp));
559 512
560 513 VERIFY(0 == scan_funcs[scn->scn_phys.scn_func](dp, bp, &zb));
561 514 }
562 515 return (0);
563 516 }
564 517
565 518 static void
566 519 dsl_scan_zil(dsl_pool_t *dp, zil_header_t *zh)
567 520 {
568 521 uint64_t claim_txg = zh->zh_claim_txg;
569 522 zil_scan_arg_t zsa = { dp, zh };
570 523 zilog_t *zilog;
571 524
572 525 /*
573 526 * We only want to visit blocks that have been claimed but not yet
574 527 * replayed (or, in read-only mode, blocks that *would* be claimed).
575 528 */
576 529 if (claim_txg == 0 && spa_writeable(dp->dp_spa))
577 530 return;
578 531
579 532 zilog = zil_alloc(dp->dp_meta_objset, zh);
580 533
581 534 (void) zil_parse(zilog, dsl_scan_zil_block, dsl_scan_zil_record, &zsa,
582 535 claim_txg);
583 536
584 537 zil_free(zilog);
585 538 }
586 539
587 540 /* ARGSUSED */
588 541 static void
589 542 dsl_scan_prefetch(dsl_scan_t *scn, arc_buf_t *buf, blkptr_t *bp,
590 543 uint64_t objset, uint64_t object, uint64_t blkid)
591 544 {
592 545 zbookmark_t czb;
593 546 uint32_t flags = ARC_NOWAIT | ARC_PREFETCH;
594 547
595 548 if (zfs_no_scrub_prefetch)
596 549 return;
597 550
598 551 if (BP_IS_HOLE(bp) || bp->blk_birth <= scn->scn_phys.scn_min_txg ||
599 552 (BP_GET_LEVEL(bp) == 0 && BP_GET_TYPE(bp) != DMU_OT_DNODE))
600 553 return;
601 554
602 555 SET_BOOKMARK(&czb, objset, object, BP_GET_LEVEL(bp), blkid);
603 556
604 557 /*
605 558 * XXX need to make sure all of these arc_read() prefetches are
606 559 * done before setting xlateall (similar to dsl_read())
607 560 */
608 561 (void) arc_read(scn->scn_zio_root, scn->scn_dp->dp_spa, bp,
609 562 buf, NULL, NULL, ZIO_PRIORITY_ASYNC_READ,
|
↓ open down ↓ |
134 lines elided |
↑ open up ↑ |
610 563 ZIO_FLAG_CANFAIL | ZIO_FLAG_SCAN_THREAD, &flags, &czb);
611 564 }
612 565
613 566 static boolean_t
614 567 dsl_scan_check_resume(dsl_scan_t *scn, const dnode_phys_t *dnp,
615 568 const zbookmark_t *zb)
616 569 {
617 570 /*
618 571 * We never skip over user/group accounting objects (obj<0)
619 572 */
620 - if (!bookmark_is_zero(&scn->scn_phys.scn_bookmark) &&
573 + if (!ZB_IS_ZERO(&scn->scn_phys.scn_bookmark) &&
621 574 (int64_t)zb->zb_object >= 0) {
622 575 /*
623 576 * If we already visited this bp & everything below (in
624 577 * a prior txg sync), don't bother doing it again.
625 578 */
626 - if (bookmark_is_before(dnp, zb, &scn->scn_phys.scn_bookmark))
579 + if (zbookmark_is_before(dnp, zb, &scn->scn_phys.scn_bookmark))
627 580 return (B_TRUE);
628 581
629 582 /*
630 583 * If we found the block we're trying to resume from, or
631 584 * we went past it to a different object, zero it out to
632 585 * indicate that it's OK to start checking for pausing
633 586 * again.
634 587 */
635 588 if (bcmp(zb, &scn->scn_phys.scn_bookmark, sizeof (*zb)) == 0 ||
636 589 zb->zb_object > scn->scn_phys.scn_bookmark.zb_object) {
637 590 dprintf("resuming at %llx/%llx/%llx/%llx\n",
638 591 (longlong_t)zb->zb_objset,
639 592 (longlong_t)zb->zb_object,
640 593 (longlong_t)zb->zb_level,
641 594 (longlong_t)zb->zb_blkid);
642 595 bzero(&scn->scn_phys.scn_bookmark, sizeof (*zb));
643 596 }
644 597 }
645 598 return (B_FALSE);
646 599 }
647 600
648 601 /*
649 602 * Return nonzero on i/o error.
650 603 * Return new buf to write out in *bufp.
651 604 */
652 605 static int
653 606 dsl_scan_recurse(dsl_scan_t *scn, dsl_dataset_t *ds, dmu_objset_type_t ostype,
654 607 dnode_phys_t *dnp, const blkptr_t *bp,
655 608 const zbookmark_t *zb, dmu_tx_t *tx, arc_buf_t **bufp)
656 609 {
657 610 dsl_pool_t *dp = scn->scn_dp;
658 611 int zio_flags = ZIO_FLAG_CANFAIL | ZIO_FLAG_SCAN_THREAD;
659 612 int err;
660 613
661 614 if (BP_GET_LEVEL(bp) > 0) {
662 615 uint32_t flags = ARC_WAIT;
663 616 int i;
664 617 blkptr_t *cbp;
665 618 int epb = BP_GET_LSIZE(bp) >> SPA_BLKPTRSHIFT;
666 619
667 620 err = arc_read_nolock(NULL, dp->dp_spa, bp,
668 621 arc_getbuf_func, bufp,
669 622 ZIO_PRIORITY_ASYNC_READ, zio_flags, &flags, zb);
670 623 if (err) {
671 624 scn->scn_phys.scn_errors++;
672 625 return (err);
673 626 }
674 627 for (i = 0, cbp = (*bufp)->b_data; i < epb; i++, cbp++) {
675 628 dsl_scan_prefetch(scn, *bufp, cbp, zb->zb_objset,
676 629 zb->zb_object, zb->zb_blkid * epb + i);
677 630 }
678 631 for (i = 0, cbp = (*bufp)->b_data; i < epb; i++, cbp++) {
679 632 zbookmark_t czb;
680 633
681 634 SET_BOOKMARK(&czb, zb->zb_objset, zb->zb_object,
682 635 zb->zb_level - 1,
683 636 zb->zb_blkid * epb + i);
684 637 dsl_scan_visitbp(cbp, &czb, dnp,
685 638 *bufp, ds, scn, ostype, tx);
686 639 }
687 640 } else if (BP_GET_TYPE(bp) == DMU_OT_USERGROUP_USED) {
688 641 uint32_t flags = ARC_WAIT;
689 642
690 643 err = arc_read_nolock(NULL, dp->dp_spa, bp,
691 644 arc_getbuf_func, bufp,
692 645 ZIO_PRIORITY_ASYNC_READ, zio_flags, &flags, zb);
693 646 if (err) {
694 647 scn->scn_phys.scn_errors++;
695 648 return (err);
696 649 }
697 650 } else if (BP_GET_TYPE(bp) == DMU_OT_DNODE) {
698 651 uint32_t flags = ARC_WAIT;
699 652 dnode_phys_t *cdnp;
700 653 int i, j;
701 654 int epb = BP_GET_LSIZE(bp) >> DNODE_SHIFT;
702 655
703 656 err = arc_read_nolock(NULL, dp->dp_spa, bp,
704 657 arc_getbuf_func, bufp,
705 658 ZIO_PRIORITY_ASYNC_READ, zio_flags, &flags, zb);
706 659 if (err) {
707 660 scn->scn_phys.scn_errors++;
708 661 return (err);
709 662 }
710 663 for (i = 0, cdnp = (*bufp)->b_data; i < epb; i++, cdnp++) {
711 664 for (j = 0; j < cdnp->dn_nblkptr; j++) {
712 665 blkptr_t *cbp = &cdnp->dn_blkptr[j];
713 666 dsl_scan_prefetch(scn, *bufp, cbp,
714 667 zb->zb_objset, zb->zb_blkid * epb + i, j);
715 668 }
716 669 }
717 670 for (i = 0, cdnp = (*bufp)->b_data; i < epb; i++, cdnp++) {
718 671 dsl_scan_visitdnode(scn, ds, ostype,
719 672 cdnp, *bufp, zb->zb_blkid * epb + i, tx);
720 673 }
721 674
722 675 } else if (BP_GET_TYPE(bp) == DMU_OT_OBJSET) {
723 676 uint32_t flags = ARC_WAIT;
724 677 objset_phys_t *osp;
725 678
726 679 err = arc_read_nolock(NULL, dp->dp_spa, bp,
727 680 arc_getbuf_func, bufp,
728 681 ZIO_PRIORITY_ASYNC_READ, zio_flags, &flags, zb);
729 682 if (err) {
730 683 scn->scn_phys.scn_errors++;
731 684 return (err);
732 685 }
733 686
734 687 osp = (*bufp)->b_data;
735 688
736 689 dsl_scan_visitdnode(scn, ds, osp->os_type,
737 690 &osp->os_meta_dnode, *bufp, DMU_META_DNODE_OBJECT, tx);
738 691
739 692 if (OBJSET_BUF_HAS_USERUSED(*bufp)) {
740 693 /*
741 694 * We also always visit user/group accounting
742 695 * objects, and never skip them, even if we are
743 696 * pausing. This is necessary so that the space
744 697 * deltas from this txg get integrated.
745 698 */
746 699 dsl_scan_visitdnode(scn, ds, osp->os_type,
747 700 &osp->os_groupused_dnode, *bufp,
748 701 DMU_GROUPUSED_OBJECT, tx);
749 702 dsl_scan_visitdnode(scn, ds, osp->os_type,
750 703 &osp->os_userused_dnode, *bufp,
751 704 DMU_USERUSED_OBJECT, tx);
752 705 }
753 706 }
754 707
755 708 return (0);
756 709 }
757 710
758 711 static void
759 712 dsl_scan_visitdnode(dsl_scan_t *scn, dsl_dataset_t *ds,
760 713 dmu_objset_type_t ostype, dnode_phys_t *dnp, arc_buf_t *buf,
761 714 uint64_t object, dmu_tx_t *tx)
762 715 {
763 716 int j;
764 717
765 718 for (j = 0; j < dnp->dn_nblkptr; j++) {
766 719 zbookmark_t czb;
767 720
768 721 SET_BOOKMARK(&czb, ds ? ds->ds_object : 0, object,
769 722 dnp->dn_nlevels - 1, j);
770 723 dsl_scan_visitbp(&dnp->dn_blkptr[j],
771 724 &czb, dnp, buf, ds, scn, ostype, tx);
772 725 }
773 726
774 727 if (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) {
775 728 zbookmark_t czb;
776 729 SET_BOOKMARK(&czb, ds ? ds->ds_object : 0, object,
777 730 0, DMU_SPILL_BLKID);
778 731 dsl_scan_visitbp(&dnp->dn_spill,
779 732 &czb, dnp, buf, ds, scn, ostype, tx);
780 733 }
781 734 }
782 735
783 736 /*
784 737 * The arguments are in this order because mdb can only print the
785 738 * first 5; we want them to be useful.
786 739 */
787 740 static void
788 741 dsl_scan_visitbp(blkptr_t *bp, const zbookmark_t *zb,
789 742 dnode_phys_t *dnp, arc_buf_t *pbuf,
790 743 dsl_dataset_t *ds, dsl_scan_t *scn, dmu_objset_type_t ostype,
791 744 dmu_tx_t *tx)
792 745 {
793 746 dsl_pool_t *dp = scn->scn_dp;
794 747 arc_buf_t *buf = NULL;
795 748 blkptr_t bp_toread = *bp;
796 749
797 750 /* ASSERT(pbuf == NULL || arc_released(pbuf)); */
798 751
799 752 if (dsl_scan_check_pause(scn, zb))
800 753 return;
801 754
802 755 if (dsl_scan_check_resume(scn, dnp, zb))
803 756 return;
804 757
805 758 if (bp->blk_birth == 0)
806 759 return;
807 760
808 761 scn->scn_visited_this_txg++;
|
↓ open down ↓ |
172 lines elided |
↑ open up ↑ |
809 762
810 763 dprintf_bp(bp,
811 764 "visiting ds=%p/%llu zb=%llx/%llx/%llx/%llx buf=%p bp=%p",
812 765 ds, ds ? ds->ds_object : 0,
813 766 zb->zb_objset, zb->zb_object, zb->zb_level, zb->zb_blkid,
814 767 pbuf, bp);
815 768
816 769 if (bp->blk_birth <= scn->scn_phys.scn_cur_min_txg)
817 770 return;
818 771
819 - if (BP_GET_TYPE(bp) != DMU_OT_USERGROUP_USED) {
820 - /*
821 - * For non-user-accounting blocks, we need to read the
822 - * new bp (from a deleted snapshot, found in
823 - * check_existing_xlation). If we used the old bp,
824 - * pointers inside this block from before we resumed
825 - * would be untranslated.
826 - *
827 - * For user-accounting blocks, we need to read the old
828 - * bp, because we will apply the entire space delta to
829 - * it (original untranslated -> translations from
830 - * deleted snap -> now).
831 - */
832 - bp_toread = *bp;
833 - }
834 -
835 772 if (dsl_scan_recurse(scn, ds, ostype, dnp, &bp_toread, zb, tx,
836 773 &buf) != 0)
837 774 return;
838 775
839 776 /*
840 777 * If dsl_scan_ddt() has aready visited this block, it will have
841 778 * already done any translations or scrubbing, so don't call the
842 779 * callback again.
843 780 */
844 781 if (ddt_class_contains(dp->dp_spa,
845 782 scn->scn_phys.scn_ddt_class_max, bp)) {
846 783 ASSERT(buf == NULL);
847 784 return;
848 785 }
849 786
850 787 /*
851 788 * If this block is from the future (after cur_max_txg), then we
852 789 * are doing this on behalf of a deleted snapshot, and we will
853 790 * revisit the future block on the next pass of this dataset.
854 791 * Don't scan it now unless we need to because something
855 792 * under it was modified.
856 793 */
857 794 if (bp->blk_birth <= scn->scn_phys.scn_cur_max_txg) {
858 795 scan_funcs[scn->scn_phys.scn_func](dp, bp, zb);
859 796 }
860 797 if (buf)
861 798 (void) arc_buf_remove_ref(buf, &buf);
862 799 }
863 800
864 801 static void
865 802 dsl_scan_visit_rootbp(dsl_scan_t *scn, dsl_dataset_t *ds, blkptr_t *bp,
866 803 dmu_tx_t *tx)
867 804 {
868 805 zbookmark_t zb;
869 806
870 807 SET_BOOKMARK(&zb, ds ? ds->ds_object : DMU_META_OBJSET,
871 808 ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
872 809 dsl_scan_visitbp(bp, &zb, NULL, NULL,
873 810 ds, scn, DMU_OST_NONE, tx);
874 811
875 812 dprintf_ds(ds, "finished scan%s", "");
876 813 }
877 814
878 815 void
879 816 dsl_scan_ds_destroyed(dsl_dataset_t *ds, dmu_tx_t *tx)
880 817 {
881 818 dsl_pool_t *dp = ds->ds_dir->dd_pool;
882 819 dsl_scan_t *scn = dp->dp_scan;
883 820 uint64_t mintxg;
884 821
885 822 if (scn->scn_phys.scn_state != DSS_SCANNING)
886 823 return;
887 824
888 825 if (scn->scn_phys.scn_bookmark.zb_objset == ds->ds_object) {
889 826 if (dsl_dataset_is_snapshot(ds)) {
890 827 /* Note, scn_cur_{min,max}_txg stays the same. */
891 828 scn->scn_phys.scn_bookmark.zb_objset =
892 829 ds->ds_phys->ds_next_snap_obj;
893 830 zfs_dbgmsg("destroying ds %llu; currently traversing; "
894 831 "reset zb_objset to %llu",
895 832 (u_longlong_t)ds->ds_object,
896 833 (u_longlong_t)ds->ds_phys->ds_next_snap_obj);
897 834 scn->scn_phys.scn_flags |= DSF_VISIT_DS_AGAIN;
898 835 } else {
899 836 SET_BOOKMARK(&scn->scn_phys.scn_bookmark,
900 837 ZB_DESTROYED_OBJSET, 0, 0, 0);
901 838 zfs_dbgmsg("destroying ds %llu; currently traversing; "
902 839 "reset bookmark to -1,0,0,0",
903 840 (u_longlong_t)ds->ds_object);
904 841 }
905 842 } else if (zap_lookup_int_key(dp->dp_meta_objset,
906 843 scn->scn_phys.scn_queue_obj, ds->ds_object, &mintxg) == 0) {
907 844 ASSERT3U(ds->ds_phys->ds_num_children, <=, 1);
908 845 VERIFY3U(0, ==, zap_remove_int(dp->dp_meta_objset,
909 846 scn->scn_phys.scn_queue_obj, ds->ds_object, tx));
910 847 if (dsl_dataset_is_snapshot(ds)) {
911 848 /*
912 849 * We keep the same mintxg; it could be >
913 850 * ds_creation_txg if the previous snapshot was
914 851 * deleted too.
915 852 */
916 853 VERIFY(zap_add_int_key(dp->dp_meta_objset,
917 854 scn->scn_phys.scn_queue_obj,
918 855 ds->ds_phys->ds_next_snap_obj, mintxg, tx) == 0);
919 856 zfs_dbgmsg("destroying ds %llu; in queue; "
920 857 "replacing with %llu",
921 858 (u_longlong_t)ds->ds_object,
922 859 (u_longlong_t)ds->ds_phys->ds_next_snap_obj);
923 860 } else {
924 861 zfs_dbgmsg("destroying ds %llu; in queue; removing",
925 862 (u_longlong_t)ds->ds_object);
926 863 }
927 864 } else {
928 865 zfs_dbgmsg("destroying ds %llu; ignoring",
929 866 (u_longlong_t)ds->ds_object);
930 867 }
931 868
932 869 /*
933 870 * dsl_scan_sync() should be called after this, and should sync
934 871 * out our changed state, but just to be safe, do it here.
935 872 */
936 873 dsl_scan_sync_state(scn, tx);
937 874 }
938 875
939 876 void
940 877 dsl_scan_ds_snapshotted(dsl_dataset_t *ds, dmu_tx_t *tx)
941 878 {
942 879 dsl_pool_t *dp = ds->ds_dir->dd_pool;
943 880 dsl_scan_t *scn = dp->dp_scan;
944 881 uint64_t mintxg;
945 882
946 883 if (scn->scn_phys.scn_state != DSS_SCANNING)
947 884 return;
948 885
949 886 ASSERT(ds->ds_phys->ds_prev_snap_obj != 0);
950 887
951 888 if (scn->scn_phys.scn_bookmark.zb_objset == ds->ds_object) {
952 889 scn->scn_phys.scn_bookmark.zb_objset =
953 890 ds->ds_phys->ds_prev_snap_obj;
954 891 zfs_dbgmsg("snapshotting ds %llu; currently traversing; "
955 892 "reset zb_objset to %llu",
956 893 (u_longlong_t)ds->ds_object,
957 894 (u_longlong_t)ds->ds_phys->ds_prev_snap_obj);
958 895 } else if (zap_lookup_int_key(dp->dp_meta_objset,
959 896 scn->scn_phys.scn_queue_obj, ds->ds_object, &mintxg) == 0) {
960 897 VERIFY3U(0, ==, zap_remove_int(dp->dp_meta_objset,
961 898 scn->scn_phys.scn_queue_obj, ds->ds_object, tx));
962 899 VERIFY(zap_add_int_key(dp->dp_meta_objset,
963 900 scn->scn_phys.scn_queue_obj,
964 901 ds->ds_phys->ds_prev_snap_obj, mintxg, tx) == 0);
965 902 zfs_dbgmsg("snapshotting ds %llu; in queue; "
966 903 "replacing with %llu",
967 904 (u_longlong_t)ds->ds_object,
968 905 (u_longlong_t)ds->ds_phys->ds_prev_snap_obj);
969 906 }
970 907 dsl_scan_sync_state(scn, tx);
971 908 }
972 909
973 910 void
974 911 dsl_scan_ds_clone_swapped(dsl_dataset_t *ds1, dsl_dataset_t *ds2, dmu_tx_t *tx)
975 912 {
976 913 dsl_pool_t *dp = ds1->ds_dir->dd_pool;
977 914 dsl_scan_t *scn = dp->dp_scan;
978 915 uint64_t mintxg;
979 916
980 917 if (scn->scn_phys.scn_state != DSS_SCANNING)
981 918 return;
982 919
983 920 if (scn->scn_phys.scn_bookmark.zb_objset == ds1->ds_object) {
984 921 scn->scn_phys.scn_bookmark.zb_objset = ds2->ds_object;
985 922 zfs_dbgmsg("clone_swap ds %llu; currently traversing; "
986 923 "reset zb_objset to %llu",
987 924 (u_longlong_t)ds1->ds_object,
988 925 (u_longlong_t)ds2->ds_object);
989 926 } else if (scn->scn_phys.scn_bookmark.zb_objset == ds2->ds_object) {
990 927 scn->scn_phys.scn_bookmark.zb_objset = ds1->ds_object;
991 928 zfs_dbgmsg("clone_swap ds %llu; currently traversing; "
992 929 "reset zb_objset to %llu",
993 930 (u_longlong_t)ds2->ds_object,
994 931 (u_longlong_t)ds1->ds_object);
995 932 }
996 933
997 934 if (zap_lookup_int_key(dp->dp_meta_objset, scn->scn_phys.scn_queue_obj,
998 935 ds1->ds_object, &mintxg) == 0) {
999 936 int err;
1000 937
1001 938 ASSERT3U(mintxg, ==, ds1->ds_phys->ds_prev_snap_txg);
1002 939 ASSERT3U(mintxg, ==, ds2->ds_phys->ds_prev_snap_txg);
1003 940 VERIFY3U(0, ==, zap_remove_int(dp->dp_meta_objset,
1004 941 scn->scn_phys.scn_queue_obj, ds1->ds_object, tx));
1005 942 err = zap_add_int_key(dp->dp_meta_objset,
1006 943 scn->scn_phys.scn_queue_obj, ds2->ds_object, mintxg, tx);
1007 944 VERIFY(err == 0 || err == EEXIST);
1008 945 if (err == EEXIST) {
1009 946 /* Both were there to begin with */
1010 947 VERIFY(0 == zap_add_int_key(dp->dp_meta_objset,
1011 948 scn->scn_phys.scn_queue_obj,
1012 949 ds1->ds_object, mintxg, tx));
1013 950 }
1014 951 zfs_dbgmsg("clone_swap ds %llu; in queue; "
1015 952 "replacing with %llu",
1016 953 (u_longlong_t)ds1->ds_object,
1017 954 (u_longlong_t)ds2->ds_object);
1018 955 } else if (zap_lookup_int_key(dp->dp_meta_objset,
1019 956 scn->scn_phys.scn_queue_obj, ds2->ds_object, &mintxg) == 0) {
1020 957 ASSERT3U(mintxg, ==, ds1->ds_phys->ds_prev_snap_txg);
1021 958 ASSERT3U(mintxg, ==, ds2->ds_phys->ds_prev_snap_txg);
1022 959 VERIFY3U(0, ==, zap_remove_int(dp->dp_meta_objset,
1023 960 scn->scn_phys.scn_queue_obj, ds2->ds_object, tx));
1024 961 VERIFY(0 == zap_add_int_key(dp->dp_meta_objset,
1025 962 scn->scn_phys.scn_queue_obj, ds1->ds_object, mintxg, tx));
1026 963 zfs_dbgmsg("clone_swap ds %llu; in queue; "
1027 964 "replacing with %llu",
1028 965 (u_longlong_t)ds2->ds_object,
1029 966 (u_longlong_t)ds1->ds_object);
1030 967 }
1031 968
1032 969 dsl_scan_sync_state(scn, tx);
1033 970 }
1034 971
1035 972 struct enqueue_clones_arg {
1036 973 dmu_tx_t *tx;
1037 974 uint64_t originobj;
1038 975 };
1039 976
1040 977 /* ARGSUSED */
1041 978 static int
1042 979 enqueue_clones_cb(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
1043 980 {
1044 981 struct enqueue_clones_arg *eca = arg;
1045 982 dsl_dataset_t *ds;
1046 983 int err;
1047 984 dsl_pool_t *dp = spa->spa_dsl_pool;
1048 985 dsl_scan_t *scn = dp->dp_scan;
1049 986
1050 987 err = dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds);
1051 988 if (err)
1052 989 return (err);
1053 990
1054 991 if (ds->ds_dir->dd_phys->dd_origin_obj == eca->originobj) {
1055 992 while (ds->ds_phys->ds_prev_snap_obj != eca->originobj) {
1056 993 dsl_dataset_t *prev;
1057 994 err = dsl_dataset_hold_obj(dp,
1058 995 ds->ds_phys->ds_prev_snap_obj, FTAG, &prev);
1059 996
1060 997 dsl_dataset_rele(ds, FTAG);
1061 998 if (err)
1062 999 return (err);
1063 1000 ds = prev;
1064 1001 }
1065 1002 VERIFY(zap_add_int_key(dp->dp_meta_objset,
1066 1003 scn->scn_phys.scn_queue_obj, ds->ds_object,
1067 1004 ds->ds_phys->ds_prev_snap_txg, eca->tx) == 0);
1068 1005 }
1069 1006 dsl_dataset_rele(ds, FTAG);
1070 1007 return (0);
1071 1008 }
1072 1009
1073 1010 static void
1074 1011 dsl_scan_visitds(dsl_scan_t *scn, uint64_t dsobj, dmu_tx_t *tx)
1075 1012 {
1076 1013 dsl_pool_t *dp = scn->scn_dp;
1077 1014 dsl_dataset_t *ds;
1078 1015 objset_t *os;
1079 1016
1080 1017 VERIFY3U(0, ==, dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
1081 1018
1082 1019 if (dmu_objset_from_ds(ds, &os))
1083 1020 goto out;
1084 1021
1085 1022 /*
1086 1023 * Only the ZIL in the head (non-snapshot) is valid. Even though
1087 1024 * snapshots can have ZIL block pointers (which may be the same
1088 1025 * BP as in the head), they must be ignored. So we traverse the
1089 1026 * ZIL here, rather than in scan_recurse(), because the regular
1090 1027 * snapshot block-sharing rules don't apply to it.
1091 1028 */
1092 1029 if (DSL_SCAN_IS_SCRUB_RESILVER(scn) && !dsl_dataset_is_snapshot(ds))
1093 1030 dsl_scan_zil(dp, &os->os_zil_header);
1094 1031
1095 1032 /*
1096 1033 * Iterate over the bps in this ds.
1097 1034 */
1098 1035 dmu_buf_will_dirty(ds->ds_dbuf, tx);
1099 1036 dsl_scan_visit_rootbp(scn, ds, &ds->ds_phys->ds_bp, tx);
1100 1037
1101 1038 char *dsname = kmem_alloc(ZFS_MAXNAMELEN, KM_SLEEP);
1102 1039 dsl_dataset_name(ds, dsname);
1103 1040 zfs_dbgmsg("scanned dataset %llu (%s) with min=%llu max=%llu; "
1104 1041 "pausing=%u",
1105 1042 (longlong_t)dsobj, dsname,
1106 1043 (longlong_t)scn->scn_phys.scn_cur_min_txg,
1107 1044 (longlong_t)scn->scn_phys.scn_cur_max_txg,
1108 1045 (int)scn->scn_pausing);
1109 1046 kmem_free(dsname, ZFS_MAXNAMELEN);
1110 1047
1111 1048 if (scn->scn_pausing)
1112 1049 goto out;
1113 1050
1114 1051 /*
1115 1052 * We've finished this pass over this dataset.
1116 1053 */
1117 1054
1118 1055 /*
1119 1056 * If we did not completely visit this dataset, do another pass.
1120 1057 */
1121 1058 if (scn->scn_phys.scn_flags & DSF_VISIT_DS_AGAIN) {
1122 1059 zfs_dbgmsg("incomplete pass; visiting again");
1123 1060 scn->scn_phys.scn_flags &= ~DSF_VISIT_DS_AGAIN;
1124 1061 VERIFY(zap_add_int_key(dp->dp_meta_objset,
1125 1062 scn->scn_phys.scn_queue_obj, ds->ds_object,
1126 1063 scn->scn_phys.scn_cur_max_txg, tx) == 0);
1127 1064 goto out;
1128 1065 }
1129 1066
1130 1067 /*
1131 1068 * Add descendent datasets to work queue.
1132 1069 */
1133 1070 if (ds->ds_phys->ds_next_snap_obj != 0) {
1134 1071 VERIFY(zap_add_int_key(dp->dp_meta_objset,
1135 1072 scn->scn_phys.scn_queue_obj, ds->ds_phys->ds_next_snap_obj,
1136 1073 ds->ds_phys->ds_creation_txg, tx) == 0);
1137 1074 }
1138 1075 if (ds->ds_phys->ds_num_children > 1) {
1139 1076 boolean_t usenext = B_FALSE;
1140 1077 if (ds->ds_phys->ds_next_clones_obj != 0) {
1141 1078 uint64_t count;
1142 1079 /*
1143 1080 * A bug in a previous version of the code could
1144 1081 * cause upgrade_clones_cb() to not set
1145 1082 * ds_next_snap_obj when it should, leading to a
1146 1083 * missing entry. Therefore we can only use the
1147 1084 * next_clones_obj when its count is correct.
1148 1085 */
1149 1086 int err = zap_count(dp->dp_meta_objset,
1150 1087 ds->ds_phys->ds_next_clones_obj, &count);
1151 1088 if (err == 0 &&
1152 1089 count == ds->ds_phys->ds_num_children - 1)
1153 1090 usenext = B_TRUE;
1154 1091 }
1155 1092
1156 1093 if (usenext) {
1157 1094 VERIFY(zap_join_key(dp->dp_meta_objset,
1158 1095 ds->ds_phys->ds_next_clones_obj,
1159 1096 scn->scn_phys.scn_queue_obj,
1160 1097 ds->ds_phys->ds_creation_txg, tx) == 0);
1161 1098 } else {
1162 1099 struct enqueue_clones_arg eca;
1163 1100 eca.tx = tx;
1164 1101 eca.originobj = ds->ds_object;
1165 1102
1166 1103 (void) dmu_objset_find_spa(ds->ds_dir->dd_pool->dp_spa,
1167 1104 NULL, enqueue_clones_cb, &eca, DS_FIND_CHILDREN);
1168 1105 }
1169 1106 }
1170 1107
1171 1108 out:
1172 1109 dsl_dataset_rele(ds, FTAG);
1173 1110 }
1174 1111
1175 1112 /* ARGSUSED */
1176 1113 static int
1177 1114 enqueue_cb(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
1178 1115 {
1179 1116 dmu_tx_t *tx = arg;
1180 1117 dsl_dataset_t *ds;
1181 1118 int err;
1182 1119 dsl_pool_t *dp = spa->spa_dsl_pool;
1183 1120 dsl_scan_t *scn = dp->dp_scan;
1184 1121
1185 1122 err = dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds);
1186 1123 if (err)
1187 1124 return (err);
1188 1125
1189 1126 while (ds->ds_phys->ds_prev_snap_obj != 0) {
1190 1127 dsl_dataset_t *prev;
1191 1128 err = dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj,
1192 1129 FTAG, &prev);
1193 1130 if (err) {
1194 1131 dsl_dataset_rele(ds, FTAG);
1195 1132 return (err);
1196 1133 }
1197 1134
1198 1135 /*
1199 1136 * If this is a clone, we don't need to worry about it for now.
1200 1137 */
1201 1138 if (prev->ds_phys->ds_next_snap_obj != ds->ds_object) {
1202 1139 dsl_dataset_rele(ds, FTAG);
1203 1140 dsl_dataset_rele(prev, FTAG);
1204 1141 return (0);
1205 1142 }
1206 1143 dsl_dataset_rele(ds, FTAG);
1207 1144 ds = prev;
1208 1145 }
1209 1146
1210 1147 VERIFY(zap_add_int_key(dp->dp_meta_objset, scn->scn_phys.scn_queue_obj,
1211 1148 ds->ds_object, ds->ds_phys->ds_prev_snap_txg, tx) == 0);
1212 1149 dsl_dataset_rele(ds, FTAG);
1213 1150 return (0);
1214 1151 }
1215 1152
1216 1153 /*
1217 1154 * Scrub/dedup interaction.
1218 1155 *
1219 1156 * If there are N references to a deduped block, we don't want to scrub it
1220 1157 * N times -- ideally, we should scrub it exactly once.
1221 1158 *
1222 1159 * We leverage the fact that the dde's replication class (enum ddt_class)
1223 1160 * is ordered from highest replication class (DDT_CLASS_DITTO) to lowest
1224 1161 * (DDT_CLASS_UNIQUE) so that we may walk the DDT in that order.
1225 1162 *
1226 1163 * To prevent excess scrubbing, the scrub begins by walking the DDT
1227 1164 * to find all blocks with refcnt > 1, and scrubs each of these once.
1228 1165 * Since there are two replication classes which contain blocks with
1229 1166 * refcnt > 1, we scrub the highest replication class (DDT_CLASS_DITTO) first.
1230 1167 * Finally the top-down scrub begins, only visiting blocks with refcnt == 1.
1231 1168 *
1232 1169 * There would be nothing more to say if a block's refcnt couldn't change
1233 1170 * during a scrub, but of course it can so we must account for changes
1234 1171 * in a block's replication class.
1235 1172 *
1236 1173 * Here's an example of what can occur:
1237 1174 *
1238 1175 * If a block has refcnt > 1 during the DDT scrub phase, but has refcnt == 1
1239 1176 * when visited during the top-down scrub phase, it will be scrubbed twice.
1240 1177 * This negates our scrub optimization, but is otherwise harmless.
1241 1178 *
1242 1179 * If a block has refcnt == 1 during the DDT scrub phase, but has refcnt > 1
1243 1180 * on each visit during the top-down scrub phase, it will never be scrubbed.
1244 1181 * To catch this, ddt_sync_entry() notifies the scrub code whenever a block's
1245 1182 * reference class transitions to a higher level (i.e DDT_CLASS_UNIQUE to
1246 1183 * DDT_CLASS_DUPLICATE); if it transitions from refcnt == 1 to refcnt > 1
1247 1184 * while a scrub is in progress, it scrubs the block right then.
1248 1185 */
1249 1186 static void
1250 1187 dsl_scan_ddt(dsl_scan_t *scn, dmu_tx_t *tx)
1251 1188 {
1252 1189 ddt_bookmark_t *ddb = &scn->scn_phys.scn_ddt_bookmark;
1253 1190 ddt_entry_t dde = { 0 };
1254 1191 int error;
1255 1192 uint64_t n = 0;
1256 1193
1257 1194 while ((error = ddt_walk(scn->scn_dp->dp_spa, ddb, &dde)) == 0) {
1258 1195 ddt_t *ddt;
1259 1196
1260 1197 if (ddb->ddb_class > scn->scn_phys.scn_ddt_class_max)
1261 1198 break;
1262 1199 dprintf("visiting ddb=%llu/%llu/%llu/%llx\n",
1263 1200 (longlong_t)ddb->ddb_class,
1264 1201 (longlong_t)ddb->ddb_type,
1265 1202 (longlong_t)ddb->ddb_checksum,
1266 1203 (longlong_t)ddb->ddb_cursor);
1267 1204
1268 1205 /* There should be no pending changes to the dedup table */
1269 1206 ddt = scn->scn_dp->dp_spa->spa_ddt[ddb->ddb_checksum];
1270 1207 ASSERT(avl_first(&ddt->ddt_tree) == NULL);
1271 1208
1272 1209 dsl_scan_ddt_entry(scn, ddb->ddb_checksum, &dde, tx);
1273 1210 n++;
1274 1211
1275 1212 if (dsl_scan_check_pause(scn, NULL))
1276 1213 break;
1277 1214 }
1278 1215
1279 1216 zfs_dbgmsg("scanned %llu ddt entries with class_max = %u; pausing=%u",
1280 1217 (longlong_t)n, (int)scn->scn_phys.scn_ddt_class_max,
1281 1218 (int)scn->scn_pausing);
1282 1219
1283 1220 ASSERT(error == 0 || error == ENOENT);
1284 1221 ASSERT(error != ENOENT ||
1285 1222 ddb->ddb_class > scn->scn_phys.scn_ddt_class_max);
1286 1223 }
1287 1224
1288 1225 /* ARGSUSED */
1289 1226 void
1290 1227 dsl_scan_ddt_entry(dsl_scan_t *scn, enum zio_checksum checksum,
1291 1228 ddt_entry_t *dde, dmu_tx_t *tx)
1292 1229 {
1293 1230 const ddt_key_t *ddk = &dde->dde_key;
1294 1231 ddt_phys_t *ddp = dde->dde_phys;
1295 1232 blkptr_t bp;
1296 1233 zbookmark_t zb = { 0 };
1297 1234
1298 1235 if (scn->scn_phys.scn_state != DSS_SCANNING)
1299 1236 return;
1300 1237
1301 1238 for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
1302 1239 if (ddp->ddp_phys_birth == 0 ||
1303 1240 ddp->ddp_phys_birth > scn->scn_phys.scn_cur_max_txg)
1304 1241 continue;
1305 1242 ddt_bp_create(checksum, ddk, ddp, &bp);
1306 1243
1307 1244 scn->scn_visited_this_txg++;
1308 1245 scan_funcs[scn->scn_phys.scn_func](scn->scn_dp, &bp, &zb);
1309 1246 }
1310 1247 }
1311 1248
1312 1249 static void
1313 1250 dsl_scan_visit(dsl_scan_t *scn, dmu_tx_t *tx)
1314 1251 {
1315 1252 dsl_pool_t *dp = scn->scn_dp;
1316 1253 zap_cursor_t zc;
1317 1254 zap_attribute_t za;
1318 1255
1319 1256 if (scn->scn_phys.scn_ddt_bookmark.ddb_class <=
1320 1257 scn->scn_phys.scn_ddt_class_max) {
1321 1258 scn->scn_phys.scn_cur_min_txg = scn->scn_phys.scn_min_txg;
1322 1259 scn->scn_phys.scn_cur_max_txg = scn->scn_phys.scn_max_txg;
1323 1260 dsl_scan_ddt(scn, tx);
1324 1261 if (scn->scn_pausing)
1325 1262 return;
1326 1263 }
1327 1264
1328 1265 if (scn->scn_phys.scn_bookmark.zb_objset == DMU_META_OBJSET) {
1329 1266 /* First do the MOS & ORIGIN */
1330 1267
1331 1268 scn->scn_phys.scn_cur_min_txg = scn->scn_phys.scn_min_txg;
1332 1269 scn->scn_phys.scn_cur_max_txg = scn->scn_phys.scn_max_txg;
1333 1270 dsl_scan_visit_rootbp(scn, NULL,
1334 1271 &dp->dp_meta_rootbp, tx);
1335 1272 spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp);
1336 1273 if (scn->scn_pausing)
1337 1274 return;
1338 1275
1339 1276 if (spa_version(dp->dp_spa) < SPA_VERSION_DSL_SCRUB) {
1340 1277 VERIFY(0 == dmu_objset_find_spa(dp->dp_spa,
1341 1278 NULL, enqueue_cb, tx, DS_FIND_CHILDREN));
1342 1279 } else {
1343 1280 dsl_scan_visitds(scn,
1344 1281 dp->dp_origin_snap->ds_object, tx);
1345 1282 }
1346 1283 ASSERT(!scn->scn_pausing);
1347 1284 } else if (scn->scn_phys.scn_bookmark.zb_objset !=
1348 1285 ZB_DESTROYED_OBJSET) {
1349 1286 /*
1350 1287 * If we were paused, continue from here. Note if the
1351 1288 * ds we were paused on was deleted, the zb_objset may
1352 1289 * be -1, so we will skip this and find a new objset
1353 1290 * below.
1354 1291 */
1355 1292 dsl_scan_visitds(scn, scn->scn_phys.scn_bookmark.zb_objset, tx);
1356 1293 if (scn->scn_pausing)
1357 1294 return;
1358 1295 }
1359 1296
1360 1297 /*
1361 1298 * In case we were paused right at the end of the ds, zero the
1362 1299 * bookmark so we don't think that we're still trying to resume.
1363 1300 */
1364 1301 bzero(&scn->scn_phys.scn_bookmark, sizeof (zbookmark_t));
1365 1302
1366 1303 /* keep pulling things out of the zap-object-as-queue */
1367 1304 while (zap_cursor_init(&zc, dp->dp_meta_objset,
1368 1305 scn->scn_phys.scn_queue_obj),
1369 1306 zap_cursor_retrieve(&zc, &za) == 0) {
1370 1307 dsl_dataset_t *ds;
1371 1308 uint64_t dsobj;
1372 1309
1373 1310 dsobj = strtonum(za.za_name, NULL);
1374 1311 VERIFY3U(0, ==, zap_remove_int(dp->dp_meta_objset,
1375 1312 scn->scn_phys.scn_queue_obj, dsobj, tx));
1376 1313
1377 1314 /* Set up min/max txg */
1378 1315 VERIFY3U(0, ==, dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
1379 1316 if (za.za_first_integer != 0) {
1380 1317 scn->scn_phys.scn_cur_min_txg =
1381 1318 MAX(scn->scn_phys.scn_min_txg,
1382 1319 za.za_first_integer);
1383 1320 } else {
1384 1321 scn->scn_phys.scn_cur_min_txg =
1385 1322 MAX(scn->scn_phys.scn_min_txg,
1386 1323 ds->ds_phys->ds_prev_snap_txg);
1387 1324 }
1388 1325 scn->scn_phys.scn_cur_max_txg = dsl_scan_ds_maxtxg(ds);
|
↓ open down ↓ |
544 lines elided |
↑ open up ↑ |
1389 1326 dsl_dataset_rele(ds, FTAG);
1390 1327
1391 1328 dsl_scan_visitds(scn, dsobj, tx);
1392 1329 zap_cursor_fini(&zc);
1393 1330 if (scn->scn_pausing)
1394 1331 return;
1395 1332 }
1396 1333 zap_cursor_fini(&zc);
1397 1334 }
1398 1335
1399 -static int
1400 -dsl_scan_free_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
1336 +static boolean_t
1337 +dsl_scan_free_should_pause(dsl_scan_t *scn)
1401 1338 {
1402 - dsl_scan_t *scn = arg;
1403 1339 uint64_t elapsed_nanosecs;
1404 1340
1405 1341 elapsed_nanosecs = gethrtime() - scn->scn_sync_start_time;
1406 -
1407 - if (elapsed_nanosecs / NANOSEC > zfs_txg_timeout ||
1342 + return (elapsed_nanosecs / NANOSEC > zfs_txg_timeout ||
1408 1343 (elapsed_nanosecs / MICROSEC > zfs_free_min_time_ms &&
1409 1344 txg_sync_waiting(scn->scn_dp)) ||
1410 - spa_shutting_down(scn->scn_dp->dp_spa))
1411 - return (ERESTART);
1345 + spa_shutting_down(scn->scn_dp->dp_spa));
1346 +}
1412 1347
1348 +static int
1349 +dsl_scan_free_block_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
1350 +{
1351 + dsl_scan_t *scn = arg;
1352 +
1353 + if (!scn->scn_is_bptree ||
1354 + (BP_GET_LEVEL(bp) == 0 && BP_GET_TYPE(bp) != DMU_OT_OBJSET)) {
1355 + if (dsl_scan_free_should_pause(scn))
1356 + return (ERESTART);
1357 + }
1358 +
1413 1359 zio_nowait(zio_free_sync(scn->scn_zio_root, scn->scn_dp->dp_spa,
1414 1360 dmu_tx_get_txg(tx), bp, 0));
1415 1361 dsl_dir_diduse_space(tx->tx_pool->dp_free_dir, DD_USED_HEAD,
1416 1362 -bp_get_dsize_sync(scn->scn_dp->dp_spa, bp),
1417 1363 -BP_GET_PSIZE(bp), -BP_GET_UCSIZE(bp), tx);
1418 1364 scn->scn_visited_this_txg++;
1419 1365 return (0);
1420 1366 }
1421 1367
1422 1368 boolean_t
1423 1369 dsl_scan_active(dsl_scan_t *scn)
1424 1370 {
1425 1371 spa_t *spa = scn->scn_dp->dp_spa;
|
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
1426 1372 uint64_t used = 0, comp, uncomp;
1427 1373
1428 1374 if (spa->spa_load_state != SPA_LOAD_NONE)
1429 1375 return (B_FALSE);
1430 1376 if (spa_shutting_down(spa))
1431 1377 return (B_FALSE);
1432 1378
1433 1379 if (scn->scn_phys.scn_state == DSS_SCANNING)
1434 1380 return (B_TRUE);
1435 1381
1382 + if (spa_feature_is_active(spa,
1383 + &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
1384 + return (B_TRUE);
1385 + }
1436 1386 if (spa_version(scn->scn_dp->dp_spa) >= SPA_VERSION_DEADLISTS) {
1437 1387 (void) bpobj_space(&scn->scn_dp->dp_free_bpobj,
1438 1388 &used, &comp, &uncomp);
1439 1389 }
1440 1390 return (used != 0);
1441 1391 }
1442 1392
1443 1393 void
1444 1394 dsl_scan_sync(dsl_pool_t *dp, dmu_tx_t *tx)
1445 1395 {
1446 1396 dsl_scan_t *scn = dp->dp_scan;
1447 1397 spa_t *spa = dp->dp_spa;
1448 1398 int err;
1449 1399
1450 1400 /*
1451 1401 * Check for scn_restart_txg before checking spa_load_state, so
1452 1402 * that we can restart an old-style scan while the pool is being
1453 1403 * imported (see dsl_scan_init).
1454 1404 */
1455 1405 if (scn->scn_restart_txg != 0 &&
1456 1406 scn->scn_restart_txg <= tx->tx_txg) {
1457 1407 pool_scan_func_t func = POOL_SCAN_SCRUB;
1458 1408 dsl_scan_done(scn, B_FALSE, tx);
1459 1409 if (vdev_resilver_needed(spa->spa_root_vdev, NULL, NULL))
1460 1410 func = POOL_SCAN_RESILVER;
1461 1411 zfs_dbgmsg("restarting scan func=%u txg=%llu",
1462 1412 func, tx->tx_txg);
1463 1413 dsl_scan_setup_sync(scn, &func, tx);
1464 1414 }
1465 1415
1466 1416 if (!dsl_scan_active(scn) ||
1467 1417 spa_sync_pass(dp->dp_spa) > 1)
1468 1418 return;
1469 1419
1470 1420 scn->scn_visited_this_txg = 0;
1471 1421 scn->scn_pausing = B_FALSE;
|
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
1472 1422 scn->scn_sync_start_time = gethrtime();
1473 1423 spa->spa_scrub_active = B_TRUE;
1474 1424
1475 1425 /*
1476 1426 * First process the free list. If we pause the free, don't do
1477 1427 * any scanning. This ensures that there is no free list when
1478 1428 * we are scanning, so the scan code doesn't have to worry about
1479 1429 * traversing it.
1480 1430 */
1481 1431 if (spa_version(dp->dp_spa) >= SPA_VERSION_DEADLISTS) {
1432 + scn->scn_is_bptree = B_FALSE;
1482 1433 scn->scn_zio_root = zio_root(dp->dp_spa, NULL,
1483 1434 NULL, ZIO_FLAG_MUSTSUCCEED);
1484 1435 err = bpobj_iterate(&dp->dp_free_bpobj,
1485 - dsl_scan_free_cb, scn, tx);
1436 + dsl_scan_free_block_cb, scn, tx);
1486 1437 VERIFY3U(0, ==, zio_wait(scn->scn_zio_root));
1438 +
1439 + if (err == 0 && spa_feature_is_active(spa,
1440 + &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
1441 + scn->scn_is_bptree = B_TRUE;
1442 + scn->scn_zio_root = zio_root(dp->dp_spa, NULL,
1443 + NULL, ZIO_FLAG_MUSTSUCCEED);
1444 + err = bptree_iterate(dp->dp_meta_objset,
1445 + dp->dp_bptree_obj, B_TRUE, dsl_scan_free_block_cb,
1446 + scn, tx);
1447 + VERIFY3U(0, ==, zio_wait(scn->scn_zio_root));
1448 + if (err != 0)
1449 + return;
1450 +
1451 + /* disable async destroy feature */
1452 + spa_feature_decr(spa,
1453 + &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY], tx);
1454 + ASSERT(!spa_feature_is_active(spa,
1455 + &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY]));
1456 + VERIFY3U(0, ==, zap_remove(dp->dp_meta_objset,
1457 + DMU_POOL_DIRECTORY_OBJECT,
1458 + DMU_POOL_BPTREE_OBJ, tx));
1459 + VERIFY3U(0, ==, bptree_free(dp->dp_meta_objset,
1460 + dp->dp_bptree_obj, tx));
1461 + dp->dp_bptree_obj = 0;
1462 + }
1487 1463 if (scn->scn_visited_this_txg) {
1488 1464 zfs_dbgmsg("freed %llu blocks in %llums from "
1489 - "free_bpobj txg %llu",
1465 + "free_bpobj/bptree txg %llu",
1490 1466 (longlong_t)scn->scn_visited_this_txg,
1491 1467 (longlong_t)
1492 1468 (gethrtime() - scn->scn_sync_start_time) / MICROSEC,
1493 1469 (longlong_t)tx->tx_txg);
1494 1470 scn->scn_visited_this_txg = 0;
1495 1471 /*
1496 1472 * Re-sync the ddt so that we can further modify
1497 1473 * it when doing bprewrite.
1498 1474 */
1499 1475 ddt_sync(spa, tx->tx_txg);
1500 1476 }
1501 1477 if (err == ERESTART)
1502 1478 return;
1503 1479 }
1504 1480
1505 1481 if (scn->scn_phys.scn_state != DSS_SCANNING)
1506 1482 return;
1507 1483
1508 1484 if (scn->scn_phys.scn_ddt_bookmark.ddb_class <=
1509 1485 scn->scn_phys.scn_ddt_class_max) {
1510 1486 zfs_dbgmsg("doing scan sync txg %llu; "
1511 1487 "ddt bm=%llu/%llu/%llu/%llx",
1512 1488 (longlong_t)tx->tx_txg,
1513 1489 (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_class,
1514 1490 (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_type,
1515 1491 (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_checksum,
1516 1492 (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_cursor);
1517 1493 ASSERT(scn->scn_phys.scn_bookmark.zb_objset == 0);
1518 1494 ASSERT(scn->scn_phys.scn_bookmark.zb_object == 0);
1519 1495 ASSERT(scn->scn_phys.scn_bookmark.zb_level == 0);
1520 1496 ASSERT(scn->scn_phys.scn_bookmark.zb_blkid == 0);
1521 1497 } else {
1522 1498 zfs_dbgmsg("doing scan sync txg %llu; bm=%llu/%llu/%llu/%llu",
1523 1499 (longlong_t)tx->tx_txg,
1524 1500 (longlong_t)scn->scn_phys.scn_bookmark.zb_objset,
1525 1501 (longlong_t)scn->scn_phys.scn_bookmark.zb_object,
1526 1502 (longlong_t)scn->scn_phys.scn_bookmark.zb_level,
1527 1503 (longlong_t)scn->scn_phys.scn_bookmark.zb_blkid);
1528 1504 }
1529 1505
1530 1506 scn->scn_zio_root = zio_root(dp->dp_spa, NULL,
1531 1507 NULL, ZIO_FLAG_CANFAIL);
1532 1508 dsl_scan_visit(scn, tx);
1533 1509 (void) zio_wait(scn->scn_zio_root);
1534 1510 scn->scn_zio_root = NULL;
1535 1511
1536 1512 zfs_dbgmsg("visited %llu blocks in %llums",
1537 1513 (longlong_t)scn->scn_visited_this_txg,
1538 1514 (longlong_t)(gethrtime() - scn->scn_sync_start_time) / MICROSEC);
1539 1515
1540 1516 if (!scn->scn_pausing) {
1541 1517 /* finished with scan. */
1542 1518 zfs_dbgmsg("finished scan txg %llu", (longlong_t)tx->tx_txg);
1543 1519 dsl_scan_done(scn, B_TRUE, tx);
1544 1520 }
1545 1521
1546 1522 if (DSL_SCAN_IS_SCRUB_RESILVER(scn)) {
1547 1523 mutex_enter(&spa->spa_scrub_lock);
1548 1524 while (spa->spa_scrub_inflight > 0) {
1549 1525 cv_wait(&spa->spa_scrub_io_cv,
1550 1526 &spa->spa_scrub_lock);
1551 1527 }
1552 1528 mutex_exit(&spa->spa_scrub_lock);
1553 1529 }
1554 1530
1555 1531 dsl_scan_sync_state(scn, tx);
1556 1532 }
1557 1533
1558 1534 /*
1559 1535 * This will start a new scan, or restart an existing one.
1560 1536 */
1561 1537 void
1562 1538 dsl_resilver_restart(dsl_pool_t *dp, uint64_t txg)
1563 1539 {
1564 1540 if (txg == 0) {
1565 1541 dmu_tx_t *tx;
1566 1542 tx = dmu_tx_create_dd(dp->dp_mos_dir);
1567 1543 VERIFY(0 == dmu_tx_assign(tx, TXG_WAIT));
1568 1544
1569 1545 txg = dmu_tx_get_txg(tx);
1570 1546 dp->dp_scan->scn_restart_txg = txg;
1571 1547 dmu_tx_commit(tx);
1572 1548 } else {
1573 1549 dp->dp_scan->scn_restart_txg = txg;
1574 1550 }
1575 1551 zfs_dbgmsg("restarting resilver txg=%llu", txg);
1576 1552 }
1577 1553
1578 1554 boolean_t
1579 1555 dsl_scan_resilvering(dsl_pool_t *dp)
1580 1556 {
1581 1557 return (dp->dp_scan->scn_phys.scn_state == DSS_SCANNING &&
1582 1558 dp->dp_scan->scn_phys.scn_func == POOL_SCAN_RESILVER);
1583 1559 }
1584 1560
1585 1561 /*
1586 1562 * scrub consumers
1587 1563 */
1588 1564
1589 1565 static void
1590 1566 count_block(zfs_all_blkstats_t *zab, const blkptr_t *bp)
1591 1567 {
1592 1568 int i;
1593 1569
|
↓ open down ↓ |
94 lines elided |
↑ open up ↑ |
1594 1570 /*
1595 1571 * If we resume after a reboot, zab will be NULL; don't record
1596 1572 * incomplete stats in that case.
1597 1573 */
1598 1574 if (zab == NULL)
1599 1575 return;
1600 1576
1601 1577 for (i = 0; i < 4; i++) {
1602 1578 int l = (i < 2) ? BP_GET_LEVEL(bp) : DN_MAX_LEVELS;
1603 1579 int t = (i & 1) ? BP_GET_TYPE(bp) : DMU_OT_TOTAL;
1580 + if (t & DMU_OT_NEWTYPE)
1581 + t = DMU_OT_OTHER;
1604 1582 zfs_blkstat_t *zb = &zab->zab_type[l][t];
1605 1583 int equal;
1606 1584
1607 1585 zb->zb_count++;
1608 1586 zb->zb_asize += BP_GET_ASIZE(bp);
1609 1587 zb->zb_lsize += BP_GET_LSIZE(bp);
1610 1588 zb->zb_psize += BP_GET_PSIZE(bp);
1611 1589 zb->zb_gangs += BP_COUNT_GANG(bp);
1612 1590
1613 1591 switch (BP_GET_NDVAS(bp)) {
1614 1592 case 2:
1615 1593 if (DVA_GET_VDEV(&bp->blk_dva[0]) ==
1616 1594 DVA_GET_VDEV(&bp->blk_dva[1]))
1617 1595 zb->zb_ditto_2_of_2_samevdev++;
1618 1596 break;
1619 1597 case 3:
1620 1598 equal = (DVA_GET_VDEV(&bp->blk_dva[0]) ==
1621 1599 DVA_GET_VDEV(&bp->blk_dva[1])) +
1622 1600 (DVA_GET_VDEV(&bp->blk_dva[0]) ==
1623 1601 DVA_GET_VDEV(&bp->blk_dva[2])) +
1624 1602 (DVA_GET_VDEV(&bp->blk_dva[1]) ==
1625 1603 DVA_GET_VDEV(&bp->blk_dva[2]));
1626 1604 if (equal == 1)
1627 1605 zb->zb_ditto_2_of_3_samevdev++;
1628 1606 else if (equal == 3)
1629 1607 zb->zb_ditto_3_of_3_samevdev++;
1630 1608 break;
1631 1609 }
1632 1610 }
1633 1611 }
1634 1612
1635 1613 static void
1636 1614 dsl_scan_scrub_done(zio_t *zio)
1637 1615 {
1638 1616 spa_t *spa = zio->io_spa;
1639 1617
1640 1618 zio_data_buf_free(zio->io_data, zio->io_size);
1641 1619
1642 1620 mutex_enter(&spa->spa_scrub_lock);
1643 1621 spa->spa_scrub_inflight--;
1644 1622 cv_broadcast(&spa->spa_scrub_io_cv);
1645 1623
1646 1624 if (zio->io_error && (zio->io_error != ECKSUM ||
1647 1625 !(zio->io_flags & ZIO_FLAG_SPECULATIVE))) {
1648 1626 spa->spa_dsl_pool->dp_scan->scn_phys.scn_errors++;
1649 1627 }
1650 1628 mutex_exit(&spa->spa_scrub_lock);
1651 1629 }
1652 1630
1653 1631 static int
1654 1632 dsl_scan_scrub_cb(dsl_pool_t *dp,
1655 1633 const blkptr_t *bp, const zbookmark_t *zb)
1656 1634 {
1657 1635 dsl_scan_t *scn = dp->dp_scan;
1658 1636 size_t size = BP_GET_PSIZE(bp);
1659 1637 spa_t *spa = dp->dp_spa;
1660 1638 uint64_t phys_birth = BP_PHYSICAL_BIRTH(bp);
1661 1639 boolean_t needs_io;
1662 1640 int zio_flags = ZIO_FLAG_SCAN_THREAD | ZIO_FLAG_RAW | ZIO_FLAG_CANFAIL;
1663 1641 int zio_priority;
1664 1642 int scan_delay = 0;
1665 1643
1666 1644 if (phys_birth <= scn->scn_phys.scn_min_txg ||
1667 1645 phys_birth >= scn->scn_phys.scn_max_txg)
1668 1646 return (0);
1669 1647
1670 1648 count_block(dp->dp_blkstats, bp);
1671 1649
1672 1650 ASSERT(DSL_SCAN_IS_SCRUB_RESILVER(scn));
1673 1651 if (scn->scn_phys.scn_func == POOL_SCAN_SCRUB) {
1674 1652 zio_flags |= ZIO_FLAG_SCRUB;
1675 1653 zio_priority = ZIO_PRIORITY_SCRUB;
1676 1654 needs_io = B_TRUE;
1677 1655 scan_delay = zfs_scrub_delay;
1678 1656 } else if (scn->scn_phys.scn_func == POOL_SCAN_RESILVER) {
1679 1657 zio_flags |= ZIO_FLAG_RESILVER;
1680 1658 zio_priority = ZIO_PRIORITY_RESILVER;
1681 1659 needs_io = B_FALSE;
1682 1660 scan_delay = zfs_resilver_delay;
1683 1661 }
1684 1662
1685 1663 /* If it's an intent log block, failure is expected. */
1686 1664 if (zb->zb_level == ZB_ZIL_LEVEL)
1687 1665 zio_flags |= ZIO_FLAG_SPECULATIVE;
1688 1666
1689 1667 for (int d = 0; d < BP_GET_NDVAS(bp); d++) {
1690 1668 vdev_t *vd = vdev_lookup_top(spa,
1691 1669 DVA_GET_VDEV(&bp->blk_dva[d]));
1692 1670
1693 1671 /*
1694 1672 * Keep track of how much data we've examined so that
1695 1673 * zpool(1M) status can make useful progress reports.
1696 1674 */
1697 1675 scn->scn_phys.scn_examined += DVA_GET_ASIZE(&bp->blk_dva[d]);
1698 1676 spa->spa_scan_pass_exam += DVA_GET_ASIZE(&bp->blk_dva[d]);
1699 1677
1700 1678 /* if it's a resilver, this may not be in the target range */
1701 1679 if (!needs_io) {
1702 1680 if (DVA_GET_GANG(&bp->blk_dva[d])) {
1703 1681 /*
1704 1682 * Gang members may be spread across multiple
1705 1683 * vdevs, so the best estimate we have is the
1706 1684 * scrub range, which has already been checked.
1707 1685 * XXX -- it would be better to change our
1708 1686 * allocation policy to ensure that all
1709 1687 * gang members reside on the same vdev.
1710 1688 */
1711 1689 needs_io = B_TRUE;
1712 1690 } else {
1713 1691 needs_io = vdev_dtl_contains(vd, DTL_PARTIAL,
1714 1692 phys_birth, 1);
1715 1693 }
1716 1694 }
1717 1695 }
1718 1696
1719 1697 if (needs_io && !zfs_no_scrub_io) {
1720 1698 vdev_t *rvd = spa->spa_root_vdev;
1721 1699 uint64_t maxinflight = rvd->vdev_children * zfs_top_maxinflight;
1722 1700 void *data = zio_data_buf_alloc(size);
1723 1701
1724 1702 mutex_enter(&spa->spa_scrub_lock);
1725 1703 while (spa->spa_scrub_inflight >= maxinflight)
1726 1704 cv_wait(&spa->spa_scrub_io_cv, &spa->spa_scrub_lock);
1727 1705 spa->spa_scrub_inflight++;
1728 1706 mutex_exit(&spa->spa_scrub_lock);
1729 1707
1730 1708 /*
1731 1709 * If we're seeing recent (zfs_scan_idle) "important" I/Os
1732 1710 * then throttle our workload to limit the impact of a scan.
1733 1711 */
1734 1712 if (ddi_get_lbolt64() - spa->spa_last_io <= zfs_scan_idle)
1735 1713 delay(scan_delay);
1736 1714
1737 1715 zio_nowait(zio_read(NULL, spa, bp, data, size,
1738 1716 dsl_scan_scrub_done, NULL, zio_priority,
1739 1717 zio_flags, zb));
1740 1718 }
1741 1719
1742 1720 /* do not relocate this block */
1743 1721 return (0);
1744 1722 }
1745 1723
1746 1724 int
1747 1725 dsl_scan(dsl_pool_t *dp, pool_scan_func_t func)
1748 1726 {
1749 1727 spa_t *spa = dp->dp_spa;
1750 1728
1751 1729 /*
1752 1730 * Purge all vdev caches and probe all devices. We do this here
1753 1731 * rather than in sync context because this requires a writer lock
1754 1732 * on the spa_config lock, which we can't do from sync context. The
1755 1733 * spa_scrub_reopen flag indicates that vdev_open() should not
1756 1734 * attempt to start another scrub.
1757 1735 */
1758 1736 spa_vdev_state_enter(spa, SCL_NONE);
1759 1737 spa->spa_scrub_reopen = B_TRUE;
1760 1738 vdev_reopen(spa->spa_root_vdev);
1761 1739 spa->spa_scrub_reopen = B_FALSE;
1762 1740 (void) spa_vdev_state_exit(spa, NULL, 0);
1763 1741
1764 1742 return (dsl_sync_task_do(dp, dsl_scan_setup_check,
1765 1743 dsl_scan_setup_sync, dp->dp_scan, &func, 0));
1766 1744 }
|
↓ open down ↓ |
153 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX