cleanup btrfs bio handling, part 1
Subsystems (2)
Hi all,
this series moves btrfs to use the new as of 5.18 bio interface and cleans up a few close by areas. Larger cleanups focussed around the btrfs_bio will follow as a next step.
Diffstat:
check-integrity.c | 165 +++++++++++++++++++++++++----------------------------- check-integrity.h | 8 +- disk-io.c | 6 + extent_io.c | 55 ++++++++---------- extent_io.h | 2 raid56.c | 46 ++++++--------- scrub.c | 92 ++++++++++++------------------ volumes.c | 12 ++- 8 files changed, 179 insertions(+), 207 deletions(-)
PATCH 1/12 btrfs: refactor __btrfsic_submit_bio
Split out two helpers to mak __btrfsic_submit_bio more readable.
--- fs/btrfs/check-integrity.c | 150 +++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 72 deletions(-)
fs/btrfs/check-integrity.c +78 -72
@@ -2635,6 +2635,74 @@ static struct btrfsic_dev_state *btrfsic_dev_state_lookup(dev_t dev) &btrfsic_dev_state_hashtable); } +static void btrfsic_check_write_bio (struct bio *bio, +struct btrfsic_dev_state *dev_state) +{ +unsigned int segs =bio_segments (bio); +u64 dev_bytenr =512 * bio->bi_iter.bi_sector; +u64 cur_bytenr = dev_bytenr; +struct bvec_iter iter; +struct bio_vec bvec; +char **mapped_datav; +int bio_is_patched =0 ; +int i =0 ; + +if (dev_state->state->print_mask &BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH ) +pr_info ("submit_bio(rw=%d,0x%x, bi_vcnt=%u, bi_sector=%llu (bytenr %llu), bi_bdev=%p)\n" , +bio_op (bio), bio->bi_opf, segs, + bio->bi_iter.bi_sector, dev_bytenr, bio->bi_bdev); + + mapped_datav =kmalloc_array (segs,sizeof (*mapped_datav),GFP_NOFS ); +if (!mapped_datav) +return ; + +bio_for_each_segment (bvec, bio, iter) { +BUG_ON (bvec.bv_len !=PAGE_SIZE ); + mapped_datav[i] =page_address (bvec.bv_page); + i++; + +if (dev_state->state->print_mask & +BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH_VERBOSE ) +pr_info ("#%u: bytenr=%llu, len=%u, offset=%u\n" , + i, cur_bytenr, bvec.bv_len, bvec.bv_offset); + cur_bytenr += bvec.bv_len; + } + +btrfsic_process_written_block (dev_state, dev_bytenr, mapped_datav, segs, + bio, &bio_is_patched, bio->bi_opf); +kfree (mapped_datav); +} + +static void btrfsic_check_flush_bio (struct bio *bio, +struct btrfsic_dev_state *dev_state) +{ +if (dev_state->state->print_mask &BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH ) +pr_info ("submit_bio(rw=%d,0x%x FLUSH, bdev=%p)\n" , +bio_op (bio), bio->bi_opf, bio->bi_bdev); + +if (dev_state->dummy_block_for_bio_bh_flush.is_iodone) { +struct btrfsic_block *const block = + &dev_state->dummy_block_for_bio_bh_flush; + + block->is_iodone =0 ; + block->never_written =0 ; + block->iodone_w_error =0 ; + block->flush_gen = dev_state->last_flush_gen +1 ; + block->submit_bio_bh_rw = bio->bi_opf; + block->orig_bio_private = bio->bi_private; + block->orig_bio_end_io = bio->bi_end_io; + block->next_in_same_bio =NULL ; + bio->bi_private = block; + bio->bi_end_io = btrfsic_bio_end_io; + }else if ((dev_state->state->print_mask & + (BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH | +BTRFSIC_PRINT_MASK_VERBOSE ))) { +pr_info ( +"btrfsic_submit_bio(%pg) with FLUSH but dummy block already in use (ignored)!\n" , + dev_state->bdev); + } +} +static void __btrfsic_submit_bio (struct bio *bio) {struct btrfsic_dev_state *dev_state;
@@ -2642,80 +2710,18 @@ static void __btrfsic_submit_bio(struct bio *bio)if (!btrfsic_is_initialized)return ; -mutex_lock (&btrfsic_mutex); -/* since btrfsic_submit_bio() is also called before -* btrfsic_mount(), this might return NULL */ +/* +* We can be called before btrfsic_mount, so there might not be a +* dev_state. +*/ dev_state =btrfsic_dev_state_lookup (bio->bi_bdev->bd_dev); -if (NULL != dev_state && - (bio_op (bio) ==REQ_OP_WRITE ) &&bio_has_data (bio)) { -int i =0 ; -u64 dev_bytenr; -u64 cur_bytenr; -struct bio_vec bvec; -struct bvec_iter iter; -int bio_is_patched; -char **mapped_datav; -unsigned int segs =bio_segments (bio); - - dev_bytenr =512 * bio->bi_iter.bi_sector; - bio_is_patched =0 ; -if (dev_state->state->print_mask & -BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH ) -pr_info ("submit_bio(rw=%d,0x%x, bi_vcnt=%u, bi_sector=%llu (bytenr %llu), bi_bdev=%p)\n" , -bio_op (bio), bio->bi_opf, segs, - bio->bi_iter.bi_sector, dev_bytenr, bio->bi_bdev); - - mapped_datav =kmalloc_array (segs, -sizeof (*mapped_datav),GFP_NOFS ); -if (!mapped_datav) - goto leave; - cur_bytenr = dev_bytenr; - -bio_for_each_segment (bvec, bio, iter) { -BUG_ON (bvec.bv_len !=PAGE_SIZE ); - mapped_datav[i] =page_address (bvec.bv_page); - i++; - -if (dev_state->state->print_mask & -BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH_VERBOSE ) -pr_info ("#%u: bytenr=%llu, len=%u, offset=%u\n" , - i, cur_bytenr, bvec.bv_len, bvec.bv_offset); - cur_bytenr += bvec.bv_len; - } -btrfsic_process_written_block (dev_state, dev_bytenr, - mapped_datav, segs, - bio, &bio_is_patched, - bio->bi_opf); -kfree (mapped_datav); - }else if (NULL != dev_state && (bio->bi_opf &REQ_PREFLUSH )) { -if (dev_state->state->print_mask & -BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH ) -pr_info ("submit_bio(rw=%d,0x%x FLUSH, bdev=%p)\n" , -bio_op (bio), bio->bi_opf, bio->bi_bdev); -if (!dev_state->dummy_block_for_bio_bh_flush.is_iodone) { -if ((dev_state->state->print_mask & - (BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH | -BTRFSIC_PRINT_MASK_VERBOSE ))) -pr_info ( -"btrfsic_submit_bio(%pg) with FLUSH but dummy block already in use (ignored)!\n" , - dev_state->bdev); - }else { -struct btrfsic_block *const block = - &dev_state->dummy_block_for_bio_bh_flush; - - block->is_iodone =0 ; - block->never_written =0 ; - block->iodone_w_error =0 ; - block->flush_gen = dev_state->last_flush_gen +1 ; - block->submit_bio_bh_rw = bio->bi_opf; - block->orig_bio_private = bio->bi_private; - block->orig_bio_end_io = bio->bi_end_io; - block->next_in_same_bio =NULL ; - bio->bi_private = block; - bio->bi_end_io = btrfsic_bio_end_io; - } +mutex_lock (&btrfsic_mutex); +if (dev_state) { +if (bio_op (bio) ==REQ_OP_WRITE &&bio_has_data (bio)) +btrfsic_check_write_bio (bio, dev_state); +else if (bio->bi_opf &REQ_PREFLUSH ) +btrfsic_check_flush_bio (bio, dev_state); } -leave:mutex_unlock (&btrfsic_mutex); }
Signature · 1 line
2.30.2
PATCH 2/12 btrfs: split submit_bio from btrfsic checking
In reply to Christoph HellwigRequire a separate call to the integrity checking helpers from the actual bio submission.
--- fs/btrfs/check-integrity.c | 14 +------------- fs/btrfs/check-integrity.h | 8 ++++---- fs/btrfs/disk-io.c | 6 ++++-- fs/btrfs/extent_io.c | 3 ++- fs/btrfs/scrub.c | 12 ++++++++---- fs/btrfs/volumes.c | 3 ++- 6 files changed, 21 insertions(+), 25 deletions(-)
fs/btrfs/check-integrity.c +1 -13
@@ -2703,7 +2703,7 @@ static void btrfsic_check_flush_bio(struct bio *bio, } } -static void __btrfsic_submit_bio (struct bio *bio) +void btrfsic_check_bio (struct bio *bio) {struct btrfsic_dev_state *dev_state;
@@ -2725,18 +2725,6 @@ static void __btrfsic_submit_bio(struct bio *bio)mutex_unlock (&btrfsic_mutex); } -void btrfsic_submit_bio (struct bio *bio) -{ -__btrfsic_submit_bio (bio); -submit_bio (bio); -} - -int btrfsic_submit_bio_wait (struct bio *bio) -{ -__btrfsic_submit_bio (bio); -return submit_bio_wait (bio); -} -int btrfsic_mount (struct btrfs_fs_info *fs_info,struct btrfs_fs_devices *fs_devices,int including_extent_data,u32 print_mask)
fs/btrfs/check-integrity.h +4 -4
@@ -7,11 +7,11 @@#define BTRFS_CHECK_INTEGRITY_H #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY -void btrfsic_submit_bio (struct bio *bio); -int btrfsic_submit_bio_wait (struct bio *bio); +void btrfsic_check_bio (struct bio *bio);#else -#define btrfsic_submit_bio submit_bio -#define btrfsic_submit_bio_wait submit_bio_wait +static inline void btrfsic_check_bio (struct bio *bio) +{ +}#endif int btrfsic_mount(struct btrfs_fs_info *fs_info,
fs/btrfs/disk-io.c +4 -2
@@ -4144,7 +4144,8 @@ static int write_dev_supers(struct btrfs_device *device,if (i ==0 && !btrfs_test_opt (device->fs_info,NOBARRIER )) bio->bi_opf |=REQ_FUA ; -btrfsic_submit_bio (bio); +btrfsic_check_bio (bio); +submit_bio (bio);if (btrfs_advance_sb_log (device, i)) errors++;
@@ -4257,7 +4258,8 @@ static void write_dev_flush(struct btrfs_device *device)init_completion (&device->flush_wait); bio->bi_private = &device->flush_wait; -btrfsic_submit_bio (bio); +btrfsic_check_bio (bio); +submit_bio (bio);set_bit (BTRFS_DEV_STATE_FLUSH_SENT , &device->dev_state); }
fs/btrfs/extent_io.c +2 -1
@@ -2366,7 +2366,8 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, bio->bi_opf =REQ_OP_WRITE |REQ_SYNC ;bio_add_page (bio, page, length, pg_offset); -if (btrfsic_submit_bio_wait (bio)) { +btrfsic_check_bio (bio); +if (submit_bio_wait (bio)) {/* try to remap that extent elsewhere? */ btrfs_bio_counter_dec (fs_info);bio_put (bio);
fs/btrfs/scrub.c +8 -4
@@ -1479,7 +1479,8 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info, bio->bi_iter.bi_sector = spage->physical >>9 ; bio->bi_opf =REQ_OP_READ ; -if (btrfsic_submit_bio_wait (bio)) { +btrfsic_check_bio (bio); +if (submit_bio_wait (bio)) { spage->io_error =1 ; sblock->no_io_error_seen =0 ; }
@@ -1565,7 +1566,8 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,return -EIO ; } -if (btrfsic_submit_bio_wait (bio)) { +btrfsic_check_bio (bio); +if (submit_bio_wait (bio)) {btrfs_dev_stat_inc_and_print (spage_bad->dev,BTRFS_DEV_STAT_WRITE_ERRS );atomic64_inc (&fs_info->dev_replace.num_write_errors);
@@ -1723,7 +1725,8 @@ static void scrub_wr_submit(struct scrub_ctx *sctx)* orders the requests before sending them to the driver which * doubled the write performance on spinning disks when measured * with Linux 3.5 */ -btrfsic_submit_bio (sbio->bio); +btrfsic_check_bio (sbio->bio); +submit_bio (sbio->bio);if (btrfs_is_zoned (sctx->fs_info)) sctx->write_pointer = sbio->physical + sbio->page_count *
@@ -2057,7 +2060,8 @@ static void scrub_submit(struct scrub_ctx *sctx) sbio = sctx->bios[sctx->curr]; sctx->curr =-1 ;scrub_pending_bio_inc (sctx); -btrfsic_submit_bio (sbio->bio); +btrfsic_check_bio (sbio->bio); +submit_bio (sbio->bio); } static int scrub_add_page_to_rd_bio(struct scrub_ctx *sctx,
fs/btrfs/volumes.c +2 -1
@@ -6749,7 +6749,8 @@ static void submit_stripe_bio(struct btrfs_io_context *bioc, struct bio *bio,btrfs_bio_counter_inc_noblocked (fs_info); -btrfsic_submit_bio (bio); +btrfsic_check_bio (bio); +submit_bio (bio); }static void bioc_error (struct btrfs_io_context *bioc,struct bio *bio,u64 logical)
Signature · 1 line
2.30.2
Re: [PATCH 02/12] btrfs: split submit_bio from btrfsic checking
Quoted 5 lines · Christoph Hellwig
Require a separate call to the integrity checking helpers from the actual bio submission.
Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Qu Wenruo <[email protected]
This patch doesn't apply cleanly on latest misc-next
PATCH 3/12 btrfs: simplify btrfsic_read_block
In reply to Christoph Hellwigbtrfsic_read_block does not need the btrfs_bio structure, so switch to plain bio_alloc.
--- fs/btrfs/check-integrity.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/btrfs/check-integrity.c +2 -3
@@ -1563,10 +1563,9 @@ static int btrfsic_read_block(struct btrfsic_state *state,struct bio *bio;unsigned int j; - bio =btrfs_bio_alloc (num_pages - i); -bio_set_dev (bio, block_ctx->dev->bdev); + bio =bio_alloc (block_ctx->dev->bdev, num_pages - i, +REQ_OP_READ ,GFP_NOFS ); bio->bi_iter.bi_sector = dev_bytenr >>9 ; - bio->bi_opf =REQ_OP_READ ;for (j = i; j < num_pages; j++) { ret = bio_add_page(bio, block_ctx->pagev[j],
Signature · 1 line
2.30.2
PATCH 4/12 btrfs: simplify repair_io_failure
In reply to Christoph HellwigThe I/O in repair_io_failue is synchronous and doesn't need a btrfs_bio, so just use an on-stack bio. Also cleanup the error handling to use goto labels and not discard the actual return values.
--- fs/btrfs/extent_io.c | 52 ++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 28 deletions(-)
fs/btrfs/extent_io.c +24 -28
@@ -2303,12 +2303,13 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, u64 length, u64 logical, struct page *page, unsigned int pg_offset, int mirror_num) { - struct bio *bio; struct btrfs_device *dev; +struct bio_vec bvec; +struct bio bio;u64 map_length =0 ;u64 sector;struct btrfs_io_context *bioc =NULL ; -int ret; +int ret =0 ;ASSERT (!(fs_info->sb->s_flags &SB_RDONLY ));BUG_ON (!mirror_num);
@@ -2316,8 +2317,6 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,if (btrfs_repair_one_zone (fs_info, logical))return 0 ; - bio =btrfs_bio_alloc (1 ); - bio->bi_iter.bi_size =0 ; map_length = length;/*
@@ -2335,53 +2334,50 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,*/ ret =btrfs_map_block (fs_info,BTRFS_MAP_READ , logical, &map_length, &bioc,0 ); -if (ret) { -btrfs_bio_counter_dec (fs_info); -bio_put (bio); -return -EIO ; - } +if (ret) + goto out_counter_dec;ASSERT (bioc->mirror_num ==1 ); }else { ret =btrfs_map_block (fs_info,BTRFS_MAP_WRITE , logical, &map_length, &bioc, mirror_num); -if (ret) { -btrfs_bio_counter_dec (fs_info); -bio_put (bio); -return -EIO ; - } +if (ret) + goto out_counter_dec;BUG_ON (mirror_num != bioc->mirror_num); } sector = bioc->stripes[bioc->mirror_num -1 ].physical >>9 ; - bio->bi_iter.bi_sector = sector; dev = bioc->stripes[bioc->mirror_num -1 ].dev;btrfs_put_bioc (bioc); +if (!dev || !dev->bdev || !test_bit (BTRFS_DEV_STATE_WRITEABLE , &dev->dev_state)) { -btrfs_bio_counter_dec (fs_info); -bio_put (bio); -return -EIO ; + ret = -EIO ; + goto out_counter_dec; } -bio_set_dev (bio, dev->bdev); - bio->bi_opf =REQ_OP_WRITE |REQ_SYNC ; -bio_add_page (bio, page, length, pg_offset); -btrfsic_check_bio (bio); -if (submit_bio_wait (bio)) { +bio_init (&bio, dev->bdev, &bvec,1 ,REQ_OP_WRITE |REQ_SYNC ); + bio.bi_iter.bi_sector = sector; +__bio_add_page (&bio, page, length, pg_offset); + +btrfsic_check_bio (&bio); + ret =submit_bio_wait (&bio); +if (ret) {/* try to remap that extent elsewhere? */ -btrfs_bio_counter_dec (fs_info); -bio_put (bio);btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_WRITE_ERRS ); -return -EIO ; + goto out_bio_uninit; }btrfs_info_rl_in_rcu (fs_info,"read error corrected: ino %llu off %llu (dev %s sector %llu)" , ino, start,rcu_str_deref (dev->name), sector); + ret =0 ; + +out_bio_uninit: +bio_uninit (&bio); +out_counter_dec:btrfs_bio_counter_dec (fs_info); -bio_put (bio); -return 0 ; +return ret; }int btrfs_repair_eb_io_failure (const struct extent_buffer *eb,int mirror_num)
Signature · 1 line
2.30.2
PATCH 5/12 btrfs: simplify scrub_recheck_block
In reply to Christoph HellwigThe I/O in repair_io_failue is synchronous and doesn't need a btrfs_bio, so just use an on-stack bio.
--- fs/btrfs/scrub.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
fs/btrfs/scrub.c +8 -10
@@ -1462,8 +1462,9 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info,return scrub_recheck_block_on_raid56 (fs_info, sblock);for (page_num =0 ; page_num < sblock->page_count; page_num++) { -struct bio *bio;struct scrub_page *spage = sblock->pagev[page_num]; +struct bio bio; +struct bio_vec bvec;if (spage->dev->bdev ==NULL ) { spage->io_error =1 ;
@@ -1472,20 +1473,17 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info, }WARN_ON (!spage->page); - bio =btrfs_bio_alloc (1 ); -bio_set_dev (bio, spage->dev->bdev); - -bio_add_page (bio, spage->page, fs_info->sectorsize,0 ); - bio->bi_iter.bi_sector = spage->physical >>9 ; - bio->bi_opf =REQ_OP_READ ; +bio_init (&bio, spage->dev->bdev, &bvec,1 ,REQ_OP_READ ); +bio_add_page (&bio, spage->page, fs_info->sectorsize,0 ); + bio.bi_iter.bi_sector = spage->physical >>9 ; -btrfsic_check_bio (bio); -if (submit_bio_wait (bio)) { +btrfsic_check_bio (&bio); +if (submit_bio_wait (&bio)) { spage->io_error =1 ; sblock->no_io_error_seen =0 ; } -bio_put (bio); +bio_uninit (&bio); }if (sblock->no_io_error_seen)
Signature · 1 line
2.30.2
Re: [PATCH 05/12] btrfs: simplify scrub_recheck_block
Quoted 14 lines · Christoph Hellwig
The I/O in
repair_io_failueis synchronous and doesn't need abtrfs_bio, so just use an on-stack bio.Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Qu Wenruo <[email protected]>--- fs/btrfs/scrub.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)fs/btrfs/scrub.c +0
-0
fs/btrfs/scrub.c static void scrub_recheck_block(struct btrfs_fs_info *fs_info, · line 1465
Quoted 5 lines
fs/btrfs/scrub.c +0
-1@@ -1462,8 +1462,9 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info,return scrub_recheck_block_on_raid56 (fs_info, sblock);for (page_num =0 ; page_num < sblock->page_count; page_num++) { -struct bio *bio;struct scrub_page *spage = sblock->pagev[page_num];
This line comes from a patch which is not yet in misc-next as a result the patch fails to apply. So which branch are those changes based off?
<snip>
Re: [PATCH 05/12] btrfs: simplify scrub_recheck_block
Quoted 2 lines · Nikolay Borisov
This line comes from a patch which is not yet in misc-next as a result the patch fails to apply. So which branch are those changes based off?
The series is against 5.18-rc1. The whole branch can be found here:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/btrfs-bio-cleanup-part1
PATCH 6/12 btrfs: simplify scrub_repair_page_from_good_copy
In reply to Christoph HellwigThe I/O in repair_io_failue is synchronous and doesn't need a btrfs_bio, so just use an on-stack bio.
--- fs/btrfs/scrub.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
fs/btrfs/scrub.c +9 -14
@@ -1544,7 +1544,8 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,BUG_ON (spage_good->page ==NULL );if (force_write || sblock_bad->header_error || sblock_bad->checksum_error || spage_bad->io_error) { -struct bio *bio; +struct bio bio; +struct bio_vec bvec;int ret;if (!spage_bad->dev->bdev) {
@@ -1553,26 +1554,20 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,return -EIO ; } - bio =btrfs_bio_alloc (1 ); -bio_set_dev (bio, spage_bad->dev->bdev); - bio->bi_iter.bi_sector = spage_bad->physical >>9 ; - bio->bi_opf =REQ_OP_WRITE ; +bio_init (&bio, spage_bad->dev->bdev, &bvec,1 ,REQ_OP_WRITE ); + bio.bi_iter.bi_sector = spage_bad->physical >>9 ; +__bio_add_page (&bio, spage_good->page, sectorsize,0 ); - ret =bio_add_page (bio, spage_good->page, sectorsize,0 ); -if (ret != sectorsize) { -bio_put (bio); -return -EIO ; - } +btrfsic_check_bio (&bio); + ret =submit_bio_wait (&bio); +bio_uninit (&bio); -btrfsic_check_bio (bio); -if (submit_bio_wait (bio)) { +if (ret) {btrfs_dev_stat_inc_and_print (spage_bad->dev,BTRFS_DEV_STAT_WRITE_ERRS );atomic64_inc (&fs_info->dev_replace.num_write_errors); -bio_put (bio);return -EIO ; } -bio_put (bio); }return 0 ;
Signature · 1 line
2.30.2
PATCH 7/12 btrfs: move the call to bio_set_dev out of submit_stripe_bio
In reply to Christoph HellwigPrepare for additional refactoring.
--- fs/btrfs/volumes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/volumes.c +1 -1
@@ -6745,7 +6745,6 @@ static void submit_stripe_bio(struct btrfs_io_context *bioc, struct bio *bio,bio_op (bio), bio->bi_opf, bio->bi_iter.bi_sector, (unsigned long )dev->bdev->bd_dev,rcu_str_deref (dev->name), dev->devid, bio->bi_iter.bi_size); -bio_set_dev (bio, dev->bdev);btrfs_bio_counter_inc_noblocked (fs_info);
@@ -6837,6 +6836,7 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,else bio = first_bio; +bio_set_dev (bio, dev->bdev);submit_stripe_bio (bioc, bio, bioc->stripes[dev_nr].physical, dev); }btrfs_bio_counter_dec (fs_info);
Signature · 1 line
2.30.2
PATCH 8/12 btrfs: pass a block_device to btrfs_bio_clone
In reply to Christoph HellwigPass the block_device to bio_alloc_clone instead of setting it later.
--- fs/btrfs/extent_io.c | 4 ++-- fs/btrfs/extent_io.h | 2 +- fs/btrfs/volumes.c | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-)
fs/btrfs/extent_io.c +2 -2
@@ -3153,13 +3153,13 @@ struct bio *btrfs_bio_alloc(unsigned int nr_iovecs)return bio; } -struct bio *btrfs_bio_clone (struct bio *bio) +struct bio *btrfs_bio_clone (struct block_device *bdev,struct bio *bio) {struct btrfs_bio *bbio;struct bio *new;/* Bio allocation backed by a bioset does not fail */ - new =bio_alloc_clone (bio->bi_bdev, bio,GFP_NOFS , &btrfs_bioset); + new =bio_alloc_clone (bdev, bio,GFP_NOFS , &btrfs_bioset); bbio =btrfs_bio (new);btrfs_bio_init (bbio); bbio->iter = bio->bi_iter;
fs/btrfs/extent_io.h +1 -1
@@ -278,7 +278,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 (unsigned int nr_iovecs); -struct bio *btrfs_bio_clone (struct bio *bio); +struct bio *btrfs_bio_clone (struct block_device *bdev,struct bio *bio);struct bio *btrfs_bio_clone_partial (struct bio *orig,u64 offset,u64 size);void end_extent_writepage (struct page *page,int err,u64 start,u64 end);
fs/btrfs/volumes.c +5 -4
@@ -6831,12 +6831,13 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,continue ; } -if (dev_nr < total_devs -1 ) - bio =btrfs_bio_clone (first_bio); -else +if (dev_nr < total_devs -1 ) { + bio =btrfs_bio_clone (dev->bdev, first_bio); + }else { bio = first_bio; +bio_set_dev (bio, dev->bdev); + } -bio_set_dev (bio, dev->bdev);submit_stripe_bio (bioc, bio, bioc->stripes[dev_nr].physical, dev); }btrfs_bio_counter_dec (fs_info);
Signature · 1 line
2.30.2
Re: [PATCH 08/12] btrfs: pass a block_device to btrfs_bio_clone
Quoted 1 line · Christoph Hellwig
Pass the
block_devicetobio_alloc_cloneinstead of setting it later.
s/bio_alloc_clone/btrfs_bio_clone
Re: [PATCH 08/12] btrfs: pass a block_device to btrfs_bio_clone
Quoted 4 lines · Johannes Thumshirn
Quoted 1 line · Christoph Hellwig
Pass the
block_devicetobio_alloc_cloneinstead of setting it later.s/bio_alloc_clone/btrfs_bio_clone
Well, both if we want to be pedantic.
PATCH 9/12 btrfs: initialize ->bi_opf and ->bi_private in rbio_add_io_page
In reply to Christoph HellwigPrepare for further refactoring by moving this initialization to a single place.
--- fs/btrfs/raid56.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-)
fs/btrfs/raid56.c +18 -20
@@ -1069,7 +1069,8 @@ static int rbio_add_io_page(struct btrfs_raid_bio *rbio,struct page *page, int stripe_nr, unsigned long page_index, - unsigned long bio_max_len) + unsigned long bio_max_len, + unsigned int opf) { struct bio *last = bio_list->tail;int ret;
@@ -1106,7 +1107,9 @@ static int rbio_add_io_page(struct btrfs_raid_bio *rbio,btrfs_bio (bio)->device = stripe->dev; bio->bi_iter.bi_size =0 ;bio_set_dev (bio, stripe->dev->bdev); + bio->bi_opf = opf; bio->bi_iter.bi_sector = disk_start >>9 ; + bio->bi_private = rbio;bio_add_page (bio, page,PAGE_SIZE ,0 );bio_list_add (bio_list, bio);
@@ -1275,7 +1278,8 @@ static noinline void finish_rmw(struct btrfs_raid_bio *rbio) } ret =rbio_add_io_page (rbio, &bio_list, - page, stripe, pagenr, rbio->stripe_len); + page, stripe, pagenr, rbio->stripe_len, +REQ_OP_WRITE );if (ret) goto cleanup; }
@@ -1300,7 +1304,8 @@ static noinline void finish_rmw(struct btrfs_raid_bio *rbio) ret =rbio_add_io_page (rbio, &bio_list, page, rbio->bioc->tgtdev_map[stripe], - pagenr, rbio->stripe_len); + pagenr, rbio->stripe_len, +REQ_OP_WRITE );if (ret) goto cleanup; }
@@ -1311,9 +1316,7 @@ static noinline void finish_rmw(struct btrfs_raid_bio *rbio)BUG_ON (atomic_read (&rbio->stripes_pending) ==0 );while ((bio =bio_list_pop (&bio_list))) { - bio->bi_private = rbio; bio->bi_end_io = raid_write_end_io; - bio->bi_opf =REQ_OP_WRITE ;submit_bio (bio); }
@@ -1517,7 +1520,8 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)continue ; ret =rbio_add_io_page (rbio, &bio_list, page, - stripe, pagenr, rbio->stripe_len); + stripe, pagenr, rbio->stripe_len, +REQ_OP_READ );if (ret) goto cleanup; }
@@ -1540,9 +1544,7 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)*/ atomic_set (&rbio->stripes_pending, bios_to_read);while ((bio =bio_list_pop (&bio_list))) { - bio->bi_private = rbio; bio->bi_end_io = raid_rmw_end_io; - bio->bi_opf =REQ_OP_READ ;btrfs_bio_wq_end_io (rbio->bioc->fs_info, bio,BTRFS_WQ_ENDIO_RAID56 );
@@ -2059,7 +2061,8 @@ static int __raid56_parity_recover(struct btrfs_raid_bio *rbio) ret =rbio_add_io_page (rbio, &bio_list,rbio_stripe_page (rbio, stripe, pagenr), - stripe, pagenr, rbio->stripe_len); + stripe, pagenr, rbio->stripe_len, +REQ_OP_READ );if (ret <0 ) goto cleanup; }
@@ -2086,9 +2089,7 @@ static int __raid56_parity_recover(struct btrfs_raid_bio *rbio)*/ atomic_set (&rbio->stripes_pending, bios_to_read);while ((bio =bio_list_pop (&bio_list))) { - bio->bi_private = rbio; bio->bi_end_io = raid_recover_end_io; - bio->bi_opf =REQ_OP_READ ;btrfs_bio_wq_end_io (rbio->bioc->fs_info, bio,BTRFS_WQ_ENDIO_RAID56 );
@@ -2419,8 +2420,8 @@ static noinline void finish_parity_scrub(struct btrfs_raid_bio *rbio,struct page *page; page =rbio_stripe_page (rbio, rbio->scrubp, pagenr); - ret =rbio_add_io_page (rbio, &bio_list, - page, rbio->scrubp, pagenr, rbio->stripe_len); + ret =rbio_add_io_page (rbio, &bio_list, page, rbio->scrubp, + pagenr, rbio->stripe_len,REQ_OP_WRITE );if (ret) goto cleanup; }
@@ -2434,7 +2435,7 @@ static noinline void finish_parity_scrub(struct btrfs_raid_bio *rbio, page =rbio_stripe_page (rbio, rbio->scrubp, pagenr); ret =rbio_add_io_page (rbio, &bio_list, page, bioc->tgtdev_map[rbio->scrubp], - pagenr, rbio->stripe_len); + pagenr, rbio->stripe_len,REQ_OP_WRITE );if (ret) goto cleanup; }
@@ -2450,9 +2451,7 @@ static noinline void finish_parity_scrub(struct btrfs_raid_bio *rbio,atomic_set (&rbio->stripes_pending, nr_data);while ((bio =bio_list_pop (&bio_list))) { - bio->bi_private = rbio; bio->bi_end_io = raid_write_end_io; - bio->bi_opf =REQ_OP_WRITE ;submit_bio (bio); }
@@ -2604,8 +2603,9 @@ static void raid56_parity_scrub_stripe(struct btrfs_raid_bio *rbio)if (PageUptodate (page))continue ; - ret =rbio_add_io_page (rbio, &bio_list, page, - stripe, pagenr, rbio->stripe_len); + ret =rbio_add_io_page (rbio, &bio_list, page, stripe, + pagenr, rbio->stripe_len, +REQ_OP_READ );if (ret) goto cleanup; }
@@ -2628,9 +2628,7 @@ static void raid56_parity_scrub_stripe(struct btrfs_raid_bio *rbio)*/ atomic_set (&rbio->stripes_pending, bios_to_read);while ((bio =bio_list_pop (&bio_list))) { - bio->bi_private = rbio; bio->bi_end_io = raid56_parity_scrub_end_io; - bio->bi_opf =REQ_OP_READ ;btrfs_bio_wq_end_io (rbio->bioc->fs_info, bio,BTRFS_WQ_ENDIO_RAID56 );
Signature · 1 line
2.30.2
PATCH 10/12 btrfs: don't allocate a btrfs_bio for raid56 per-stripe bios
In reply to Christoph HellwigExcept for the spurious initialization of ->device just after allocation nothing uses the btrfs_bio, so just allocate a normal bio without extra data.
--- fs/btrfs/raid56.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
fs/btrfs/raid56.c +2 -5
@@ -1103,11 +1103,8 @@ static int rbio_add_io_page(struct btrfs_raid_bio *rbio, }/* put a new bio on the list */ - bio =btrfs_bio_alloc (bio_max_len >>PAGE_SHIFT ?:1 ); -btrfs_bio (bio)->device = stripe->dev; - bio->bi_iter.bi_size =0 ; -bio_set_dev (bio, stripe->dev->bdev); - bio->bi_opf = opf; + bio =bio_alloc (stripe->dev->bdev,max (bio_max_len >>PAGE_SHIFT ,1UL ), + opf,GFP_NOFS ); bio->bi_iter.bi_sector = disk_start >>9 ; bio->bi_private = rbio;
Signature · 1 line
2.30.2
PATCH 11/12 btrfs: don't allocate a btrfs_bio for scrub bios
In reply to Christoph HellwigAll the scrub bios go straight to the block device or the raid56 code, none of which looks at the btrfs_bio.
--- fs/btrfs/scrub.c | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-)
fs/btrfs/scrub.c +18 -29
@@ -1415,8 +1415,8 @@ static void scrub_recheck_block_on_raid56(struct btrfs_fs_info *fs_info,if (!first_page->dev->bdev) goto out; - bio =btrfs_bio_alloc (BIO_MAX_VECS ); -bio_set_dev (bio, first_page->dev->bdev); + bio =bio_alloc (first_page->dev->bdev,BIO_MAX_VECS ,REQ_OP_READ , +GFP_NOFS );for (page_num =0 ; page_num < sblock->page_count; page_num++) {struct scrub_page *spage = sblock->pagev[page_num];
@@ -1649,8 +1649,6 @@ static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx, } sbio = sctx->wr_curr_bio;if (sbio->page_count ==0 ) { -struct bio *bio; - ret =fill_writer_pointer_gap (sctx, spage->physical_for_dev_replace);if (ret) {
@@ -1661,17 +1659,14 @@ static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx, sbio->physical = spage->physical_for_dev_replace; sbio->logical = spage->logical; sbio->dev = sctx->wr_tgtdev; - bio = sbio->bio; -if (!bio) { - bio =btrfs_bio_alloc (sctx->pages_per_bio); - sbio->bio = bio; +if (!sbio->bio) { + sbio->bio =bio_alloc (sbio->dev->bdev, + sctx->pages_per_bio, +REQ_OP_WRITE ,GFP_NOFS ); } - - bio->bi_private = sbio; - bio->bi_end_io = scrub_wr_bio_end_io; -bio_set_dev (bio, sbio->dev->bdev); - bio->bi_iter.bi_sector = sbio->physical >>9 ; - bio->bi_opf =REQ_OP_WRITE ; + sbio->bio->bi_private = sbio; + sbio->bio->bi_end_io = scrub_wr_bio_end_io; + sbio->bio->bi_iter.bi_sector = sbio->physical >>9 ; sbio->status =0 ; } else if (sbio->physical + sbio->page_count * sectorsize != spage->physical_for_dev_replace ||
@@ -1712,7 +1707,6 @@ static void scrub_wr_submit(struct scrub_ctx *sctx) sbio = sctx->wr_curr_bio; sctx->wr_curr_bio =NULL ; -WARN_ON (!sbio->bio->bi_bdev);scrub_pending_bio_inc (sctx);/* process all writes in a single worker thread. Then the block layer * orders the requests before sending them to the driver which
@@ -2084,22 +2078,17 @@ static int scrub_add_page_to_rd_bio(struct scrub_ctx *sctx, } sbio = sctx->bios[sctx->curr];if (sbio->page_count ==0 ) { -struct bio *bio; - sbio->physical = spage->physical; sbio->logical = spage->logical; sbio->dev = spage->dev; - bio = sbio->bio; -if (!bio) { - bio =btrfs_bio_alloc (sctx->pages_per_bio); - sbio->bio = bio; +if (!sbio->bio) { + sbio->bio =bio_alloc (sbio->dev->bdev, + sctx->pages_per_bio, +REQ_OP_READ ,GFP_NOFS ); } - - bio->bi_private = sbio; - bio->bi_end_io = scrub_bio_end_io; -bio_set_dev (bio, sbio->dev->bdev); - bio->bi_iter.bi_sector = sbio->physical >>9 ; - bio->bi_opf =REQ_OP_READ ; + sbio->bio->bi_private = sbio; + sbio->bio->bi_end_io = scrub_bio_end_io; + sbio->bio->bi_iter.bi_sector = sbio->physical >>9 ; sbio->status =0 ; } else if (sbio->physical + sbio->page_count * sectorsize != spage->physical ||
@@ -2215,7 +2204,7 @@ static void scrub_missing_raid56_pages(struct scrub_block *sblock) goto bioc_out; } - bio =btrfs_bio_alloc (BIO_MAX_VECS ); + bio =bio_alloc (NULL ,BIO_MAX_VECS ,REQ_OP_READ ,GFP_NOFS ); bio->bi_iter.bi_sector = logical >>9 ; bio->bi_private = sblock; bio->bi_end_io = scrub_missing_raid56_end_io;
@@ -2831,7 +2820,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)if (ret || !bioc || !bioc->raid_map) goto bioc_out; - bio =btrfs_bio_alloc (BIO_MAX_VECS ); + bio =bio_alloc (NULL ,BIO_MAX_VECS ,REQ_OP_READ ,GFP_NOFS ); 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.30.2
PATCH 12/12 btrfs: stop using the btrfs_bio saved iter in index_rbio_pages
In reply to Christoph HellwigThe bios added to ->bio_list are the original bios fed into btrfs_map_bio, which are never advanced. Just use the iter in the bio itself.
--- fs/btrfs/raid56.c | 3 --- 1 file changed, 3 deletions(-)
fs/btrfs/raid56.c +0 -3
@@ -1155,9 +1155,6 @@ static void index_rbio_pages(struct btrfs_raid_bio *rbio) stripe_offset = start - rbio->bioc->raid_map[0 ]; page_index = stripe_offset >>PAGE_SHIFT ; -if (bio_flagged (bio,BIO_CLONED )) - bio->bi_iter =btrfs_bio (bio)->iter; -bio_for_each_segment (bvec, bio, iter) { rbio->bio_pages[page_index + i] = bvec.bv_page; i++;
Signature · 1 line
2.30.2
Quoted 5 lines · Christoph Hellwig
Hi all,
this series moves btrfs to use the new as of 5.18 bio interface and cleans up a few close by areas. Larger cleanups focussed around the
btrfs_biowill follow as a next step.
I've looked at the previous batch of 40 patches which was doing some things I did not like (eg. removing the worker) but this subset are just cleanups and all seem to be fine. I'll add the series as topic branch to for-next and move misc-next. Thanks.
Quoted 11 lines · David Sterba
Quoted 5 lines · Christoph Hellwig
Hi all,
this series moves btrfs to use the new as of 5.18 bio interface and cleans up a few close by areas. Larger cleanups focussed around the
btrfs_biowill follow as a next step.I've looked at the previous batch of 40 patches which was doing some things I did not like (eg. removing the worker) but this subset are just cleanups and all seem to be fine. I'll add the series as topic branch to for-next and move misc-next. Thanks.
If it helps can rebase. And it would be really helpful to start a discussion on the things you did not like on the patches already on the list if you have a little time to spare.
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · David Sterba
Quoted 5 lines · Christoph Hellwig
Hi all,
this series moves btrfs to use the new as of 5.18 bio interface and cleans up a few close by areas. Larger cleanups focussed around the
btrfs_biowill follow as a next step.
Quoted 8 lines
Quoted 4 lines
I've looked at the previous batch of 40 patches which was doing some things I did not like (eg. removing the worker) but this subset are just cleanups and all seem to be fine. I'll add the series as topic branch to for-next and move misc-next. Thanks.
If it helps can rebase. And it would be really helpful to start a discussion on the things you did not like on the patches already on the list if you have a little time to spare.
I was able to resolve all the merge conflicts either manually or using the tool wiggle, no need to rebase. Regarding the whole patchset, I'll reply there. Right now I'm trying to merge all the easy or short series first, from the lower layers up in case there's a need to rebase.
Quoted 2 lines · David Sterba
I was able to resolve all the merge conflicts either manually or using the tool wiggle, no need to rebase.
No problem. What branch should I use as baseline? for-next seems to be merged from not otherwise visible branches so I'm not sure that is a good baseline.
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · David Sterba
I was able to resolve all the merge conflicts either manually or using the tool wiggle, no need to rebase.
No problem. What branch should I use as baseline? for-next seems to be merged from not otherwise visible branches so I'm not sure that is a good baseline.
Most (if not all) btrfs development happens based on misc-next which is at https://github.com/kdave/btrfs-devel.git misc-next
Quoted 7 lines · Johannes Thumshirn
Quoted 4 lines
No problem. What branch should I use as baseline? for-next seems to be merged from not otherwise visible branches so I'm not sure that is a good baseline.
Most (if not all) btrfs development happens based on misc-next which is at https://github.com/kdave/btrfs-devel.git misc-next
Eww. Having to track to it trees is a bit of a nightmare..