From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

zfs: use spa_dev_path instead of defaulting to /dev/vblk0.1

The commit c9640a385c44704626a9169c03cff0752bfe764d addressing the issue
#918, tweaked the vdev disk mounting logic to default to import the root
pool from the device /dev/vblk0.1. This was really a hack that was
satisfactory to support mounting a ZFS image created or modified on host.

However, if we want to be able to import root pool and mount ZFS
filesystem from arbitrary device and partition like /dev/vblk0.2 or
/deb/vblk1.1, we have to pass the specific device path to all places
in ZFS code where it references it. There are 4 code paths that end up
calling vdev_alloc() but unfortunately changing all relevant functions
and its callers to pass the device path would be quite untenable.

So instead, this patch adds new field spa_dev_path to the spa structure
that holds the information about the Storage Pool Allocator in memory.
This new field is set to point to the device we want to import the ZFS
root pool from in spa_import_rootpool() function called by ZFS mount
disk process and then used by vdev_alloc() downstream.

Refs #1200

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
Message-Id: <20220717042947.95504-1-jwkozac...@gmail.com>

---
diff --git a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c 
b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c
--- a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c
+++ b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c
@@ -4206,6 +4206,7 @@ spa_import_rootpool(const char *name)
        }
        spa->spa_is_root = B_TRUE;
        spa->spa_import_flags = ZFS_IMPORT_VERBATIM;
+       spa->spa_dev_path = name;
 
        /*
         * Build up a vdev tree based on the boot device's label config.
diff --git a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c 
b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c
--- a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c
+++ b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c
@@ -464,6 +464,7 @@ spa_add(const char *name, nvlist_t *config, const char 
*altroot)
        spa->spa_load_max_txg = UINT64_MAX;
        spa->spa_proc = &p0;
        spa->spa_proc_state = SPA_PROC_NONE;
+       spa->spa_dev_path = NULL;
 
        refcount_create(&spa->spa_refcount);
        spa_config_lock_init(spa);
diff --git a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa_impl.h 
b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa_impl.h
--- a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa_impl.h
+++ b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa_impl.h
@@ -243,6 +243,7 @@ struct spa {
 #ifndef sun
        boolean_t       spa_splitting_newspa;   /* creating new spa in split */
 #endif
+       const char      *spa_dev_path;          /* device spa is mounted */
 };
 
 extern const char *spa_config_path;
diff --git a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev.c 
b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev.c
--- a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev.c
+++ b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev.c
@@ -442,8 +442,12 @@ vdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *nv, vdev_t 
*parent, uint_t id,
        vd->vdev_islog = islog;
        vd->vdev_nparity = nparity;
 
-       if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &vd->vdev_path) == 0)
-               vd->vdev_path = spa_strdup(vd->vdev_path);
+       if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &vd->vdev_path) == 0) {
+               if (spa->spa_dev_path)
+                       vd->vdev_path = strdup(spa->spa_dev_path);
+               else
+                       vd->vdev_path = spa_strdup(vd->vdev_path);
+       }
        if (nvlist_lookup_string(nv, ZPOOL_CONFIG_DEVID, &vd->vdev_devid) == 0)
                vd->vdev_devid = spa_strdup(vd->vdev_devid);
        if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PHYS_PATH,
diff --git a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_disk.c 
b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_disk.c
--- a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_disk.c
+++ b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_disk.c
@@ -74,9 +74,6 @@ vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t 
*max_psize,
                dvd = vd->vdev_tsd = kmem_zalloc(sizeof(struct vdev_disk), 
KM_SLEEP);
 
                device_name = vd->vdev_path + 5;
-               if (strncmp(device_name, "vblk", 4) != 0) {
-                       device_name = "vblk0.1";
-               }
                error = device_open(device_name, DO_RDWR, &dvd->device);
                if (error) {
                        vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/0000000000001174df05e3fb3d0a%40google.com.

Reply via email to