mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-17 20:05:24 +00:00
btrfs-progs: mkfs: fix minimum size calculation for zoned mode
Currently, we check if a device is larger than 5 zones to determine we can create btrfs on the device or not. Actually, we need more zones to create DUP block groups, so it fails with "ERROR: not enough free space to allocate chunk". Implement proper support for non-SINGLE profile. Also, current code does not ensure we can create tree-log BG and data relocation BG, which are essential for the real usage. Count them as requirement too. The calculation for a regular btrfs is also adjusted to use dev_stripes style. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com>
This commit is contained in:
parent
2190d77a1c
commit
48c5ef6582
@ -817,15 +817,50 @@ u64 btrfs_min_dev_size(u32 nodesize, bool mixed, u64 zone_size, u64 meta_profile
|
||||
u64 reserved = 0;
|
||||
u64 meta_size;
|
||||
u64 data_size;
|
||||
u64 dev_stripes;
|
||||
|
||||
/*
|
||||
* 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 (zone_size)
|
||||
return 5 * zone_size;
|
||||
if (zone_size) {
|
||||
/* 2 zones for the primary superblock. */
|
||||
reserved += 2 * zone_size;
|
||||
|
||||
/*
|
||||
* 1 zone each for the initial SINGLE system, SINGLE metadata,
|
||||
* and SINGLE data block group.
|
||||
*/
|
||||
reserved += 3 * zone_size;
|
||||
|
||||
/*
|
||||
* On non-SINGLE profile, we need to add real system and
|
||||
* metadata block group. And, we also need to add a space for a
|
||||
* tree-log block group.
|
||||
*
|
||||
* SINGLE profile can reuse the initial block groups and only
|
||||
* need to add a tree-log block group
|
||||
*/
|
||||
dev_stripes = ((meta_profile & BTRFS_BLOCK_GROUP_DUP) ? 2 : 1);
|
||||
if (meta_profile & BTRFS_BLOCK_GROUP_PROFILE_MASK)
|
||||
meta_size = 3 * dev_stripes * zone_size;
|
||||
else
|
||||
meta_size = dev_stripes * zone_size;
|
||||
reserved += meta_size;
|
||||
|
||||
/*
|
||||
* On non-SINGLE profile, we need to add real data block group.
|
||||
* And, we also need to add a space for a data relocation block
|
||||
* group.
|
||||
*
|
||||
* SINGLE profile can reuse the initial block groups and only
|
||||
* need to add a data relocation block group.
|
||||
*/
|
||||
dev_stripes = (data_profile & BTRFS_BLOCK_GROUP_DUP) ? 2 : 1;
|
||||
if (data_profile & BTRFS_BLOCK_GROUP_PROFILE_MASK)
|
||||
data_size = 2 * dev_stripes * zone_size;
|
||||
else
|
||||
data_size = dev_stripes * zone_size;
|
||||
reserved += data_size;
|
||||
|
||||
return reserved;
|
||||
}
|
||||
|
||||
if (mixed)
|
||||
return 2 * (BTRFS_MKFS_SYSTEM_GROUP_SIZE +
|
||||
@ -863,22 +898,18 @@ u64 btrfs_min_dev_size(u32 nodesize, bool mixed, u64 zone_size, u64 meta_profile
|
||||
*
|
||||
* And use the stripe size to calculate its physical used space.
|
||||
*/
|
||||
dev_stripes = ((meta_profile & BTRFS_BLOCK_GROUP_DUP) ? 2 : 1);
|
||||
if (meta_profile & BTRFS_BLOCK_GROUP_PROFILE_MASK)
|
||||
meta_size = SZ_8M + SZ_32M;
|
||||
meta_size = dev_stripes * (SZ_8M + SZ_32M);
|
||||
else
|
||||
meta_size = SZ_8M + SZ_8M;
|
||||
/* For DUP/metadata, 2 stripes on one disk */
|
||||
if (meta_profile & BTRFS_BLOCK_GROUP_DUP)
|
||||
meta_size *= 2;
|
||||
meta_size = dev_stripes * (SZ_8M + SZ_8M);
|
||||
reserved += meta_size;
|
||||
|
||||
dev_stripes = ((data_profile & BTRFS_BLOCK_GROUP_DUP) ? 2 : 1);
|
||||
if (data_profile & BTRFS_BLOCK_GROUP_PROFILE_MASK)
|
||||
data_size = SZ_64M;
|
||||
data_size = dev_stripes * SZ_64M;
|
||||
else
|
||||
data_size = SZ_8M;
|
||||
/* For DUP/data, 2 stripes on one disk */
|
||||
if (data_profile & BTRFS_BLOCK_GROUP_DUP)
|
||||
data_size *= 2;
|
||||
data_size = dev_stripes * SZ_8M;
|
||||
reserved += data_size;
|
||||
|
||||
return reserved;
|
||||
|
Loading…
Reference in New Issue
Block a user