diff mbox series

[v5,03/10] iomap: refactor iomap_iter() length check and tracepoint

Message ID 20250205135821.178256-4-bfoster@redhat.com (mailing list archive)
State New
Headers show
Series iomap: incremental per-operation iter advance | expand

Commit Message

Brian Foster Feb. 5, 2025, 1:58 p.m. UTC
iomap_iter() checks iomap.length to skip individual code blocks not
appropriate for the initial case where there is no mapping in the
iter. To prepare for upcoming changes, refactor the code to jump
straight to the ->iomap_begin() handler in the initial case and move
the tracepoint to the top of the function so it always executes.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 fs/iomap/iter.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

Comments

Darrick J. Wong Feb. 5, 2025, 6:50 p.m. UTC | #1
On Wed, Feb 05, 2025 at 08:58:14AM -0500, Brian Foster wrote:
> iomap_iter() checks iomap.length to skip individual code blocks not
> appropriate for the initial case where there is no mapping in the
> iter. To prepare for upcoming changes, refactor the code to jump
> straight to the ->iomap_begin() handler in the initial case and move
> the tracepoint to the top of the function so it always executes.
> 
> Signed-off-by: Brian Foster <bfoster@redhat.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Looks ok,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  fs/iomap/iter.c | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c
> index 731ea7267f27..a2ae99fe6431 100644
> --- a/fs/iomap/iter.c
> +++ b/fs/iomap/iter.c
> @@ -73,7 +73,12 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
>  {
>  	int ret;
>  
> -	if (iter->iomap.length && ops->iomap_end) {
> +	trace_iomap_iter(iter, ops, _RET_IP_);
> +
> +	if (!iter->iomap.length)
> +		goto begin;
> +
> +	if (ops->iomap_end) {
>  		ret = ops->iomap_end(iter->inode, iter->pos, iomap_length(iter),
>  				iter->processed > 0 ? iter->processed : 0,
>  				iter->flags, &iter->iomap);
> @@ -82,14 +87,12 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
>  	}
>  
>  	/* advance and clear state from the previous iteration */
> -	trace_iomap_iter(iter, ops, _RET_IP_);
> -	if (iter->iomap.length) {
> -		ret = iomap_iter_advance(iter, iter->processed);
> -		iomap_iter_reset_iomap(iter);
> -		if (ret <= 0)
> -			return ret;
> -	}
> +	ret = iomap_iter_advance(iter, iter->processed);
> +	iomap_iter_reset_iomap(iter);
> +	if (ret <= 0)
> +		return ret;
>  
> +begin:
>  	ret = ops->iomap_begin(iter->inode, iter->pos, iter->len, iter->flags,
>  			       &iter->iomap, &iter->srcmap);
>  	if (ret < 0)
> -- 
> 2.48.1
> 
>
diff mbox series

Patch

diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c
index 731ea7267f27..a2ae99fe6431 100644
--- a/fs/iomap/iter.c
+++ b/fs/iomap/iter.c
@@ -73,7 +73,12 @@  int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
 {
 	int ret;
 
-	if (iter->iomap.length && ops->iomap_end) {
+	trace_iomap_iter(iter, ops, _RET_IP_);
+
+	if (!iter->iomap.length)
+		goto begin;
+
+	if (ops->iomap_end) {
 		ret = ops->iomap_end(iter->inode, iter->pos, iomap_length(iter),
 				iter->processed > 0 ? iter->processed : 0,
 				iter->flags, &iter->iomap);
@@ -82,14 +87,12 @@  int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
 	}
 
 	/* advance and clear state from the previous iteration */
-	trace_iomap_iter(iter, ops, _RET_IP_);
-	if (iter->iomap.length) {
-		ret = iomap_iter_advance(iter, iter->processed);
-		iomap_iter_reset_iomap(iter);
-		if (ret <= 0)
-			return ret;
-	}
+	ret = iomap_iter_advance(iter, iter->processed);
+	iomap_iter_reset_iomap(iter);
+	if (ret <= 0)
+		return ret;
 
+begin:
 	ret = ops->iomap_begin(iter->inode, iter->pos, iter->len, iter->flags,
 			       &iter->iomap, &iter->srcmap);
 	if (ret < 0)