From: Josef Bacik Date: Wed, 20 Nov 2019 19:57:47 +0000 (-0800) Subject: btrfs: hold a ref on the root in btrfs_recover_relocation X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=265d9d69a93cd9591c62ec96d3b531cd4deae46f;p=linux btrfs: hold a ref on the root in btrfs_recover_relocation We look up the fs root in various places in here when recovering from a crashed relcoation. Make sure we hold a ref on the root whenever we look them up. Signed-off-by: Josef Bacik --- diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 4e455703439b..d40d145588f3 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4542,6 +4542,10 @@ int btrfs_recover_relocation(struct btrfs_root *root) if (btrfs_root_refs(&reloc_root->root_item) > 0) { fs_root = read_fs_root(fs_info, reloc_root->root_key.offset); + if (!btrfs_grab_fs_root(fs_root)) { + err = -ENOENT; + goto out; + } if (IS_ERR(fs_root)) { ret = PTR_ERR(fs_root); if (ret != -ENOENT) { @@ -4553,6 +4557,8 @@ int btrfs_recover_relocation(struct btrfs_root *root) err = ret; goto out; } + } else { + btrfs_put_fs_root(fs_root); } } @@ -4602,10 +4608,15 @@ int btrfs_recover_relocation(struct btrfs_root *root) list_add_tail(&reloc_root->root_list, &reloc_roots); goto out_free; } + if (!btrfs_grab_fs_root(fs_root)) { + err = -ENOENT; + goto out_free; + } err = __add_reloc_root(reloc_root); BUG_ON(err < 0); /* -ENOMEM or logic error */ fs_root->reloc_root = reloc_root; + btrfs_put_fs_root(fs_root); } err = btrfs_commit_transaction(trans); @@ -4637,10 +4648,14 @@ out: if (err == 0) { /* cleanup orphan inode in data relocation tree */ fs_root = read_fs_root(fs_info, BTRFS_DATA_RELOC_TREE_OBJECTID); - if (IS_ERR(fs_root)) + if (IS_ERR(fs_root)) { err = PTR_ERR(fs_root); - else - err = btrfs_orphan_cleanup(fs_root); + } else { + if (btrfs_grab_fs_root(fs_root)) { + err = btrfs_orphan_cleanup(fs_root); + btrfs_put_fs_root(fs_root); + } + } } return err; }