]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: correctly identify crush names
authorSage Weil <sage@inktank.com>
Fri, 16 Nov 2012 00:24:38 +0000 (16:24 -0800)
committerSage Weil <sage@inktank.com>
Fri, 16 Nov 2012 00:32:50 +0000 (16:32 -0800)
get_item_id() returns 0 if the name already exists; that's not what we
want here.  Verify the name exists before checking its id.

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

index c0c7b5c99d1a2e4052ab275c69d26d88bde7a05f..c2563c32cd7431aa920ce94e8e1ce58e531defcf 100644 (file)
@@ -2208,9 +2208,14 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
        bufferlist::iterator p = bl.begin();
        newcrush.decode(p);
 
+       if (!newcrush.name_exists(m->cmd[3].c_str())) {
+         err = -ENOENT;
+         ss << "device '" << m->cmd[3] << "' does not appear in the crush map";
+         break;
+       }
        int id = newcrush.get_item_id(m->cmd[3].c_str());
        if (id < 0) {
-         ss << "device '" << m->cmd[3] << "' does not appear in the crush map";
+         ss << "item '" << m->cmd[3] << "' is not a leaf in the crush map";
          break;
        }
        err = newcrush.remove_item(g_ceph_context, id);
@@ -2237,9 +2242,15 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
        bufferlist::iterator p = bl.begin();
        newcrush.decode(p);
 
+       if (!newcrush.name_exists(m->cmd[3].c_str())) {
+         err = -ENOENT;
+         ss << "device '" << m->cmd[3] << "' does not appear in the crush map";
+         break;
+       }
+
        int id = newcrush.get_item_id(m->cmd[3].c_str());
        if (id < 0) {
-         ss << "device '" << m->cmd[3] << "' does not appear in the crush map";
+         ss << "device '" << m->cmd[3] << "' is not a leaf in the crush map";
          break;
        }
        float w = atof(m->cmd[4].c_str());