diff options
author | Amir Goldstein <amir73il@gmail.com> | 2023-08-31 22:07:55 +0200 |
---|---|---|
committer | Miklos Szeredi <mszeredi@redhat.com> | 2024-02-23 17:36:32 +0100 |
commit | aed918310ea2542059eeab6c74defca95c30f77b (patch) | |
tree | 0b564aa6f18752ed26afb31ada9953b842059da7 /fs/fuse/dev.c | |
parent | fuse: allow parallel dio writes with FUSE_DIRECT_IO_ALLOW_MMAP (diff) | |
download | linux-aed918310ea2542059eeab6c74defca95c30f77b.tar.xz linux-aed918310ea2542059eeab6c74defca95c30f77b.zip |
fuse: factor out helper for FUSE_DEV_IOC_CLONE
In preparation to adding more fuse dev ioctls.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/fuse/dev.c')
-rw-r--r-- | fs/fuse/dev.c | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 1a8f82f478cb..eba68b57bd7c 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -2251,43 +2251,50 @@ static int fuse_device_clone(struct fuse_conn *fc, struct file *new) return 0; } -static long fuse_dev_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) +static long fuse_dev_ioctl_clone(struct file *file, __u32 __user *argp) { int res; int oldfd; struct fuse_dev *fud = NULL; struct fd f; + if (get_user(oldfd, argp)) + return -EFAULT; + + f = fdget(oldfd); + if (!f.file) + return -EINVAL; + + /* + * Check against file->f_op because CUSE + * uses the same ioctl handler. + */ + if (f.file->f_op == file->f_op) + fud = fuse_get_dev(f.file); + + res = -EINVAL; + if (fud) { + mutex_lock(&fuse_mutex); + res = fuse_device_clone(fud->fc, file); + mutex_unlock(&fuse_mutex); + } + + fdput(f); + return res; +} + +static long fuse_dev_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + void __user *argp = (void __user *)arg; + switch (cmd) { case FUSE_DEV_IOC_CLONE: - if (get_user(oldfd, (__u32 __user *)arg)) - return -EFAULT; + return fuse_dev_ioctl_clone(file, argp); - f = fdget(oldfd); - if (!f.file) - return -EINVAL; - - /* - * Check against file->f_op because CUSE - * uses the same ioctl handler. - */ - if (f.file->f_op == file->f_op) - fud = fuse_get_dev(f.file); - - res = -EINVAL; - if (fud) { - mutex_lock(&fuse_mutex); - res = fuse_device_clone(fud->fc, file); - mutex_unlock(&fuse_mutex); - } - fdput(f); - break; default: - res = -ENOTTY; - break; + return -ENOTTY; } - return res; } const struct file_operations fuse_dev_operations = { |