[PATCH 07/28] fuse: create a per-inode flag for toggling iomap

Darrick J. Wong
2025-09-16T00:29:48Z

Create a per-inode flag to control whether or not this inode actually
uses iomap. This is required for non-regular files because iomap
doesn't apply there; and enables fuse filesystems to provide some
non-iomap files if desired.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
fs/fuse/fuse_i.h | 15 +++++++++++++++
include/uapi/linux/fuse.h | 3 +++
fs/fuse/file.c | 1 +
fs/fuse/file_iomap.c | 32 ++++++++++++++++++++++++++++++++
fs/fuse/inode.c | 2 ++
5 files changed, 53 insertions(+)

diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 3cda9bc6af23fe..791e868e568cc5 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -250,6 +250,8 @@ enum {
FUSE_I_BTIME,
/* Wants or already has page cache IO */
FUSE_I_CACHE_IO_MODE,
+ /* Use iomap for this inode */
+ FUSE_I_IOMAP,
};

struct fuse_conn;
@@ -1715,11 +1717,24 @@ extern const struct fuse_backing_ops fuse_iomap_backing_ops;

void fuse_iomap_mount(struct fuse_mount *fm);
void fuse_iomap_unmount(struct fuse_mount *fm);
+
+void fuse_iomap_init_inode(struct inode *inode, unsigned attr_flags);
+void fuse_iomap_evict_inode(struct inode *inode);
+
+static inline bool fuse_inode_has_iomap(const struct inode *inode)
+{
+ const struct fuse_inode *fi = get_fuse_inode_c(inode);
+
+ return test_bit(FUSE_I_IOMAP, &fi->state);
+}
#else
# define fuse_iomap_enabled(...) (false)
# define fuse_has_iomap(...) (false)
# define fuse_iomap_mount(...) ((void)0)
# define fuse_iomap_unmount(...) ((void)0)
+# define fuse_iomap_init_inode(...) ((void)0)
+# define fuse_iomap_evict_inode(...) ((void)0)
+# define fuse_inode_has_iomap(...) (false)
#endif

#endif /* _FS_FUSE_I_H */
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 3a367f387795ff..cc4bca2941cb79 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -238,6 +238,7 @@
*
* 7.99
* - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations
+ * - add FUSE_ATTR_IOMAP to enable iomap for specific inodes
*/

#ifndef _LINUX_FUSE_H
@@ -578,9 +579,11 @@ struct fuse_file_lock {
*
* FUSE_ATTR_SUBMOUNT: Object is a submount root
* FUSE_ATTR_DAX: Enable DAX for this file in per inode DAX mode
+ * FUSE_ATTR_IOMAP: Use iomap for this inode
*/
#define FUSE_ATTR_SUBMOUNT (1 << 0)
#define FUSE_ATTR_DAX (1 << 1)
+#define FUSE_ATTR_IOMAP (1 << 2)

/**
* Open flags
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index ebdca39b2261d7..8982e0b9661bb1 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -3127,4 +3127,5 @@ void fuse_init_file_inode(struct inode *inode, unsigned int flags)

if (IS_ENABLED(CONFIG_FUSE_DAX))
fuse_dax_inode_init(inode, flags);
+ fuse_iomap_init_inode(inode, flags);
}
diff --git a/fs/fuse/file_iomap.c b/fs/fuse/file_iomap.c
index 75e6f668baa9ef..6ffa5710a92ad5 100644
--- a/fs/fuse/file_iomap.c
+++ b/fs/fuse/file_iomap.c
@@ -633,3 +633,35 @@ void fuse_iomap_unmount(struct fuse_mount *fm)
fuse_flush_requests_and_wait(fc);
fuse_send_destroy(fm);
}
+
+static inline void fuse_inode_set_iomap(struct inode *inode)
+{
+ struct fuse_inode *fi = get_fuse_inode(inode);
+
+ ASSERT(fuse_has_iomap(inode));
+
+ set_bit(FUSE_I_IOMAP, &fi->state);
+}
+
+static inline void fuse_inode_clear_iomap(struct inode *inode)
+{
+ struct fuse_inode *fi = get_fuse_inode(inode);
+
+ ASSERT(fuse_has_iomap(inode));
+
+ clear_bit(FUSE_I_IOMAP, &fi->state);
+}
+
+void fuse_iomap_init_inode(struct inode *inode, unsigned attr_flags)
+{
+ struct fuse_conn *conn = get_fuse_conn(inode);
+
+ if (conn->iomap && (attr_flags & FUSE_ATTR_IOMAP))
+ fuse_inode_set_iomap(inode);
+}
+
+void fuse_iomap_evict_inode(struct inode *inode)
+{
+ if (fuse_inode_has_iomap(inode))
+ fuse_inode_clear_iomap(inode);
+}
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 7cb1426ca3e767..b209db07e60e33 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -199,6 +199,8 @@ static void fuse_evict_inode(struct inode *inode)
WARN_ON(!list_empty(&fi->write_files));
WARN_ON(!list_empty(&fi->queued_writes));
}
+
+ fuse_iomap_evict_inode(inode);
}

static int fuse_reconfigure(struct fs_context *fsc)