Btrfs: Refactor btrfs_ioctl_snap_create()

Split it into two functions for two different ioctls, since they
share no common code.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
This commit is contained in:
Li Zefan 2010-12-20 15:53:28 +08:00
parent 83a50de97f
commit fa0d2b9bd7

View File

@ -946,58 +946,54 @@ out:
} }
static noinline int btrfs_ioctl_snap_create(struct file *file, static noinline int btrfs_ioctl_snap_create(struct file *file,
void __user *arg, int subvol, void __user *arg, int subvol)
int v2)
{ {
struct btrfs_ioctl_vol_args *vol_args = NULL; struct btrfs_ioctl_vol_args *vol_args;
struct btrfs_ioctl_vol_args_v2 *vol_args_v2 = NULL;
char *name;
u64 fd;
int ret; int ret;
if (v2) { vol_args = memdup_user(arg, sizeof(*vol_args));
u64 transid = 0; if (IS_ERR(vol_args))
u64 *ptr = NULL; return PTR_ERR(vol_args);
vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
vol_args_v2 = memdup_user(arg, sizeof(*vol_args_v2)); ret = btrfs_ioctl_snap_create_transid(file, vol_args->name,
if (IS_ERR(vol_args_v2)) vol_args->fd, subvol, NULL);
return PTR_ERR(vol_args_v2);
if (vol_args_v2->flags & ~BTRFS_SUBVOL_CREATE_ASYNC) { kfree(vol_args);
ret = -EINVAL; return ret;
goto out; }
}
name = vol_args_v2->name; static noinline int btrfs_ioctl_snap_create_v2(struct file *file,
fd = vol_args_v2->fd; void __user *arg, int subvol)
vol_args_v2->name[BTRFS_SUBVOL_NAME_MAX] = '\0'; {
struct btrfs_ioctl_vol_args_v2 *vol_args;
int ret;
u64 transid = 0;
u64 *ptr = NULL;
if (vol_args_v2->flags & BTRFS_SUBVOL_CREATE_ASYNC) vol_args = memdup_user(arg, sizeof(*vol_args));
ptr = &transid; if (IS_ERR(vol_args))
return PTR_ERR(vol_args);
vol_args->name[BTRFS_SUBVOL_NAME_MAX] = '\0';
ret = btrfs_ioctl_snap_create_transid(file, name, fd, if (vol_args->flags & ~BTRFS_SUBVOL_CREATE_ASYNC) {
subvol, ptr); ret = -EINVAL;
goto out;
if (ret == 0 && ptr &&
copy_to_user(arg +
offsetof(struct btrfs_ioctl_vol_args_v2,
transid), ptr, sizeof(*ptr)))
ret = -EFAULT;
} else {
vol_args = memdup_user(arg, sizeof(*vol_args));
if (IS_ERR(vol_args))
return PTR_ERR(vol_args);
name = vol_args->name;
fd = vol_args->fd;
vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
ret = btrfs_ioctl_snap_create_transid(file, name, fd,
subvol, NULL);
} }
if (vol_args->flags & BTRFS_SUBVOL_CREATE_ASYNC)
ptr = &transid;
ret = btrfs_ioctl_snap_create_transid(file, vol_args->name,
vol_args->fd, subvol, ptr);
if (ret == 0 && ptr &&
copy_to_user(arg +
offsetof(struct btrfs_ioctl_vol_args_v2,
transid), ptr, sizeof(*ptr)))
ret = -EFAULT;
out: out:
kfree(vol_args); kfree(vol_args);
kfree(vol_args_v2);
return ret; return ret;
} }
@ -2257,11 +2253,11 @@ long btrfs_ioctl(struct file *file, unsigned int
case FS_IOC_GETVERSION: case FS_IOC_GETVERSION:
return btrfs_ioctl_getversion(file, argp); return btrfs_ioctl_getversion(file, argp);
case BTRFS_IOC_SNAP_CREATE: case BTRFS_IOC_SNAP_CREATE:
return btrfs_ioctl_snap_create(file, argp, 0, 0); return btrfs_ioctl_snap_create(file, argp, 0);
case BTRFS_IOC_SNAP_CREATE_V2: case BTRFS_IOC_SNAP_CREATE_V2:
return btrfs_ioctl_snap_create(file, argp, 0, 1); return btrfs_ioctl_snap_create_v2(file, argp, 0);
case BTRFS_IOC_SUBVOL_CREATE: case BTRFS_IOC_SUBVOL_CREATE:
return btrfs_ioctl_snap_create(file, argp, 1, 0); return btrfs_ioctl_snap_create(file, argp, 1);
case BTRFS_IOC_SNAP_DESTROY: case BTRFS_IOC_SNAP_DESTROY:
return btrfs_ioctl_snap_destroy(file, argp); return btrfs_ioctl_snap_destroy(file, argp);
case BTRFS_IOC_DEFAULT_SUBVOL: case BTRFS_IOC_DEFAULT_SUBVOL: