[PATCH V2] generic _require_dm_target() helper, use in generic/085

Eric Sandeen
2015-09-28T22:26:21Z

The first 2 files below are functional changes, creating the helper
& using it in generic/085; the rest are just perl edit-in-place
changes to use the new generic helper.

Reported-by: Angelo Dureghello <angelo.dureghello@nomovok.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2: assign _target using actual bash syntax! o_O
combine dmsetup stdout & stderr for target grep
modprobe the target we're looking for
define cleanup_dmdev() before we _notrun, trap, and try to run it

diff --git a/common/rc b/common/rc
index 3e97060..5110261 100644
--- a/common/rc
+++ b/common/rc
@@ -1346,32 +1346,22 @@ _require_sane_bdev_flush()
fi
}

-# this test requires the device mapper flakey target
-#
-_require_dm_flakey()
+# this test requires a specific device mapper target
+_require_dm_target()
{
+ _target=$1
+
# require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
# behaviour
_require_block_device $SCRATCH_DEV
_require_sane_bdev_flush $SCRATCH_DEV
_require_command "$DMSETUP_PROG" dmsetup

- modprobe dm-flakey >/dev/null 2>&1
- $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
- if [ $? -ne 0 ]; then
- _notrun "This test requires dm flakey support"
- fi
-}
-
-_require_dm_snapshot()
-{
- _require_block_device $SCRATCH_DEV
- _require_sane_bdev_flush $SCRATCH_DEV
- _require_command "$DMSETUP_PROG" dmsetup
- modprobe dm-snapshot >/dev/null 2>&1
- $DMSETUP_PROG targets | grep -q snapshot
+ modprobe dm-$_target >/dev/null 2>&1
+
+ $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
if [ $? -ne 0 ]; then
- _notrun "This test requires dm snapshot support"
+ _notrun "This test requires dm $_target support"
fi
}

diff --git a/tests/generic/085 b/tests/generic/085
index 8398752..8fb313c 100755
--- a/tests/generic/085
+++ b/tests/generic/085
@@ -41,6 +41,16 @@ _cleanup()
cleanup_dmdev
}

+cleanup_dmdev()
+{
+ # in case it's still suspended and/or mounted
+ $DMSETUP_PROG resume $lvdev >/dev/null 2>&1
+ $UMOUNT_PROG $lvdev >/dev/null 2>&1
+
+ $DMSETUP_PROG remove $node >>$seqres.full 2>&1
+ $DMSETUP_PROG mknodes >/dev/null 2>&1
+}
+
# get standard environment, filters and checks
. ./common/rc
. ./common/filter
@@ -50,7 +60,7 @@ _supported_fs generic
_supported_os Linux
_require_scratch
_require_block_device $SCRATCH_DEV
-_require_command $DMSETUP_PROG
+_require_dm_target linear
_require_freeze

setup_dmdev()
@@ -61,16 +71,6 @@ setup_dmdev()
return $?
}

-cleanup_dmdev()
-{
- # in case it's still suspended and/or mounted
- $DMSETUP_PROG resume $lvdev >/dev/null 2>&1
- $UMOUNT_PROG $lvdev >/dev/null 2>&1
-
- $DMSETUP_PROG remove $node >>$seqres.full 2>&1