linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eryu Guan <guan@eryu.me>
To: Josef Bacik <josef@toxicpanda.com>
Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com, fstests@vger.kernel.org
Subject: Re: [PATCH][v2] fstests: btrfs/219 add a test to test -o rescue=all
Date: Sun, 13 Sep 2020 23:45:36 +0800	[thread overview]
Message-ID: <20200913154536.GJ3853@desktop> (raw)
In-Reply-To: <36b3a0eafee6f43d489bf8fcfe5a1ac13a9f896a.1599654294.git.josef@toxicpanda.com>

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

      reply	other threads:[~2020-09-13 15:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=20200913154536.GJ3853@desktop \
    --to=guan@eryu.me \
    --cc=fstests@vger.kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.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;
as well as URLs for NNTP newsgroup(s).