From abcf05801ad259c06197b9ef54a76e58cf319509 Mon Sep 17 00:00:00 2001 From: Zak-K-Abdi Date: Tue, 1 Aug 2023 07:48:43 +0100 Subject: [PATCH] Kernel: Allow Ext2FS::flush_writes() to return ErrorOr --- Kernel/FileSystem/BlockBasedFileSystem.cpp | 3 ++- Kernel/FileSystem/BlockBasedFileSystem.h | 2 +- Kernel/FileSystem/Ext2FS/FileSystem.cpp | 13 +++++++++---- Kernel/FileSystem/Ext2FS/FileSystem.h | 2 +- Kernel/FileSystem/FileSystem.h | 2 +- Kernel/FileSystem/Inode.cpp | 6 +++++- Kernel/FileSystem/VirtualFileSystem.cpp | 8 ++++++-- Kernel/Tasks/PowerStateSwitchTask.cpp | 2 +- 8 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Kernel/FileSystem/BlockBasedFileSystem.cpp b/Kernel/FileSystem/BlockBasedFileSystem.cpp index 1f203a7043..c60a2e1caa 100644 --- a/Kernel/FileSystem/BlockBasedFileSystem.cpp +++ b/Kernel/FileSystem/BlockBasedFileSystem.cpp @@ -305,9 +305,10 @@ void BlockBasedFileSystem::flush_writes_impl() }); } -void BlockBasedFileSystem::flush_writes() +ErrorOr BlockBasedFileSystem::flush_writes() { flush_writes_impl(); + return {}; } } diff --git a/Kernel/FileSystem/BlockBasedFileSystem.h b/Kernel/FileSystem/BlockBasedFileSystem.h index 3fb80e46ff..4b1b23ffae 100644 --- a/Kernel/FileSystem/BlockBasedFileSystem.h +++ b/Kernel/FileSystem/BlockBasedFileSystem.h @@ -19,7 +19,7 @@ public: u64 device_block_size() const { return m_device_block_size; } - virtual void flush_writes() override; + virtual ErrorOr flush_writes() override; void flush_writes_impl(); protected: diff --git a/Kernel/FileSystem/Ext2FS/FileSystem.cpp b/Kernel/FileSystem/Ext2FS/FileSystem.cpp index 67ad8e8083..f4f354fed3 100644 --- a/Kernel/FileSystem/Ext2FS/FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FS/FileSystem.cpp @@ -662,7 +662,7 @@ void Ext2FS::flush_block_group_descriptor_table() } } -void Ext2FS::flush_writes() +ErrorOr Ext2FS::flush_writes() { { MutexLocker locker(m_lock); @@ -670,8 +670,7 @@ void Ext2FS::flush_writes() auto result = flush_super_block(); if (result.is_error()) { dbgln("Ext2FS[{}]::flush_writes(): Failed to write superblock: {}", fsid(), result.error()); - // FIXME: We should handle this error. - VERIFY_NOT_REACHED(); + return result.release_error(); } m_super_block_dirty = false; } @@ -708,7 +707,13 @@ void Ext2FS::flush_writes() }); } - BlockBasedFileSystem::flush_writes(); + auto result = BlockBasedFileSystem::flush_writes(); + if (result.is_error()) { + dbgln("Ext2FS[{}]::flush_writes(): Failed to flush writes: {}", BlockBasedFileSystem::fsid(), result.error()); + return result.release_error(); + } + + return {}; } ErrorOr> Ext2FS::build_root_inode() const diff --git a/Kernel/FileSystem/Ext2FS/FileSystem.h b/Kernel/FileSystem/Ext2FS/FileSystem.h index 8080837dff..586346028c 100644 --- a/Kernel/FileSystem/Ext2FS/FileSystem.h +++ b/Kernel/FileSystem/Ext2FS/FileSystem.h @@ -77,7 +77,7 @@ private: ErrorOr> get_inode(InodeIdentifier) const; ErrorOr> create_inode(Ext2FSInode& parent_inode, StringView name, mode_t, dev_t, UserID, GroupID); ErrorOr> create_directory(Ext2FSInode& parent_inode, StringView name, mode_t, UserID, GroupID); - virtual void flush_writes() override; + virtual ErrorOr flush_writes() override; BlockIndex first_block_index() const; BlockIndex first_block_of_block_group_descriptors() const; diff --git a/Kernel/FileSystem/FileSystem.h b/Kernel/FileSystem/FileSystem.h index ffd4f74a0e..0bb72530e8 100644 --- a/Kernel/FileSystem/FileSystem.h +++ b/Kernel/FileSystem/FileSystem.h @@ -51,7 +51,7 @@ public: u8 file_type { 0 }; }; - virtual void flush_writes() { } + virtual ErrorOr flush_writes() { return {}; } u64 logical_block_size() const { return m_logical_block_size; } size_t fragment_size() const { return m_fragment_size; } diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index 3cce39ea8c..bc248f45f5 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -48,7 +48,11 @@ void Inode::sync() { if (is_metadata_dirty()) (void)flush_metadata(); - fs().flush_writes(); + auto result = fs().flush_writes(); + if (result.is_error()) { + // TODO: Figure out how to propagate error to a higher function. + } + } ErrorOr> Inode::resolve_as_link(Credentials const& credentials, Custody& base, RefPtr* out_parent, int options, int symlink_recursion_level) const diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index a1d5219f69..0bbbde1c3d 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -259,8 +259,12 @@ void VirtualFileSystem::sync_filesystems() file_systems.append(fs); }); - for (auto& fs : file_systems) - fs->flush_writes(); + for (auto& fs : file_systems) { + auto result = fs->flush_writes(); + if (result.is_error()) { + //TODO: Figure out how to propagate error to a higher function. + } + } } void VirtualFileSystem::lock_all_filesystems() diff --git a/Kernel/Tasks/PowerStateSwitchTask.cpp b/Kernel/Tasks/PowerStateSwitchTask.cpp index 4fed1b4632..fff0ef4319 100644 --- a/Kernel/Tasks/PowerStateSwitchTask.cpp +++ b/Kernel/Tasks/PowerStateSwitchTask.cpp @@ -106,7 +106,7 @@ ErrorOr PowerStateSwitchTask::perform_shutdown(PowerStateSwitchTask::DoReb while (!mounts.is_empty()) { auto& mount = mounts.take_last(); - mount.guest_fs().flush_writes(); + TRY(mount.guest_fs().flush_writes()); auto mount_path = TRY(mount.absolute_path()); auto& mount_inode = mount.guest();