From ec931b790789605c7e392d494c946f44713a2698 Mon Sep 17 00:00:00 2001 From: Pierre-Hugues Husson Date: Fri, 19 Jun 2020 01:16:54 +0200 Subject: [PATCH] Autodetect best group, not everyone uses main --- cmds/lptools.cc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cmds/lptools.cc b/cmds/lptools.cc index 840c97f..375db13 100644 --- a/cmds/lptools.cc +++ b/cmds/lptools.cc @@ -78,12 +78,32 @@ void saveToDisk(std::unique_ptr builder) { } } +std::string findGroup(std::unique_ptr& 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) { if(argc<=1) { std::cerr << "Usage: " << argv[0] << " " << std::endl; exit(1); } auto builder = makeBuilder(); + auto group = findGroup(builder); + std::cout << "Best group seems to be " << group << std::endl; + if(strcmp(argv[1], "create") == 0) { if(argc != 4) { std::cerr << "Usage: " << argv[0] << " create " << std::endl; @@ -96,7 +116,7 @@ int main(int argc, char **argv) { std::cerr << "Partition " << partName << " already exists." << std::endl; exit(1); } - partition = builder->AddPartition(partName, "main", 0); + partition = builder->AddPartition(partName, group, 0); std::cout << "Growing partition " << builder->ResizePartition(partition, size) << std::endl; saveToDisk(std::move(builder)); @@ -158,7 +178,7 @@ int main(int argc, char **argv) { } builder->RemovePartition(src); builder->RemovePartition(dst); - auto newDstPartition = builder->AddPartition(dst, "main", 0); + auto newDstPartition = builder->AddPartition(dst, group, 0); for(auto&& extent: originalExtents) { newDstPartition->AddExtent(std::move(extent)); }