btrfs-progs: cache csum_size and csum_type in btrfs_fs_info

Just like kernel commit 22b6331d9617 ("btrfs: store precalculated
csum_size in fs_info"), we can cache csum_size and csum_type in
btrfs_fs_info.

Furthermore, there is already a 32 bits hole in btrfs_fs_info, and we
can fit csum_type and csum_size into the hole without increase the size
of btrfs_fs_info.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2021-10-21 09:40:20 +08:00 committed by David Sterba
parent 636b2e6027
commit c4ff87c3d1
8 changed files with 22 additions and 23 deletions

View File

@ -158,9 +158,9 @@ static void corrupt_keys(struct btrfs_trans_handle *trans,
}
btrfs_mark_buffer_dirty(eb);
if (!trans) {
u16 csum_size =
btrfs_super_csum_size(fs_info->super_copy);
u16 csum_type = btrfs_super_csum_type(fs_info->super_copy);
u16 csum_size = fs_info->csum_size;
u16 csum_type = fs_info->csum_type;
csum_tree_block_size(eb, csum_size, 0, csum_type);
write_extent_to_disk(eb);
}

View File

@ -5762,8 +5762,8 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
struct extent_buffer *eb)
{
u64 offset = 0;
u16 csum_size = btrfs_super_csum_size(gfs_info->super_copy);
u16 csum_type = btrfs_super_csum_type(gfs_info->super_copy);
u16 csum_size = gfs_info->csum_size;
u16 csum_type = gfs_info->csum_type;
u8 *data;
unsigned long csum_offset;
u8 result[BTRFS_CSUM_SIZE];
@ -5981,7 +5981,7 @@ static int check_csums(struct btrfs_root *root)
struct btrfs_key key;
u64 last_data_end = 0;
u64 offset = 0, num_bytes = 0;
u16 csum_size = btrfs_super_csum_size(gfs_info->super_copy);
u16 csum_size = gfs_info->csum_size;
int errors = 0;
int ret;
u64 data_len;

View File

@ -294,7 +294,7 @@ int count_csum_range(u64 start, u64 len, u64 *found)
size_t size;
*found = 0;
u64 csum_end;
u16 csum_size = btrfs_super_csum_size(gfs_info->super_copy);
u16 csum_size = gfs_info->csum_size;
btrfs_init_path(&path);

View File

@ -1812,7 +1812,7 @@ static int next_csum(struct btrfs_root *root,
struct btrfs_root *csum_root = root->fs_info->csum_root;
struct btrfs_csum_item *csum_item;
u32 blocksize = root->fs_info->sectorsize;
u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
u16 csum_size = root->fs_info->csum_size;
int csums_in_item = btrfs_item_size_nr(*leaf, *slot) / csum_size;
if (*csum_offset >= csums_in_item) {
@ -1896,7 +1896,7 @@ out:
static u64 item_end_offset(struct btrfs_root *root, struct btrfs_key *key,
struct extent_buffer *leaf, int slot) {
u32 blocksize = root->fs_info->sectorsize;
u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
u16 csum_size = root->fs_info->csum_size;
u64 offset = btrfs_item_size_nr(leaf, slot);
offset /= csum_size;

View File

@ -1235,6 +1235,8 @@ struct btrfs_fs_info {
u32 nodesize;
u32 sectorsize;
u32 stripesize;
u16 csum_type;
u16 csum_size;
/*
* Zone size > 0 when in ZONED mode, otherwise it's used for a check

View File

@ -209,8 +209,8 @@ int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size,
int csum_tree_block(struct btrfs_fs_info *fs_info,
struct extent_buffer *buf, int verify)
{
u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
u16 csum_type = btrfs_super_csum_type(fs_info->super_copy);
u16 csum_size = fs_info->csum_size;
u16 csum_type = fs_info->csum_type;
if (verify && fs_info->suppress_check_block_errors)
return verify_tree_block_csum_silent(buf, csum_size, csum_type);
@ -1297,6 +1297,8 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_flags *oc
fs_info->sectorsize = btrfs_super_sectorsize(disk_super);
fs_info->nodesize = btrfs_super_nodesize(disk_super);
fs_info->stripesize = btrfs_super_stripesize(disk_super);
fs_info->csum_type = btrfs_super_csum_type(disk_super);
fs_info->csum_size = btrfs_super_csum_size(disk_super);
ret = btrfs_check_fs_compatibility(fs_info->super_copy, flags);
if (ret)

View File

@ -142,8 +142,7 @@ btrfs_lookup_csum(struct btrfs_trans_handle *trans,
struct btrfs_csum_item *item;
struct extent_buffer *leaf;
u64 csum_offset = 0;
u16 csum_size =
btrfs_super_csum_size(root->fs_info->super_copy);
u16 csum_size = root->fs_info->csum_size;
int csums_in_item;
file_key.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
@ -199,11 +198,8 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
u32 sectorsize = root->fs_info->sectorsize;
u32 nritems;
u32 ins_size;
u16 csum_size =
btrfs_super_csum_size(root->fs_info->super_copy);
u16 csum_type =
btrfs_super_csum_type(root->fs_info->super_copy);
u16 csum_size = root->fs_info->csum_size;
u16 csum_type = root->fs_info->csum_type;
path = btrfs_alloc_path();
if (!path)
@ -341,8 +337,7 @@ static noinline int truncate_one_csum(struct btrfs_root *root,
u64 bytenr, u64 len)
{
struct extent_buffer *leaf;
u16 csum_size =
btrfs_super_csum_size(root->fs_info->super_copy);
u16 csum_size = root->fs_info->csum_size;
u64 csum_end;
u64 end_byte = bytenr + len;
u32 blocksize = root->fs_info->sectorsize;
@ -399,7 +394,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 bytenr, u64 len)
u64 csum_end;
struct extent_buffer *leaf;
int ret;
u16 csum_size = btrfs_super_csum_size(trans->fs_info->super_copy);
u16 csum_size = trans->fs_info->csum_size;
int blocksize = trans->fs_info->sectorsize;
struct btrfs_root *csum_root = trans->fs_info->csum_root;

View File

@ -1153,7 +1153,7 @@ static void print_extent_csum(struct extent_buffer *eb,
printf("\t\trange start %llu\n", (unsigned long long)offset);
return;
}
csum_size = btrfs_super_csum_size(fs_info->super_copy);
csum_size = fs_info->csum_size;
size = (item_size / csum_size) * fs_info->sectorsize;
printf("\t\trange start %llu end %llu length %u\n",
(unsigned long long)offset,
@ -1244,7 +1244,7 @@ static void print_header_info(struct extent_buffer *eb, unsigned int mode)
char *tmp = csum_str;
u8 *csum = (u8 *)(eb->data + offsetof(struct btrfs_header, csum));
csum_size = btrfs_super_csum_size(fs_info->super_copy);
csum_size = fs_info->csum_size;
strcpy(csum_str, " csum 0x");
tmp = csum_str + strlen(csum_str);
for (i = 0; i < csum_size; i++) {