Print this page
5269 zfs: zpool import slow
PORTING: this code relies on the property of taskq_wait to wait
until no more tasks are queued and no more tasks are active. As
we always queue new tasks from within other tasks, task_wait
reliably waits for the full recursion to finish, even though we
enqueue new tasks after taskq_wait has been called.
On platforms other than illumos, taskq_wait may not have this
property.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: George Wilson <george.wilson@delphix.com>


1721                         vdev_load_log_state(tvd, mtvd);
1722                         vdev_reopen(tvd);
1723                 }
1724         }
1725         vdev_free(mrvd);
1726         spa_config_exit(spa, SCL_ALL, FTAG);
1727 
1728         /*
1729          * Ensure we were able to validate the config.
1730          */
1731         return (rvd->vdev_guid_sum == spa->spa_uberblock.ub_guid_sum);
1732 }
1733 
1734 /*
1735  * Check for missing log devices
1736  */
1737 static boolean_t
1738 spa_check_logs(spa_t *spa)
1739 {
1740         boolean_t rv = B_FALSE;

1741 
1742         switch (spa->spa_log_state) {
1743         case SPA_LOG_MISSING:
1744                 /* need to recheck in case slog has been restored */
1745         case SPA_LOG_UNKNOWN:
1746                 rv = (dmu_objset_find(spa->spa_name, zil_check_log_chain,
1747                     NULL, DS_FIND_CHILDREN) != 0);
1748                 if (rv)
1749                         spa_set_log_state(spa, SPA_LOG_MISSING);
1750                 break;
1751         }
1752         return (rv);
1753 }
1754 
1755 static boolean_t
1756 spa_passivate_log(spa_t *spa)
1757 {
1758         vdev_t *rvd = spa->spa_root_vdev;
1759         boolean_t slog_found = B_FALSE;
1760 
1761         ASSERT(spa_config_held(spa, SCL_ALLOC, RW_WRITER));
1762 
1763         if (!spa_has_slogs(spa))
1764                 return (B_FALSE);
1765 
1766         for (int c = 0; c < rvd->vdev_children; c++) {
1767                 vdev_t *tvd = rvd->vdev_child[c];


2698                  * read-only mode but not read-write mode. We now have enough
2699                  * information and can return to userland.
2700                  */
2701                 return (spa_vdev_err(rvd, VDEV_AUX_UNSUP_FEAT, ENOTSUP));
2702         }
2703 
2704         /*
2705          * We've successfully opened the pool, verify that we're ready
2706          * to start pushing transactions.
2707          */
2708         if (state != SPA_LOAD_TRYIMPORT) {
2709                 if (error = spa_load_verify(spa))
2710                         return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA,
2711                             error));
2712         }
2713 
2714         if (spa_writeable(spa) && (state == SPA_LOAD_RECOVER ||
2715             spa->spa_load_max_txg == UINT64_MAX)) {
2716                 dmu_tx_t *tx;
2717                 int need_update = B_FALSE;

2718 
2719                 ASSERT(state != SPA_LOAD_TRYIMPORT);
2720 
2721                 /*
2722                  * Claim log blocks that haven't been committed yet.
2723                  * This must all happen in a single txg.
2724                  * Note: spa_claim_max_txg is updated by spa_claim_notify(),
2725                  * invoked from zil_claim_log_block()'s i/o done callback.
2726                  * Price of rollback is that we abandon the log.
2727                  */
2728                 spa->spa_claiming = B_TRUE;
2729 
2730                 tx = dmu_tx_create_assigned(spa_get_dsl(spa),
2731                     spa_first_txg(spa));
2732                 (void) dmu_objset_find(spa_name(spa),
2733                     zil_claim, tx, DS_FIND_CHILDREN);
2734                 dmu_tx_commit(tx);
2735 
2736                 spa->spa_claiming = B_FALSE;
2737 
2738                 spa_set_log_state(spa, SPA_LOG_GOOD);
2739                 spa->spa_sync_on = B_TRUE;
2740                 txg_sync_start(spa->spa_dsl_pool);
2741 
2742                 /*
2743                  * Wait for all claims to sync.  We sync up to the highest
2744                  * claimed log block birth time so that claimed log blocks
2745                  * don't appear to be from the future.  spa_claim_max_txg
2746                  * will have been set for us by either zil_check_log_chain()
2747                  * (invoked from spa_check_logs()) or zil_claim() above.
2748                  */
2749                 txg_wait_synced(spa->spa_dsl_pool, spa->spa_claim_max_txg);
2750 
2751                 /*
2752                  * If the config cache is stale, or we have uninitialized




1721                         vdev_load_log_state(tvd, mtvd);
1722                         vdev_reopen(tvd);
1723                 }
1724         }
1725         vdev_free(mrvd);
1726         spa_config_exit(spa, SCL_ALL, FTAG);
1727 
1728         /*
1729          * Ensure we were able to validate the config.
1730          */
1731         return (rvd->vdev_guid_sum == spa->spa_uberblock.ub_guid_sum);
1732 }
1733 
1734 /*
1735  * Check for missing log devices
1736  */
1737 static boolean_t
1738 spa_check_logs(spa_t *spa)
1739 {
1740         boolean_t rv = B_FALSE;
1741         dsl_pool_t *dp = spa_get_dsl(spa);
1742 
1743         switch (spa->spa_log_state) {
1744         case SPA_LOG_MISSING:
1745                 /* need to recheck in case slog has been restored */
1746         case SPA_LOG_UNKNOWN:
1747                 rv = (dmu_objset_find_dp(dp, dp->dp_root_dir_obj,
1748                     zil_check_log_chain, NULL, DS_FIND_CHILDREN) != 0);
1749                 if (rv)
1750                         spa_set_log_state(spa, SPA_LOG_MISSING);
1751                 break;
1752         }
1753         return (rv);
1754 }
1755 
1756 static boolean_t
1757 spa_passivate_log(spa_t *spa)
1758 {
1759         vdev_t *rvd = spa->spa_root_vdev;
1760         boolean_t slog_found = B_FALSE;
1761 
1762         ASSERT(spa_config_held(spa, SCL_ALLOC, RW_WRITER));
1763 
1764         if (!spa_has_slogs(spa))
1765                 return (B_FALSE);
1766 
1767         for (int c = 0; c < rvd->vdev_children; c++) {
1768                 vdev_t *tvd = rvd->vdev_child[c];


2699                  * read-only mode but not read-write mode. We now have enough
2700                  * information and can return to userland.
2701                  */
2702                 return (spa_vdev_err(rvd, VDEV_AUX_UNSUP_FEAT, ENOTSUP));
2703         }
2704 
2705         /*
2706          * We've successfully opened the pool, verify that we're ready
2707          * to start pushing transactions.
2708          */
2709         if (state != SPA_LOAD_TRYIMPORT) {
2710                 if (error = spa_load_verify(spa))
2711                         return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA,
2712                             error));
2713         }
2714 
2715         if (spa_writeable(spa) && (state == SPA_LOAD_RECOVER ||
2716             spa->spa_load_max_txg == UINT64_MAX)) {
2717                 dmu_tx_t *tx;
2718                 int need_update = B_FALSE;
2719                 dsl_pool_t *dp = spa_get_dsl(spa);
2720 
2721                 ASSERT(state != SPA_LOAD_TRYIMPORT);
2722 
2723                 /*
2724                  * Claim log blocks that haven't been committed yet.
2725                  * This must all happen in a single txg.
2726                  * Note: spa_claim_max_txg is updated by spa_claim_notify(),
2727                  * invoked from zil_claim_log_block()'s i/o done callback.
2728                  * Price of rollback is that we abandon the log.
2729                  */
2730                 spa->spa_claiming = B_TRUE;
2731 
2732                 tx = dmu_tx_create_assigned(dp, spa_first_txg(spa));
2733                 (void) dmu_objset_find_dp(dp, dp->dp_root_dir_obj,

2734                     zil_claim, tx, DS_FIND_CHILDREN);
2735                 dmu_tx_commit(tx);
2736 
2737                 spa->spa_claiming = B_FALSE;
2738 
2739                 spa_set_log_state(spa, SPA_LOG_GOOD);
2740                 spa->spa_sync_on = B_TRUE;
2741                 txg_sync_start(spa->spa_dsl_pool);
2742 
2743                 /*
2744                  * Wait for all claims to sync.  We sync up to the highest
2745                  * claimed log block birth time so that claimed log blocks
2746                  * don't appear to be from the future.  spa_claim_max_txg
2747                  * will have been set for us by either zil_check_log_chain()
2748                  * (invoked from spa_check_logs()) or zil_claim() above.
2749                  */
2750                 txg_wait_synced(spa->spa_dsl_pool, spa->spa_claim_max_txg);
2751 
2752                 /*
2753                  * If the config cache is stale, or we have uninitialized