[PATCH 17/18] libfuse: add upper-level API to invalidate parts of an iomap block device

Darrick J. Wong
2025-09-16T00:46:13Z

Wire up the upper-level wrappers to
fuse_lowlevel_iomap_invalidate_device.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
include/fuse.h | 10 ++++++++++
lib/fuse.c | 9 +++++++++
lib/fuse_versionscript | 1 +
3 files changed, 20 insertions(+)

diff --git a/include/fuse.h b/include/fuse.h
index 74b86e8d27fb35..e53e92786cea08 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -1422,6 +1422,16 @@ int fuse_fs_iomap_device_add(int fd, unsigned int flags);
*/
int fuse_fs_iomap_device_remove(int device_id);

+/**
+ * Invalidate any pagecache for the given iomap (block) device.
+ *
+ * @param device_id device index as returned by fuse_lowlevel_iomap_device_add
+ * @param offset starting offset of the range to invalidate
+ * @param length length of the range to invalidate
+ * @return 0 on success, or negative errno on failure
+ */
+int fuse_fs_iomap_device_invalidate(int device_id, off_t offset, off_t length);
+
/**
* Decide if we can enable iomap mode for a particular file for an upper-level
* fuse server.
diff --git a/lib/fuse.c b/lib/fuse.c
index 177c524eff736b..1c813ec5a697a0 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -2917,6 +2917,15 @@ int fuse_fs_iomap_device_remove(int device_id)
return fuse_lowlevel_iomap_device_remove(se, device_id);
}

+int fuse_fs_iomap_device_invalidate(int device_id, off_t offset, off_t length)
+{
+ struct fuse_context *ctxt = fuse_get_context();
+ struct fuse_session *se = fuse_get_session(ctxt->fuse);
+
+ return fuse_lowlevel_iomap_device_invalidate(se, device_id, offset,
+ length);
+}
+
static int fuse_fs_iomap_ioend(struct fuse_fs *fs, const char *path,
uint64_t nodeid, uint64_t attr_ino, off_t pos,
size_t written, uint32_t ioendflags, int error,
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index d268471ae5bd38..a275b53c6f9f1a 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -235,6 +235,7 @@ FUSE_3.99 {
fuse_lowlevel_discover_iomap;
fuse_reply_iomap_config;
fuse_lowlevel_iomap_device_invalidate;
+ fuse_fs_iomap_device_invalidate;
} FUSE_3.18;