Commit 889bfa39 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: drop log root for dropped roots

If we fsync on a subvolume and create a log root for that volume, and
then later delete that subvolume we'll never clean up its log root.  Fix
this by making switch_commit_roots free the log for any dropped roots we
encounter.  The extra churn is because we need a btrfs_trans_handle, not
the btrfs_transaction.

CC: stable@vger.kernel.org # 5.4+
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 668e48af
...@@ -147,13 +147,14 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction) ...@@ -147,13 +147,14 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction)
} }
} }
static noinline void switch_commit_roots(struct btrfs_transaction *trans) static noinline void switch_commit_roots(struct btrfs_trans_handle *trans)
{ {
struct btrfs_transaction *cur_trans = trans->transaction;
struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_root *root, *tmp; struct btrfs_root *root, *tmp;
down_write(&fs_info->commit_root_sem); down_write(&fs_info->commit_root_sem);
list_for_each_entry_safe(root, tmp, &trans->switch_commits, list_for_each_entry_safe(root, tmp, &cur_trans->switch_commits,
dirty_list) { dirty_list) {
list_del_init(&root->dirty_list); list_del_init(&root->dirty_list);
free_extent_buffer(root->commit_root); free_extent_buffer(root->commit_root);
...@@ -165,16 +166,17 @@ static noinline void switch_commit_roots(struct btrfs_transaction *trans) ...@@ -165,16 +166,17 @@ static noinline void switch_commit_roots(struct btrfs_transaction *trans)
} }
/* We can free old roots now. */ /* We can free old roots now. */
spin_lock(&trans->dropped_roots_lock); spin_lock(&cur_trans->dropped_roots_lock);
while (!list_empty(&trans->dropped_roots)) { while (!list_empty(&cur_trans->dropped_roots)) {
root = list_first_entry(&trans->dropped_roots, root = list_first_entry(&cur_trans->dropped_roots,
struct btrfs_root, root_list); struct btrfs_root, root_list);
list_del_init(&root->root_list); list_del_init(&root->root_list);
spin_unlock(&trans->dropped_roots_lock); spin_unlock(&cur_trans->dropped_roots_lock);
btrfs_free_log(trans, root);
btrfs_drop_and_free_fs_root(fs_info, root); btrfs_drop_and_free_fs_root(fs_info, root);
spin_lock(&trans->dropped_roots_lock); spin_lock(&cur_trans->dropped_roots_lock);
} }
spin_unlock(&trans->dropped_roots_lock); spin_unlock(&cur_trans->dropped_roots_lock);
up_write(&fs_info->commit_root_sem); up_write(&fs_info->commit_root_sem);
} }
...@@ -1421,7 +1423,7 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, ...@@ -1421,7 +1423,7 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,
ret = commit_cowonly_roots(trans); ret = commit_cowonly_roots(trans);
if (ret) if (ret)
goto out; goto out;
switch_commit_roots(trans->transaction); switch_commit_roots(trans);
ret = btrfs_write_and_wait_transaction(trans); ret = btrfs_write_and_wait_transaction(trans);
if (ret) if (ret)
btrfs_handle_fs_error(fs_info, ret, btrfs_handle_fs_error(fs_info, ret,
...@@ -2301,7 +2303,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) ...@@ -2301,7 +2303,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
list_add_tail(&fs_info->chunk_root->dirty_list, list_add_tail(&fs_info->chunk_root->dirty_list,
&cur_trans->switch_commits); &cur_trans->switch_commits);
switch_commit_roots(cur_trans); switch_commit_roots(trans);
ASSERT(list_empty(&cur_trans->dirty_bgs)); ASSERT(list_empty(&cur_trans->dirty_bgs));
ASSERT(list_empty(&cur_trans->io_bgs)); ASSERT(list_empty(&cur_trans->io_bgs));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment