浏览代码

Kernel/Ext2FS: Don't hog both locks in Ext2FSInode::lookup()

This function was acquiring both the inode and file system locks (in
that order) which could lead to deadlocks.
Andreas Kling 4 年之前
父节点
当前提交
ace8b9a0ee
共有 1 个文件被更改,包括 12 次插入6 次删除
  1. 12 6
      Kernel/FileSystem/Ext2FileSystem.cpp

+ 12 - 6
Kernel/FileSystem/Ext2FileSystem.cpp

@@ -1623,12 +1623,18 @@ RefPtr<Inode> Ext2FSInode::lookup(StringView name)
     dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): Looking up '{}'", identifier(), name);
     if (populate_lookup_cache().is_error())
         return {};
-    Locker locker(m_lock);
-    auto it = m_lookup_cache.find(name.hash(), [&](auto& entry) { return entry.key == name; });
-    if (it != m_lookup_cache.end())
-        return fs().get_inode({ fsid(), (*it).value });
-    dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): '{}' not found", identifier(), name);
-    return {};
+
+    InodeIndex inode_index;
+    {
+        Locker locker(m_lock);
+        auto it = m_lookup_cache.find(name.hash(), [&](auto& entry) { return entry.key == name; });
+        if (it == m_lookup_cache.end()) {
+            dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): '{}' not found", identifier(), name);
+            return {};
+        }
+        inode_index = it->value;
+    }
+    return fs().get_inode({ fsid(), inode_index });
 }
 
 void Ext2FSInode::one_ref_left()