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
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013 by Delphix. All rights reserved.
25 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
26 */
27
28 /*
29 * SPA: Storage Pool Allocator
30 *
31 * This file contains all the routines used when modifying on-disk SPA state.
32 * This includes opening, importing, destroying, exporting a pool, and syncing a
33 * pool.
34 */
35
36 #include <sys/zfs_context.h>
37 #include <sys/fm/fs/zfs.h>
38 #include <sys/spa_impl.h>
39 #include <sys/zio.h>
40 #include <sys/zio_checksum.h>
41 #include <sys/dmu.h>
42 #include <sys/dmu_tx.h>
43 #include <sys/zap.h>
44 #include <sys/zil.h>
45 #include <sys/ddt.h>
2393 "another system (host: %s hostid: 0x%lx). "
2394 "See: http://illumos.org/msg/ZFS-8000-EY",
2395 spa_name(spa), hostname,
2396 (unsigned long)hostid);
2397 return (SET_ERROR(EBADF));
2398 }
2399 }
2400 if (nvlist_lookup_nvlist(spa->spa_config,
2401 ZPOOL_REWIND_POLICY, &policy) == 0)
2402 VERIFY(nvlist_add_nvlist(nvconfig,
2403 ZPOOL_REWIND_POLICY, policy) == 0);
2404
2405 spa_config_set(spa, nvconfig);
2406 spa_unload(spa);
2407 spa_deactivate(spa);
2408 spa_activate(spa, orig_mode);
2409
2410 return (spa_load(spa, state, SPA_IMPORT_EXISTING, B_TRUE));
2411 }
2412
2413 if (spa_dir_prop(spa, DMU_POOL_SYNC_BPOBJ, &obj) != 0)
2414 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2415 error = bpobj_open(&spa->spa_deferred_bpobj, spa->spa_meta_objset, obj);
2416 if (error != 0)
2417 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2418
2419 /*
2420 * Load the bit that tells us to use the new accounting function
2421 * (raid-z deflation). If we have an older pool, this will not
2422 * be present.
2423 */
2424 error = spa_dir_prop(spa, DMU_POOL_DEFLATE, &spa->spa_deflate);
2425 if (error != 0 && error != ENOENT)
2426 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2427
2428 error = spa_dir_prop(spa, DMU_POOL_CREATION_VERSION,
2429 &spa->spa_creation_version);
2430 if (error != 0 && error != ENOENT)
2431 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2432
3539 * keeps changing.
3540 */
3541 obj = bpobj_alloc(spa->spa_meta_objset, 1 << 14, tx);
3542 dmu_object_set_compress(spa->spa_meta_objset, obj,
3543 ZIO_COMPRESS_OFF, tx);
3544 if (zap_add(spa->spa_meta_objset,
3545 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_SYNC_BPOBJ,
3546 sizeof (uint64_t), 1, &obj, tx) != 0) {
3547 cmn_err(CE_PANIC, "failed to add bpobj");
3548 }
3549 VERIFY3U(0, ==, bpobj_open(&spa->spa_deferred_bpobj,
3550 spa->spa_meta_objset, obj));
3551
3552 /*
3553 * Create the pool's history object.
3554 */
3555 if (version >= SPA_VERSION_ZPOOL_HISTORY)
3556 spa_history_create_obj(spa, tx);
3557
3558 /*
3559 * Set pool properties.
3560 */
3561 spa->spa_bootfs = zpool_prop_default_numeric(ZPOOL_PROP_BOOTFS);
3562 spa->spa_delegation = zpool_prop_default_numeric(ZPOOL_PROP_DELEGATION);
3563 spa->spa_failmode = zpool_prop_default_numeric(ZPOOL_PROP_FAILUREMODE);
3564 spa->spa_autoexpand = zpool_prop_default_numeric(ZPOOL_PROP_AUTOEXPAND);
3565
3566 if (props != NULL) {
3567 spa_configfile_set(spa, props, B_FALSE);
3568 spa_sync_props(props, tx);
3569 }
3570
3571 dmu_tx_commit(tx);
3572
3573 spa->spa_sync_on = B_TRUE;
3574 txg_sync_start(spa->spa_dsl_pool);
3575
3576 /*
3577 * We explicitly wait for the first transaction to complete so that our
3578 * bean counters are appropriately updated.
|
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
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013 by Delphix. All rights reserved.
25 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
26 * Copyright 2013 Saso Kiselkov. All rights reserved.
27 */
28
29 /*
30 * SPA: Storage Pool Allocator
31 *
32 * This file contains all the routines used when modifying on-disk SPA state.
33 * This includes opening, importing, destroying, exporting a pool, and syncing a
34 * pool.
35 */
36
37 #include <sys/zfs_context.h>
38 #include <sys/fm/fs/zfs.h>
39 #include <sys/spa_impl.h>
40 #include <sys/zio.h>
41 #include <sys/zio_checksum.h>
42 #include <sys/dmu.h>
43 #include <sys/dmu_tx.h>
44 #include <sys/zap.h>
45 #include <sys/zil.h>
46 #include <sys/ddt.h>
2394 "another system (host: %s hostid: 0x%lx). "
2395 "See: http://illumos.org/msg/ZFS-8000-EY",
2396 spa_name(spa), hostname,
2397 (unsigned long)hostid);
2398 return (SET_ERROR(EBADF));
2399 }
2400 }
2401 if (nvlist_lookup_nvlist(spa->spa_config,
2402 ZPOOL_REWIND_POLICY, &policy) == 0)
2403 VERIFY(nvlist_add_nvlist(nvconfig,
2404 ZPOOL_REWIND_POLICY, policy) == 0);
2405
2406 spa_config_set(spa, nvconfig);
2407 spa_unload(spa);
2408 spa_deactivate(spa);
2409 spa_activate(spa, orig_mode);
2410
2411 return (spa_load(spa, state, SPA_IMPORT_EXISTING, B_TRUE));
2412 }
2413
2414 /* Grab the secret checksum salt from the MOS. */
2415 if (spa_dir_prop(spa, DMU_POOL_CHECKSUM_SALT,
2416 &spa->spa_cksum_salt_obj) == 0) {
2417 if (zap_lookup(spa->spa_meta_objset, spa->spa_cksum_salt_obj,
2418 DMU_POOL_CHECKSUM_SALT, 1,
2419 sizeof (spa->spa_cksum_salt.zcs_bytes),
2420 spa->spa_cksum_salt.zcs_bytes) != 0) {
2421 /*
2422 * MOS format is broken, the salt object is there but
2423 * is missing the actual salt value.
2424 */
2425 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2426 }
2427 } else {
2428 /* Generate a new salt for subsequent use */
2429 (void) random_get_pseudo_bytes(spa->spa_cksum_salt.zcs_bytes,
2430 sizeof (spa->spa_cksum_salt.zcs_bytes));
2431 }
2432
2433 if (spa_dir_prop(spa, DMU_POOL_SYNC_BPOBJ, &obj) != 0)
2434 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2435 error = bpobj_open(&spa->spa_deferred_bpobj, spa->spa_meta_objset, obj);
2436 if (error != 0)
2437 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2438
2439 /*
2440 * Load the bit that tells us to use the new accounting function
2441 * (raid-z deflation). If we have an older pool, this will not
2442 * be present.
2443 */
2444 error = spa_dir_prop(spa, DMU_POOL_DEFLATE, &spa->spa_deflate);
2445 if (error != 0 && error != ENOENT)
2446 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2447
2448 error = spa_dir_prop(spa, DMU_POOL_CREATION_VERSION,
2449 &spa->spa_creation_version);
2450 if (error != 0 && error != ENOENT)
2451 return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, EIO));
2452
3559 * keeps changing.
3560 */
3561 obj = bpobj_alloc(spa->spa_meta_objset, 1 << 14, tx);
3562 dmu_object_set_compress(spa->spa_meta_objset, obj,
3563 ZIO_COMPRESS_OFF, tx);
3564 if (zap_add(spa->spa_meta_objset,
3565 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_SYNC_BPOBJ,
3566 sizeof (uint64_t), 1, &obj, tx) != 0) {
3567 cmn_err(CE_PANIC, "failed to add bpobj");
3568 }
3569 VERIFY3U(0, ==, bpobj_open(&spa->spa_deferred_bpobj,
3570 spa->spa_meta_objset, obj));
3571
3572 /*
3573 * Create the pool's history object.
3574 */
3575 if (version >= SPA_VERSION_ZPOOL_HISTORY)
3576 spa_history_create_obj(spa, tx);
3577
3578 /*
3579 * Generate some random noise for salted checksums to operate on. As
3580 * soon as a salted checksum is used for the first time we will
3581 * generate the persistent MOS object to hold the salt (see
3582 * spa_activate_salted_cksum).
3583 */
3584 (void) random_get_pseudo_bytes(spa->spa_cksum_salt.zcs_bytes,
3585 sizeof (spa->spa_cksum_salt.zcs_bytes));
3586
3587 /*
3588 * Set pool properties.
3589 */
3590 spa->spa_bootfs = zpool_prop_default_numeric(ZPOOL_PROP_BOOTFS);
3591 spa->spa_delegation = zpool_prop_default_numeric(ZPOOL_PROP_DELEGATION);
3592 spa->spa_failmode = zpool_prop_default_numeric(ZPOOL_PROP_FAILUREMODE);
3593 spa->spa_autoexpand = zpool_prop_default_numeric(ZPOOL_PROP_AUTOEXPAND);
3594
3595 if (props != NULL) {
3596 spa_configfile_set(spa, props, B_FALSE);
3597 spa_sync_props(props, tx);
3598 }
3599
3600 dmu_tx_commit(tx);
3601
3602 spa->spa_sync_on = B_TRUE;
3603 txg_sync_start(spa->spa_dsl_pool);
3604
3605 /*
3606 * We explicitly wait for the first transaction to complete so that our
3607 * bean counters are appropriately updated.
|