Patchwork [20/75] Btrfs: re-add root to dead root list if we stop dropping it

mail settings
Submitter Luis Henriques
Date Aug. 14, 2013, 10:36 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/267059/
State New
Headers show


Luis Henriques - Aug. 14, 2013, 10:36 a.m. -stable review patch.  If anyone has any objections, please let me know.


From: Josef Bacik <>

commit d29a9f629e009c9b90e5859bce581070fd6247fc upstream.

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.

Reported-by: Alex Lyakas <>
Signed-off-by: Josef Bacik <>
Signed-off-by: Luis Henriques <>
 fs/btrfs/extent-tree.c | 11 +++++++++++
 1 file changed, 11 insertions(+)


diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 9b1dc7b..6bb1213 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -6848,6 +6848,7 @@  int btrfs_drop_snapshot(struct btrfs_root *root,
 	int err = 0;
 	int ret;
 	int level;
+	bool root_dropped = false;
 	path = btrfs_alloc_path();
 	if (!path) {
@@ -7018,12 +7019,22 @@  int btrfs_drop_snapshot(struct btrfs_root *root,
+	root_dropped = true;
 	btrfs_end_transaction_throttle(trans, tree_root);
+	/*
+	 * So if we need to stop dropping the snapshot for whatever reason we
+	 * need to make sure to add it back to the dead root list so that we
+	 * keep trying to do the work later.  This also cleans up roots if we
+	 * don't have it in the radix (like when we recover after a power fail
+	 * or unmount) so we don't leak memory.
+	 */
+	if (root_dropped == false)
+		btrfs_add_dead_root(root);
 	if (err)
 		btrfs_std_error(root->fs_info, err);
 	return err;