btrfs-progs: mkfs: Prevent temporary system chunk to use space in reserved 1M range
authorQu Wenruo <wqu@suse.com>
Wed, 10 Jan 2018 04:56:47 +0000 (12:56 +0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 31 Jan 2018 14:14:02 +0000 (15:14 +0100)
commit997f9977c24397eb6980bb91e7f9cbc6fe21815a
treee0b43642f7505f5316e0079ab98bec71b489ea6d
parentde802a47e0d7474bd446c5eb6974a33dacca5100
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>
mkfs/common.c
mkfs/main.c