aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLOLi <[email protected]>2017-07-31 20:07:05 +0200
committerBrian Behlendorf <[email protected]>2017-07-31 11:07:05 -0700
commitc7a7601c08d3f7db42dfca46e0ad8aa287df43da (patch)
tree90c1469b35fc69dab920a2caa7a578af7bd5e346
parent1e0565d10a5f75bd15104df3db3264554e8b2dd1 (diff)
Fix volmode=none property behavior at import time
At import time spa_import() calls zvol_create_minors() directly: with the current implementation we have no way to avoid device node creation when volmode=none. Fix this by enforcing volmode=none directly in zvol_alloc(). Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: loli10K <[email protected]> Closes #6426
-rw-r--r--module/zfs/zvol.c3
-rw-r--r--tests/zfs-tests/include/libtest.shlib2
-rwxr-xr-xtests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_volmode.ksh14
3 files changed, 16 insertions, 3 deletions
diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c
index 623fb9b22..254760220 100644
--- a/module/zfs/zvol.c
+++ b/module/zfs/zvol.c
@@ -1603,6 +1603,9 @@ zvol_alloc(dev_t dev, const char *name)
if (volmode == ZFS_VOLMODE_DEFAULT)
volmode = zvol_volmode;
+ if (volmode == ZFS_VOLMODE_NONE)
+ return (NULL);
+
zv = kmem_zalloc(sizeof (zvol_state_t), KM_SLEEP);
list_link_init(&zv->zv_next);
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib
index b6ac41dfa..4395d2868 100644
--- a/tests/zfs-tests/include/libtest.shlib
+++ b/tests/zfs-tests/include/libtest.shlib
@@ -3460,7 +3460,7 @@ function swap_setup
typeset swapdev=$1
if is_linux; then
- log_must mkswap $swapdev > /dev/null 2>&1
+ log_must eval "mkswap $swapdev > /dev/null 2>&1"
log_must swapon $swapdev
else
log_must swap -a $swapdev
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_volmode.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_volmode.ksh
index 5cf6a60b3..934d8942f 100755
--- a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_volmode.ksh
+++ b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_volmode.ksh
@@ -40,7 +40,8 @@
# 4. Verify "volmode=dev" hides partition info on the device
# 5. Verify "volmode=default" behaves accordingly to "volmode" module parameter
# 6. Verify "volmode" property is inherited correctly
-# 7. Verify "volmode" behaves accordingly to zvol_inhibit_dev (Linux only)
+# 7. Verify "volmode" behaves correctly at import time
+# 8. Verify "volmode" behaves accordingly to zvol_inhibit_dev (Linux only)
#
# NOTE: changing volmode may need to remove minors, which could be open, so call
# udev_wait() before we "zfs set volmode=<value>".
@@ -54,6 +55,7 @@ function cleanup
log_must zfs inherit volmode $TESTPOOL
udev_wait
sysctl_inhibit_dev 0
+ sysctl_volmode 1
udev_cleanup
}
@@ -194,10 +196,18 @@ log_must zfs set volmode=full $TESTPOOL
verify_inherited 'volmode' 'none' $SUBZVOL $VOLFS
blockdev_missing $SUBZDEV
blockdev_exists $ZDEV
+
+# 7. Verify "volmode" behaves correctly at import time
+log_must zpool export $TESTPOOL
+blockdev_missing $ZDEV
+blockdev_missing $SUBZDEV
+log_must zpool import $TESTPOOL
+blockdev_exists $ZDEV
+blockdev_missing $SUBZDEV
log_must_busy zfs destroy $ZVOL
log_must_busy zfs destroy $SUBZVOL
-# 7. Verify "volmode" behaves accordingly to zvol_inhibit_dev (Linux only)
+# 8. Verify "volmode" behaves accordingly to zvol_inhibit_dev (Linux only)
if is_linux; then
sysctl_inhibit_dev 1
# 7.1 Verify device nodes not are not created with "volmode=full"