Skip to contentSkip to conversation

fstests: test xfs rw remount with unknown ro-compat features

PATCH Superseded Zorro Lang 2 participants 2 messages Aug 27, 2016 – Aug 28, 2016

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zorro Lang

author
#0 lore raw

PATCH v2 1/1 fstests: test xfs rw remount with unknown ro-compat features

Although ro-compat features cannot be mounted rw, a bug allows an ro->rw remount transition, and this will corrupt the filesystem if it contains ro-compat features unknown to the running kernel.

This bug has been fix on linux kernel (d0a58e8 xfs: disallow rw remount on fs with unknown ro-compat features), this case is the regression testcase of that bug.

---

V2 fix some mistakes of golden image(.out) file.

Thanks,
Zorro

 tests/xfs/263     | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/263.out |  6 ++++
 tests/xfs/group   |  1 +
 3 files changed, 106 insertions(+)
 create mode 100755 tests/xfs/263
 create mode 100644 tests/xfs/263.out
tests/xfs/263 new file +99 -0
new file mode 100755
index 0000000..a46e250
@@ -0,0 +1,99 @@
+#! /bin/bash
+# FS QA Test 263
+#
+# Test upstream d0a58e8:
+#   xfs: disallow rw remount on fs with unknown ro-compat features
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2016 Red Hat, Inc.  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.*
+	# Due to we've broken the superblock of SCRATCH_DEV by
+	# xfs_db, so clean bad superblock at the end
+	_scratch_unmount
+	_scratch_mkfs >/dev/null 2>&1
+}
+
+# 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_scratch
+_require_xfs_crc
+
+# Only V5 XFS disallow rw mount/remount with unknown ro-compat
+# features
+MKFS_OPTIONS="-m crc=1"
+_scratch_mkfs_xfs >>$seqres.full 2>&1
+
+# set the highest bit of features_ro_compat, use it as an unknown
+# feature bit. If one day this bit become known feature, please
+# change this case.
+$XFS_DB_PROG -x -c "sb 0" \
+                -c "write features_ro_compat $((2**31))" \
+		$SCRATCH_DEV
+
+echo "rw mount test"
+# Maybe this mount will fail by bad superblock
+# But keep testing this anyway
+MOUNT_OPTIONS="-o rw"
+_scratch_mount 2>>$seqres.full
+if [ $? -eq 0 ]; then
+	_fail "rw mount test failed"
+fi
+
+echo "ro mount test"
+MOUNT_OPTIONS="-o ro"
+_scratch_mount
+if [ $? -ne 0 ]; then
+	_fail "ro mount test failed"
+else
+	# no hang/panic is fine
+	$FSSTRESS_PROG -d $SCRATCH_MNT -p 4 -n 400 >>$seqres.full 2>&1
+fi
+
+dmesg -c >/dev/null
+echo "rw remount test"
+MOUNT_OPTIONS="-o rw,remount"
+_scratch_mount 2>>$seqres.full
+if [ $? -eq 0 ]; then
+	_fail "rw,remount test failed"
+fi
+dmesg -c | sed -n -e "s/.*XFS.*: \(ro->rw transition prohibited.*\)/\1/p"
+
+# success, all done
+status=0
+exit
tests/xfs/263.out new file +6 -0
new file mode 100644
index 0000000..440ed32
@@ -0,0 +1,6 @@
+QA output created by 263
+features_ro_compat = 0x80000000
+rw mount test
+ro mount test
+rw remount test
+ro->rw transition prohibited on unknown (0x80000000) ro-compat filesystem
tests/xfs/group +1 -0
index 6905a62..ec3c022 100644
@@ -260,6 +260,7 @@
 260 auto quick quota
 261 auto quick quota
 262 auto quick quota
+263 auto quick mount
 265 auto clone
 266 dump ioctl auto quick
 267 dump ioctl tape
Signature · 1 line
2.7.4
#1 lore raw
Quoted 29 lines · Zorro Lang

Although ro-compat features cannot be mounted rw, a bug allows an ro->rw remount transition, and this will corrupt the filesystem if it contains ro-compat features unknown to the running kernel.

This bug has been fix on linux kernel (d0a58e8 xfs: disallow rw remount on fs with unknown ro-compat features), this case is the regression testcase of that bug.

---

V2 fix some mistakes of golden image(.out) file.

Thanks,
Zorro

 tests/xfs/263     | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/263.out |  6 ++++
 tests/xfs/group   |  1 +
 3 files changed, 106 insertions(+)
 create mode 100755 tests/xfs/263
 create mode 100644 tests/xfs/263.out
tests/xfs/263 new file +0 -0
new file mode 100755
index 0000000..a46e250

tests/xfs/263 line 5

Quoted 5 lines
tests/xfs/263 new file +5 -0
@@ -0,0 +1,99 @@
+#! /bin/bash
+# FS QA Test 263
+#
+# Test upstream d0a58e8:
+#   xfs: disallow rw remount on fs with unknown ro-compat features

Need detailed test description here too.

Quoted 26 lines
tests/xfs/263 new file +26 -0
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2016 Red Hat, Inc.  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!

tests/xfs/263 line 41

Quoted 10 lines
tests/xfs/263 new file +10 -0
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+	# Due to we've broken the superblock of SCRATCH_DEV by
+	# xfs_db, so clean bad superblock at the end
+	_scratch_unmount
+	_scratch_mkfs >/dev/null 2>&1

This can be done by calling _require_scratch_nocheck in the test instead of _require_scratch, so there's no fsck run after test.

Quoted 4 lines
tests/xfs/263 new file +4 -0
+}
+
+# get standard environment, filters and checks
+. ./common/rc

tests/xfs/263 line 55

Quoted 10 lines
tests/xfs/263 new file +10 -0
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs xfs
+_supported_os Linux
+_require_scratch
+_require_xfs_crc

_require_scratch_xfs_crc and ..

tests/xfs/263 line 59

Quoted 4 lines
tests/xfs/263 new file +4 -0
+
+# Only V5 XFS disallow rw mount/remount with unknown ro-compat
+# features
+MKFS_OPTIONS="-m crc=1"

you don't have to overwrite MKFS_OPTIONS, let the user specify test config, and just skip the test if scratch_dev has no crc support.

tests/xfs/263 line 72

Quoted 13 lines
tests/xfs/263 new file +13 -0
+_scratch_mkfs_xfs >>$seqres.full 2>&1
+
+# set the highest bit of features_ro_compat, use it as an unknown
+# feature bit. If one day this bit become known feature, please
+# change this case.
+$XFS_DB_PROG -x -c "sb 0" \
+                -c "write features_ro_compat $((2**31))" \
+		$SCRATCH_DEV
+
+echo "rw mount test"
+# Maybe this mount will fail by bad superblock
+# But keep testing this anyway
+MOUNT_OPTIONS="-o rw"

rw mount is the default, I don't think overwriting MOUNT_OPTIONS is necessary.

tests/xfs/263 line 80

Quoted 8 lines
tests/xfs/263 new file +8 -0
+_scratch_mount 2>>$seqres.full
+if [ $? -eq 0 ]; then
+	_fail "rw mount test failed"
+fi
+
+echo "ro mount test"
+MOUNT_OPTIONS="-o ro"
+_scratch_mount

_scratch_mount -o ro

No need to overwrite MOUNT_OPTIONS either.

tests/xfs/263 line 85

Quoted 5 lines
tests/xfs/263 new file +5 -0
+if [ $? -ne 0 ]; then
+	_fail "ro mount test failed"
+else
+	# no hang/panic is fine
+	$FSSTRESS_PROG -d $SCRATCH_MNT -p 4 -n 400 >>$seqres.full 2>&1

I don't think this is necessary, because the fs is ro-mounted, but it's fine by me, just make sure there's no hang/panic on unknown ro_compat feature ro-mount.

tests/xfs/263 line 91

Quoted 6 lines
tests/xfs/263 new file +6 -0
+fi
+
+dmesg -c >/dev/null
+echo "rw remount test"
+MOUNT_OPTIONS="-o rw,remount"
+_scratch_mount 2>>$seqres.full

_scratch_remount rw

tests/xfs/263 line 95

Quoted 4 lines
tests/xfs/263 new file +4 -0
+if [ $? -eq 0 ]; then
+	_fail "rw,remount test failed"
+fi
+dmesg -c | sed -n -e "s/.*XFS.*: \(ro->rw transition prohibited.*\)/\1/p"

We probably don't want to clear dmesg buffer if possible, and I think making sure remount,rw failed is good enough. Or we can write a new helper to look for specific dmesg by following how _check_dmesg does?

Thanks,
Eryu

Quoted 35 lines
tests/xfs/263 new file +4 -0
+
+# success, all done
+status=0
+exit
tests/xfs/263.out new file +6 -0
new file mode 100644
index 0000000..440ed32
@@ -0,0 +1,6 @@
+QA output created by 263
+features_ro_compat = 0x80000000
+rw mount test
+ro mount test
+rw remount test
+ro->rw transition prohibited on unknown (0x80000000) ro-compat filesystem
tests/xfs/group +1 -0
index 6905a62..ec3c022 100644
@@ -260,6 +260,7 @@
 260 auto quick quota
 261 auto quick quota
 262 auto quick quota
+263 auto quick mount
 265 auto clone
 266 dump ioctl auto quick
 267 dump ioctl tape
Signature · 6 lines
2.7.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs