* [PATCH v2] fstests: btrfs: add a regression test case to make sure scrub can detect errors
@ 2022-11-09 5:47 Qu Wenruo
2022-11-09 11:06 ` Filipe Manana
0 siblings, 1 reply; 2+ messages in thread
From: Qu Wenruo @ 2022-11-09 5:47 UTC (permalink / raw)
To: linux-btrfs, fstests
There is a regression in v6.1-rc kernel, which will prevent btrfs scrub
from detecting corruption (thus no repair either).
The regression is caused by commit 786672e9e1a3 ("btrfs: scrub: use
larger block size for data extent scrub").
The new test case will:
- Create a data extent with 2 sectors
- Corrupt the second sector of above data extent
- Scrub to make sure we detect the corruption
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
Changelog:
v2:
- Remove include for common/btrfs
Which is included by default.
- Add comment for why including common/filter
Needed by _btrfs_get_*() helpers.
- Migrated to btrfs/278
Which is the latest result by "./new btrfs" on for-next branch.
- Add "-s 4k" for _scratch_mkfs
To support systems with larger page sizes.
- Remove comments from the template
---
tests/btrfs/281 | 62 +++++++++++++++++++++++++++++++++++++++++++++
tests/btrfs/281.out | 2 ++
2 files changed, 64 insertions(+)
create mode 100755 tests/btrfs/281
create mode 100644 tests/btrfs/281.out
diff --git a/tests/btrfs/281 b/tests/btrfs/281
new file mode 100755
index 00000000..69b5ac02
--- /dev/null
+++ b/tests/btrfs/281
@@ -0,0 +1,62 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# A regression test for offending commit 786672e9e1a3 ("btrfs: scrub: use
+# larger block size for data extent scrub"), which makes btrfs scrub unable
+# to detect corruption if it's not the first sector of an data extent.
+#
+
+. ./common/preamble
+_begin_fstest auto quick scrub
+
+# For _btrfs_get_*() helpers which needs filtering.
+. ./common/filter
+
+_supported_fs btrfs
+_require_scratch
+
+# Need to use 4K as sector size
+_require_btrfs_support_sectorsize 4096
+_require_scratch
+
+_scratch_mkfs -s 4k >> $seqres.full
+_scratch_mount
+
+# Create a data extent with 2 sectors
+$XFS_IO_PROG -fc "pwrite -S 0xff 0 8k" $SCRATCH_MNT/foobar >> $seqres.full
+sync
+
+first_logical=$(_btrfs_get_first_logical $SCRATCH_MNT/foobar)
+echo "logical of the first sector: $first_logical" >> $seqres.full
+
+second_logical=$(( $first_logical + 4096 ))
+echo "logical of the second sector: $second_logical" >> $seqres.full
+
+second_physical=$(_btrfs_get_physical $second_logical 1)
+echo "physical of the second sector: $second_physical" >> $seqres.full
+
+second_dev=$(_btrfs_get_device_path $second_logical 1)
+echo "device of the second sector: $second_dev" >> $seqres.full
+
+_scratch_unmount
+
+# Corrupt the second sector of the data extent.
+$XFS_IO_PROG -c "pwrite -S 0x00 $second_physical 4k" $second_dev >> $seqres.full
+_scratch_mount
+
+# Redirect stderr and stdout, as if btrfs detected the unrepairable corruption,
+# it will output an error message.
+$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT &> $tmp.output
+cat $tmp.output >> $seqres.full
+_scratch_unmount
+
+if ! grep -q "csum=1" $tmp.output; then
+ echo "Scrub failed to detect corruption"
+fi
+
+echo "Silence is golden"
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/281.out b/tests/btrfs/281.out
new file mode 100644
index 00000000..3678e27f
--- /dev/null
+++ b/tests/btrfs/281.out
@@ -0,0 +1,2 @@
+QA output created by 281
+Silence is golden
--
2.38.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] fstests: btrfs: add a regression test case to make sure scrub can detect errors
2022-11-09 5:47 [PATCH v2] fstests: btrfs: add a regression test case to make sure scrub can detect errors Qu Wenruo
@ 2022-11-09 11:06 ` Filipe Manana
0 siblings, 0 replies; 2+ messages in thread
From: Filipe Manana @ 2022-11-09 11:06 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs, fstests
On Wed, Nov 09, 2022 at 01:47:23PM +0800, Qu Wenruo wrote:
> There is a regression in v6.1-rc kernel, which will prevent btrfs scrub
> from detecting corruption (thus no repair either).
>
> The regression is caused by commit 786672e9e1a3 ("btrfs: scrub: use
> larger block size for data extent scrub").
>
> The new test case will:
>
> - Create a data extent with 2 sectors
> - Corrupt the second sector of above data extent
> - Scrub to make sure we detect the corruption
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> Changelog:
> v2:
> - Remove include for common/btrfs
> Which is included by default.
>
> - Add comment for why including common/filter
> Needed by _btrfs_get_*() helpers.
>
> - Migrated to btrfs/278
> Which is the latest result by "./new btrfs" on for-next branch.
>
> - Add "-s 4k" for _scratch_mkfs
> To support systems with larger page sizes.
>
> - Remove comments from the template
> ---
> tests/btrfs/281 | 62 +++++++++++++++++++++++++++++++++++++++++++++
> tests/btrfs/281.out | 2 ++
> 2 files changed, 64 insertions(+)
> create mode 100755 tests/btrfs/281
> create mode 100644 tests/btrfs/281.out
>
> diff --git a/tests/btrfs/281 b/tests/btrfs/281
> new file mode 100755
> index 00000000..69b5ac02
> --- /dev/null
> +++ b/tests/btrfs/281
> @@ -0,0 +1,62 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2022 SUSE Linux Products GmbH. All Rights Reserved.
> +#
> +# A regression test for offending commit 786672e9e1a3 ("btrfs: scrub: use
> +# larger block size for data extent scrub"), which makes btrfs scrub unable
> +# to detect corruption if it's not the first sector of an data extent.
> +#
> +
> +. ./common/preamble
> +_begin_fstest auto quick scrub
> +
> +# For _btrfs_get_*() helpers which needs filtering.
> +. ./common/filter
> +
> +_supported_fs btrfs
> +_require_scratch
> +
> +# Need to use 4K as sector size
> +_require_btrfs_support_sectorsize 4096
> +_require_scratch
Nit: duplicated, already called before.
> +
> +_scratch_mkfs -s 4k >> $seqres.full
Btw, older btrfs-progs versions had mkfs print messages to stderr when
they do a discard, like this:
"Performing full device TRIM (100.00GiB) ..."
So it's better to redirect stderr as well, to avoid golden output mismatch.
That's why all (or almost all) test cases also redirect stderr when calling
_scratch_mkfs.
> +_scratch_mount
> +
> +# Create a data extent with 2 sectors
> +$XFS_IO_PROG -fc "pwrite -S 0xff 0 8k" $SCRATCH_MNT/foobar >> $seqres.full
Instead of redirecting stdout, in situations like this I prefer to filter
xfs_io's output (| _fitler_xfs_io) and then place it in the golden output.
That's just to make it easier to debug if we somehow get a short write
(can happen during development), as that doesn't print anything to stderr.
Otherwise failing below at _btrfs_get_physical will probably give a more
cryptic failure, not immediately obvious.
Otherwise it looks good to me, thanks.
Reviewed-by: Filipe Manana <fdmanana@suse.com>
> +sync
> +
> +first_logical=$(_btrfs_get_first_logical $SCRATCH_MNT/foobar)
> +echo "logical of the first sector: $first_logical" >> $seqres.full
> +
> +second_logical=$(( $first_logical + 4096 ))
> +echo "logical of the second sector: $second_logical" >> $seqres.full
> +
> +second_physical=$(_btrfs_get_physical $second_logical 1)
> +echo "physical of the second sector: $second_physical" >> $seqres.full
> +
> +second_dev=$(_btrfs_get_device_path $second_logical 1)
> +echo "device of the second sector: $second_dev" >> $seqres.full
> +
> +_scratch_unmount
> +
> +# Corrupt the second sector of the data extent.
> +$XFS_IO_PROG -c "pwrite -S 0x00 $second_physical 4k" $second_dev >> $seqres.full
> +_scratch_mount
> +
> +# Redirect stderr and stdout, as if btrfs detected the unrepairable corruption,
> +# it will output an error message.
> +$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT &> $tmp.output
> +cat $tmp.output >> $seqres.full
> +_scratch_unmount
> +
> +if ! grep -q "csum=1" $tmp.output; then
> + echo "Scrub failed to detect corruption"
> +fi
> +
> +echo "Silence is golden"
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/btrfs/281.out b/tests/btrfs/281.out
> new file mode 100644
> index 00000000..3678e27f
> --- /dev/null
> +++ b/tests/btrfs/281.out
> @@ -0,0 +1,2 @@
> +QA output created by 281
> +Silence is golden
> --
> 2.38.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-09 11:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-09 5:47 [PATCH v2] fstests: btrfs: add a regression test case to make sure scrub can detect errors Qu Wenruo
2022-11-09 11:06 ` Filipe Manana
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox