Re: [PATCH] fstests: btrfs: add a new test case for fstrim crash
Filipe Manana <[email protected]>
| Newsgroups | org.kernel.vger.fstests,org.kernel.vger.linux-btrfs |
|---|---|
| Message-ID | <CAL3q7H7HxyDhgDShkDrZkoZgJ0yHcOB7wAr9u3kS-ZWaqSMQ1Q@mail.gmail.com> |
On Tue, Jun 2, 2026 at 5:34 AM Qu Wenruo <[email protected]> wrote: > > 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 <[email protected]> > Link: https://lore.kernel.org/linux-btrfs/[email protected]/ > Signed-off-by: Qu Wenruo <[email protected]> > --- > 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. nor -> and > +# > +# For unpatched kernel, it will crash with a NULL pointer dereference. > +$FSTRIM_PROG $SCRATCH_MNT Misses a call to: _scratch_dev_pool_put Otherwise: Reviewed-by: Filipe Manana <[email protected]> Thanks. > + > +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 > >