• Josef Bacik's avatar
    btrfs: add helpers for manipulating leaf items and data · 637e3b48
    Josef Bacik authored
    We have some gnarly memmove and copy_extent_buffer calls for leaf
    manipulation.  This is because our item offsets aren't absolute, they're
    based on 0 being where the items start in the leaf, which is after the
    btrfs_header.  This means any manipulation of the data requires adding
    sizeof(struct btrfs_header) to the offsets we pull from the items.
    Moving the items themselves is easier as the helpers are absolute
    offsets, however we of course have to call the helpers to get the
    offsets for the item numbers.  This makes for
    copy_extent_buffer/memmove_extent_buffer calls that are kind of hard to
    reason about what's happening.
    
    Fix this by pushing this logic into helpers.  For data we'll only use
    the item provided offsets, and the helpers will use the
    BTRFS_LEAF_DATA_OFFSET addition for the offsets.  Additionally for the
    item manipulation simply pass in the item numbers, and then the helpers
    will call the offset helper to get the actual offset into the leaf.
    
    The diffstat makes this look like more code, but that's simply because I
    added comments for the helpers, it's net negative for the amount of
    code, and is easier to reason.
    Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    637e3b48
ctree.c 131 KB