Skip to content

Commit 50dbbb7

Browse files
josefbacikkdave
authored andcommitted
btrfs: restart relocate_tree_blocks properly
There are two bugs here, but fixing them independently would just result in pain if you happened to bisect between the two patches. First is how we handle the -EAGAIN from relocate_tree_block(). We don't set error, unless we happen to be the first node, which makes no sense, I have no idea what the code was trying to accomplish here. We in fact _do_ want err set here so that we know we need to restart in relocate_block_group(). Also we need finish_pending_nodes() to not actually call link_to_upper(), because we didn't actually relocate the block. And then if we do get -EAGAIN we do not want to set our backref cache last_trans to the one before ours. This would force us to update our backref cache if we didn't cross transaction ids, which would mean we'd have some nodes updated to their new_bytenr, but still able to find their old bytenr because we're searching the same commit root as the last time we went through relocate_tree_blocks. Fixing these two things keeps us from panicing when we start breaking out of relocate_tree_blocks() either for delayed ref flushing or enospc. Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 5f6b2e5 commit 50dbbb7

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

fs/btrfs/relocation.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3269,9 +3269,8 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
32693269
ret = relocate_tree_block(trans, rc, node, &block->key,
32703270
path);
32713271
if (ret < 0) {
3272-
if (ret != -EAGAIN || &block->rb_node == rb_first(blocks))
3273-
err = ret;
3274-
goto out;
3272+
err = ret;
3273+
break;
32753274
}
32763275
}
32773276
out:
@@ -4051,12 +4050,6 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
40514050
if (!RB_EMPTY_ROOT(&blocks)) {
40524051
ret = relocate_tree_blocks(trans, rc, &blocks);
40534052
if (ret < 0) {
4054-
/*
4055-
* if we fail to relocate tree blocks, force to update
4056-
* backref cache when committing transaction.
4057-
*/
4058-
rc->backref_cache.last_trans = trans->transid - 1;
4059-
40604053
if (ret != -EAGAIN) {
40614054
err = ret;
40624055
break;

0 commit comments

Comments
 (0)