Commit 31fecccb authored by David Sterba's avatar David Sterba

btrfs: remove redundant csum buffer in btrfs_io_bio

The io_bio tracks checksums and has an inline buffer or an allocated
one. And there's a third member that points to the right one, but we
don't need to use an extra pointer for that. Let btrfs_io_bio::csum
point to the right buffer and check that the inline buffer is not
accidentally freed.

This shrinks struct btrfs_io_bio by 8 bytes.
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 600b6cf4
...@@ -144,7 +144,10 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, ...@@ -144,7 +144,10 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
static void btrfs_io_bio_endio_readpage(struct btrfs_io_bio *bio, int err) static void btrfs_io_bio_endio_readpage(struct btrfs_io_bio *bio, int err)
{ {
kfree(bio->csum_allocated); if (bio->csum != bio->csum_inline) {
kfree(bio->csum);
bio->csum = NULL;
}
} }
static blk_status_t __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, static blk_status_t __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
...@@ -175,13 +178,12 @@ static blk_status_t __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio ...@@ -175,13 +178,12 @@ static blk_status_t __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio
nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits; nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits;
if (!dst) { if (!dst) {
if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) { if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) {
btrfs_bio->csum_allocated = kmalloc_array(nblocks, btrfs_bio->csum = kmalloc_array(nblocks, csum_size,
csum_size, GFP_NOFS); GFP_NOFS);
if (!btrfs_bio->csum_allocated) { if (!btrfs_bio->csum) {
btrfs_free_path(path); btrfs_free_path(path);
return BLK_STS_RESOURCE; return BLK_STS_RESOURCE;
} }
btrfs_bio->csum = btrfs_bio->csum_allocated;
btrfs_bio->end_io = btrfs_io_bio_endio_readpage; btrfs_bio->end_io = btrfs_io_bio_endio_readpage;
} else { } else {
btrfs_bio->csum = btrfs_bio->csum_inline; btrfs_bio->csum = btrfs_bio->csum_inline;
......
...@@ -274,7 +274,6 @@ struct btrfs_io_bio { ...@@ -274,7 +274,6 @@ struct btrfs_io_bio {
u64 logical; u64 logical;
u8 *csum; u8 *csum;
u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE]; u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
u8 *csum_allocated;
btrfs_io_bio_end_io_t *end_io; btrfs_io_bio_end_io_t *end_io;
struct bvec_iter iter; struct bvec_iter iter;
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment