hulk inclusion category: bugfix bugzilla: https://atomgit.com/src-openeuler/kernel/issues/13283 ------------------ In MFS's remote mode, the directory tree in cache layer will sync from mtree layer. The MFS will hold the parent inode lock and truncate the file which will hold the sb_writers lock first. At this time, if one process create file in the same parent directory, it will holds the sb_writers lock first. And this cause the ABBA deadlock. ``` CPU0 CPU1 ---- ---- lock(&type->i_mutex_dir_key#6/1); lock(sb_writers#9); lock(&type->i_mutex_dir_key#6/1); rlock(sb_writers#9); ``` Fixes: d4b9a6307289 ("mfs: Add basic metadata operation for MFS") Signed-off-by: Hongbo Li <lihongbo22@huawei.com> --- fs/mfs/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/mfs/inode.c b/fs/mfs/inode.c index e45a5da7a67c..83ae8580573b 100644 --- a/fs/mfs/inode.c +++ b/fs/mfs/inode.c @@ -90,18 +90,21 @@ static int _lookup_create(struct path *lpath, struct path *parent_cpath, dput(dentry); goto retry; } + inode_unlock(cdir); } else { /* dir or file, symlink will be considerred the regular file */ ret = vfs_create(&nop_mnt_idmap, cdir, dentry, linode->i_mode, true); if (ret) goto new_err; + inode_unlock(cdir); ret = vfs_truncate(cpath, linode->i_size); if (ret) goto truncate_err; } - goto out; + return ret; truncate_err: + inode_lock_nested(cdir, I_MUTEX_PARENT); _ret = vfs_unlink(&nop_mnt_idmap, cdir, dentry, NULL); if (_ret) pr_err("cleanup failed for file:%s, err:%d\n", name, _ret); -- 2.34.1