Commit 1a0afa0e authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

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: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
[ use rbtree_postorder_for_each_entry_safe ]
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 2abc726a
...@@ -4202,6 +4202,18 @@ static struct reloc_control *alloc_reloc_control(struct btrfs_fs_info *fs_info) ...@@ -4202,6 +4202,18 @@ static struct reloc_control *alloc_reloc_control(struct btrfs_fs_info *fs_info)
return rc; return rc;
} }
static void free_reloc_control(struct reloc_control *rc)
{
struct mapping_node *node, *tmp;
free_reloc_roots(&rc->reloc_roots);
rbtree_postorder_for_each_entry_safe(node, tmp,
&rc->reloc_root_tree.rb_root, rb_node)
kfree(node);
kfree(rc);
}
/* /*
* Print the block group being relocated * Print the block group being relocated
*/ */
...@@ -4346,7 +4358,7 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start) ...@@ -4346,7 +4358,7 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start)
btrfs_dec_block_group_ro(rc->block_group); btrfs_dec_block_group_ro(rc->block_group);
iput(rc->data_inode); iput(rc->data_inode);
btrfs_put_block_group(rc->block_group); btrfs_put_block_group(rc->block_group);
kfree(rc); free_reloc_control(rc);
return err; return err;
} }
...@@ -4522,7 +4534,7 @@ int btrfs_recover_relocation(struct btrfs_root *root) ...@@ -4522,7 +4534,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
err = ret; err = ret;
out_unset: out_unset:
unset_reloc_control(rc); unset_reloc_control(rc);
kfree(rc); free_reloc_control(rc);
out: out:
if (!list_empty(&reloc_roots)) if (!list_empty(&reloc_roots))
free_reloc_roots(&reloc_roots); free_reloc_roots(&reloc_roots);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment