Skip to content

Commit a962959

Browse files
fdmananamasoncl
authored andcommitted
Btrfs: fix racy system chunk allocation when setting block group ro
If while setting a block group read-only we end up allocating a system chunk, through check_system_chunk(), we were not doing it while holding the chunk mutex which is a problem if a concurrent chunk allocation is happening, through do_chunk_alloc(), as it means both block groups can end up using the same logical addresses and physical regions in the device(s). So make sure we hold the chunk mutex. Cc: [email protected] # 4.0+ Fixes: 2f08108 ("btrfs: delete chunk allocation attemp when setting block group ro") Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent 2c2ed5a commit a962959

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

fs/btrfs/extent-tree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8842,7 +8842,9 @@ int btrfs_set_block_group_ro(struct btrfs_root *root,
88428842
out:
88438843
if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) {
88448844
alloc_flags = update_block_group_flags(root, cache->flags);
8845+
lock_chunks(root->fs_info->chunk_root);
88458846
check_system_chunk(trans, root, alloc_flags);
8847+
unlock_chunks(root->fs_info->chunk_root);
88468848
}
88478849
mutex_unlock(&root->fs_info->ro_block_group_mutex);
88488850

fs/btrfs/volumes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4625,6 +4625,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
46254625
{
46264626
u64 chunk_offset;
46274627

4628+
ASSERT(mutex_is_locked(&extent_root->fs_info->chunk_mutex));
46284629
chunk_offset = find_next_chunk(extent_root->fs_info);
46294630
return __btrfs_alloc_chunk(trans, extent_root, chunk_offset, type);
46304631
}

0 commit comments

Comments
 (0)