• Z
    Revert "ext4: Stop trying writing pages if no free blocks generated" · 1dd1a93d
    Zhihao Cheng 提交于
    hulk inclusion
    category: bugfix
    bugzilla: https://gitee.com/openeuler/kernel/issues/I7CBCS
    CVE: NA
    
    --------------------------------
    
    This reverts commit 07a8109d.
    
    When ext4 runs out of space, there could be a potential data lost in
    ext4_writepages:
    If there are many preallocated blocks for some files, e4b bitmap is
    different from block bitmap, and there are more free blocks accounted
    by block bitmap.
    
        ext4_writepages                         P2
    ext4_mb_new_blocks                  ext4_map_blocks
     ext4_mb_regular_allocator // No free bits in e4b bitmap
     ext4_mb_discard_preallocations_should_retry
      ext4_mb_discard_preallocations
       ext4_mb_discard_group_preallocations
        ext4_mb_release_inode_pa // updates e4b bitmap by pa->pa_free
         mb_free_blocks
                                         ext4_mb_new_blocks
                                          ext4_mb_regular_allocator
                                          // Got e4b bitmap's free bits
     ext4_mb_regular_allocator  // After 3 times retrying, ret ENOSPC
    
    ext4_writepages
     mpage_map_and_submit_extent
      mpage_map_one_extent // ret ENOSPC
      if (err == -ENOSPC && EXT4_SB(sb)->s_mb_free_pending)
      // s_mb_free_pending is 0
      *give_up_on_write = true  // Abandon writeback, data lost!
    
    Fixes: 07a8109d ("ext4: Stop trying writing pages if no free ...")
    Signed-off-by: NZhihao Cheng <chengzhihao1@huawei.com>
    (cherry picked from commit 5f142164)
    1dd1a93d
ext4.h 129.2 KB