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@xxxxxxxxxx> --- include/linux/iomap.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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); } /** -- 2.47.1