Commit 1a4319cc authored by Liu Bo's avatar Liu Bo Committed by Chris Mason

Btrfs: fix extent state leak on transaction abortion

When transaction is aborted, we fail to commit transaction, instead we do
cleanup work.  After that when we umount btrfs, we get to free fs roots' log
trees respectively, but that happens after we unpin extents, so those extents
pinned by freeing log trees will remain in memory and lead to the leak.
Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent 07802534
...@@ -2065,6 +2065,12 @@ static void del_fs_roots(struct btrfs_fs_info *fs_info) ...@@ -2065,6 +2065,12 @@ static void del_fs_roots(struct btrfs_fs_info *fs_info)
for (i = 0; i < ret; i++) for (i = 0; i < ret; i++)
btrfs_drop_and_free_fs_root(fs_info, gang[i]); btrfs_drop_and_free_fs_root(fs_info, gang[i]);
} }
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
btrfs_free_log_root_tree(NULL, fs_info);
btrfs_destroy_pinned_extent(fs_info->tree_root,
fs_info->pinned_extents);
}
} }
int open_ctree(struct super_block *sb, int open_ctree(struct super_block *sb,
...@@ -3455,10 +3461,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, ...@@ -3455,10 +3461,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
if (btrfs_root_refs(&root->root_item) == 0) if (btrfs_root_refs(&root->root_item) == 0)
synchronize_srcu(&fs_info->subvol_srcu); synchronize_srcu(&fs_info->subvol_srcu);
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
btrfs_free_log(NULL, root); btrfs_free_log(NULL, root);
btrfs_free_log_root_tree(NULL, fs_info);
}
__btrfs_remove_free_space_cache(root->free_ino_pinned); __btrfs_remove_free_space_cache(root->free_ino_pinned);
__btrfs_remove_free_space_cache(root->free_ino_ctl); __btrfs_remove_free_space_cache(root->free_ino_ctl);
...@@ -3569,8 +3573,6 @@ int close_ctree(struct btrfs_root *root) ...@@ -3569,8 +3573,6 @@ int close_ctree(struct btrfs_root *root)
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
btrfs_error_commit_super(root); btrfs_error_commit_super(root);
btrfs_put_block_group_cache(fs_info);
kthread_stop(fs_info->transaction_kthread); kthread_stop(fs_info->transaction_kthread);
kthread_stop(fs_info->cleaner_kthread); kthread_stop(fs_info->cleaner_kthread);
...@@ -3588,6 +3590,8 @@ int close_ctree(struct btrfs_root *root) ...@@ -3588,6 +3590,8 @@ int close_ctree(struct btrfs_root *root)
del_fs_roots(fs_info); del_fs_roots(fs_info);
btrfs_put_block_group_cache(fs_info);
btrfs_free_block_groups(fs_info); btrfs_free_block_groups(fs_info);
btrfs_stop_all_workers(fs_info); btrfs_stop_all_workers(fs_info);
......
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