Skip to contentSkip to conversation

btrfs: add test case for read-only scrub on read-only mount

PATCH New Qu Wenruo 1 participant 1 message Dec 16, 2021 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 btrfs: add test case for read-only scrub on read-only mount

There is a long existing bug that read-only scrub on read-only mounted btrfs can lead to a uncommitted and empty transaction.

Such problem is not detected until v5.11 which new ASSERT() is added.

The purposed fix is titled "btrfs: don't start transaction for scrub if the fs is mounted read-only".

The test case is here to make sure a read-only scrub on read-only mounted btrfs won't crash/trigger ASSERT() at unmount time.

---
 tests/btrfs/254     | 48 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/254.out |  3 +++
 2 files changed, 51 insertions(+)
 create mode 100755 tests/btrfs/254
 create mode 100644 tests/btrfs/254.out
tests/btrfs/254 new file +48 -0
new file mode 100755
index 00000000..0e001cd9
@@ -0,0 +1,48 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test 254
+#
+# Make sure running read-only scrub on read-only mounted btrfs won't crash
+# the kernel at unmount time
+#
+. ./common/preamble
+_begin_fstest auto quick scrub
+
+# Override the default cleanup function.
+# _cleanup()
+# {
+# 	cd /
+# 	rm -r -f $tmp.*
+# }
+
+# Import common functions.
+. ./common/filter
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs btrfs
+_require_scratch
+
+_scratch_mkfs >> $seqres.full
+_scratch_mount
+
+# Fill the fs with some content for later scrub
+_pwrite_byte 0xff 0 64k "$SCRATCH_MNT/foobar" | _filter_xfs_io
+
+# Cycle mount to read-only
+_scratch_cycle_mount ro
+
+# Do the read-only scrub.
+# For unpatched kernel, this would lead to a new transaction
+# on read-only fs, which will not be committed
+$BTRFS_UTIL_PROG scrub start -Br "$SCRATCH_MNT"  >> $seqres.full
+
+# At unmount time, if kernel has CONFIG_BTRFS_ASSERT, then it would
+# crash at one ASSERT(), cause by above uncommitted transaction.
+
+# success, all done
+status=0
+exit
tests/btrfs/254.out new file +3 -0
new file mode 100644
index 00000000..58fd5a0f
@@ -0,0 +1,3 @@
+QA output created by 254
+wrote 65536/65536 bytes at offset 0
+XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
Signature · 1 line
2.34.1