From 98c230b37046bedba672515d8624a4fda4cc5f4f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 16 Jul 2021 01:38:50 +0200 Subject: [PATCH] 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. --- Kernel/FileSystem/Ext2FileSystem.cpp | 7 +++++++ 1 file changed, 7 insertions(+) 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 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())