btrfs-progs: pass in fs_info to btrfs_csum_data

For passing authentication keys to the checksumming functions we need a
container for the key.

Pass in a btrfs_fs_info to btrfs_csum_data() so we can use the fs_info
as a container for the authentication key.

Note this is not always possible for all callers of btrfs_csum_data() so
we're just passing in NULL for now

Functions calling btrfs_csum_data() with a NULL fs_info argument are
currently not supported in the context of an authenticated file system.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Johannes Thumshirn 2021-02-18 01:38:08 +01:00 committed by David Sterba
parent 6bb6d1215d
commit 94b60b67a9
8 changed files with 17 additions and 15 deletions

View File

@ -36,7 +36,7 @@ static int check_csum_superblock(void *sb)
u8 result[BTRFS_CSUM_SIZE];
u16 csum_type = btrfs_super_csum_type(sb);
btrfs_csum_data(csum_type, (unsigned char *)sb + BTRFS_CSUM_SIZE,
btrfs_csum_data(NULL, csum_type, (unsigned char *)sb + BTRFS_CSUM_SIZE,
result, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
return !memcmp(sb, result, csum_size);
@ -48,7 +48,7 @@ static void update_block_csum(void *block)
struct btrfs_header *hdr;
u16 csum_type = btrfs_super_csum_type(block);
btrfs_csum_data(csum_type, (unsigned char *)block + BTRFS_CSUM_SIZE,
btrfs_csum_data(NULL, csum_type, (unsigned char *)block + BTRFS_CSUM_SIZE,
result, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
memset(block, 0, BTRFS_CSUM_SIZE);

View File

@ -5759,7 +5759,7 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
while (data_checked < read_len) {
tmp = offset + data_checked;
btrfs_csum_data(csum_type, data + tmp,
btrfs_csum_data(gfs_info, csum_type, data + tmp,
result, gfs_info->sectorsize);
csum_offset = leaf_offset +

View File

@ -1911,7 +1911,7 @@ static int check_one_csum(int fd, u64 start, u32 len, u32 tree_csum,
}
ret = 0;
put_unaligned_le32(tree_csum, expected_csum);
btrfs_csum_data(csum_type, (u8 *)data, result, len);
btrfs_csum_data(NULL, csum_type, (u8 *)data, result, len);
if (memcmp(result, expected_csum, csum_size) != 0)
ret = 1;
out:

View File

@ -66,7 +66,7 @@ static inline int write_temp_super(int fd, struct btrfs_super_block *sb,
u16 csum_type = btrfs_super_csum_type(sb);
int ret;
btrfs_csum_data(csum_type, (u8 *)sb + BTRFS_CSUM_SIZE,
btrfs_csum_data(NULL, csum_type, (u8 *)sb + BTRFS_CSUM_SIZE,
result, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
memcpy(&sb->csum[0], result, BTRFS_CSUM_SIZE);
ret = pwrite(fd, sb, BTRFS_SUPER_INFO_SIZE, sb_bytenr);

View File

@ -139,7 +139,8 @@ static void print_tree_block_error(struct btrfs_fs_info *fs_info,
}
}
int btrfs_csum_data(u16 csum_type, const u8 *data, u8 *out, size_t len)
int btrfs_csum_data(struct btrfs_fs_info *fs_info, u16 csum_type, const u8 *data,
u8 *out, size_t len)
{
memset(out, 0, BTRFS_CSUM_SIZE);
@ -181,7 +182,7 @@ static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
u32 len;
len = buf->len - BTRFS_CSUM_SIZE;
btrfs_csum_data(csum_type, (u8 *)buf->data + BTRFS_CSUM_SIZE,
btrfs_csum_data(buf->fs_info, csum_type, (u8 *)buf->data + BTRFS_CSUM_SIZE,
result, len);
if (verify) {
@ -1437,7 +1438,7 @@ int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags)
}
csum_size = btrfs_super_csum_size(sb);
btrfs_csum_data(csum_type, (u8 *)sb + BTRFS_CSUM_SIZE,
btrfs_csum_data(NULL, csum_type, (u8 *)sb + BTRFS_CSUM_SIZE,
result, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
if (memcmp(result, sb->csum, csum_size)) {
@ -1691,8 +1692,8 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info,
}
if (fs_info->super_bytenr != BTRFS_SUPER_INFO_OFFSET) {
btrfs_set_super_bytenr(sb, fs_info->super_bytenr);
btrfs_csum_data(csum_type, (u8 *)sb + BTRFS_CSUM_SIZE, result,
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
btrfs_csum_data(fs_info, csum_type, (u8 *)sb + BTRFS_CSUM_SIZE,
result, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
memcpy(&sb->csum[0], result, BTRFS_CSUM_SIZE);
/*
@ -1726,8 +1727,8 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info,
btrfs_set_super_bytenr(sb, bytenr);
btrfs_csum_data(csum_type, (u8 *)sb + BTRFS_CSUM_SIZE, result,
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
btrfs_csum_data(fs_info, csum_type, (u8 *)sb + BTRFS_CSUM_SIZE,
result, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
memcpy(&sb->csum[0], result, BTRFS_CSUM_SIZE);
/*

View File

@ -194,7 +194,8 @@ int btrfs_free_fs_root(struct btrfs_root *root);
void btrfs_mark_buffer_dirty(struct extent_buffer *buf);
int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid);
int btrfs_set_buffer_uptodate(struct extent_buffer *buf);
int btrfs_csum_data(u16 csum_type, const u8 *data, u8 *out, size_t len);
int btrfs_csum_data(struct btrfs_fs_info *fs_info, u16 csum_type, const u8 *data,
u8 *out, size_t len);
int btrfs_open_device(struct btrfs_device *dev);
int csum_tree_block_size(struct extent_buffer *buf, u16 csum_sectorsize,

View File

@ -315,7 +315,7 @@ csum:
item = (struct btrfs_csum_item *)((unsigned char *)item +
csum_offset * csum_size);
found:
btrfs_csum_data(csum_type, (u8 *)data, csum_result, len);
btrfs_csum_data(root->fs_info, csum_type, (u8 *)data, csum_result, len);
/* FIXME: does not make sense for non-crc32c */
if (csum_result == 0) {
printk("csum result is 0 for block %llu\n",

View File

@ -1577,7 +1577,7 @@ static int check_csum_sblock(void *sb, int csum_size, u16 csum_type)
{
u8 result[BTRFS_CSUM_SIZE];
btrfs_csum_data(csum_type, (u8 *)sb + BTRFS_CSUM_SIZE,
btrfs_csum_data(NULL, csum_type, (u8 *)sb + BTRFS_CSUM_SIZE,
result, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
return !memcmp(sb, result, csum_size);