Autodetect best group, not everyone uses main

This commit is contained in:
Pierre-Hugues Husson 2020-06-19 01:16:54 +02:00
parent 97b340689d
commit 01390142b9

View File

@ -78,12 +78,32 @@ void saveToDisk(std::unique_ptr<MetadataBuilder> builder) {
} }
} }
std::string findGroup(std::unique_ptr<MetadataBuilder>& builder) {
auto groups = builder->ListGroups();
std::string maxGroup = "";
uint64_t maxGroupSize = 0;
for(auto groupName: groups) {
auto group = builder->FindGroup(groupName);
if(group->maximum_size() > maxGroupSize) {
maxGroup = groupName;
maxGroupSize = group->maximum_size();
}
}
return maxGroup;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
if(argc<=1) { if(argc<=1) {
std::cerr << "Usage: " << argv[0] << " <create|remove|resize|rename>" << std::endl; std::cerr << "Usage: " << argv[0] << " <create|remove|resize|rename>" << std::endl;
exit(1); exit(1);
} }
auto builder = makeBuilder(); auto builder = makeBuilder();
auto group = findGroup(builder);
std::cout << "Best group seems to be " << group << std::endl;
if(strcmp(argv[1], "create") == 0) { if(strcmp(argv[1], "create") == 0) {
if(argc != 4) { if(argc != 4) {
std::cerr << "Usage: " << argv[0] << " create <partition name> <partition size>" << std::endl; std::cerr << "Usage: " << argv[0] << " create <partition name> <partition size>" << std::endl;
@ -96,7 +116,7 @@ int main(int argc, char **argv) {
std::cerr << "Partition " << partName << " already exists." << std::endl; std::cerr << "Partition " << partName << " already exists." << std::endl;
exit(1); exit(1);
} }
partition = builder->AddPartition(partName, "main", 0); partition = builder->AddPartition(partName, group, 0);
std::cout << "Growing partition " << builder->ResizePartition(partition, size) << std::endl; std::cout << "Growing partition " << builder->ResizePartition(partition, size) << std::endl;
saveToDisk(std::move(builder)); saveToDisk(std::move(builder));
@ -158,7 +178,7 @@ int main(int argc, char **argv) {
} }
builder->RemovePartition(src); builder->RemovePartition(src);
builder->RemovePartition(dst); builder->RemovePartition(dst);
auto newDstPartition = builder->AddPartition(dst, "main", 0); auto newDstPartition = builder->AddPartition(dst, group, 0);
for(auto&& extent: originalExtents) { for(auto&& extent: originalExtents) {
newDstPartition->AddExtent(std::move(extent)); newDstPartition->AddExtent(std::move(extent));
} }