btrfs: initialize fs_info::csum_size earlier in open_ctree

User reported that btrfs-progs misc-tests/028-superblock-recover fails:

[TEST/misc] 028-superblock-recover
unexpected success: mounted fs with corrupted superblock
test failed for case 028-superblock-recover

The test case expects that a broken image with bad superblock will be
rejected to be mounted. However, the test image just passed csum check
of superblock and was successfully mounted.

Commit 55fc29bed8dd ("btrfs: use cached value of fs_info::csum_size
everywhere") replaces all calls to btrfs_super_csum_size by
fs_info::csum_size. The calls include the place where fs_info->csum_size
is not initialized. So btrfs_check_super_csum() passes because memcmp()
with len 0 always returns 0.

Fix it by caching csum size in btrfs_fs_info::csum_size once we know the
csum type in superblock is valid in open_ctree().

Link: https://github.com/kdave/btrfs-progs/issues/250
Fixes: 55fc29bed8dd ("btrfs: use cached value of fs_info::csum_size everywhere")
Signed-off-by: Su Yue <l@damenly.su>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by Su Yue and committed by David Sterba 83c68bbc 9ad6d91f

Changed files
+2 -1
fs
btrfs
+2 -1
fs/btrfs/disk-io.c
··· 3044 3044 goto fail_alloc; 3045 3045 } 3046 3046 3047 + fs_info->csum_size = btrfs_super_csum_size(disk_super); 3048 + 3047 3049 ret = btrfs_init_csum_hash(fs_info, csum_type); 3048 3050 if (ret) { 3049 3051 err = ret; ··· 3163 3161 fs_info->nodesize = nodesize; 3164 3162 fs_info->sectorsize = sectorsize; 3165 3163 fs_info->sectorsize_bits = ilog2(sectorsize); 3166 - fs_info->csum_size = btrfs_super_csum_size(disk_super); 3167 3164 fs_info->csums_per_leaf = BTRFS_MAX_ITEM_SIZE(fs_info) / fs_info->csum_size; 3168 3165 fs_info->stripesize = stripesize; 3169 3166