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.
Unified · Split
| @@ -3950,16 +3950,10 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in, · 3949 unmodified lines | ||
| 3950 | 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 | 3953 | /* don't make the dst file partly checksummed */ |
| 3959 | 3954 | if ((BTRFS_I(inode_in)->flags & BTRFS_INODE_NODATASUM) != |
| 3960 | 3955 | (BTRFS_I(inode_out)->flags & BTRFS_INODE_NODATASUM)) { |
| 3961 | − ret = -EINVAL; | |
| 3962 | − goto out_unlock; | |
| 3956 | + return -EINVAL; | |
| 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 | 3987 | ret = btrfs_wait_ordered_range(inode_in, ALIGN_DOWN(pos_in, bs), |
| 3994 | 3988 | wb_len); |
| 3995 | 3989 | if (ret < 0) |
| 3996 | − goto out_unlock; | |
| 3990 | + return ret; | |
| 3997 | 3991 | ret = btrfs_wait_ordered_range(inode_out, ALIGN_DOWN(pos_out, bs), |
| 3998 | 3992 | wb_len); |
| 3999 | 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 | 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 | |
| 4018 | 4000 | loff_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 | 4009 | if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) |
| 4028 | 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 | 4017 | ret = btrfs_remap_file_range_prep(src_file, off, dst_file, destoff, |
| 4031 | 4018 | &len, remap_flags); |
| 4032 | 4019 | if (ret < 0 || len == 0) |
| 4033 | − return ret; | |
| 4020 | + goto out_unlock; | |
| 4034 | 4021 | |
| 4035 | 4022 | if (remap_flags & REMAP_FILE_DEDUP) |
| 4036 | 4023 | ret = btrfs_extent_same(src_inode, off, len, dst_inode, destoff); |
| 4037 | 4024 | else |
| 4038 | 4025 | ret = btrfs_clone_files(dst_file, src_file, off, len, destoff); |
| 4039 | 4026 | |
| 4027 | +out_unlock: | |
| 4040 | 4028 | if (same_inode) |
| 4041 | 4029 | inode_unlock(src_inode); |
| 4042 | 4030 | else |