* This is the primary entry point for scans that is called from syncing * context. Scans must happen entirely during syncing context so that we * can guarantee that blocks we are currently scanning will not change out * from under us. While a scan is active, this function controls how quickly * transaction groups proceed, instead of the normal handling provided by * txg_sync_thread(). */
| 3500 | * txg_sync_thread(). |
| 3501 | */ |
| 3502 | void |
| 3503 | dsl_scan_sync(dsl_pool_t *dp, dmu_tx_t *tx) |
| 3504 | { |
| 3505 | int err = 0; |
| 3506 | dsl_scan_t *scn = dp->dp_scan; |
| 3507 | spa_t *spa = dp->dp_spa; |
| 3508 | state_sync_type_t sync_type = SYNC_OPTIONAL; |
| 3509 | |
| 3510 | if (spa->spa_resilver_deferred && |
| 3511 | !spa_feature_is_active(dp->dp_spa, SPA_FEATURE_RESILVER_DEFER)) |
| 3512 | spa_feature_incr(spa, SPA_FEATURE_RESILVER_DEFER, tx); |
| 3513 | |
| 3514 | /* |
| 3515 | * Check for scn_restart_txg before checking spa_load_state, so |
| 3516 | * that we can restart an old-style scan while the pool is being |
| 3517 | * imported (see dsl_scan_init). We also restart scans if there |
| 3518 | * is a deferred resilver and the user has manually disabled |
| 3519 | * deferred resilvers via the tunable. |
| 3520 | */ |
| 3521 | if (dsl_scan_restarting(scn, tx) || |
| 3522 | (spa->spa_resilver_deferred && zfs_resilver_disable_defer)) { |
| 3523 | pool_scan_func_t func = POOL_SCAN_SCRUB; |
| 3524 | dsl_scan_done(scn, B_FALSE, tx); |
| 3525 | if (vdev_resilver_needed(spa->spa_root_vdev, NULL, NULL)) |
| 3526 | func = POOL_SCAN_RESILVER; |
| 3527 | zfs_dbgmsg("restarting scan func=%u txg=%llu", |
| 3528 | func, (longlong_t)tx->tx_txg); |
| 3529 | dsl_scan_setup_sync(&func, tx); |
| 3530 | } |
| 3531 | |
| 3532 | /* |
| 3533 | * Only process scans in sync pass 1. |
| 3534 | */ |
| 3535 | if (spa_sync_pass(spa) > 1) |
| 3536 | return; |
| 3537 | |
| 3538 | /* |
| 3539 | * If the spa is shutting down, then stop scanning. This will |
| 3540 | * ensure that the scan does not dirty any new data during the |
| 3541 | * shutdown phase. |
| 3542 | */ |
| 3543 | if (spa_shutting_down(spa)) |
| 3544 | return; |
| 3545 | |
| 3546 | /* |
| 3547 | * If the scan is inactive due to a stalled async destroy, try again. |
| 3548 | */ |
| 3549 | if (!scn->scn_async_stalled && !dsl_scan_active(scn)) |
| 3550 | return; |
| 3551 | |
| 3552 | /* reset scan statistics */ |
| 3553 | scn->scn_visited_this_txg = 0; |
| 3554 | scn->scn_dedup_frees_this_txg = 0; |
| 3555 | scn->scn_holes_this_txg = 0; |
| 3556 | scn->scn_lt_min_this_txg = 0; |
| 3557 | scn->scn_gt_max_this_txg = 0; |
| 3558 | scn->scn_ddt_contained_this_txg = 0; |
| 3559 | scn->scn_objsets_visited_this_txg = 0; |
no test coverage detected