diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2010-12-20 02:53:28 -0500 |
---|---|---|
committer | Li Zefan <lizf@cn.fujitsu.com> | 2010-12-22 19:49:15 -0500 |
commit | fa0d2b9bd717340e0bc4850a80ac0eb344e9a7fb (patch) | |
tree | f17b1e86d602236e7be49821ed8f9109819e29fb /fs | |
parent | 83a50de97fe96aca82389e061862ed760ece2283 (diff) |
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/ioctl.c | 84 |
1 files changed, 40 insertions, 44 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index f87552a1d7e..02554e19d97 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -946,58 +946,54 @@ out: | |||
946 | } | 946 | } |
947 | 947 | ||
948 | static noinline int btrfs_ioctl_snap_create(struct file *file, | 948 | static noinline int btrfs_ioctl_snap_create(struct file *file, |
949 | void __user *arg, int subvol, | 949 | void __user *arg, int subvol) |
950 | int v2) | ||
951 | { | 950 | { |
952 | struct btrfs_ioctl_vol_args *vol_args = NULL; | 951 | struct btrfs_ioctl_vol_args *vol_args; |
953 | struct btrfs_ioctl_vol_args_v2 *vol_args_v2 = NULL; | ||
954 | char *name; | ||
955 | u64 fd; | ||
956 | int ret; | 952 | int ret; |
957 | 953 | ||
958 | if (v2) { | 954 | vol_args = memdup_user(arg, sizeof(*vol_args)); |
959 | u64 transid = 0; | 955 | if (IS_ERR(vol_args)) |
960 | u64 *ptr = NULL; | 956 | return PTR_ERR(vol_args); |
957 | vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; | ||
961 | 958 | ||
962 | vol_args_v2 = memdup_user(arg, sizeof(*vol_args_v2)); | 959 | ret = btrfs_ioctl_snap_create_transid(file, vol_args->name, |
963 | if (IS_ERR(vol_args_v2)) | 960 | vol_args->fd, subvol, NULL); |
964 | return PTR_ERR(vol_args_v2); | ||
965 | 961 | ||
966 | if (vol_args_v2->flags & ~BTRFS_SUBVOL_CREATE_ASYNC) { | 962 | kfree(vol_args); |
967 | ret = -EINVAL; | 963 | return ret; |
968 | goto out; | 964 | } |
969 | } | ||
970 | |||
971 | name = vol_args_v2->name; | ||
972 | fd = vol_args_v2->fd; | ||
973 | vol_args_v2->name[BTRFS_SUBVOL_NAME_MAX] = '\0'; | ||
974 | 965 | ||
975 | if (vol_args_v2->flags & BTRFS_SUBVOL_CREATE_ASYNC) | 966 | static noinline int btrfs_ioctl_snap_create_v2(struct file *file, |
976 | ptr = &transid; | 967 | void __user *arg, int subvol) |
968 | { | ||
969 | struct btrfs_ioctl_vol_args_v2 *vol_args; | ||
970 | int ret; | ||
971 | u64 transid = 0; | ||
972 | u64 *ptr = NULL; | ||
977 | 973 | ||
978 | ret = btrfs_ioctl_snap_create_transid(file, name, fd, | 974 | vol_args = memdup_user(arg, sizeof(*vol_args)); |
979 | subvol, ptr); | 975 | if (IS_ERR(vol_args)) |
976 | return PTR_ERR(vol_args); | ||
977 | vol_args->name[BTRFS_SUBVOL_NAME_MAX] = '\0'; | ||
980 | 978 | ||
981 | if (ret == 0 && ptr && | 979 | if (vol_args->flags & ~BTRFS_SUBVOL_CREATE_ASYNC) { |
982 | copy_to_user(arg + | 980 | ret = -EINVAL; |
983 | offsetof(struct btrfs_ioctl_vol_args_v2, | 981 | goto out; |
984 | transid), ptr, sizeof(*ptr))) | ||
985 | ret = -EFAULT; | ||
986 | } else { | ||
987 | vol_args = memdup_user(arg, sizeof(*vol_args)); | ||
988 | if (IS_ERR(vol_args)) | ||
989 | return PTR_ERR(vol_args); | ||
990 | name = vol_args->name; | ||
991 | fd = vol_args->fd; | ||
992 | vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; | ||
993 | |||
994 | ret = btrfs_ioctl_snap_create_transid(file, name, fd, | ||
995 | subvol, NULL); | ||
996 | } | 982 | } |
983 | |||
984 | if (vol_args->flags & BTRFS_SUBVOL_CREATE_ASYNC) | ||
985 | ptr = &transid; | ||
986 | |||
987 | ret = btrfs_ioctl_snap_create_transid(file, vol_args->name, | ||
988 | vol_args->fd, subvol, ptr); | ||
989 | |||
990 | if (ret == 0 && ptr && | ||
991 | copy_to_user(arg + | ||
992 | offsetof(struct btrfs_ioctl_vol_args_v2, | ||
993 | transid), ptr, sizeof(*ptr))) | ||
994 | ret = -EFAULT; | ||
997 | out: | 995 | out: |
998 | kfree(vol_args); | 996 | kfree(vol_args); |
999 | kfree(vol_args_v2); | ||
1000 | |||
1001 | return ret; | 997 | return ret; |
1002 | } | 998 | } |
1003 | 999 | ||
@@ -2257,11 +2253,11 @@ long btrfs_ioctl(struct file *file, unsigned int | |||
2257 | case FS_IOC_GETVERSION: | 2253 | case FS_IOC_GETVERSION: |
2258 | return btrfs_ioctl_getversion(file, argp); | 2254 | return btrfs_ioctl_getversion(file, argp); |
2259 | case BTRFS_IOC_SNAP_CREATE: | 2255 | case BTRFS_IOC_SNAP_CREATE: |
2260 | return btrfs_ioctl_snap_create(file, argp, 0, 0); | 2256 | return btrfs_ioctl_snap_create(file, argp, 0); |
2261 | case BTRFS_IOC_SNAP_CREATE_V2: | 2257 | case BTRFS_IOC_SNAP_CREATE_V2: |
2262 | return btrfs_ioctl_snap_create(file, argp, 0, 1); | 2258 | return btrfs_ioctl_snap_create_v2(file, argp, 0); |
2263 | case BTRFS_IOC_SUBVOL_CREATE: | 2259 | case BTRFS_IOC_SUBVOL_CREATE: |
2264 | return btrfs_ioctl_snap_create(file, argp, 1, 0); | 2260 | return btrfs_ioctl_snap_create(file, argp, 1); |
2265 | case BTRFS_IOC_SNAP_DESTROY: | 2261 | case BTRFS_IOC_SNAP_DESTROY: |
2266 | return btrfs_ioctl_snap_destroy(file, argp); | 2262 | return btrfs_ioctl_snap_destroy(file, argp); |
2267 | case BTRFS_IOC_DEFAULT_SUBVOL: | 2263 | case BTRFS_IOC_DEFAULT_SUBVOL: |