summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/FileSystem.cpp
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2022-08-20 09:28:02 +0300
committerAndrew Kaster <andrewdkaster@gmail.com>2022-10-22 16:57:52 -0400
commitfea3cb5ff9127d2f5524d8923157c5281d6b8340 (patch)
tree380041e77cce7ec4642f1d4ff999ca68cbc9db5b /Kernel/FileSystem/FileSystem.cpp
parent24977996a693a05607c8f8788c94d6719a3dbad9 (diff)
downloadserenity-fea3cb5ff9127d2f5524d8923157c5281d6b8340.zip
Kernel/FileSystem: Discard safely filesystems when unmounted last time
This commit reached that goal of "safely discarding" a filesystem by doing the following: 1. Stop using the s_file_system_map HashMap as it was an unsafe measure to access pointers of FileSystems. Instead, make sure to register all FileSystems at the VFS layer, with an IntrusiveList, to avoid problems related to OOM conditions. 2. Make sure to cleanly remove the DiskCache object from a BlockBased filesystem, so the destructor of such object will not need to do that in the destruction point. 3. For ext2 filesystems, don't cache the root inode at m_inode_cache HashMap. The reason for this is that when unmounting an ext2 filesystem, we lookup at the cache to see if there's a reference to a cached inode and if that's the case, we fail with EBUSY. If we keep the m_root_inode also being referenced at the m_inode_cache map, we have 2 references to that object, which will lead to fail with EBUSY. Also, it's much simpler to always ask for a root inode and get it immediately from m_root_inode, instead of looking up the cache for that inode.
Diffstat (limited to 'Kernel/FileSystem/FileSystem.cpp')
-rw-r--r--Kernel/FileSystem/FileSystem.cpp32
1 files changed, 3 insertions, 29 deletions
diff --git a/Kernel/FileSystem/FileSystem.cpp b/Kernel/FileSystem/FileSystem.cpp
index 09f3bfc143..47d88ef485 100644
--- a/Kernel/FileSystem/FileSystem.cpp
+++ b/Kernel/FileSystem/FileSystem.cpp
@@ -9,6 +9,7 @@
#include <AK/StringView.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h>
+#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/InterruptDisabler.h>
#include <Kernel/Memory/MemoryManager.h>
#include <Kernel/Net/LocalSocket.h>
@@ -16,30 +17,14 @@
namespace Kernel {
static u32 s_lastFileSystemID;
-static Singleton<HashMap<FileSystemID, FileSystem*>> s_file_system_map;
-
-static HashMap<FileSystemID, FileSystem*>& all_file_systems()
-{
- return *s_file_system_map;
-}
FileSystem::FileSystem()
: m_fsid(++s_lastFileSystemID)
{
- s_file_system_map->set(m_fsid, this);
}
FileSystem::~FileSystem()
{
- s_file_system_map->remove(m_fsid);
-}
-
-FileSystem* FileSystem::from_fsid(FileSystemID id)
-{
- auto it = all_file_systems().find(id);
- if (it != all_file_systems().end())
- return (*it).value;
- return nullptr;
}
ErrorOr<void> FileSystem::prepare_to_unmount()
@@ -61,23 +46,12 @@ FileSystem::DirectoryEntryView::DirectoryEntryView(StringView n, InodeIdentifier
void FileSystem::sync()
{
Inode::sync_all();
-
- NonnullLockRefPtrVector<FileSystem, 32> file_systems;
- {
- InterruptDisabler disabler;
- for (auto& it : all_file_systems())
- file_systems.append(*it.value);
- }
-
- for (auto& fs : file_systems)
- fs.flush_writes();
+ VirtualFileSystem::the().sync_filesystems();
}
void FileSystem::lock_all()
{
- for (auto& it : all_file_systems()) {
- it.value->m_lock.lock();
- }
+ VirtualFileSystem::the().lock_all_filesystems();
}
}