From 1bc9c86d08cfb408768c080ed5ea1ea82325ed57 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Thu, 21 Mar 2019 17:14:27 +0800 Subject: [PATCH] mon/ConfigMonitor: make 'num' of 'config reset' command optional This way it can be used to fast cancel/undo the last command. Also make the tip message a litter bit nicer.. Signed-off-by: xie xingguo --- qa/workunits/mon/config.sh | 16 ++++++++++++++++ src/mon/ConfigMonitor.cc | 25 ++++++++++++------------- src/mon/MonCommands.h | 7 ++++--- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/qa/workunits/mon/config.sh b/qa/workunits/mon/config.sh index 29d22f9329a..98d4e85aea6 100755 --- a/qa/workunits/mon/config.sh +++ b/qa/workunits/mon/config.sh @@ -6,6 +6,19 @@ function expect_false() if "$@"; then return 1; else return 0; fi } +# some of the commands are just not idempotent. +function without_test_dup_command() +{ + if [ -z ${CEPH_CLI_TEST_DUP_COMMAND+x} ]; then + $@ + else + local saved=${CEPH_CLI_TEST_DUP_COMMAND} + unset CEPH_CLI_TEST_DUP_COMMAND + $@ + CEPH_CLI_TEST_DUP_COMMAND=saved + fi +} + ceph config dump # value validation @@ -51,6 +64,9 @@ ceph config get mon.a debug_asok | grep 11 ceph config rm mon debug_asok ceph config get mon.a debug_asok | grep 33 ceph config rm global debug_asok +without_test_dup_command ceph config reset +ceph config get mon.a debug_asok | grep 33 +without_test_dup_command ceph config reset # help ceph config help debug_asok | grep debug_asok diff --git a/src/mon/ConfigMonitor.cc b/src/mon/ConfigMonitor.cc index d550af8fe1e..6be226ed14c 100644 --- a/src/mon/ConfigMonitor.cc +++ b/src/mon/ConfigMonitor.cc @@ -524,24 +524,23 @@ bool ConfigMonitor::prepare_command(MonOpRequestRef op) } 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)) { + int64_t num = -1; + cmd_getval(g_ceph_context, cmdmap, "num", num); + int64_t revert_to = num; + if (revert_to < 0) // revert to last version + revert_to = version - 1; + if (revert_to > (int64_t)version) { err = -EINVAL; - ss << "must specify a valid version to revert to"; + ss << "must specify a valid historical version to revert to; " + << "see 'ceph config log' for a list of avialable configuration " + << "historical versions"; goto reply; } - if (num == (int64_t)version) { + if (revert_to == (int64_t)version) { err = 0; goto reply; } - ceph_assert((version_t)num < version); - for (int64_t v = version; v > num; --v) { + for (int64_t v = version; v > revert_to; --v) { ConfigChangeSet ch; load_changeset(v, &ch); for (auto& i : ch.diff) { @@ -554,7 +553,7 @@ bool ConfigMonitor::prepare_command(MonOpRequestRef op) } } } - pending_description = string("reset to ") + stringify(num); + pending_description = string("reset to ") + stringify(revert_to); goto update; } else if (prefix == "config assimilate-conf") { ConfFile cf; diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 14962cf9cd1..7c09aeca98e 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -1192,9 +1192,10 @@ COMMAND("config assimilate-conf", COMMAND("config log name=num,type=CephInt,req=False", "Show recent history of config changes", "config", "r") -COMMAND("config reset" \ - " name=num,type=CephInt", - "Revert configuration to previous state", +COMMAND("config reset " \ + "name=num,type=CephInt,range=0,req=False", + "Revert configuration to a historical version specified by , " + "or simply revert to last version", "config", "rw") COMMAND("config generate-minimal-conf", "Generate a minimal ceph.conf file", -- 2.39.5