From 0c12988394743f45c0c60fb76f4a99a00d6aa425 Mon Sep 17 00:00:00 2001 From: Alex Marangone Date: Sun, 16 Feb 2020 09:56:27 -0800 Subject: [PATCH] osdmaptool: Add options to change CRUSH weights Signed-off-by: Alex Marangone --- src/tools/osdmaptool.cc | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/tools/osdmaptool.cc b/src/tools/osdmaptool.cc index 325450e0aa80c..834546d414a46 100644 --- a/src/tools/osdmaptool.cc +++ b/src/tools/osdmaptool.cc @@ -64,6 +64,8 @@ void usage() cout << " --dump displays the map in plain text when is 'plain', 'json' if specified format is not supported" << std::endl; cout << " --tree displays a tree of the map" << std::endl; cout << " --test-crush [--range-first --range-last ] map pgs to acting osds" << std::endl; + cout << " --adjust-crush-weight [,,<...>] change CRUSH (but do not persist)" << std::endl; + cout << " --crush-adjust-save saves adjust-crush-weight to CRUSHmap" << std::endl; exit(1); } @@ -131,7 +133,8 @@ int main(int argc, const char **argv) int pgp_bits = 6; bool clobber = false; bool modified = false; - std::string export_crush, import_crush, test_map_pg, test_map_object; + std::string export_crush, import_crush, test_map_pg, test_map_object, adjust_crush_weight; + bool crush_adjust_save = false; bool test_crush = false; int range_first = -1; int range_last = -1; @@ -257,6 +260,10 @@ int main(int argc, const char **argv) cerr << err.str() << std::endl; exit(EXIT_FAILURE); } + } else if (ceph_argparse_witharg(args, i, &val, err, "--adjust-crush-weight", (char*)NULL)) { + adjust_crush_weight = val; + } else if (ceph_argparse_flag(args, i, "--crush-adjust-save", (char*)NULL)) { + crush_adjust_save = true; } else { ++i; } @@ -378,6 +385,27 @@ int main(int argc, const char **argv) osdmap.set_weight(id, CEPH_OSD_IN); } + for_each_substr(adjust_crush_weight, ",", [&](auto osd_to_adjust) { + std::string_view osd_to_weight_delimiter{":"}; + size_t pos = osd_to_adjust.find(osd_to_weight_delimiter); + if (pos == osd_to_adjust.npos) { + cerr << me << ": use ':' as separator of osd id and its weight" + << std::endl; + usage(); + } + int osd_id = std::stoi(string(osd_to_adjust.substr(0, pos))); + float new_weight = std::stof(string(osd_to_adjust.substr(pos + 1))); + osdmap.crush->adjust_item_weightf(g_ceph_context, osd_id, new_weight); + std::cout << "Adjusted osd." << osd_id << " CRUSH weight to " << new_weight + << std::endl; + if (crush_adjust_save) { + OSDMap::Incremental inc; + inc.fsid = osdmap.get_fsid(); + inc.epoch = osdmap.get_epoch() + 1; + osdmap.apply_incremental(inc); + modified = true; + } + }); if (clear_temp) { cout << "clearing pg/primary temp" << std::endl; @@ -763,7 +791,7 @@ skip_upmap: export_crush.empty() && import_crush.empty() && test_map_pg.empty() && test_map_object.empty() && !test_map_pgs && !test_map_pgs_dump && !test_map_pgs_dump_all && - !upmap && !upmap_cleanup) { + adjust_crush_weight.empty() && !upmap && !upmap_cleanup) { cerr << me << ": no action specified?" << std::endl; usage(); } -- 2.39.5