Skip to content

Commit cd8e0cc

Browse files
adam900710kdave
authored andcommitted
btrfs: remove btrfs_bio_alloc() helper
The helper btrfs_bio_alloc() is almost the same as btrfs_io_bio_alloc(), except it's allocating using BIO_MAX_VECS as @nr_iovecs, and initializes bio->bi_iter.bi_sector. However the naming itself is not using "btrfs_io_bio" to indicate its parameter is "strcut btrfs_io_bio" and can be easily confused with "struct btrfs_bio". Considering assigned bio->bi_iter.bi_sector is such a simple work and there are already tons of call sites doing that manually, there is no need to do that in a helper. Remove btrfs_bio_alloc() helper, and enhance btrfs_io_bio_alloc() function to provide a fail-safe value for its @nr_iovecs. And then replace all btrfs_bio_alloc() callers with btrfs_io_bio_alloc(). Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 4c66461 commit cd8e0cc

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

fs/btrfs/compression.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
418418
cb->orig_bio = NULL;
419419
cb->nr_pages = nr_pages;
420420

421-
bio = btrfs_bio_alloc(first_byte);
421+
bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
422+
bio->bi_iter.bi_sector = first_byte >> SECTOR_SHIFT;
422423
bio->bi_opf = bio_op | write_flags;
423424
bio->bi_private = cb;
424425
bio->bi_end_io = end_compressed_bio_write;
@@ -490,7 +491,8 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
490491
bio_endio(bio);
491492
}
492493

493-
bio = btrfs_bio_alloc(first_byte);
494+
bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
495+
bio->bi_iter.bi_sector = first_byte >> SECTOR_SHIFT;
494496
bio->bi_opf = bio_op | write_flags;
495497
bio->bi_private = cb;
496498
bio->bi_end_io = end_compressed_bio_write;
@@ -748,7 +750,8 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
748750
/* include any pages we added in add_ra-bio_pages */
749751
cb->len = bio->bi_iter.bi_size;
750752

751-
comp_bio = btrfs_bio_alloc(cur_disk_byte);
753+
comp_bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
754+
comp_bio->bi_iter.bi_sector = cur_disk_byte >> SECTOR_SHIFT;
752755
comp_bio->bi_opf = REQ_OP_READ;
753756
comp_bio->bi_private = cb;
754757
comp_bio->bi_end_io = end_compressed_bio_read;
@@ -806,7 +809,8 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
806809
bio_endio(comp_bio);
807810
}
808811

809-
comp_bio = btrfs_bio_alloc(cur_disk_byte);
812+
comp_bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
813+
comp_bio->bi_iter.bi_sector = cur_disk_byte >> SECTOR_SHIFT;
810814
comp_bio->bi_opf = REQ_OP_READ;
811815
comp_bio->bi_private = cb;
812816
comp_bio->bi_end_io = end_compressed_bio_read;

fs/btrfs/extent_io.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,16 +3121,16 @@ static inline void btrfs_io_bio_init(struct btrfs_io_bio *btrfs_bio)
31213121
}
31223122

31233123
/*
3124-
* The following helpers allocate a bio. As it's backed by a bioset, it'll
3125-
* never fail. We're returning a bio right now but you can call btrfs_io_bio
3126-
* for the appropriate container_of magic
3124+
* Allocate a btrfs_io_bio, with @nr_iovecs as maximum number of iovecs.
3125+
*
3126+
* The bio allocation is backed by bioset and does not fail.
31273127
*/
3128-
struct bio *btrfs_bio_alloc(u64 first_byte)
3128+
struct bio *btrfs_io_bio_alloc(unsigned int nr_iovecs)
31293129
{
31303130
struct bio *bio;
31313131

3132-
bio = bio_alloc_bioset(GFP_NOFS, BIO_MAX_VECS, &btrfs_bioset);
3133-
bio->bi_iter.bi_sector = first_byte >> 9;
3132+
ASSERT(0 < nr_iovecs && nr_iovecs <= BIO_MAX_VECS);
3133+
bio = bio_alloc_bioset(GFP_NOFS, nr_iovecs, &btrfs_bioset);
31343134
btrfs_io_bio_init(btrfs_io_bio(bio));
31353135
return bio;
31363136
}
@@ -3148,16 +3148,6 @@ struct bio *btrfs_bio_clone(struct bio *bio)
31483148
return new;
31493149
}
31503150

3151-
struct bio *btrfs_io_bio_alloc(unsigned int nr_iovecs)
3152-
{
3153-
struct bio *bio;
3154-
3155-
/* Bio allocation backed by a bioset does not fail */
3156-
bio = bio_alloc_bioset(GFP_NOFS, nr_iovecs, &btrfs_bioset);
3157-
btrfs_io_bio_init(btrfs_io_bio(bio));
3158-
return bio;
3159-
}
3160-
31613151
struct bio *btrfs_bio_clone_partial(struct bio *orig, u64 offset, u64 size)
31623152
{
31633153
struct bio *bio;
@@ -3307,14 +3297,15 @@ static int alloc_new_bio(struct btrfs_inode *inode,
33073297
struct bio *bio;
33083298
int ret;
33093299

3300+
bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
33103301
/*
33113302
* For compressed page range, its disk_bytenr is always @disk_bytenr
33123303
* passed in, no matter if we have added any range into previous bio.
33133304
*/
33143305
if (bio_flags & EXTENT_BIO_COMPRESSED)
3315-
bio = btrfs_bio_alloc(disk_bytenr);
3306+
bio->bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT;
33163307
else
3317-
bio = btrfs_bio_alloc(disk_bytenr + offset);
3308+
bio->bi_iter.bi_sector = (disk_bytenr + offset) >> SECTOR_SHIFT;
33183309
bio_ctrl->bio = bio;
33193310
bio_ctrl->bio_flags = bio_flags;
33203311
bio->bi_end_io = end_io_func;

fs/btrfs/extent_io.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end);
278278
void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
279279
struct page *locked_page,
280280
u32 bits_to_clear, unsigned long page_ops);
281-
struct bio *btrfs_bio_alloc(u64 first_byte);
282281
struct bio *btrfs_io_bio_alloc(unsigned int nr_iovecs);
283282
struct bio *btrfs_bio_clone(struct bio *bio);
284283
struct bio *btrfs_bio_clone_partial(struct bio *orig, u64 offset, u64 size);

fs/btrfs/scrub.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,7 +2225,7 @@ static void scrub_missing_raid56_pages(struct scrub_block *sblock)
22252225
goto bioc_out;
22262226
}
22272227

2228-
bio = btrfs_io_bio_alloc(0);
2228+
bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
22292229
bio->bi_iter.bi_sector = logical >> 9;
22302230
bio->bi_private = sblock;
22312231
bio->bi_end_io = scrub_missing_raid56_end_io;
@@ -2841,7 +2841,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
28412841
if (ret || !bioc || !bioc->raid_map)
28422842
goto bioc_out;
28432843

2844-
bio = btrfs_io_bio_alloc(0);
2844+
bio = btrfs_io_bio_alloc(BIO_MAX_VECS);
28452845
bio->bi_iter.bi_sector = sparity->logic_start >> 9;
28462846
bio->bi_private = sparity;
28472847
bio->bi_end_io = scrub_parity_bio_endio;

0 commit comments

Comments
 (0)