btrfs: refactor btrfs_find_device() take fs_devices as argument
[sfrench/cifs-2.6.git] / fs / btrfs / ioctl.c
index 9c8e1734429c7649721eeadd3dca941ff2ee490c..fd5f97aeb35c2c61cc8729070eaeef4135bd9956 100644 (file)
@@ -1642,7 +1642,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
                btrfs_info(fs_info, "resizing devid %llu", devid);
        }
 
-       device = btrfs_find_device(fs_info, devid, NULL, NULL);
+       device = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
        if (!device) {
                btrfs_info(fs_info, "resizer unable to find device %llu",
                           devid);
@@ -3178,7 +3178,8 @@ static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info,
                s_uuid = di_args->uuid;
 
        rcu_read_lock();
-       dev = btrfs_find_device(fs_info, di_args->devid, s_uuid, NULL);
+       dev = btrfs_find_device(fs_info->fs_devices, di_args->devid, s_uuid,
+                               NULL);
 
        if (!dev) {
                ret = -ENODEV;
@@ -3278,21 +3279,10 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,
                             struct inode *dst, u64 dst_loff)
 {
        int ret;
-       int num_pages = PAGE_ALIGN(BTRFS_MAX_DEDUPE_LEN) >> PAGE_SHIFT;
        u64 i, tail_len, chunk_count;
 
-       /* don't make the dst file partly checksummed */
-       if ((BTRFS_I(src)->flags & BTRFS_INODE_NODATASUM) !=
-           (BTRFS_I(dst)->flags & BTRFS_INODE_NODATASUM))
-               return -EINVAL;
-
-       if (IS_SWAPFILE(src) || IS_SWAPFILE(dst))
-               return -ETXTBSY;
-
        tail_len = olen % BTRFS_MAX_DEDUPE_LEN;
        chunk_count = div_u64(olen, BTRFS_MAX_DEDUPE_LEN);
-       if (chunk_count == 0)
-               num_pages = PAGE_ALIGN(tail_len) >> PAGE_SHIFT;
 
        for (i = 0; i < chunk_count; i++) {
                ret = btrfs_extent_same_range(src, loff, BTRFS_MAX_DEDUPE_LEN,
@@ -3908,14 +3898,6 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
         *   be either compressed or non-compressed.
         */
 
-       /* don't make the dst file partly checksummed */
-       if ((BTRFS_I(src)->flags & BTRFS_INODE_NODATASUM) !=
-           (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM))
-               return -EINVAL;
-
-       if (IS_SWAPFILE(src) || IS_SWAPFILE(inode))
-               return -ETXTBSY;
-
        /*
         * VFS's generic_remap_file_range_prep() protects us from cloning the
         * eof block into the middle of a file, which would result in corruption
@@ -3991,6 +3973,13 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in,
        else
                btrfs_double_inode_lock(inode_in, inode_out);
 
+       /* don't make the dst file partly checksummed */
+       if ((BTRFS_I(inode_in)->flags & BTRFS_INODE_NODATASUM) !=
+           (BTRFS_I(inode_out)->flags & BTRFS_INODE_NODATASUM)) {
+               ret = -EINVAL;
+               goto out_unlock;
+       }
+
        /*
         * Now that the inodes are locked, we need to start writeback ourselves
         * and can not rely on the writeback from the VFS's generic helper
@@ -4381,7 +4370,7 @@ static long btrfs_ioctl_scrub(struct file *file, void __user *arg)
                              &sa->progress, sa->flags & BTRFS_SCRUB_READONLY,
                              0);
 
-       if (copy_to_user(arg, sa, sizeof(*sa)))
+       if (ret == 0 && copy_to_user(arg, sa, sizeof(*sa)))
                ret = -EFAULT;
 
        if (!(sa->flags & BTRFS_SCRUB_READONLY))
@@ -4414,7 +4403,7 @@ static long btrfs_ioctl_scrub_progress(struct btrfs_fs_info *fs_info,
 
        ret = btrfs_scrub_progress(fs_info, sa->devid, &sa->progress);
 
-       if (copy_to_user(arg, sa, sizeof(*sa)))
+       if (ret == 0 && copy_to_user(arg, sa, sizeof(*sa)))
                ret = -EFAULT;
 
        kfree(sa);
@@ -4438,7 +4427,7 @@ static long btrfs_ioctl_get_dev_stats(struct btrfs_fs_info *fs_info,
 
        ret = btrfs_get_dev_stats(fs_info, sa);
 
-       if (copy_to_user(arg, sa, sizeof(*sa)))
+       if (ret == 0 && copy_to_user(arg, sa, sizeof(*sa)))
                ret = -EFAULT;
 
        kfree(sa);
@@ -4484,7 +4473,7 @@ static long btrfs_ioctl_dev_replace(struct btrfs_fs_info *fs_info,
                break;
        }
 
-       if (copy_to_user(arg, p, sizeof(*p)))
+       if ((ret == 0 || ret == -ECANCELED) && copy_to_user(arg, p, sizeof(*p)))
                ret = -EFAULT;
 out:
        kfree(p);
@@ -4790,7 +4779,7 @@ do_balance:
        ret = btrfs_balance(fs_info, bctl, bargs);
        bctl = NULL;
 
-       if (arg) {
+       if ((ret == 0 || ret == -ECANCELED) && arg) {
                if (copy_to_user(arg, bargs, sizeof(*bargs)))
                        ret = -EFAULT;
        }