Add vitastor-disk prepare --dry-run option
This commit is contained in:
@@ -73,6 +73,8 @@ Options (automatic mode):
|
|||||||
--max_other 10%
|
--max_other 10%
|
||||||
Use disks for OSD data even if they already have non-Vitastor partitions,
|
Use disks for OSD data even if they already have non-Vitastor partitions,
|
||||||
but only if these take up no more than this percent of disk space.
|
but only if these take up no more than this percent of disk space.
|
||||||
|
--dry-run
|
||||||
|
Check and print new OSD count for each disk but do not actually create them.
|
||||||
```
|
```
|
||||||
|
|
||||||
Options (single-device mode):
|
Options (single-device mode):
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ vitastor-disk - инструмент командной строки для уп
|
|||||||
--max_other 10%
|
--max_other 10%
|
||||||
Использовать диски под данные OSD, даже если на них уже есть не-Vitastor-овые
|
Использовать диски под данные OSD, даже если на них уже есть не-Vitastor-овые
|
||||||
разделы, но только в случае, если они занимают не более данного процента диска.
|
разделы, но только в случае, если они занимают не более данного процента диска.
|
||||||
|
--dry-run
|
||||||
|
Проверить и вывести число новых OSD для каждого диска, но не создавать их.
|
||||||
```
|
```
|
||||||
|
|
||||||
Опции для режима одного OSD:
|
Опции для режима одного OSD:
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ static const char *help_text =
|
|||||||
" --max_other 10%\n"
|
" --max_other 10%\n"
|
||||||
" Use disks for OSD data even if they already have non-Vitastor partitions,\n"
|
" Use disks for OSD data even if they already have non-Vitastor partitions,\n"
|
||||||
" but only if these take up no more than this percent of disk space.\n"
|
" but only if these take up no more than this percent of disk space.\n"
|
||||||
|
" --dry-run\n"
|
||||||
|
" Check and print new OSD count for each disk but do not actually create them.\n"
|
||||||
" \n"
|
" \n"
|
||||||
" Options (single-device mode):\n"
|
" Options (single-device mode):\n"
|
||||||
" --data_device <DEV> Use partition <DEV> for data\n"
|
" --data_device <DEV> Use partition <DEV> for data\n"
|
||||||
|
|||||||
@@ -134,7 +134,8 @@ struct disk_tool_t
|
|||||||
int prepare(std::vector<std::string> devices);
|
int prepare(std::vector<std::string> devices);
|
||||||
std::vector<vitastor_dev_info_t> collect_devices(const std::vector<std::string> & devices);
|
std::vector<vitastor_dev_info_t> collect_devices(const std::vector<std::string> & devices);
|
||||||
json11::Json add_partitions(vitastor_dev_info_t & devinfo, std::vector<std::string> sizes);
|
json11::Json add_partitions(vitastor_dev_info_t & devinfo, std::vector<std::string> sizes);
|
||||||
std::vector<std::string> get_new_data_parts(vitastor_dev_info_t & dev, uint64_t osd_per_disk, uint64_t max_other_percent);
|
std::vector<std::string> get_new_data_parts(vitastor_dev_info_t & dev,
|
||||||
|
uint64_t osd_per_disk, uint64_t max_other_percent, uint64_t *check_new_count);
|
||||||
int get_meta_partition(std::vector<vitastor_dev_info_t> & ssds, std::map<std::string, std::string> & options);
|
int get_meta_partition(std::vector<vitastor_dev_info_t> & ssds, std::map<std::string, std::string> & options);
|
||||||
|
|
||||||
int upgrade_simple_unit(std::string unit);
|
int upgrade_simple_unit(std::string unit);
|
||||||
|
|||||||
@@ -435,7 +435,7 @@ json11::Json disk_tool_t::add_partitions(vitastor_dev_info_t & devinfo, std::vec
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> disk_tool_t::get_new_data_parts(vitastor_dev_info_t & dev,
|
std::vector<std::string> disk_tool_t::get_new_data_parts(vitastor_dev_info_t & dev,
|
||||||
uint64_t osd_per_disk, uint64_t max_other_percent)
|
uint64_t osd_per_disk, uint64_t max_other_percent, uint64_t *check_new_count)
|
||||||
{
|
{
|
||||||
std::vector<std::string> use_parts;
|
std::vector<std::string> use_parts;
|
||||||
uint64_t want_parts = 0;
|
uint64_t want_parts = 0;
|
||||||
@@ -457,7 +457,6 @@ std::vector<std::string> disk_tool_t::get_new_data_parts(vitastor_dev_info_t & d
|
|||||||
{
|
{
|
||||||
// Use this partition
|
// Use this partition
|
||||||
use_parts.push_back(part["uuid"].string_value());
|
use_parts.push_back(part["uuid"].string_value());
|
||||||
osds_exist++;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -480,9 +479,21 @@ std::vector<std::string> disk_tool_t::get_new_data_parts(vitastor_dev_info_t & d
|
|||||||
}
|
}
|
||||||
// Still create OSD(s) if a disk has no more than (max_other_percent) other data
|
// Still create OSD(s) if a disk has no more than (max_other_percent) other data
|
||||||
if (osds_exist >= osd_per_disk || (dev.free+osds_size) < dev.size*(100-max_other_percent)/100)
|
if (osds_exist >= osd_per_disk || (dev.free+osds_size) < dev.size*(100-max_other_percent)/100)
|
||||||
|
{
|
||||||
fprintf(stderr, "%s is already partitioned, skipping\n", dev.path.c_str());
|
fprintf(stderr, "%s is already partitioned, skipping\n", dev.path.c_str());
|
||||||
|
use_parts.clear();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
want_parts = osd_per_disk-osds_exist;
|
{
|
||||||
|
if (use_parts.size() >= osd_per_disk-osds_exist)
|
||||||
|
use_parts.resize(osd_per_disk-osds_exist);
|
||||||
|
want_parts = osd_per_disk-osds_exist-use_parts.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (check_new_count)
|
||||||
|
{
|
||||||
|
*check_new_count = want_parts;
|
||||||
|
return use_parts;
|
||||||
}
|
}
|
||||||
if (want_parts > 0)
|
if (want_parts > 0)
|
||||||
{
|
{
|
||||||
@@ -684,10 +695,25 @@ int disk_tool_t::prepare(std::vector<std::string> devices)
|
|||||||
}
|
}
|
||||||
json11::Json::array all_results, errors;
|
json11::Json::array all_results, errors;
|
||||||
auto journal_size = options["journal_size"];
|
auto journal_size = options["journal_size"];
|
||||||
|
if (options.find("dry_run") != options.end())
|
||||||
|
{
|
||||||
|
json11::Json::array results;
|
||||||
|
for (auto & dev: devinfo)
|
||||||
|
{
|
||||||
|
uint64_t new_part_count = 0;
|
||||||
|
auto existing_part_count = get_new_data_parts(dev, osd_per_disk, max_other_percent, &new_part_count).size();
|
||||||
|
results.push_back(json11::Json::object{ { "device_path", dev.path }, { "new_osd_count", existing_part_count+new_part_count } });
|
||||||
|
if (!json && new_part_count+existing_part_count > 0)
|
||||||
|
printf("Will initialize %ju OSD(s) on %s\n", existing_part_count+new_part_count, dev.path.c_str());
|
||||||
|
}
|
||||||
|
if (json)
|
||||||
|
printf("%s\n", json11::Json(json11::Json::object{{ "devices", results }}).dump().c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
for (auto & dev: devinfo)
|
for (auto & dev: devinfo)
|
||||||
{
|
{
|
||||||
// Select new partitions and create an OSD on each of them
|
// Select new partitions and create an OSD on each of them
|
||||||
for (const auto & uuid: get_new_data_parts(dev, osd_per_disk, max_other_percent))
|
for (const auto & uuid: get_new_data_parts(dev, osd_per_disk, max_other_percent, NULL))
|
||||||
{
|
{
|
||||||
options["force"] = true;
|
options["force"] = true;
|
||||||
options["data_device"] = "/dev/disk/by-partuuid/"+strtolower(uuid);
|
options["data_device"] = "/dev/disk/by-partuuid/"+strtolower(uuid);
|
||||||
|
|||||||
Reference in New Issue
Block a user