aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ioctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r--fs/btrfs/ioctl.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index fce6fd0e3f50..8a8e29878c34 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1019,8 +1019,10 @@ static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em)
1019 return false; 1019 return false;
1020 1020
1021 next = defrag_lookup_extent(inode, em->start + em->len); 1021 next = defrag_lookup_extent(inode, em->start + em->len);
1022 if (!next || next->block_start >= EXTENT_MAP_LAST_BYTE || 1022 if (!next || next->block_start >= EXTENT_MAP_LAST_BYTE)
1023 (em->block_start + em->block_len == next->block_start)) 1023 ret = false;
1024 else if ((em->block_start + em->block_len == next->block_start) &&
1025 (em->block_len > 128 * 1024 && next->block_len > 128 * 1024))
1024 ret = false; 1026 ret = false;
1025 1027
1026 free_extent_map(next); 1028 free_extent_map(next);
@@ -1055,7 +1057,6 @@ static int should_defrag_range(struct inode *inode, u64 start, int thresh,
1055 } 1057 }
1056 1058
1057 next_mergeable = defrag_check_next_extent(inode, em); 1059 next_mergeable = defrag_check_next_extent(inode, em);
1058
1059 /* 1060 /*
1060 * we hit a real extent, if it is big or the next extent is not a 1061 * we hit a real extent, if it is big or the next extent is not a
1061 * real extent, don't bother defragging it 1062 * real extent, don't bother defragging it
@@ -1702,7 +1703,7 @@ static noinline int btrfs_ioctl_snap_create_v2(struct file *file,
1702 ~(BTRFS_SUBVOL_CREATE_ASYNC | BTRFS_SUBVOL_RDONLY | 1703 ~(BTRFS_SUBVOL_CREATE_ASYNC | BTRFS_SUBVOL_RDONLY |
1703 BTRFS_SUBVOL_QGROUP_INHERIT)) { 1704 BTRFS_SUBVOL_QGROUP_INHERIT)) {
1704 ret = -EOPNOTSUPP; 1705 ret = -EOPNOTSUPP;
1705 goto out; 1706 goto free_args;
1706 } 1707 }
1707 1708
1708 if (vol_args->flags & BTRFS_SUBVOL_CREATE_ASYNC) 1709 if (vol_args->flags & BTRFS_SUBVOL_CREATE_ASYNC)
@@ -1712,27 +1713,31 @@ static noinline int btrfs_ioctl_snap_create_v2(struct file *file,
1712 if (vol_args->flags & BTRFS_SUBVOL_QGROUP_INHERIT) { 1713 if (vol_args->flags & BTRFS_SUBVOL_QGROUP_INHERIT) {
1713 if (vol_args->size > PAGE_CACHE_SIZE) { 1714 if (vol_args->size > PAGE_CACHE_SIZE) {
1714 ret = -EINVAL; 1715 ret = -EINVAL;
1715 goto out; 1716 goto free_args;
1716 } 1717 }
1717 inherit = memdup_user(vol_args->qgroup_inherit, vol_args->size); 1718 inherit = memdup_user(vol_args->qgroup_inherit, vol_args->size);
1718 if (IS_ERR(inherit)) { 1719 if (IS_ERR(inherit)) {
1719 ret = PTR_ERR(inherit); 1720 ret = PTR_ERR(inherit);
1720 goto out; 1721 goto free_args;
1721 } 1722 }
1722 } 1723 }
1723 1724
1724 ret = btrfs_ioctl_snap_create_transid(file, vol_args->name, 1725 ret = btrfs_ioctl_snap_create_transid(file, vol_args->name,
1725 vol_args->fd, subvol, ptr, 1726 vol_args->fd, subvol, ptr,
1726 readonly, inherit); 1727 readonly, inherit);
1728 if (ret)
1729 goto free_inherit;
1727 1730
1728 if (ret == 0 && ptr && 1731 if (ptr && copy_to_user(arg +
1729 copy_to_user(arg + 1732 offsetof(struct btrfs_ioctl_vol_args_v2,
1730 offsetof(struct btrfs_ioctl_vol_args_v2, 1733 transid),
1731 transid), ptr, sizeof(*ptr))) 1734 ptr, sizeof(*ptr)))
1732 ret = -EFAULT; 1735 ret = -EFAULT;
1733out: 1736
1734 kfree(vol_args); 1737free_inherit:
1735 kfree(inherit); 1738 kfree(inherit);
1739free_args:
1740 kfree(vol_args);
1736 return ret; 1741 return ret;
1737} 1742}
1738 1743
@@ -2652,7 +2657,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
2652 vol_args = memdup_user(arg, sizeof(*vol_args)); 2657 vol_args = memdup_user(arg, sizeof(*vol_args));
2653 if (IS_ERR(vol_args)) { 2658 if (IS_ERR(vol_args)) {
2654 ret = PTR_ERR(vol_args); 2659 ret = PTR_ERR(vol_args);
2655 goto out; 2660 goto err_drop;
2656 } 2661 }
2657 2662
2658 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; 2663 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
@@ -2670,6 +2675,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
2670 2675
2671out: 2676out:
2672 kfree(vol_args); 2677 kfree(vol_args);
2678err_drop:
2673 mnt_drop_write_file(file); 2679 mnt_drop_write_file(file);
2674 return ret; 2680 return ret;
2675} 2681}