From 3ab835b059fd74a525cc2a8ebe8b6a1453e0cc87 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 2 Dec 2014 16:43:16 -0800 Subject: [PATCH] mon: add 'osd crush {get,set}-tunable [value]' commands For now, just add the straw_calc_version tunable. Signed-off-by: Sage Weil (cherry picked from commit 9000068ae45a8b89315c152b7d5509ac873f2957) Conflicts: src/mon/OSDMonitor.cc --- qa/workunits/cephtool/test.sh | 5 +++ src/mon/MonCommands.h | 9 +++++ src/mon/OSDMonitor.cc | 65 +++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 20f6319d30028..46f6a94dcf60c 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -428,6 +428,11 @@ function test_mon_osd() ceph osd crush tunables firefly ceph osd crush show-tunables | grep firefly + ceph osd crush set-tunable straw_calc_version 0 + ceph osd crush get-tunable straw_calc_version | grep 0 + ceph osd crush set-tunable straw_calc_version 1 + ceph osd crush get-tunable straw_calc_version | grep 1 + # # osd scrub # diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index bd9dd2e79d63c..f5af54eb014ea 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -433,6 +433,15 @@ COMMAND("osd crush reweight " \ COMMAND("osd crush tunables " \ "name=profile,type=CephChoices,strings=legacy|argonaut|bobtail|firefly|optimal|default", \ "set crush tunables values to ", "osd", "rw", "cli,rest") +COMMAND("osd crush set-tunable " \ + "name=tunable,type=CephChoices,strings=straw_calc_version " \ + "name=value,type=CephInt", + "set crush tunable to ", + "osd", "rw", "cli,rest") +COMMAND("osd crush get-tunable " \ + "name=tunable,type=CephChoices,strings=straw_calc_version", + "get crush tunable ", + "osd", "rw", "cli,rest") COMMAND("osd crush show-tunables", \ "show current crush tunables", "osd", "r", "cli,rest") COMMAND("osd crush rule create-simple " \ diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 5f54f94d6c179..18428229430f6 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2465,6 +2465,31 @@ bool OSDMonitor::preprocess_command(MMonCommand *m) } ss << "listed " << osdmap.blacklist.size() << " entries"; + } else if (prefix == "osd crush get-tunable") { + string tunable; + cmd_getval(g_ceph_context, cmdmap, "tunable", tunable); + int value; + cmd_getval(g_ceph_context, cmdmap, "value", value); + ostringstream rss; + if (f) + f->open_object_section("tunable"); + if (tunable == "straw_calc_version") { + if (f) + f->dump_int(tunable.c_str(), osdmap.crush->get_straw_calc_version()); + else + rss << osdmap.crush->get_straw_calc_version() << "\n"; + } else { + r = -EINVAL; + goto reply; + } + if (f) { + f->close_section(); + f->flush(rdata); + } else { + rdata.append(rss.str()); + } + r = 0; + } else if (prefix == "osd pool get") { string poolstr; cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); @@ -4217,6 +4242,46 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m, wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs, get_last_committed() + 1)); return true; + } else if (prefix == "osd crush set-tunable") { + CrushWrapper newcrush; + _get_pending_crush(newcrush); + + err = 0; + string tunable; + cmd_getval(g_ceph_context, cmdmap, "tunable", tunable); + + int64_t value = -1; + if (!cmd_getval(g_ceph_context, cmdmap, "value", value)) { + err = -EINVAL; + ss << "failed to parse integer value " << cmd_vartype_stringify(cmdmap["value"]); + goto reply; + } + + if (tunable == "straw_calc_version") { + if (value < 0 || value > 2) { + ss << "value must be 0 or 1; got " << value; + err = -EINVAL; + goto reply; + } + newcrush.set_straw_calc_version(value); + } else { + ss << "unrecognized tunable '" << tunable << "'"; + err = -EINVAL; + goto reply; + } + + if (!validate_crush_against_features(&newcrush, ss)) { + err = -EINVAL; + goto reply; + } + + pending_inc.crush.clear(); + newcrush.encode(pending_inc.crush); + ss << "adjusted tunable " << tunable << " to " << value; + getline(ss, rs); + wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs, + get_last_committed() + 1)); + return true; } else if (prefix == "osd crush rule create-simple") { string name, root, type, mode; -- 2.39.5