From 344c4fdc3f70b7cdc9b077891efb4fbd80848907 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 15 Nov 2012 16:24:38 -0800 Subject: [PATCH] mon: correctly identify crush names 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 --- src/mon/OSDMonitor.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index c0c7b5c99d1a2..c2563c32cd743 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -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()); -- 2.39.5