From: "Darrick J. Wong" <djwong@kernel.org>
To: Brian Foster <bfoster@redhat.com>
Cc: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org,
Christoph Hellwig <hch@infradead.org>
Subject: Re: [PATCH v2 10/12] iomap: remove unnecessary advance from iomap_iter()
Date: Wed, 19 Feb 2025 14:30:10 -0800 [thread overview]
Message-ID: <20250219223010.GE21808@frogsfrogsfrogs> (raw)
In-Reply-To: <20250219175050.83986-11-bfoster@redhat.com>
On Wed, Feb 19, 2025 at 12:50:48PM -0500, Brian Foster wrote:
> 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>
Looks reasonable,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> fs/iomap/iter.c | 39 +++++++++++++++------------------------
> 1 file changed, 15 insertions(+), 24 deletions(-)
>
> diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c
> index 0ebcabc7df52..e4dfe64029cc 100644
> --- a/fs/iomap/iter.c
> +++ b/fs/iomap/iter.c
> @@ -60,9 +60,8 @@ static inline void iomap_iter_done(struct iomap_iter *iter)
> int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
> {
> bool stale = iter->iomap.flags & IOMAP_F_STALE;
> - ssize_t advanced = iter->processed > 0 ? iter->processed : 0;
> - u64 olen = iter->len;
> - s64 processed;
> + ssize_t advanced;
> + u64 olen;
> int ret;
>
> trace_iomap_iter(iter, ops, _RET_IP_);
> @@ -71,14 +70,11 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
> goto begin;
>
> /*
> - * If iter.processed is zero, the op may still have advanced the iter
> - * itself. Calculate the advanced and original length bytes based on how
> - * far pos has advanced for ->iomap_end().
> + * Calculate how far the iter was advanced and the original length bytes
> + * for ->iomap_end().
> */
> - if (!advanced) {
> - advanced = iter->pos - iter->iter_start_pos;
> - olen += advanced;
> - }
> + advanced = iter->pos - iter->iter_start_pos;
> + olen = iter->len + advanced;
>
> if (ops->iomap_end) {
> 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)
> return ret;
> }
>
> - processed = iter->processed;
> - if (processed < 0) {
> - iomap_iter_reset_iomap(iter);
> - return processed;
> - }
> + /* detect old return semantics where this would advance */
> + if (WARN_ON_ONCE(iter->processed > 0))
> + iter->processed = -EIO;
>
> /*
> - * Advance the iter and clear state from the previous iteration. This
> - * passes iter->processed because that reflects the bytes processed but
> - * not yet advanced by the iter handler.
> - *
> * Use iter->len to determine whether to continue onto the next mapping.
> - * Explicitly terminate in the case where the current iter has not
> + * Explicitly terminate on error status or if the current iter has not
> * advanced at all (i.e. no work was done for some reason) unless the
> * mapping has been marked stale and needs to be reprocessed.
> */
> - ret = iomap_iter_advance(iter, &processed);
> - if (!ret && iter->len > 0)
> - ret = 1;
> - if (ret > 0 && !advanced && !stale)
> + if (iter->processed < 0)
> + ret = iter->processed;
> + else if (iter->len == 0 || (!advanced && !stale))
> ret = 0;
> + else
> + ret = 1;
> iomap_iter_reset_iomap(iter);
> if (ret <= 0)
> return ret;
> --
> 2.48.1
>
>
next prev parent reply other threads:[~2025-02-19 22:30 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-19 17:50 [PATCH v2 00/12] iomap: incremental advance conversion -- phase 2 Brian Foster
2025-02-19 17:50 ` [PATCH v2 01/12] iomap: advance the iter directly on buffered read Brian Foster
2025-02-19 22:22 ` Darrick J. Wong
2025-02-19 22:31 ` Darrick J. Wong
2025-02-19 17:50 ` [PATCH v2 02/12] iomap: advance the iter on direct I/O Brian Foster
2025-02-19 22:22 ` Darrick J. Wong
2025-02-19 17:50 ` [PATCH v2 03/12] iomap: convert misc simple ops to incremental advance Brian Foster
2025-02-19 22:24 ` Darrick J. Wong
2025-02-19 22:31 ` Darrick J. Wong
2025-02-19 17:50 ` [PATCH v2 04/12] dax: advance the iomap_iter in the read/write path Brian Foster
2025-02-19 22:33 ` Darrick J. Wong
2025-02-20 14:58 ` Brian Foster
2025-02-19 17:50 ` [PATCH v2 05/12] dax: push advance down into dax_iomap_iter() for read and write Brian Foster
2025-02-19 22:34 ` Darrick J. Wong
2025-02-19 17:50 ` [PATCH v2 06/12] dax: advance the iomap_iter on zero range Brian Foster
2025-02-19 22:34 ` Darrick J. Wong
2025-02-19 17:50 ` [PATCH v2 07/12] dax: advance the iomap_iter on unshare range Brian Foster
2025-02-19 22:35 ` Darrick J. Wong
2025-02-19 17:50 ` [PATCH v2 08/12] dax: advance the iomap_iter on dedupe range Brian Foster
2025-02-19 22:35 ` Darrick J. Wong
2025-02-19 17:50 ` [PATCH v2 09/12] dax: advance the iomap_iter on pte and pmd faults Brian Foster
2025-02-19 22:36 ` Darrick J. Wong
2025-02-19 17:50 ` [PATCH v2 10/12] iomap: remove unnecessary advance from iomap_iter() Brian Foster
2025-02-19 22:30 ` Darrick J. Wong [this message]
2025-02-19 17:50 ` [PATCH v2 11/12] iomap: rename iomap_iter processed field to status Brian Foster
2025-02-19 22:30 ` Darrick J. Wong
2025-02-19 17:50 ` [PATCH v2 12/12] iomap: introduce a full map advance helper Brian Foster
2025-02-19 22:31 ` Darrick J. Wong
2025-02-20 9:10 ` [PATCH v2 00/12] iomap: incremental advance conversion -- phase 2 Christian Brauner
2025-02-20 14:59 ` Brian Foster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250219223010.GE21808@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=bfoster@redhat.com \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).