From: Darrick J. Wong <djwong@xxxxxxxxxx> 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@xxxxxxxxxx> --- include/fuse_common.h | 7 +++++++ include/fuse_kernel.h | 5 +++++ lib/fuse_lowlevel.c | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/include/fuse_common.h b/include/fuse_common.h index 11eb22d011896c..657256b6309284 100644 --- a/include/fuse_common.h +++ b/include/fuse_common.h @@ -525,6 +525,11 @@ struct fuse_loop_config_v1 { */ #define FUSE_CAP_IOMAP (1ULL << 32) +/** + * Client supports using iomap for direct I/O file operations + */ +#define FUSE_CAP_IOMAP_DIRECTIO (1ULL << 33) + /** * Ioctl flags * @@ -1212,6 +1217,8 @@ struct fuse_iomap { /* enable fsdax */ #define FUSE_IFLAG_DAX (1U << 0) +/* use iomap for directio */ +#define FUSE_IFLAG_IOMAP_DIRECTIO (1U << 1) #endif /* FUSE_USE_VERSION >= 318 */ diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h index a06c16243a7885..7205de018634b9 100644 --- a/include/fuse_kernel.h +++ b/include/fuse_kernel.h @@ -240,6 +240,7 @@ * - add FUSE_IOMAP and iomap_{begin,end,ioend} handlers for FIEMAP and * SEEK_{DATA,HOLE} support * - add FUSE_DEV_IOC_IOMAP_DEV_ADD to configure block devices for iomap + * - add FUSE_IOMAP_DIRECTIO/FUSE_ATTR_IOMAP_DIRECTIO for direct I/O support */ #ifndef _LINUX_FUSE_H @@ -450,6 +451,7 @@ struct fuse_file_lock { * init_out.request_timeout contains the timeout (in secs) * FUSE_IOMAP: Client supports iomap for FIEMAP and SEEK_{DATA,HOLE} file * operations. + * FUSE_IOMAP_DIRECTIO: Client supports iomap for direct I/O operations. */ #define FUSE_ASYNC_READ (1 << 0) #define FUSE_POSIX_LOCKS (1 << 1) @@ -498,6 +500,7 @@ struct fuse_file_lock { #define FUSE_OVER_IO_URING (1ULL << 41) #define FUSE_REQUEST_TIMEOUT (1ULL << 42) #define FUSE_IOMAP (1ULL << 43) +#define FUSE_IOMAP_DIRECTIO (1ULL << 44) /** * CUSE INIT request/reply flags @@ -581,9 +584,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_DIRECTIO: Use iomap for directio */ #define FUSE_ATTR_SUBMOUNT (1 << 0) #define FUSE_ATTR_DAX (1 << 1) +#define FUSE_ATTR_IOMAP_DIRECTIO (1 << 2) /** * Open flags diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c index 568db13502a7d7..f98900c51d4a9b 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_DIRECTIO) + attr->flags |= FUSE_ATTR_IOMAP_DIRECTIO; } static void convert_attr(const struct fuse_setattr_in *attr, struct stat *stbuf) @@ -2777,6 +2779,8 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in, se->conn.capable_ext |= FUSE_CAP_OVER_IO_URING; if (inargflags & FUSE_IOMAP) se->conn.capable_ext |= FUSE_CAP_IOMAP; + if (inargflags & FUSE_IOMAP_DIRECTIO) + se->conn.capable_ext |= FUSE_CAP_IOMAP_DIRECTIO; } else { se->conn.max_readahead = 0; } @@ -2824,6 +2828,7 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in, /* servers need to opt-in to iomap explicitly */ LL_SET_DEFAULT(0, FUSE_CAP_IOMAP); + LL_SET_DEFAULT(0, FUSE_CAP_IOMAP_DIRECTIO); /* This could safely become default, but libfuse needs an API extension * to support it @@ -2945,6 +2950,8 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in, } if (se->conn.want_ext & FUSE_CAP_IOMAP) outargflags |= FUSE_IOMAP; + if (se->conn.want_ext & FUSE_CAP_IOMAP_DIRECTIO) + outargflags |= FUSE_IOMAP_DIRECTIO; if (inargflags & FUSE_INIT_EXT) { outargflags |= FUSE_INIT_EXT; @@ -2988,6 +2995,8 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in, outarg.max_stack_depth); if (se->conn.want_ext & FUSE_CAP_IOMAP) fuse_log(FUSE_LOG_DEBUG, " iomap=1\n"); + if (se->conn.want_ext & FUSE_CAP_IOMAP_DIRECTIO) + fuse_log(FUSE_LOG_DEBUG, " iomap_directio=1\n"); } if (arg->minor < 5) outargsize = FUSE_COMPAT_INIT_OUT_SIZE;