Skip to content

Commit 51184ae

Browse files
committed
Merge tag 'for-5.7-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - regression fixes: - transaction leak when deleting unused block group - log cleanup after transaction abort - fix block group leak when removing fails - transaction leak if relocation recovery fails - fix SPDX header * tag 'for-5.7-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: fix transaction leak in btrfs_recover_relocation btrfs: fix block group leak when removing fails btrfs: drop logs when we've aborted a transaction btrfs: fix memory leak of transaction when deleting unused block group btrfs: discard: Use the correct style for SPDX License Identifier
2 parents 869997b + 1402d17 commit 51184ae

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

fs/btrfs/block-group.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
916916
path = btrfs_alloc_path();
917917
if (!path) {
918918
ret = -ENOMEM;
919-
goto out;
919+
goto out_put_group;
920920
}
921921

922922
/*
@@ -954,7 +954,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
954954
ret = btrfs_orphan_add(trans, BTRFS_I(inode));
955955
if (ret) {
956956
btrfs_add_delayed_iput(inode);
957-
goto out;
957+
goto out_put_group;
958958
}
959959
clear_nlink(inode);
960960
/* One for the block groups ref */
@@ -977,13 +977,13 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
977977

978978
ret = btrfs_search_slot(trans, tree_root, &key, path, -1, 1);
979979
if (ret < 0)
980-
goto out;
980+
goto out_put_group;
981981
if (ret > 0)
982982
btrfs_release_path(path);
983983
if (ret == 0) {
984984
ret = btrfs_del_item(trans, tree_root, path);
985985
if (ret)
986-
goto out;
986+
goto out_put_group;
987987
btrfs_release_path(path);
988988
}
989989

@@ -1102,9 +1102,9 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
11021102

11031103
ret = remove_block_group_free_space(trans, block_group);
11041104
if (ret)
1105-
goto out;
1105+
goto out_put_group;
11061106

1107-
btrfs_put_block_group(block_group);
1107+
/* Once for the block groups rbtree */
11081108
btrfs_put_block_group(block_group);
11091109

11101110
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
@@ -1127,6 +1127,10 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
11271127
/* once for the tree */
11281128
free_extent_map(em);
11291129
}
1130+
1131+
out_put_group:
1132+
/* Once for the lookup reference */
1133+
btrfs_put_block_group(block_group);
11301134
out:
11311135
if (remove_rsv)
11321136
btrfs_delayed_refs_rsv_release(fs_info, 1);
@@ -1288,11 +1292,15 @@ static bool clean_pinned_extents(struct btrfs_trans_handle *trans,
12881292
if (ret)
12891293
goto err;
12901294
mutex_unlock(&fs_info->unused_bg_unpin_mutex);
1295+
if (prev_trans)
1296+
btrfs_put_transaction(prev_trans);
12911297

12921298
return true;
12931299

12941300
err:
12951301
mutex_unlock(&fs_info->unused_bg_unpin_mutex);
1302+
if (prev_trans)
1303+
btrfs_put_transaction(prev_trans);
12961304
btrfs_dec_block_group_ro(bg);
12971305
return false;
12981306
}

fs/btrfs/discard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-License-Identifier: GPL-2.0
1+
/* SPDX-License-Identifier: GPL-2.0 */
22

33
#ifndef BTRFS_DISCARD_H
44
#define BTRFS_DISCARD_H

fs/btrfs/disk-io.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,9 +2036,6 @@ void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info)
20362036
for (i = 0; i < ret; i++)
20372037
btrfs_drop_and_free_fs_root(fs_info, gang[i]);
20382038
}
2039-
2040-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
2041-
btrfs_free_log_root_tree(NULL, fs_info);
20422039
}
20432040

20442041
static void btrfs_init_scrub(struct btrfs_fs_info *fs_info)
@@ -3888,7 +3885,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
38883885
spin_unlock(&fs_info->fs_roots_radix_lock);
38893886

38903887
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
3891-
btrfs_free_log(NULL, root);
3888+
ASSERT(root->log_root == NULL);
38923889
if (root->reloc_root) {
38933890
btrfs_put_root(root->reloc_root);
38943891
root->reloc_root = NULL;
@@ -4211,6 +4208,36 @@ static void btrfs_error_commit_super(struct btrfs_fs_info *fs_info)
42114208
up_write(&fs_info->cleanup_work_sem);
42124209
}
42134210

4211+
static void btrfs_drop_all_logs(struct btrfs_fs_info *fs_info)
4212+
{
4213+
struct btrfs_root *gang[8];
4214+
u64 root_objectid = 0;
4215+
int ret;
4216+
4217+
spin_lock(&fs_info->fs_roots_radix_lock);
4218+
while ((ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix,
4219+
(void **)gang, root_objectid,
4220+
ARRAY_SIZE(gang))) != 0) {
4221+
int i;
4222+
4223+
for (i = 0; i < ret; i++)
4224+
gang[i] = btrfs_grab_root(gang[i]);
4225+
spin_unlock(&fs_info->fs_roots_radix_lock);
4226+
4227+
for (i = 0; i < ret; i++) {
4228+
if (!gang[i])
4229+
continue;
4230+
root_objectid = gang[i]->root_key.objectid;
4231+
btrfs_free_log(NULL, gang[i]);
4232+
btrfs_put_root(gang[i]);
4233+
}
4234+
root_objectid++;
4235+
spin_lock(&fs_info->fs_roots_radix_lock);
4236+
}
4237+
spin_unlock(&fs_info->fs_roots_radix_lock);
4238+
btrfs_free_log_root_tree(NULL, fs_info);
4239+
}
4240+
42144241
static void btrfs_destroy_ordered_extents(struct btrfs_root *root)
42154242
{
42164243
struct btrfs_ordered_extent *ordered;
@@ -4603,6 +4630,7 @@ static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info)
46034630
btrfs_destroy_delayed_inodes(fs_info);
46044631
btrfs_assert_delayed_root_empty(fs_info);
46054632
btrfs_destroy_all_delalloc_inodes(fs_info);
4633+
btrfs_drop_all_logs(fs_info);
46064634
mutex_unlock(&fs_info->transaction_kthread_mutex);
46074635

46084636
return 0;

fs/btrfs/relocation.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4559,6 +4559,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
45594559
if (IS_ERR(fs_root)) {
45604560
err = PTR_ERR(fs_root);
45614561
list_add_tail(&reloc_root->root_list, &reloc_roots);
4562+
btrfs_end_transaction(trans);
45624563
goto out_unset;
45634564
}
45644565

0 commit comments

Comments
 (0)