[PATCH 11/18] libfuse: support direct I/O through iomap

Darrick J. Wong
2025-09-16T00:44:39Z

Make it so that fuse servers can ask the kernel fuse driver to use iomap
to support direct IO.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
include/fuse_common.h | 2 ++
include/fuse_kernel.h | 3 +++
lib/fuse_lowlevel.c | 2 ++
3 files changed, 7 insertions(+)

diff --git a/include/fuse_common.h b/include/fuse_common.h
index faf0bc57bcdbe6..191d9749960992 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -1223,6 +1223,8 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,

/* enable fsdax */
#define FUSE_IFLAG_DAX (1U << 0)
+/* use iomap for this inode */
+#define FUSE_IFLAG_IOMAP (1U << 1)

/* ----------------------------------------------------------- *
* Compatibility stuff *
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index b349ede09e494f..48db6ba118a47c 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.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/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index bddc161412f33e..8654ca263b374d 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -124,6 +124,8 @@ static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr,
attr->flags = 0;
if (iflags & FUSE_IFLAG_DAX)
attr->flags |= FUSE_ATTR_DAX;
+ if (iflags & FUSE_IFLAG_IOMAP)
+ attr->flags |= FUSE_ATTR_IOMAP;
}

static void convert_attr(const struct fuse_setattr_in *attr, struct stat *stbuf)