Skip to content

Commit 2e4b0b6

Browse files
Brian Fosterbrauner
authored andcommitted
iomap: split out iomap check and reset logic from iter advance
In preparation for more granular iomap_iter advancing, break out some of the logic associated with higher level iteration from iomap_advance_iter(). Specifically, factor the iomap reset code into a separate helper and lift the iomap.length check into the calling code, similar to how ->iomap_end() calls are handled. Signed-off-by: Brian Foster <bfoster@redhat.com> Link: https://lore.kernel.org/r/20250207143253.314068-3-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>
1 parent abb0ea1 commit 2e4b0b6

1 file changed

Lines changed: 26 additions & 23 deletions

File tree

fs/iomap/iter.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,38 @@
77
#include <linux/iomap.h>
88
#include "trace.h"
99

10+
static inline void iomap_iter_reset_iomap(struct iomap_iter *iter)
11+
{
12+
iter->processed = 0;
13+
memset(&iter->iomap, 0, sizeof(iter->iomap));
14+
memset(&iter->srcmap, 0, sizeof(iter->srcmap));
15+
}
16+
1017
/*
1118
* Advance to the next range we need to map.
1219
*
1320
* If the iomap is marked IOMAP_F_STALE, it means the existing map was not fully
1421
* processed - it was aborted because the extent the iomap spanned may have been
1522
* changed during the operation. In this case, the iteration behaviour is to
1623
* remap the unprocessed range of the iter, and that means we may need to remap
17-
* even when we've made no progress (i.e. iter->processed = 0). Hence the
18-
* "finished iterating" case needs to distinguish between
19-
* (processed = 0) meaning we are done and (processed = 0 && stale) meaning we
20-
* need to remap the entire remaining range.
24+
* even when we've made no progress (i.e. count = 0). Hence the "finished
25+
* iterating" case needs to distinguish between (count = 0) meaning we are done
26+
* and (count = 0 && stale) meaning we need to remap the entire remaining range.
2127
*/
22-
static inline int iomap_iter_advance(struct iomap_iter *iter)
28+
static inline int iomap_iter_advance(struct iomap_iter *iter, s64 count)
2329
{
2430
bool stale = iter->iomap.flags & IOMAP_F_STALE;
2531
int ret = 1;
2632

27-
/* handle the previous iteration (if any) */
28-
if (iter->iomap.length) {
29-
if (iter->processed < 0)
30-
return iter->processed;
31-
if (WARN_ON_ONCE(iter->processed > iomap_length(iter)))
32-
return -EIO;
33-
iter->pos += iter->processed;
34-
iter->len -= iter->processed;
35-
if (!iter->len || (!iter->processed && !stale))
36-
ret = 0;
37-
}
33+
if (count < 0)
34+
return count;
35+
if (WARN_ON_ONCE(count > iomap_length(iter)))
36+
return -EIO;
37+
iter->pos += count;
38+
iter->len -= count;
39+
if (!iter->len || (!count && !stale))
40+
ret = 0;
3841

39-
/* clear the per iteration state */
40-
iter->processed = 0;
41-
memset(&iter->iomap, 0, sizeof(iter->iomap));
42-
memset(&iter->srcmap, 0, sizeof(iter->srcmap));
4342
return ret;
4443
}
4544

@@ -82,10 +81,14 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
8281
return ret;
8382
}
8483

84+
/* advance and clear state from the previous iteration */
8585
trace_iomap_iter(iter, ops, _RET_IP_);
86-
ret = iomap_iter_advance(iter);
87-
if (ret <= 0)
88-
return ret;
86+
if (iter->iomap.length) {
87+
ret = iomap_iter_advance(iter, iter->processed);
88+
iomap_iter_reset_iomap(iter);
89+
if (ret <= 0)
90+
return ret;
91+
}
8992

9093
ret = ops->iomap_begin(iter->inode, iter->pos, iter->len, iter->flags,
9194
&iter->iomap, &iter->srcmap);

0 commit comments

Comments
 (0)