Skip to content

Commit

Permalink
btrfs: rename struct btrfs_io_bio to btrfs_bio
Browse files Browse the repository at this point in the history
Previously we had "struct btrfs_bio", which records IO context for
mirrored IO and RAID56, and "strcut btrfs_io_bio", which records extra
btrfs specific info for logical bytenr bio.

With "btrfs_bio" renamed to "btrfs_io_context", we are safe to rename
"btrfs_io_bio" to "btrfs_bio" which is a more suitable name now.

The struct btrfs_bio changes meaning by this commit. There was a
suggested name like btrfs_logical_bio but it's a bit long and we'd
prefer to use a shorter name.

This could be a concern for backports to older kernels where the
different meaning could possibly cause confusion or bugs. Comparing the
new and old structures, there's no overlap among the struct members so a
build would break in case of incorrect backport.

We haven't had many backports to bio code anyway so this is more of a
theoretical cause of bugs and a matter of precaution but we'll need to
keep the semantic change in mind.

Signed-off-by: Qu Wenruo <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
adam900710 authored and kdave committed Oct 4, 2021
1 parent dfe17f2 commit 0b31649
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 106 deletions.
2 changes: 1 addition & 1 deletion fs/btrfs/check-integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ static int btrfsic_read_block(struct btrfsic_state *state,
struct bio *bio;
unsigned int j;

bio = btrfs_io_bio_alloc(num_pages - i);
bio = btrfs_bio_alloc(num_pages - i);
bio_set_dev(bio, block_ctx->dev->bdev);
bio->bi_iter.bi_sector = dev_bytenr >> 9;
bio->bi_opf = REQ_OP_READ;
Expand Down
16 changes: 8 additions & 8 deletions fs/btrfs/compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ static int check_compressed_csum(struct btrfs_inode *inode, struct bio *bio,
if (memcmp(&csum, cb_sum, csum_size) != 0) {
btrfs_print_data_csum_error(inode, disk_start,
csum, cb_sum, cb->mirror_num);
if (btrfs_io_bio(bio)->device)
if (btrfs_bio(bio)->device)
btrfs_dev_stat_inc_and_print(
btrfs_io_bio(bio)->device,
btrfs_bio(bio)->device,
BTRFS_DEV_STAT_CORRUPTION_ERRS);
return -EIO;
}
Expand All @@ -208,7 +208,7 @@ static void end_compressed_bio_read(struct bio *bio)
struct inode *inode;
struct page *page;
unsigned int index;
unsigned int mirror = btrfs_io_bio(bio)->mirror_num;
unsigned int mirror = btrfs_bio(bio)->mirror_num;
int ret = 0;

if (bio->bi_status)
Expand All @@ -224,7 +224,7 @@ static void end_compressed_bio_read(struct bio *bio)
* Record the correct mirror_num in cb->orig_bio so that
* read-repair can work properly.
*/
btrfs_io_bio(cb->orig_bio)->mirror_num = mirror;
btrfs_bio(cb->orig_bio)->mirror_num = mirror;
cb->mirror_num = mirror;

/*
Expand Down Expand Up @@ -418,7 +418,7 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
cb->orig_bio = NULL;
cb->nr_pages = nr_pages;

bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
bio = btrfs_bio_alloc(BIO_MAX_VECS);
bio->bi_iter.bi_sector = first_byte >> SECTOR_SHIFT;
bio->bi_opf = bio_op | write_flags;
bio->bi_private = cb;
Expand Down Expand Up @@ -491,7 +491,7 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
bio_endio(bio);
}

bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
bio = btrfs_bio_alloc(BIO_MAX_VECS);
bio->bi_iter.bi_sector = first_byte >> SECTOR_SHIFT;
bio->bi_opf = bio_op | write_flags;
bio->bi_private = cb;
Expand Down Expand Up @@ -750,7 +750,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
/* include any pages we added in add_ra-bio_pages */
cb->len = bio->bi_iter.bi_size;

comp_bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
comp_bio = btrfs_bio_alloc(BIO_MAX_VECS);
comp_bio->bi_iter.bi_sector = cur_disk_byte >> SECTOR_SHIFT;
comp_bio->bi_opf = REQ_OP_READ;
comp_bio->bi_private = cb;
Expand Down Expand Up @@ -809,7 +809,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
bio_endio(comp_bio);
}

comp_bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
comp_bio = btrfs_bio_alloc(BIO_MAX_VECS);
comp_bio->bi_iter.bi_sector = cur_disk_byte >> SECTOR_SHIFT;
comp_bio->bi_opf = REQ_OP_READ;
comp_bio->bi_private = cb;
Expand Down
6 changes: 4 additions & 2 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern struct kmem_cache *btrfs_free_space_cachep;
extern struct kmem_cache *btrfs_free_space_bitmap_cachep;
struct btrfs_ordered_sum;
struct btrfs_ref;
struct btrfs_bio;

#define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */

Expand Down Expand Up @@ -3140,8 +3141,9 @@ u64 btrfs_file_extent_end(const struct btrfs_path *path);
/* inode.c */
blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
int mirror_num, unsigned long bio_flags);
unsigned int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u32 bio_offset,
struct page *page, u64 start, u64 end);
unsigned int btrfs_verify_data_csum(struct btrfs_bio *bbio,
u32 bio_offset, struct page *page,
u64 start, u64 end);
struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode,
u64 start, u64 len);
noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ static int validate_subpage_buffer(struct page *page, u64 start, u64 end,
return ret;
}

int btrfs_validate_metadata_buffer(struct btrfs_io_bio *io_bio,
int btrfs_validate_metadata_buffer(struct btrfs_bio *bbio,
struct page *page, u64 start, u64 end,
int mirror)
{
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/disk-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info);
void btrfs_btree_balance_dirty_nodelay(struct btrfs_fs_info *fs_info);
void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
struct btrfs_root *root);
int btrfs_validate_metadata_buffer(struct btrfs_io_bio *io_bio,
int btrfs_validate_metadata_buffer(struct btrfs_bio *bbio,
struct page *page, u64 start, u64 end,
int mirror);
blk_status_t btrfs_submit_metadata_bio(struct inode *inode, struct bio *bio,
Expand Down
64 changes: 32 additions & 32 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ int __init extent_io_init(void)
return -ENOMEM;

if (bioset_init(&btrfs_bioset, BIO_POOL_SIZE,
offsetof(struct btrfs_io_bio, bio),
offsetof(struct btrfs_bio, bio),
BIOSET_NEED_BVECS))
goto free_buffer_cache;

Expand Down Expand Up @@ -2299,7 +2299,7 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
if (btrfs_is_zoned(fs_info))
return btrfs_repair_one_zone(fs_info, logical);

bio = btrfs_io_bio_alloc(1);
bio = btrfs_bio_alloc(1);
bio->bi_iter.bi_size = 0;
map_length = length;

Expand Down Expand Up @@ -2618,10 +2618,10 @@ int btrfs_repair_one_sector(struct inode *inode,
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
struct extent_io_tree *failure_tree = &BTRFS_I(inode)->io_failure_tree;
struct btrfs_io_bio *failed_io_bio = btrfs_io_bio(failed_bio);
struct btrfs_bio *failed_bbio = btrfs_bio(failed_bio);
const int icsum = bio_offset >> fs_info->sectorsize_bits;
struct bio *repair_bio;
struct btrfs_io_bio *repair_io_bio;
struct btrfs_bio *repair_bbio;
blk_status_t status;

btrfs_debug(fs_info,
Expand All @@ -2639,24 +2639,24 @@ int btrfs_repair_one_sector(struct inode *inode,
return -EIO;
}

repair_bio = btrfs_io_bio_alloc(1);
repair_io_bio = btrfs_io_bio(repair_bio);
repair_bio = btrfs_bio_alloc(1);
repair_bbio = btrfs_bio(repair_bio);
repair_bio->bi_opf = REQ_OP_READ;
repair_bio->bi_end_io = failed_bio->bi_end_io;
repair_bio->bi_iter.bi_sector = failrec->logical >> 9;
repair_bio->bi_private = failed_bio->bi_private;

if (failed_io_bio->csum) {
if (failed_bbio->csum) {
const u32 csum_size = fs_info->csum_size;

repair_io_bio->csum = repair_io_bio->csum_inline;
memcpy(repair_io_bio->csum,
failed_io_bio->csum + csum_size * icsum, csum_size);
repair_bbio->csum = repair_bbio->csum_inline;
memcpy(repair_bbio->csum,
failed_bbio->csum + csum_size * icsum, csum_size);
}

bio_add_page(repair_bio, page, failrec->len, pgoff);
repair_io_bio->logical = failrec->start;
repair_io_bio->iter = repair_bio->bi_iter;
repair_bbio->logical = failrec->start;
repair_bbio->iter = repair_bio->bi_iter;

btrfs_debug(btrfs_sb(inode->i_sb),
"repair read error: submitting new read to mirror %d",
Expand Down Expand Up @@ -2976,7 +2976,7 @@ static struct extent_buffer *find_extent_buffer_readpage(
static void end_bio_extent_readpage(struct bio *bio)
{
struct bio_vec *bvec;
struct btrfs_io_bio *io_bio = btrfs_io_bio(bio);
struct btrfs_bio *bbio = btrfs_bio(bio);
struct extent_io_tree *tree, *failure_tree;
struct processed_extent processed = { 0 };
/*
Expand All @@ -3003,7 +3003,7 @@ static void end_bio_extent_readpage(struct bio *bio)
btrfs_debug(fs_info,
"end_bio_extent_readpage: bi_sector=%llu, err=%d, mirror=%u",
bio->bi_iter.bi_sector, bio->bi_status,
io_bio->mirror_num);
bbio->mirror_num);
tree = &BTRFS_I(inode)->io_tree;
failure_tree = &BTRFS_I(inode)->io_failure_tree;

Expand All @@ -3028,14 +3028,14 @@ static void end_bio_extent_readpage(struct bio *bio)
end = start + bvec->bv_len - 1;
len = bvec->bv_len;

mirror = io_bio->mirror_num;
mirror = bbio->mirror_num;
if (likely(uptodate)) {
if (is_data_inode(inode)) {
error_bitmap = btrfs_verify_data_csum(io_bio,
error_bitmap = btrfs_verify_data_csum(bbio,
bio_offset, page, start, end);
ret = error_bitmap;
} else {
ret = btrfs_validate_metadata_buffer(io_bio,
ret = btrfs_validate_metadata_buffer(bbio,
page, start, end, mirror);
}
if (ret)
Expand Down Expand Up @@ -3106,7 +3106,7 @@ static void end_bio_extent_readpage(struct bio *bio)
}
/* Release the last extent */
endio_readpage_release_extent(&processed, NULL, 0, 0, false);
btrfs_io_bio_free_csum(io_bio);
btrfs_bio_free_csum(bbio);
bio_put(bio);
}

Expand All @@ -3115,55 +3115,55 @@ static void end_bio_extent_readpage(struct bio *bio)
* new bio by bio_alloc_bioset as it does not initialize the bytes outside of
* 'bio' because use of __GFP_ZERO is not supported.
*/
static inline void btrfs_io_bio_init(struct btrfs_io_bio *btrfs_bio)
static inline void btrfs_bio_init(struct btrfs_bio *bbio)
{
memset(btrfs_bio, 0, offsetof(struct btrfs_io_bio, bio));
memset(bbio, 0, offsetof(struct btrfs_bio, bio));
}

/*
* Allocate a btrfs_io_bio, with @nr_iovecs as maximum number of iovecs.
*
* The bio allocation is backed by bioset and does not fail.
*/
struct bio *btrfs_io_bio_alloc(unsigned int nr_iovecs)
struct bio *btrfs_bio_alloc(unsigned int nr_iovecs)
{
struct bio *bio;

ASSERT(0 < nr_iovecs && nr_iovecs <= BIO_MAX_VECS);
bio = bio_alloc_bioset(GFP_NOFS, nr_iovecs, &btrfs_bioset);
btrfs_io_bio_init(btrfs_io_bio(bio));
btrfs_bio_init(btrfs_bio(bio));
return bio;
}

struct bio *btrfs_bio_clone(struct bio *bio)
{
struct btrfs_io_bio *btrfs_bio;
struct btrfs_bio *bbio;
struct bio *new;

/* Bio allocation backed by a bioset does not fail */
new = bio_clone_fast(bio, GFP_NOFS, &btrfs_bioset);
btrfs_bio = btrfs_io_bio(new);
btrfs_io_bio_init(btrfs_bio);
btrfs_bio->iter = bio->bi_iter;
bbio = btrfs_bio(new);
btrfs_bio_init(bbio);
bbio->iter = bio->bi_iter;
return new;
}

struct bio *btrfs_bio_clone_partial(struct bio *orig, u64 offset, u64 size)
{
struct bio *bio;
struct btrfs_io_bio *btrfs_bio;
struct btrfs_bio *bbio;

ASSERT(offset <= UINT_MAX && size <= UINT_MAX);

/* this will never fail when it's backed by a bioset */
bio = bio_clone_fast(orig, GFP_NOFS, &btrfs_bioset);
ASSERT(bio);

btrfs_bio = btrfs_io_bio(bio);
btrfs_io_bio_init(btrfs_bio);
bbio = btrfs_bio(bio);
btrfs_bio_init(bbio);

bio_trim(bio, offset >> 9, size >> 9);
btrfs_bio->iter = bio->bi_iter;
bbio->iter = bio->bi_iter;
return bio;
}

Expand Down Expand Up @@ -3297,7 +3297,7 @@ static int alloc_new_bio(struct btrfs_inode *inode,
struct bio *bio;
int ret;

bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
bio = btrfs_bio_alloc(BIO_MAX_VECS);
/*
* For compressed page range, its disk_bytenr is always @disk_bytenr
* passed in, no matter if we have added any range into previous bio.
Expand Down Expand Up @@ -3332,7 +3332,7 @@ static int alloc_new_bio(struct btrfs_inode *inode,
goto error;
}

btrfs_io_bio(bio)->device = device;
btrfs_bio(bio)->device = device;
}
return 0;
error:
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/extent_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end);
void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
struct page *locked_page,
u32 bits_to_clear, unsigned long page_ops);
struct bio *btrfs_io_bio_alloc(unsigned int nr_iovecs);
struct bio *btrfs_bio_alloc(unsigned int nr_iovecs);
struct bio *btrfs_bio_clone(struct bio *bio);
struct bio *btrfs_bio_clone_partial(struct bio *orig, u64 offset, u64 size);

Expand Down
13 changes: 6 additions & 7 deletions fs/btrfs/file-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ static int search_file_offset_in_bio(struct bio *bio, struct inode *inode,
* @dst: Buffer of size nblocks * btrfs_super_csum_size() used to return
* checksum (nblocks = bio->bi_iter.bi_size / fs_info->sectorsize). If
* NULL, the checksum buffer is allocated and returned in
* btrfs_io_bio(bio)->csum instead.
* btrfs_bio(bio)->csum instead.
*
* Return: BLK_STS_RESOURCE if allocating memory fails, BLK_STS_OK otherwise.
*/
Expand Down Expand Up @@ -397,19 +397,18 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst
return BLK_STS_RESOURCE;

if (!dst) {
struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
struct btrfs_bio *bbio = btrfs_bio(bio);

if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) {
btrfs_bio->csum = kmalloc_array(nblocks, csum_size,
GFP_NOFS);
if (!btrfs_bio->csum) {
bbio->csum = kmalloc_array(nblocks, csum_size, GFP_NOFS);
if (!bbio->csum) {
btrfs_free_path(path);
return BLK_STS_RESOURCE;
}
} else {
btrfs_bio->csum = btrfs_bio->csum_inline;
bbio->csum = bbio->csum_inline;
}
csum = btrfs_bio->csum;
csum = bbio->csum;
} else {
csum = dst;
}
Expand Down
Loading

0 comments on commit 0b31649

Please sign in to comment.