diff options
author | Liav A <liavalb@gmail.com> | 2022-08-20 09:28:02 +0300 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-10-22 16:57:52 -0400 |
commit | fea3cb5ff9127d2f5524d8923157c5281d6b8340 (patch) | |
tree | 380041e77cce7ec4642f1d4ff999ca68cbc9db5b /Kernel/FileSystem/BlockBasedFileSystem.cpp | |
parent | 24977996a693a05607c8f8788c94d6719a3dbad9 (diff) | |
download | serenity-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/BlockBasedFileSystem.cpp')
-rw-r--r-- | Kernel/FileSystem/BlockBasedFileSystem.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Kernel/FileSystem/BlockBasedFileSystem.cpp b/Kernel/FileSystem/BlockBasedFileSystem.cpp index b343022ecf..4e78a5d3ed 100644 --- a/Kernel/FileSystem/BlockBasedFileSystem.cpp +++ b/Kernel/FileSystem/BlockBasedFileSystem.cpp @@ -27,7 +27,7 @@ public: , m_entries(move(entries_buffer)) { for (size_t i = 0; i < EntryCount; ++i) { - entries()[i].data = m_cached_block_data->data() + i * m_fs.block_size(); + entries()[i].data = m_cached_block_data->data() + i * m_fs->block_size(); m_clean_list.append(entries()[i]); } } @@ -72,7 +72,7 @@ public: // Not a single clean entry! Flush writes and try again. // NOTE: We want to make sure we only call FileBackedFileSystem flush here, // not some FileBackedFileSystem subclass flush! - m_fs.flush_writes_impl(); + m_fs->flush_writes_impl(); return ensure(block_index); } @@ -100,10 +100,10 @@ public: } private: - BlockBasedFileSystem& m_fs; - mutable HashMap<BlockBasedFileSystem::BlockIndex, CacheEntry*> m_hash; - mutable IntrusiveList<&CacheEntry::list_node> m_clean_list; + mutable NonnullRefPtr<BlockBasedFileSystem> m_fs; mutable IntrusiveList<&CacheEntry::list_node> m_dirty_list; + mutable IntrusiveList<&CacheEntry::list_node> m_clean_list; + mutable HashMap<BlockBasedFileSystem::BlockIndex, CacheEntry*> m_hash; NonnullOwnPtr<KBuffer> m_cached_block_data; NonnullOwnPtr<KBuffer> m_entries; }; @@ -116,6 +116,14 @@ BlockBasedFileSystem::BlockBasedFileSystem(OpenFileDescription& file_description BlockBasedFileSystem::~BlockBasedFileSystem() = default; +void BlockBasedFileSystem::remove_disk_cache_before_last_unmount() +{ + VERIFY(m_lock.is_locked()); + m_cache.with_exclusive([&](auto& cache) { + cache.clear(); + }); +} + ErrorOr<void> BlockBasedFileSystem::initialize_while_locked() { VERIFY(m_lock.is_locked()); |