From patchwork Wed Nov 8 08:02:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 10047915 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C9D76603FF for ; Wed, 8 Nov 2017 07:57:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC03F2A503 for ; Wed, 8 Nov 2017 07:57:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B10EC2A502; Wed, 8 Nov 2017 07:57:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56A242A4FB for ; Wed, 8 Nov 2017 07:57:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750955AbdKHH5M (ORCPT ); Wed, 8 Nov 2017 02:57:12 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:53840 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751040AbdKHH5I (ORCPT ); Wed, 8 Nov 2017 02:57:08 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 60EF511ECBE69; Wed, 8 Nov 2017 15:56:55 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.361.1; Wed, 8 Nov 2017 15:56:13 +0800 From: Hou Tao To: CC: , , , 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 Message-ID: <20171108080250.5662-3-houtao1@huawei.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171108080250.5662-1-houtao1@huawei.com> References: <20171108080250.5662-1-houtao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 }