Commit 5f6b2e5c authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: reloc: reorder reservation before root selection

Since we're not only checking for metadata reservations but also if we
need to throttle our delayed ref generation, reorder
reserve_metadata_space() above the select_one_root() call in
relocate_tree_block().

The reason we want this is because select_reloc_root() will mess with
the backref cache, and if we're going to bail we want to be able to
cleanly remove this node from the backref cache and come back along to
regenerate it.  Move it up so this is the first thing we do to make
restarting cleaner.
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent d7ff00f6
...@@ -3177,6 +3177,14 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, ...@@ -3177,6 +3177,14 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans,
if (!node) if (!node)
return 0; return 0;
/*
* If we fail here we want to drop our backref_node because we are going
* to start over and regenerate the tree for it.
*/
ret = reserve_metadata_space(trans, rc, node);
if (ret)
goto out;
BUG_ON(node->processed); BUG_ON(node->processed);
root = select_one_root(node); root = select_one_root(node);
if (root == ERR_PTR(-ENOENT)) { if (root == ERR_PTR(-ENOENT)) {
...@@ -3184,12 +3192,6 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, ...@@ -3184,12 +3192,6 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans,
goto out; goto out;
} }
if (!root || test_bit(BTRFS_ROOT_REF_COWS, &root->state)) {
ret = reserve_metadata_space(trans, rc, node);
if (ret)
goto out;
}
if (root) { if (root) {
if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) { if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) {
BUG_ON(node->new_bytenr); BUG_ON(node->new_bytenr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment