linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][v2] fstests: btrfs/219 add a test to test -o rescue=all
@ 2020-09-09 12:25 Josef Bacik
  2020-09-13 15:45 ` Eryu Guan
  0 siblings, 1 reply; 2+ messages in thread
From: Josef Bacik @ 2020-09-09 12:25 UTC (permalink / raw)
  To: linux-btrfs, kernel-team, fstests

This new mount option makes sure we can still mount the file system if
any of the core roots are corrupted.  This test corrupts each of these
roots and validates that it can still mount the fs and read the file.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
v1->v2:
- Sent the actual intended patch this time.

 tests/btrfs/219     | 99 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/219.out | 30 ++++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 130 insertions(+)
 create mode 100755 tests/btrfs/219
 create mode 100644 tests/btrfs/219.out

diff --git a/tests/btrfs/219 b/tests/btrfs/219
new file mode 100755
index 00000000..c6abc111
--- /dev/null
+++ b/tests/btrfs/219
@@ -0,0 +1,99 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Facebook.  All Rights Reserved.
+#
+# FS QA Test 219
+#
+# A test to exercise the various failure scenarios for -o rescue=all.  This is
+# mainly a regression test for
+#
+#   btrfs: introduce rescue=all
+#
+# We simply corrupt a bunch of core roots and validate that it works the way we
+# expect it to.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+_generate_fs()
+{
+	# We need single so we don't just read the duplicates
+	_scratch_mkfs -m single -d single > $seqres.full 2>&1
+	_scratch_mount
+	$XFS_IO_PROG -f -c "pwrite -S 0xab 0 1M" $SCRATCH_MNT/foo | \
+		_filter_xfs_io
+	md5sum $SCRATCH_MNT/foo | _filter_scratch
+	_scratch_unmount
+}
+
+_clear_root()
+{
+	# Grab the bytenr for the root by dumping the tree roots, clearing up to
+	# the key so our first column is the bytenr.  With a normal device with
+	# single should mean that physical == logical
+	local bytenr=$($BTRFS_UTIL_PROG inspect-internal dump-tree -r \
+		$SCRATCH_DEV | grep "$1" | sed 's/.*) //g'| \
+		awk '{ print $1 }')
+	dd if=/dev/zero of=$SCRATCH_DEV bs=1 seek=$bytenr count=4096 | \
+		_filter_dd
+}
+
+_test_failure()
+{
+	_try_scratch_mount $* > /dev/null 2>&1
+	[ $? -eq 0 ] && _fail "We should have failed to mount"
+}
+
+_test_success()
+{
+	_generate_fs
+	_clear_root "$1"
+	_test_failure
+	_scratch_mount -o rescue=all,ro
+	md5sum $SCRATCH_MNT/foo | _filter_scratch
+	_scratch_unmount
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+_supported_fs generic
+_supported_os Linux
+_require_test
+_require_scratch_mountopt "rescue=all,ro"
+
+# Test with the roots that should definitely pass
+_test_success "extent tree"
+_test_success "checksum tree"
+_test_success "uuid tree"
+_test_success "data reloc"
+
+# Now test the roots that will definitely fail
+_generate_fs
+_clear_root "fs tree"
+_test_failure -o rescue=all,ro
+
+# We have to re-mkfs the fs because otherwise the post-test fsck will blow up
+_scratch_mkfs > /dev/null 2>&1
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/219.out b/tests/btrfs/219.out
new file mode 100644
index 00000000..9a6d43c4
--- /dev/null
+++ b/tests/btrfs/219.out
@@ -0,0 +1,30 @@
+QA output created by 219
+wrote 1048576/1048576 bytes at offset 0
+XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
+4096+0 records in
+4096+0 records out
+096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
+wrote 1048576/1048576 bytes at offset 0
+XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
+4096+0 records in
+4096+0 records out
+096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
+wrote 1048576/1048576 bytes at offset 0
+XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
+4096+0 records in
+4096+0 records out
+096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
+wrote 1048576/1048576 bytes at offset 0
+XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
+4096+0 records in
+4096+0 records out
+096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
+wrote 1048576/1048576 bytes at offset 0
+XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
+4096+0 records in
+4096+0 records out
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 3295856d..f4dbfafb 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -221,3 +221,4 @@
 216 auto quick seed
 217 auto quick trim dangerous
 218 auto quick volume
+219 auto quick
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH][v2] fstests: btrfs/219 add a test to test -o rescue=all
  2020-09-09 12:25 [PATCH][v2] fstests: btrfs/219 add a test to test -o rescue=all Josef Bacik
@ 2020-09-13 15:45 ` Eryu Guan
  0 siblings, 0 replies; 2+ messages in thread
From: Eryu Guan @ 2020-09-13 15:45 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team, fstests

On Wed, Sep 09, 2020 at 08:25:51AM -0400, Josef Bacik wrote:
> This new mount option makes sure we can still mount the file system if
> any of the core roots are corrupted.  This test corrupts each of these
> roots and validates that it can still mount the fs and read the file.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

I think patch "fstests: add a _require_scratch_mountopt helper" could be
folded into this one. So the new helper is with its usage, which should
be easier to review.

> ---
> v1->v2:
> - Sent the actual intended patch this time.
> 
>  tests/btrfs/219     | 99 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/219.out | 30 ++++++++++++++
>  tests/btrfs/group   |  1 +
>  3 files changed, 130 insertions(+)
>  create mode 100755 tests/btrfs/219
>  create mode 100644 tests/btrfs/219.out
> 
> diff --git a/tests/btrfs/219 b/tests/btrfs/219
> new file mode 100755
> index 00000000..c6abc111
> --- /dev/null
> +++ b/tests/btrfs/219
> @@ -0,0 +1,99 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2020 Facebook.  All Rights Reserved.
> +#
> +# FS QA Test 219
> +#
> +# A test to exercise the various failure scenarios for -o rescue=all.  This is
> +# mainly a regression test for
> +#
> +#   btrfs: introduce rescue=all

This kernel patch is still in review, I'd wait for it to be merged, or
at least acked by other btrfs folks and/or maintainer.

> +#
> +# We simply corrupt a bunch of core roots and validate that it works the way we
> +# expect it to.
> +#
> +seq=`basename $0`
> +seqres=$RESULT_DIR/$seq
> +echo "QA output created by $seq"
> +
> +here=`pwd`
> +tmp=/tmp/$$
> +status=1	# failure is the default!
> +trap "_cleanup; exit \$status" 0 1 2 3 15
> +
> +_cleanup()
> +{
> +	cd /
> +	rm -f $tmp.*
> +}
> +
> +_generate_fs()

Local functions don't need to be prefixed with "_".

> +{
> +	# We need single so we don't just read the duplicates
> +	_scratch_mkfs -m single -d single > $seqres.full 2>&1
> +	_scratch_mount
> +	$XFS_IO_PROG -f -c "pwrite -S 0xab 0 1M" $SCRATCH_MNT/foo | \
> +		_filter_xfs_io
> +	md5sum $SCRATCH_MNT/foo | _filter_scratch
> +	_scratch_unmount
> +}
> +
> +_clear_root()
> +{
> +	# Grab the bytenr for the root by dumping the tree roots, clearing up to
> +	# the key so our first column is the bytenr.  With a normal device with
> +	# single should mean that physical == logical
> +	local bytenr=$($BTRFS_UTIL_PROG inspect-internal dump-tree -r \

Add a require for this?

_require_btrfs_command inspect-internal dump-tree

> +		$SCRATCH_DEV | grep "$1" | sed 's/.*) //g'| \
> +		awk '{ print $1 }')
                ^^^ $AWK_PROG

Thanks,
Eryu

> +	dd if=/dev/zero of=$SCRATCH_DEV bs=1 seek=$bytenr count=4096 | \
> +		_filter_dd
> +}
> +
> +_test_failure()
> +{
> +	_try_scratch_mount $* > /dev/null 2>&1
> +	[ $? -eq 0 ] && _fail "We should have failed to mount"
> +}
> +
> +_test_success()
> +{
> +	_generate_fs
> +	_clear_root "$1"
> +	_test_failure
> +	_scratch_mount -o rescue=all,ro
> +	md5sum $SCRATCH_MNT/foo | _filter_scratch
> +	_scratch_unmount
> +}
> +
> +# get standard environment, filters and checks
> +. ./common/rc
> +. ./common/filter
> +
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
> +
> +# real QA test starts here
> +
> +_supported_fs generic
> +_supported_os Linux
> +_require_test
> +_require_scratch_mountopt "rescue=all,ro"
> +
> +# Test with the roots that should definitely pass
> +_test_success "extent tree"
> +_test_success "checksum tree"
> +_test_success "uuid tree"
> +_test_success "data reloc"
> +
> +# Now test the roots that will definitely fail
> +_generate_fs
> +_clear_root "fs tree"
> +_test_failure -o rescue=all,ro
> +
> +# We have to re-mkfs the fs because otherwise the post-test fsck will blow up
> +_scratch_mkfs > /dev/null 2>&1
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/btrfs/219.out b/tests/btrfs/219.out
> new file mode 100644
> index 00000000..9a6d43c4
> --- /dev/null
> +++ b/tests/btrfs/219.out
> @@ -0,0 +1,30 @@
> +QA output created by 219
> +wrote 1048576/1048576 bytes at offset 0
> +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
> +096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
> +4096+0 records in
> +4096+0 records out
> +096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
> +wrote 1048576/1048576 bytes at offset 0
> +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
> +096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
> +4096+0 records in
> +4096+0 records out
> +096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
> +wrote 1048576/1048576 bytes at offset 0
> +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
> +096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
> +4096+0 records in
> +4096+0 records out
> +096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
> +wrote 1048576/1048576 bytes at offset 0
> +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
> +096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
> +4096+0 records in
> +4096+0 records out
> +096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
> +wrote 1048576/1048576 bytes at offset 0
> +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
> +096003817ad2638000a6836e55866697  SCRATCH_MNT/foo
> +4096+0 records in
> +4096+0 records out
> diff --git a/tests/btrfs/group b/tests/btrfs/group
> index 3295856d..f4dbfafb 100644
> --- a/tests/btrfs/group
> +++ b/tests/btrfs/group
> @@ -221,3 +221,4 @@
>  216 auto quick seed
>  217 auto quick trim dangerous
>  218 auto quick volume
> +219 auto quick
> -- 
> 2.26.2

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-13 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-09 12:25 [PATCH][v2] fstests: btrfs/219 add a test to test -o rescue=all Josef Bacik
2020-09-13 15:45 ` Eryu Guan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).