diff options
author | Andreas Kling <kling@serenityos.org> | 2022-02-03 01:37:46 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-03 16:11:26 +0100 |
commit | 210689281f1eee5c635dc20aed110410e1d36424 (patch) | |
tree | 894979fdf0b6e1d5b95f3165030b5068fd08ac35 | |
parent | 3becff9eaeb70639b1ff72e8c19133b51d2ef9c8 (diff) | |
download | serenity-210689281f1eee5c635dc20aed110410e1d36424.zip |
Kernel: Protect mounted filesystem list with spinlock instead of mutex
-rw-r--r-- | Kernel/FileSystem/VirtualFileSystem.cpp | 14 | ||||
-rw-r--r-- | Kernel/FileSystem/VirtualFileSystem.h | 4 |
2 files changed, 9 insertions, 9 deletions
diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 8a4f68737b..8efdacc338 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -52,7 +52,7 @@ InodeIdentifier VirtualFileSystem::root_inode_id() const ErrorOr<void> VirtualFileSystem::mount(FileSystem& fs, Custody& mount_point, int flags) { - return m_mounts.with_exclusive([&](auto& mounts) -> ErrorOr<void> { + return m_mounts.with([&](auto& mounts) -> ErrorOr<void> { auto& inode = mount_point.inode(); dbgln("VirtualFileSystem: Mounting {} at inode {} with flags {}", fs.class_name(), @@ -67,7 +67,7 @@ ErrorOr<void> VirtualFileSystem::mount(FileSystem& fs, Custody& mount_point, int ErrorOr<void> VirtualFileSystem::bind_mount(Custody& source, Custody& mount_point, int flags) { - return m_mounts.with_exclusive([&](auto& mounts) -> ErrorOr<void> { + return m_mounts.with([&](auto& mounts) -> ErrorOr<void> { dbgln("VirtualFileSystem: Bind-mounting inode {} at inode {}", source.inode().identifier(), mount_point.inode().identifier()); // FIXME: check that this is not already a mount point Mount mount { source.inode(), mount_point, flags }; @@ -92,7 +92,7 @@ ErrorOr<void> VirtualFileSystem::unmount(Inode& guest_inode) { dbgln("VirtualFileSystem: unmount called with inode {}", guest_inode.identifier()); - return m_mounts.with_exclusive([&](auto& mounts) -> ErrorOr<void> { + return m_mounts.with([&](auto& mounts) -> ErrorOr<void> { for (size_t i = 0; i < mounts.size(); ++i) { auto& mount = mounts[i]; if (&mount.guest() != &guest_inode) @@ -126,7 +126,7 @@ ErrorOr<void> VirtualFileSystem::mount_root(FileSystem& fs) auto pseudo_path = TRY(static_cast<FileBackedFileSystem&>(fs).file_description().pseudo_path()); dmesgln("VirtualFileSystem: mounted root from {} ({})", fs.class_name(), pseudo_path); - m_mounts.with_exclusive([&](auto& mounts) { + m_mounts.with([&](auto& mounts) { mounts.append(move(mount)); }); @@ -136,7 +136,7 @@ ErrorOr<void> VirtualFileSystem::mount_root(FileSystem& fs) auto VirtualFileSystem::find_mount_for_host(InodeIdentifier id) -> Mount* { - return m_mounts.with_exclusive([&](auto& mounts) -> Mount* { + return m_mounts.with([&](auto& mounts) -> Mount* { for (auto& mount : mounts) { if (mount.host() && mount.host()->identifier() == id) return &mount; @@ -147,7 +147,7 @@ auto VirtualFileSystem::find_mount_for_host(InodeIdentifier id) -> Mount* auto VirtualFileSystem::find_mount_for_guest(InodeIdentifier id) -> Mount* { - return m_mounts.with_exclusive([&](auto& mounts) -> Mount* { + return m_mounts.with([&](auto& mounts) -> Mount* { for (auto& mount : mounts) { if (mount.guest().identifier() == id) return &mount; @@ -724,7 +724,7 @@ ErrorOr<void> VirtualFileSystem::rmdir(StringView path, Custody& base) void VirtualFileSystem::for_each_mount(Function<IterationDecision(Mount const&)> callback) const { - m_mounts.with_shared([&](auto& mounts) { + m_mounts.with([&](auto& mounts) { for (auto& mount : mounts) { if (callback(mount) == IterationDecision::Break) break; diff --git a/Kernel/FileSystem/VirtualFileSystem.h b/Kernel/FileSystem/VirtualFileSystem.h index 9fbde822ca..72993c3093 100644 --- a/Kernel/FileSystem/VirtualFileSystem.h +++ b/Kernel/FileSystem/VirtualFileSystem.h @@ -19,7 +19,7 @@ #include <Kernel/FileSystem/Mount.h> #include <Kernel/FileSystem/UnveilNode.h> #include <Kernel/Forward.h> -#include <Kernel/Locking/MutexProtected.h> +#include <Kernel/Locking/SpinlockProtected.h> namespace Kernel { @@ -95,7 +95,7 @@ private: RefPtr<Inode> m_root_inode; RefPtr<Custody> m_root_custody; - MutexProtected<Vector<Mount, 16>> m_mounts; + SpinlockProtected<Vector<Mount, 16>> m_mounts; }; } |