aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ioctl.c
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2017-01-18 02:37:38 -0500
committerDavid Sterba <dsterba@suse.com>2017-02-14 09:50:58 -0500
commitfc4badd9fe6aab008b85024f0e6af9b58cca283c (patch)
tree57d81e2c511dde2b48d87fc3eda5e4397a6743b2 /fs/btrfs/ioctl.c
parent310712b2f73ac1da4c3a99fd9886e8b652727508 (diff)
Btrfs: refactor btrfs_extent_same() slightly
This was originally a prep patch for changing the behavior on len=0, but we went another direction with that. This still makes the function slightly easier to follow. Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Omar Sandoval <osandov@fb.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r--fs/btrfs/ioctl.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 529cc273e817..77f93a1e65c7 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3125,26 +3125,27 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,
3125 int ret; 3125 int ret;
3126 u64 len = olen; 3126 u64 len = olen;
3127 struct cmp_pages cmp; 3127 struct cmp_pages cmp;
3128 int same_inode = 0; 3128 bool same_inode = (src == dst);
3129 u64 same_lock_start = 0; 3129 u64 same_lock_start = 0;
3130 u64 same_lock_len = 0; 3130 u64 same_lock_len = 0;
3131 3131
3132 if (src == dst)
3133 same_inode = 1;
3134
3135 if (len == 0) 3132 if (len == 0)
3136 return 0; 3133 return 0;
3137 3134
3138 if (same_inode) { 3135 if (same_inode)
3139 inode_lock(src); 3136 inode_lock(src);
3137 else
3138 btrfs_double_inode_lock(src, dst);
3140 3139
3141 ret = extent_same_check_offsets(src, loff, &len, olen); 3140 ret = extent_same_check_offsets(src, loff, &len, olen);
3142 if (ret) 3141 if (ret)
3143 goto out_unlock; 3142 goto out_unlock;
3144 ret = extent_same_check_offsets(src, dst_loff, &len, olen);
3145 if (ret)
3146 goto out_unlock;
3147 3143
3144 ret = extent_same_check_offsets(dst, dst_loff, &len, olen);
3145 if (ret)
3146 goto out_unlock;
3147
3148 if (same_inode) {
3148 /* 3149 /*
3149 * Single inode case wants the same checks, except we 3150 * Single inode case wants the same checks, except we
3150 * don't want our length pushed out past i_size as 3151 * don't want our length pushed out past i_size as
@@ -3172,16 +3173,6 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,
3172 3173
3173 same_lock_start = min_t(u64, loff, dst_loff); 3174 same_lock_start = min_t(u64, loff, dst_loff);
3174 same_lock_len = max_t(u64, loff, dst_loff) + len - same_lock_start; 3175 same_lock_len = max_t(u64, loff, dst_loff) + len - same_lock_start;
3175 } else {
3176 btrfs_double_inode_lock(src, dst);
3177
3178 ret = extent_same_check_offsets(src, loff, &len, olen);
3179 if (ret)
3180 goto out_unlock;
3181
3182 ret = extent_same_check_offsets(dst, dst_loff, &len, olen);
3183 if (ret)
3184 goto out_unlock;
3185 } 3176 }
3186 3177
3187 /* don't make the dst file partly checksummed */ 3178 /* don't make the dst file partly checksummed */