]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/OSDMonitor: add 'osd crush reweight-subtree ...'
authorSage Weil <sage@inktank.com>
Sun, 25 May 2014 21:02:16 +0000 (14:02 -0700)
committerSage Weil <sage@inktank.com>
Tue, 27 May 2014 22:42:08 +0000 (15:42 -0700)
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 <sage@inktank.com>
qa/workunits/mon/crush_ops.sh
src/mon/MonCommands.h
src/mon/OSDMonitor.cc

index 56a0d232d71248bc352f946fdd6c6fd672804449..80950032fb2f97ad89a3283b9eed7838db261e39 100755 (executable)
@@ -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
index 36f1e9fc7c4ecb24a35faaab7dc2187997c7f1bb..64e260d61739798a43dba91ece2a3fa957204f89 100644 (file)
@@ -430,6 +430,11 @@ COMMAND("osd crush reweight " \
        "name=weight,type=CephFloat,range=0.0", \
        "change <name>'s weight to <weight> 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 <name> to <weight> 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 <profile>", "osd", "rw", "cli,rest")
index 6785f904d5eb78a35378ba5b5cfbd826c4ca377e..54d9780f222e845f1e3f1b5dd3bd911324a1c21b 100644 (file)
@@ -3978,6 +3978,44 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m,
       }
     } while (false);
 
+  } else if (prefix == "osd crush reweight-subtree") {
+    // osd crush reweight <name> <weight>
+    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);