From: Darrick J. Wong <djwong@xxxxxxxxxx> Create a library function so that we can discover the kernel's iomap capabilities ahead of time. Signed-off-by: "Darrick J. Wong" <djwong@xxxxxxxxxx> --- include/fuse_common.h | 7 +++++++ include/fuse_kernel.h | 7 +++++++ include/fuse_lowlevel.h | 5 +++++ lib/fuse_lowlevel.c | 15 +++++++++++++++ lib/fuse_versionscript | 1 + 5 files changed, 35 insertions(+) diff --git a/include/fuse_common.h b/include/fuse_common.h index 6e8b2958373258..f9cc3702411680 100644 --- a/include/fuse_common.h +++ b/include/fuse_common.h @@ -542,6 +542,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 eafad773a1fd5f..dbd2ce1fbbe6ed 100644 --- a/include/fuse_kernel.h +++ b/include/fuse_kernel.h @@ -1134,12 +1134,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, 3, \ + struct fuse_iomap_support) struct fuse_lseek_in { uint64_t fh; diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h index e0642032127686..2931a57ec4079b 100644 --- a/include/fuse_lowlevel.h +++ b/include/fuse_lowlevel.h @@ -2556,6 +2556,11 @@ int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf); */ bool fuse_req_is_uring(fuse_req_t req); +/** + * Discover the kernel's iomap capabilities. Returns FUSE_CAP_IOMAP_* flags. + */ +uint64_t fuse_lowlevel_discover_iomap(void); + #ifdef __cplusplus } #endif diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c index 6a96c0f62d5884..ab10204c8042d9 100644 --- a/lib/fuse_lowlevel.c +++ b/lib/fuse_lowlevel.c @@ -4603,3 +4603,18 @@ int fuse_session_exited(struct fuse_session *se) return exited ? 1 : 0; } + +uint64_t fuse_lowlevel_discover_iomap(void) +{ + struct fuse_iomap_support ios = { }; + int fd; + + 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 aa16efdd8a9879..5275a17ba1ed51 100644 --- a/lib/fuse_versionscript +++ b/lib/fuse_versionscript @@ -231,6 +231,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: