[PATCH v1 1/2] iomap: add helpers to mark and clear folio uptodate state

Joanne Koong <[email protected]> Tue, 23 Jun 2026 13:28:41 -0700
Newsgroups dev.linux.lists.fuse-devel,org.kernel.vger.linux-fsdevel
Message-ID <[email protected]>
Add two exported helpers, iomap_folio_mark_uptodate() and
iomap_folio_clear_uptodate(). These set or clear the uptodate state of a
folio and adjust the uptodate bitmap if there is iomap state attached to
the folio.

This is needed because there are some filesystems (eg fuse) that have
paths outside of conventional iomap calls that need to mark or clear a
folio as uptodate (eg writing server-pushed data directly into the page
cache) and need the iomap-internal uptodate bitmap to be in sync with
the uptodate state of the folio.

Signed-off-by: Joanne Koong <[email protected]>
---
 fs/iomap/buffered-io.c | 27 +++++++++++++++++++++++++++
 include/linux/iomap.h  |  2 ++
 2 files changed, 29 insertions(+)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 8d4806dc46d4..317fa7af98bd 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -105,6 +105,33 @@ static void iomap_set_range_uptodate(struct folio *folio, size_t off,
 		folio_mark_uptodate(folio);
 }
 
+void iomap_folio_mark_uptodate(struct folio *folio)
+{
+	iomap_set_range_uptodate(folio, 0, folio_size(folio));
+}
+EXPORT_SYMBOL_GPL(iomap_folio_mark_uptodate);
+
+void iomap_folio_clear_uptodate(struct folio *folio)
+{
+	struct iomap_folio_state *ifs = folio->private;
+	unsigned long flags;
+
+	if (!folio_test_uptodate(folio))
+		return;
+
+	if (ifs) {
+		struct inode *inode = folio->mapping->host;
+		unsigned int nr_blks = i_blocks_per_folio(inode, folio);
+
+		spin_lock_irqsave(&ifs->state_lock, flags);
+		bitmap_clear(ifs->state, 0, nr_blks);
+		spin_unlock_irqrestore(&ifs->state_lock, flags);
+	}
+
+	folio_clear_uptodate(folio);
+}
+EXPORT_SYMBOL_GPL(iomap_folio_clear_uptodate);
+
 /*
  * Find the next dirty block in the folio. end_blk is inclusive.
  * If no dirty block is found, this will return end_blk + 1.
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 3582ed1fe236..f13ae425f552 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -365,6 +365,8 @@ struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len);
 bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags);
 void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len);
 bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio);
+void iomap_folio_mark_uptodate(struct folio *folio);
+void iomap_folio_clear_uptodate(struct folio *folio);
 int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
 		const struct iomap_ops *ops,
 		const struct iomap_write_ops *write_ops);
-- 
2.52.0