linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: dsterba@suse.cz, Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v3 03/12] btrfs: introduce a new helper to submit write bio for scrub
Date: Tue, 21 Mar 2023 08:54:22 +0800	[thread overview]
Message-ID: <900424d7-0659-aabd-4456-277b60e808e8@gmx.com> (raw)
In-Reply-To: <20230321001445.GJ10580@twin.jikos.cz>



On 2023/3/21 08:14, David Sterba wrote:
> On Mon, Mar 20, 2023 at 10:12:49AM +0800, Qu Wenruo wrote:
>> diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
>> index b96f40160b08..633447b6ba44 100644
>> --- a/fs/btrfs/bio.c
>> +++ b/fs/btrfs/bio.c
>> +	/* Map the RAID56 multi-stripe writes to a single one. */
>> +	if (bioc->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
>> +		int data_stripes = bioc->map_type & BTRFS_BLOCK_GROUP_RAID5 ?
>> +				   bioc->num_stripes - 1 : bioc->num_stripes - 2;
> 
> When ternary operator is used in expression, please put ( ) around it so
> it's clear where it starts.
> 
>> +		int i;
>> +
>> +		/* This special write only works for data stripes. */
>> +		ASSERT(mirror_num == 1);
>> +		for (i = 0; i < data_stripes; i++) {
> 
> 		for (int i = 0; ...)
> 
> We can now use the iterator value defined inside for (), it's relatively
> new due to bumped minimum compiler version so I'd like to see it used
> where possible.

Just one question.

There are quite some for loops in the last few patches.

In that case, should we still go the "for (int i = 0;...)" way?
Or it's better to declare "i" as the old way?

Thanks,
Qu

> 
>> +			u64 stripe_start = bioc->full_stripe_logical +
>> +					   (i << BTRFS_STRIPE_LEN_SHIFT);
>> +
>> +			if (logical >= stripe_start &&
>> +			    logical < stripe_start + BTRFS_STRIPE_LEN)
>> +				break;
>> +		}
>> +		ASSERT(i < data_stripes);
>> +		smap.dev = bioc->stripes[i].dev;
>> +		smap.physical = bioc->stripes[i].physical +
>> +				((logical - bioc->full_stripe_logical) &
>> +				 BTRFS_STRIPE_LEN_MASK);
>> +		goto submit;
>> +	}
>> +	ASSERT(mirror_num <= bioc->num_stripes);
>> +	smap.dev = bioc->stripes[mirror_num - 1].dev;
>> +	smap.physical = bioc->stripes[mirror_num - 1].physical;
>> +submit:
>> +	ASSERT(smap.dev);
>> +	btrfs_put_bioc(bioc);
>> +	bioc = NULL;
>> +	if (dev_replace) {
>> +		ASSERT(smap.dev == fs_info->dev_replace.srcdev);
>> +		smap.dev = fs_info->dev_replace.tgtdev;
>> +	}
>> +	__btrfs_submit_bio(&bbio->bio, bioc, &smap, mirror_num);
>> +	return;
>> +
>> +fail:
>> +	btrfs_bio_counter_dec(fs_info);
>> +	btrfs_bio_end_io(orig_bbio, ret);
>> +}

  reply	other threads:[~2023-03-21  0:54 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 [this message]
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
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=900424d7-0659-aabd-4456-277b60e808e8@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).