]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/OSDMonitor: spin-off osd and crush rm functions
authorJoao Eduardo Luis <joao@suse.de>
Wed, 12 Apr 2017 13:20:43 +0000 (14:20 +0100)
committerJoao Eduardo Luis <joao@suse.de>
Mon, 5 Jun 2017 14:31:40 +0000 (15:31 +0100)
Signed-off-by: Joao Eduardo Luis <joao@suse.de>
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h

index fc70966800d288202932e2c908f5450cccf3ee13..38ed0395161eb4f3dc52a64fc35dcecea42101a4 100644 (file)
@@ -6375,6 +6375,46 @@ int OSDMonitor::prepare_command_pool_set(map<string,cmd_vartype> &cmdmap,
   return 0;
 }
 
+int OSDMonitor::prepare_command_osd_crush_remove(
+    CrushWrapper &newcrush,
+    int32_t id,
+    int32_t ancestor,
+    bool has_ancestor,
+    bool unlink_only)
+{
+  int err = 0;
+
+  if (has_ancestor) {
+    err = newcrush.remove_item_under(g_ceph_context, id, ancestor,
+        unlink_only);
+  } else {
+    err = newcrush.remove_item(g_ceph_context, id, unlink_only);
+  }
+
+  if (err < 0)
+    return err;
+
+  assert(err == 0);
+  pending_inc.crush.clear();
+  newcrush.encode(pending_inc.crush, mon->get_quorum_con_features());
+
+  return 0;
+}
+
+int OSDMonitor::prepare_command_osd_remove(int32_t id)
+{
+  if (osdmap.is_up(id)) {
+    return -EBUSY;
+  }
+
+  pending_inc.new_state[id] = osdmap.get_state(id);
+  pending_inc.new_uuid[id] = uuid_d();
+  pending_metadata_rm.insert(id);
+  pending_metadata.erase(id);
+
+  return 0;
+}
+
 bool OSDMonitor::prepare_command(MonOpRequestRef op)
 {
   op->mark_osdmon_event(__func__);
@@ -7040,6 +7080,8 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
        return true;
       }
       int id = newcrush.get_item_id(name);
+      int ancestor = 0;
+
       bool unlink_only = prefix == "osd crush unlink";
       string ancestor_str;
       if (cmd_getval(g_ceph_context, cmdmap, "ancestor", ancestor_str)) {
@@ -7049,20 +7091,20 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
             << "' does not appear in the crush map";
          break;
        }
-       int ancestor = newcrush.get_item_id(ancestor_str);
-       err = newcrush.remove_item_under(g_ceph_context, id, ancestor,
-                                        unlink_only);
-      } else {
-       err = newcrush.remove_item(g_ceph_context, id, unlink_only);
+        ancestor = newcrush.get_item_id(ancestor_str);
       }
+
+      err = prepare_command_osd_crush_remove(
+          newcrush,
+          id, ancestor,
+          (ancestor < 0), unlink_only);
+
       if (err == -ENOENT) {
        ss << "item " << id << " does not appear in that position";
        err = 0;
        break;
       }
       if (err == 0) {
-       pending_inc.crush.clear();
-       newcrush.encode(pending_inc.crush, mon->get_quorum_con_features());
        ss << "removed item id " << id << " name '" << name << "' from crush map";
        getline(ss, rs);
        wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs,
@@ -7808,16 +7850,14 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
          any = true;
        }
       } else if (prefix == "osd rm") {
-       if (osdmap.is_up(osd)) {
+        err = prepare_command_osd_remove(osd);
+
+        if (err == -EBUSY) {
          if (any)
            ss << ", ";
           ss << "osd." << osd << " is still up; must be down before removal. ";
-         err = -EBUSY;
        } else {
-         pending_inc.new_state[osd] = osdmap.get_state(osd);
-          pending_inc.new_uuid[osd] = uuid_d();
-         pending_metadata_rm.insert(osd);
-         pending_metadata.erase(osd);
+          assert(err == 0);
          if (any) {
            ss << ", osd." << osd;
           } else {
index 840cebb1462d9902d36e138cc4cc7f588ca27f16..f4aa28803a4bcdf644cb19b4a848b9933c216913 100644 (file)
@@ -477,6 +477,13 @@ public:
   bool prepare_command_impl(MonOpRequestRef op, map<string,cmd_vartype>& cmdmap);
 
   int prepare_command_osd_destroy(int32_t id, stringstream& ss);
+  int prepare_command_osd_crush_remove(
+      CrushWrapper &newcrush,
+      int32_t id,
+      int32_t ancestor,
+      bool has_ancestor,
+      bool unlink_only);
+  int prepare_command_osd_remove(int32_t id);
   int prepare_command_pool_set(map<string,cmd_vartype> &cmdmap,
                                stringstream& ss);