summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/Ext2FileSystem.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-16 01:38:50 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-16 02:40:53 +0200
commit98c230b37046bedba672515d8624a4fda4cc5f4f (patch)
tree04bb4636394a499af09b5d05647fd05fba25edf7 /Kernel/FileSystem/Ext2FileSystem.cpp
parenta7d193951f94b44105288a22bd0829123a4fcd35 (diff)
downloadserenity-98c230b37046bedba672515d8624a4fda4cc5f4f.zip
Kernel/Ext2FS: Uncache unknown inode indices when flushing writes
Ext2FS::get_inode() will remember unknown inode indices that it has been asked about and put them into the inode cache as null inodes. flush_writes() was not null-checking these while iterating, which was a bug I finally managed to hit. Flushing also seemed like a good time to drop unknown inodes from the cache, since there's no good reason to hold to them indefinitely.
Diffstat (limited to 'Kernel/FileSystem/Ext2FileSystem.cpp')
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp
index bd2b081129..ade39a1a8d 100644
--- a/Kernel/FileSystem/Ext2FileSystem.cpp
+++ b/Kernel/FileSystem/Ext2FileSystem.cpp
@@ -718,6 +718,13 @@ void Ext2FS::flush_writes()
// for their (child name lookup) and (block list) caches.
Vector<InodeIndex> unused_inodes;
for (auto& it : m_inode_cache) {
+ // NOTE: If we're asked to look up an inode by number (via get_inode) and it turns out
+ // to not exist, we remember the fact that it doesn't exist by caching a nullptr.
+ // This seems like a reasonable time to uncache ideas about unknown inodes, so do that.
+ if (!it.value) {
+ unused_inodes.append(it.key);
+ continue;
+ }
if (it.value->ref_count() != 1)
continue;
if (it.value->has_watchers())