linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Su Yue <suy.fnst@cn.fujitsu.com>
To: Qu Wenruo <wqu@suse.com>, <linux-btrfs@vger.kernel.org>,
	Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: <dsterba@suse.cz>
Subject: Re: [PATCH 1/4] btrfs-progs: check: Check data csum for all copies
Date: Tue, 27 Feb 2018 18:01:19 +0800	[thread overview]
Message-ID: <241a459e-048b-e872-0e99-dc6263c9a6dd@cn.fujitsu.com> (raw)
In-Reply-To: <20180227091259.10877-2-wqu@suse.com>



On 02/27/2018 05:12 PM, Qu Wenruo wrote:
> Original --check-data-csum option will skip the extra copy if the first
> copy matches csum.
> 
> Since offline scrub (with recoverability report) is still out-of-tree, at
> least enhance --check-data-csum option to handle multiple copies.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>   check/main.c | 65 ++++++++++++++++++++++++++++++------------------------------
>   1 file changed, 32 insertions(+), 33 deletions(-)
> 
> diff --git a/check/main.c b/check/main.c
> index 97baae583f04..f25fdc765d63 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -5381,42 +5381,37 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
>   	if (!data)
>   		return -ENOMEM;
>   
> +	num_copies = btrfs_num_copies(root->fs_info, bytenr, num_bytes);
>   	while (offset < num_bytes) {
> -		mirror = 0;
> -again:
> -		read_len = num_bytes - offset;
> -		/* read as much space once a time */
> -		ret = read_extent_data(fs_info, data + offset,
> -				bytenr + offset, &read_len, mirror);
> -		if (ret)
> -			goto out;
> -		data_checked = 0;
> -		/* verify every 4k data's checksum */
> -		while (data_checked < read_len) {
> -			csum = ~(u32)0;
> -			tmp = offset + data_checked;
> -
> -			csum = btrfs_csum_data((char *)data + tmp,
> -					       csum, fs_info->sectorsize);
> -			btrfs_csum_final(csum, (u8 *)&csum);
> -
> -			csum_offset = leaf_offset +
> -				 tmp / fs_info->sectorsize * csum_size;
> -			read_extent_buffer(eb, (char *)&csum_expected,
> -					   csum_offset, csum_size);
> -			/* try another mirror */
> -			if (csum != csum_expected) {
> -				fprintf(stderr, "mirror %d bytenr %llu csum %u expected csum %u\n",
> +		for (mirror = 1; mirror <= num_copies; mirror++) {

Got your point.
But what confuses me is that why mirror starts from 1 here.
The mirror influences btrfs_map_block() which is not related
to this patch though.

Thanks,
Su
> +			read_len = num_bytes - offset;
> +			/* read as much space once a time */
> +			ret = read_extent_data(fs_info, data + offset,
> +					bytenr + offset, &read_len, mirror);
> +			if (ret)
> +				goto out;
> +
> +			data_checked = 0;
> +			/* verify every 4k data's checksum */
> +			while (data_checked < read_len) {
> +				csum = ~(u32)0;
> +				tmp = offset + data_checked;
> +
> +				csum = btrfs_csum_data((char *)data + tmp,
> +						csum, fs_info->sectorsize);
> +				btrfs_csum_final(csum, (u8 *)&csum);
> +
> +				csum_offset = leaf_offset +
> +					 tmp / fs_info->sectorsize * csum_size;
> +				read_extent_buffer(eb, (char *)&csum_expected,
> +						   csum_offset, csum_size);
> +				if (csum != csum_expected)
> +					fprintf(stderr,
> +			"mirror %d bytenr %llu csum %u expected csum %u\n",
>   						mirror, bytenr + tmp,
>   						csum, csum_expected);
> -				num_copies = btrfs_num_copies(root->fs_info,
> -						bytenr, num_bytes);
> -				if (mirror < num_copies - 1) {
> -					mirror += 1;
> -					goto again;
> -				}
> +				data_checked += fs_info->sectorsize;
>   			}
> -			data_checked += fs_info->sectorsize;
>   		}
>   		offset += read_len;
>   	}
> @@ -5624,7 +5619,11 @@ static int check_csums(struct btrfs_root *root)
>   		leaf_offset = btrfs_item_ptr_offset(leaf, path.slots[0]);
>   		ret = check_extent_csums(root, key.offset, data_len,
>   					 leaf_offset, leaf);
> -		if (ret)
> +		/*
> +		 * Only break for fatal errors, if mismatch is found,
> +		 * continue checking until all extents are checked.
> +		 */
> +		if (ret < 0)
>   			break;
>   skip_csum_check:
>   		if (!num_bytes) {
> 



  reply	other threads:[~2018-02-27  9:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-27  9:12 [PATCH 0/4] btrfs check --check-data-csum enhancement for Qu Wenruo
2018-02-27  9:12 ` [PATCH 1/4] btrfs-progs: check: Check data csum for all copies Qu Wenruo
2018-02-27 10:01   ` Su Yue [this message]
2018-02-27 10:31     ` Qu Wenruo
2018-02-27 11:09       ` Nikolay Borisov
2018-02-27 11:21         ` Qu Wenruo
2018-02-28  1:10       ` Su Yue
2018-02-27  9:12 ` [PATCH 2/4] btrfs-progs: check: Fix data csum check return value Qu Wenruo
2018-02-27  9:12 ` [PATCH 3/4] btrfs-progs: check: Continue check even csum error is found Qu Wenruo
2018-02-27  9:12 ` [PATCH 4/4] btrfs-progs: check: Distingusih csum checking output for --check-data-csum Qu Wenruo
2018-05-07 18:34 ` [PATCH 0/4] btrfs check --check-data-csum enhancement for David Sterba
2018-05-28 12:20 ` Qu Wenruo
2018-05-28 13:14   ` David Sterba

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=241a459e-048b-e872-0e99-dc6263c9a6dd@cn.fujitsu.com \
    --to=suy.fnst@cn.fujitsu.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.com \
    --cc=wqu@suse.com \
    /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).