mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
btrfs: do not panic in __add_reloc_root
If we have a duplicate entry for a reloc root then we could have fs corruption that resulted in a double allocation. Since this shouldn't happen unless there is corruption, add an ASSERT(ret != -EEXIST) to all of the callers of __add_reloc_root() to catch any logic mistakes for developers, otherwise normal error handling will happen for normal users. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
3c9258632c
commit
57a304cfd4
|
|
@ -638,9 +638,10 @@ static int __must_check __add_reloc_root(struct btrfs_root *root)
|
||||||
node->bytenr, &node->rb_node);
|
node->bytenr, &node->rb_node);
|
||||||
spin_unlock(&rc->reloc_root_tree.lock);
|
spin_unlock(&rc->reloc_root_tree.lock);
|
||||||
if (rb_node) {
|
if (rb_node) {
|
||||||
btrfs_panic(fs_info, -EEXIST,
|
btrfs_err(fs_info,
|
||||||
"Duplicate root found for start=%llu while inserting into relocation tree",
|
"Duplicate root found for start=%llu while inserting into relocation tree",
|
||||||
node->bytenr);
|
node->bytenr);
|
||||||
|
return -EEXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
list_add_tail(&root->root_list, &rc->reloc_roots);
|
list_add_tail(&root->root_list, &rc->reloc_roots);
|
||||||
|
|
@ -882,6 +883,7 @@ int btrfs_init_reloc_root(struct btrfs_trans_handle *trans,
|
||||||
return PTR_ERR(reloc_root);
|
return PTR_ERR(reloc_root);
|
||||||
|
|
||||||
ret = __add_reloc_root(reloc_root);
|
ret = __add_reloc_root(reloc_root);
|
||||||
|
ASSERT(ret != -EEXIST);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
/* Pairs with create_reloc_root */
|
/* Pairs with create_reloc_root */
|
||||||
btrfs_put_root(reloc_root);
|
btrfs_put_root(reloc_root);
|
||||||
|
|
@ -4059,6 +4061,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = __add_reloc_root(reloc_root);
|
err = __add_reloc_root(reloc_root);
|
||||||
|
ASSERT(err != -EEXIST);
|
||||||
if (err) {
|
if (err) {
|
||||||
list_add_tail(&reloc_root->root_list, &reloc_roots);
|
list_add_tail(&reloc_root->root_list, &reloc_roots);
|
||||||
btrfs_put_root(fs_root);
|
btrfs_put_root(fs_root);
|
||||||
|
|
@ -4279,6 +4282,7 @@ int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
|
||||||
return PTR_ERR(reloc_root);
|
return PTR_ERR(reloc_root);
|
||||||
|
|
||||||
ret = __add_reloc_root(reloc_root);
|
ret = __add_reloc_root(reloc_root);
|
||||||
|
ASSERT(ret != -EEXIST);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
/* Pairs with create_reloc_root */
|
/* Pairs with create_reloc_root */
|
||||||
btrfs_put_root(reloc_root);
|
btrfs_put_root(reloc_root);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user