summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-07 10:47:11 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-07 10:47:11 +0100
commit4df92709c801e6cbdbaea71d55550171e65a95b3 (patch)
tree3ccc733f2478829d964e2f98afbd7c970cda3f64
parentb5e5541cbc81c821eddb194254d5305c256fa5a3 (diff)
downloadserenity-4df92709c801e6cbdbaea71d55550171e65a95b3.zip
Kernel: Add proper locking to SynthFS and stop disabling interrupts.
-rw-r--r--Kernel/DevPtsFS.cpp2
-rw-r--r--Kernel/SyntheticFileSystem.cpp13
-rw-r--r--Kernel/SyntheticFileSystem.h1
3 files changed, 12 insertions, 4 deletions
diff --git a/Kernel/DevPtsFS.cpp b/Kernel/DevPtsFS.cpp
index 72738a8ed2..ee7cb2bddd 100644
--- a/Kernel/DevPtsFS.cpp
+++ b/Kernel/DevPtsFS.cpp
@@ -59,13 +59,11 @@ RetainPtr<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index)
void DevPtsFS::register_slave_pty(SlavePTY& slave_pty)
{
- InterruptDisabler disabler;
auto inode_id = add_file(create_slave_pty_device_file(slave_pty.index()));
slave_pty.set_devpts_inode_id(inode_id);
}
void DevPtsFS::unregister_slave_pty(SlavePTY& slave_pty)
{
- InterruptDisabler disabler;
remove_file(slave_pty.devpts_inode_id().index());
}
diff --git a/Kernel/SyntheticFileSystem.cpp b/Kernel/SyntheticFileSystem.cpp
index fd396731b5..221168ee52 100644
--- a/Kernel/SyntheticFileSystem.cpp
+++ b/Kernel/SyntheticFileSystem.cpp
@@ -87,7 +87,7 @@ RetainPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<B
InodeIdentifier SynthFS::add_file(RetainPtr<SynthFSInode>&& file, InodeIndex parent)
{
- ASSERT_INTERRUPTS_DISABLED();
+ LOCKER(m_lock);
ASSERT(file);
auto it = m_inodes.find(parent);
ASSERT(it != m_inodes.end());
@@ -101,7 +101,7 @@ InodeIdentifier SynthFS::add_file(RetainPtr<SynthFSInode>&& file, InodeIndex par
bool SynthFS::remove_file(InodeIndex inode)
{
- ASSERT_INTERRUPTS_DISABLED();
+ LOCKER(m_lock);
auto it = m_inodes.find(inode);
if (it == m_inodes.end())
return false;
@@ -158,16 +158,19 @@ RetainPtr<Inode> SynthFS::create_directory(InodeIdentifier, const String&, mode_
auto SynthFS::generate_inode_index() -> InodeIndex
{
+ LOCKER(m_lock);
return m_next_inode_index++;
}
RetainPtr<Inode> SynthFSInode::parent() const
{
+ LOCKER(m_lock);
return fs().get_inode(m_parent);
}
RetainPtr<Inode> SynthFS::get_inode(InodeIdentifier inode) const
{
+ LOCKER(m_lock);
auto it = m_inodes.find(inode.index());
if (it == m_inodes.end())
return { };
@@ -191,6 +194,7 @@ InodeMetadata SynthFSInode::metadata() const
ssize_t SynthFSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDescriptor* descriptor) const
{
+ LOCKER(m_lock);
#ifdef SYNTHFS_DEBUG
kprintf("SynthFS: read_bytes %u\n", index());
#endif
@@ -218,6 +222,7 @@ ssize_t SynthFSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileD
bool SynthFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)> callback) const
{
+ LOCKER(m_lock);
#ifdef SYNTHFS_DEBUG
kprintf("SynthFS: traverse_as_directory %u\n", index());
#endif
@@ -235,6 +240,7 @@ bool SynthFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&
InodeIdentifier SynthFSInode::lookup(const String& name)
{
+ LOCKER(m_lock);
ASSERT(is_directory());
if (name == ".")
return identifier();
@@ -249,6 +255,7 @@ InodeIdentifier SynthFSInode::lookup(const String& name)
String SynthFSInode::reverse_lookup(InodeIdentifier child_id)
{
+ LOCKER(m_lock);
ASSERT(is_directory());
for (auto& child : m_children) {
if (child->identifier() == child_id)
@@ -263,6 +270,7 @@ void SynthFSInode::flush_metadata()
ssize_t SynthFSInode::write_bytes(off_t offset, size_t size, const byte* buffer, FileDescriptor*)
{
+ LOCKER(m_lock);
if (!m_write_callback)
return -EPERM;
// FIXME: Being able to write into SynthFS at a non-zero offset seems like something we should support..
@@ -296,6 +304,7 @@ SynthFSInodeCustomData::~SynthFSInodeCustomData()
size_t SynthFSInode::directory_entry_count() const
{
+ LOCKER(m_lock);
ASSERT(is_directory());
// NOTE: The 2 is for '.' and '..'
return m_children.size() + 2;
diff --git a/Kernel/SyntheticFileSystem.h b/Kernel/SyntheticFileSystem.h
index a001c5b913..f1cc853785 100644
--- a/Kernel/SyntheticFileSystem.h
+++ b/Kernel/SyntheticFileSystem.h
@@ -37,6 +37,7 @@ protected:
private:
InodeIndex m_next_inode_index { 2 };
HashMap<InodeIndex, RetainPtr<SynthFSInode>> m_inodes;
+ mutable Lock m_lock;
};
struct SynthFSInodeCustomData {