From 4bc1a9222a64442bb2bcbdabca2c3c0eb4f9dad6 Mon Sep 17 00:00:00 2001 From: swj <1186093704@qq.com> Date: Wed, 23 Apr 2025 22:39:28 +0800 Subject: example: fix memfs_rename deadlock error Signed-off-by: swj <1186093704@qq.com> --- example/memfs_ll.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/example/memfs_ll.cc b/example/memfs_ll.cc index 9898f25..6038850 100644 --- a/example/memfs_ll.cc +++ b/example/memfs_ll.cc @@ -900,6 +900,7 @@ static void memfs_rename(fuse_req_t req, fuse_ino_t parent, const char *name, Inode *parentInode = nullptr; Inode *newparentInode = nullptr; Dentry *child_dentry = nullptr; + Dentry *child_dentry_copy = nullptr; Dentry *existing_dentry = nullptr; if (flags & (RENAME_EXCHANGE | RENAME_NOREPLACE)) { @@ -909,8 +910,8 @@ static void memfs_rename(fuse_req_t req, fuse_ino_t parent, const char *name, Inodes.lock(); - parentInode = Inodes.find(parent); - newparentInode = Inodes.find(newparent); + parentInode = Inodes.find_locked(parent); + newparentInode = Inodes.find_locked(newparent); if (!parentInode || !parentInode->is_dir() || !newparentInode || !newparentInode->is_dir()) { error = ENOENT; @@ -941,9 +942,9 @@ static void memfs_rename(fuse_req_t req, fuse_ino_t parent, const char *name, existing_dentry->get_inode()->dec_nlink(); } + child_dentry_copy = new Dentry(newname, child_dentry->get_inode()); parentInode->remove_child(name); - child_dentry->name = newname; - newparentInode->add_child(newname, child_dentry); + newparentInode->add_child_locked(newname, child_dentry_copy); out_unlock: parentInode->unlock(); -- cgit v1.2.3