• Y
    f2fs: fix to avoid inconsistent quota data · 9151458a
    Yi Chen 提交于
    stable inclusion
    from stable-5.10.20
    commit a9553ae64da0009553a62a07d2787728de903617
    bugzilla: 50608
    
    --------------------------------
    
    [ Upstream commit 25fb04db ]
    
    Occasionally, quota data may be corrupted detected by fsck:
    
    Info: checkpoint state = 45 :  crc compacted_summary unmount
    [QUOTA WARNING] Usage inconsistent for ID 0:actual (1543036928, 762) != expected (1543032832, 762)
    [ASSERT] (fsck_chk_quota_files:1986)  --> Quota file is missing or invalid quota file content found.
    [QUOTA WARNING] Usage inconsistent for ID 0:actual (1352478720, 344) != expected (1352474624, 344)
    [ASSERT] (fsck_chk_quota_files:1986)  --> Quota file is missing or invalid quota file content found.
    
    [FSCK] Unreachable nat entries                        [Ok..] [0x0]
    [FSCK] SIT valid block bitmap checking                [Ok..]
    [FSCK] Hard link checking for regular file            [Ok..] [0x0]
    [FSCK] valid_block_count matching with CP             [Ok..] [0xdf299]
    [FSCK] valid_node_count matcing with CP (de lookup)   [Ok..] [0x2b01]
    [FSCK] valid_node_count matcing with CP (nat lookup)  [Ok..] [0x2b01]
    [FSCK] valid_inode_count matched with CP              [Ok..] [0x2665]
    [FSCK] free segment_count matched with CP             [Ok..] [0xcb04]
    [FSCK] next block offset is free                      [Ok..]
    [FSCK] fixing SIT types
    [FSCK] other corrupted bugs                           [Fail]
    
    The root cause is:
    If we open file w/ readonly flag, disk quota info won't be initialized
    for this file, however, following mmap() will force to convert inline
    inode via f2fs_convert_inline_inode(), which may increase block usage
    for this inode w/o updating quota data, it causes inconsistent disk quota
    info.
    
    The issue will happen in following stack:
    open(file, O_RDONLY)
    mmap(file)
    - f2fs_convert_inline_inode
     - f2fs_convert_inline_page
      - f2fs_reserve_block
       - f2fs_reserve_new_block
        - f2fs_reserve_new_blocks
         - f2fs_i_blocks_write
          - dquot_claim_block
    inode->i_blocks increase, but the dqb_curspace keep the size for the dquots
    is NULL.
    
    To fix this issue, let's call dquot_initialize() anyway in both
    f2fs_truncate() and f2fs_convert_inline_inode() functions to avoid potential
    inconsistent quota data issue.
    
    Fixes: 0abd675e ("f2fs: support plain user/group quota")
    Signed-off-by: NDaiyue Zhang <zhangdaiyue1@huawei.com>
    Signed-off-by: NDehe Gu <gudehe@huawei.com>
    Signed-off-by: NJunchao Jiang <jiangjunchao1@huawei.com>
    Signed-off-by: NGe Qiu <qiuge@huawei.com>
    Signed-off-by: NYi Chen <chenyi77@huawei.com>
    Reviewed-by: NChao Yu <yuchao0@huawei.com>
    Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
    Signed-off-by: NSasha Levin <sashal@kernel.org>
    Signed-off-by: NChen Jun <chenjun102@huawei.com>
    Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
    Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
    9151458a
file.c 99.3 KB