Skip to content

Commit dc9492c

Browse files
josefbacikkdave
authored andcommitted
btrfs: hold a ref on the root on the dead roots list
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 <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 5c8fd99 commit dc9492c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

fs/btrfs/disk-io.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,8 +2035,7 @@ void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info)
20352035

20362036
if (test_bit(BTRFS_ROOT_IN_RADIX, &gang[0]->state))
20372037
btrfs_drop_and_free_fs_root(fs_info, gang[0]);
2038-
else
2039-
btrfs_put_root(gang[0]);
2038+
btrfs_put_root(gang[0]);
20402039
}
20412040

20422041
while (1) {

fs/btrfs/transaction.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,10 @@ void btrfs_add_dead_root(struct btrfs_root *root)
12641264
struct btrfs_fs_info *fs_info = root->fs_info;
12651265

12661266
spin_lock(&fs_info->trans_lock);
1267-
if (list_empty(&root->root_list))
1267+
if (list_empty(&root->root_list)) {
1268+
btrfs_grab_root(root);
12681269
list_add_tail(&root->root_list, &fs_info->dead_roots);
1270+
}
12691271
spin_unlock(&fs_info->trans_lock);
12701272
}
12711273

@@ -2435,6 +2437,7 @@ int btrfs_clean_one_deleted_snapshot(struct btrfs_root *root)
24352437
else
24362438
ret = btrfs_drop_snapshot(root, 1, 0);
24372439

2440+
btrfs_put_root(root);
24382441
return (ret < 0) ? 0 : 1;
24392442
}
24402443

0 commit comments

Comments
 (0)