]> git.hungrycats.org Git - linux/commitdiff
btrfs: hold a ref for the root in btrfs_find_orphan_roots
authorJosef Bacik <josef@toxicpanda.com>
Wed, 20 Nov 2019 20:05:37 +0000 (12:05 -0800)
committerJosef Bacik <josef@toxicpanda.com>
Fri, 6 Dec 2019 16:34:48 +0000 (08:34 -0800)
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 <josef@toxicpanda.com>
fs/btrfs/root-tree.c

index 9617dcedf521b9420faf399d33aface6972492ea..cac2407cc00323b2974538dceddc7ec27e26b786 100644 (file)
@@ -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) {
@@ -288,6 +290,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);