From: Sage Weil Date: Sun, 25 May 2014 21:02:16 +0000 (-0700) Subject: mon/OSDMonitor: add 'osd crush reweight-subtree ...' X-Git-Tag: v0.83~117^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=576315ac15e50bb1350dd32e31ccfcebf3f39562;p=ceph.git mon/OSDMonitor: add 'osd crush reweight-subtree ...' Reweight all items within a subtree. For example, you might reweigh tall OSDs within a rack to a new value. Signed-off-by: Sage Weil --- diff --git a/qa/workunits/mon/crush_ops.sh b/qa/workunits/mon/crush_ops.sh index 56a0d232d712..80950032fb2f 100755 --- a/qa/workunits/mon/crush_ops.sh +++ b/qa/workunits/mon/crush_ops.sh @@ -84,4 +84,19 @@ ceph osd tree | grep osd.$o3 | grep 113 ceph osd crush rm osd.$o3 ceph osd rm osd.$o3 +# test reweight-subtree +o4=`ceph osd create` +o5=`ceph osd create` +ceph osd crush add $o4 123 root=default host=foobaz +ceph osd crush add $o5 123 root=default host=foobaz +ceph osd tree | grep osd.$o4 | grep 123 +ceph osd tree | grep osd.$o5 | grep 123 +ceph osd crush reweight-subtree foobaz 155 +ceph osd tree | grep osd.$o4 | grep 155 +ceph osd tree | grep osd.$o5 | grep 155 +ceph osd crush rm osd.$o4 +ceph osd crush rm osd.$o5 +ceph osd rm osd.$o4 +ceph osd rm osd.$o5 + echo OK diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 36f1e9fc7c4e..64e260d61739 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -430,6 +430,11 @@ COMMAND("osd crush reweight " \ "name=weight,type=CephFloat,range=0.0", \ "change 's weight to in crush map", \ "osd", "rw", "cli,rest") +COMMAND("osd crush reweight-subtree " \ + "name=name,type=CephString,goodchars=[A-Za-z0-9-_.] " \ + "name=weight,type=CephFloat,range=0.0", \ + "change all leaf items beneath to in crush map", \ + "osd", "rw", "cli,rest") COMMAND("osd crush tunables " \ "name=profile,type=CephChoices,strings=legacy|argonaut|bobtail|firefly|optimal|default", \ "set crush tunables values to ", "osd", "rw", "cli,rest") diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 6785f904d5eb..54d9780f222e 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -3978,6 +3978,44 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m, } } while (false); + } else if (prefix == "osd crush reweight-subtree") { + // osd crush reweight + CrushWrapper newcrush; + _get_pending_crush(newcrush); + + string name; + cmd_getval(g_ceph_context, cmdmap, "name", name); + if (!newcrush.name_exists(name)) { + err = -ENOENT; + ss << "device '" << name << "' does not appear in the crush map"; + goto reply; + } + + int id = newcrush.get_item_id(name); + if (id >= 0) { + ss << "device '" << name << "' is not a subtree in the crush map"; + err = -EINVAL; + goto reply; + } + double w; + if (!cmd_getval(g_ceph_context, cmdmap, "weight", w)) { + ss << "unable to parse weight value '" + << cmd_vartype_stringify(cmdmap["weight"]) << "'"; + err = -EINVAL; + goto reply; + } + + err = newcrush.adjust_subtree_weightf(g_ceph_context, id, w); + if (err < 0) + goto reply; + pending_inc.crush.clear(); + newcrush.encode(pending_inc.crush); + ss << "reweighted subtree id " << id << " name '" << name << "' to " << w + << " in crush map"; + 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 tunables") { CrushWrapper newcrush; _get_pending_crush(newcrush);