From: Josef Bacik Date: Wed, 20 Nov 2019 15:47:14 +0000 (-0800) Subject: btrfs: hold a ref on fs roots while they're in the radix tree X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d17bf0b583a70f6bf9ffa58696a992681b702c3;p=linux btrfs: hold a ref on fs roots while they're in the radix tree If we're sitting in the radix tree, we should probably have a ref for the radix tree. Grab a ref on the root when we insert it, and drop it when it gets deleted. Signed-off-by: Josef Bacik --- diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 4c55db4b3147..dfeeabfc341b 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1515,8 +1515,10 @@ int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info, ret = radix_tree_insert(&fs_info->fs_roots_radix, (unsigned long)root->root_key.objectid, root); - if (ret == 0) + if (ret == 0) { + btrfs_grab_fs_root(root); set_bit(BTRFS_ROOT_IN_RADIX, &root->state); + } spin_unlock(&fs_info->fs_roots_radix_lock); radix_tree_preload_end(); @@ -3816,6 +3818,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, spin_lock(&fs_info->fs_roots_radix_lock); radix_tree_delete(&fs_info->fs_roots_radix, (unsigned long)root->root_key.objectid); + if (test_and_clear_bit(BTRFS_ROOT_IN_RADIX, &root->state)) + btrfs_put_fs_root(root); spin_unlock(&fs_info->fs_roots_radix_lock); if (btrfs_root_refs(&root->root_item) == 0)