]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: 'osd crush set ...' do an add or update
authorSage Weil <sage@newdream.net>
Wed, 2 May 2012 21:17:26 +0000 (14:17 -0700)
committerSage Weil <sage@newdream.net>
Wed, 2 May 2012 21:55:54 +0000 (14:55 -0700)
This operation will add/update/move the item to the specified location.
It is idempotent and much more useful than 'osd crush add ...'.

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

index d0d0a7f4a515016ef27c79fa2d00a0241c516a6c..57a47b38f14d3da394d0b138208d6e73f77add08 100644 (file)
@@ -1783,6 +1783,52 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
        }
       } while (false);
     }
+    else if (m->cmd.size() >= 6 && m->cmd[1] == "crush" && m->cmd[2] == "set") {
+      do {
+       // osd crush update <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/updating 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.update_item(g_ceph_context, id, weight, name, loc);
+       if (err == 0) {
+         ss << "updated item id " << id << " name '" << name << "' weight " << weight
+            << " at location " << loc << " to crush map";
+         break;
+       }
+       if (err > 0) {
+         pending_inc.crush.clear();
+         newcrush.encode(pending_inc.crush);
+         ss << "updated 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.size() > 3 && m->cmd[1] == "crush" && (m->cmd[2] == "rm" || m->cmd[2] == "remove")) {
       do {
        // osd crush rm <id>