btrfs-progs: mkfs: refactor test_minimum_size to use the calculated minimal size
test_minimum_size() function is only called to check if provided device is large enough. However the minimal device size only needs to be calculated once, and can be reused everywhere. Refactor that function to make later modification easier. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
da2659b090
commit
b84aa6033c
|
@ -698,7 +698,7 @@ int is_vol_small(const char *file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_minimum_size(const char *file, u32 nodesize)
|
int test_minimum_size(const char *file, u64 min_dev_size)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
@ -710,7 +710,7 @@ int test_minimum_size(const char *file, u32 nodesize)
|
||||||
close(fd);
|
close(fd);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
if (btrfs_device_size(fd, &statbuf) < btrfs_min_dev_size(nodesize)) {
|
if (btrfs_device_size(fd, &statbuf) < min_dev_size) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,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);
|
||||||
u64 btrfs_min_dev_size(u32 nodesize);
|
u64 btrfs_min_dev_size(u32 nodesize);
|
||||||
u64 btrfs_min_global_blk_rsv_size(u32 nodesize);
|
u64 btrfs_min_global_blk_rsv_size(u32 nodesize);
|
||||||
int test_minimum_size(const char *file, u32 nodesize);
|
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);
|
||||||
int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
|
int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
|
||||||
u64 dev_cnt, int mixed, int ssd);
|
u64 dev_cnt, int mixed, int ssd);
|
||||||
|
|
10
mkfs/main.c
10
mkfs/main.c
|
@ -1453,6 +1453,7 @@ int main(int argc, char **argv)
|
||||||
u64 num_of_meta_chunks = 0;
|
u64 num_of_meta_chunks = 0;
|
||||||
u64 size_of_data = 0;
|
u64 size_of_data = 0;
|
||||||
u64 source_dir_size = 0;
|
u64 source_dir_size = 0;
|
||||||
|
u64 min_dev_size;
|
||||||
int dev_cnt = 0;
|
int dev_cnt = 0;
|
||||||
int saved_optind;
|
int saved_optind;
|
||||||
char fs_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 };
|
char fs_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 };
|
||||||
|
@ -1663,19 +1664,20 @@ int main(int argc, char **argv)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
min_dev_size = btrfs_min_dev_size(nodesize);
|
||||||
/* Check device/block_count after the nodesize is determined */
|
/* Check device/block_count after the nodesize is determined */
|
||||||
if (block_count && block_count < btrfs_min_dev_size(nodesize)) {
|
if (block_count && block_count < min_dev_size) {
|
||||||
error("size %llu is too small to make a usable filesystem",
|
error("size %llu is too small to make a usable filesystem",
|
||||||
block_count);
|
block_count);
|
||||||
error("minimum size for btrfs filesystem is %llu",
|
error("minimum size for btrfs filesystem is %llu",
|
||||||
btrfs_min_dev_size(nodesize));
|
min_dev_size);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
for (i = saved_optind; i < saved_optind + dev_cnt; i++) {
|
for (i = saved_optind; i < saved_optind + dev_cnt; i++) {
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
path = argv[i];
|
path = argv[i];
|
||||||
ret = test_minimum_size(path, nodesize);
|
ret = test_minimum_size(path, min_dev_size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error("failed to check size for %s: %s",
|
error("failed to check size for %s: %s",
|
||||||
path, strerror(-ret));
|
path, strerror(-ret));
|
||||||
|
@ -1685,7 +1687,7 @@ int main(int argc, char **argv)
|
||||||
error("'%s' is too small to make a usable filesystem",
|
error("'%s' is too small to make a usable filesystem",
|
||||||
path);
|
path);
|
||||||
error("minimum size for each btrfs device is %llu",
|
error("minimum size for each btrfs device is %llu",
|
||||||
btrfs_min_dev_size(nodesize));
|
min_dev_size);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue