]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: 'osd crush add <id> <name> <weight> [<loc1=foo> [<loc2=bar> ...]]'
authorSage Weil <sage@newdream.net>
Tue, 23 Aug 2011 19:31:35 +0000 (12:31 -0700)
committerSage Weil <sage@newdream.net>
Tue, 23 Aug 2011 19:31:35 +0000 (12:31 -0700)
This is identical to the crushtool --add-item functionality, but does not
require a racy and tedious

 - get crush map
 - update crush map
 - set new crush map

Signed-off-by: Sage Weil <sage@newdream.net>
src/mon/OSDMonitor.cc

index 68879c4e6e6eb7d5cbab13a472d99f36dc578f58..16cf78d7dbe2e05358211602909df0bd2c5bdb6f 100644 (file)
@@ -1409,6 +1409,53 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
       paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
       return true;
     }
+    else if (m->cmd[1] == "crush" && m->cmd[2] == "add" && m->cmd.size() >= 6) {
+      do {
+       // osd crush add <id> <name> <weight> [<loc1> [<loc2> ...]]
+       int id = atoi(m->cmd[3].c_str());
+       string name = m->cmd[4];
+       float weight = atof(m->cmd[5].c_str());
+       map<string,string> loc;
+       for (unsigned i = 6; i < m->cmd.size(); ++i) {
+         const char *s = m->cmd[i].c_str();
+         const char *pos = strchr(s, '=');
+         if (!pos)
+           break;
+         string key(s, 0, pos-s);
+         string value(pos+1);
+         loc[key] = value;
+       }
+
+       dout(0) << "adding crush item id " << id << " name '" << name << "' weight " << weight
+               << " at location " << loc << dendl;
+       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);
+
+       err = newcrush.insert_item(id, (int)(weight * (float)0x10000), name, loc);
+       if (err == 0) {
+         if (newcrush.get_max_devices() > osdmap.get_max_osd()) {
+           err = -ERANGE;
+           ss << "crushmap max_devices " << newcrush.get_max_devices()
+              << " > osdmap max_osd " << osdmap.get_max_osd();
+           break;
+         }
+         pending_inc.crush.clear();
+         newcrush.encode(pending_inc.crush);
+         ss << "added item id " << id << " name '" << name << "' weight " << weight
+            << " at location " << loc << " to crush map";
+         getline(ss, rs);
+         paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
+         return true;
+       }
+      } while (false);
+    }
     else if (m->cmd[1] == "setmaxosd" && m->cmd.size() > 2) {
       int newmax = atoi(m->cmd[2].c_str());
       if (newmax < osdmap.crush.get_max_devices()) {