Skip to content

Commit

Permalink
Kernel/Ext2FS: Don't hog both locks in Ext2FSInode::lookup()
Browse files Browse the repository at this point in the history
This function was acquiring both the inode and file system locks (in
that order) which could lead to deadlocks.
  • Loading branch information
awesomekling committed Jul 16, 2021
1 parent 9d7e391 commit ace8b9a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Kernel/FileSystem/Ext2FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ace8b9a

Please sign in to comment.