• Liu Bo's avatar
    Btrfs: fix race of using total_bytes_pinned · d288db5d
    Liu Bo authored
    This percpu counter @total_bytes_pinned is introduced to skip unnecessary
    operations of 'commit transaction', it accounts for those space we may free
    but are stuck in delayed refs.
    
    And we zero out @space_info->total_bytes_pinned every transaction period so
    we have a better idea of how much space we'll actually free up by committing
    this transaction.  However, we do the 'zero out' part a little earlier, before
    we actually unpin space, so we end up returning ENOSPC when we actually have
    free space that's just unpinned from committing transaction.
    
    xfstests/generic/074 complained then.
    
    This fixes it by actually accounting the percpu pinned number when 'unpin',
    and since it's protected by space_info->lock, the race is gone now.
    Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
    Reviewed-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
    Signed-off-by: default avatarChris Mason <clm@fb.com>
    d288db5d
extent-tree.c 248 KB