From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Christoph Hellwig <hch@lst.de>,
Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>, Qu Wenruo <wqu@suse.com>
Cc: Naohiro Aota <naohiro.aota@wdc.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 01/12] btrfs: refactor __btrfsic_submit_bio
Date: Fri, 8 Apr 2022 15:22:29 +0800 [thread overview]
Message-ID: <27e9d39c-3546-7be3-31af-2e41ece556a7@gmx.com> (raw)
In-Reply-To: <20220408050839.239113-2-hch@lst.de>
On 2022/4/8 13:08, Christoph Hellwig wrote:
> Split out two helpers to mak __btrfsic_submit_bio more readable.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
The refactor itself is already pretty good.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/check-integrity.c | 150 +++++++++++++++++++------------------
> 1 file changed, 78 insertions(+), 72 deletions(-)
>
> diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
> index b8f9dfa326207..ec8a73ff82717 100644
> --- a/fs/btrfs/check-integrity.c
> +++ b/fs/btrfs/check-integrity.c
> @@ -2633,6 +2633,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;
> @@ -2640,80 +2708,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);
> }
>
next prev parent reply other threads:[~2022-04-08 7:22 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-08 5:08 cleanup btrfs bio handling, part 1 v2 Christoph Hellwig
2022-04-08 5:08 ` [PATCH 01/12] btrfs: refactor __btrfsic_submit_bio Christoph Hellwig
2022-04-08 7:22 ` Qu Wenruo [this message]
2022-04-08 5:08 ` [PATCH 02/12] btrfs: split submit_bio from btrfsic checking Christoph Hellwig
2022-04-08 5:08 ` [PATCH 03/12] btrfs: simplify btrfsic_read_block Christoph Hellwig
2022-04-08 7:23 ` Qu Wenruo
2022-04-08 5:08 ` [PATCH 04/12] btrfs: simplify repair_io_failure Christoph Hellwig
2022-04-08 5:08 ` [PATCH 05/12] btrfs: simplify scrub_recheck_block Christoph Hellwig
2022-04-08 5:08 ` [PATCH 06/12] btrfs: simplify scrub_repair_page_from_good_copy Christoph Hellwig
2022-04-08 5:08 ` [PATCH 07/12] btrfs: move the call to bio_set_dev out of submit_stripe_bio Christoph Hellwig
2022-04-08 7:27 ` Qu Wenruo
2022-04-08 13:27 ` David Sterba
2022-04-08 5:08 ` [PATCH 08/12] btrfs: pass a block_device to btrfs_bio_clone Christoph Hellwig
2022-04-08 5:08 ` [PATCH 09/12] btrfs: initialize ->bi_opf and ->bi_private in rbio_add_io_page Christoph Hellwig
2022-04-08 5:08 ` [PATCH 10/12] btrfs: don't allocate a btrfs_bio for raid56 per-stripe bios Christoph Hellwig
2022-04-08 5:08 ` [PATCH 11/12] btrfs: don't allocate a btrfs_bio for scrub bios Christoph Hellwig
2022-04-08 5:08 ` [PATCH 12/12] btrfs: stop using the btrfs_bio saved iter in index_rbio_pages Christoph Hellwig
2022-04-08 7:37 ` Qu Wenruo
2022-04-08 16:00 ` cleanup btrfs bio handling, part 1 v2 David Sterba
-- strict thread matches above, loose matches on Subject: below --
2022-04-04 4:45 cleanup btrfs bio handling, part 1 Christoph Hellwig
2022-04-04 4:45 ` [PATCH 01/12] btrfs: refactor __btrfsic_submit_bio Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=27e9d39c-3546-7be3-31af-2e41ece556a7@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=dsterba@suse.com \
--cc=hch@lst.de \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=naohiro.aota@wdc.com \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox