]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: add a helper to iterate through a btrfs_bio with sector sized chunks
authorQu Wenruo <wqu@suse.com>
Sun, 22 May 2022 11:47:53 +0000 (13:47 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 Jul 2022 15:44:34 +0000 (17:44 +0200)
Add a helper that works similar to __bio_for_each_segment, but instead of
iterating over PAGE_SIZE chunks it iterates over each sector.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
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: David Sterba <dsterba@suse.com>
[ add parameter comments ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.h

index 6721002000ee0fc0cb69ec727c19189783cea40f..1e86c48268eddef2222ae5545b667b96ee2a5058 100644 (file)
@@ -391,6 +391,22 @@ static inline void btrfs_bio_free_csum(struct btrfs_bio *bbio)
        }
 }
 
+/*
+ * Iterate through a btrfs_bio (@bbio) on a per-sector basis.
+ *
+ * bvl        - struct bio_vec
+ * bbio       - struct btrfs_bio
+ * iters      - struct bvec_iter
+ * bio_offset - unsigned int
+ */
+#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;