All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v3 09/12] btrfs: scrub: introduce a writeback helper for scrub_stripe
Date: Tue, 21 Mar 2023 01:43:38 +0100	[thread overview]
Message-ID: <20230321004338.GM10580@twin.jikos.cz> (raw)
In-Reply-To: <40123ebdfdaabedf0d2811e64b28766e38de4148.1679278088.git.wqu@suse.com>

On Mon, Mar 20, 2023 at 10:12:55AM +0800, Qu Wenruo wrote:
> +static void scrub_write_endio(struct btrfs_bio *bbio)
> +{
> +	struct scrub_stripe *stripe = bbio->private;
> +	struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
> +	struct bio_vec *bvec;
> +	unsigned long flags;
> +	int sector_nr = calc_sector_number(stripe, bio_first_bvec_all(&bbio->bio));
> +	int bio_size = 0;
> +	int i;
> +
> +	bio_for_each_bvec_all(bvec, &bbio->bio, i)
> +		bio_size += bvec->bv_len;

The types should match, bv_len is u32 so it should be summed to a u32
type (bio_size).

> +
> +	if (bbio->bio.bi_status) {
> +		spin_lock_irqsave(&stripe->write_error_lock, flags);
> +		bitmap_set(&stripe->write_error_bitmap, sector_nr,
> +				bio_size >> fs_info->sectorsize_bits);
> +		spin_unlock_irqrestore(&stripe->write_error_lock, flags);
> +	}
> +	bio_put(&bbio->bio);
> +
> +	if (atomic_dec_and_test(&stripe->pending_io))
> +		wake_up(&stripe->io_wait);
> +}
> +
> +/*
> + * Submit the write bio(s) for the sectors specified by @write_bitmap.
> + *
> + * Here we utilize btrfs_submit_scrub_write(), which has some extra benefits:
> + *
> + * - Only needs logical bytenr and mirror_num
> + *   Just like the scrub read path
> + *
> + * - Would only result writes to the specified mirror
> + *   Unlike the regular writeback path, which would write back to all stripes
> + *
> + * - Handle dev-replace and read-repair writeback differently
> + */
> +void scrub_write_sectors(struct scrub_ctx *sctx,
> +			struct scrub_stripe *stripe,
> +			unsigned long write_bitmap, bool dev_replace)
> +{
> +	struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
> +	struct btrfs_bio *bbio = NULL;
> +	bool zoned = btrfs_is_zoned(fs_info);
> +	int sector_nr;
> +
> +	for_each_set_bit(sector_nr, &write_bitmap, stripe->nr_sectors) {
> +		struct page *page = scrub_stripe_get_page(stripe, sector_nr);
> +		unsigned int pgoff = scrub_stripe_get_page_offset(stripe,
> +								  sector_nr);
> +		int ret;
> +
> +		/* We should only writeback sectors covered by an extent. */
> +		ASSERT(test_bit(sector_nr, &stripe->extent_sector_bitmap));
> +
> +		/* Can not merge with previous sector, submit the current one. */
> +		if (bbio && sector_nr && !test_bit(sector_nr - 1, &write_bitmap)) {
> +			fill_writer_pointer_gap(sctx, stripe->physical +
> +					(sector_nr << fs_info->sectorsize_bits));
> +			atomic_inc(&stripe->pending_io);
> +			btrfs_submit_scrub_write(fs_info, bbio,
> +						 stripe->mirror_num, dev_replace);
> +			/* For zoned writeback, QD must be 1. */

QD means queue depth? I'd rather spell it out, QD is not a common
abbreviation in our code.

> +			if (zoned)
> +				wait_scrub_stripe_io(stripe);
> +			bbio = NULL;
> +		}
> +		if (!bbio) {
> +			bbio = btrfs_bio_alloc(BTRFS_STRIPE_LEN >> PAGE_SHIFT,

					       SCRUB_STRIPE_PAGES

> +					REQ_OP_WRITE, NULL, scrub_write_endio, stripe);
> +			/* Backed by mempool */
> +			ASSERT(bbio);

Not sure if this is the first that does it but we could drop the comment
and assert around btrfs_bio_alloc because it's documented in the
function.

> +
> +			bbio->bio.bi_iter.bi_sector = (stripe->logical +
> +				(sector_nr << fs_info->sectorsize_bits)) >>
> +				SECTOR_SHIFT;
> +		}
> +		ret = bio_add_page(&bbio->bio, page, fs_info->sectorsize, pgoff);
> +		ASSERT(ret == fs_info->sectorsize);
> +	}
> +	if (bbio) {
> +		fill_writer_pointer_gap(sctx, bbio->bio.bi_iter.bi_sector <<
> +					SECTOR_SHIFT);
> +		atomic_inc(&stripe->pending_io);
> +		btrfs_submit_scrub_write(fs_info, bbio, stripe->mirror_num,
> +					 dev_replace);
> +		if (zoned)
> +			wait_scrub_stripe_io(stripe);
> +	}
> +}

  reply	other threads:[~2023-03-21  0:51 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-20  2:12 [PATCH v3 00/12] btrfs: scrub: use a more reader friendly code to implement scrub_simple_mirror() Qu Wenruo
2023-03-20  2:12 ` [PATCH v3 01/12] btrfs: scrub: use dedicated super block verification function to scrub one super block Qu Wenruo
2023-03-21  5:22   ` Anand Jain
2023-03-21  7:25     ` Qu Wenruo
2023-03-21 22:12       ` David Sterba
2023-03-20  2:12 ` [PATCH v3 02/12] btrfs: introduce a new helper to submit bio for scrub Qu Wenruo
2023-03-21 12:02   ` Christoph Hellwig
2023-03-24  9:58     ` Qu Wenruo
2023-03-25  8:09       ` Christoph Hellwig
2023-03-25  8:21         ` Qu Wenruo
2023-03-25  8:31           ` Christoph Hellwig
2023-03-25  8:48             ` Qu Wenruo
2023-03-27  3:36               ` Christoph Hellwig
2023-03-20  2:12 ` [PATCH v3 03/12] btrfs: introduce a new helper to submit write " Qu Wenruo
2023-03-21  0:14   ` David Sterba
2023-03-21  0:54     ` Qu Wenruo
2023-03-21  1:27       ` David Sterba
2023-03-23  8:48     ` Qu Wenruo
2023-03-20  2:12 ` [PATCH v3 04/12] btrfs: scrub: introduce the structure for new BTRFS_STRIPE_LEN based interface Qu Wenruo
2023-03-21  0:22   ` David Sterba
2023-03-20  2:12 ` [PATCH v3 05/12] btrfs: scrub: introduce a helper to find and fill the sector info for a scrub_stripe Qu Wenruo
2023-03-20  2:12 ` [PATCH v3 06/12] btrfs: scrub: introduce a helper to verify one metadata Qu Wenruo
2023-03-21  0:31   ` David Sterba
2023-03-20  2:12 ` [PATCH v3 07/12] btrfs: scrub: introduce a helper to verify one scrub_stripe Qu Wenruo
2023-03-20  2:12 ` [PATCH v3 08/12] btrfs: scrub: introduce the main read repair worker for scrub_stripe Qu Wenruo
2023-03-20  2:12 ` [PATCH v3 09/12] btrfs: scrub: introduce a writeback helper " Qu Wenruo
2023-03-21  0:43   ` David Sterba [this message]
2023-03-20  2:12 ` [PATCH v3 10/12] btrfs: scrub: introduce error reporting functionality " Qu Wenruo
2023-03-20  2:12 ` [PATCH v3 11/12] btrfs: scrub: introduce the helper to queue a stripe for scrub Qu Wenruo
2023-03-20  2:12 ` [PATCH v3 12/12] btrfs: scrub: switch scrub_simple_mirror() to scrub_stripe infrastructure Qu Wenruo
2023-03-21  1:12   ` David Sterba
2023-03-21  0:09 ` [PATCH v3 00/12] btrfs: scrub: use a more reader friendly code to implement scrub_simple_mirror() David Sterba
2023-03-23  6:28   ` Qu Wenruo
2023-03-23 17:51     ` David Sterba
2023-03-24  0:42       ` Qu Wenruo
2023-03-27 23:28         ` David Sterba

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=20230321004338.GM10580@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.