aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2023-02-25 17:14:38 +0800
committerZorro Lang <zlang@kernel.org>2023-07-23 12:56:22 +0800
commit9b84d93f225f4ffbb61030ac39ef89ee459e64b1 (patch)
treeff9678b2306ad09412e27a61e16d7705b8e56614
parent6ca154c1b239d1e1fa9153d66272a1bf9e34c65e (diff)
downloadxfstests-dev-9b84d93f225f4ffbb61030ac39ef89ee459e64b1.tar.gz
btrfs: add a test case to check btrfs won't crash on certain corruption
The test case would reproduce the situation by creating an empty fs, with SINGLE metadata profile, then corrupt the tree root manually. Finally try mounting the corrupted fs, the mount should fail while our kernel should not fail. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> [ Update commit log. Fix a line gt 80 chars. Use append to $seqres.full. Fix comment ] Signed-off-by: Anand Jain <anand.jain@oracle.com>
-rwxr-xr-xtests/btrfs/29538
-rw-r--r--tests/btrfs/295.out2
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/btrfs/295 b/tests/btrfs/295
new file mode 100755
index 0000000000..a9a8e5530a
--- /dev/null
+++ b/tests/btrfs/295
@@ -0,0 +1,38 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2023 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test No. 295
+#
+# Make sure btrfs handles critical errors gracefully during mount.
+#
+. ./common/preamble
+_begin_fstest auto quick dangerous
+
+. ./common/filter
+_supported_fs btrfs
+_require_scratch
+
+# Use single metadata profile so we only need to corrupt one copy of tree block
+_scratch_mkfs -m single > $seqres.full
+
+logical_root=$($BTRFS_UTIL_PROG inspect dump-tree -t root "$SCRATCH_DEV" | \
+ grep leaf | head -n1 | cut -f2 -d\ )
+physical_root=$(_btrfs_get_physical $logical_root 1)
+
+echo "tree root logical=$logical_root" >> $seqres.full
+echo "tree root physical=$physical_root" >> $seqres.full
+
+_pwrite_byte 0x00 "$physical_root" 4 $SCRATCH_DEV >> $seqres.full
+
+# mount may lead to crash
+_try_scratch_mount >> $seqres.full 2>&1
+
+echo "Silence is golden"
+
+# Re-create the fs to avoid false alert from the corrupted fs.
+_scratch_mkfs -m single >> $seqres.full
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/295.out b/tests/btrfs/295.out
new file mode 100644
index 0000000000..cbebcba74f
--- /dev/null
+++ b/tests/btrfs/295.out
@@ -0,0 +1,2 @@
+QA output created by 295
+Silence is golden