summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-11-23 16:19:30 +0100
committerAndreas Kling <kling@serenityos.org>2020-11-23 16:19:30 +0100
commitdfce9051faf758c9eddae5f5607f6cdd734eeef6 (patch)
tree828107f8631547713aa2f7b949ed223b88db5441
parent086522537eca0b63f8dcb45c4852c95d23014d52 (diff)
downloadserenity-dfce9051faf758c9eddae5f5607f6cdd734eeef6.zip
ProcFS: Take the "all inodes" lock when generating /proc/inodes
Otherwise the kernel asserts.
-rw-r--r--Kernel/FileSystem/Inode.cpp5
-rw-r--r--Kernel/FileSystem/Inode.h2
-rw-r--r--Kernel/FileSystem/ProcFS.cpp1
3 files changed, 8 insertions, 0 deletions
diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp
index 106c39ffd6..e19ffcac90 100644
--- a/Kernel/FileSystem/Inode.cpp
+++ b/Kernel/FileSystem/Inode.cpp
@@ -41,6 +41,11 @@ namespace Kernel {
static SpinLock s_all_inodes_lock;
static AK::Singleton<InlineLinkedList<Inode>> s_list;
+SpinLock<u32>& Inode::all_inodes_lock()
+{
+ return s_all_inodes_lock;
+}
+
InlineLinkedList<Inode>& Inode::all_with_lock()
{
ASSERT(s_all_inodes_lock.is_locked());
diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h
index 2567e6fcc4..7cea0178c6 100644
--- a/Kernel/FileSystem/Inode.h
+++ b/Kernel/FileSystem/Inode.h
@@ -120,6 +120,8 @@ public:
Inode* m_next { nullptr };
Inode* m_prev { nullptr };
+ static SpinLock<u32>& all_inodes_lock();
+
protected:
Inode(FS& fs, unsigned index);
void set_metadata_dirty(bool);
diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp
index d3ab37c2ad..6e5996a23b 100644
--- a/Kernel/FileSystem/ProcFS.cpp
+++ b/Kernel/FileSystem/ProcFS.cpp
@@ -914,6 +914,7 @@ static Optional<KBuffer> procfs$inodes(InodeIdentifier)
{
KBufferBuilder builder;
InterruptDisabler disabler;
+ ScopedSpinLock all_inodes_lock(Inode::all_inodes_lock());
for (auto& inode : Inode::all_with_lock()) {
builder.appendf("Inode{K%x} %02u:%08u (%u)\n", &inode, inode.fsid(), inode.index(), inode.ref_count());
}