btrfs: Simplify btrfs_check_super_csum() and get rid of size assumptions
Now that we have already checked for a valid checksum type before calling btrfs_check_super_csum(), it can be simplified even further. While at it get rid of the implicit size assumption of the resulting checksum as well. This is a preparation for changing all checksum functionality to use the crypto layer later. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
committed by
David Sterba
parent
8dc3f22c8b
commit
51bce6c9b9
@@ -371,30 +371,20 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
|
|||||||
{
|
{
|
||||||
struct btrfs_super_block *disk_sb =
|
struct btrfs_super_block *disk_sb =
|
||||||
(struct btrfs_super_block *)raw_disk_sb;
|
(struct btrfs_super_block *)raw_disk_sb;
|
||||||
u16 csum_type = btrfs_super_csum_type(disk_sb);
|
u32 crc = ~(u32)0;
|
||||||
|
char result[BTRFS_CSUM_SIZE];
|
||||||
|
|
||||||
if (!btrfs_supported_super_csum(csum_type)) {
|
/*
|
||||||
btrfs_err(fs_info, "unsupported checksum algorithm %u",
|
* The super_block structure does not span the whole
|
||||||
csum_type);
|
* BTRFS_SUPER_INFO_SIZE range, we expect that the unused space is
|
||||||
|
* filled with zeros and is included in the checksum.
|
||||||
|
*/
|
||||||
|
crc = btrfs_csum_data(raw_disk_sb + BTRFS_CSUM_SIZE,
|
||||||
|
crc, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
||||||
|
btrfs_csum_final(crc, result);
|
||||||
|
|
||||||
|
if (memcmp(disk_sb->csum, result, btrfs_super_csum_size(disk_sb)))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
if (csum_type == BTRFS_CSUM_TYPE_CRC32) {
|
|
||||||
u32 crc = ~(u32)0;
|
|
||||||
char result[sizeof(crc)];
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The super_block structure does not span the whole
|
|
||||||
* BTRFS_SUPER_INFO_SIZE range, we expect that the unused space
|
|
||||||
* is filled with zeros and is included in the checksum.
|
|
||||||
*/
|
|
||||||
crc = btrfs_csum_data(raw_disk_sb + BTRFS_CSUM_SIZE,
|
|
||||||
crc, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
|
||||||
btrfs_csum_final(crc, result);
|
|
||||||
|
|
||||||
if (memcmp(raw_disk_sb, result, sizeof(result)))
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -2611,6 +2601,7 @@ int open_ctree(struct super_block *sb,
|
|||||||
u32 stripesize;
|
u32 stripesize;
|
||||||
u64 generation;
|
u64 generation;
|
||||||
u64 features;
|
u64 features;
|
||||||
|
u16 csum_type;
|
||||||
struct btrfs_key location;
|
struct btrfs_key location;
|
||||||
struct buffer_head *bh;
|
struct buffer_head *bh;
|
||||||
struct btrfs_super_block *disk_super;
|
struct btrfs_super_block *disk_super;
|
||||||
@@ -2820,11 +2811,10 @@ int open_ctree(struct super_block *sb,
|
|||||||
* Verify the type first, if that or the the checksum value are
|
* Verify the type first, if that or the the checksum value are
|
||||||
* corrupted, we'll find out
|
* corrupted, we'll find out
|
||||||
*/
|
*/
|
||||||
if (!btrfs_supported_super_csum(btrfs_super_csum_type(
|
csum_type = btrfs_super_csum_type((struct btrfs_super_block *)bh->b_data);
|
||||||
(struct btrfs_super_block *) bh->b_data))) {
|
if (!btrfs_supported_super_csum(csum_type)) {
|
||||||
btrfs_err(fs_info, "unsupported checksum algorithm: %u",
|
btrfs_err(fs_info, "unsupported checksum algorithm: %u",
|
||||||
btrfs_super_csum_type((struct btrfs_super_block *)
|
csum_type);
|
||||||
bh->b_data));
|
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
brelse(bh);
|
brelse(bh);
|
||||||
goto fail_alloc;
|
goto fail_alloc;
|
||||||
|
|||||||
Reference in New Issue
Block a user