diff mbox series

[v2,2/7] iomap: factor out iomap length helper

Message ID 20250122133434.535192-3-bfoster@redhat.com (mailing list archive)
State New
Headers show
Series iomap: incremental per-operation iter advance | expand

Commit Message

Brian Foster Jan. 22, 2025, 1:34 p.m. UTC
In preparation to support more granular iomap iter advancing, factor
the pos/len values as parameters to length calculation.

Signed-off-by: Brian Foster <bfoster@redhat.com>
---
 include/linux/iomap.h | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 75bf54e76f3b..b6f7d96156f2 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -230,6 +230,16 @@  struct iomap_iter {
 
 int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops);
 
+static inline u64 iomap_length_trim(const struct iomap_iter *iter, loff_t pos,
+		u64 len)
+{
+	u64 end = iter->iomap.offset + iter->iomap.length;
+
+	if (iter->srcmap.type != IOMAP_HOLE)
+		end = min(end, iter->srcmap.offset + iter->srcmap.length);
+	return min(len, end - pos);
+}
+
 /**
  * iomap_length - length of the current iomap iteration
  * @iter: iteration structure
@@ -238,11 +248,7 @@  int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops);
  */
 static inline u64 iomap_length(const struct iomap_iter *iter)
 {
-	u64 end = iter->iomap.offset + iter->iomap.length;
-
-	if (iter->srcmap.type != IOMAP_HOLE)
-		end = min(end, iter->srcmap.offset + iter->srcmap.length);
-	return min(iter->len, end - iter->pos);
+	return iomap_length_trim(iter, iter->pos, iter->len);
 }
 
 /**