• Qu Wenruo's avatar
    btrfs: qgroup: Fix wrong qgroup reservation update for relationship modification · 429d6275
    Qu Wenruo authored
    When modifying qgroup relationship, for qgroup which only owns exclusive
    extents, we will go through quick update path.
    
    In this path, we will add/subtract exclusive and reference number for
    parent qgroup, since the source (child) qgroup only has exclusive
    extents, destination (parent) qgroup will also own or lose those extents
    exclusively.
    
    The same should be the same for reservation, since later reservation
    adding/releasing will also affect parent qgroup, without the reservation
    carried from child, parent will underflow reservation or have dead
    reservation which will never be freed.
    
    However original code doesn't do the same thing for reservation.
    It handles qgroup reservation quite differently:
    
    It removes qgroup reservation, as it's allocating space from the
    reserved qgroup for relationship adding.
    But does nothing for qgroup reservation if we're removing a qgroup
    relationship.
    
    According to the original code, it looks just like because we're adding
    qgroup->rfer, the code assumes we're writing new data, so it's follows
    the normal write routine, by reducing qgroup->reserved and adding
    qgroup->rfer/excl.
    
    This old behavior is wrong, and should be fixed to follow the same
    excl/rfer behavior.
    
    Just fix it by using the correct behavior described above.
    
    Fixes: 31193213 ("Btrfs: qgroup: Introduce a may_use to account space_info->bytes_may_use.")
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    429d6275
qgroup.c 78.9 KB