From dcf8d359f36789d8395c14dcc038a4da5c75245b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 3 Nov 2019 00:21:17 +0100 Subject: [PATCH] Kernel: Fick infinite recursion when filling up disk cache We can't be calling the virtual FS::flush_writes() in order to flush the disk cache from within the disk cache, since an FS subclass may try to do cache stuff in its flush_writes() implementation. Instead, separate out the implementation of DiskBackedFS's flushing logic into a flush_writes_impl() and call that from the cache code. --- Kernel/FileSystem/DiskBackedFileSystem.cpp | 14 ++++++++++---- Kernel/FileSystem/DiskBackedFileSystem.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Kernel/FileSystem/DiskBackedFileSystem.cpp b/Kernel/FileSystem/DiskBackedFileSystem.cpp index f0b24f1957..6c2c1d0693 100644 --- a/Kernel/FileSystem/DiskBackedFileSystem.cpp +++ b/Kernel/FileSystem/DiskBackedFileSystem.cpp @@ -50,7 +50,9 @@ public: } if (!oldest_clean_entry) { // Not a single clean entry! Flush writes and try again. - m_fs.flush_writes(); + // NOTE: We want to make sure we only call DiskBackedFS flush here, + // not some DiskBackedFS subclass flush! + m_fs.flush_writes_impl(); return get(block_index); } @@ -148,7 +150,7 @@ bool DiskBackedFS::read_blocks(unsigned index, unsigned count, u8* buffer) const return true; } -void DiskBackedFS::flush_writes() +void DiskBackedFS::flush_writes_impl() { LOCKER(m_lock); if (!cache().is_dirty()) @@ -163,8 +165,12 @@ void DiskBackedFS::flush_writes() entry.is_dirty = false; }); cache().set_dirty(false); - dbg() << class_name() << ": " - << "Flushed " << count << " blocks to disk"; + dbg() << class_name() << ": Flushed " << count << " blocks to disk"; +} + +void DiskBackedFS::flush_writes() +{ + flush_writes_impl(); } DiskCache& DiskBackedFS::cache() const diff --git a/Kernel/FileSystem/DiskBackedFileSystem.h b/Kernel/FileSystem/DiskBackedFileSystem.h index bfd797ffb6..2d287fed3b 100644 --- a/Kernel/FileSystem/DiskBackedFileSystem.h +++ b/Kernel/FileSystem/DiskBackedFileSystem.h @@ -16,6 +16,8 @@ public: virtual void flush_writes() override; + void flush_writes_impl(); + protected: explicit DiskBackedFS(NonnullRefPtr&&);