Prechádzať zdrojové kódy

Kernel: Make Ext2FS::free_inode() return KResult, and use TRY() more

While there's no clear propagation path for errors that happen in an
inode destructor, using TRY() still makes the code a lot nicer.
Andreas Kling 3 rokov pred
rodič
commit
fe98cb2c4b

+ 11 - 12
Kernel/FileSystem/Ext2FileSystem.cpp

@@ -633,7 +633,7 @@ Vector<Ext2FS::BlockIndex> Ext2FSInode::compute_block_list_impl_internal(const e
     return list;
 }
 
-void Ext2FS::free_inode(Ext2FSInode& inode)
+KResult Ext2FS::free_inode(Ext2FSInode& inode)
 {
     MutexLocker locker(m_lock);
     VERIFY(inode.m_raw_inode.i_links_count == 0);
@@ -642,11 +642,8 @@ void Ext2FS::free_inode(Ext2FSInode& inode)
     // Mark all blocks used by this inode as free.
     for (auto block_index : inode.compute_block_list_with_meta_blocks()) {
         VERIFY(block_index <= super_block().s_blocks_count);
-        if (block_index.value()) {
-            if (auto result = set_block_allocation_state(block_index, false); result.is_error()) {
-                dbgln("Ext2FS[{}]::free_inode(): Failed to deallocate block {} for inode {}", fsid(), block_index, inode.index());
-            }
-        }
+        if (block_index.value())
+            TRY(set_block_allocation_state(block_index, false));
     }
 
     // If the inode being freed is a directory, update block group directory counter.
@@ -660,12 +657,12 @@ void Ext2FS::free_inode(Ext2FSInode& inode)
     // NOTE: After this point, the inode metadata is wiped.
     memset(&inode.m_raw_inode, 0, sizeof(ext2_inode));
     inode.m_raw_inode.i_dtime = kgettimeofday().to_truncated_seconds();
-    if (auto result = write_ext2_inode(inode.index(), inode.m_raw_inode); result.is_error())
-        dbgln("Ext2FS[{}]::free_inode(): Failed to write inode {}: {}", fsid(), inode.index(), result.error());
+    TRY(write_ext2_inode(inode.index(), inode.m_raw_inode));
 
     // Mark the inode as free.
-    if (auto result = set_inode_allocation_state(inode.index(), false); result.is_error())
-        dbgln("Ext2FS[{}]::free_inode(): Failed to free inode {}: {}", fsid(), inode.index(), result.error());
+    TRY(set_inode_allocation_state(inode.index(), false));
+
+    return KSuccess;
 }
 
 void Ext2FS::flush_block_group_descriptor_table()
@@ -736,8 +733,10 @@ Ext2FSInode::Ext2FSInode(Ext2FS& fs, InodeIndex index)
 
 Ext2FSInode::~Ext2FSInode()
 {
-    if (m_raw_inode.i_links_count == 0)
-        fs().free_inode(*this);
+    if (m_raw_inode.i_links_count == 0) {
+        // Alas, we have nowhere to propagate any errors that occur here.
+        (void)fs().free_inode(*this);
+    }
 }
 
 u64 Ext2FSInode::size() const

+ 1 - 1
Kernel/FileSystem/Ext2FileSystem.h

@@ -145,7 +145,7 @@ private:
     KResult set_block_allocation_state(BlockIndex, bool);
 
     void uncache_inode(InodeIndex);
-    void free_inode(Ext2FSInode&);
+    KResult free_inode(Ext2FSInode&);
 
     struct BlockListShape {
         unsigned direct_blocks { 0 };