iomap: factor out iomap length helper

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>
This commit is contained in:
Brian Foster 2025-02-07 09:32:44 -05:00 committed by Christian Brauner
parent f87897339a
commit abb0ea1923
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2

View File

@ -237,6 +237,25 @@ struct iomap_iter {
int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops);
/**
* 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 a trimmed length that the operation applies to for the current
* iteration.
*/
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
@ -245,11 +264,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);
}
/**