Skip to content

Commit 4930338

Browse files
Liu Bokdave
authored andcommitted
Btrfs: bail out if block group has different mixed flag
Currently we allow inconsistence about mixed flag (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA). We'd get ENOSPC if block group has mixed flag and btrfs doesn't. If that happens, we have one space_info with mixed flag and another space_info only with BTRFS_BLOCK_GROUP_METADATA, and global_block_rsv.space_info points to the latter one, but all bytes from block_group contributes to the mixed space_info, thus all the allocation will fail with ENOSPC. This adds a check for the above case. Reported-by: Vegard Nossum <[email protected]> Signed-off-by: Liu Bo <[email protected]> [ updated message ] Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2571e73 commit 4930338

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fs/btrfs/extent-tree.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10129,6 +10129,11 @@ int btrfs_read_block_groups(struct btrfs_root *root)
1012910129
struct extent_buffer *leaf;
1013010130
int need_clear = 0;
1013110131
u64 cache_gen;
10132+
u64 feature;
10133+
int mixed;
10134+
10135+
feature = btrfs_super_incompat_flags(info->super_copy);
10136+
mixed = !!(feature & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS);
1013210137

1013310138
root = info->extent_root;
1013410139
key.objectid = 0;
@@ -10182,6 +10187,15 @@ int btrfs_read_block_groups(struct btrfs_root *root)
1018210187
btrfs_item_ptr_offset(leaf, path->slots[0]),
1018310188
sizeof(cache->item));
1018410189
cache->flags = btrfs_block_group_flags(&cache->item);
10190+
if (!mixed &&
10191+
((cache->flags & BTRFS_BLOCK_GROUP_METADATA) &&
10192+
(cache->flags & BTRFS_BLOCK_GROUP_DATA))) {
10193+
btrfs_err(info,
10194+
"bg %llu is a mixed block group but filesystem hasn't enabled mixed block groups",
10195+
cache->key.objectid);
10196+
ret = -EINVAL;
10197+
goto error;
10198+
}
1018510199

1018610200
key.objectid = found_key.objectid + found_key.offset;
1018710201
btrfs_release_path(path);

0 commit comments

Comments
 (0)