Deleted Added
full compact
spa.c (240868) spa.c (241286)
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

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

3545
3546 spa->spa_minref = refcount_count(&spa->spa_refcount);
3547
3548 mutex_exit(&spa_namespace_lock);
3549
3550 return (0);
3551}
3552
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

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

3545
3546 spa->spa_minref = refcount_count(&spa->spa_refcount);
3547
3548 mutex_exit(&spa_namespace_lock);
3549
3550 return (0);
3551}
3552
3553#if defined(sun)
3554#ifdef _KERNEL
3553#ifdef _KERNEL
3554#if defined(sun)
3555/*
3556 * Get the root pool information from the root disk, then import the root pool
3557 * during the system boot up time.
3558 */
3559extern int vdev_disk_read_rootlabel(char *, char *, nvlist_t **);
3560
3561static nvlist_t *
3562spa_generate_rootconf(char *devpath, char *devid, uint64_t *guid)

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

3748 vdev_free(rvd);
3749 spa_config_exit(spa, SCL_ALL, FTAG);
3750 mutex_exit(&spa_namespace_lock);
3751
3752 nvlist_free(config);
3753 return (error);
3754}
3755
3555/*
3556 * Get the root pool information from the root disk, then import the root pool
3557 * during the system boot up time.
3558 */
3559extern int vdev_disk_read_rootlabel(char *, char *, nvlist_t **);
3560
3561static nvlist_t *
3562spa_generate_rootconf(char *devpath, char *devid, uint64_t *guid)

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

3748 vdev_free(rvd);
3749 spa_config_exit(spa, SCL_ALL, FTAG);
3750 mutex_exit(&spa_namespace_lock);
3751
3752 nvlist_free(config);
3753 return (error);
3754}
3755
3756#endif
3756#else
3757
3758extern int
3759vdev_geom_read_pool_label(const char *name, nvlist_t **config);
3760
3761static nvlist_t *
3762spa_generate_rootconf(const char *name)
3763{
3764 nvlist_t *config;
3765 nvlist_t *nvtop, *nvroot;
3766 uint64_t pgid;
3767
3768 if (vdev_geom_read_pool_label(name, &config) != 0)
3769 return (NULL);
3770
3771 /*
3772 * Add this top-level vdev to the child array.
3773 */
3774 VERIFY(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
3775 &nvtop) == 0);
3776 VERIFY(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
3777 &pgid) == 0);
3778
3779 /*
3780 * Put this pool's top-level vdevs into a root vdev.
3781 */
3782 VERIFY(nvlist_alloc(&nvroot, NV_UNIQUE_NAME, KM_SLEEP) == 0);
3783 VERIFY(nvlist_add_string(nvroot, ZPOOL_CONFIG_TYPE,
3784 VDEV_TYPE_ROOT) == 0);
3785 VERIFY(nvlist_add_uint64(nvroot, ZPOOL_CONFIG_ID, 0ULL) == 0);
3786 VERIFY(nvlist_add_uint64(nvroot, ZPOOL_CONFIG_GUID, pgid) == 0);
3787 VERIFY(nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
3788 &nvtop, 1) == 0);
3789
3790 /*
3791 * Replace the existing vdev_tree with the new root vdev in
3792 * this pool's configuration (remove the old, add the new).
3793 */
3794 VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, nvroot) == 0);
3795 nvlist_free(nvroot);
3796 return (config);
3797}
3798
3799int
3800spa_import_rootpool(const char *name)
3801{
3802 spa_t *spa;
3803 vdev_t *rvd, *bvd, *avd = NULL;
3804 nvlist_t *config, *nvtop;
3805 uint64_t txg;
3806 char *pname;
3807 int error;
3808
3809 /*
3810 * Read the label from the boot device and generate a configuration.
3811 */
3812 config = spa_generate_rootconf(name);
3813 if (config == NULL) {
3814 cmn_err(CE_NOTE, "Cannot find the pool label for '%s'",
3815 name);
3816 return (EIO);
3817 }
3818
3819 VERIFY(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
3820 &pname) == 0 && strcmp(name, pname) == 0);
3821 VERIFY(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_TXG, &txg) == 0);
3822
3823 mutex_enter(&spa_namespace_lock);
3824 if ((spa = spa_lookup(pname)) != NULL) {
3825 /*
3826 * Remove the existing root pool from the namespace so that we
3827 * can replace it with the correct config we just read in.
3828 */
3829 spa_remove(spa);
3830 }
3831 spa = spa_add(pname, config, NULL);
3832 spa->spa_is_root = B_TRUE;
3833 spa->spa_import_flags = ZFS_IMPORT_VERBATIM;
3834
3835 /*
3836 * Build up a vdev tree based on the boot device's label config.
3837 */
3838 VERIFY(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
3839 &nvtop) == 0);
3840 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
3841 error = spa_config_parse(spa, &rvd, nvtop, NULL, 0,
3842 VDEV_ALLOC_ROOTPOOL);
3843 spa_config_exit(spa, SCL_ALL, FTAG);
3844 if (error) {
3845 mutex_exit(&spa_namespace_lock);
3846 nvlist_free(config);
3847 cmn_err(CE_NOTE, "Can not parse the config for pool '%s'",
3848 pname);
3849 return (error);
3850 }
3851
3852 error = 0;
3853 spa_history_log_version(spa, LOG_POOL_IMPORT);
3854out:
3855 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
3856 vdev_free(rvd);
3857 spa_config_exit(spa, SCL_ALL, FTAG);
3858 mutex_exit(&spa_namespace_lock);
3859
3860 return (error);
3861}
3862
3757#endif /* sun */
3863#endif /* sun */
3864#endif
3758
3759/*
3760 * Import a non-root pool into the system.
3761 */
3762int
3763spa_import(const char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags)
3764{
3765 spa_t *spa;

--- 2677 unchanged lines hidden ---
3865
3866/*
3867 * Import a non-root pool into the system.
3868 */
3869int
3870spa_import(const char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags)
3871{
3872 spa_t *spa;

--- 2677 unchanged lines hidden ---