Kernel/FileSystem: Mark ext2 inode lookup cache non-const

For the lookup cache, no method being declared const tried to modify it,
so it was easy to drop the mutable declaration on the HashMap member.
This commit is contained in:
Liav A 2022-08-06 18:07:03 +03:00 committed by Idan Horowitz
commit 843bd43c5b
Notes: sideshowbarker 2024-07-17 07:07:16 +09:00
2 changed files with 5 additions and 5 deletions

View file

@ -1499,9 +1499,9 @@ ErrorOr<NonnullLockRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode
return new_inode; return new_inode;
} }
ErrorOr<void> Ext2FSInode::populate_lookup_cache() const ErrorOr<void> Ext2FSInode::populate_lookup_cache()
{ {
MutexLocker locker(m_inode_lock); VERIFY(m_inode_lock.is_exclusively_locked_by_current_thread());
if (!m_lookup_cache.is_empty()) if (!m_lookup_cache.is_empty())
return {}; return {};
HashMap<NonnullOwnPtr<KString>, InodeIndex> children; HashMap<NonnullOwnPtr<KString>, InodeIndex> children;
@ -1521,11 +1521,11 @@ ErrorOr<NonnullLockRefPtr<Inode>> Ext2FSInode::lookup(StringView name)
{ {
VERIFY(is_directory()); VERIFY(is_directory());
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): Looking up '{}'", identifier(), name); dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): Looking up '{}'", identifier(), name);
TRY(populate_lookup_cache());
InodeIndex inode_index; InodeIndex inode_index;
{ {
MutexLocker locker(m_inode_lock); MutexLocker locker(m_inode_lock);
TRY(populate_lookup_cache());
auto it = m_lookup_cache.find(name); auto it = m_lookup_cache.find(name);
if (it == m_lookup_cache.end()) { if (it == m_lookup_cache.end()) {
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): '{}' not found", identifier(), name); dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): '{}' not found", identifier(), name);

View file

@ -53,7 +53,7 @@ private:
virtual ErrorOr<int> get_block_address(int) override; virtual ErrorOr<int> get_block_address(int) override;
ErrorOr<void> write_directory(Vector<Ext2FSDirectoryEntry>&); ErrorOr<void> write_directory(Vector<Ext2FSDirectoryEntry>&);
ErrorOr<void> populate_lookup_cache() const; ErrorOr<void> populate_lookup_cache();
ErrorOr<void> resize(u64); ErrorOr<void> resize(u64);
ErrorOr<void> write_indirect_block(BlockBasedFileSystem::BlockIndex, Span<BlockBasedFileSystem::BlockIndex>); ErrorOr<void> write_indirect_block(BlockBasedFileSystem::BlockIndex, Span<BlockBasedFileSystem::BlockIndex>);
ErrorOr<void> grow_doubly_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, Span<BlockBasedFileSystem::BlockIndex>, Vector<BlockBasedFileSystem::BlockIndex>&, unsigned&); ErrorOr<void> grow_doubly_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, Span<BlockBasedFileSystem::BlockIndex>, Vector<BlockBasedFileSystem::BlockIndex>&, unsigned&);
@ -71,7 +71,7 @@ private:
Ext2FSInode(Ext2FS&, InodeIndex); Ext2FSInode(Ext2FS&, InodeIndex);
mutable Vector<BlockBasedFileSystem::BlockIndex> m_block_list; mutable Vector<BlockBasedFileSystem::BlockIndex> m_block_list;
mutable HashMap<NonnullOwnPtr<KString>, InodeIndex> m_lookup_cache; HashMap<NonnullOwnPtr<KString>, InodeIndex> m_lookup_cache;
ext2_inode m_raw_inode {}; ext2_inode m_raw_inode {};
}; };