From: Amir Goldstein <amir73il@gmail.com>
To: Eryu Guan <eguan@redhat.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>, Xiong Zhou <xzhou@redhat.com>,
linux-unionfs@vger.kernel.org, fstests@vger.kernel.org
Subject: [PATCH v5 01/10] fstests: sanity check that test partitions are not mounted elsewhere
Date: Tue, 28 Feb 2017 14:18:28 +0200 [thread overview]
Message-ID: <1488284317-3119-2-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1488284317-3119-1-git-send-email-amir73il@gmail.com>
When $TEST_DEV is mounted at a different location then $TEST_DIR,
_require_test() aborts the test with an error:
TEST_DEV=/dev/sda5 is mounted but not on TEST_DIR=/mnt/test
There are several problems with current sanity check:
1. the output of the error is mixed into out.bad and hard to see
2. the test partition is unmounted at the end of the test regardless
of the fact that it not pass the sanity that we have exclusivity
3. scratch partition has a similar sanity check in _require_scratch(),
but we may not get to it, because $SCRATCH_DEV is unmounted prior
to running the tests (which could unmount another mount point).
To solve all these problems, introduce a helper _check_mounted_on().
It checks if a device is mounted on a given mount point and optionally
checks the mounted fs type.
The sanity checks in _require_scratch() and _require_test() are
converted to use the helper and gain the check for correct fs type.
The helper is used in init_rc() to sanity check both test and scratch
partitions, before tests are run and before $SCRATCH_DEV is unmounted.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
common/rc | 90 +++++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 56 insertions(+), 34 deletions(-)
diff --git a/common/rc b/common/rc
index 8f23334..dab3cb2 100644
--- a/common/rc
+++ b/common/rc
@@ -1354,6 +1354,43 @@ _supported_os()
_notrun "not suitable for this OS: $HOSTOS"
}
+# check if a FS on a device is mounted
+# if so, verify that it is mounted on mount point
+# if fstype is given as argument, verify that it is also
+# mounted with correct fs type
+#
+_check_mounted_on()
+{
+ local devname=$1
+ local dev=$2
+ local mntname=$3
+ local mnt=$4
+ local type=$5
+
+ # Note that we use -F here so grep doesn't try to interpret an NFS over
+ # IPv6 server as a regular expression
+ local mount_rec=`_mount | grep -F "$dev"`
+ [ -n "$mount_rec" ] || return 1 # 1 = not mounted
+
+ # if it's mounted, make sure its on $mnt
+ if ! (echo $mount_rec | grep -q "$mnt")
+ then
+ echo "$devname=$dev is mounted but not on $mntname=$mnt - aborting"
+ echo "Already mounted result:"
+ echo $mount_rec
+ return 2 # 2 = mounted on wrong mnt
+ fi
+
+ if [ -n "$type" -a "`_fs_type $dev`" != "$type" ]
+ then
+ echo "$devname=$dev is mounted but not a type $type filesystem"
+ # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
+ _df_device $dev
+ return 3 # 3 = mounted as wrong type
+ fi
+ return 0 # 0 = mounted as expected
+}
+
# this test needs a scratch partition - check we're ok & unmount it
# No post-test check of the device is required. e.g. the test intentionally
# finishes the test with the filesystem in a corrupt state
@@ -1408,21 +1445,12 @@ _require_scratch_nocheck()
;;
esac
- # mounted?
- # Note that we use -F here so grep doesn't try to interpret an NFS over
- # IPv6 server as a regular expression.
- mount_rec=`_mount | grep -F $SCRATCH_DEV`
- if [ "$mount_rec" ]
+ _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
+ local err=$?
+ [ $err -le 1 ] || exit 1
+ if [ $err -eq 0 ]
then
- # if it's mounted, make sure its on $SCRATCH_MNT
- if ! echo $mount_rec | grep -q $SCRATCH_MNT
- then
- echo "\$SCRATCH_DEV=$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT=$SCRATCH_MNT - aborting"
- echo "Already mounted result:"
- echo $mount_rec
- exit 1
- fi
- # and then unmount it
+ # if it's mounted, unmount it
if ! _scratch_unmount
then
echo "failed to unmount $SCRATCH_DEV"
@@ -1493,21 +1521,11 @@ _require_test()
;;
esac
- # mounted?
- # Note that we use -F here so grep doesn't try to interpret an NFS over
- # IPv6 server as a regular expression.
- mount_rec=`_mount | grep -F $TEST_DEV`
- if [ "$mount_rec" ]
+ _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
+ local err=$?
+ [ $err -le 1 ] || exit 1
+ if [ $err -ne 0 ]
then
- # if it's mounted, make sure its on $TEST_DIR
- if ! echo $mount_rec | grep -q $TEST_DIR
- then
- echo "\$TEST_DEV=$TEST_DEV is mounted but not on \$TEST_DIR=$TEST_DIR - aborting"
- echo "Already mounted result:"
- echo $mount_rec
- exit 1
- fi
- else
out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
if [ $? -ne 1 ]; then
echo $out
@@ -3132,13 +3150,17 @@ init_rc()
fi
fi
- if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
- then
- echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
- # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
- _df_device $TEST_DEV
- exit 1
+ # Sanity check that TEST partition is not mounted at another mount point
+ # or as another fs type
+ _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR $FSTYP || exit 1
+ if [ -n "$SCRATCH_DEV" ]; then
+ # Sanity check that SCRATCH partition is not mounted at another
+ # mount point, because it is about to be unmounted and formatted.
+ # Another fs type for scratch is fine (bye bye old fs type).
+ _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
+ [ $? -le 1 ] || exit 1
fi
+
# Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
$XFS_IO_PROG -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
export XFS_IO_PROG="$XFS_IO_PROG -F"
--
2.7.4
next prev parent reply other threads:[~2017-02-28 12:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-28 12:18 [PATCH v5 0/10] fstests: new way to run overlay tests Amir Goldstein
2017-02-28 12:18 ` Amir Goldstein [this message]
2017-02-28 12:18 ` [PATCH v5 02/10] fstests: use _test_mount() consistently Amir Goldstein
2017-02-28 12:18 ` [PATCH v5 03/10] fstests: canonicalize mount points on every config section Amir Goldstein
2017-02-28 12:18 ` [PATCH v5 04/10] fstests: fix test and scratch filters for overlapping DEV/MNT paths Amir Goldstein
2017-02-28 12:18 ` [PATCH v5 05/10] fstests: allow overlay SCRATCH_DEV to be a base fs mount point Amir Goldstein
2017-02-28 12:18 ` [PATCH v5 06/10] generic/064: access SCRATCH_MNT after _scratch_mount Amir Goldstein
2017-02-28 12:18 ` [PATCH v5 07/10] overlay: rename OVERLAY_LOWER/UPPER/WORK_DIR Amir Goldstein
2017-02-28 12:18 ` [PATCH v5 08/10] overlay: configure TEST/SCRATCH vars to base fs Amir Goldstein
2017-02-28 12:18 ` [PATCH v5 09/10] overlay: mount/unmount base fs before/after running tests Amir Goldstein
2017-02-28 12:18 ` [PATCH v5 10/10] overlay: use OVL_BASE_SCRATCH_MNT instead of SCRATCH_DEV Amir Goldstein
2017-03-01 3:47 ` [PATCH v5 0/10] fstests: new way to run overlay tests 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=1488284317-3119-2-git-send-email-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=eguan@redhat.com \
--cc=fstests@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=xzhou@redhat.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