[RFC PATCH v4 04/12] iomap: Add helper to revert iomap iter
From: Ojaswin Mujoo
Date: Mon Sep 28 2026 - 08:17:12 EST
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 <ojaswin@xxxxxxxxxxxxx>
---
fs/iomap/iter.c | 10 ++++++++++
include/linux/iomap.h | 1 +
2 files changed, 11 insertions(+)
diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c
index c445a38b6285..81af220dca47 100644
--- a/fs/iomap/iter.c
+++ b/fs/iomap/iter.c
@@ -32,6 +32,16 @@ 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(iter->pos < count ||
+ iter->pos - count < iter->iter_start_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 bc7ae6327dbf..a9ebf486e7b4 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