• Zhihao Cheng's avatar
    ext4: fix unttached inode after power cut with orphan file feature enabled · 15247734
    Zhihao Cheng authored
    Running generic/475(filesystem consistent tests after power cut) could
    easily trigger unattached inode error while doing fsck:
      Unattached zero-length inode 39405.  Clear? no
    
      Unattached inode 39405
      Connect to /lost+found? no
    
    Above inconsistence is caused by following process:
           P1                       P2
    ext4_create
     inode = ext4_new_inode_start_handle  // itable records nlink=1
     ext4_add_nondir
       err = ext4_add_entry  // ENOSPC
        ext4_append
         ext4_bread
          ext4_getblk
           ext4_map_blocks // returns ENOSPC
       drop_nlink(inode) // won't be updated into disk inode
       ext4_orphan_add(handle, inode)
        ext4_orphan_file_add
     ext4_journal_stop(handle)
    		      jbd2_journal_commit_transaction // commit success
                  >> power cut <<
    ext4_fill_super
     ext4_load_and_init_journal   // itable records nlink=1
     ext4_orphan_cleanup
      ext4_process_orphan
       if (inode->i_nlink)        // true, inode won't be deleted
    
    Then, allocated inode will be reserved on disk and corresponds to no
    dentries, so e2fsck reports 'unattached inode' problem.
    
    The problem won't happen if orphan file feature is disabled, because
    ext4_orphan_add() will update disk inode in orphan list mode. There
    are several places not updating disk inode while putting inode into
    orphan area, such as ext4_add_nondir(), ext4_symlink() and whiteout
    in ext4_rename(). Fix it by updating inode into disk in all error
    branches of these places.
    
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=217605
    Fixes: 02f310fc ("ext4: Speedup ext4 orphan inode handling")
    Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
    Reviewed-by: default avatarJan Kara <jack@suse.cz>
    Link: https://lore.kernel.org/r/20230628132011.650383-1-chengzhihao1@huawei.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
    15247734
namei.c 111 KB