Skip to content

Commit c78a10a

Browse files
josefbacikkdave
authored andcommitted
btrfs: fix reloc root leak with 0 ref reloc roots on recovery
When recovering a relocation, if we run into a reloc root that has 0 refs we simply add it to the reloc_control->reloc_roots list, and then clean it up later. The problem with this is __del_reloc_root() doesn't do anything if the root isn't in the radix tree, which in this case it won't be because we never call __add_reloc_root() on the reloc_root. This exit condition simply isn't correct really. During normal operation we can remove ourselves from the rb tree and then we're meant to clean up later at merge_reloc_roots() time, and this happens correctly. During recovery we're depending on free_reloc_roots() to drop our references, but we're short-circuiting. Fix this by continuing to check if we're on the list and dropping ourselves from the reloc_control root list and dropping our reference appropriately. Change the corresponding BUG_ON() to an ASSERT() that does the correct thing if we aren't in the rb tree. CC: [email protected] # 4.4+ Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2e626e5 commit c78a10a

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

fs/btrfs/relocation.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,7 @@ static void __del_reloc_root(struct btrfs_root *root)
669669
RB_CLEAR_NODE(&node->rb_node);
670670
}
671671
spin_unlock(&rc->reloc_root_tree.lock);
672-
if (!node)
673-
return;
674-
BUG_ON((struct btrfs_root *)node->data != root);
672+
ASSERT(!node || (struct btrfs_root *)node->data == root);
675673
}
676674

677675
/*

0 commit comments

Comments
 (0)