public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Christoph Hellwig <hch@lst.de>, Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 5/8] btrfs: simplify bvec iteration in index_one_bio
Date: Fri, 18 Apr 2025 11:39:41 +0930	[thread overview]
Message-ID: <d6fa1d98-4b4b-4e40-937f-3854fb2a91e5@gmx.com> (raw)
In-Reply-To: <20250409111055.3640328-6-hch@lst.de>



在 2025/4/9 20:40, Christoph Hellwig 写道:
> Flatten the two loops by open coding bio_for_each_segment and advancing
> the iterator one sector at a time.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   fs/btrfs/raid56.c | 21 +++++++++------------
>   1 file changed, 9 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
> index 28dbded86cc2..703e713bac03 100644
> --- a/fs/btrfs/raid56.c
> +++ b/fs/btrfs/raid56.c
> @@ -1195,23 +1195,20 @@ static int rbio_add_io_sector(struct btrfs_raid_bio *rbio,
>   static void index_one_bio(struct btrfs_raid_bio *rbio, struct bio *bio)
>   {
>   	const u32 sectorsize = rbio->bioc->fs_info->sectorsize;
> -	struct bio_vec bvec;
> -	struct bvec_iter iter;
> +	struct bvec_iter iter = bio->bi_iter;
>   	u32 offset = (bio->bi_iter.bi_sector << SECTOR_SHIFT) -
>   		     rbio->bioc->full_stripe_logical;
>   
> -	bio_for_each_segment(bvec, bio, iter) {
> -		u32 bvec_offset;
> +	while (iter.bi_size) {
> +		int index = offset / sectorsize;

The value @offset is no longer updated, this means only the first sector 
of the current bio will be updated, and it's updated several times, 
resulting incorrect location.

Furthermore, for full stripe write since we do not allocate pages for 
the stripes_pages[], we will got incorrect bio_sectors[] pointing to NULL.

This will crash rmw_rbio(), easily reproduced by btrfs/011.

I'll also fix it in my local branch.

Thanks,
Qu

> +		struct sector_ptr *sector = &rbio->bio_sectors[index];
> +		struct bio_vec bv = bio_iter_iovec(bio, iter);
>   
> -		for (bvec_offset = 0; bvec_offset < bvec.bv_len;
> -		     bvec_offset += sectorsize, offset += sectorsize) {
> -			int index = offset / sectorsize;
> -			struct sector_ptr *sector = &rbio->bio_sectors[index];
> +		sector->page = bv.bv_page;
> +		sector->pgoff = bv.bv_offset;
> +		ASSERT(sector->pgoff < PAGE_SIZE);
>   
> -			sector->page = bvec.bv_page;
> -			sector->pgoff = bvec.bv_offset + bvec_offset;
> -			ASSERT(sector->pgoff < PAGE_SIZE);
> -		}
> +		bio_advance_iter_single(bio, &iter, sectorsize);
>   	}
>   }
>   


  reply	other threads:[~2025-04-18  2:09 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-09 11:10 RFC: (almost) stop poking into bvec internals in btrfs Christoph Hellwig
2025-04-09 11:10 ` [PATCH 1/8] btrfs: remove the alignment checks in end_bbio_data_read Christoph Hellwig
2025-04-09 22:13   ` Qu Wenruo
2025-04-10  5:30     ` Christoph Hellwig
2025-04-10  5:39       ` Qu Wenruo
2025-04-09 11:10 ` [PATCH 2/8] btrfs: track the next file offset in struct btrfs_bio_ctrl Christoph Hellwig
2025-04-09 22:15   ` Qu Wenruo
2025-04-09 11:10 ` [PATCH 3/8] btrfs: pass a physical address to btrfs_repair_io_failure Christoph Hellwig
2025-04-09 22:19   ` Qu Wenruo
2025-04-10  5:31     ` Christoph Hellwig
2025-04-10  6:06   ` Johannes Thumshirn
2025-04-10  6:17     ` hch
2025-04-09 11:10 ` [PATCH 4/8] btrfs: move kmapping out of btrfs_check_sector_csum Christoph Hellwig
2025-04-10  6:16   ` Johannes Thumshirn
2025-04-16  4:51   ` Qu Wenruo
2025-04-09 11:10 ` [PATCH 5/8] btrfs: simplify bvec iteration in index_one_bio Christoph Hellwig
2025-04-18  2:09   ` Qu Wenruo [this message]
2025-04-09 11:10 ` [PATCH 6/8] btrfs: store a kernel virtual address in struct sector_ptr Christoph Hellwig
2025-04-09 22:34   ` Qu Wenruo
2025-04-10  5:34     ` Christoph Hellwig
2025-04-14  3:04       ` Qu Wenruo
2025-04-17 23:41         ` Qu Wenruo
2025-04-09 11:10 ` [PATCH 7/8] btrfs: refactor getting the address of a stripe sector Christoph Hellwig
2025-04-09 22:38   ` Qu Wenruo
2025-04-19  1:01   ` Qu Wenruo
2025-04-09 11:10 ` [PATCH 8/8] btrfs: use bvec_kmap_local in btrfs_decompress_buf2page 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=d6fa1d98-4b4b-4e40-937f-3854fb2a91e5@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=hch@lst.de \
    --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