btrfs-progs: mkfs: check for minimal needed number of zones

In order to create a usable zoned filesystem a minimum of 5 zones is
needed:

- 2 zones for the 1st superblock
- 1 zone for the system block group
- 1 zone for a metadata block group
- 1 zone for a data block group

Some tests in fstests create a sized filesystem and depending on the zone
size of the underlying device, it may happen, that this filesystem is too
small to be used. It's better to not create a filesystem at all than to
create an unusable filesystem.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Johannes Thumshirn 2021-05-12 16:53:05 +09:00 committed by David Sterba
parent 79bc8135c0
commit e1d9e1e1a3
1 changed files with 14 additions and 0 deletions

View File

@ -1283,6 +1283,20 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
min_dev_size);
goto error;
}
/*
* 2 zones for the primary superblock
* 1 zone for the system block group
* 1 zone for a metadata block group
* 1 zone for a data block group
*/
if (zoned && block_count && block_count < 5 * zone_size(file)) {
error("size %llu is too small to make a usable filesystem",
block_count);
error("minimum size for a zoned btrfs filesystem is %llu",
min_dev_size);
goto error;
}
for (i = saved_optind; i < saved_optind + dev_cnt; i++) {
char *path;