From patchwork Thu Mar 1 12:13:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 10251119 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 7853360211 for ; Thu, 1 Mar 2018 12:04:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6793529031 for ; Thu, 1 Mar 2018 12:04:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A34429033; Thu, 1 Mar 2018 12:04:47 +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=ham 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 17C1528FC1 for ; Thu, 1 Mar 2018 12:04:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030256AbeCAMEp (ORCPT ); Thu, 1 Mar 2018 07:04:45 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:5693 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1030251AbeCAMEo (ORCPT ); Thu, 1 Mar 2018 07:04:44 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 032AA92103E01; Thu, 1 Mar 2018 20:04:30 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.361.1; Thu, 1 Mar 2018 20:04:24 +0800 From: "zhangyi (F)" To: , CC: , , , , , Subject: [xfstests PATCH v5 1/5] common/rc: improve dev mounted check helper Date: Thu, 1 Mar 2018 20:13:43 +0800 Message-ID: <20180301121347.5824-2-yi.zhang@huawei.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180301121347.5824-1-yi.zhang@huawei.com> References: <20180301121347.5824-1-yi.zhang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is a problem of missing fstype check in _is_mounted() helper, it will return the mountpoint if only the device arguments matches. For example: Base mounted filesystem: /dev/sda2 on /boot type ext4 (rw,relatime,data=ordered) FSTYPE=xfs mountpoint=`_is_mounted /dev/sda1` echo "$mountpoint" Output: /boot This patch rename _is_mounted to _is_dev_mounted because it check the given device only (not mount dir), and add an optional "fstype" parameter, let user specify file system type instead of default FSTYPE. Finally, use findmnt instead of mount to avoid complex processing of mount info and fix this problem simply. Signed-off-by: zhangyi (F) --- common/rc | 29 ++++++++++------------------- common/xfs | 2 +- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/common/rc b/common/rc index a68e6cc..1dae3bf 100644 --- a/common/rc +++ b/common/rc @@ -2381,27 +2381,18 @@ _scratch_mkfs_richacl() esac } -# check that a FS on a device is mounted -# if so, return mount point -# -_is_mounted() +# check if the given device is mounted, if so, return mount point +_is_dev_mounted() { - if [ $# -ne 1 ] - then - echo "Usage: _is_mounted device" 1>&2 - exit 1 - fi + local dev=$1 + local fstype=${2:-$FSTYP} - device=$1 + if [ $# -lt 1 ]; then + echo "Usage: _is_dev_mounted [fstype]" 1>&2 + exit 1 + fi - if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" ' - pattern { print $3 ; exit 0 } - END { exit 1 } - ' - then - echo "_is_mounted: $device is not a mounted $FSTYP FS" - exit 1 - fi + findmnt -rncv -S $dev -t $fstype -o TARGET | head -1 } # remount a FS to a new mode (ro or rw) @@ -2441,7 +2432,7 @@ _umount_or_remount_ro() fi device=$1 - mountpoint=`_is_mounted $device` + mountpoint=`_is_dev_mounted $device` if [ $USE_REMOUNT -eq 0 ]; then $UMOUNT_PROG $device diff --git a/common/xfs b/common/xfs index 354f584..37cd80c 100644 --- a/common/xfs +++ b/common/xfs @@ -356,7 +356,7 @@ _check_xfs_filesystem() ok=1 # Run online scrub if we can. - mntpt="$(_is_mounted $device)" + mntpt="$(_is_dev_mounted $device)" if [ -n "$mntpt" ] && _supports_xfs_scrub "$mntpt" "$device"; then "$XFS_SCRUB_PROG" $scrubflag -v -d -n $device > $tmp.scrub 2>&1 if [ $? -ne 0 ]; then