Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

f2fs: avoid potential deadlock in f2fs_move_file_range

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>

authored by

Chao Yu and committed by
Jaegeuk Kim
20a3d61d fe8494bf

+7 -2
+7 -2
fs/f2fs/file.c
··· 2093 2093 return -EOPNOTSUPP; 2094 2094 2095 2095 inode_lock(src); 2096 - if (src != dst) 2097 - inode_lock(dst); 2096 + if (src != dst) { 2097 + if (!inode_trylock(dst)) { 2098 + ret = -EBUSY; 2099 + goto out; 2100 + } 2101 + } 2098 2102 2099 2103 ret = -EINVAL; 2100 2104 if (pos_in + len > src->i_size || pos_in + len < pos_in) ··· 2156 2152 out_unlock: 2157 2153 if (src != dst) 2158 2154 inode_unlock(dst); 2155 + out: 2159 2156 inode_unlock(src); 2160 2157 return ret; 2161 2158 }