Skip to content

Commit

Permalink
btrfs: hold a ref on the root on the dead roots list
Browse files Browse the repository at this point in the history
At the point we add a root to the dead roots list we have no open inodes
for that root, so we need to hold a ref on that root to keep it from
disappearing.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Josef Bacik authored and David Sterba committed Mar 23, 2020
1 parent 5c8fd99 commit dc9492c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 1 addition & 2 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2035,8 +2035,7 @@ void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info)

if (test_bit(BTRFS_ROOT_IN_RADIX, &gang[0]->state))
btrfs_drop_and_free_fs_root(fs_info, gang[0]);
else
btrfs_put_root(gang[0]);
btrfs_put_root(gang[0]);
}

while (1) {
Expand Down
5 changes: 4 additions & 1 deletion fs/btrfs/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,8 +1264,10 @@ void btrfs_add_dead_root(struct btrfs_root *root)
struct btrfs_fs_info *fs_info = root->fs_info;

spin_lock(&fs_info->trans_lock);
if (list_empty(&root->root_list))
if (list_empty(&root->root_list)) {
btrfs_grab_root(root);
list_add_tail(&root->root_list, &fs_info->dead_roots);
}
spin_unlock(&fs_info->trans_lock);
}

Expand Down Expand Up @@ -2435,6 +2437,7 @@ int btrfs_clean_one_deleted_snapshot(struct btrfs_root *root)
else
ret = btrfs_drop_snapshot(root, 1, 0);

btrfs_put_root(root);
return (ret < 0) ? 0 : 1;
}

Expand Down

0 comments on commit dc9492c

Please sign in to comment.