From: Sage Weil Date: Mon, 5 Mar 2018 15:13:43 +0000 (-0600) Subject: mon/ConfigMonitor: add 'config reset' command X-Git-Tag: v13.1.0~385^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b31e2aad13da2f7846394b2d029f91af12261039;p=ceph.git mon/ConfigMonitor: add 'config reset' command Signed-off-by: Sage Weil --- diff --git a/src/mon/ConfigMonitor.cc b/src/mon/ConfigMonitor.cc index 5772fdf065466..28c7e8dc59b92 100644 --- a/src/mon/ConfigMonitor.cc +++ b/src/mon/ConfigMonitor.cc @@ -1,6 +1,8 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab +#include + #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 errors; diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 90d5e2c2aae18..d6a47027fc767 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -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")