Skip to content

Commit 1a0afa0

Browse files
josefbacikkdave
authored andcommitted
btrfs: free the reloc_control in a consistent way
If we have an error while processing the reloc roots we could leak roots that were added to rc->reloc_roots before we hit the error. We could have also not removed the reloc tree mapping from our rb_tree, so clean up any remaining nodes in the reloc root rb_tree. Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> [ use rbtree_postorder_for_each_entry_safe ] Signed-off-by: David Sterba <[email protected]>
1 parent 2abc726 commit 1a0afa0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

fs/btrfs/relocation.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4202,6 +4202,18 @@ static struct reloc_control *alloc_reloc_control(struct btrfs_fs_info *fs_info)
42024202
return rc;
42034203
}
42044204

4205+
static void free_reloc_control(struct reloc_control *rc)
4206+
{
4207+
struct mapping_node *node, *tmp;
4208+
4209+
free_reloc_roots(&rc->reloc_roots);
4210+
rbtree_postorder_for_each_entry_safe(node, tmp,
4211+
&rc->reloc_root_tree.rb_root, rb_node)
4212+
kfree(node);
4213+
4214+
kfree(rc);
4215+
}
4216+
42054217
/*
42064218
* Print the block group being relocated
42074219
*/
@@ -4346,7 +4358,7 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start)
43464358
btrfs_dec_block_group_ro(rc->block_group);
43474359
iput(rc->data_inode);
43484360
btrfs_put_block_group(rc->block_group);
4349-
kfree(rc);
4361+
free_reloc_control(rc);
43504362
return err;
43514363
}
43524364

@@ -4522,7 +4534,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
45224534
err = ret;
45234535
out_unset:
45244536
unset_reloc_control(rc);
4525-
kfree(rc);
4537+
free_reloc_control(rc);
45264538
out:
45274539
if (!list_empty(&reloc_roots))
45284540
free_reloc_roots(&reloc_roots);

0 commit comments

Comments
 (0)