diff options
author | Qu Wenruo <wqu@suse.com> | 2018-01-10 12:56:47 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2018-01-31 15:14:02 +0100 |
commit | 997f9977c24397eb6980bb91e7f9cbc6fe21815a (patch) | |
tree | e0b43642f7505f5316e0079ab98bec71b489ea6d /mkfs/main.c | |
parent | de802a47e0d7474bd446c5eb6974a33dacca5100 (diff) |
btrfs-progs: mkfs: Prevent temporary system chunk to use space in reserved 1M range
When creating btrfs, mkfs.btrfs will firstly create a temporary system
chunk as basis, and then created needed trees or new devices.
However the layout temporary system chunk is hard-coded and uses
reserved [0, 1M) range of devid 1.
Change the temporary chunk layout from old:
0 1M 4M 5M
|<----------- temp chunk -------------->|
And it's 1:1 mapped, which means it's a SINGLE chunk,
and stripe offset is also 0.
to new layout:
0 1M 4M 5M
|<----------- temp chunk -------------->|
And still keeps the 1:1 mapping.
However this also affects btrfs_min_dev_size() which still assume
temporary chunks starts at device offset 0.
The problem can only be exposed by "-m single" or "-M" where we reuse the
temporary chunk.
With other meta profiles, system and meta chunks are allocated by later
btrfs_alloc_chunk() call, and old SINGLE chunks are removed, so it will
be no such problem for other meta profiles.
Reported-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Tested-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
[ folded fix for the minimal device size calculation ]
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'mkfs/main.c')
-rw-r--r-- | mkfs/main.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/mkfs/main.c b/mkfs/main.c index 1a3852e4..9bb1f602 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -66,10 +66,15 @@ static int create_metadata_block_groups(struct btrfs_root *root, int mixed, bytes_used = btrfs_super_bytes_used(fs_info->super_copy); root->fs_info->system_allocs = 1; + /* + * First temporary system chunk must match the chunk layout + * created in make_btrfs(). + */ ret = btrfs_make_block_group(trans, fs_info, bytes_used, BTRFS_BLOCK_GROUP_SYSTEM, BTRFS_FIRST_CHUNK_TREE_OBJECTID, - 0, BTRFS_MKFS_SYSTEM_GROUP_SIZE); + BTRFS_BLOCK_RESERVED_1M_FOR_SUPER, + BTRFS_MKFS_SYSTEM_GROUP_SIZE); allocation->system += BTRFS_MKFS_SYSTEM_GROUP_SIZE; if (ret) return ret; |