From: "zhangyi (F)" <yi.zhang@huawei.com>
To: eguan@redhat.com, fstests@vger.kernel.org
Cc: linux-unionfs@vger.kernel.org, miklos@szeredi.hu,
amir73il@gmail.com, yi.zhang@huawei.com, miaoxie@huawei.com,
yangerkun@huawei.com
Subject: [xfstests PATCH v3 1/6] common/rc: improve dev mounted check helper
Date: Tue, 13 Feb 2018 15:08:27 +0800 [thread overview]
Message-ID: <20180213070832.43159-2-yi.zhang@huawei.com> (raw)
In-Reply-To: <20180213070832.43159-1-yi.zhang@huawei.com>
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) <yi.zhang@huawei.com>
---
common/rc | 29 ++++++++++-------------------
common/xfs | 2 +-
2 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/common/rc b/common/rc
index 4ad59b1..2fae2be 100644
--- a/common/rc
+++ b/common/rc
@@ -2372,27 +2372,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 <device> [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)
@@ -2432,7 +2423,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 9b20b03..572b084 100644
--- a/common/xfs
+++ b/common/xfs
@@ -355,7 +355,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
--
2.5.0
next prev parent reply other threads:[~2018-02-13 6:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-13 7:08 [xfstests PATCH v3 0/6] overlay: add overlay filesystem dirs check zhangyi (F)
2018-02-13 7:08 ` zhangyi (F) [this message]
2018-02-13 7:08 ` [xfstests PATCH v3 2/6] overlay: hook filesystem check helper zhangyi (F)
2018-02-13 7:08 ` [xfstests PATCH v3 3/6] overlay/003: fix fs check failure zhangyi (F)
2018-02-13 7:08 ` [xfstests PATCH v3 4/6] overlay: skip check for tests finished with corrupt filesystem zhangyi (F)
2018-02-13 7:08 ` [xfstests PATCH v3 5/6] overlay: correct scratch dirs check zhangyi (F)
2018-02-13 8:58 ` Amir Goldstein
2018-02-13 7:08 ` [xfstests PATCH v3 6/6] overlay: correct test mount options zhangyi (F)
2018-02-13 9:26 ` Amir Goldstein
2018-02-13 9:48 ` Eryu Guan
2018-02-13 9:54 ` Amir Goldstein
2018-02-15 8:39 ` [xfstests PATCH v3 0/6] overlay: add overlay filesystem dirs check 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=20180213070832.43159-2-yi.zhang@huawei.com \
--to=yi.zhang@huawei.com \
--cc=amir73il@gmail.com \
--cc=eguan@redhat.com \
--cc=fstests@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miaoxie@huawei.com \
--cc=miklos@szeredi.hu \
--cc=yangerkun@huawei.com \
/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