diff mbox series

[7/8] btrfs: add a helper to iterate through a btrfs_bio with sector sized chunks

Message ID 20220522114754.173685-8-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/8] btrfs: quit early if the fs has no RAID56 support for raid56 related checks | expand

Commit Message

Christoph Hellwig May 22, 2022, 11:47 a.m. UTC
From: Qu Wenruo <wqu@suse.com>

Add a helper that works similar to __bio_for_each_segment, but instead of
iterating over PAGE_SIZE chunks it iterates over each sector.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[hch: split from a larger patch, and iterate over the offset instead of
      the offset bits]
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/volumes.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Nikolay Borisov May 26, 2022, 12:58 p.m. UTC | #1
On 22.05.22 г. 14:47 ч., Christoph Hellwig wrote:
> From: Qu Wenruo <wqu@suse.com>
> 
> Add a helper that works similar to __bio_for_each_segment, but instead of
> iterating over PAGE_SIZE chunks it iterates over each sector.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> [hch: split from a larger patch, and iterate over the offset instead of
>        the offset bits]
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 12b2af9260e92..6f784d4f54664 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -391,6 +391,18 @@  static inline void btrfs_bio_free_csum(struct btrfs_bio *bbio)
 	}
 }
 
+/*
+ * Iterate through a btrfs_bio (@bbio) on a per-sector basis.
+ */
+#define btrfs_bio_for_each_sector(fs_info, bvl, bbio, iter, bio_offset)	\
+	for ((iter) = (bbio)->iter, (bio_offset) = 0;			\
+	     (iter).bi_size &&					\
+	     (((bvl) = bio_iter_iovec((&(bbio)->bio), (iter))), 1);	\
+	     (bio_offset) += fs_info->sectorsize,			\
+	     bio_advance_iter_single(&(bbio)->bio, &(iter),		\
+	     (fs_info)->sectorsize))
+
+
 struct btrfs_io_stripe {
 	struct btrfs_device *dev;
 	u64 physical;