]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: introduce btrfs_bio_for_each_block_all() helper
authorQu Wenruo <wqu@suse.com>
Tue, 2 Sep 2025 07:15:02 +0000 (16:45 +0930)
committerDavid Sterba <dsterba@suse.com>
Tue, 23 Sep 2025 06:49:17 +0000 (08:49 +0200)
commit7425a2894019778460e65d24e8adfaeddac3b3b1
tree069585a1948a606596cb6f9e4174eba58d75dead
parent9afc617265383f591614e94b702d558dfb1519c0
btrfs: introduce btrfs_bio_for_each_block_all() helper

Currently if we want to iterate all blocks inside a bio, we do something
like this:

bio_for_each_segment_all(bvec, bio, iter_all) {
for (off = 0; off < bvec->bv_len; off += sectorsize) {
/* Iterate blocks using bv + off */
}
}

That's fine for now, but it will not handle future bs > ps, as
bio_for_each_segment_all() is a single-page iterator, it will always
return a bvec that's no larger than a page.

But for bs > ps cases, we need a full folio (which covers at least one
block) so that we can work on the block.

To address this problem and handle future bs > ps cases better:

- Introduce a helper btrfs_bio_for_each_block_all()
  This helper will create a local bvec_iter, which has the size of the
  target bio. Then grab the current physical address of the current
  location, then advance the iterator by block size.

- Use btrfs_bio_for_each_block_all() to replace existing call sites
  Including:

  * set_bio_pages_uptodate() in raid56
  * verify_bio_data_sectors() in raid56

  Both will result much easier to read code.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/misc.h
fs/btrfs/raid56.c