Skip to content

Commit d29a9f6

Browse files
author
Josef Bacik
committed
Btrfs: re-add root to dead root list if we stop dropping it
If we stop dropping a root for whatever reason we need to add it back to the dead root list so that we will re-start the dropping next transaction commit. The other case this happens is if we recover a drop because we will add a root without adding it to the fs radix tree, so we can leak it's root and commit root extent buffer, adding this to the dead root list makes this cleanup happen. Thanks, Cc: [email protected] Reported-by: Alex Lyakas <[email protected]> Signed-off-by: Josef Bacik <[email protected]>
1 parent fec386a commit d29a9f6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fs/btrfs/extent-tree.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7466,6 +7466,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
74667466
int err = 0;
74677467
int ret;
74687468
int level;
7469+
bool root_dropped = false;
74697470

74707471
path = btrfs_alloc_path();
74717472
if (!path) {
@@ -7643,12 +7644,22 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
76437644
free_extent_buffer(root->commit_root);
76447645
btrfs_put_fs_root(root);
76457646
}
7647+
root_dropped = true;
76467648
out_end_trans:
76477649
btrfs_end_transaction_throttle(trans, tree_root);
76487650
out_free:
76497651
kfree(wc);
76507652
btrfs_free_path(path);
76517653
out:
7654+
/*
7655+
* So if we need to stop dropping the snapshot for whatever reason we
7656+
* need to make sure to add it back to the dead root list so that we
7657+
* keep trying to do the work later. This also cleans up roots if we
7658+
* don't have it in the radix (like when we recover after a power fail
7659+
* or unmount) so we don't leak memory.
7660+
*/
7661+
if (root_dropped == false)
7662+
btrfs_add_dead_root(root);
76527663
if (err)
76537664
btrfs_std_error(root->fs_info, err);
76547665
return err;

0 commit comments

Comments
 (0)