Extend bio_no_advance_iter() iteration to also increment the offset.
It's not currently needed because the currently listed request types
don't have a buffer, but will be useful once we add bios backed by
dma-buf, which don't have a bvec but work with a single range.

Suggested-by: Christoph Hellwig <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
 drivers/md/dm-io-rewind.c |  6 ++++--
 include/linux/bio.h       | 12 ++++++++----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/md/dm-io-rewind.c b/drivers/md/dm-io-rewind.c
index 04f3fc8aeb6f..b22719c6411c 100644
--- a/drivers/md/dm-io-rewind.c
+++ b/drivers/md/dm-io-rewind.c
@@ -113,10 +113,12 @@ static inline void dm_bio_rewind_iter(const struct bio 
*bio,
        iter->bi_sector -= bytes >> 9;
 
        /* No advance means no rewind */
-       if (bio_no_advance_iter(bio))
+       if (bio_no_advance_iter(bio)) {
                iter->bi_size += bytes;
-       else
+               iter->bi_offset -= bytes;
+       } else {
                dm_bvec_iter_rewind(bio->bi_io_vec, iter, bytes);
+       }
 }
 
 /**
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 8f33f717b14f..dea9f567379d 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -113,11 +113,13 @@ static inline void bio_advance_iter(const struct bio *bio,
 {
        iter->bi_sector += bytes >> 9;
 
-       if (bio_no_advance_iter(bio))
+       if (bio_no_advance_iter(bio)) {
                iter->bi_size -= bytes;
-       else
+               iter->bi_offset += bytes;
+       } else {
                bvec_iter_advance(bio->bi_io_vec, iter, bytes);
                /* TODO: It is reasonable to complete bio with error here. */
+       }
 }
 
 /* @bytes should be less or equal to bvec[i->bi_idx].bv_len */
@@ -127,10 +129,12 @@ static inline void bio_advance_iter_single(const struct 
bio *bio,
 {
        iter->bi_sector += bytes >> 9;
 
-       if (bio_no_advance_iter(bio))
+       if (bio_no_advance_iter(bio)) {
                iter->bi_size -= bytes;
-       else
+               iter->bi_offset += bytes;
+       } else {
                bvec_iter_advance_single(bio->bi_io_vec, iter, bytes);
+       }
 }
 
 void __bio_advance(struct bio *, unsigned bytes);
-- 
2.54.0


Reply via email to