• Filipe Manana's avatar
    btrfs: send: make ensure_commit_roots_uptodate() simpler and more efficient · 9e79c497
    Filipe Manana authored
    Before starting a send operation we have to make sure that every root has
    its commit root matching the regular root, to that send doesn't find stale
    inodes in the commit root (inodes that were deleted in the regular root)
    and fails the inode lookups with -ESTALE.
    
    Currently we keep looking for roots used by the send operation and as soon
    as we find one we commit the current transaction (or a new one since
    btrfs_join_transaction() creates one if there isn't any running or the
    running one is in a state >= TRANS_STATE_UNBLOCKED). It's pointless to
    keep looking until we don't find any, because after the first transaction
    commit all the other roots are updated too, as they were already tagged in
    the fs_info->fs_roots_radix radix tree when they were modified in order to
    have a commit root different from the regular root.
    
    Currently we are also always passing the main send root into
    btrfs_join_transaction(), which despite not having any functional issue,
    it is not optimal because in case the root wasn't modified we end up
    adding it to fs_info->fs_roots_radix and then update its root item in the
    root tree when committing the transaction, causing unnecessary work.
    
    So simplify and make this more efficient by removing the looping and by
    passing the first root we found that is modified as the argument to
    btrfs_join_transaction().
    Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
    Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    9e79c497
send.c 216 KB