• Z
    jbd2: recheck chechpointing non-dirty buffer · 4d00544e
    Zhang Yi 提交于
    maillist inclusion
    category: bugfix
    bugzilla: https://gitee.com/openeuler/kernel/issues/I70WHL
    
    Reference: https://lore.kernel.org/linux-ext4/20230531115100.2779605-1-yi.zhang@huaweicloud.com/T/#t
    
    ---------------------------------------------------------------
    
    There is a long-standing metadata corruption issue that happens from
    time to time, but it's very difficult to reproduce and analyse, benefit
    from the JBD2_CYCLE_RECORD option, we found out that the problem is the
    checkpointing process miss to write out some buffers which are raced by
    another do_get_write_access(). Looks below for detail.
    
    jbd2_log_do_checkpoint() //transaction X
     //buffer A is dirty and not belones to any transaction
     __buffer_relink_io() //move it to the IO list
     __flush_batch()
      write_dirty_buffer()
                                 do_get_write_access()
                                 clear_buffer_dirty
                                 __jbd2_journal_file_buffer()
                                 //add buffer A to a new transaction Y
       lock_buffer(bh)
       //doesn't write out
     __jbd2_journal_remove_checkpoint()
     //finish checkpoint except buffer A
     //filesystem corrupt if the new transaction Y isn't fully write out.
    
    Due to the t_checkpoint_list walking loop in jbd2_log_do_checkpoint()
    have already handles waiting for buffers under IO and re-added new
    transaction to complete commit, and it also removing cleaned buffers,
    this makes sure the list will eventually get empty. So it's fine to
    leave buffers on the t_checkpoint_list while flushing out and completely
    stop using the t_checkpoint_io_list.
    
    Cc: stable@vger.kernel.org
    Suggested-by: NJan Kara <jack@suse.cz>
    Signed-off-by: NZhang Yi <yi.zhang@huawei.com>
    Tested-by: NZhihao Cheng <chengzhihao1@huawei.com>
    Reviewed-by: NJan Kara <jack@suse.cz>
    Signed-off-by: NZhihao Cheng <chengzhihao1@huawei.com>
    (cherry picked from commit caa8415e)
    4d00544e
checkpoint.c 22.2 KB