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
39503950 return -EXDEV;
39513951 }
39523952
3953− if (same_inode)
3954− inode_lock(inode_in);
3955− else
3956− lock_two_nondirectories(inode_in, inode_out);
3957−
39583953 /* don't make the dst file partly checksummed */
39593954 if ((BTRFS_I(inode_in)->flags & BTRFS_INODE_NODATASUM) !=
39603955 (BTRFS_I(inode_out)->flags & BTRFS_INODE_NODATASUM)) {
3961− ret = -EINVAL;
3962− goto out_unlock;
3956+ return -EINVAL;
39633957 }
39643958
39653959 /*
@@ -3993,26 +3987,14 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in, · 27 unmodified lines
39933987 ret = btrfs_wait_ordered_range(inode_in, ALIGN_DOWN(pos_in, bs),
39943988 wb_len);
39953989 if (ret < 0)
3996− goto out_unlock;
3990+ return ret;
39973991 ret = btrfs_wait_ordered_range(inode_out, ALIGN_DOWN(pos_out, bs),
39983992 wb_len);
39993993 if (ret < 0)
4000− goto out_unlock;
3994+ return ret;
40013995
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,
40033997 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;
40163998 }
40173999
40184000 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
40274009 if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY))
40284010 return -EINVAL;
40294011
4012+ if (same_inode)
4013+ inode_lock(src_inode);
4014+ else
4015+ lock_two_nondirectories(src_inode, dst_inode);
4016+
40304017 ret = btrfs_remap_file_range_prep(src_file, off, dst_file, destoff,
40314018 &len, remap_flags);
40324019 if (ret < 0 || len == 0)
4033− return ret;
4020+ goto out_unlock;
40344021
40354022 if (remap_flags & REMAP_FILE_DEDUP)
40364023 ret = btrfs_extent_same(src_inode, off, len, dst_inode, destoff);
40374024 else
40384025 ret = btrfs_clone_files(dst_file, src_file, off, len, destoff);
40394026
4027+out_unlock:
40404028 if (same_inode)
40414029 inode_unlock(src_inode);
40424030 else