Skip to content

Commit

Permalink
f2fs: avoid potential deadlock in f2fs_move_file_range
Browse files Browse the repository at this point in the history
Thread A			Thread B
- inode_lock fileA
				- inode_lock fileB
				 - inode_lock fileA
 - inode_lock fileB

We may encounter above potential deadlock during moving file range in
concurrent scenario. This patch fixes the issue by using inode_trylock
instead.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
  • Loading branch information
chaseyu authored and Jaegeuk Kim committed Aug 19, 2016
1 parent fe8494b commit 20a3d61
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions fs/f2fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2093,8 +2093,12 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
return -EOPNOTSUPP;

inode_lock(src);
if (src != dst)
inode_lock(dst);
if (src != dst) {
if (!inode_trylock(dst)) {
ret = -EBUSY;
goto out;
}
}

ret = -EINVAL;
if (pos_in + len > src->i_size || pos_in + len < pos_in)
Expand Down Expand Up @@ -2152,6 +2156,7 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
out_unlock:
if (src != dst)
inode_unlock(dst);
out:
inode_unlock(src);
return ret;
}
Expand Down

0 comments on commit 20a3d61

Please sign in to comment.