summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorloli10K <[email protected]>2020-01-07 00:40:06 +0100
committerBrian Behlendorf <[email protected]>2020-01-06 15:40:06 -0800
commitc24fa4b19a1b117945f3235e014f926fe93b0c5a (patch)
tree37178dc7c410829ef81f1f2c61c7df44d6d41710 /tests
parentbc9cef11fddfe8e6e240477084a49f4bad1fb4f3 (diff)
Fix "zpool add -n" for dedup, special and log devices
For dedup, special and log devices "zpool add -n" does not print correctly their vdev type: ~# zpool add -n pool dedup /tmp/dedup special /tmp/special log /tmp/log would update 'pool' to the following configuration: pool /tmp/normal /tmp/dedup /tmp/special /tmp/log This could lead storage administrators to modify their ZFS pools to unexpected and unintended vdev configurations. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: loli10K <[email protected]> Closes #9783 Closes #9390
Diffstat (limited to 'tests')
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos.ksh69
1 files changed, 44 insertions, 25 deletions
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos.ksh
index cfdc29d95..f27004130 100755
--- a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos.ksh
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos.ksh
@@ -34,26 +34,23 @@
#
# DESCRIPTION:
-# 'zpool add -n <pool> <vdev> ...' can display the configuration without
-# adding the specified devices to given pool
+# 'zpool add -n <pool> <vdev> ...' can display the configuration without adding
+# the specified devices to given pool
#
# STRATEGY:
-# 1. Create a storage pool
-# 2. Use -n to add a device to the pool
-# 3. Verify the device is not added actually
+# 1. Create a storage pool
+# 2. Use -n to add devices to the pool
+# 3. Verify the devices are not added actually
+# 4. Add devices to the pool for real this time, verify the vdev tree is the
+# same printed by the dryrun iteration
#
verify_runnable "global"
function cleanup
{
- poolexists $TESTPOOL && \
- destroy_pool $TESTPOOL
-
- partition_cleanup
-
- [[ -e $tmpfile ]] && \
- log_must rm -f $tmpfile
+ destroy_pool $TESTPOOL
+ rm -f $TMPFILE_PREFIX* $VDEV_PREFIX*
}
log_assert "'zpool add -n <pool> <vdev> ...' can display the configuration" \
@@ -61,18 +58,40 @@ log_assert "'zpool add -n <pool> <vdev> ...' can display the configuration" \
log_onexit cleanup
-tmpfile="$TEST_BASE_DIR/zpool_add_003.tmp$$"
-
-create_pool "$TESTPOOL" "${disk}${SLICE_PREFIX}${SLICE0}"
-log_must poolexists "$TESTPOOL"
+typeset TMPFILE_PREFIX="$TEST_BASE_DIR/zpool_add_003"
+typeset STR_DRYRUN="would update '$TESTPOOL' to the following configuration:"
+typeset VDEV_PREFIX="$TEST_BASE_DIR/filedev"
+typeset -a VDEV_TYPES=("" "dedup" "special" "log" "cache")
-zpool add -n "$TESTPOOL" ${disk}${SLICE_PREFIX}${SLICE1} > $tmpfile
+vdevs=""
+config=""
-log_mustnot vdevs_in_pool "$TESTPOOL" "${disk}${SLICE_PREFIX}${SLICE1}"
-
-str="would update '$TESTPOOL' to the following configuration:"
-cat $tmpfile | grep "$str" >/dev/null 2>&1
-(( $? != 0 )) && \
- log_fail "'zpool add -n <pool> <vdev> ...' is executed as unexpected"
-
-log_pass "'zpool add -n <pool> <vdev> ...'executes successfully."
+# 1. Create a storage pool
+log_must truncate -s $SPA_MINDEVSIZE "$VDEV_PREFIX-root"
+log_must zpool create "$TESTPOOL" "$VDEV_PREFIX-root"
+log_must poolexists "$TESTPOOL"
+for vdevtype in "${VDEV_TYPES[@]}"; do
+ log_must truncate -s $SPA_MINDEVSIZE "$VDEV_PREFIX-$vdevtype"
+ vdevs="$vdevs $VDEV_PREFIX-$vdevtype"
+ config="$config $vdevtype $VDEV_PREFIX-$vdevtype"
+done
+
+# 2. Use -n to add devices to the pool
+log_must eval "zpool add -f -n $TESTPOOL $config > $TMPFILE_PREFIX-dryrun"
+log_must grep -q "$STR_DRYRUN" "$TMPFILE_PREFIX-dryrun"
+
+# 3. Verify the devices are not added actually
+for vdev in $vdevs; do
+ log_mustnot vdevs_in_pool "$TESTPOOL" "$vdev"
+done
+
+# 4. Add devices to the pool for real this time, verify the vdev tree is the
+# same printed by the dryrun iteration
+log_must zpool add -f $TESTPOOL $config
+zpool status $TESTPOOL | awk 'NR == 1, /NAME/ { next } /^$/ {exit}
+ {print $1}' > "$TMPFILE_PREFIX-vdevtree"
+cat "$TMPFILE_PREFIX-dryrun" | awk 'NR == 1, /would/ {next}
+ {print $1}' > "$TMPFILE_PREFIX-vdevtree-n"
+log_must eval "diff $TMPFILE_PREFIX-vdevtree-n $TMPFILE_PREFIX-vdevtree"
+
+log_pass "'zpool add -n <pool> <vdev> ...' executes successfully."