History

btrfs: Perform locking/unlocking in btrfs_remap_file_range()

Move code to make it more readable, so as locking and unlocking is done in the same function. The generic checks that are now performed in the locked section are unaffected.

Goldwyn Rodrigues committed 7 years ago

Commit 7984ae51 parent 290342f1 file · +11 −23Browse files

Unified · Split

fs/btrfs/ioctl.c+11−23
@@ -3950,16 +3950,10 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in, · 3949 unmodified lines
3950 return -EXDEV;3950 return -EXDEV;
3951 }3951 }
3952 3952
3953 if (same_inode)
3954 inode_lock(inode_in);
3955 else
3956 lock_two_nondirectories(inode_in, inode_out);
3957
3958 /* don't make the dst file partly checksummed */3953 /* don't make the dst file partly checksummed */
3959 if ((BTRFS_I(inode_in)->flags & BTRFS_INODE_NODATASUM) !=3954 if ((BTRFS_I(inode_in)->flags & BTRFS_INODE_NODATASUM) !=
3960 (BTRFS_I(inode_out)->flags & BTRFS_INODE_NODATASUM)) {3955 (BTRFS_I(inode_out)->flags & BTRFS_INODE_NODATASUM)) {
3961 ret = -EINVAL;3956 return -EINVAL;
3962 goto out_unlock;
3963 }3957 }
3964 3958
3965 /*3959 /*
@@ -3993,26 +3987,14 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in, · 27 unmodified lines
3993 ret = btrfs_wait_ordered_range(inode_in, ALIGN_DOWN(pos_in, bs),3987 ret = btrfs_wait_ordered_range(inode_in, ALIGN_DOWN(pos_in, bs),
3994 wb_len);3988 wb_len);
3995 if (ret < 0)3989 if (ret < 0)
3996 goto out_unlock;3990 return ret;
3997 ret = btrfs_wait_ordered_range(inode_out, ALIGN_DOWN(pos_out, bs),3991 ret = btrfs_wait_ordered_range(inode_out, ALIGN_DOWN(pos_out, bs),
3998 wb_len);3992 wb_len);
3999 if (ret < 0)3993 if (ret < 0)
4000 goto out_unlock;3994 return ret;
4001 3995
4002 ret = generic_remap_file_range_prep(file_in, pos_in, file_out, pos_out,3996 return generic_remap_file_range_prep(file_in, pos_in, file_out, pos_out,
4003 len, remap_flags);3997 len, remap_flags);
4004 if (ret < 0 || *len == 0)
4005 goto out_unlock;
4006
4007 return 0;
4008
4009 out_unlock:
4010 if (same_inode)
4011 inode_unlock(inode_in);
4012 else
4013 unlock_two_nondirectories(inode_in, inode_out);
4014
4015 return ret;
4016}3998}
4017 3999
4018loff_t btrfs_remap_file_range(struct file *src_file, loff_t off,4000loff_t btrfs_remap_file_range(struct file *src_file, loff_t off,
@@ -4027,16 +4009,22 @@ loff_t btrfs_remap_file_range(struct file *src_file, loff_t off, · 8 unmodified lines
4027 if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY))4009 if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY))
4028 return -EINVAL;4010 return -EINVAL;
4029 4011
4012 if (same_inode)
4013 inode_lock(src_inode);
4014 else
4015 lock_two_nondirectories(src_inode, dst_inode);
4016
4030 ret = btrfs_remap_file_range_prep(src_file, off, dst_file, destoff,4017 ret = btrfs_remap_file_range_prep(src_file, off, dst_file, destoff,
4031 &len, remap_flags);4018 &len, remap_flags);
4032 if (ret < 0 || len == 0)4019 if (ret < 0 || len == 0)
4033 return ret;4020 goto out_unlock;
4034 4021
4035 if (remap_flags & REMAP_FILE_DEDUP)4022 if (remap_flags & REMAP_FILE_DEDUP)
4036 ret = btrfs_extent_same(src_inode, off, len, dst_inode, destoff);4023 ret = btrfs_extent_same(src_inode, off, len, dst_inode, destoff);
4037 else4024 else
4038 ret = btrfs_clone_files(dst_file, src_file, off, len, destoff);4025 ret = btrfs_clone_files(dst_file, src_file, off, len, destoff);
4039 4026
4027out_unlock:
4040 if (same_inode)4028 if (same_inode)
4041 inode_unlock(src_inode);4029 inode_unlock(src_inode);
4042 else4030 else