iomap: factor out iomap length helper
authorBrian Foster <bfoster@redhat.com>
Fri, 7 Feb 2025 14:32:44 +0000 (09:32 -0500)
committerChristian Brauner <brauner@kernel.org>
Mon, 10 Feb 2025 11:46:33 +0000 (12:46 +0100)
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>
Link: https://lore.kernel.org/r/20250207143253.314068-2-bfoster@redhat.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/iomap.h

index 022d7f338c68df71619aa1a873655e970d8bb3b0..feb748eb629451d1504f5c1d7cc3a46ec833b3a7 100644 (file)
@@ -238,18 +238,33 @@ struct iomap_iter {
 int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops);
 
 /**
- * iomap_length - length of the current iomap iteration
+ * iomap_length_trim - trimmed length of the current iomap iteration
  * @iter: iteration structure
+ * @pos: File position to trim from.
+ * @len: Length of the mapping to trim to.
  *
- * Returns the length that the operation applies to for the current iteration.
+ * Returns a trimmed length that the operation applies to for the current
+ * iteration.
  */
-static inline u64 iomap_length(const struct iomap_iter *iter)
+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(iter->len, end - iter->pos);
+       return min(len, end - pos);
+}
+
+/**
+ * iomap_length - length of the current iomap iteration
+ * @iter: iteration structure
+ *
+ * Returns the length that the operation applies to for the current iteration.
+ */
+static inline u64 iomap_length(const struct iomap_iter *iter)
+{
+       return iomap_length_trim(iter, iter->pos, iter->len);
 }
 
 /**