]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon,mgr: guard 'osd destroy' with 'osd safe-to-destroy' check
authorSage Weil <sage@redhat.com>
Tue, 26 Jun 2018 12:00:33 +0000 (07:00 -0500)
committerSage Weil <sage@redhat.com>
Wed, 1 Aug 2018 13:12:15 +0000 (08:12 -0500)
Rename actual command 'osd destroy-actual', and map 'osd destroy' to the
mgr code so that we first check safe-to-destroy.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/DaemonServer.cc
src/mgr/MgrCommands.h
src/mon/MonCommands.h
src/mon/OSDMonitor.cc

index d94e663ae1e0eca3fe86bf49be44674fdce199e5..ae427392e6df7d35119178fd55f84e5511ed5ce2 100644 (file)
@@ -1201,17 +1201,28 @@ bool DaemonServer::handle_command(MCommand *m)
       cmdctx->reply(r, ss);
       return true;
     }
-  } else if (prefix == "osd safe-to-destroy") {
-    vector<string> ids;
-    cmd_getval(g_ceph_context, cmdctx->cmdmap, "ids", ids);
+  } else if (prefix == "osd safe-to-destroy" ||
+            prefix == "osd destroy") {
     set<int> osds;
-    int r;
-    cluster_state.with_osdmap([&](const OSDMap& osdmap) {
-       r = osdmap.parse_osd_id_list(ids, &osds, &ss);
-      });
-    if (!r && osds.empty()) {
-      ss << "must specify one or more OSDs";
-      r = -EINVAL;
+    int r = 0;
+    if (prefix == "osd safe-to-destroy") {
+      vector<string> ids;
+      cmd_getval(g_ceph_context, cmdctx->cmdmap, "ids", ids);
+      cluster_state.with_osdmap([&](const OSDMap& osdmap) {
+                                 r = osdmap.parse_osd_id_list(ids, &osds, &ss);
+                               });
+      if (!r && osds.empty()) {
+       ss << "must specify one or more OSDs";
+       r = -EINVAL;
+      }
+    } else {
+      int64_t id;
+      if (!cmd_getval(g_ceph_context, cmdctx->cmdmap, "id", id)) {
+       r = -EINVAL;
+       ss << "must specify OSD id";
+      } else {
+       osds.insert(id);
+      }
     }
     if (r < 0) {
       cmdctx->reply(r, ss);
@@ -1272,13 +1283,34 @@ bool DaemonServer::handle_command(MCommand *m)
         << " aren't still needed.";
       r = -EBUSY;
     }
+
+    if (r && prefix == "osd destroy") {
+      string sure;
+      if (!cmd_getval(cct, cmdctx->cmdmap, "sure", sure) ||
+         sure != "--force") {
+       ss << "\nYou can proceed with OSD removal by passing --force, but be warned that this will likely mean real, permanent data loss.";
+      } else {
+       r = 0;
+      }
+    }
     if (r) {
       cmdctx->reply(r, ss);
       return true;
     }
-    ss << "OSD(s) " << osds << " are safe to destroy without reducing data"
-       << " durability.";
-    cmdctx->reply(0, ss);
+    if (prefix == "osd destroy") {
+      const string cmd =
+       "{"
+       "\"prefix\": \"osd destroy-actual\", "
+       "\"id\": " + stringify(osds) + ", "
+       "\"sure\": \"--yes-i-really-mean-it\""
+       "}";
+      auto on_finish = new ReplyOnFinish(cmdctx);
+      monc->start_mon_command({cmd}, {}, nullptr, &on_finish->outs, on_finish);
+    } else {
+      ss << "OSD(s) " << osds << " are safe to destroy without reducing data"
+        << " durability.";
+      cmdctx->reply(0, ss);
+    }
     return true;
   } else if (prefix == "osd ok-to-stop") {
     vector<string> ids;
index 17a3671aa926c929176702bed74760f999808c0e..6d532237ed0bb81701a2a2f009795cfabd010a43 100644 (file)
@@ -107,6 +107,14 @@ COMMAND("osd test-reweight-by-pg " \
        "dry run of reweight OSDs by PG distribution [overload-percentage-for-consideration, default 120]", \
        "osd", "r", "cli,rest")
 
+COMMAND("osd destroy "     \
+        "name=id,type=CephOsdName " \
+        "name=sure,type=CephString,req=False",
+        "mark osd as being destroyed. Keeps the ID intact (allowing reuse), " \
+        "but removes cephx keys, config-key data and lockbox keys, "\
+        "rendering data permanently unreadable.", \
+        "osd", "rw", "cli,rest")
+
 COMMAND("osd safe-to-destroy name=ids,type=CephString,n=N",
        "check whether osd(s) can be safely destroyed without reducing data durability",
        "osd", "r", "cli,rest")
index cc484a3a820b640808083113cfb38d5629925f57..56626085ec267c21c6fefad71634264245c1de8a 100644 (file)
@@ -870,7 +870,7 @@ COMMAND("osd primary-affinity " \
        "type=CephFloat,name=weight,range=0.0|1.0", \
        "adjust osd primary-affinity from 0.0 <= <weight> <= 1.0", \
        "osd", "rw", "cli,rest")
-COMMAND("osd destroy " \
+COMMAND("osd destroy-actual "      \
         "name=id,type=CephOsdName " \
         "name=sure,type=CephChoices,strings=--yes-i-really-mean-it,req=false", \
         "mark osd as being destroyed. Keeps the ID intact (allowing reuse), " \
index 03d84df25f146e78148f05b65843240ef8a0bf1a..ff5dd5fbb9e0f333b510526f3393c947d71b1c1e 100644 (file)
@@ -10640,7 +10640,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
       return true;
     }
 
-  } else if (prefix == "osd destroy" ||
+  } else if (prefix == "osd destroy-actual" ||
             prefix == "osd purge" ||
             prefix == "osd purge-new") {
     /* Destroying an OSD means that we don't expect to further make use of
@@ -10665,13 +10665,18 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
 
     int64_t id;
     if (!cmd_getval(cct, cmdmap, "id", id)) {
-      ss << "unable to parse osd id value '"
-         << cmd_vartype_stringify(cmdmap.at("id")) << "";
+      auto p = cmdmap.find("id");
+      if (p == cmdmap.end()) {
+       ss << "no osd id specified";
+      } else {
+       ss << "unable to parse osd id value '"
+          << cmd_vartype_stringify(cmdmap.at("id")) << "";
+      }
       err = -EINVAL;
       goto reply;
     }
 
-    bool is_destroy = (prefix == "osd destroy");
+    bool is_destroy = (prefix == "osd destroy-actual");
     if (!is_destroy) {
       assert("osd purge" == prefix ||
             "osd purge-new" == prefix);