public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
From: Hou Tao <houtao1@huawei.com>
To: fstests@vger.kernel.org
Cc: guaneryu@gmail.com, linux-xfs@vger.kernel.org,
	darrick.wong@oracle.com, cmaiolino@redhat.com
Subject: [PATCH v2 2/4] common/rc: support checking the version of dm-target in _require_dm_target()
Date: Wed, 8 Nov 2017 16:02:48 +0800	[thread overview]
Message-ID: <20171108080250.5662-3-houtao1@huawei.com> (raw)
In-Reply-To: <20171108080250.5662-1-houtao1@huawei.com>

Some features of dm-target are not available on the old linux kernel,
and we can use the version of dm-target to check the availability.

Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 common/rc | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/common/rc b/common/rc
index e2a8229..9ea84ba 100644
--- a/common/rc
+++ b/common/rc
@@ -1779,10 +1779,12 @@ _require_sane_bdev_flush()
 	fi
 }
 
-# this test requires a specific device mapper target
+# this test requires a specific device mapper target and
+# an optional version number (e.g., 1.4.0)
 _require_dm_target()
 {
-	_target=$1
+	local target=$1
+	local version=$2
 
 	# require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
 	# behaviour
@@ -1790,11 +1792,38 @@ _require_dm_target()
 	_require_sane_bdev_flush $SCRATCH_DEV
 	_require_command "$DMSETUP_PROG" dmsetup
 
-	modprobe dm-$_target >/dev/null 2>&1
+	modprobe dm-$target >/dev/null 2>&1
 
-	$DMSETUP_PROG targets 2>&1 | grep -q ^$_target
+	$DMSETUP_PROG targets 2>&1 | grep -q ^$target
 	if [ $? -ne 0 ]; then
-		_notrun "This test requires dm $_target support"
+		_notrun "This test requires dm $target support"
+	fi
+
+	if [ -n "$version" ]; then
+		local got
+
+		got=$($DMSETUP_PROG targets 2>&1 | \
+				awk -v tgt=$target '$0 ~ tgt {sub("v", "", $2); print $2}')
+		if [ -z "$got" ]; then
+			_notrun "This test requires dm $target $version at least (got unknown)"
+		fi
+
+		awk -v min=$version -v got=$got '
+		BEGIN \
+		{
+			cmin = split(min, amin, ".");
+			cgot = split(got, agot, ".");
+			for (i = 1; i <= cgot && i <= cmin; i++) {
+				if (agot[i] != amin[i]) {
+					exit(agot[i] < amin[i]);
+				}
+			}
+			exit(cgot < cmin);
+		}
+		'
+		if [ $? -ne 0 ]; then
+			_notrun "This test requires dm $target $version at least (got $got)"
+		fi
 	fi
 }
 
-- 
2.9.5


  parent reply	other threads:[~2017-11-08  7:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-08  8:02 [PATCH v2 0/4] test for XFS umount hang caused by the pending dquota log item in AIL Hou Tao
2017-11-08  8:02 ` [PATCH v2 1/4] dmflakey: support multiple dm targets for a dm-flakey device Hou Tao
2017-11-08  8:02 ` Hou Tao [this message]
2017-11-08  9:49   ` [PATCH v2 2/4] common/rc: support checking the version of dm-target in _require_dm_target() Eryu Guan
2017-11-08 13:39     ` Hou Tao
2017-11-08  8:02 ` [PATCH v2 3/4] xfs: test for umount hang caused by the pending dquota log item in AIL Hou Tao
2017-11-08  9:56   ` Eryu Guan
2017-11-08 13:37     ` Hou Tao
2017-11-08  8:02 ` [PATCH v2 4/4] common/rc: factor out _get|set_xfs_scratch_sb_field() Hou Tao
2017-11-08 16:49   ` Darrick J. Wong
2017-11-09  3:53     ` Eryu Guan
2017-11-09  4:30       ` Hou Tao
2017-11-08  9:20 ` [PATCH v2 0/4] test for XFS umount hang caused by the pending dquota log item in AIL Eryu Guan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171108080250.5662-3-houtao1@huawei.com \
    --to=houtao1@huawei.com \
    --cc=cmaiolino@redhat.com \
    --cc=darrick.wong@oracle.com \
    --cc=fstests@vger.kernel.org \
    --cc=guaneryu@gmail.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox