Skip to content

Commit 5f6b2e5

Browse files
josefbacikkdave
authored andcommitted
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: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d7ff00f commit 5f6b2e5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

fs/btrfs/relocation.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,19 +3177,21 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans,
31773177
if (!node)
31783178
return 0;
31793179

3180+
/*
3181+
* If we fail here we want to drop our backref_node because we are going
3182+
* to start over and regenerate the tree for it.
3183+
*/
3184+
ret = reserve_metadata_space(trans, rc, node);
3185+
if (ret)
3186+
goto out;
3187+
31803188
BUG_ON(node->processed);
31813189
root = select_one_root(node);
31823190
if (root == ERR_PTR(-ENOENT)) {
31833191
update_processed_blocks(rc, node);
31843192
goto out;
31853193
}
31863194

3187-
if (!root || test_bit(BTRFS_ROOT_REF_COWS, &root->state)) {
3188-
ret = reserve_metadata_space(trans, rc, node);
3189-
if (ret)
3190-
goto out;
3191-
}
3192-
31933195
if (root) {
31943196
if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) {
31953197
BUG_ON(node->new_bytenr);

0 commit comments

Comments
 (0)