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

Eric Sandeen
2015-09-29T14:00:35Z

Add the helper, use it in test generic/085, and convert
_require_dm_flakey, _require_dm_snapshot, and
_dmerror_required with this new 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

V3: Fix whitespace
replace _dmerror_required in btrfs tests with _require_dm_target error

diff --git a/common/dmerror b/common/dmerror
index a81856d..3900a4e 100644
--- a/common/dmerror
+++ b/common/dmerror
@@ -18,20 +18,6 @@
#
# common functions for setting up and tearing down a dmerror device

-# this test requires the device mapper error target
-#
-_dmerror_required()
-{
- _require_command "$DMSETUP_PROG" dmsetup
-
- _require_block_device $SCRATCH_DEV
- _require_sane_bdev_flush $SCRATCH_DEV
-
- modprobe dm-mod >/dev/null 2>&1
- $DMSETUP_PROG targets | grep error >/dev/null 2>&1
- [ $? -ne 0 ] && _notrun "This test requires dm error support"
-}
-
_dmerror_init()
{
local dm_backing_dev=$SCRATCH_DEV
diff --git a/common/rc b/common/rc
index 3e97060..adf1edf 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
-}
+ modprobe dm-$_target >/dev/null 2>&1

-_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
+ $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/btrfs/049 b/tests/btrfs/049
index 5b17a77..38ed7ad 100755
--- a/tests/btrfs/049
+++ b/tests/btrfs/049
@@ -50,7 +50,7 @@ _supported_fs btrfs
_supported_os Linux
_need_to_be_root
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey

rm -f $seqres.full

diff --git a/tests/btrfs/056 b/tests/btrfs/056
index 9e9d92b..add8288 100755
--- a/tests/btrfs/056
+++ b/tests/btrfs/056
@@ -55,7 +55,7 @@ _require_scratch
_require_cloner
_require_btrfs_fs_feature "no_holes"
_require_btrfs_mkfs_feature "no-holes"
-_require_dm_flakey
+_require_dm_target flakey
_need_to_be_root

rm -f $seqres.full
diff --git a/tests/btrfs/085 b/tests/btrfs/085
index 44e476b..d82f79a 100755
--- a/tests/btrfs/085
+++ b/tests/btrfs/085
@@ -54,7 +54,7 @@ trap "_cleanup ; exit \$status" 0 1 2 3 15
_supported_fs btrfs
_supported_os Linux
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_need_to_be_root

BTRFS_DEBUG_TREE_PROG="`set_prog_path btrfs-debug-tree`"
diff --git a/tests/btrfs/095 b/tests/btrfs/095
index 032d1ff..854ba40 100755
--- a/tests/btrfs/095
+++ b/tests/btrfs/095
@@ -52,7 +52,7 @@ _need_to_be_root
_supported_fs btrfs
_supported_os Linux
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_cloner
_require_metadata_journaling $SCRATCH_DEV
_require_xfs_io_command "falloc"
diff --git a/tests/btrfs/098 b/tests/btrfs/098
index c412c73..f12df5f 100755
--- a/tests/btrfs/098
+++ b/tests/btrfs/098
@@ -48,7 +48,7 @@ _need_to_be_root
_supported_fs btrfs
_supported_os Linux
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_cloner
_require_metadata_journaling $SCRATCH_DEV

diff --git a/tests/btrfs/100 b/tests/btrfs/100
index 4343fcb..080d0ae 100755
--- a/tests/btrfs/100
+++ b/tests/btrfs/100
@@ -46,7 +46,7 @@ _supported_fs btrfs
_supported_os Linux
_need_to_be_root
_require_scratch_dev_pool 3
-_dmerror_required
+_require_dm_target error

rm -f $seqres.full

diff --git a/tests/btrfs/101 b/tests/btrfs/101
index 5969ab6..0824de1 100755
--- a/tests/btrfs/101
+++ b/tests/btrfs/101
@@ -47,7 +47,7 @@ _supported_os Linux
_need_to_be_root
_require_scratch_dev_pool 3
_require_btrfs_dev_del_by_devid
-_dmerror_required
+_require_dm_target error

rm -f $seqres.full

diff --git a/tests/generic/034 b/tests/generic/034
index 966b3d2..ee889c2 100755
--- a/tests/generic/034
+++ b/tests/generic/034
@@ -52,7 +52,7 @@ _supported_fs generic
_supported_os Linux
_need_to_be_root
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_metadata_journaling $SCRATCH_DEV

rm -f $seqres.full
diff --git a/tests/generic/039 b/tests/generic/039
index 4bbfc50..35cb7a4 100755
--- a/tests/generic/039
+++ b/tests/generic/039
@@ -56,7 +56,7 @@ _supported_fs generic
_supported_os Linux
_need_to_be_root
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_metadata_journaling $SCRATCH_DEV

rm -f $seqres.full
diff --git a/tests/generic/040 b/tests/generic/040
index b44a433..3142bbb 100755
--- a/tests/generic/040
+++ b/tests/generic/040
@@ -61,7 +61,7 @@ _supported_fs generic
_supported_os Linux
_need_to_be_root
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_metadata_journaling $SCRATCH_DEV

rm -f $seqres.full
diff --git a/tests/generic/041 b/tests/generic/041
index 50fb26f..506d8a9 100755
--- a/tests/generic/041
+++ b/tests/generic/041
@@ -65,7 +65,7 @@ _supported_fs generic
_supported_os Linux
_need_to_be_root
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_metadata_journaling $SCRATCH_DEV

rm -f $seqres.full
diff --git a/tests/generic/056 b/tests/generic/056
index 8bb1522..2ec155f 100755
--- a/tests/generic/056
+++ b/tests/generic/056
@@ -54,7 +54,7 @@ _supported_fs generic
_supported_os Linux
_need_to_be_root
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_metadata_journaling $SCRATCH_DEV

rm -f $seqres.full
diff --git a/tests/generic/057 b/tests/generic/057
index 3b9f89e..c11c329 100755
--- a/tests/generic/057
+++ b/tests/generic/057
@@ -54,7 +54,7 @@ _supported_fs generic
_supported_os Linux
_need_to_be_root
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_metadata_journaling $SCRATCH_DEV

rm -f $seqres.full
diff --git a/tests/generic/059 b/tests/generic/059
index 13dfb09..4b9184a 100755
--- a/tests/generic/059
+++ b/tests/generic/059
@@ -59,7 +59,7 @@ _supported_fs generic
_supported_os Linux
_need_to_be_root
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_metadata_journaling $SCRATCH_DEV
_require_xfs_io_command "fpunch"

diff --git a/tests/generic/065 b/tests/generic/065
index 739a4d5..ddab687 100755
--- a/tests/generic/065
+++ b/tests/generic/065
@@ -55,7 +55,7 @@ _supported_fs generic
_supported_os Linux
_need_to_be_root
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_metadata_journaling $SCRATCH_DEV

rm -f $seqres.full
diff --git a/tests/generic/066 b/tests/generic/066
index cb36506..211152d 100755
--- a/tests/generic/066
+++ b/tests/generic/066
@@ -59,7 +59,7 @@ _supported_fs generic
_supported_os Linux
_need_to_be_root
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_attrs
_require_metadata_journaling $SCRATCH_DEV

diff --git a/tests/generic/073 b/tests/generic/073
index 9cf0d90..759098d 100755
--- a/tests/generic/073
+++ b/tests/generic/073
@@ -55,7 +55,7 @@ _supported_fs generic
_supported_os Linux
_need_to_be_root
_require_scratch
-_require_dm_flakey
+_require_dm_target flakey
_require_metadata_journaling $SCRATCH_DEV

rm -f $seqres.full
diff --git a/tests/generic/081 b/tests/generic/081
index 34da1ac..8334ec9 100755
--- a/tests/generic/081
+++ b/tests/generic/081
@@ -49,7 +49,7 @@ _supported_fs generic
_supported_os Linux
_require_test
_require_scratch_nocheck
-_require_dm_snapshot
+_require_dm_target snapshot
_require_command $LVM_PROG lvm

echo "Silence is golden"
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