summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-28 21:51:59 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-28 21:51:59 +0100
commit6b581aff773659ff5201450bb25d6bbc360d3b30 (patch)
tree133311b9cf0e89dd2f7f973530a5ab18aa253d02
parentbff5b71467b9ef1f5fcee496923dbc9a814fee40 (diff)
downloadserenity-6b581aff773659ff5201450bb25d6bbc360d3b30.zip
Kernel: Make a copy of the dirty inode list before iterating in sync().
-rw-r--r--Kernel/Ext2FileSystem.cpp1
-rw-r--r--Kernel/Ext2FileSystem.h1
-rw-r--r--Kernel/FileSystem.cpp18
-rw-r--r--Kernel/FileSystem.h4
-rw-r--r--Kernel/SyntheticFileSystem.cpp1
-rw-r--r--Kernel/SyntheticFileSystem.h1
6 files changed, 18 insertions, 8 deletions
diff --git a/Kernel/Ext2FileSystem.cpp b/Kernel/Ext2FileSystem.cpp
index cac3049d01..8b813de1f3 100644
--- a/Kernel/Ext2FileSystem.cpp
+++ b/Kernel/Ext2FileSystem.cpp
@@ -20,7 +20,6 @@ Retained<Ext2FS> Ext2FS::create(Retained<DiskDevice>&& device)
Ext2FS::Ext2FS(Retained<DiskDevice>&& device)
: DiskBackedFS(move(device))
- , m_lock("Ext2FS")
{
}
diff --git a/Kernel/Ext2FileSystem.h b/Kernel/Ext2FileSystem.h
index c6c8b57575..cbd280a29e 100644
--- a/Kernel/Ext2FileSystem.h
+++ b/Kernel/Ext2FileSystem.h
@@ -133,7 +133,6 @@ private:
mutable ByteBuffer m_cached_super_block;
mutable ByteBuffer m_cached_group_descriptor_table;
- mutable Lock m_lock;
mutable HashMap<BlockIndex, RetainPtr<Ext2FSInode>> m_inode_cache;
};
diff --git a/Kernel/FileSystem.cpp b/Kernel/FileSystem.cpp
index 2b6758a9bf..d6ca427ec0 100644
--- a/Kernel/FileSystem.cpp
+++ b/Kernel/FileSystem.cpp
@@ -25,7 +25,8 @@ HashTable<Inode*>& all_inodes()
}
FS::FS()
- : m_fsid(++s_lastFileSystemID)
+ : m_lock("FS")
+ , m_fsid(++s_lastFileSystemID)
{
all_fses().set(m_fsid, this);
}
@@ -143,9 +144,18 @@ int Inode::decrement_link_count()
void FS::sync()
{
- for (auto* inode : all_inodes()) {
- if (inode->is_metadata_dirty())
- inode->flush_metadata();
+ Vector<Retained<Inode>> inodes;
+ {
+ InterruptDisabler disabler;
+ for (auto* inode : all_inodes()) {
+ if (inode->is_metadata_dirty())
+ inodes.unchecked_append(*inode);
+ }
+ }
+
+ for (auto& inode : inodes) {
+ ASSERT(inode->is_metadata_dirty());
+ inode->flush_metadata();
}
}
diff --git a/Kernel/FileSystem.h b/Kernel/FileSystem.h
index 6cc2dca2b7..a186c4ff6d 100644
--- a/Kernel/FileSystem.h
+++ b/Kernel/FileSystem.h
@@ -25,6 +25,7 @@ class LocalSocket;
class VMObject;
class FS : public Retainable<FS> {
+ friend class Inode;
public:
virtual ~FS();
@@ -60,6 +61,8 @@ public:
protected:
FS();
+ mutable Lock m_lock;
+
private:
unsigned m_fsid { 0 };
bool m_readonly { false };
@@ -67,6 +70,7 @@ private:
class Inode : public Retainable<Inode> {
friend class VFS;
+ friend class FS;
public:
virtual ~Inode();
diff --git a/Kernel/SyntheticFileSystem.cpp b/Kernel/SyntheticFileSystem.cpp
index 61dd4637d0..bcf37dcf0f 100644
--- a/Kernel/SyntheticFileSystem.cpp
+++ b/Kernel/SyntheticFileSystem.cpp
@@ -11,7 +11,6 @@ Retained<SynthFS> SynthFS::create()
}
SynthFS::SynthFS()
- : m_lock("SynthFS")
{
}
diff --git a/Kernel/SyntheticFileSystem.h b/Kernel/SyntheticFileSystem.h
index f0cebaedbf..c1b95e5fe6 100644
--- a/Kernel/SyntheticFileSystem.h
+++ b/Kernel/SyntheticFileSystem.h
@@ -37,7 +37,6 @@ protected:
private:
InodeIndex m_next_inode_index { 2 };
HashMap<InodeIndex, RetainPtr<SynthFSInode>> m_inodes;
- mutable Lock m_lock;
};
struct SynthFSInodeCustomData {