[PATCH 18/28] fuse: advertise support for iomap

Darrick J. Wong
2025-09-16T00:32:40Z

Advertise our new IO paths programmatically by creating an ioctl that
can return the capabilities of the kernel.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
fs/fuse/fuse_i.h | 4 ++++
include/uapi/linux/fuse.h | 9 +++++++++
fs/fuse/dev.c | 3 +++
fs/fuse/file_iomap.c | 13 +++++++++++++
4 files changed, 29 insertions(+)

diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 7581d22de2340c..82191e92c21097 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1781,6 +1781,9 @@ int fuse_iomap_fallocate(struct file *file, int mode, loff_t offset,
loff_t length, loff_t new_size);
int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
loff_t endpos);
+
+int fuse_dev_ioctl_iomap_support(struct file *file,
+ struct fuse_iomap_support __user *argp);
#else
# define fuse_iomap_enabled(...) (false)
# define fuse_has_iomap(...) (false)
@@ -1803,6 +1806,7 @@ int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
# define fuse_iomap_setsize_start(...) (-ENOSYS)
# define fuse_iomap_fallocate(...) (-ENOSYS)
# define fuse_iomap_flush_unmap_range(...) (-ENOSYS)
+# define fuse_dev_ioctl_iomap_support(...) (-EOPNOTSUPP)
#endif

#endif /* _FS_FUSE_I_H */
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index c0af8a4d3e30d8..675b1d4fdff8db 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1139,6 +1139,13 @@ struct fuse_backing_map {
uint64_t padding;
};

+/* basic file I/O functionality through iomap */
+#define FUSE_IOMAP_SUPPORT_FILEIO (1ULL << 0)
+struct fuse_iomap_support {
+ uint64_t flags;
+ uint64_t padding;
+};
+
/* Device ioctls: */
#define FUSE_DEV_IOC_MAGIC 229
#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
@@ -1146,6 +1153,8 @@ struct fuse_backing_map {
struct fuse_backing_map)
#define FUSE_DEV_IOC_BACKING_CLOSE _IOW(FUSE_DEV_IOC_MAGIC, 2, uint32_t)
#define FUSE_DEV_IOC_SYNC_INIT _IO(FUSE_DEV_IOC_MAGIC, 3)
+#define FUSE_DEV_IOC_IOMAP_SUPPORT _IOR(FUSE_DEV_IOC_MAGIC, 99, \
+ struct fuse_iomap_support)

struct fuse_lseek_in {
uint64_t fh;
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 871877cac2acf3..bb0ec19a368bea 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2710,6 +2710,9 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
case FUSE_DEV_IOC_SYNC_INIT:
return fuse_dev_ioctl_sync_init(file);

+ case FUSE_DEV_IOC_IOMAP_SUPPORT:
+ return fuse_dev_ioctl_iomap_support(file, argp);
+
default:
return -ENOTTY;
}
diff --git a/fs/fuse/file_iomap.c b/fs/fuse/file_iomap.c
index 6cc1f91fe3d5a4..5cefceb267f8f1 100644
--- a/fs/fuse/file_iomap.c
+++ b/fs/fuse/file_iomap.c
@@ -1695,3 +1695,16 @@ fuse_iomap_fallocate(
file_update_time(file);
return 0;
}
+
+int fuse_dev_ioctl_iomap_support(struct file *file,
+ struct fuse_iomap_support __user *argp)
+{
+ struct fuse_iomap_support ios = { };
+
+ if (fuse_iomap_enabled())
+ ios.flags = FUSE_IOMAP_SUPPORT_FILEIO;
+
+ if (copy_to_user(argp, &ios, sizeof(ios)))
+ return -EFAULT;
+ return 0;
+}