[RFC PATCH v3 03/11] iomap: Add helper to revert iomap iter

Ojaswin Mujoo <[email protected]> Wed, 5 Aug 2026 11:58:09 +0530
Newsgroups gmane.linux.file-systems,gmane.linux.kernel,gmane.linux.kernel.mm
Message-ID <c688c9ccbe13fda329d2bfcd423d5d38ec9ac561.1785908600.git.ojaswin@linux.ibm.com>
Add helper to revert back the iomap iter by count bytes. This will be
used by upcoming RWF_WRITETHROUGH feature to revert the state of the
iomap in case an error is encountered.

Writethrough can process and park folios so that they can be batched
together for IO later, this also advances the iomap iter. However if we
encounter any error, we would want to cancel the IO on those processed
folios. In this case, we want to revert the iter back so the upper
layers can know how much we were actually able to write before failure.

Signed-off-by: Ojaswin Mujoo <[email protected]>
---
 fs/iomap/iter.c       | 9 +++++++++
 include/linux/iomap.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c
index c445a38b6285..8ea849e7ccef 100644
--- a/fs/iomap/iter.c
+++ b/fs/iomap/iter.c
@@ -32,6 +32,15 @@ int iomap_iter_advance(struct iomap_iter *iter, u64 count)
 	return 0;
 }
 
+int iomap_iter_revert(struct iomap_iter *iter, u64 count)
+{
+	if (WARN_ON_ONCE(count > iter->pos))
+		return -EIO;
+	iter->pos -= count;
+	iter->len += count;
+	return 0;
+}
+
 static inline void iomap_iter_done(struct iomap_iter *iter)
 {
 	WARN_ON_ONCE(iter->iomap.offset > iter->pos);
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 8c754eb974fb..1c8f13948f81 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -275,6 +275,7 @@ struct iomap_iter {
 
 int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops);
 int iomap_iter_advance(struct iomap_iter *iter, u64 count);
+int iomap_iter_revert(struct iomap_iter *iter, u64 count);
 
 /**
  * iomap_length_trim - trimmed length of the current iomap iteration
-- 
2.55.0