diff mbox series

[v3,1/4] iomap: reset per-iter state on non-error iter advances

Message ID 20241108124246.198489-2-bfoster@redhat.com (mailing list archive)
State New
Headers show
Series iomap: zero range flush fixes | expand

Commit Message

Brian Foster Nov. 8, 2024, 12:42 p.m. UTC
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>
---
 fs/iomap/iter.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Darrick J. Wong Nov. 9, 2024, 3 a.m. UTC | #1
On Fri, Nov 08, 2024 at 07:42:43AM -0500, Brian Foster wrote:
> 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>

Seems pretty straightforward to me,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/iomap/iter.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c
> index 79a0614eaab7..3790918646af 100644
> --- a/fs/iomap/iter.c
> +++ b/fs/iomap/iter.c
> @@ -22,26 +22,25 @@
>  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)
> -- 
> 2.47.0
> 
>
Christoph Hellwig Nov. 11, 2024, 5:53 a.m. UTC | #2
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

(btw, can you keep Ccing iomap patches to linux-xfs per the entry
in MAINTAINERS?)
Brian Foster Nov. 12, 2024, 1:59 p.m. UTC | #3
On Sun, Nov 10, 2024 at 09:53:58PM -0800, Christoph Hellwig wrote:
> Looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> (btw, can you keep Ccing iomap patches to linux-xfs per the entry
> in MAINTAINERS?)
> 

Yeah.. sorry, I didn't realize that was a thing.

Brian
diff mbox series

Patch

diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c
index 79a0614eaab7..3790918646af 100644
--- a/fs/iomap/iter.c
+++ b/fs/iomap/iter.c
@@ -22,26 +22,25 @@ 
 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)