btrfs: hold a ref on the root in merge_reloc_roots
authorJosef Bacik <josef@toxicpanda.com>
Fri, 24 Jan 2020 14:32:40 +0000 (09:32 -0500)
committerDavid Sterba <dsterba@suse.com>
Mon, 23 Mar 2020 16:01:29 +0000 (17:01 +0100)
We look up the corresponding root for the reloc root, we need to hold a
ref while we're messing with it.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/relocation.c

index b85850823a1b23661b5333828a8b089ae4b2b479..679dd3958ff257f3086d71fae14f219320c0f14c 100644 (file)
@@ -2592,9 +2592,11 @@ again:
                        root = read_fs_root(fs_info,
                                            reloc_root->root_key.offset);
                        BUG_ON(IS_ERR(root));
+                       BUG_ON(!btrfs_grab_fs_root(root));
                        BUG_ON(root->reloc_root != reloc_root);
 
                        ret = merge_reloc_root(rc, root);
+                       btrfs_put_fs_root(root);
                        if (ret) {
                                if (list_empty(&reloc_root->root_list))
                                        list_add_tail(&reloc_root->root_list,