From: Josef Bacik Date: Fri, 24 Jan 2020 14:32:46 +0000 (-0500) Subject: btrfs: hold a ref for the root in btrfs_find_orphan_roots X-Git-Tag: v5.7-rc1~157^2~169 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b2dee5cff7490b5e874d33537d4cfcf66e5ba0d;p=thirdparty%2Fkernel%2Flinux.git btrfs: hold a ref for the root in btrfs_find_orphan_roots We lookup roots for every orphan item we have, we need to hold a ref on the root while we're doing this work. Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba --- diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c index 1ea4a35a0830f..a32632f439870 100644 --- a/fs/btrfs/root-tree.c +++ b/fs/btrfs/root-tree.c @@ -257,6 +257,8 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info) root = btrfs_get_fs_root(fs_info, &root_key, false); err = PTR_ERR_OR_ZERO(root); + if (!err && !btrfs_grab_fs_root(root)) + err = -ENOENT; if (err && err != -ENOENT) { break; } else if (err == -ENOENT) { @@ -287,6 +289,7 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info) set_bit(BTRFS_ROOT_DEAD_TREE, &root->state); btrfs_add_dead_root(root); } + btrfs_put_fs_root(root); } btrfs_free_path(path);