Deleted Added
sdiff udiff text old ( 332529 ) new ( 332530 )
full compact
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

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

1291 */
1292static void
1293spa_unload(spa_t *spa)
1294{
1295 int i;
1296
1297 ASSERT(MUTEX_HELD(&spa_namespace_lock));
1298
1299 /*
1300 * Stop TRIM thread.
1301 */
1302 trim_thread_destroy(spa);
1303
1304 /*
1305 * Stop async tasks.
1306 */

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

2064 dsl_pool_config_exit(spa->spa_dsl_pool, FTAG);
2065 if (error != 0)
2066 return (error);
2067
2068 rio = zio_root(spa, NULL, &sle,
2069 ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE);
2070
2071 if (spa_load_verify_metadata) {
2072 error = traverse_pool(spa, spa->spa_verify_min_txg,
2073 TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA,
2074 spa_load_verify_cb, rio);
2075 }
2076
2077 (void) zio_wait(rio);
2078
2079 spa->spa_load_meta_errors = sle.sle_meta_count;

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

2116 (void) zap_lookup(spa->spa_meta_objset, spa->spa_pool_props_object,
2117 zpool_prop_to_name(prop), sizeof (uint64_t), 1, val);
2118}
2119
2120/*
2121 * Find a value in the pool directory object.
2122 */
2123static int
2124spa_dir_prop(spa_t *spa, const char *name, uint64_t *val)
2125{
2126 return (zap_lookup(spa->spa_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
2127 name, sizeof (uint64_t), 1, val));
2128}
2129
2130static int
2131spa_vdev_err(vdev_t *vdev, vdev_aux_t aux, int err)
2132{
2133 vdev_set_state(vdev, B_TRUE, VDEV_STATE_CANT_OPEN, aux);
2134 return (SET_ERROR(err));
2135}

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

2311 total += vdev_count_verify_zaps(vd->vdev_child[i]);
2312 }
2313
2314 return (total);
2315}
2316
2317static int
2318spa_ld_parse_config(spa_t *spa, uint64_t pool_guid, nvlist_t *config,
2319 spa_load_state_t state, spa_import_type_t type)
2320{
2321 int error = 0;
2322 nvlist_t *nvtree = NULL;
2323 int parse;
2324 vdev_t *rvd;
2325
2326 ASSERT(MUTEX_HELD(&spa_namespace_lock));
2327
2328 spa->spa_load_state = state;
2329
2330 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &nvtree))
2331 return (SET_ERROR(EINVAL));
2332
2333 parse = (type == SPA_IMPORT_EXISTING ?
2334 VDEV_ALLOC_LOAD : VDEV_ALLOC_SPLIT);
2335
2336 /*
2337 * Create "The Godfather" zio to hold all async IOs
2338 */
2339 spa->spa_async_zio_root = kmem_alloc(max_ncpus * sizeof (void *),

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

2348 * Parse the configuration into a vdev tree. We explicitly set the
2349 * value that will be returned by spa_version() since parsing the
2350 * configuration requires knowing the version number.
2351 */
2352 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
2353 error = spa_config_parse(spa, &rvd, nvtree, NULL, 0, parse);
2354 spa_config_exit(spa, SCL_ALL, FTAG);
2355
2356 if (error != 0)
2357 return (error);
2358
2359 ASSERT(spa->spa_root_vdev == rvd);
2360 ASSERT3U(spa->spa_min_ashift, >=, SPA_MINBLOCKSHIFT);
2361 ASSERT3U(spa->spa_max_ashift, <=, SPA_MAXBLOCKSHIFT);
2362
2363 if (type != SPA_IMPORT_ASSEMBLE) {
2364 ASSERT(spa_guid(spa) == pool_guid);
2365 }

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

2370static int
2371spa_ld_open_vdevs(spa_t *spa)
2372{
2373 int error = 0;
2374
2375 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
2376 error = vdev_open(spa->spa_root_vdev);
2377 spa_config_exit(spa, SCL_ALL, FTAG);
2378
2379 return (error);
2380}
2381
2382static int
2383spa_ld_validate_vdevs(spa_t *spa, spa_import_type_t type,
2384 boolean_t trust_config)
2385{

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

2399 * existing pool, the labels haven't yet been updated so we skip
2400 * validation for now.
2401 */
2402 if (type != SPA_IMPORT_ASSEMBLE) {
2403 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
2404 error = vdev_validate(rvd, trust_config);
2405 spa_config_exit(spa, SCL_ALL, FTAG);
2406
2407 if (error != 0)
2408 return (error);
2409
2410 if (rvd->vdev_state <= VDEV_STATE_CANT_OPEN)
2411 return (SET_ERROR(ENXIO));
2412 }
2413
2414 return (0);
2415}
2416
2417static int
2418spa_ld_select_uberblock(spa_t *spa, nvlist_t *config, spa_import_type_t type,
2419 boolean_t trust_config)

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

2428 */
2429 vdev_uberblock_load(rvd, ub, &label);
2430
2431 /*
2432 * If we weren't able to find a single valid uberblock, return failure.
2433 */
2434 if (ub->ub_txg == 0) {
2435 nvlist_free(label);
2436 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, ENXIO));
2437 }
2438
2439 /*
2440 * If the pool has an unsupported version we can't open it.
2441 */
2442 if (!SPA_VERSION_IS_SUPPORTED(ub->ub_version)) {
2443 nvlist_free(label);
2444 return (spa_vdev_err(rvd, VDEV_AUX_VERSION_NEWER, ENOTSUP));
2445 }
2446
2447 if (ub->ub_version >= SPA_VERSION_FEATURES) {
2448 nvlist_t *features;
2449
2450 /*
2451 * If we weren't able to find what's necessary for reading the
2452 * MOS in the label, return failure.
2453 */
2454 if (label == NULL || nvlist_lookup_nvlist(label,
2455 ZPOOL_CONFIG_FEATURES_FOR_READ, &features) != 0) {
2456 nvlist_free(label);
2457 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA,
2458 ENXIO));
2459 }
2460
2461 /*
2462 * Update our in-core representation with the definitive values
2463 * from the label.
2464 */

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

2487 nvpair_name(nvp), "") == 0);
2488 }
2489 }
2490
2491 if (!nvlist_empty(unsup_feat)) {
2492 VERIFY(nvlist_add_nvlist(spa->spa_load_info,
2493 ZPOOL_CONFIG_UNSUP_FEAT, unsup_feat) == 0);
2494 nvlist_free(unsup_feat);
2495 return (spa_vdev_err(rvd, VDEV_AUX_UNSUP_FEAT,
2496 ENOTSUP));
2497 }
2498
2499 nvlist_free(unsup_feat);
2500 }
2501
2502 /*
2503 * If the vdev guid sum doesn't match the uberblock, we have an
2504 * incomplete configuration. We first check to see if the pool
2505 * is aware of the complete config (i.e ZPOOL_CONFIG_VDEV_CHILDREN).
2506 * If it is, defer the vdev_guid_sum check till later so we
2507 * can handle missing vdevs.
2508 */
2509 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_VDEV_CHILDREN,
2510 &children) != 0 && trust_config && type != SPA_IMPORT_ASSEMBLE &&
2511 rvd->vdev_guid_sum != ub->ub_guid_sum)
2512 return (spa_vdev_err(rvd, VDEV_AUX_BAD_GUID_SUM, ENXIO));
2513
2514 if (type != SPA_IMPORT_ASSEMBLE && spa->spa_config_splitting) {
2515 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
2516 spa_try_repair(spa, config);
2517 spa_config_exit(spa, SCL_ALL, FTAG);
2518 nvlist_free(spa->spa_config_splitting);
2519 spa->spa_config_splitting = NULL;
2520 }

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

2536
2537static int
2538spa_ld_open_rootbp(spa_t *spa)
2539{
2540 int error = 0;
2541 vdev_t *rvd = spa->spa_root_vdev;
2542
2543 error = dsl_pool_init(spa, spa->spa_first_txg, &spa->spa_dsl_pool);
2544 if (error)
2545 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2546 spa->spa_meta_objset = spa->spa_dsl_pool->dp_meta_objset;
2547
2548 return (0);
2549}
2550
2551static int
2552spa_ld_validate_config(spa_t *spa, spa_import_type_t type)
2553{
2554 vdev_t *rvd = spa->spa_root_vdev;
2555
2556 if (spa_dir_prop(spa, DMU_POOL_CONFIG, &spa->spa_config_object) != 0)
2557 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2558
2559 /*
2560 * Validate the config, using the MOS config to fill in any
2561 * information which might be missing. If we fail to validate
2562 * the config then declare the pool unfit for use. If we're
2563 * assembling a pool from a split, the log is not transferred
2564 * over.
2565 */
2566 if (type != SPA_IMPORT_ASSEMBLE) {
2567 nvlist_t *mos_config;
2568 if (load_nvlist(spa, spa->spa_config_object, &mos_config) != 0)
2569 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2570
2571 if (!spa_config_valid(spa, mos_config)) {
2572 nvlist_free(mos_config);
2573 return (spa_vdev_err(rvd, VDEV_AUX_BAD_GUID_SUM,
2574 ENXIO));
2575 }
2576 nvlist_free(mos_config);
2577
2578 /*
2579 * Now that we've validated the config, check the state of the
2580 * root vdev. If it can't be opened, it indicates one or
2581 * more toplevel vdevs are faulted.
2582 */
2583 if (rvd->vdev_state <= VDEV_STATE_CANT_OPEN)
2584 return (SET_ERROR(ENXIO));
2585 }
2586
2587 return (0);
2588}
2589
2590static int
2591spa_ld_open_indirect_vdev_metadata(spa_t *spa)
2592{
2593 int error = 0;
2594 vdev_t *rvd = spa->spa_root_vdev;
2595
2596 /*
2597 * Everything that we read before spa_remove_init() must be stored
2598 * on concreted vdevs. Therefore we do this as early as possible.
2599 */
2600 if (spa_remove_init(spa) != 0)
2601 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2602
2603 /*
2604 * Retrieve information needed to condense indirect vdev mappings.
2605 */
2606 error = spa_condense_init(spa);
2607 if (error != 0) {
2608 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, error));
2609 }
2610
2611 return (0);
2612}
2613
2614static int
2615spa_ld_check_features(spa_t *spa, spa_load_state_t state,
2616 boolean_t *missing_feat_writep)
2617{
2618 int error = 0;
2619 vdev_t *rvd = spa->spa_root_vdev;
2620
2621 if (spa_version(spa) >= SPA_VERSION_FEATURES) {
2622 boolean_t missing_feat_read = B_FALSE;
2623 nvlist_t *unsup_feat, *enabled_feat;
2624
2625 if (spa_dir_prop(spa, DMU_POOL_FEATURES_FOR_READ,
2626 &spa->spa_feat_for_read_obj) != 0) {
2627 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2628 }
2629
2630 if (spa_dir_prop(spa, DMU_POOL_FEATURES_FOR_WRITE,
2631 &spa->spa_feat_for_write_obj) != 0) {
2632 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2633 }
2634
2635 if (spa_dir_prop(spa, DMU_POOL_FEATURE_DESCRIPTIONS,
2636 &spa->spa_feat_desc_obj) != 0) {
2637 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2638 }
2639
2640 enabled_feat = fnvlist_alloc();
2641 unsup_feat = fnvlist_alloc();
2642
2643 if (!spa_features_check(spa, B_FALSE,
2644 unsup_feat, enabled_feat))
2645 missing_feat_read = B_TRUE;
2646
2647 if (spa_writeable(spa) || state == SPA_LOAD_TRYIMPORT) {
2648 if (!spa_features_check(spa, B_TRUE,
2649 unsup_feat, enabled_feat)) {
2650 *missing_feat_writep = B_TRUE;
2651 }
2652 }
2653
2654 fnvlist_add_nvlist(spa->spa_load_info,
2655 ZPOOL_CONFIG_ENABLED_FEAT, enabled_feat);

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

2683 * As a result, if the state is SPA_LOAD_TRYIMPORT and we are
2684 * missing a feature for write, we must first determine whether
2685 * the pool can be opened read-only before returning to
2686 * userland in order to know whether to display the
2687 * abovementioned note.
2688 */
2689 if (missing_feat_read || (*missing_feat_writep &&
2690 spa_writeable(spa))) {
2691 return (spa_vdev_err(rvd, VDEV_AUX_UNSUP_FEAT,
2692 ENOTSUP));
2693 }
2694
2695 /*
2696 * Load refcounts for ZFS features from disk into an in-memory
2697 * cache during SPA initialization.
2698 */
2699 for (spa_feature_t i = 0; i < SPA_FEATURES; i++) {
2700 uint64_t refcount;
2701
2702 error = feature_get_refcount_from_disk(spa,
2703 &spa_feature_table[i], &refcount);
2704 if (error == 0) {
2705 spa->spa_feat_refcount_cache[i] = refcount;
2706 } else if (error == ENOTSUP) {
2707 spa->spa_feat_refcount_cache[i] =
2708 SPA_FEATURE_DISABLED;
2709 } else {
2710 return (spa_vdev_err(rvd,
2711 VDEV_AUX_CORRUPT_DATA, EIO));
2712 }
2713 }
2714 }
2715
2716 if (spa_feature_is_active(spa, SPA_FEATURE_ENABLED_TXG)) {
2717 if (spa_dir_prop(spa, DMU_POOL_FEATURE_ENABLED_TXG,
2718 &spa->spa_feat_enabled_txg_obj) != 0)
2719 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2720 }
2721
2722 return (0);
2723}
2724
2725static int
2726spa_ld_load_special_directories(spa_t *spa)
2727{
2728 int error = 0;
2729 vdev_t *rvd = spa->spa_root_vdev;
2730
2731 spa->spa_is_initializing = B_TRUE;
2732 error = dsl_pool_open(spa->spa_dsl_pool);
2733 spa->spa_is_initializing = B_FALSE;
2734 if (error != 0)
2735 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2736
2737 return (0);
2738}
2739
2740static int
2741spa_ld_prepare_for_reload(spa_t *spa, int orig_mode)
2742{
2743 vdev_t *rvd = spa->spa_root_vdev;
2744
2745 uint64_t hostid;
2746 nvlist_t *policy = NULL;
2747 nvlist_t *mos_config;
2748
2749 if (load_nvlist(spa, spa->spa_config_object, &mos_config) != 0)
2750 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2751
2752 if (!spa_is_root(spa) && nvlist_lookup_uint64(mos_config,
2753 ZPOOL_CONFIG_HOSTID, &hostid) == 0) {
2754 char *hostname;
2755 unsigned long myhostid = 0;
2756
2757 VERIFY(nvlist_lookup_string(mos_config,
2758 ZPOOL_CONFIG_HOSTNAME, &hostname) == 0);

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

2803 DMU_POOL_CHECKSUM_SALT, 1,
2804 sizeof (spa->spa_cksum_salt.zcs_bytes),
2805 spa->spa_cksum_salt.zcs_bytes);
2806 if (error == ENOENT) {
2807 /* Generate a new salt for subsequent use */
2808 (void) random_get_pseudo_bytes(spa->spa_cksum_salt.zcs_bytes,
2809 sizeof (spa->spa_cksum_salt.zcs_bytes));
2810 } else if (error != 0) {
2811 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2812 }
2813
2814 if (spa_dir_prop(spa, DMU_POOL_SYNC_BPOBJ, &obj) != 0)
2815 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2816 error = bpobj_open(&spa->spa_deferred_bpobj, spa->spa_meta_objset, obj);
2817 if (error != 0)
2818 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2819
2820 /*
2821 * Load the bit that tells us to use the new accounting function
2822 * (raid-z deflation). If we have an older pool, this will not
2823 * be present.
2824 */
2825 error = spa_dir_prop(spa, DMU_POOL_DEFLATE, &spa->spa_deflate);
2826 if (error != 0 && error != ENOENT)
2827 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2828
2829 error = spa_dir_prop(spa, DMU_POOL_CREATION_VERSION,
2830 &spa->spa_creation_version);
2831 if (error != 0 && error != ENOENT)
2832 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2833
2834 /*
2835 * Load the persistent error log. If we have an older pool, this will
2836 * not be present.
2837 */
2838 error = spa_dir_prop(spa, DMU_POOL_ERRLOG_LAST, &spa->spa_errlog_last);
2839 if (error != 0 && error != ENOENT)
2840 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2841
2842 error = spa_dir_prop(spa, DMU_POOL_ERRLOG_SCRUB,
2843 &spa->spa_errlog_scrub);
2844 if (error != 0 && error != ENOENT)
2845 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2846
2847 /*
2848 * Load the history object. If we have an older pool, this
2849 * will not be present.
2850 */
2851 error = spa_dir_prop(spa, DMU_POOL_HISTORY, &spa->spa_history);
2852 if (error != 0 && error != ENOENT)
2853 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2854
2855 /*
2856 * Load the per-vdev ZAP map. If we have an older pool, this will not
2857 * be present; in this case, defer its creation to a later time to
2858 * avoid dirtying the MOS this early / out of sync context. See
2859 * spa_sync_config_object.
2860 */
2861
2862 /* The sentinel is only available in the MOS config. */
2863 nvlist_t *mos_config;
2864 if (load_nvlist(spa, spa->spa_config_object, &mos_config) != 0)
2865 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2866
2867 error = spa_dir_prop(spa, DMU_POOL_VDEV_ZAP_MAP,
2868 &spa->spa_all_vdev_zaps);
2869
2870 if (error == ENOENT) {
2871 VERIFY(!nvlist_exists(mos_config,
2872 ZPOOL_CONFIG_HAS_PER_VDEV_ZAPS));
2873 spa->spa_avz_action = AVZ_ACTION_INITIALIZE;
2874 ASSERT0(vdev_count_verify_zaps(spa->spa_root_vdev));
2875 } else if (error != 0) {
2876 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));

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

2886 * before this. Better be sure of it.
2887 */
2888 ASSERT0(vdev_count_verify_zaps(spa->spa_root_vdev));
2889 }
2890 nvlist_free(mos_config);
2891
2892 spa->spa_delegation = zpool_prop_default_numeric(ZPOOL_PROP_DELEGATION);
2893
2894 error = spa_dir_prop(spa, DMU_POOL_PROPS, &spa->spa_pool_props_object);
2895 if (error && error != ENOENT)
2896 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2897
2898 if (error == 0) {
2899 uint64_t autoreplace;
2900
2901 spa_prop_find(spa, ZPOOL_PROP_BOOTFS, &spa->spa_bootfs);
2902 spa_prop_find(spa, ZPOOL_PROP_AUTOREPLACE, &autoreplace);

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

2922 * If we're assembling the pool from the split-off vdevs of
2923 * an existing pool, we don't want to attach the spares & cache
2924 * devices.
2925 */
2926
2927 /*
2928 * Load any hot spares for this pool.
2929 */
2930 error = spa_dir_prop(spa, DMU_POOL_SPARES, &spa->spa_spares.sav_object);
2931 if (error != 0 && error != ENOENT)
2932 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2933 if (error == 0 && type != SPA_IMPORT_ASSEMBLE) {
2934 ASSERT(spa_version(spa) >= SPA_VERSION_SPARES);
2935 if (load_nvlist(spa, spa->spa_spares.sav_object,
2936 &spa->spa_spares.sav_config) != 0)
2937 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2938
2939 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
2940 spa_load_spares(spa);
2941 spa_config_exit(spa, SCL_ALL, FTAG);
2942 } else if (error == 0) {
2943 spa->spa_spares.sav_sync = B_TRUE;
2944 }
2945
2946 /*
2947 * Load any level 2 ARC devices for this pool.
2948 */
2949 error = spa_dir_prop(spa, DMU_POOL_L2CACHE,
2950 &spa->spa_l2cache.sav_object);
2951 if (error != 0 && error != ENOENT)
2952 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2953 if (error == 0 && type != SPA_IMPORT_ASSEMBLE) {
2954 ASSERT(spa_version(spa) >= SPA_VERSION_L2CACHE);
2955 if (load_nvlist(spa, spa->spa_l2cache.sav_object,
2956 &spa->spa_l2cache.sav_config) != 0)
2957 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2958
2959 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
2960 spa_load_l2cache(spa);
2961 spa_config_exit(spa, SCL_ALL, FTAG);
2962 } else if (error == 0) {
2963 spa->spa_l2cache.sav_sync = B_TRUE;
2964 }
2965
2966 return (0);
2967}
2968
2969static int
2970spa_ld_load_vdev_metadata(spa_t *spa, spa_load_state_t state)
2971{
2972 int error = 0;
2973 vdev_t *rvd = spa->spa_root_vdev;
2974
2975 /*
2976 * If the 'autoreplace' property is set, then post a resource notifying
2977 * the ZFS DE that it should not issue any faults for unopenable
2978 * devices. We also iterate over the vdevs, and post a sysevent for any
2979 * unopenable vdevs so that the normal autoreplace handler can take
2980 * over.
2981 */
2982 if (spa->spa_autoreplace && state != SPA_LOAD_TRYIMPORT) {
2983 spa_check_removed(spa->spa_root_vdev);
2984 /*
2985 * For the import case, this is done in spa_import(), because
2986 * at this point we're using the spare definitions from
2987 * the MOS config, not necessarily from the userland config.
2988 */
2989 if (state != SPA_LOAD_IMPORT) {
2990 spa_aux_check_removed(&spa->spa_spares);
2991 spa_aux_check_removed(&spa->spa_l2cache);
2992 }
2993 }
2994
2995 /*
2996 * Load the vdev metadata such as metaslabs, DTLs, spacemap object, etc.
2997 */
2998 error = vdev_load(rvd);
2999 if (error != 0) {
3000 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, error));
3001 }
3002
3003 /*
3004 * Propagate the leaf DTLs we just loaded all the way up the vdev tree.
3005 */
3006 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
3007 vdev_dtl_reassess(rvd, 0, 0, B_FALSE);

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

3012
3013static int
3014spa_ld_load_dedup_tables(spa_t *spa)
3015{
3016 int error = 0;
3017 vdev_t *rvd = spa->spa_root_vdev;
3018
3019 error = ddt_load(spa);
3020 if (error != 0)
3021 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
3022
3023 return (0);
3024}
3025
3026static int
3027spa_ld_verify_logs(spa_t *spa, spa_import_type_t type, char **ereport)
3028{
3029 vdev_t *rvd = spa->spa_root_vdev;
3030
3031 if (type != SPA_IMPORT_ASSEMBLE && spa_writeable(spa) &&
3032 spa_check_logs(spa)) {
3033 *ereport = FM_EREPORT_ZFS_LOG_REPLAY;
3034 return (spa_vdev_err(rvd, VDEV_AUX_BAD_LOG, ENXIO));
3035 }
3036
3037 return (0);
3038}
3039
3040static int
3041spa_ld_verify_pool_data(spa_t *spa, spa_load_state_t state)
3042{
3043 int error = 0;
3044 vdev_t *rvd = spa->spa_root_vdev;
3045
3046 /*
3047 * We've successfully opened the pool, verify that we're ready
3048 * to start pushing transactions.
3049 */
3050 if (state != SPA_LOAD_TRYIMPORT) {
3051 error = spa_load_verify(spa);
3052 if (error != 0) {
3053 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA,
3054 error));
3055 }
3056 }
3057
3058 return (0);
3059}
3060

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

3079 dmu_tx_commit(tx);
3080
3081 spa->spa_claiming = B_FALSE;
3082
3083 spa_set_log_state(spa, SPA_LOG_GOOD);
3084}
3085
3086static void
3087spa_ld_check_for_config_update(spa_t *spa, spa_load_state_t state,
3088 int64_t config_cache_txg)
3089{
3090 vdev_t *rvd = spa->spa_root_vdev;
3091 int need_update = B_FALSE;
3092
3093 /*
3094 * If the config cache is stale, or we have uninitialized
3095 * metaslabs (see spa_vdev_add()), then update the config.
3096 *
3097 * If this is a verbatim import, trust the current
3098 * in-core spa_config and update the disk labels.
3099 */
3100 if (config_cache_txg != spa->spa_config_txg ||
3101 state == SPA_LOAD_IMPORT ||
3102 state == SPA_LOAD_RECOVER ||
3103 (spa->spa_import_flags & ZFS_IMPORT_VERBATIM))
3104 need_update = B_TRUE;
3105
3106 for (int c = 0; c < rvd->vdev_children; c++)
3107 if (rvd->vdev_child[c]->vdev_ms_array == 0)
3108 need_update = B_TRUE;
3109
3110 /*

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

3126 spa_load_state_t state, spa_import_type_t type, boolean_t trust_config,
3127 char **ereport)
3128{
3129 int error = 0;
3130 uint64_t config_cache_txg = spa->spa_config_txg;
3131 int orig_mode = spa->spa_mode;
3132 boolean_t missing_feat_write = B_FALSE;
3133
3134 /*
3135 * If this is an untrusted config, first access the pool in read-only
3136 * mode. We will then retrieve a trusted copy of the config from the MOS
3137 * and use it to reopen the pool in read-write mode.
3138 */
3139 if (!trust_config)
3140 spa->spa_mode = FREAD;
3141
3142 /*
3143 * Parse the config provided to create a vdev tree.
3144 */
3145 error = spa_ld_parse_config(spa, pool_guid, config, state, type);
3146 if (error != 0)
3147 return (error);
3148
3149 /*
3150 * Now that we have the vdev tree, try to open each vdev. This involves
3151 * opening the underlying physical device, retrieving its geometry and
3152 * probing the vdev with a dummy I/O. The state of each vdev will be set
3153 * based on the success of those operations. After this we'll be ready

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

3205 error = spa_ld_open_indirect_vdev_metadata(spa);
3206 if (error != 0)
3207 return (error);
3208
3209 /*
3210 * Retrieve the full list of active features from the MOS and check if
3211 * they are all supported.
3212 */
3213 error = spa_ld_check_features(spa, state, &missing_feat_write);
3214 if (error != 0)
3215 return (error);
3216
3217 /*
3218 * Load several special directories from the MOS needed by the dsl_pool
3219 * layer.
3220 */
3221 error = spa_ld_load_special_directories(spa);
3222 if (error != 0)
3223 return (error);
3224
3225 /*
3226 * If the config provided is not trusted, discard it and use the config
3227 * from the MOS to reload the pool.
3228 */
3229 if (!trust_config) {
3230 error = spa_ld_prepare_for_reload(spa, orig_mode);
3231 if (error != 0)
3232 return (error);
3233 return (spa_load(spa, state, SPA_IMPORT_EXISTING, B_TRUE));
3234 }
3235
3236 /*
3237 * Retrieve pool properties from the MOS.
3238 */
3239 error = spa_ld_get_props(spa);
3240 if (error != 0)

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

3247 error = spa_ld_open_aux_vdevs(spa, type);
3248 if (error != 0)
3249 return (error);
3250
3251 /*
3252 * Load the metadata for all vdevs. Also check if unopenable devices
3253 * should be autoreplaced.
3254 */
3255 error = spa_ld_load_vdev_metadata(spa, state);
3256 if (error != 0)
3257 return (error);
3258
3259 error = spa_ld_load_dedup_tables(spa);
3260 if (error != 0)
3261 return (error);
3262
3263 /*

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

3280 ENOTSUP));
3281 }
3282
3283 /*
3284 * Traverse the last txgs to make sure the pool was left off in a safe
3285 * state. When performing an extreme rewind, we verify the whole pool,
3286 * which can take a very long time.
3287 */
3288 error = spa_ld_verify_pool_data(spa, state);
3289 if (error != 0)
3290 return (error);
3291
3292 /*
3293 * Calculate the deflated space for the pool. This must be done before
3294 * we write anything to the pool because we'd need to update the space
3295 * accounting using the deflated sizes.
3296 */

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

3337 */
3338 txg_wait_synced(spa->spa_dsl_pool, spa->spa_claim_max_txg);
3339
3340 /*
3341 * Check if we need to request an update of the config. On the
3342 * next sync, we would update the config stored in vdev labels
3343 * and the cachefile (by default /etc/zfs/zpool.cache).
3344 */
3345 spa_ld_check_for_config_update(spa, state, config_cache_txg);
3346
3347 /*
3348 * Check all DTLs to see if anything needs resilvering.
3349 */
3350 if (!dsl_scan_resilvering(spa->spa_dsl_pool) &&
3351 vdev_resilver_needed(spa->spa_root_vdev, NULL, NULL))
3352 spa_async_request(spa, SPA_ASYNC_RESILVER);
3353

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

3374 * can start a removal while we hold the spa_namespace_lock.
3375 */
3376 spa_restart_removal(spa);
3377
3378 if (condense_in_progress)
3379 spa_condense_indirect_restart(spa);
3380 }
3381
3382 return (0);
3383}
3384
3385static int
3386spa_load_retry(spa_t *spa, spa_load_state_t state, int trust_config)
3387{
3388 int mode = spa->spa_mode;
3389
3390 spa_unload(spa);
3391 spa_deactivate(spa);
3392
3393 spa->spa_load_max_txg = spa->spa_uberblock.ub_txg - 1;
3394
3395 spa_activate(spa, mode);
3396 spa_async_suspend(spa);
3397
3398 return (spa_load(spa, state, SPA_IMPORT_EXISTING, trust_config));
3399}
3400
3401/*
3402 * If spa_load() fails this function will try loading prior txg's. If
3403 * 'state' is SPA_LOAD_RECOVER and one of these loads succeeds the pool
3404 * will be rewound to that txg. If 'state' is not SPA_LOAD_RECOVER this
3405 * function will not rewind the pool and will return the same error as

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

3544 if (policy.zrp_request & ZPOOL_DO_REWIND)
3545 state = SPA_LOAD_RECOVER;
3546
3547 spa_activate(spa, spa_mode_global);
3548
3549 if (state != SPA_LOAD_RECOVER)
3550 spa->spa_last_ubsync_txg = spa->spa_load_txg = 0;
3551
3552 error = spa_load_best(spa, state, B_FALSE, policy.zrp_txg,
3553 policy.zrp_request);
3554
3555 if (error == EBADF) {
3556 /*
3557 * If vdev_validate() returns failure (indicated by
3558 * EBADF), it indicates that one of the vdevs indicates
3559 * that the pool has been exported or destroyed. If

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

4766 * as if it had been loaded at boot.
4767 */
4768 if (spa->spa_import_flags & ZFS_IMPORT_VERBATIM) {
4769 if (props != NULL)
4770 spa_configfile_set(spa, props, B_FALSE);
4771
4772 spa_write_cachefile(spa, B_FALSE, B_TRUE);
4773 spa_event_notify(spa, NULL, NULL, ESC_ZFS_POOL_IMPORT);
4774
4775 mutex_exit(&spa_namespace_lock);
4776 return (0);
4777 }
4778
4779 spa_activate(spa, mode);
4780
4781 /*
4782 * Don't start async tasks until we know everything is healthy.

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

4790 /*
4791 * Pass off the heavy lifting to spa_load(). Pass TRUE for trust_config
4792 * because the user-supplied config is actually the one to trust when
4793 * doing an import.
4794 */
4795 if (state != SPA_LOAD_RECOVER)
4796 spa->spa_last_ubsync_txg = spa->spa_load_txg = 0;
4797
4798 error = spa_load_best(spa, state, B_TRUE, policy.zrp_txg,
4799 policy.zrp_request);
4800
4801 /*
4802 * Propagate anything learned while loading the pool and pass it
4803 * back to caller (i.e. rewind info, missing devices, etc).
4804 */
4805 VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_LOAD_INFO,

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

4932
4933 /*
4934 * Create and initialize the spa structure.
4935 */
4936 mutex_enter(&spa_namespace_lock);
4937 spa = spa_add(TRYIMPORT_NAME, tryconfig, NULL);
4938 spa_activate(spa, FREAD);
4939
4940 /*
4941 * Pass off the heavy lifting to spa_load().
4942 * Pass TRUE for trust_config because the user-supplied config
4943 * is actually the one to trust when doing an import.
4944 */
4945 error = spa_load(spa, SPA_LOAD_TRYIMPORT, SPA_IMPORT_EXISTING, B_TRUE);
4946
4947 /*

--- 2699 unchanged lines hidden ---