]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/ConfigMonitor: add 'config reset' command 20760/head
authorSage Weil <sage@redhat.com>
Mon, 5 Mar 2018 15:13:43 +0000 (09:13 -0600)
committerSage Weil <sage@redhat.com>
Sat, 17 Mar 2018 16:09:04 +0000 (11:09 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/ConfigMonitor.cc
src/mon/MonCommands.h

index 5772fdf06546650512672bd06f57169bf17cea83..28c7e8dc59b92556c4312acc8b5f427125602776 100644 (file)
@@ -1,6 +1,8 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 
+#include <boost/algorithm/string/predicate.hpp>
+
 #include "mon/Monitor.h"
 #include "mon/ConfigMonitor.h"
 #include "mon/OSDMonitor.h"
@@ -439,6 +441,40 @@ bool ConfigMonitor::prepare_command(MonOpRequestRef op)
       pending[key] = boost::none;
     }
     goto update;
+  } else if (prefix == "config reset") {
+    int64_t num;
+    if (!cmd_getval(g_ceph_context, cmdmap, "num", num)) {
+      err = -EINVAL;
+      ss << "must specify what to revert to";
+      goto reply;
+    }
+    if (num < 0 ||
+       (num > 0 && num > (int64_t)version)) {
+      err = -EINVAL;
+      ss << "must specify a valid version to revert to";
+      goto reply;
+    }
+    if (num == (int64_t)version) {
+      err = 0;
+      goto reply;
+    }
+    assert(num > 0);
+    assert((version_t)num < version);
+    for (int64_t v = version; v > num; --v) {
+      ConfigChangeSet ch;
+      load_changeset(v, &ch);
+      for (auto& i : ch.diff) {
+       if (i.second.first) {
+         bufferlist bl;
+         bl.append(*i.second.first);
+         pending[i.first] = bl;
+       } else if (i.second.second) {
+         pending[i.first] = boost::none;
+       }
+      }
+    }
+    pending_description = string("reset to ") + stringify(num);
+    goto update;
   } else if (prefix == "config assimilate-conf") {
     ConfFile cf;
     deque<string> errors;
index 90d5e2c2aae18458fa269ae2681b3ac558130493..d6a47027fc767361b180d1d183878c4341c2bcc8 100644 (file)
@@ -1120,4 +1120,7 @@ COMMAND("config assimilate-conf",
 COMMAND("config log name=num,type=CephInt,req=False",
        "Show recent history of config changes",
        "config", "r", "cli,rest")
-
+COMMAND("config reset" \
+       " name=num,type=CephInt",
+       "Revert configuration to previous state",
+       "config", "rw", "cli,rest")