[PATCH v6 03/10] iomap: refactor iomap_iter() length check and tracepoint

Brian Foster
2025-02-07T14:30:36Z

iomap_iter() checks iomap.length to skip individual code blocks not
appropriate for the initial case where there is no mapping in the
iter. To prepare for upcoming changes, refactor the code to jump
straight to the ->iomap_begin() handler in the initial case and move
the tracepoint to the top of the function so it always executes.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
---
fs/iomap/iter.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c
index 731ea7267f27..a2ae99fe6431 100644
--- a/fs/iomap/iter.c
+++ b/fs/iomap/iter.c
@@ -73,7 +73,12 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
{
int ret;

- if (iter->iomap.length && ops->iomap_end) {
+ trace_iomap_iter(iter, ops, _RET_IP_);
+
+ if (!iter->iomap.length)
+ goto begin;
+
+ if (ops->iomap_end) {
ret = ops->iomap_end(iter->inode, iter->pos, iomap_length(iter),
iter->processed > 0 ? iter->processed : 0,
iter->flags, &iter->iomap);
@@ -82,14 +87,12 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
}

/* advance and clear state from the previous iteration */
- trace_iomap_iter(iter, ops, _RET_IP_);
- if (iter->iomap.length) {
- ret = iomap_iter_advance(iter, iter->processed);
- iomap_iter_reset_iomap(iter);
- if (ret <= 0)
- return ret;
- }
+ ret = iomap_iter_advance(iter, iter->processed);
+ iomap_iter_reset_iomap(iter);
+ if (ret <= 0)
+ return ret;

+begin:
ret = ops->iomap_begin(iter->inode, iter->pos, iter->len, iter->flags,
&iter->iomap, &iter->srcmap);
if (ret < 0)
--
2.48.1