mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-23 15:35:18 +00:00
btrfs-progs: mkfs: unify zoned mode minimum size calc into btrfs_min_dev_size()
We are going to implement a better minimum size calculation for the zoned mode. Move the current logic to btrfs_min_dev_size() and unify the size checking path. Also, convert "int mixed" to "bool mixed" while at it. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
5ff2e9c069
commit
2190d77a1c
@ -811,13 +811,22 @@ static u64 btrfs_min_global_blk_rsv_size(u32 nodesize)
|
|||||||
return (u64)nodesize << 10;
|
return (u64)nodesize << 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 btrfs_min_dev_size(u32 nodesize, int mixed, u64 meta_profile,
|
u64 btrfs_min_dev_size(u32 nodesize, bool mixed, u64 zone_size, u64 meta_profile,
|
||||||
u64 data_profile)
|
u64 data_profile)
|
||||||
{
|
{
|
||||||
u64 reserved = 0;
|
u64 reserved = 0;
|
||||||
u64 meta_size;
|
u64 meta_size;
|
||||||
u64 data_size;
|
u64 data_size;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 (mixed)
|
if (mixed)
|
||||||
return 2 * (BTRFS_MKFS_SYSTEM_GROUP_SIZE +
|
return 2 * (BTRFS_MKFS_SYSTEM_GROUP_SIZE +
|
||||||
btrfs_min_global_blk_rsv_size(nodesize));
|
btrfs_min_global_blk_rsv_size(nodesize));
|
||||||
|
@ -105,7 +105,7 @@ struct btrfs_mkfs_config {
|
|||||||
int make_btrfs(int fd, struct btrfs_mkfs_config *cfg);
|
int make_btrfs(int fd, struct btrfs_mkfs_config *cfg);
|
||||||
int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
|
int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_root *root, u64 objectid);
|
struct btrfs_root *root, u64 objectid);
|
||||||
u64 btrfs_min_dev_size(u32 nodesize, int mixed, u64 meta_profile,
|
u64 btrfs_min_dev_size(u32 nodesize, bool mixed, u64 zone_size, u64 meta_profile,
|
||||||
u64 data_profile);
|
u64 data_profile);
|
||||||
int test_minimum_size(const char *file, u64 min_dev_size);
|
int test_minimum_size(const char *file, u64 min_dev_size);
|
||||||
int is_vol_small(const char *file);
|
int is_vol_small(const char *file);
|
||||||
|
21
mkfs/main.c
21
mkfs/main.c
@ -1588,8 +1588,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
min_dev_size = btrfs_min_dev_size(nodesize, mixed, metadata_profile,
|
min_dev_size = btrfs_min_dev_size(nodesize, mixed,
|
||||||
data_profile);
|
opt_zoned ? zone_size(file) : 0,
|
||||||
|
metadata_profile, data_profile);
|
||||||
/*
|
/*
|
||||||
* Enlarge the destination file or create a new one, using the size
|
* Enlarge the destination file or create a new one, using the size
|
||||||
* calculated from source dir.
|
* calculated from source dir.
|
||||||
@ -1649,20 +1650,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
|
|||||||
/* Check device/byte_count after the nodesize is determined */
|
/* Check device/byte_count after the nodesize is determined */
|
||||||
if (byte_count && byte_count < min_dev_size) {
|
if (byte_count && byte_count < min_dev_size) {
|
||||||
error("size %llu is too small to make a usable filesystem", byte_count);
|
error("size %llu is too small to make a usable filesystem", byte_count);
|
||||||
error("minimum size for btrfs filesystem is %llu",
|
error("minimum size for a %sbtrfs filesystem is %llu",
|
||||||
min_dev_size);
|
opt_zoned ? "zoned mode " : "", 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 (opt_zoned && byte_count && byte_count < 5 * zone_size(file)) {
|
|
||||||
error("size %llu is too small to make a usable filesystem", byte_count);
|
|
||||||
error("minimum size for a zoned btrfs filesystem is %llu",
|
|
||||||
min_dev_size);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user