Skip to content

Commit 19c4d2f

Browse files
committed
Revert "btrfs: let btrfs_delete_unused_bgs() to clean relocated bgs"
This reverts commit 5d8eb6f. When we remove devices, we free the device structures. Delaying btfs_remove_chunk() ends up hitting a use-after-free on them. Signed-off-by: Chris Mason <clm@fb.com>
1 parent 196e024 commit 19c4d2f

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

fs/btrfs/extent-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10849,7 +10849,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
1084910849
spin_lock(&block_group->lock);
1085010850
if (block_group->reserved ||
1085110851
btrfs_block_group_used(&block_group->item) ||
10852-
(block_group->ro && !block_group->removed) ||
10852+
block_group->ro ||
1085310853
list_is_singular(&block_group->list)) {
1085410854
/*
1085510855
* We want to bail if we made new allocations or have

fs/btrfs/volumes.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,8 +2906,8 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
29062906
static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset)
29072907
{
29082908
struct btrfs_root *extent_root;
2909+
struct btrfs_trans_handle *trans;
29092910
int ret;
2910-
struct btrfs_block_group_cache *block_group;
29112911

29122912
root = root->fs_info->chunk_root;
29132913
extent_root = root->fs_info->extent_root;
@@ -2937,17 +2937,21 @@ static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset)
29372937
if (ret)
29382938
return ret;
29392939

2940+
trans = btrfs_start_trans_remove_block_group(root->fs_info,
2941+
chunk_offset);
2942+
if (IS_ERR(trans)) {
2943+
ret = PTR_ERR(trans);
2944+
btrfs_handle_fs_error(root->fs_info, ret, NULL);
2945+
return ret;
2946+
}
2947+
29402948
/*
2941-
* step two, flag the chunk as removed and let
2942-
* btrfs_delete_unused_bgs() remove it.
2949+
* step two, delete the device extents and the
2950+
* chunk tree entries
29432951
*/
2944-
block_group = btrfs_lookup_block_group(root->fs_info, chunk_offset);
2945-
spin_lock(&block_group->lock);
2946-
block_group->removed = 1;
2947-
spin_unlock(&block_group->lock);
2948-
btrfs_put_block_group(block_group);
2949-
2950-
return 0;
2952+
ret = btrfs_remove_chunk(trans, root, chunk_offset);
2953+
btrfs_end_transaction(trans, extent_root);
2954+
return ret;
29512955
}
29522956

29532957
static int btrfs_relocate_sys_chunks(struct btrfs_root *root)

0 commit comments

Comments
 (0)