public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: dsterba@suse.cz, Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/3] btrfs: Do super block verification before writing it to disk
Date: Thu, 19 Apr 2018 18:32:33 +0800	[thread overview]
Message-ID: <454cdaee-d9ec-b427-f08d-aa0310ffe29a@gmx.com> (raw)
In-Reply-To: <20180419101651.GZ21272@twin.jikos.cz>


[-- Attachment #1.1: Type: text/plain, Size: 3871 bytes --]



On 2018年04月19日 18:16, David Sterba wrote:
> Looks good, some minor comments below. I'm wondering how to test that.

Currently I'm using the most stupid way to test it, insert code randomly
modifies super blocks.

> We'd have to inject either the corruption or to provide a way to
> forcibly fail the test. For the latter a debugfs should do, I'll send
> something for comments.

What about a sysfs interface to modify super blocks?
Since we already have sectorsize and nodessize, allow it to be writeable
for CONFIG_BTRFS_DEBUG looks pretty good.

Thanks,
Qu

> 
> On Thu, Apr 19, 2018 at 05:38:16PM +0800, Qu Wenruo wrote:
>> @@ -3563,6 +3565,12 @@ int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors)
>>  	sb = fs_info->super_for_commit;
>>  	dev_item = &sb->dev_item;
>>  
>> +	if (btrfs_check_super_valid(fs_info, sb, -1)) {
> 
> A comment that this is skipping the bytenr check would be good.
> 
>> +		btrfs_err(fs_info,
>> +		"superblock corruption detected before transaction commitment");
> 
>                                                                    commit
> 
> 
>> +		return -EUCLEAN;
>> +	}
>> +
>>  	mutex_lock(&fs_info->fs_devices->device_list_mutex);
>>  	head = &fs_info->fs_devices->devices;
>>  	max_errors = btrfs_super_num_devices(fs_info->super_copy) - 1;
>> @@ -3974,9 +3982,18 @@ int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid, int level,
>>  					      level, first_key);
>>  }
>>  
>> -static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info)
>> +/*
>> + * Check the validation of btrfs super block.
>> + *
>> + * @sb:			super block to check
>> + * @super_mirror:	the super block number to check its bytenr.
>> + * 			0 means the primary (1st) sb, 1 and 2 means 2nd and
>> + * 			3rd backup sb, while -1 means to skip bytenr check.
>> + */
>> +static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
>> +				   struct btrfs_super_block *sb,
>> +				   int super_mirror)
>>  {
>> -	struct btrfs_super_block *sb = fs_info->super_copy;
>>  	u64 nodesize = btrfs_super_nodesize(sb);
>>  	u64 sectorsize = btrfs_super_sectorsize(sb);
>>  	int ret = 0;
>> @@ -4019,7 +4036,7 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info)
>>  	 * Check sectorsize and nodesize first, other check will need it.
>>  	 * Check all possible sectorsize(4K, 8K, 16K, 32K, 64K) here.
>>  	 */
>> -	if (!is_power_of_2(sectorsize) || sectorsize < 4096 ||
>> +	if (!is_power_of_2(sectorsize) || sectorsize < SZ_4K ||
> 
> No unrelated changes please. There are some remaining raw values, send a
> separate patch if you want to convert them.
> 
>>  	    sectorsize > BTRFS_MAX_METADATA_BLOCKSIZE) {
>>  		btrfs_err(fs_info, "invalid sectorsize %llu", sectorsize);
>>  		ret = -EINVAL;
>> @@ -4088,9 +4105,10 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info)
>>  		ret = -EINVAL;
>>  	}
>>  
>> -	if (btrfs_super_bytenr(sb) != BTRFS_SUPER_INFO_OFFSET) {
>> -		btrfs_err(fs_info, "super offset mismatch %llu != %u",
>> -			  btrfs_super_bytenr(sb), BTRFS_SUPER_INFO_OFFSET);
>> +	if (super_mirror >= 0 && btrfs_super_bytenr(sb) !=
>> +	    btrfs_sb_offset(super_mirror)) {
>> +		btrfs_err(fs_info, "super offset mismatch %llu != %llu",
>> +			btrfs_super_bytenr(sb), btrfs_sb_offset(super_mirror));
>>  		ret = -EINVAL;
>>  	}
>>  
>> -- 
>> 2.17.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2018-04-19 10:32 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
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 [this message]
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=454cdaee-d9ec-b427-f08d-aa0310ffe29a@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=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