diff mbox series

[22/44] btrfs: hold a ref on the root in prepare_to_merge

Message ID 20200124143301.2186319-23-josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series Cleanup how we handle root refs, part 1 | expand

Commit Message

Josef Bacik Jan. 24, 2020, 2:32 p.m. UTC
We look up the reloc roots corresponding root, we need to hold a ref on
that root.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

David Sterba Feb. 5, 2020, 2:52 p.m. UTC | #1
On Fri, Jan 24, 2020 at 09:32:39AM -0500, Josef Bacik wrote:
> We look up the reloc roots corresponding root, we need to hold a ref on
> that root.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/relocation.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 990595a27a15..53df57b59bc3 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -2474,6 +2474,8 @@ int prepare_to_merge(struct reloc_control *rc, int err)
>  		list_del_init(&reloc_root->root_list);
>  
>  		root = read_fs_root(fs_info, reloc_root->root_key.offset);
> +		if (!btrfs_grab_fs_root(root))
> +			BUG();
>  		BUG_ON(IS_ERR(root));

These two should be swapped, first the root is "checked" if it's
valid, then the reference can be grabbed. The code is later pushed into
the other helper and there it's in the right order so it's only
temporary.

>  		BUG_ON(root->reloc_root != reloc_root);
>
diff mbox series

Patch

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 990595a27a15..53df57b59bc3 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2474,6 +2474,8 @@  int prepare_to_merge(struct reloc_control *rc, int err)
 		list_del_init(&reloc_root->root_list);
 
 		root = read_fs_root(fs_info, reloc_root->root_key.offset);
+		if (!btrfs_grab_fs_root(root))
+			BUG();
 		BUG_ON(IS_ERR(root));
 		BUG_ON(root->reloc_root != reloc_root);
 
@@ -2486,6 +2488,7 @@  int prepare_to_merge(struct reloc_control *rc, int err)
 		btrfs_update_reloc_root(trans, root);
 
 		list_add(&reloc_root->root_list, &reloc_roots);
+		btrfs_put_fs_root(root);
 	}
 
 	list_splice(&reloc_roots, &rc->reloc_roots);