@@ -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);
}
/**
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(-)