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.
This commit is contained in:
Andreas Kling 2021-07-16 01:38:50 +02:00
parent a7d193951f
commit 98c230b370
Notes: sideshowbarker 2024-07-18 08:57:06 +09:00

View file

@ -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())