public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/3] btrfs: Add csum type check for btrfs_check_super_valid()
Date: Thu, 19 Apr 2018 12:09:31 +0200	[thread overview]
Message-ID: <20180419100931.GY21272@twin.jikos.cz> (raw)
In-Reply-To: <20180419093816.888-2-wqu@suse.com>

On Thu, Apr 19, 2018 at 05:38:15PM +0800, Qu Wenruo wrote:
> Just like incompat flags check, although we have already done super csum
> type check before calling btrfs_check_super_valid(), we can still add
> such check for later write time check.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  fs/btrfs/disk-io.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index ec123158f051..b189ec086bc2 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -3981,6 +3981,15 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info)
>  	u64 sectorsize = btrfs_super_sectorsize(sb);
>  	int ret = 0;
>  
> +	/*
> +	 * For write time check, as for mount time we have checked csum before
> +	 * calling btrfs_check_super_valid(), so it must be a corruption
> +	 */
> +	if (btrfs_super_csum_type(sb) >= ARRAY_SIZE(btrfs_csum_sizes)) {
> +		btrfs_err(fs_info, "corrupted csum type %u",
> +			  btrfs_super_csum_type(sb));
> +		ret = -EINVAL;
> +	}
>  	if (btrfs_super_magic(sb) != BTRFS_MAGIC) {

The test for magic should be IMO the first one, that's how the
filesystem type is identified before anything else. Granted that the
magic must be correct before it can be even mounted, but the code should
follow that logic too. Otherwise ok.

  reply	other threads:[~2018-04-19 10:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-19  9:38 [PATCH 1/3] btrfs: Add incompat flags check for btrfs_check_super_valid() Qu Wenruo
2018-04-19  9:38 ` [PATCH 2/3] btrfs: Add csum type " Qu Wenruo
2018-04-19 10:09   ` David Sterba [this message]
2018-04-19 10:24     ` Qu Wenruo
2018-04-19  9:38 ` [PATCH 3/3] btrfs: Do super block verification before writing it to disk Qu Wenruo
2018-04-19 10:16   ` David Sterba
2018-04-19 10:32     ` Qu Wenruo
2018-04-20 14:46   ` Anand Jain
2018-04-19 10:59 ` [PATCH 1/3] btrfs: Add incompat flags check for btrfs_check_super_valid() Nikolay Borisov
2018-04-19 11:10   ` Qu Wenruo
2018-04-19 15:31     ` David Sterba
2018-04-19 16:24       ` Nikolay Borisov
2018-04-20 13:04         ` David Sterba
2018-04-20 14:32 ` Anand Jain
2018-04-20 15:15   ` David Sterba
2018-04-21  2:38     ` Anand Jain
2018-04-21  2:43       ` Qu Wenruo
2018-04-21  5:18         ` Anand Jain

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=20180419100931.GY21272@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --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