aboutsummaryrefslogtreecommitdiffstats
path: root/uts
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2018-12-26 10:41:17 +0000
committerAndriy Gapon <avg@FreeBSD.org>2018-12-26 10:41:17 +0000
commit207bd3fed67f7228191c53a2bdadb135476271b0 (patch)
treee63de6e690e27ed27f7fc698bcc731e3c41be335 /uts
parent48114cb5bef6d2b4383107fbabd77fd0e52c3dee (diff)
downloadsrc-207bd3fed67f7228191c53a2bdadb135476271b0.tar.gz
src-207bd3fed67f7228191c53a2bdadb135476271b0.zip
5882 Temporary pool names
illumos/illumos-gate@04e56356520b98d5a93c496b10f02530bb6647e0 https://github.com/illumos/illumos-gate/commit/04e56356520b98d5a93c496b10f02530bb6647e0 https://www.illumos.org/issues/5882 This is an import of the temporary pool names functionality from ZoL: https://github.com/zfsonlinux/zfs/commit/ e2282ef57edc79cdce2a4b9b7e3333c56494a807 https://github.com/zfsonlinux/zfs/commit/ 26b42f3f9d03f85cc7966dc2fe4dfe9216601b0e https://github.com/zfsonlinux/zfs/commit/ 2f3ec9006146844af6763d1fa4e823fd9047fd54 https://github.com/zfsonlinux/zfs/commit/ 00d2a8c92f614f49d23dea5d73f7ea7eb489ccf1 https://github.com/zfsonlinux/zfs/commit/ 83e9986f6eefdf0afc387f06407087bba3ead4e9 https://github.com/zfsonlinux/zfs/commit/ 023bbe6f017380f4a04c5060feb24dd8cdda9fce It is intended to assist the creation and management of virtual machines that have their rootfs on ZFS on hosts that also have their rootfs on ZFS. These situations cause SPA namespace collisions when the standard name rpool is used in both cases. The solution is either to give each guest pool a name unique to the host, which is not always desireable, or boot a VM environment containing an ISO image to install it, which is cumbersome. As a side note, this commit includes the removal of `zpool import -r`, which previously did nothing. patch [Magnifier] (14.3 KB) Richard Yao, 2015-04-30 04:33 PM Reviewed by: Matt Ahrens <matt@delphix.com> Reviewed by: Igor Kozhukhov <igor@dilos.org> Reviewed by: John Kennedy <john.kennedy@delphix.com> Approved by: Dan McDonald <danmcd@joyent.com> Author: Andriy Gapon <agapon@panzura.com>
Notes
Notes: svn path=/vendor-sys/illumos/dist/; revision=342532
Diffstat (limited to 'uts')
-rw-r--r--uts/common/fs/zfs/spa.c19
-rw-r--r--uts/common/fs/zfs/spa_config.c30
-rw-r--r--uts/common/fs/zfs/zfs_ioctl.c10
-rw-r--r--uts/common/sys/fs/zfs.h4
4 files changed, 56 insertions, 7 deletions
diff --git a/uts/common/fs/zfs/spa.c b/uts/common/fs/zfs/spa.c
index 599ae9faded9..e531587f3a6a 100644
--- a/uts/common/fs/zfs/spa.c
+++ b/uts/common/fs/zfs/spa.c
@@ -4578,12 +4578,18 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
uint_t nspares, nl2cache;
uint64_t version, obj;
boolean_t has_features;
+ char *poolname;
+ nvlist_t *nvl;
+
+ if (nvlist_lookup_string(props,
+ zpool_prop_to_name(ZPOOL_PROP_TNAME), &poolname) != 0)
+ poolname = (char *)pool;
/*
* If this pool already exists, return failure.
*/
mutex_enter(&spa_namespace_lock);
- if (spa_lookup(pool) != NULL) {
+ if (spa_lookup(poolname) != NULL) {
mutex_exit(&spa_namespace_lock);
return (SET_ERROR(EEXIST));
}
@@ -4591,9 +4597,12 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
/*
* Allocate a new spa_t structure.
*/
+ nvl = fnvlist_alloc();
+ fnvlist_add_string(nvl, ZPOOL_CONFIG_POOL_NAME, pool);
(void) nvlist_lookup_string(props,
zpool_prop_to_name(ZPOOL_PROP_ALTROOT), &altroot);
- spa = spa_add(pool, NULL, altroot);
+ spa = spa_add(poolname, nvl, altroot);
+ fnvlist_free(nvl);
spa_activate(spa, spa_mode_global);
if (props && (error = spa_prop_validate(spa, props))) {
@@ -4603,6 +4612,12 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
return (error);
}
+ /*
+ * Temporary pool names should never be written to disk.
+ */
+ if (poolname != pool)
+ spa->spa_import_flags |= ZFS_IMPORT_TEMP_NAME;
+
has_features = B_FALSE;
for (nvpair_t *elem = nvlist_next_nvpair(props, NULL);
elem != NULL; elem = nvlist_next_nvpair(props, elem)) {
diff --git a/uts/common/fs/zfs/spa_config.c b/uts/common/fs/zfs/spa_config.c
index 7d568ffcf8b2..ad61dd07230f 100644
--- a/uts/common/fs/zfs/spa_config.c
+++ b/uts/common/fs/zfs/spa_config.c
@@ -208,6 +208,7 @@ spa_write_cachefile(spa_t *target, boolean_t removing, boolean_t postsysevent)
nvlist_t *nvl;
boolean_t ccw_failure;
int error;
+ char *pool_name;
ASSERT(MUTEX_HELD(&spa_namespace_lock));
@@ -254,7 +255,14 @@ spa_write_cachefile(spa_t *target, boolean_t removing, boolean_t postsysevent)
if (nvl == NULL)
nvl = fnvlist_alloc();
- fnvlist_add_nvlist(nvl, spa->spa_name,
+ if (spa->spa_import_flags & ZFS_IMPORT_TEMP_NAME) {
+ pool_name = fnvlist_lookup_string(
+ spa->spa_config, ZPOOL_CONFIG_POOL_NAME);
+ } else {
+ pool_name = spa_name(spa);
+ }
+
+ fnvlist_add_nvlist(nvl, pool_name,
spa->spa_config);
mutex_exit(&spa->spa_props_lock);
}
@@ -359,6 +367,7 @@ spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, int getstats)
unsigned long hostid = 0;
boolean_t locked = B_FALSE;
uint64_t split_guid;
+ char *pool_name;
if (vd == NULL) {
vd = rvd;
@@ -375,10 +384,27 @@ spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, int getstats)
if (txg == -1ULL)
txg = spa->spa_config_txg;
+ /*
+ * Originally, users had to handle spa namespace collisions by either
+ * exporting the already imported pool or by specifying a new name for
+ * the pool with a conflicting name. In the case of root pools from
+ * virtual guests, neither approach to collision resolution is
+ * reasonable. This is addressed by extending the new name syntax with
+ * an option to specify that the new name is temporary. When specified,
+ * ZFS_IMPORT_TEMP_NAME will be set in spa->spa_import_flags to tell us
+ * to use the previous name, which we do below.
+ */
+ if (spa->spa_import_flags & ZFS_IMPORT_TEMP_NAME) {
+ pool_name = fnvlist_lookup_string(spa->spa_config,
+ ZPOOL_CONFIG_POOL_NAME);
+ } else {
+ pool_name = spa_name(spa);
+ }
+
config = fnvlist_alloc();
fnvlist_add_uint64(config, ZPOOL_CONFIG_VERSION, spa_version(spa));
- fnvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME, spa_name(spa));
+ fnvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME, pool_name);
fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_STATE, spa_state(spa));
fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_TXG, txg);
fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_GUID, spa_guid(spa));
diff --git a/uts/common/fs/zfs/zfs_ioctl.c b/uts/common/fs/zfs/zfs_ioctl.c
index 0abdbe9badc3..87435f18ac1a 100644
--- a/uts/common/fs/zfs/zfs_ioctl.c
+++ b/uts/common/fs/zfs/zfs_ioctl.c
@@ -1492,6 +1492,7 @@ zfs_ioc_pool_create(zfs_cmd_t *zc)
nvlist_t *config, *props = NULL;
nvlist_t *rootprops = NULL;
nvlist_t *zplprops = NULL;
+ char *spa_name = zc->zc_name;
if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
zc->zc_iflags, &config))
@@ -1507,6 +1508,7 @@ zfs_ioc_pool_create(zfs_cmd_t *zc)
if (props) {
nvlist_t *nvl = NULL;
uint64_t version = SPA_VERSION;
+ char *tname;
(void) nvlist_lookup_uint64(props,
zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
@@ -1529,6 +1531,10 @@ zfs_ioc_pool_create(zfs_cmd_t *zc)
zplprops, NULL);
if (error != 0)
goto pool_props_bad;
+
+ if (nvlist_lookup_string(props,
+ zpool_prop_to_name(ZPOOL_PROP_TNAME), &tname) == 0)
+ spa_name = tname;
}
error = spa_create(zc->zc_name, config, props, zplprops);
@@ -1536,9 +1542,9 @@ zfs_ioc_pool_create(zfs_cmd_t *zc)
/*
* Set the remaining root properties
*/
- if (!error && (error = zfs_set_prop_nvlist(zc->zc_name,
+ if (!error && (error = zfs_set_prop_nvlist(spa_name,
ZPROP_SRC_LOCAL, rootprops, NULL)) != 0)
- (void) spa_destroy(zc->zc_name);
+ (void) spa_destroy(spa_name);
pool_props_bad:
nvlist_free(rootprops);
diff --git a/uts/common/sys/fs/zfs.h b/uts/common/sys/fs/zfs.h
index f85062f66bfd..4c26edaecde6 100644
--- a/uts/common/sys/fs/zfs.h
+++ b/uts/common/sys/fs/zfs.h
@@ -210,6 +210,7 @@ typedef enum {
ZPOOL_PROP_MAXBLOCKSIZE,
ZPOOL_PROP_BOOTSIZE,
ZPOOL_PROP_CHECKPOINT,
+ ZPOOL_PROP_TNAME,
ZPOOL_NUM_PROPS
} zpool_prop_t;
@@ -855,7 +856,7 @@ typedef struct vdev_stat {
* is passed between kernel and userland as an nvlist uint64 array.
*/
typedef struct ddt_object {
- uint64_t ddo_count; /* number of elments in ddt */
+ uint64_t ddo_count; /* number of elments in ddt */
uint64_t ddo_dspace; /* size of ddt on disk */
uint64_t ddo_mspace; /* size of ddt in-core */
} ddt_object_t;
@@ -1061,6 +1062,7 @@ typedef enum {
#define ZFS_IMPORT_MISSING_LOG 0x4
#define ZFS_IMPORT_ONLY 0x8
#define ZFS_IMPORT_CHECKPOINT 0x10
+#define ZFS_IMPORT_TEMP_NAME 0x20
/*
* Channel program argument/return nvlist keys and defaults.