• Boris Burkov's avatar
    btrfs: qgroup: track metadata relocation COW with simple quota · 60ea105a
    Boris Burkov authored
    Relocation COWs metadata blocks in two cases for the reloc root:
    
    - copying the subvolume root item when creating the reloc root
    - copying a btree node when there is a COW during relocation
    
    In both cases, the resulting btree node hits an abnormal code path with
    respect to the owner field in its btrfs_header. It first creates the
    root item for the new objectid, which populates the reloc root id, and
    it at this point that delayed refs are created.
    
    Later, it fully copies the old node into the new node (including the
    original owner field) which overwrites it. This results in a simple
    quotas mismatch where we run the delayed ref for the reloc root which
    has no simple quota effect (reloc root is not an fstree) but when we
    ultimately delete the node, the owner is the real original fstree and we
    do free the space.
    
    To work around this without tampering with the behavior of relocation,
    add a parameter to btrfs_add_tree_block that lets the relocation code
    path specify a different owning root than the "operating" root (in this
    case, owning root is the real root and the operating root is the reloc
    root). These can naturally be plumbed into delayed refs that have the
    same concept.
    
    Note that this is a double count in some sense, but a relatively natural
    one, as there are really two extents, and the old one will be deleted
    soon. This is consistent with how data relocation extents are accounted
    by simple quotas.
    Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
    Signed-off-by: default avatarBoris Burkov <boris@bur.io>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    60ea105a
ctree.c 137 KB