]> Git Repo - linux.git/blobdiff - fs/btrfs/ioctl.c
Merge branch 'stable/for-linus-5.1' of git://git.kernel.org/pub/scm/linux/kernel...
[linux.git] / fs / btrfs / ioctl.c
index 9c8e1734429c7649721eeadd3dca941ff2ee490c..494f0f10d70e091664bfa14fd1c6639b3a0b4714 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, true);
        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, true);
 
        if (!dev) {
                ret = -ENODEV;
@@ -3241,32 +3242,17 @@ static void btrfs_double_extent_lock(struct inode *inode1, u64 loff1,
        lock_extent(&BTRFS_I(inode2)->io_tree, loff2, loff2 + len - 1);
 }
 
-static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 olen,
+static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 len,
                                   struct inode *dst, u64 dst_loff)
 {
-       u64 bs = BTRFS_I(src)->root->fs_info->sb->s_blocksize;
        int ret;
-       u64 len = olen;
-
-       if (loff + len == src->i_size)
-               len = ALIGN(src->i_size, bs) - loff;
-       /*
-        * For same inode case we don't want our length pushed out past i_size
-        * as comparing that data range makes no sense.
-        *
-        * This effectively means we require aligned extents for the single
-        * inode case, whereas the other cases allow an unaligned length so long
-        * as it ends at i_size.
-        */
-       if (dst == src && len != olen)
-               return -EINVAL;
 
        /*
         * Lock destination range to serialize with concurrent readpages() and
         * source range to serialize with relocation.
         */
        btrfs_double_extent_lock(src, loff, dst, dst_loff, len);
-       ret = btrfs_clone(src, dst, loff, olen, len, dst_loff, 1);
+       ret = btrfs_clone(src, dst, loff, len, len, dst_loff, 1);
        btrfs_double_extent_unlock(src, loff, dst, dst_loff, len);
 
        return ret;
@@ -3278,21 +3264,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 +3883,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 +3958,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 +4355,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 +4388,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 +4412,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 +4458,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 +4764,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;
        }
This page took 0.035027 seconds and 4 git commands to generate.