From: Darrick J. Wong <djwong@xxxxxxxxxx> 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@xxxxxxxxxx> --- 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 74fb5971f8fec7..5380a220741014 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1721,6 +1721,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) @@ -1746,6 +1749,7 @@ int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos, # define fuse_iomap_set_i_blkbits(...) ((void)0) # 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 12d15c186256f3..d0f71136837068 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -1134,12 +1134,21 @@ 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) #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/fs/fuse/dev.c b/fs/fuse/dev.c index 31d9f006836ac1..d239946a46c463 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -2664,6 +2664,9 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd, case FUSE_DEV_IOC_BACKING_CLOSE: return fuse_dev_ioctl_backing_close(file, argp); + 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 701df0d34067ee..5a2910919ba209 100644 --- a/fs/fuse/file_iomap.c +++ b/fs/fuse/file_iomap.c @@ -1756,3 +1756,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; +}