• Boris Burkov's avatar
    btrfs: record simple quota deltas in delayed refs · cecbb533
    Boris Burkov authored
    At the moment that we run delayed refs, we make the final ref-count
    based decision on creating/removing extent (and metadata) items.
    Therefore, it is exactly the spot to hook up simple quotas.
    
    There are a few important subtleties to the fields we must collect to
    accurately track simple quotas, particularly when removing an extent.
    When removing a data extent, the ref could be in any tree (due to
    reflink, for example) and so we need to recover the owning root id from
    the owner ref item. When removing a metadata extent, we know the owning
    root from the owner field in the header when we create the delayed ref,
    so we can recover it from there.
    
    We must also be careful to handle reservations properly to not leaked
    reserved space. The happy path is freeing the reservation when the
    simple quota delta runs on a data extent. If that doesn't happen, due to
    refs canceling out or some error, the ref head already has the
    must_insert_reserved machinery to handle this, so we piggy back on that
    and use it to clean up the reserved data.
    Signed-off-by: default avatarBoris Burkov <boris@bur.io>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    cecbb533
delayed-ref.h 12.4 KB