Commit aed91831 authored by Amir Goldstein's avatar Amir Goldstein Committed by Miklos Szeredi

fuse: factor out helper for FUSE_DEV_IOC_CLONE

In preparation to adding more fuse dev ioctls.
Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 205c1d80
...@@ -2251,43 +2251,50 @@ static int fuse_device_clone(struct fuse_conn *fc, struct file *new) ...@@ -2251,43 +2251,50 @@ static int fuse_device_clone(struct fuse_conn *fc, struct file *new)
return 0; return 0;
} }
static long fuse_dev_ioctl(struct file *file, unsigned int cmd, static long fuse_dev_ioctl_clone(struct file *file, __u32 __user *argp)
unsigned long arg)
{ {
int res; int res;
int oldfd; int oldfd;
struct fuse_dev *fud = NULL; struct fuse_dev *fud = NULL;
struct fd f; 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) { switch (cmd) {
case FUSE_DEV_IOC_CLONE: case FUSE_DEV_IOC_CLONE:
if (get_user(oldfd, (__u32 __user *)arg)) return fuse_dev_ioctl_clone(file, 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);
break;
default: default:
res = -ENOTTY; return -ENOTTY;
break;
} }
return res;
} }
const struct file_operations fuse_dev_operations = { const struct file_operations fuse_dev_operations = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment