Deleted Added
full compact
spa.c (332549) spa.c (332550)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 2095 unchanged lines hidden (view full) ---

2104 return (0);
2105}
2106
2107static int
2108spa_load_verify(spa_t *spa)
2109{
2110 zio_t *rio;
2111 spa_load_error_t sle = { 0 };
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 2095 unchanged lines hidden (view full) ---

2104 return (0);
2105}
2106
2107static int
2108spa_load_verify(spa_t *spa)
2109{
2110 zio_t *rio;
2111 spa_load_error_t sle = { 0 };
2112 zpool_rewind_policy_t policy;
2112 zpool_load_policy_t policy;
2113 boolean_t verify_ok = B_FALSE;
2114 int error = 0;
2115
2113 boolean_t verify_ok = B_FALSE;
2114 int error = 0;
2115
2116 zpool_get_rewind_policy(spa->spa_config, &policy);
2116 zpool_get_load_policy(spa->spa_config, &policy);
2117
2117
2118 if (policy.zrp_request & ZPOOL_NEVER_REWIND)
2118 if (policy.zlp_rewind & ZPOOL_NEVER_REWIND)
2119 return (0);
2120
2121 dsl_pool_config_enter(spa->spa_dsl_pool, FTAG);
2122 error = dmu_objset_find_dp(spa->spa_dsl_pool,
2123 spa->spa_dsl_pool->dp_root_dir_obj, verify_dataset_name_len, NULL,
2124 DS_FIND_CHILDREN);
2125 dsl_pool_config_exit(spa->spa_dsl_pool, FTAG);
2126 if (error != 0)

--- 22 unchanged lines hidden (view full) ---

2149
2150 if (sle.sle_meta_count != 0 || sle.sle_data_count != 0) {
2151 spa_load_note(spa, "spa_load_verify found %llu metadata errors "
2152 "and %llu data errors", (u_longlong_t)sle.sle_meta_count,
2153 (u_longlong_t)sle.sle_data_count);
2154 }
2155
2156 if (spa_load_verify_dryrun ||
2119 return (0);
2120
2121 dsl_pool_config_enter(spa->spa_dsl_pool, FTAG);
2122 error = dmu_objset_find_dp(spa->spa_dsl_pool,
2123 spa->spa_dsl_pool->dp_root_dir_obj, verify_dataset_name_len, NULL,
2124 DS_FIND_CHILDREN);
2125 dsl_pool_config_exit(spa->spa_dsl_pool, FTAG);
2126 if (error != 0)

--- 22 unchanged lines hidden (view full) ---

2149
2150 if (sle.sle_meta_count != 0 || sle.sle_data_count != 0) {
2151 spa_load_note(spa, "spa_load_verify found %llu metadata errors "
2152 "and %llu data errors", (u_longlong_t)sle.sle_meta_count,
2153 (u_longlong_t)sle.sle_data_count);
2154 }
2155
2156 if (spa_load_verify_dryrun ||
2157 (!error && sle.sle_meta_count <= policy.zrp_maxmeta &&
2158 sle.sle_data_count <= policy.zrp_maxdata)) {
2157 (!error && sle.sle_meta_count <= policy.zlp_maxmeta &&
2158 sle.sle_data_count <= policy.zlp_maxdata)) {
2159 int64_t loss = 0;
2160
2161 verify_ok = B_TRUE;
2162 spa->spa_load_txg = spa->spa_uberblock.ub_txg;
2163 spa->spa_load_txg_ts = spa->spa_uberblock.ub_timestamp;
2164
2165 loss = spa->spa_last_ubsync_txg_ts - spa->spa_load_txg_ts;
2166 VERIFY(nvlist_add_uint64(spa->spa_load_info,

--- 683 unchanged lines hidden (view full) ---

2850 vdev_free(rvd);
2851 spa->spa_root_vdev = mrvd;
2852 rvd = mrvd;
2853 spa_config_exit(spa, SCL_ALL, FTAG);
2854
2855 /*
2856 * We will use spa_config if we decide to reload the spa or if spa_load
2857 * fails and we rewind. We must thus regenerate the config using the
2159 int64_t loss = 0;
2160
2161 verify_ok = B_TRUE;
2162 spa->spa_load_txg = spa->spa_uberblock.ub_txg;
2163 spa->spa_load_txg_ts = spa->spa_uberblock.ub_timestamp;
2164
2165 loss = spa->spa_last_ubsync_txg_ts - spa->spa_load_txg_ts;
2166 VERIFY(nvlist_add_uint64(spa->spa_load_info,

--- 683 unchanged lines hidden (view full) ---

2850 vdev_free(rvd);
2851 spa->spa_root_vdev = mrvd;
2852 rvd = mrvd;
2853 spa_config_exit(spa, SCL_ALL, FTAG);
2854
2855 /*
2856 * We will use spa_config if we decide to reload the spa or if spa_load
2857 * fails and we rewind. We must thus regenerate the config using the
2858 * MOS information with the updated paths. Rewind policy is an import
2859 * setting and is not in the MOS. We copy it over to our new, trusted
2860 * config.
2858 * MOS information with the updated paths. ZPOOL_LOAD_POLICY is used to
2859 * pass settings on how to load the pool and is not stored in the MOS.
2860 * We copy it over to our new, trusted config.
2861 */
2862 mos_config_txg = fnvlist_lookup_uint64(mos_config,
2863 ZPOOL_CONFIG_POOL_TXG);
2864 nvlist_free(mos_config);
2865 mos_config = spa_config_generate(spa, NULL, mos_config_txg, B_FALSE);
2861 */
2862 mos_config_txg = fnvlist_lookup_uint64(mos_config,
2863 ZPOOL_CONFIG_POOL_TXG);
2864 nvlist_free(mos_config);
2865 mos_config = spa_config_generate(spa, NULL, mos_config_txg, B_FALSE);
2866 if (nvlist_lookup_nvlist(spa->spa_config, ZPOOL_REWIND_POLICY,
2866 if (nvlist_lookup_nvlist(spa->spa_config, ZPOOL_LOAD_POLICY,
2867 &policy) == 0)
2867 &policy) == 0)
2868 fnvlist_add_nvlist(mos_config, ZPOOL_REWIND_POLICY, policy);
2868 fnvlist_add_nvlist(mos_config, ZPOOL_LOAD_POLICY, policy);
2869 spa_config_set(spa, mos_config);
2870 spa->spa_config_source = SPA_CONFIG_SRC_MOS;
2871
2872 /*
2873 * Now that we got the config from the MOS, we should be more strict
2874 * in checking blkptrs and can make assumptions about the consistency
2875 * of the vdev tree. spa_trust_config must be set to true before opening
2876 * vdevs in order for them to be writeable.

--- 1243 unchanged lines hidden (view full) ---

4120
4121 if ((spa = spa_lookup(pool)) == NULL) {
4122 if (locked)
4123 mutex_exit(&spa_namespace_lock);
4124 return (SET_ERROR(ENOENT));
4125 }
4126
4127 if (spa->spa_state == POOL_STATE_UNINITIALIZED) {
2869 spa_config_set(spa, mos_config);
2870 spa->spa_config_source = SPA_CONFIG_SRC_MOS;
2871
2872 /*
2873 * Now that we got the config from the MOS, we should be more strict
2874 * in checking blkptrs and can make assumptions about the consistency
2875 * of the vdev tree. spa_trust_config must be set to true before opening
2876 * vdevs in order for them to be writeable.

--- 1243 unchanged lines hidden (view full) ---

4120
4121 if ((spa = spa_lookup(pool)) == NULL) {
4122 if (locked)
4123 mutex_exit(&spa_namespace_lock);
4124 return (SET_ERROR(ENOENT));
4125 }
4126
4127 if (spa->spa_state == POOL_STATE_UNINITIALIZED) {
4128 zpool_rewind_policy_t policy;
4128 zpool_load_policy_t policy;
4129
4130 firstopen = B_TRUE;
4131
4129
4130 firstopen = B_TRUE;
4131
4132 zpool_get_rewind_policy(nvpolicy ? nvpolicy : spa->spa_config,
4132 zpool_get_load_policy(nvpolicy ? nvpolicy : spa->spa_config,
4133 &policy);
4133 &policy);
4134 if (policy.zrp_request & ZPOOL_DO_REWIND)
4134 if (policy.zlp_rewind & ZPOOL_DO_REWIND)
4135 state = SPA_LOAD_RECOVER;
4136
4137 spa_activate(spa, spa_mode_global);
4138
4139 if (state != SPA_LOAD_RECOVER)
4140 spa->spa_last_ubsync_txg = spa->spa_load_txg = 0;
4141 spa->spa_config_source = SPA_CONFIG_SRC_CACHEFILE;
4142
4143 zfs_dbgmsg("spa_open_common: opening %s", pool);
4135 state = SPA_LOAD_RECOVER;
4136
4137 spa_activate(spa, spa_mode_global);
4138
4139 if (state != SPA_LOAD_RECOVER)
4140 spa->spa_last_ubsync_txg = spa->spa_load_txg = 0;
4141 spa->spa_config_source = SPA_CONFIG_SRC_CACHEFILE;
4142
4143 zfs_dbgmsg("spa_open_common: opening %s", pool);
4144 error = spa_load_best(spa, state, policy.zrp_txg,
4145 policy.zrp_request);
4144 error = spa_load_best(spa, state, policy.zlp_txg,
4145 policy.zlp_rewind);
4146
4147 if (error == EBADF) {
4148 /*
4149 * If vdev_validate() returns failure (indicated by
4150 * EBADF), it indicates that one of the vdevs indicates
4151 * that the pool has been exported or destroyed. If
4152 * this is the case, the config cache is out of sync and
4153 * we should remove the pool from the namespace.

--- 1167 unchanged lines hidden (view full) ---

5321 * Import a non-root pool into the system.
5322 */
5323int
5324spa_import(const char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags)
5325{
5326 spa_t *spa;
5327 char *altroot = NULL;
5328 spa_load_state_t state = SPA_LOAD_IMPORT;
4146
4147 if (error == EBADF) {
4148 /*
4149 * If vdev_validate() returns failure (indicated by
4150 * EBADF), it indicates that one of the vdevs indicates
4151 * that the pool has been exported or destroyed. If
4152 * this is the case, the config cache is out of sync and
4153 * we should remove the pool from the namespace.

--- 1167 unchanged lines hidden (view full) ---

5321 * Import a non-root pool into the system.
5322 */
5323int
5324spa_import(const char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags)
5325{
5326 spa_t *spa;
5327 char *altroot = NULL;
5328 spa_load_state_t state = SPA_LOAD_IMPORT;
5329 zpool_rewind_policy_t policy;
5329 zpool_load_policy_t policy;
5330 uint64_t mode = spa_mode_global;
5331 uint64_t readonly = B_FALSE;
5332 int error;
5333 nvlist_t *nvroot;
5334 nvlist_t **spares, **l2cache;
5335 uint_t nspares, nl2cache;
5336
5337 /*

--- 34 unchanged lines hidden (view full) ---

5372
5373 spa_activate(spa, mode);
5374
5375 /*
5376 * Don't start async tasks until we know everything is healthy.
5377 */
5378 spa_async_suspend(spa);
5379
5330 uint64_t mode = spa_mode_global;
5331 uint64_t readonly = B_FALSE;
5332 int error;
5333 nvlist_t *nvroot;
5334 nvlist_t **spares, **l2cache;
5335 uint_t nspares, nl2cache;
5336
5337 /*

--- 34 unchanged lines hidden (view full) ---

5372
5373 spa_activate(spa, mode);
5374
5375 /*
5376 * Don't start async tasks until we know everything is healthy.
5377 */
5378 spa_async_suspend(spa);
5379
5380 zpool_get_rewind_policy(config, &policy);
5381 if (policy.zrp_request & ZPOOL_DO_REWIND)
5380 zpool_get_load_policy(config, &policy);
5381 if (policy.zlp_rewind & ZPOOL_DO_REWIND)
5382 state = SPA_LOAD_RECOVER;
5383
5384 spa->spa_config_source = SPA_CONFIG_SRC_TRYIMPORT;
5385
5386 if (state != SPA_LOAD_RECOVER) {
5387 spa->spa_last_ubsync_txg = spa->spa_load_txg = 0;
5388 zfs_dbgmsg("spa_import: importing %s", pool);
5389 } else {
5390 zfs_dbgmsg("spa_import: importing %s, max_txg=%lld "
5382 state = SPA_LOAD_RECOVER;
5383
5384 spa->spa_config_source = SPA_CONFIG_SRC_TRYIMPORT;
5385
5386 if (state != SPA_LOAD_RECOVER) {
5387 spa->spa_last_ubsync_txg = spa->spa_load_txg = 0;
5388 zfs_dbgmsg("spa_import: importing %s", pool);
5389 } else {
5390 zfs_dbgmsg("spa_import: importing %s, max_txg=%lld "
5391 "(RECOVERY MODE)", pool, (longlong_t)policy.zrp_txg);
5391 "(RECOVERY MODE)", pool, (longlong_t)policy.zlp_txg);
5392 }
5392 }
5393 error = spa_load_best(spa, state, policy.zrp_txg, policy.zrp_request);
5393 error = spa_load_best(spa, state, policy.zlp_txg, policy.zlp_rewind);
5394
5395 /*
5396 * Propagate anything learned while loading the pool and pass it
5397 * back to caller (i.e. rewind info, missing devices, etc).
5398 */
5399 VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_LOAD_INFO,
5400 spa->spa_load_info) == 0);
5401

--- 110 unchanged lines hidden (view full) ---

5512nvlist_t *
5513spa_tryimport(nvlist_t *tryconfig)
5514{
5515 nvlist_t *config = NULL;
5516 char *poolname, *cachefile;
5517 spa_t *spa;
5518 uint64_t state;
5519 int error;
5394
5395 /*
5396 * Propagate anything learned while loading the pool and pass it
5397 * back to caller (i.e. rewind info, missing devices, etc).
5398 */
5399 VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_LOAD_INFO,
5400 spa->spa_load_info) == 0);
5401

--- 110 unchanged lines hidden (view full) ---

5512nvlist_t *
5513spa_tryimport(nvlist_t *tryconfig)
5514{
5515 nvlist_t *config = NULL;
5516 char *poolname, *cachefile;
5517 spa_t *spa;
5518 uint64_t state;
5519 int error;
5520 zpool_rewind_policy_t policy;
5520 zpool_load_policy_t policy;
5521
5522 if (nvlist_lookup_string(tryconfig, ZPOOL_CONFIG_POOL_NAME, &poolname))
5523 return (NULL);
5524
5525 if (nvlist_lookup_uint64(tryconfig, ZPOOL_CONFIG_POOL_STATE, &state))
5526 return (NULL);
5527
5528 /*
5529 * Create and initialize the spa structure.
5530 */
5531 mutex_enter(&spa_namespace_lock);
5532 spa = spa_add(TRYIMPORT_NAME, tryconfig, NULL);
5533 spa_activate(spa, FREAD);
5534
5535 /*
5521
5522 if (nvlist_lookup_string(tryconfig, ZPOOL_CONFIG_POOL_NAME, &poolname))
5523 return (NULL);
5524
5525 if (nvlist_lookup_uint64(tryconfig, ZPOOL_CONFIG_POOL_STATE, &state))
5526 return (NULL);
5527
5528 /*
5529 * Create and initialize the spa structure.
5530 */
5531 mutex_enter(&spa_namespace_lock);
5532 spa = spa_add(TRYIMPORT_NAME, tryconfig, NULL);
5533 spa_activate(spa, FREAD);
5534
5535 /*
5536 * Rewind pool if a max txg was provided. Note that even though we
5537 * retrieve the complete rewind policy, only the rewind txg is relevant
5538 * for tryimport.
5536 * Rewind pool if a max txg was provided.
5539 */
5537 */
5540 zpool_get_rewind_policy(spa->spa_config, &policy);
5541 if (policy.zrp_txg != UINT64_MAX) {
5542 spa->spa_load_max_txg = policy.zrp_txg;
5538 zpool_get_load_policy(spa->spa_config, &policy);
5539 if (policy.zlp_txg != UINT64_MAX) {
5540 spa->spa_load_max_txg = policy.zlp_txg;
5543 spa->spa_extreme_rewind = B_TRUE;
5544 zfs_dbgmsg("spa_tryimport: importing %s, max_txg=%lld",
5541 spa->spa_extreme_rewind = B_TRUE;
5542 zfs_dbgmsg("spa_tryimport: importing %s, max_txg=%lld",
5545 poolname, (longlong_t)policy.zrp_txg);
5543 poolname, (longlong_t)policy.zlp_txg);
5546 } else {
5547 zfs_dbgmsg("spa_tryimport: importing %s", poolname);
5548 }
5549
5550 if (nvlist_lookup_string(tryconfig, ZPOOL_CONFIG_CACHEFILE, &cachefile)
5551 == 0) {
5552 zfs_dbgmsg("spa_tryimport: using cachefile '%s'", cachefile);
5553 spa->spa_config_source = SPA_CONFIG_SRC_CACHEFILE;

--- 2769 unchanged lines hidden ---
5544 } else {
5545 zfs_dbgmsg("spa_tryimport: importing %s", poolname);
5546 }
5547
5548 if (nvlist_lookup_string(tryconfig, ZPOOL_CONFIG_CACHEFILE, &cachefile)
5549 == 0) {
5550 zfs_dbgmsg("spa_tryimport: using cachefile '%s'", cachefile);
5551 spa->spa_config_source = SPA_CONFIG_SRC_CACHEFILE;

--- 2769 unchanged lines hidden ---