Skip to content

Commit

Permalink
Btrfs: unlock inodes in correct order in clone ioctl
Browse files Browse the repository at this point in the history
In the clone ioctl, when the source and target inodes are different,
we can acquire their mutexes in 2 possible different orders. After
we're done cloning, we were releasing the mutexes always in the same
order - the most correct way of doing it is to release them by the
reverse order they were acquired.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
  • Loading branch information
Filipe David Borba Manana authored and Chris Mason committed Jan 28, 2014
1 parent f499e40 commit c57c2b3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3263,9 +3263,17 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,

unlock_extent(&BTRFS_I(src)->io_tree, off, off + len - 1);
out_unlock:
mutex_unlock(&src->i_mutex);
if (!same_inode)
mutex_unlock(&inode->i_mutex);
if (!same_inode) {
if (inode < src) {
mutex_unlock(&src->i_mutex);
mutex_unlock(&inode->i_mutex);
} else {
mutex_unlock(&inode->i_mutex);
mutex_unlock(&src->i_mutex);
}
} else {
mutex_unlock(&src->i_mutex);
}
out_fput:
fdput(src_file);
out_drop_write:
Expand Down

0 comments on commit c57c2b3

Please sign in to comment.