Skip to content

Commit b26f2ea

Browse files
Brian Fosterbrauner
authored andcommitted
iomap: lift iter termination logic from iomap_iter_advance()
The iter termination logic in iomap_iter_advance() is only needed by iomap_iter() to determine whether to proceed with the next mapping for an ongoing operation. The old logic sets ret to 1 and then terminates if the operation is complete (iter->len == 0) or the previous iteration performed no work and the mapping has not been marked stale. The stale check exists to allow operations to retry the current mapping if an inconsistency has been detected. To further genericize iomap_iter_advance(), lift the termination logic into iomap_iter() and update the former to return success (0) or an error code. iomap_iter() continues on successful advance and non-zero iter->len or otherwise terminates in the no progress (and not stale) or error cases. Signed-off-by: Brian Foster <bfoster@redhat.com> Link: https://lore.kernel.org/r/20250207143253.314068-6-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 9183b2a commit b26f2ea

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

fs/iomap/iter.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@ static inline void iomap_iter_reset_iomap(struct iomap_iter *iter)
2727
*/
2828
static inline int iomap_iter_advance(struct iomap_iter *iter, s64 count)
2929
{
30-
bool stale = iter->iomap.flags & IOMAP_F_STALE;
31-
int ret = 1;
32-
3330
if (WARN_ON_ONCE(count > iomap_length(iter)))
3431
return -EIO;
3532
iter->pos += count;
3633
iter->len -= count;
37-
if (!iter->len || (!count && !stale))
38-
ret = 0;
39-
40-
return ret;
34+
return 0;
4135
}
4236

4337
static inline void iomap_iter_done(struct iomap_iter *iter)
@@ -69,6 +63,7 @@ static inline void iomap_iter_done(struct iomap_iter *iter)
6963
*/
7064
int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
7165
{
66+
bool stale = iter->iomap.flags & IOMAP_F_STALE;
7267
s64 processed;
7368
int ret;
7469

@@ -91,8 +86,18 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
9186
return processed;
9287
}
9388

94-
/* advance and clear state from the previous iteration */
89+
/*
90+
* Advance the iter and clear state from the previous iteration. Use
91+
* iter->len to determine whether to continue onto the next mapping.
92+
* Explicitly terminate in the case where the current iter has not
93+
* advanced at all (i.e. no work was done for some reason) unless the
94+
* mapping has been marked stale and needs to be reprocessed.
95+
*/
9596
ret = iomap_iter_advance(iter, processed);
97+
if (!ret && iter->len > 0)
98+
ret = 1;
99+
if (ret > 0 && !iter->processed && !stale)
100+
ret = 0;
96101
iomap_iter_reset_iomap(iter);
97102
if (ret <= 0)
98103
return ret;

0 commit comments

Comments
 (0)