FS/XFS testing framework
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: fstests@vger.kernel.org, linux-btrfs@vger.kernel.org
Cc: Su Yue <glass.su@suse.com>
Subject: [PATCH] fstests: btrfs: add a new test case for fstrim crash
Date: Tue,  2 Jun 2026 14:03:47 +0930	[thread overview]
Message-ID: <20260602043347.50381-1-wqu@suse.com> (raw)

There is a bug report that btrfs/242 can crash very randomly.

It turns out the crash is caused by a re-appearing missing device, which
screwed up several checks in fstrim.

This new test case is a more reliable version, dedicated for such crash,
which will:

- Create a raid1 btrfs
- Mount with a single device in degraded mode
- Let the missing device to re-appear
- Run fstrim

Which is reliably crashing in my environment without the submitted fix.
And with the submitted fix, the test no longer crashes.

Reported-by: Su Yue <glass.su@suse.com>
Link: https://lore.kernel.org/linux-btrfs/wlwir19t.fsf@damenly.org/
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 tests/btrfs/350     | 38 ++++++++++++++++++++++++++++++++++++++
 tests/btrfs/350.out |  2 ++
 2 files changed, 40 insertions(+)
 create mode 100755 tests/btrfs/350
 create mode 100644 tests/btrfs/350.out

diff --git a/tests/btrfs/350 b/tests/btrfs/350
new file mode 100755
index 00000000..1206d66f
--- /dev/null
+++ b/tests/btrfs/350
@@ -0,0 +1,38 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 SUSE S.A.  All Rights Reserved.
+#
+# FS QA Test 350
+#
+# Make sure fstrim will not crash when a missing device re-appeared.
+#
+. ./common/preamble
+_begin_fstest auto quick volume trim raid
+
+_fixed_by_kernel_commit XXXXXXXXXXXX \
+	"btrfs: do not trim a device which is not writeable"
+
+_require_btrfs_forget_or_module_loadable
+_require_scratch_dev_pool 2
+_scratch_dev_pool_get 2
+dev1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $1 }')
+dev2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $2 }')
+
+_scratch_pool_mkfs "-m raid1 -d raid1"
+_require_batched_discard $SCRATCH_MNT
+
+# Mount the filesystem in degraded mode
+_btrfs_forget_or_module_reload
+_mount -o degraded $dev1 $SCRATCH_MNT
+
+# Now let devid 2 reappear
+_btrfs device scan $dev2
+
+# Run fstrim, it should skip the re-appeared device, as it still
+# lacks WRITEBALE flag nor a proper bdev pointer.
+#
+# For unpatched kernel, it will crash with a NULL pointer dereference.
+$FSTRIM_PROG $SCRATCH_MNT
+
+echo "Silence is golden"
+_exit 0
diff --git a/tests/btrfs/350.out b/tests/btrfs/350.out
new file mode 100644
index 00000000..e9aad823
--- /dev/null
+++ b/tests/btrfs/350.out
@@ -0,0 +1,2 @@
+QA output created by 350
+Silence is golden
-- 
2.51.2


             reply	other threads:[~2026-06-02  4:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02  4:33 Qu Wenruo [this message]
2026-06-02 10:25 ` [PATCH] fstests: btrfs: add a new test case for fstrim crash Filipe Manana

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=20260602043347.50381-1-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=fstests@vger.kernel.org \
    --cc=glass.su@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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