Commit d29a9f629e009c9b90e5859bce581070fd6247fc

Authored by Josef Bacik
1 parent fec386ac14

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: stable@vger.kernel.org
Reported-by: Alex Lyakas <alex.btrfs@zadarastorage.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>

Showing 1 changed file with 11 additions and 0 deletions Side-by-side Diff

fs/btrfs/extent-tree.c
... ... @@ -7466,6 +7466,7 @@
7466 7466 int err = 0;
7467 7467 int ret;
7468 7468 int level;
  7469 + bool root_dropped = false;
7469 7470  
7470 7471 path = btrfs_alloc_path();
7471 7472 if (!path) {
7472 7473  
... ... @@ -7643,12 +7644,22 @@
7643 7644 free_extent_buffer(root->commit_root);
7644 7645 btrfs_put_fs_root(root);
7645 7646 }
  7647 + root_dropped = true;
7646 7648 out_end_trans:
7647 7649 btrfs_end_transaction_throttle(trans, tree_root);
7648 7650 out_free:
7649 7651 kfree(wc);
7650 7652 btrfs_free_path(path);
7651 7653 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);
7652 7663 if (err)
7653 7664 btrfs_std_error(root->fs_info, err);
7654 7665 return err;