diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c index c1624ee1..d00ed98e 100644 --- a/btrfs-corrupt-block.c +++ b/btrfs-corrupt-block.c @@ -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); } diff --git a/check/main.c b/check/main.c index 235a9bab..9b8ead7b 100644 --- a/check/main.c +++ b/check/main.c @@ -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; diff --git a/check/mode-common.c b/check/mode-common.c index 0059672c..d28e79af 100644 --- a/check/mode-common.c +++ b/check/mode-common.c @@ -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); diff --git a/cmds/rescue-chunk-recover.c b/cmds/rescue-chunk-recover.c index 614ba2f9..2e27a47f 100644 --- a/cmds/rescue-chunk-recover.c +++ b/cmds/rescue-chunk-recover.c @@ -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; diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index e448464b..6c4e2e15 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -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 diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index 30f16f4d..e79f8b5a 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -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) diff --git a/kernel-shared/file-item.c b/kernel-shared/file-item.c index c910e27e..ecb8e5cd 100644 --- a/kernel-shared/file-item.c +++ b/kernel-shared/file-item.c @@ -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; diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index beda7865..c7748f15 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -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++) {