btrfs: btrfs_bio and btrfs_io_bio rename
cover btrfs: btrfs_bio and btrfs_io_bio rename
The branch can be fetched from github, and is the preferred way to grab the code, as this patchset changed quite a lot of code.
https://github.com/adam900710/linux/tree/chunk_refactor
There are two structure, btrfs_io_bio and btrfs_bio, which have very similar names but completely different meanings.
Btrfs_io_bio mostly works at logical bytenr layer (its bio->bi_iter.bi_sector points to btrfs logical bytenr), and just contains extra info like csum and mirror_num.
While btrfs_io_bio acts more like a phyical mapping, mapping logical bytenr to real devices.
Such naming is completely anti-human.
So this patchset will rename btrfs_io_bio to btrfs_logical_bio and rename btrfs_bio to btrfs_physical_bio.
This acts as the first step towards chunk layer code refactor, the ultimate goals include:
- Move bio split code into chunk layer
Currently btrfs_map_bio() requires the bio passed in not to cross stripe boundaries.
Thus it requires submit_extent_page() to do bio splitting.
In fact higher layer code shouldn't bother that at all, chunk layer code should do the bio splitting.
- Hide btrfs_physical_bio
In fact for certain types, like SINGLE it doesn't need complex btrfs_physical_bio, and can do its IO just remapping the existing bio.
In fact, each chunk type should have their own bio mapping and physical bio tracing code.
They can share some common infrastructure, but definitely not exporting the whole btrfs_physical_bio as a core structure.
- Create fs/btrfs/raid/*.[ch] for each chunk type
Some chunk mapping can definitely share some code, but we definitely don't want to put all chunk mapping code into volumes.[ch]/scrub.[ch].
- Provide better exported chunk layer interface. Can't we just use bytenr + mirror_num to handle most things?
For device map code, we never bother whatever the underlying layer is.
If we can unify the interface to bare minimal, we can really separate the chunk mapping code from higher layer code.
Although I'm not that optimistic since we still have scrub to bother.
Qu Wenruo (3):
btrfs: rename btrfs_io_bio_alloc() to btrfs_bio_alloc_iovecs()
btrfs: rename struct btrfs_io_bio to struct btrfs_logical_bio
btrfs: rename struct btrfs_bio to btrfs_physical_bio
fs/btrfs/check-integrity.c | 4 +- fs/btrfs/compression.c | 16 +-- fs/btrfs/ctree.h | 5 +- fs/btrfs/disk-io.c | 2 +- fs/btrfs/disk-io.h | 2 +- fs/btrfs/extent-tree.c | 14 +- fs/btrfs/extent_io.c | 96 +++++++------- fs/btrfs/extent_io.h | 11 +- fs/btrfs/file-item.c | 12 +- fs/btrfs/inode.c | 57 ++++---- fs/btrfs/raid56.c | 126 +++++++++--------- fs/btrfs/raid56.h | 8 +- fs/btrfs/reada.c | 26 ++-- fs/btrfs/scrub.c | 130 +++++++++--------- fs/btrfs/volumes.c | 263 +++++++++++++++++++------------------ fs/btrfs/volumes.h | 67 +++++++--- fs/btrfs/zoned.c | 16 +-- 17 files changed, 446 insertions(+), 409 deletions(-)
Signature · 1 line
2.33.0
PATCH 1/3 btrfs: rename btrfs_io_bio_alloc() to btrfs_bio_alloc_iovecs()
Function btrfs_io_bio_alloc() is pretty similar to btrfs_bio_alloc(), the only major difference is the number of iovecs, and whether bi_sector is initialized.
Thus there is no need to add the extra "_io", which is only going to cause confusion.
Rename it to btrfs_bio_alloc_iovecs() to be easier to read.
--- fs/btrfs/check-integrity.c | 2 +- fs/btrfs/extent_io.c | 6 +++--- fs/btrfs/extent_io.h | 2 +- fs/btrfs/raid56.c | 2 +- fs/btrfs/scrub.c | 14 +++++++------- 5 files changed, 13 insertions(+), 13 deletions(-)
fs/btrfs/check-integrity.c +1 -1
@@ -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_iovecs (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 ;
fs/btrfs/extent_io.c +3 -3
@@ -2299,7 +2299,7 @@ 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_iovecs (1 ); bio->bi_iter.bi_size =0 ; map_length = length;
@@ -2639,7 +2639,7 @@ int btrfs_repair_one_sector(struct inode *inode,return -EIO ; } - repair_bio =btrfs_io_bio_alloc (1 ); + repair_bio =btrfs_bio_alloc_iovecs (1 ); repair_io_bio =btrfs_io_bio (repair_bio); repair_bio->bi_opf =REQ_OP_READ ; repair_bio->bi_end_io = failed_bio->bi_end_io;
@@ -3148,7 +3148,7 @@ struct bio *btrfs_bio_clone(struct bio *bio)return new; } -struct bio *btrfs_io_bio_alloc (unsigned int nr_iovecs) +struct bio *btrfs_bio_alloc_iovecs (unsigned int nr_iovecs) {struct bio *bio;
fs/btrfs/extent_io.h +1 -1
@@ -279,7 +279,7 @@ 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_bio_alloc (u64 first_byte); -struct bio *btrfs_io_bio_alloc (unsigned int nr_iovecs); +struct bio *btrfs_bio_alloc_iovecs (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);
fs/btrfs/raid56.c +1 -1
@@ -1105,7 +1105,7 @@ static int rbio_add_io_page(struct btrfs_raid_bio *rbio, }/* put a new bio on the list */ - bio =btrfs_io_bio_alloc (bio_max_len >>PAGE_SHIFT ?:1 ); + bio =btrfs_bio_alloc_iovecs (bio_max_len >>PAGE_SHIFT ?:1 );btrfs_io_bio (bio)->device = stripe->dev; bio->bi_iter.bi_size =0 ;bio_set_dev (bio, stripe->dev->bdev);
fs/btrfs/scrub.c +7 -7
@@ -1423,7 +1423,7 @@ static void scrub_recheck_block_on_raid56(struct btrfs_fs_info *fs_info,if (!first_page->dev->bdev) goto out; - bio =btrfs_io_bio_alloc (BIO_MAX_VECS ); + bio =btrfs_bio_alloc_iovecs (BIO_MAX_VECS );bio_set_dev (bio, first_page->dev->bdev);for (page_num =0 ; page_num < sblock->page_count; page_num++) {
@@ -1480,7 +1480,7 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info, }WARN_ON (!spage->page); - bio =btrfs_io_bio_alloc (1 ); + bio =btrfs_bio_alloc_iovecs (1 );bio_set_dev (bio, spage->dev->bdev);bio_add_page (bio, spage->page, fs_info->sectorsize,0 );
@@ -1562,7 +1562,7 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,return -EIO ; } - bio =btrfs_io_bio_alloc (1 ); + bio =btrfs_bio_alloc_iovecs (1 );bio_set_dev (bio, spage_bad->dev->bdev); bio->bi_iter.bi_sector = spage_bad->physical >>9 ; bio->bi_opf =REQ_OP_WRITE ;
@@ -1676,7 +1676,7 @@ static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx, sbio->dev = sctx->wr_tgtdev; bio = sbio->bio;if (!bio) { - bio =btrfs_io_bio_alloc (sctx->pages_per_wr_bio); + bio =btrfs_bio_alloc_iovecs (sctx->pages_per_wr_bio); sbio->bio = bio; }
@@ -2102,7 +2102,7 @@ static int scrub_add_page_to_rd_bio(struct scrub_ctx *sctx, sbio->dev = spage->dev; bio = sbio->bio;if (!bio) { - bio =btrfs_io_bio_alloc (sctx->pages_per_rd_bio); + bio =btrfs_bio_alloc_iovecs (sctx->pages_per_rd_bio); sbio->bio = bio; }
@@ -2226,7 +2226,7 @@ static void scrub_missing_raid56_pages(struct scrub_block *sblock) goto bbio_out; } - bio =btrfs_io_bio_alloc (0 ); + bio =btrfs_bio_alloc_iovecs (0 ); bio->bi_iter.bi_sector = logical >>9 ; bio->bi_private = sblock; bio->bi_end_io = scrub_missing_raid56_end_io;
@@ -2842,7 +2842,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)if (ret || !bbio || !bbio->raid_map) goto bbio_out; - bio =btrfs_io_bio_alloc (0 ); + bio =btrfs_bio_alloc_iovecs (0 ); bio->bi_iter.bi_sector = sparity->logic_start >>9 ; bio->bi_private = sparity; bio->bi_end_io = scrub_parity_bio_endio;
Signature · 1 line
2.33.0
Re: [PATCH 1/3] btrfs: rename btrfs_io_bio_alloc() to btrfs_bio_alloc_iovecs()
Quoted 8 lines · Qu Wenruo
Function
btrfs_io_bio_alloc()is pretty similar tobtrfs_bio_alloc(), the only major difference is the number of iovecs, and whetherbi_sectoris initialized.Thus there is no need to add the extra "
_io", which is only going to cause confusion.Rename it to
btrfs_bio_alloc_iovecs()to be easier to read.
The only difference between those 2 function is the fact that the latter sets bio->bi_iter.bi_sector. So I'd say those should be turned into 1 function which takes the vecs as parameter as well as the bi_sector.
I've checked all callers of io_bio_alloc and we always have the sector when allocating the bio. And this can simply be renamed to btrfs_bio_alloc and be done with it.
<snip>
PATCH 2/3 btrfs: rename struct btrfs_io_bio to struct btrfs_logical_bio
In reply to Qu WenruoIn btrfs there are at least 4 types of different bios currently:
- btrfs_io_bio
It's used to specify IO for logical bytenr
- btrfs_bio
It's real physical bio
- compressed_bio
Only used for compressed read write.
- btrfs_raid_bio
Only used by RAID56
The naming of btrfs_bio and btrfs_io_bio is just anti-human.
Rename btrfs_io_bio to btrfs_logical_bio, and all involved helpers to make clear at which layer the bio works.
Since we're here, also add extra comments on critical members like @mirror_num.
--- fs/btrfs/check-integrity.c | 2 +- fs/btrfs/compression.c | 16 ++++---- fs/btrfs/ctree.h | 5 ++- fs/btrfs/disk-io.c | 2 +- fs/btrfs/disk-io.h | 2 +- fs/btrfs/extent_io.c | 78 +++++++++++++++++++------------------- fs/btrfs/extent_io.h | 11 +++--- fs/btrfs/file-item.c | 12 +++--- fs/btrfs/inode.c | 57 +++++++++++++++------------- fs/btrfs/raid56.c | 8 ++-- fs/btrfs/scrub.c | 14 +++---- fs/btrfs/volumes.c | 11 +++--- fs/btrfs/volumes.h | 54 ++++++++++++++++++-------- 13 files changed, 153 insertions(+), 119 deletions(-)
fs/btrfs/check-integrity.c +1 -1
@@ -1561,7 +1561,7 @@ static int btrfsic_read_block(struct btrfsic_state *state,struct bio *bio;unsigned int j; - bio =btrfs_bio_alloc_iovecs (num_pages - i); + bio =btrfs_logical_bio_alloc_iovecs (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 ;
fs/btrfs/compression.c +8 -8
@@ -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_logical_bio (bio)->device)btrfs_dev_stat_inc_and_print ( -btrfs_io_bio (bio)->device, +btrfs_logical_bio (bio)->device,BTRFS_DEV_STAT_CORRUPTION_ERRS );return -EIO ; }
@@ -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_logical_bio (bio)->mirror_num;int ret =0 ;if (bio->bi_status)
@@ -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_logical_bio (cb->orig_bio)->mirror_num = mirror; cb->mirror_num = mirror;/*
@@ -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_bio_alloc (first_byte); + bio =btrfs_logical_bio_alloc (first_byte); bio->bi_opf = bio_op | write_flags; bio->bi_private = cb; bio->bi_end_io = end_compressed_bio_write;
@@ -490,7 +490,7 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,bio_endio (bio); } - bio =btrfs_bio_alloc (first_byte); + bio =btrfs_logical_bio_alloc (first_byte); bio->bi_opf = bio_op | write_flags; bio->bi_private = cb; bio->bi_end_io = end_compressed_bio_write;
@@ -748,7 +748,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_bio_alloc (cur_disk_byte); + comp_bio =btrfs_logical_bio_alloc (cur_disk_byte); comp_bio->bi_opf =REQ_OP_READ ; comp_bio->bi_private = cb; comp_bio->bi_end_io = end_compressed_bio_read;
@@ -806,7 +806,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,bio_endio (comp_bio); } - comp_bio =btrfs_bio_alloc (cur_disk_byte); + comp_bio =btrfs_logical_bio_alloc (cur_disk_byte); comp_bio->bi_opf =REQ_OP_READ ; comp_bio->bi_private = cb; comp_bio->bi_end_io = end_compressed_bio_read;
fs/btrfs/ctree.h +3 -2
@@ -3133,8 +3133,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_logical_bio *logical_bio, +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,
fs/btrfs/disk-io.c +1 -1
@@ -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_logical_bio *logical_bio,struct page *page,u64 start,u64 end,int mirror) {
fs/btrfs/disk-io.h +1 -1
@@ -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_logical_bio *logical_bio,struct page *page,u64 start,u64 end,int mirror); blk_status_t btrfs_submit_metadata_bio(struct inode *inode, struct bio *bio,
fs/btrfs/extent_io.c +40 -38
203 lines not on this page · raw message
fs/btrfs/extent_io.h +6 -5
@@ -66,7 +66,7 @@ enum {struct btrfs_root ;struct btrfs_inode ; -struct btrfs_io_bio ; +struct btrfs_logical_bio ;struct btrfs_fs_info ;struct io_failure_record ;struct extent_io_tree ;
@@ -278,10 +278,11 @@ 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_bio_alloc (u64 first_byte); -struct bio *btrfs_bio_alloc_iovecs (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); +struct bio *btrfs_logical_bio_alloc (u64 first_byte); +struct bio *btrfs_logical_bio_alloc_iovecs (unsigned int nr_iovecs); +struct bio *btrfs_logical_bio_clone (struct bio *bio); +struct bio *btrfs_logical_bio_clone_partial (struct bio *orig,u64 offset, +u64 size); int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, u64 length, u64 logical, struct page *page,
fs/btrfs/file-item.c +6 -6
@@ -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_logical_bio(bio)->csum instead. * * Return: BLK_STS_RESOURCE if allocating memory fails, BLK_STS_OK otherwise. */
@@ -397,19 +397,19 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dstreturn BLK_STS_RESOURCE ;if (!dst) { -struct btrfs_io_bio *btrfs_bio =btrfs_io_bio (bio); +struct btrfs_logical_bio *logical_bio =btrfs_logical_bio (bio);if (nblocks * csum_size >BTRFS_BIO_INLINE_CSUM_SIZE ) { - btrfs_bio->csum =kmalloc_array (nblocks, csum_size, + logical_bio->csum =kmalloc_array (nblocks, csum_size,GFP_NOFS ); -if (!btrfs_bio->csum) { +if (!logical_bio->csum) {btrfs_free_path (path);return BLK_STS_RESOURCE ; } }else { - btrfs_bio->csum = btrfs_bio->csum_inline; + logical_bio->csum = logical_bio->csum_inline; } - csum = btrfs_bio->csum; + csum = logical_bio->csum; }else { csum = dst; }
fs/btrfs/inode.c +31 -26
147 lines not on this page · raw message
fs/btrfs/raid56.c +4 -4
@@ -1105,8 +1105,8 @@ static int rbio_add_io_page(struct btrfs_raid_bio *rbio, }/* put a new bio on the list */ - bio =btrfs_bio_alloc_iovecs (bio_max_len >>PAGE_SHIFT ?:1 ); -btrfs_io_bio (bio)->device = stripe->dev; + bio =btrfs_logical_bio_alloc_iovecs (bio_max_len >>PAGE_SHIFT ?:1 ); +btrfs_logical_bio (bio)->device = stripe->dev; bio->bi_iter.bi_size =0 ;bio_set_dev (bio, stripe->dev->bdev); bio->bi_iter.bi_sector = disk_start >>9 ;
@@ -1159,7 +1159,7 @@ static void index_rbio_pages(struct btrfs_raid_bio *rbio) page_index = stripe_offset >>PAGE_SHIFT ;if (bio_flagged (bio,BIO_CLONED )) - bio->bi_iter =btrfs_io_bio (bio)->iter; + bio->bi_iter =btrfs_logical_bio (bio)->iter;bio_for_each_segment (bvec, bio, iter) { rbio->bio_pages[page_index + i] = bvec.bv_page;
@@ -2125,7 +2125,7 @@ int raid56_parity_recover(struct btrfs_fs_info *fs_info, struct bio *bio,if (generic_io) {ASSERT (bbio->mirror_num == mirror_num); -btrfs_io_bio (bio)->mirror_num = mirror_num; +btrfs_logical_bio (bio)->mirror_num = mirror_num; } rbio =alloc_rbio (fs_info, bbio, stripe_len);
fs/btrfs/scrub.c +7 -7
@@ -1423,7 +1423,7 @@ static void scrub_recheck_block_on_raid56(struct btrfs_fs_info *fs_info,if (!first_page->dev->bdev) goto out; - bio =btrfs_bio_alloc_iovecs (BIO_MAX_VECS ); + bio =btrfs_logical_bio_alloc_iovecs (BIO_MAX_VECS );bio_set_dev (bio, first_page->dev->bdev);for (page_num =0 ; page_num < sblock->page_count; page_num++) {
@@ -1480,7 +1480,7 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info, }WARN_ON (!spage->page); - bio =btrfs_bio_alloc_iovecs (1 ); + bio =btrfs_logical_bio_alloc_iovecs (1 );bio_set_dev (bio, spage->dev->bdev);bio_add_page (bio, spage->page, fs_info->sectorsize,0 );
@@ -1562,7 +1562,7 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,return -EIO ; } - bio =btrfs_bio_alloc_iovecs (1 ); + bio =btrfs_logical_bio_alloc_iovecs (1 );bio_set_dev (bio, spage_bad->dev->bdev); bio->bi_iter.bi_sector = spage_bad->physical >>9 ; bio->bi_opf =REQ_OP_WRITE ;
@@ -1676,7 +1676,7 @@ static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx, sbio->dev = sctx->wr_tgtdev; bio = sbio->bio;if (!bio) { - bio =btrfs_bio_alloc_iovecs (sctx->pages_per_wr_bio); + bio =btrfs_logical_bio_alloc_iovecs (sctx->pages_per_wr_bio); sbio->bio = bio; }
@@ -2102,7 +2102,7 @@ static int scrub_add_page_to_rd_bio(struct scrub_ctx *sctx, sbio->dev = spage->dev; bio = sbio->bio;if (!bio) { - bio =btrfs_bio_alloc_iovecs (sctx->pages_per_rd_bio); + bio =btrfs_logical_bio_alloc_iovecs (sctx->pages_per_rd_bio); sbio->bio = bio; }
@@ -2226,7 +2226,7 @@ static void scrub_missing_raid56_pages(struct scrub_block *sblock) goto bbio_out; } - bio =btrfs_bio_alloc_iovecs (0 ); + bio =btrfs_logical_bio_alloc_iovecs (0 ); bio->bi_iter.bi_sector = logical >>9 ; bio->bi_private = sblock; bio->bi_end_io = scrub_missing_raid56_end_io;
@@ -2842,7 +2842,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)if (ret || !bbio || !bbio->raid_map) goto bbio_out; - bio =btrfs_bio_alloc_iovecs (0 ); + bio =btrfs_logical_bio_alloc_iovecs (0 ); bio->bi_iter.bi_sector = sparity->logic_start >>9 ; bio->bi_private = sparity; bio->bi_end_io = scrub_parity_bio_endio;
fs/btrfs/volumes.c +6 -5
@@ -6554,7 +6554,8 @@ static void btrfs_end_bio(struct bio *bio)atomic_inc (&bbio->error);if (bio->bi_status ==BLK_STS_IOERR || bio->bi_status ==BLK_STS_TARGET ) { -struct btrfs_device *dev =btrfs_io_bio (bio)->device; +struct btrfs_device *dev = +btrfs_logical_bio (bio)->device;ASSERT (dev->bdev);if (btrfs_op (bio) ==BTRFS_MAP_WRITE )
@@ -6580,7 +6581,7 @@ static void btrfs_end_bio(struct bio *bio) bio = bbio->orig_bio; } -btrfs_io_bio (bio)->mirror_num = bbio->mirror_num; +btrfs_logical_bio (bio)->mirror_num = bbio->mirror_num;/* only send an error to the higher layers if it is * beyond the tolerance of the btrfs bio */
@@ -6606,7 +6607,7 @@ static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio,struct btrfs_fs_info *fs_info = bbio->fs_info; bio->bi_private = bbio; -btrfs_io_bio (bio)->device = dev; +btrfs_logical_bio (bio)->device = dev; bio->bi_end_io = btrfs_end_bio; bio->bi_iter.bi_sector = physical >>9 ;/*
@@ -6642,7 +6643,7 @@ static void bbio_error(struct btrfs_bio *bbio, struct bio *bio, u64 logical)/* Should be the original bio. */ WARN_ON (bio != bbio->orig_bio); -btrfs_io_bio (bio)->mirror_num = bbio->mirror_num; +btrfs_logical_bio (bio)->mirror_num = bbio->mirror_num; bio->bi_iter.bi_sector = logical >>9 ;if (atomic_read (&bbio->error) > bbio->max_errors) bio->bi_status =BLK_STS_IOERR ;
@@ -6717,7 +6718,7 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio, }if (dev_nr < total_devs -1 ) - bio =btrfs_bio_clone (first_bio); + bio =btrfs_logical_bio_clone (first_bio);else bio = first_bio;
fs/btrfs/volumes.h +39 -15
77 lines not on this page · raw message
Signature · 1 line
2.33.0
Re: [PATCH 2/3] btrfs: rename struct btrfs_io_bio to struct btrfs_logical_bio
Quoted 4 lines · Qu Wenruo
In btrfs there are at least 4 types of different bios currently:
-
btrfs_io_bio
It's used to specify IO for logical bytenr
Perhaps this structure needs to be turned into a btrfs_bio.
Quoted 3 lines
-
btrfs_bio
It's real physical bio
It's not even that, because btrfs_bio itself is not submitted at all, it's really some sort of a semaphore, which is used to signal all stripe bios i.e those bios which are submitted to the actual devices have completed. In that regard it's not even a bio per-se, more like an io_context.
Quoted 3 lines
-
compressed_bio
Only used for compressed read write.
This should be compressed_io_ctx or some such.
Quoted 13 lines
-
btrfs_raid_bio
Only used by RAID56The naming of
btrfs_bioandbtrfs_io_biois just anti-human.Rename
btrfs_io_biotobtrfs_logical_bio, and all involved helpers to make clear at which layer the bio works.Since we're here, also add extra comments on critical members like @mirror_num.
Signed-off-by Qu Wenruo <[email protected]>
<snip>
Re: [PATCH 2/3] btrfs: rename struct btrfs_io_bio to struct btrfs_logical_bio
Quoted 9 lines · Nikolay Borisov
Quoted 4 lines · Qu Wenruo
In btrfs there are at least 4 types of different bios currently:
-
btrfs_io_bio
It's used to specify IO for logical bytenrPerhaps this structure needs to be turned into a
btrfs_bio.
That makes sense, although I still want to keep the logical part to indicate what the bytenr is for.
Quoted 10 lines
Quoted 4 lines
-
btrfs_bio
It's real physical bioIt's not even that, because
btrfs_bioitself is not submitted at all, it's really some sort of a semaphore, which is used to signal all stripe bios i.e those bios which are submitted to the actual devices have completed. In that regard it's not even a bio per-se, more like anio_context.
Yep, although there is still some use-case where it integrate the logical bio into it, thus it still has bio in it.
Or maybe we should separate the mapping part completely from the bio?
Thanks,
Qu
Quoted 23 lines
Quoted 4 lines
-
compressed_bio
Only used for compressed read write.This should be
compressed_io_ctxor some such.Quoted 13 lines
-
btrfs_raid_bio
Only used by RAID56The naming of
btrfs_bioandbtrfs_io_biois just anti-human.Rename
btrfs_io_biotobtrfs_logical_bio, and all involved helpers to make clear at which layer the bio works.Since we're here, also add extra comments on critical members like @mirror_num.
Signed-off-by Qu Wenruo <[email protected]><snip>
PATCH 3/3 btrfs: rename struct btrfs_bio to btrfs_physical_bio
In reply to Qu WenruoThe structure btrfs_bio records extra mapping info for scrub/raid56 and real bio submission to each device.
The naming btrfs_bio itself makes no sense, and can be easily confused with btrfs_io_bio (now renamed to btrfs_logical_bio).
So this patch will rename btrfs_bio to btrfs_physical_bio, and use pbio to replace bbio for various call sites.
--- fs/btrfs/check-integrity.c | 2 +- fs/btrfs/extent-tree.c | 14 +- fs/btrfs/extent_io.c | 18 +-- fs/btrfs/raid56.c | 118 ++++++++--------- fs/btrfs/raid56.h | 8 +- fs/btrfs/reada.c | 26 ++-- fs/btrfs/scrub.c | 116 ++++++++--------- fs/btrfs/volumes.c | 256 ++++++++++++++++++------------------- fs/btrfs/volumes.h | 13 +- fs/btrfs/zoned.c | 16 +-- 10 files changed, 295 insertions(+), 292 deletions(-)
fs/btrfs/check-integrity.c +1 -1
@@ -1455,7 +1455,7 @@ static int btrfsic_map_block(struct btrfsic_state *state, u64 bytenr, u32 len,struct btrfs_fs_info *fs_info = state->fs_info;int ret;u64 length; -struct btrfs_bio *multi =NULL ; +struct btrfs_physical_bio *multi =NULL ;struct btrfs_device *device; length = len;
fs/btrfs/extent-tree.c +7 -7
@@ -1313,11 +1313,11 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,u64 discarded_bytes =0 ;u64 end = bytenr + num_bytes;u64 cur = bytenr; -struct btrfs_bio *bbio =NULL ; +struct btrfs_physical_bio *pbio =NULL ;/* -* Avoid races with device replace and make sure our bbio has devices +* Avoid races with device replace and make sure our pbio has devices * associated to its stripes that don't go away while we are discarding. */ btrfs_bio_counter_inc_blocked (fs_info);
@@ -1328,7 +1328,7 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, num_bytes = end - cur;/* Tell the block device(s) that the sectors can be discarded */ ret =btrfs_map_block (fs_info,BTRFS_MAP_DISCARD , cur, - &num_bytes, &bbio,0 ); + &num_bytes, &pbio,0 );/* * Error can be -ENOMEM, -ENOENT (no such chunk mapping) or * -EOPNOTSUPP. For any such error, @num_bytes is not updated,
@@ -1337,8 +1337,8 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,if (ret <0 ) goto out; - stripe = bbio->stripes; -for (i =0 ; i < bbio->num_stripes; i++, stripe++) { + stripe = pbio->stripes; +for (i =0 ; i < pbio->num_stripes; i++, stripe++) {u64 bytes;struct btrfs_device *device = stripe->dev;
@@ -1361,7 +1361,7 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,* And since there are two loops, explicitly * go to out to avoid confusion. */ -btrfs_put_bbio (bbio); +btrfs_put_physical_bio (pbio); goto out; }
@@ -1372,7 +1372,7 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,*/ ret =0 ; } -btrfs_put_bbio (bbio); +btrfs_put_physical_bio (pbio); cur += num_bytes; } out:
fs/btrfs/extent_io.c +9 -9
@@ -2290,7 +2290,7 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,struct btrfs_device *dev;u64 map_length =0 ;u64 sector; -struct btrfs_bio *bbio =NULL ; +struct btrfs_physical_bio *pbio =NULL ;int ret;ASSERT (!(fs_info->sb->s_flags &SB_RDONLY ));
@@ -2304,7 +2304,7 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, map_length = length;/* -* Avoid races with device replace and make sure our bbio has devices +* Avoid races with device replace and make sure our pbio has devices * associated to its stripes that don't go away while we are doing the * read repair operation. */
@@ -2317,28 +2317,28 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,* stripe's dev and sector. */ ret =btrfs_map_block (fs_info,BTRFS_MAP_READ , logical, - &map_length, &bbio,0 ); + &map_length, &pbio,0 );if (ret) {btrfs_bio_counter_dec (fs_info);bio_put (bio);return -EIO ; } -ASSERT (bbio->mirror_num ==1 ); +ASSERT (pbio->mirror_num ==1 ); }else { ret =btrfs_map_block (fs_info,BTRFS_MAP_WRITE , logical, - &map_length, &bbio, mirror_num); + &map_length, &pbio, mirror_num);if (ret) {btrfs_bio_counter_dec (fs_info);bio_put (bio);return -EIO ; } -BUG_ON (mirror_num != bbio->mirror_num); +BUG_ON (mirror_num != pbio->mirror_num); } - sector = bbio->stripes[bbio->mirror_num -1 ].physical >>9 ; + sector = pbio->stripes[pbio->mirror_num -1 ].physical >>9 ; bio->bi_iter.bi_sector = sector; - dev = bbio->stripes[bbio->mirror_num -1 ].dev; -btrfs_put_bbio (bbio); + dev = pbio->stripes[pbio->mirror_num -1 ].dev; +btrfs_put_physical_bio (pbio);if (!dev || !dev->bdev || !test_bit (BTRFS_DEV_STATE_WRITEABLE , &dev->dev_state)) {btrfs_bio_counter_dec (fs_info);
fs/btrfs/raid56.c +59 -59
406 lines not on this page · raw message
fs/btrfs/raid56.h +4 -4
@@ -31,24 +31,24 @@ struct btrfs_raid_bio;struct btrfs_device ;int raid56_parity_recover (struct btrfs_fs_info *fs_info,struct bio *bio, -struct btrfs_bio *bbio,u64 stripe_len, +struct btrfs_physical_bio *pbio,u64 stripe_len,int mirror_num,int generic_io);int raid56_parity_write (struct btrfs_fs_info *fs_info,struct bio *bio, -struct btrfs_bio *bbio,u64 stripe_len); +struct btrfs_physical_bio *pbio,u64 stripe_len);void raid56_add_scrub_pages (struct btrfs_raid_bio *rbio,struct page *page,u64 logical);struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio (struct btrfs_fs_info *fs_info,struct bio *bio, -struct btrfs_bio *bbio,u64 stripe_len, +struct btrfs_physical_bio *pbio,u64 stripe_len,struct btrfs_device *scrub_dev,unsigned long *dbitmap,int stripe_nsectors);void raid56_parity_submit_scrub_rbio (struct btrfs_raid_bio *rbio);struct btrfs_raid_bio *raid56_alloc_missing_rbio (struct btrfs_fs_info *fs_info,struct bio *bio, -struct btrfs_bio *bbio,u64 length); +struct btrfs_physical_bio *pbio,u64 length);void raid56_submit_missing_rbio (struct btrfs_raid_bio *rbio);int btrfs_alloc_stripe_hash_table (struct btrfs_fs_info *info);
fs/btrfs/reada.c +13 -13
@@ -227,7 +227,7 @@ int btree_readahead_hook(struct extent_buffer *eb, int err) }static struct reada_zone *reada_find_zone (struct btrfs_device *dev,u64 logical, -struct btrfs_bio *bbio) +struct btrfs_physical_bio *pbio) {struct btrfs_fs_info *fs_info = dev->fs_info;int ret;
@@ -275,11 +275,11 @@ static struct reada_zone *reada_find_zone(struct btrfs_device *dev, u64 logical,kref_init (&zone->refcnt); zone->elems =0 ; zone->device = dev;/* our device always sits at index 0 */ -for (i =0 ; i < bbio->num_stripes; ++i) { +for (i =0 ; i < pbio->num_stripes; ++i) {/* bounds have already been checked */ - zone->devs[i] = bbio->stripes[i].dev; + zone->devs[i] = pbio->stripes[i].dev; } - zone->ndevs = bbio->num_stripes; + zone->ndevs = pbio->num_stripes;spin_lock (&fs_info->reada_lock); ret = radix_tree_insert(&dev->reada_zones,
@@ -309,7 +309,7 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info,int ret;struct reada_extent *re =NULL ;struct reada_extent *re_exist =NULL ; -struct btrfs_bio *bbio =NULL ; +struct btrfs_physical_bio *pbio =NULL ;struct btrfs_device *dev;struct btrfs_device *prev_dev;u64 length;
@@ -345,28 +345,28 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info,*/ length = fs_info->nodesize; ret =btrfs_map_block (fs_info,BTRFS_MAP_GET_READ_MIRRORS , logical, - &length, &bbio,0 ); -if (ret || !bbio || length < fs_info->nodesize) + &length, &pbio,0 ); +if (ret || !pbio || length < fs_info->nodesize) goto error; -if (bbio->num_stripes >BTRFS_MAX_MIRRORS ) { +if (pbio->num_stripes >BTRFS_MAX_MIRRORS ) {btrfs_err (fs_info,"readahead: more than %d copies not supported" ,BTRFS_MAX_MIRRORS ); goto error; } - real_stripes = bbio->num_stripes - bbio->num_tgtdevs; + real_stripes = pbio->num_stripes - pbio->num_tgtdevs;for (nzones =0 ; nzones < real_stripes; ++nzones) {struct reada_zone *zone; - dev = bbio->stripes[nzones].dev; + dev = pbio->stripes[nzones].dev;/* cannot read ahead on missing device. */ if (!dev->bdev)continue ; - zone =reada_find_zone (dev, logical, bbio); + zone =reada_find_zone (dev, logical, pbio);if (!zone)continue ;
@@ -464,7 +464,7 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info,if (!have_zone) goto error; -btrfs_put_bbio (bbio); +btrfs_put_physical_bio (pbio);return re; error:
@@ -488,7 +488,7 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info,kref_put (&zone->refcnt, reada_zone_release);spin_unlock (&fs_info->reada_lock); } -btrfs_put_bbio (bbio); +btrfs_put_physical_bio (pbio);kfree (re);return re_exist; }
fs/btrfs/scrub.c +58 -58
289 lines not on this page · raw message
fs/btrfs/volumes.c +128 -128
609 lines not on this page · raw message
fs/btrfs/volumes.h +8 -5
@@ -365,7 +365,10 @@ struct btrfs_bio_stripe {u64 length;/* only used for discard mappings */ }; -struct btrfs_bio { +/* +* Records the physical mapping info and extra members to submit real device IO. +*/ +struct btrfs_physical_bio {refcount_t refs;atomic_t stripes_pending;struct btrfs_fs_info *fs_info;
@@ -461,14 +464,14 @@ static inline enum btrfs_map_op btrfs_op(struct bio *bio) } } -void btrfs_get_bbio (struct btrfs_bio *bbio); -void btrfs_put_bbio (struct btrfs_bio *bbio); +void btrfs_get_physical_bio (struct btrfs_physical_bio *pbio); +void btrfs_put_physical_bio (struct btrfs_physical_bio *pbio);int btrfs_map_block (struct btrfs_fs_info *fs_info,enum btrfs_map_op op,u64 logical,u64 *length, -struct btrfs_bio **bbio_ret,int mirror_num); +struct btrfs_physical_bio **pbio_ret,int mirror_num);int btrfs_map_sblock (struct btrfs_fs_info *fs_info,enum btrfs_map_op op,u64 logical,u64 *length, -struct btrfs_bio **bbio_ret); +struct btrfs_physical_bio **pbio_ret);int btrfs_get_io_geometry (struct btrfs_fs_info *fs_info,struct extent_map *map,enum btrfs_map_op op,u64 logical,struct btrfs_io_geometry *io_geom);
fs/btrfs/zoned.c +8 -8
@@ -1626,27 +1626,27 @@ int btrfs_zoned_issue_zeroout(struct btrfs_device *device, u64 physical, u64 lenstatic int read_zone_info (struct btrfs_fs_info *fs_info,u64 logical,struct blk_zone *zone) { -struct btrfs_bio *bbio =NULL ; +struct btrfs_physical_bio *pbio =NULL ;u64 mapped_length =PAGE_SIZE ;unsigned int nofs_flag;int nmirrors;int i, ret; ret =btrfs_map_sblock (fs_info,BTRFS_MAP_GET_READ_MIRRORS , logical, - &mapped_length, &bbio); -if (ret || !bbio || mapped_length <PAGE_SIZE ) { -btrfs_put_bbio (bbio); + &mapped_length, &pbio); +if (ret || !pbio || mapped_length <PAGE_SIZE ) { +btrfs_put_physical_bio (pbio);return -EIO ; } -if (bbio->map_type &BTRFS_BLOCK_GROUP_RAID56_MASK ) +if (pbio->map_type &BTRFS_BLOCK_GROUP_RAID56_MASK )return -EINVAL ; nofs_flag =memalloc_nofs_save (); - nmirrors = (int )bbio->num_stripes; + nmirrors = (int )pbio->num_stripes;for (i =0 ; i < nmirrors; i++) { -u64 physical = bbio->stripes[i].physical; -struct btrfs_device *dev = bbio->stripes[i].dev; +u64 physical = pbio->stripes[i].physical; +struct btrfs_device *dev = pbio->stripes[i].dev;/* Missing device */ if (!dev->bdev)
Signature · 1 line
2.33.0