From b31e2aad13da2f7846394b2d029f91af12261039 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 5 Mar 2018 09:13:43 -0600 Subject: [PATCH] mon/ConfigMonitor: add 'config reset' command Signed-off-by: Sage Weil --- src/mon/ConfigMonitor.cc | 36 ++++++++++++++++++++++++++++++++++++ src/mon/MonCommands.h | 5 ++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/mon/ConfigMonitor.cc b/src/mon/ConfigMonitor.cc index 5772fdf06546..28c7e8dc59b9 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 90d5e2c2aae1..d6a47027fc76 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") -- 2.47.3