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.
This commit is contained in:
Andreas Kling 2019-11-03 00:21:17 +01:00
parent 1e36d899f1
commit dcf8d359f3
Notes: sideshowbarker 2024-07-19 11:27:54 +09:00
2 changed files with 12 additions and 4 deletions

View File

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

View File

@ -16,6 +16,8 @@ public:
virtual void flush_writes() override;
void flush_writes_impl();
protected:
explicit DiskBackedFS(NonnullRefPtr<DiskDevice>&&);