public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/2] btrfs: introduce a common helper to calculate the size of a bio
Date: Wed, 25 Feb 2026 01:59:18 +0100	[thread overview]
Message-ID: <20260225005918.GD26902@suse.cz> (raw)
In-Reply-To: <b040a823-cfe7-42b2-97b4-3f6ba80f98d1@gmx.com>

On Wed, Feb 25, 2026 at 07:32:48AM +1030, Qu Wenruo wrote:
> 在 2026/2/25 00:45, David Sterba 写道:
> > On Fri, Feb 20, 2026 at 02:11:50PM +1030, Qu Wenruo wrote:
> >> We have several call sites doing the same work to calculate the size of
> >> a bio:
> >>
> >> 	struct bio_vec *bvec;
> >> 	u32 bio_size = 0;
> >> 	int i;
> >>
> >> 	bio_for_each_bvec_all(bvec, bio, i)
> >> 		bio_size += bvec->bv_len;
> >>
> >> We can use a common helper instead of open-coding it everywhere.
> >>
> >> This also allows us to constify the @bio_size variables used in all the
> >> call sites.
> >>
> >> Signed-off-by: Qu Wenruo <wqu@suse.com>
> >> ---
> >>   fs/btrfs/misc.h   | 15 +++++++++++----
> >>   fs/btrfs/raid56.c |  9 ++-------
> >>   fs/btrfs/scrub.c  | 22 ++++------------------
> >>   3 files changed, 17 insertions(+), 29 deletions(-)
> >>
> >> diff --git a/fs/btrfs/misc.h b/fs/btrfs/misc.h
> >> index 12c5a9d6564f..189c25cc5eff 100644
> >> --- a/fs/btrfs/misc.h
> >> +++ b/fs/btrfs/misc.h
> >> @@ -52,15 +52,22 @@ static inline phys_addr_t bio_iter_phys(struct bio *bio, struct bvec_iter *iter)
> >>   	     (paddr = bio_iter_phys((bio), (iter)), 1);			\
> >>   	     bio_advance_iter_single((bio), (iter), (blocksize)))
> >>   
> >> -/* Initialize a bvec_iter to the size of the specified bio. */
> >> -static inline struct bvec_iter init_bvec_iter_for_bio(struct bio *bio)
> >> +/* Can only be called on a non-cloned bio. */
> > 
> > Please also add an ASSERT for that.
> 
> You know how I like to add ASSERT()s almost everywhere, but for this 
> it's already implied.
> 
> bio_first_bvec_all() has a WARN_ON_ONCE() line for it already.

Ok that's good, I didn't know that.

  reply	other threads:[~2026-02-25  0:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-20  3:41 [PATCH 0/2] btrfs: remove compressed_bio::compressed_len Qu Wenruo
2026-02-20  3:41 ` [PATCH 1/2] btrfs: introduce a common helper to calculate the size of a bio Qu Wenruo
2026-02-24 14:15   ` David Sterba
2026-02-24 21:02     ` Qu Wenruo
2026-02-25  0:59       ` David Sterba [this message]
2026-02-24 22:21     ` Qu Wenruo
2026-02-20  3:41 ` [PATCH 2/2] btrfs: reduce the size of compressed_bio Qu Wenruo
2026-02-24 14:35   ` 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=20260225005918.GD26902@suse.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.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