From 81d8ab3d79ecc8fcdc2f740dc0a1a637584a41e5 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 21 May 2026 01:57:56 +0300 Subject: [PATCH] Kernel: Remove completely unnecessary lock on file lookup Mount point lookup already does locking internally, there is no need for a lock for the whole duration of the lookup :D --- kernel/include/kernel/FS/VirtualFileSystem.h | 3 ++- kernel/kernel/FS/VirtualFileSystem.cpp | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel/include/kernel/FS/VirtualFileSystem.h b/kernel/include/kernel/FS/VirtualFileSystem.h index 1c475efe..478498cf 100644 --- a/kernel/include/kernel/FS/VirtualFileSystem.h +++ b/kernel/include/kernel/FS/VirtualFileSystem.h @@ -92,8 +92,9 @@ namespace Kernel MountPoint* mount_from_root_inode(BAN::RefPtr); private: - Mutex m_mutex; BAN::RefPtr m_root_fs; + + Mutex m_mount_point_lock; BAN::Vector m_mount_points; friend class BAN::RefPtr; diff --git a/kernel/kernel/FS/VirtualFileSystem.cpp b/kernel/kernel/FS/VirtualFileSystem.cpp index cbdc813b..e4a83c16 100644 --- a/kernel/kernel/FS/VirtualFileSystem.cpp +++ b/kernel/kernel/FS/VirtualFileSystem.cpp @@ -210,14 +210,14 @@ namespace Kernel if (!file.inode->mode().ifdir()) return BAN::Error::from_errno(ENOTDIR); - LockGuard _(m_mutex); + LockGuard _(m_mount_point_lock); TRY(m_mount_points.emplace_back(file_system, BAN::move(file))); return {}; } VirtualFileSystem::MountPoint* VirtualFileSystem::mount_from_host_inode(BAN::RefPtr inode) { - LockGuard _(m_mutex); + LockGuard _(m_mount_point_lock); for (MountPoint& mount : m_mount_points) if (*mount.host.inode == *inode) return &mount; @@ -226,7 +226,7 @@ namespace Kernel VirtualFileSystem::MountPoint* VirtualFileSystem::mount_from_root_inode(BAN::RefPtr inode) { - LockGuard _(m_mutex); + LockGuard _(m_mount_point_lock); for (MountPoint& mount : m_mount_points) if (*mount.target->root_inode() == *inode) return &mount; @@ -235,8 +235,6 @@ namespace Kernel BAN::ErrorOr VirtualFileSystem::file_from_relative_path(BAN::RefPtr root_inode, const File& parent, const Credentials& credentials, BAN::StringView path, int flags) { - LockGuard _(m_mutex); - auto inode = parent.inode; ASSERT(inode);