]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
iomap: reset per-iter state on non-error iter advances
authorBrian Foster <bfoster@redhat.com>
Fri, 15 Nov 2024 20:01:53 +0000 (15:01 -0500)
committerChristian Brauner <brauner@kernel.org>
Thu, 21 Nov 2024 08:35:25 +0000 (09:35 +0100)
iomap_iter_advance() zeroes the processed and mapping fields on
every non-error iteration except for the last expected iteration
(i.e. return 0 expected to terminate the iteration loop). This
appears to be circumstantial as nothing currently relies on these
fields after the final iteration.

Therefore to better faciliate iomap_iter reuse in subsequent
patches, update iomap_iter_advance() to always reset per-iteration
state on successful completion.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Link: https://lore.kernel.org/r/20241115200155.593665-2-bfoster@redhat.com
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/iomap/iter.c

index 79a0614eaab777e71767a9148ca105e571b509e8..3790918646af76395ae7239eb0575d7e63d58658 100644 (file)
 static inline int iomap_iter_advance(struct iomap_iter *iter)
 {
        bool stale = iter->iomap.flags & IOMAP_F_STALE;
+       int ret = 1;
 
        /* handle the previous iteration (if any) */
        if (iter->iomap.length) {
                if (iter->processed < 0)
                        return iter->processed;
-               if (!iter->processed && !stale)
-                       return 0;
                if (WARN_ON_ONCE(iter->processed > iomap_length(iter)))
                        return -EIO;
                iter->pos += iter->processed;
                iter->len -= iter->processed;
-               if (!iter->len)
-                       return 0;
+               if (!iter->len || (!iter->processed && !stale))
+                       ret = 0;
        }
 
-       /* clear the state for the next iteration */
+       /* clear the per iteration state */
        iter->processed = 0;
        memset(&iter->iomap, 0, sizeof(iter->iomap));
        memset(&iter->srcmap, 0, sizeof(iter->srcmap));
-       return 1;
+       return ret;
 }
 
 static inline void iomap_iter_done(struct iomap_iter *iter)