Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Dec 2018 10:41:17 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org
Subject:   svn commit: r342532 - vendor-sys/illumos/dist/common/zfs vendor-sys/illumos/dist/uts/common/fs/zfs vendor-sys/illumos/dist/uts/common/sys/fs vendor/illumos/dist/cmd/zpool vendor/illumos/dist/lib/li...
Message-ID:  <201812261041.wBQAfHcG036526@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Wed Dec 26 10:41:17 2018
New Revision: 342532
URL: https://svnweb.freebsd.org/changeset/base/342532

Log:
  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>

Modified:
  vendor-sys/illumos/dist/common/zfs/zpool_prop.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/spa.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/spa_config.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_ioctl.c
  vendor-sys/illumos/dist/uts/common/sys/fs/zfs.h

Changes in other areas also in this revision:
Modified:
  vendor/illumos/dist/cmd/zpool/zpool_main.c
  vendor/illumos/dist/lib/libzfs/common/libzfs_pool.c
  vendor/illumos/dist/man/man1m/zpool.1m

Modified: vendor-sys/illumos/dist/common/zfs/zpool_prop.c
==============================================================================
--- vendor-sys/illumos/dist/common/zfs/zpool_prop.c	Wed Dec 26 10:41:14 2018	(r342531)
+++ vendor-sys/illumos/dist/common/zfs/zpool_prop.c	Wed Dec 26 10:41:17 2018	(r342532)
@@ -136,6 +136,8 @@ zpool_prop_init(void)
 	    PROP_READONLY, ZFS_TYPE_POOL, "NAME");
 	zprop_register_hidden(ZPOOL_PROP_MAXBLOCKSIZE, "maxblocksize",
 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_POOL, "MAXBLOCKSIZE");
+	zprop_register_hidden(ZPOOL_PROP_TNAME, "tname", PROP_TYPE_STRING,
+	    PROP_ONETIME, ZFS_TYPE_POOL, "TNAME");
 }
 
 /*

Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/spa.c
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/spa.c	Wed Dec 26 10:41:14 2018	(r342531)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/spa.c	Wed Dec 26 10:41:17 2018	(r342532)
@@ -4578,12 +4578,18 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_
 	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_
 	/*
 	 * 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))) {
@@ -4602,6 +4611,12 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_
 		mutex_exit(&spa_namespace_lock);
 		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);

Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/spa_config.c
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/spa_config.c	Wed Dec 26 10:41:14 2018	(r342531)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/spa_config.c	Wed Dec 26 10:41:17 2018	(r342532)
@@ -208,6 +208,7 @@ spa_write_cachefile(spa_t *target, boolean_t removing,
 	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,
 			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 t
 	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 t
 	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));

Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_ioctl.c
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_ioctl.c	Wed Dec 26 10:41:14 2018	(r342531)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_ioctl.c	Wed Dec 26 10:41:17 2018	(r342532)
@@ -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);

Modified: vendor-sys/illumos/dist/uts/common/sys/fs/zfs.h
==============================================================================
--- vendor-sys/illumos/dist/uts/common/sys/fs/zfs.h	Wed Dec 26 10:41:14 2018	(r342531)
+++ vendor-sys/illumos/dist/uts/common/sys/fs/zfs.h	Wed Dec 26 10:41:17 2018	(r342532)
@@ -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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201812261041.wBQAfHcG036526>