• Qu Wenruo's avatar
    btrfs: relocation: Fix leaking qgroups numbers on data extents · 62b99540
    Qu Wenruo authored
    This patch fixes a REGRESSION introduced in 4.2, caused by the big quota
    rework.
    
    When balancing data extents, qgroup will leak all its numbers for
    relocated data extents.
    
    The relocation is done in the following steps for data extents:
    1) Create data reloc tree and inode
    2) Copy all data extents to data reloc tree
       And commit transaction
    3) Create tree reloc tree(special snapshot) for any related subvolumes
    4) Replace file extent in tree reloc tree with new extents in data reloc
       tree
       And commit transaction
    5) Merge tree reloc tree with original fs, by swapping tree blocks
    
    For 1)~4), since tree reloc tree and data reloc tree doesn't count to
    qgroup, everything is OK.
    
    But for 5), the swapping of tree blocks will only info qgroup to track
    metadata extents.
    
    If metadata extents contain file extents, qgroup number for file extents
    will get lost, leading to corrupted qgroup accounting.
    
    The fix is, before commit transaction of step 5), manually info qgroup to
    track all file extents in data reloc tree.
    Since at commit transaction time, the tree swapping is done, and qgroup
    will account these data extents correctly.
    
    Cc: Mark Fasheh <mfasheh@suse.de>
    Reported-by: default avatarMark Fasheh <mfasheh@suse.de>
    Reported-by: default avatarFilipe Manana <fdmanana@gmail.com>
    Signed-off-by: default avatarQu Wenruo <quwenruo@cn.fujitsu.com>
    Tested-by: default avatarGoldwyn Rodrigues <rgoldwyn@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarChris Mason <clm@fb.com>
    62b99540
relocation.c 113 KB