[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <176169813768.1427432.13427682700847139457.stgit@frogsfrogsfrogs>
Date: Tue, 28 Oct 2025 18:02:41 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: djwong@...nel.org, bschubert@....com
Cc: linux-ext4@...r.kernel.org, linux-fsdevel@...r.kernel.org,
bernd@...ernd.com, miklos@...redi.hu, joannelkoong@...il.com, neal@...pa.dev
Subject: [PATCH 13/22] libfuse: allow discovery of the kernel's iomap
capabilities
From: Darrick J. Wong <djwong@...nel.org>
Create a library function so that we can discover the kernel's iomap
capabilities ahead of time.
Signed-off-by: "Darrick J. Wong" <djwong@...nel.org>
---
include/fuse_common.h | 7 +++++++
include/fuse_kernel.h | 7 +++++++
include/fuse_lowlevel.h | 10 ++++++++++
lib/fuse_lowlevel.c | 19 +++++++++++++++++++
lib/fuse_versionscript | 1 +
5 files changed, 44 insertions(+)
diff --git a/include/fuse_common.h b/include/fuse_common.h
index 191d9749960992..86ae8894d81dbb 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -534,6 +534,13 @@ struct fuse_loop_config_v1 {
#define FUSE_IOCTL_MAX_IOV 256
+/**
+ * iomap discovery flags
+ *
+ * FUSE_IOMAP_SUPPORT_FILEIO: basic file I/O functionality through iomap
+ */
+#define FUSE_IOMAP_SUPPORT_FILEIO (1ULL << 0)
+
/**
* Connection information, passed to the ->init() method
*
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 38aa03dce17e53..3dc00cd4cb113f 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -1144,12 +1144,19 @@ struct fuse_backing_map {
uint64_t padding;
};
+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)
#define FUSE_DEV_IOC_BACKING_OPEN _IOW(FUSE_DEV_IOC_MAGIC, 1, \
struct fuse_backing_map)
#define FUSE_DEV_IOC_BACKING_CLOSE _IOW(FUSE_DEV_IOC_MAGIC, 2, uint32_t)
+#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/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index e2d14f2e2bd911..5ce7b4aaa2ae94 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -2576,6 +2576,16 @@ bool fuse_req_is_uring(fuse_req_t req);
int fuse_req_get_payload(fuse_req_t req, char **payload, size_t *payload_sz,
void **mr);
+
+/**
+ * Discover the kernel's iomap capabilities. Returns FUSE_CAP_IOMAP_* flags.
+ *
+ * @param fd open file descriptor to a fuse device, or -1 if you're running
+ * in the same process that will call mount().
+ * @return FUSE_IOMAP_SUPPORT_* flags
+ */
+uint64_t fuse_lowlevel_discover_iomap(int fd);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index e0d18844098971..4e7bf40833b578 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -4709,3 +4709,22 @@ int fuse_session_exited(struct fuse_session *se)
return exited ? 1 : 0;
}
+
+uint64_t fuse_lowlevel_discover_iomap(int fd)
+{
+ struct fuse_iomap_support ios = { };
+
+ if (fd >= 0) {
+ ioctl(fd, FUSE_DEV_IOC_IOMAP_SUPPORT, &ios);
+ return ios.flags;
+ }
+
+ fd = open("/dev/fuse", O_RDONLY | O_CLOEXEC);
+ if (fd < 0)
+ return 0;
+
+ ioctl(fd, FUSE_DEV_IOC_IOMAP_SUPPORT, &ios);
+ close(fd);
+
+ return ios.flags;
+}
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 25a3e04c6c5ec7..704e8c2908ec4b 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -232,6 +232,7 @@ FUSE_3.99 {
fuse_add_direntry_plus_iflags;
fuse_fs_can_enable_iomap;
fuse_fs_can_enable_iomapx;
+ fuse_lowlevel_discover_iomap;
} FUSE_3.18;
# Local Variables:
Powered by blists - more mailing lists