xfs: various operations on mounted fs
authorZorro Lang <zlang@redhat.com>
Wed, 14 Sep 2016 15:55:58 +0000 (23:55 +0800)
committerEryu Guan <eguan@redhat.com>
Thu, 15 Sep 2016 04:26:58 +0000 (12:26 +0800)
xfsprogs takes use of ustat(2) to check if a given device is
mounted, but ustat(2) is deprecated and may not be available on
newer architectures, e.g. aarch64. In such cases, xfsprogs failed to
detect mounted device, which would result in something like
xfs_mdrestore overwriting a mounted XFS.

So adding a case to do xfs_mdrestore, xfs_copy, xfs_db, mkfs and
xfs_repair against mounted XFS to make sure they refuse to do so.

Signed-off-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
tests/xfs/284 [new file with mode: 0755]
tests/xfs/284.out [new file with mode: 0644]
tests/xfs/group

diff --git a/tests/xfs/284 b/tests/xfs/284
new file mode 100755 (executable)
index 0000000..e3625fe
--- /dev/null
@@ -0,0 +1,107 @@
+#! /bin/bash
+# FS QA Test 284
+#
+# Do xfs_metadump, xfs_mdrestore, xfs_copy, xfs_db, xfs_repair and mkfs.xfs
+# on mounted XFS to make sure they refuse to proceed.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2016 Red Hat.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.*
+       rm -f $METADUMP_FILE 2>/dev/null
+       rm -f $COPY_FILE 2>/dev/null
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs xfs
+_supported_os Linux
+_require_test
+_require_scratch
+
+function filter_mounted()
+{
+       grep "mounted" | _filter_scratch | head -1
+}
+
+METADUMP_FILE="${TEST_DIR}/${seq}_metadump"
+COPY_FILE="${TEST_DIR}/${seq}_copyfile"
+
+# Test dump a mounted device
+# xfs_metadump should refuse to dump a mounted device
+_scratch_mount
+_scratch_metadump $METADUMP_FILE 2>&1 | filter_mounted
+_scratch_unmount
+
+# Test restore to a mounted device
+# xfs_mdrestore should refuse to restore to a mounted device
+_scratch_metadump $METADUMP_FILE
+_scratch_mount
+xfs_mdrestore $METADUMP_FILE $SCRATCH_DEV 2>&1 | filter_mounted
+_scratch_unmount
+
+# Test xfs_copy to a mounted device
+# If source is mounted, xfs_copy will print a warning, but still
+# keep on copying. If target is mounted, xfs_copy should fail.
+$XFS_COPY_PROG $SCRATCH_DEV $COPY_FILE >/dev/null
+_scratch_mount
+$XFS_COPY_PROG $COPY_FILE $SCRATCH_DEV 2>&1 | filter_mounted
+_scratch_unmount
+
+# Test xfs_db a mounted device
+# xfs_db a mounted device without readonly (-r) option should fail
+_scratch_mount
+$XFS_DB_PROG -c sb $SCRATCH_DEV 2>&1 | filter_mounted
+_scratch_unmount
+
+# Test mkfs.xfs a mounted device
+# Generally mkfs will report device is mounted, but if it can't find
+# device is mounted, it'll report device busy.
+_scratch_mount
+_scratch_mkfs 2>&1 | filter_mounted
+_scratch_unmount
+
+# Test xfs_repair (with/without modify flag) a mounted device
+# xfs_repair (with/without modify flag) a mounted device should fail(don't
+# test -d option at here)
+_scratch_mount
+_scratch_xfs_repair -n 2>&1 | filter_mounted
+_scratch_xfs_repair 2>&1 | filter_mounted
+_scratch_unmount
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/284.out b/tests/xfs/284.out
new file mode 100644 (file)
index 0000000..302d75e
--- /dev/null
@@ -0,0 +1,8 @@
+QA output created by 284
+xfs_metadump: SCRATCH_DEV contains a mounted and writable filesystem
+xfs_mdrestore: a filesystem is mounted on target device "SCRATCH_DEV", cannot restore to a mounted filesystem.
+xfs_copy:  a filesystem is mounted on target device "SCRATCH_DEV".
+xfs_db: SCRATCH_DEV contains a mounted filesystem
+mkfs.xfs: SCRATCH_DEV contains a mounted filesystem
+xfs_repair: SCRATCH_DEV contains a mounted and writable filesystem
+xfs_repair: SCRATCH_DEV contains a mounted filesystem
index baa0ff61f530bececf7694b30854eba5964aba7b..01569609d65c2b7b010170a8b4e12fd45c36042b 100644 (file)
 281 dump ioctl auto quick
 282 dump ioctl auto quick
 283 dump ioctl auto quick
+284 auto quick dump copy db mkfs repair
 287 auto dump quota quick
 290 auto rw prealloc quick ioctl zero
 291 auto repair