diff options
| author | Filipe Manana <fdmanana@suse.com> | 2015-05-18 14:11:40 -0400 |
|---|---|---|
| committer | Chris Mason <clm@fb.com> | 2015-05-19 21:04:17 -0400 |
| commit | a96295965b600f2dc6ad661c4803c86e87db3d7b (patch) | |
| tree | 77d962c73ba063add20fcc8b47950be4c1ee75a2 /fs/btrfs | |
| parent | 2c2ed5aa0154c0be67f98c970de6b5587dbc045a (diff) | |
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: stable@vger.kernel.org # 4.0+
Fixes: 2f0810880f08 ("btrfs: delete chunk allocation attemp when
setting block group ro")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs')
| -rw-r--r-- | fs/btrfs/extent-tree.c | 2 | ||||
| -rw-r--r-- | fs/btrfs/volumes.c | 1 |
2 files changed, 3 insertions, 0 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 7effed6f2fa6..45e3f086790b 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
| @@ -8842,7 +8842,9 @@ again: | |||
| 8842 | out: | 8842 | out: |
| 8843 | if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) { | 8843 | if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) { |
| 8844 | alloc_flags = update_block_group_flags(root, cache->flags); | 8844 | alloc_flags = update_block_group_flags(root, cache->flags); |
| 8845 | lock_chunks(root->fs_info->chunk_root); | ||
| 8845 | check_system_chunk(trans, root, alloc_flags); | 8846 | check_system_chunk(trans, root, alloc_flags); |
| 8847 | unlock_chunks(root->fs_info->chunk_root); | ||
| 8846 | } | 8848 | } |
| 8847 | mutex_unlock(&root->fs_info->ro_block_group_mutex); | 8849 | mutex_unlock(&root->fs_info->ro_block_group_mutex); |
| 8848 | 8850 | ||
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 96aebf3bcd5b..174f5e1e00ab 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
| @@ -4625,6 +4625,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, | |||
| 4625 | { | 4625 | { |
| 4626 | u64 chunk_offset; | 4626 | u64 chunk_offset; |
| 4627 | 4627 | ||
| 4628 | ASSERT(mutex_is_locked(&extent_root->fs_info->chunk_mutex)); | ||
| 4628 | chunk_offset = find_next_chunk(extent_root->fs_info); | 4629 | chunk_offset = find_next_chunk(extent_root->fs_info); |
| 4629 | return __btrfs_alloc_chunk(trans, extent_root, chunk_offset, type); | 4630 | return __btrfs_alloc_chunk(trans, extent_root, chunk_offset, type); |
| 4630 | } | 4631 | } |
