]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: add 'osd crush add-bucket <name> <type>'
authorSage Weil <sage@inktank.com>
Thu, 21 Mar 2013 18:04:59 +0000 (11:04 -0700)
committerSage Weil <sage@inktank.com>
Fri, 22 Mar 2013 22:15:38 +0000 (15:15 -0700)
This is (I think) the last missing piece to let you construct an entire
map via the CLI.  The add/set commands will construct intervening ancestor
nodes provide there is an existing ancestor to stick them under, but this
is needed to create the initial root node.

Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/OSDMonitor.cc
src/test/cli/ceph/help.t
src/tools/ceph.cc

index 42d9c0ff110603d9c0b5664e4c4fd3b6041eb13d..41df0d8b36ed64dca7a7bc5cc1bd05075adb9162 100644 (file)
@@ -2256,6 +2256,42 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
       wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs, get_version()));
       return true;
     }
+    else if (m->cmd.size() == 5 && m->cmd[1] == "crush" && (m->cmd[2] == "add-bucket")) {
+      do {
+       // osd crush add-bucket <name> <type>
+       bufferlist bl;
+       if (pending_inc.crush.length())
+         bl = pending_inc.crush;
+       else
+         osdmap.crush->encode(bl);
+
+       CrushWrapper newcrush;
+       bufferlist::iterator p = bl.begin();
+       newcrush.decode(p);
+
+       if (newcrush.name_exists(m->cmd[3])) {
+         ss << "bucket '" << m->cmd[3] << "' already exists";
+         err = 0;
+         break;
+       }
+       int type = newcrush.get_type_id(m->cmd[4]);
+       if (type <= 0) {
+         ss << "type '" << m->cmd[4] << "' does not exist";
+         err = -EINVAL;
+         break;
+       }
+       int bucketno = newcrush.add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT,
+                                          type, 0, NULL, NULL);
+       newcrush.set_item_name(bucketno, m->cmd[3]);
+
+       pending_inc.crush.clear();
+       newcrush.encode(pending_inc.crush);
+       ss << "added bucket " << m->cmd[3] << " type " << m->cmd[4] << " to crush map";
+       getline(ss, rs);
+       wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs, get_version()));
+       return true;
+      } while (false);
+    }
     else if (m->cmd.size() >= 5 && m->cmd[1] == "crush" && (m->cmd[2] == "set" ||
                                                            m->cmd[2] == "add")) {
       do {
index 123a07464ebc18f12e190bee1e7d2b38026981f3..c3c0a984beed6b9d19be48b60384619f1fbb07c6 100644 (file)
@@ -49,6 +49,7 @@
     ceph osd crush create-or-move <osd-id> <initial-weight> <loc1> [<loc2> ...]
     ceph osd crush move <bucketname> <loc1> [<loc2> ...]
     ceph osd crush link <bucketname> <loc1> [<loc2> ...]
+    ceph osd crush add-bucket <bucketname> <type>
     ceph osd crush reweight <name> <weight>
     ceph osd crush tunables <legacy|argonaut|bobtail|optimal|default>
     ceph osd create [<uuid>]
index 1dcec25463211120f14e01a5012fa5750995bb54..3a7aa068a49b67441f6ae7b7f4a3bfca2a999c1a 100644 (file)
@@ -92,6 +92,7 @@ static void usage()
   cout << "  ceph osd crush create-or-move <osd-id> <initial-weight> <loc1> [<loc2> ...]\n";
   cout << "  ceph osd crush move <bucketname> <loc1> [<loc2> ...]\n";
   cout << "  ceph osd crush link <bucketname> <loc1> [<loc2> ...]\n";
+  cout << "  ceph osd crush add-bucket <bucketname> <type>\n";
   cout << "  ceph osd crush reweight <name> <weight>\n";
   cout << "  ceph osd crush tunables <legacy|argonaut|bobtail|optimal|default>\n";
   cout << "  ceph osd create [<uuid>]\n";