Skip to content

Commit 469739f

Browse files
Brian Fosterbrauner
authored andcommitted
iomap: remove unnecessary advance from iomap_iter()
At this point, all iomap operations have been updated to advance the iomap_iter directly before returning to iomap_iter(). Therefore, the complexity of handling both the old and new semantics is no longer required and can be removed from iomap_iter(). Update iomap_iter() to expect success or failure status in iter.processed. As a precaution and developer hint to prevent inadvertent use of old semantics, warn on a positive return code and fail the operation. Remove the unnecessary advance and simplify the termination logic. Signed-off-by: Brian Foster <bfoster@redhat.com> Link: https://lore.kernel.org/r/20250224144757.237706-11-bfoster@redhat.com Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 6fe32fe commit 469739f

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

fs/iomap/iter.c

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ static inline void iomap_iter_done(struct iomap_iter *iter)
6060
int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
6161
{
6262
bool stale = iter->iomap.flags & IOMAP_F_STALE;
63-
ssize_t advanced = iter->processed > 0 ? iter->processed : 0;
64-
u64 olen = iter->len;
65-
s64 processed;
63+
ssize_t advanced;
64+
u64 olen;
6665
int ret;
6766

6867
trace_iomap_iter(iter, ops, _RET_IP_);
@@ -71,14 +70,11 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
7170
goto begin;
7271

7372
/*
74-
* If iter.processed is zero, the op may still have advanced the iter
75-
* itself. Calculate the advanced and original length bytes based on how
76-
* far pos has advanced for ->iomap_end().
73+
* Calculate how far the iter was advanced and the original length bytes
74+
* for ->iomap_end().
7775
*/
78-
if (!advanced) {
79-
advanced = iter->pos - iter->iter_start_pos;
80-
olen += advanced;
81-
}
76+
advanced = iter->pos - iter->iter_start_pos;
77+
olen = iter->len + advanced;
8278

8379
if (ops->iomap_end) {
8480
ret = ops->iomap_end(iter->inode, iter->iter_start_pos,
@@ -89,27 +85,22 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
8985
return ret;
9086
}
9187

92-
processed = iter->processed;
93-
if (processed < 0) {
94-
iomap_iter_reset_iomap(iter);
95-
return processed;
96-
}
88+
/* detect old return semantics where this would advance */
89+
if (WARN_ON_ONCE(iter->processed > 0))
90+
iter->processed = -EIO;
9791

9892
/*
99-
* Advance the iter and clear state from the previous iteration. This
100-
* passes iter->processed because that reflects the bytes processed but
101-
* not yet advanced by the iter handler.
102-
*
10393
* Use iter->len to determine whether to continue onto the next mapping.
104-
* Explicitly terminate in the case where the current iter has not
94+
* Explicitly terminate on error status or if the current iter has not
10595
* advanced at all (i.e. no work was done for some reason) unless the
10696
* mapping has been marked stale and needs to be reprocessed.
10797
*/
108-
ret = iomap_iter_advance(iter, &processed);
109-
if (!ret && iter->len > 0)
110-
ret = 1;
111-
if (ret > 0 && !advanced && !stale)
98+
if (iter->processed < 0)
99+
ret = iter->processed;
100+
else if (iter->len == 0 || (!advanced && !stale))
112101
ret = 0;
102+
else
103+
ret = 1;
113104
iomap_iter_reset_iomap(iter);
114105
if (ret <= 0)
115106
return ret;

0 commit comments

Comments
 (0)