mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:32:45 +00:00 
			
		
		
		
	Kernel: Add proper locking to SynthFS and stop disabling interrupts.
This commit is contained in:
		
							parent
							
								
									b5e5541cbc
								
							
						
					
					
						commit
						4df92709c8
					
				
					 3 changed files with 12 additions and 4 deletions
				
			
		|  | @ -59,13 +59,11 @@ RetainPtr<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index) | ||||||
| 
 | 
 | ||||||
| void DevPtsFS::register_slave_pty(SlavePTY& slave_pty) | void DevPtsFS::register_slave_pty(SlavePTY& slave_pty) | ||||||
| { | { | ||||||
|     InterruptDisabler disabler; |  | ||||||
|     auto inode_id = add_file(create_slave_pty_device_file(slave_pty.index())); |     auto inode_id = add_file(create_slave_pty_device_file(slave_pty.index())); | ||||||
|     slave_pty.set_devpts_inode_id(inode_id); |     slave_pty.set_devpts_inode_id(inode_id); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void DevPtsFS::unregister_slave_pty(SlavePTY& slave_pty) | void DevPtsFS::unregister_slave_pty(SlavePTY& slave_pty) | ||||||
| { | { | ||||||
|     InterruptDisabler disabler; |  | ||||||
|     remove_file(slave_pty.devpts_inode_id().index()); |     remove_file(slave_pty.devpts_inode_id().index()); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -87,7 +87,7 @@ RetainPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<B | ||||||
| 
 | 
 | ||||||
| InodeIdentifier SynthFS::add_file(RetainPtr<SynthFSInode>&& file, InodeIndex parent) | InodeIdentifier SynthFS::add_file(RetainPtr<SynthFSInode>&& file, InodeIndex parent) | ||||||
| { | { | ||||||
|     ASSERT_INTERRUPTS_DISABLED(); |     LOCKER(m_lock); | ||||||
|     ASSERT(file); |     ASSERT(file); | ||||||
|     auto it = m_inodes.find(parent); |     auto it = m_inodes.find(parent); | ||||||
|     ASSERT(it != m_inodes.end()); |     ASSERT(it != m_inodes.end()); | ||||||
|  | @ -101,7 +101,7 @@ InodeIdentifier SynthFS::add_file(RetainPtr<SynthFSInode>&& file, InodeIndex par | ||||||
| 
 | 
 | ||||||
| bool SynthFS::remove_file(InodeIndex inode) | bool SynthFS::remove_file(InodeIndex inode) | ||||||
| { | { | ||||||
|     ASSERT_INTERRUPTS_DISABLED(); |     LOCKER(m_lock); | ||||||
|     auto it = m_inodes.find(inode); |     auto it = m_inodes.find(inode); | ||||||
|     if (it == m_inodes.end()) |     if (it == m_inodes.end()) | ||||||
|         return false; |         return false; | ||||||
|  | @ -158,16 +158,19 @@ RetainPtr<Inode> SynthFS::create_directory(InodeIdentifier, const String&, mode_ | ||||||
| 
 | 
 | ||||||
| auto SynthFS::generate_inode_index() -> InodeIndex | auto SynthFS::generate_inode_index() -> InodeIndex | ||||||
| { | { | ||||||
|  |     LOCKER(m_lock); | ||||||
|     return m_next_inode_index++; |     return m_next_inode_index++; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| RetainPtr<Inode> SynthFSInode::parent() const | RetainPtr<Inode> SynthFSInode::parent() const | ||||||
| { | { | ||||||
|  |     LOCKER(m_lock); | ||||||
|     return fs().get_inode(m_parent); |     return fs().get_inode(m_parent); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| RetainPtr<Inode> SynthFS::get_inode(InodeIdentifier inode) const | RetainPtr<Inode> SynthFS::get_inode(InodeIdentifier inode) const | ||||||
| { | { | ||||||
|  |     LOCKER(m_lock); | ||||||
|     auto it = m_inodes.find(inode.index()); |     auto it = m_inodes.find(inode.index()); | ||||||
|     if (it == m_inodes.end()) |     if (it == m_inodes.end()) | ||||||
|         return { }; |         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 | ssize_t SynthFSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDescriptor* descriptor) const | ||||||
| { | { | ||||||
|  |     LOCKER(m_lock); | ||||||
| #ifdef SYNTHFS_DEBUG | #ifdef SYNTHFS_DEBUG | ||||||
|     kprintf("SynthFS: read_bytes %u\n", index()); |     kprintf("SynthFS: read_bytes %u\n", index()); | ||||||
| #endif | #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 | bool SynthFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)> callback) const | ||||||
| { | { | ||||||
|  |     LOCKER(m_lock); | ||||||
| #ifdef SYNTHFS_DEBUG | #ifdef SYNTHFS_DEBUG | ||||||
|     kprintf("SynthFS: traverse_as_directory %u\n", index()); |     kprintf("SynthFS: traverse_as_directory %u\n", index()); | ||||||
| #endif | #endif | ||||||
|  | @ -235,6 +240,7 @@ bool SynthFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry& | ||||||
| 
 | 
 | ||||||
| InodeIdentifier SynthFSInode::lookup(const String& name) | InodeIdentifier SynthFSInode::lookup(const String& name) | ||||||
| { | { | ||||||
|  |     LOCKER(m_lock); | ||||||
|     ASSERT(is_directory()); |     ASSERT(is_directory()); | ||||||
|     if (name == ".") |     if (name == ".") | ||||||
|         return identifier(); |         return identifier(); | ||||||
|  | @ -249,6 +255,7 @@ InodeIdentifier SynthFSInode::lookup(const String& name) | ||||||
| 
 | 
 | ||||||
| String SynthFSInode::reverse_lookup(InodeIdentifier child_id) | String SynthFSInode::reverse_lookup(InodeIdentifier child_id) | ||||||
| { | { | ||||||
|  |     LOCKER(m_lock); | ||||||
|     ASSERT(is_directory()); |     ASSERT(is_directory()); | ||||||
|     for (auto& child : m_children) { |     for (auto& child : m_children) { | ||||||
|         if (child->identifier() == child_id) |         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*) | ssize_t SynthFSInode::write_bytes(off_t offset, size_t size, const byte* buffer, FileDescriptor*) | ||||||
| { | { | ||||||
|  |     LOCKER(m_lock); | ||||||
|     if (!m_write_callback) |     if (!m_write_callback) | ||||||
|         return -EPERM; |         return -EPERM; | ||||||
|     // FIXME: Being able to write into SynthFS at a non-zero offset seems like something we should support..
 |     // 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 | size_t SynthFSInode::directory_entry_count() const | ||||||
| { | { | ||||||
|  |     LOCKER(m_lock); | ||||||
|     ASSERT(is_directory()); |     ASSERT(is_directory()); | ||||||
|     // NOTE: The 2 is for '.' and '..'
 |     // NOTE: The 2 is for '.' and '..'
 | ||||||
|     return m_children.size() + 2; |     return m_children.size() + 2; | ||||||
|  |  | ||||||
|  | @ -37,6 +37,7 @@ protected: | ||||||
| private: | private: | ||||||
|     InodeIndex m_next_inode_index { 2 }; |     InodeIndex m_next_inode_index { 2 }; | ||||||
|     HashMap<InodeIndex, RetainPtr<SynthFSInode>> m_inodes; |     HashMap<InodeIndex, RetainPtr<SynthFSInode>> m_inodes; | ||||||
|  |     mutable Lock m_lock; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| struct SynthFSInodeCustomData { | struct SynthFSInodeCustomData { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling