From: Sage Weil Date: Sun, 23 May 2021 14:47:35 +0000 (-0400) Subject: mon/MonCommands: convert some CephChoices to CephBool X-Git-Tag: v17.1.0~1726^2~8 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=bd242c4997cd934c8f11022ec362d143c314e4fa;p=ceph.git mon/MonCommands: convert some CephChoices to CephBool These are old bool options that never got converted to CephBool. Signed-off-by: Sage Weil --- diff --git a/src/common/cmdparse.cc b/src/common/cmdparse.cc index 03f634123eb16..9b296f8fbf4e0 100644 --- a/src/common/cmdparse.cc +++ b/src/common/cmdparse.cc @@ -682,4 +682,23 @@ bool cmd_getval(const cmdmap_t& cmdmap, return false; } +bool cmd_getval_compat_cephbool( + const cmdmap_t& cmdmap, + const std::string& k, bool& val) +{ + try { + return cmd_getval(cmdmap, k, val); + } catch (bad_cmd_get& e) { + // try as legacy/compat CephChoices + std::string t; + if (!cmd_getval(cmdmap, k, t)) { + return false; + } + std::string expected = "--"s + k; + std::replace(expected.begin(), expected.end(), '_', '-'); + val = (t == expected); + return true; + } +} + } diff --git a/src/common/cmdparse.h b/src/common/cmdparse.h index 112c249305321..4d5160d3333b2 100644 --- a/src/common/cmdparse.h +++ b/src/common/cmdparse.h @@ -59,6 +59,10 @@ struct bad_cmd_get : public std::exception { bool cmd_getval(const cmdmap_t& cmdmap, const std::string& k, bool& val); +bool cmd_getval_compat_cephbool( + const cmdmap_t& cmdmap, + const std::string& k, bool& val); + template bool cmd_getval(const cmdmap_t& cmdmap, const std::string& k, T& val) diff --git a/src/mon/MgrMonitor.cc b/src/mon/MgrMonitor.cc index 4c9cfb6efd9db..f3647ca29c5d1 100644 --- a/src/mon/MgrMonitor.cc +++ b/src/mon/MgrMonitor.cc @@ -1186,10 +1186,10 @@ bool MgrMonitor::prepare_command(MonOpRequestRef op) ss << "module '" << module << "' is already enabled (always-on)"; goto out; } - string force; - cmd_getval(cmdmap, "force", force); + bool force = false; + cmd_getval_compat_cephbool(cmdmap, "force", force); if (!pending_map.all_support_module(module) && - force != "--force") { + !force) { ss << "all mgr daemons do not support module '" << module << "', pass " << "--force to force enablement"; r = -ENOENT; @@ -1197,7 +1197,7 @@ bool MgrMonitor::prepare_command(MonOpRequestRef op) } std::string can_run_error; - if (force != "--force" && !pending_map.can_run_module(module, &can_run_error)) { + if (!force && !pending_map.can_run_module(module, &can_run_error)) { ss << "module '" << module << "' reports that it cannot run on the active " "manager daemon: " << can_run_error << " (pass --force to force " "enablement)"; diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index e10a4129f085b..2ca0d0e8f1c40 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -474,7 +474,7 @@ COMMAND_WITH_FLAG("mon remove " "remove monitor named ", "mon", "rw", FLAG(DEPRECATED)) COMMAND("mon feature ls " - "name=with_value,type=CephChoices,strings=--with-value,req=false", + "name=with_value,type=CephBool,req=false", "list available mon map features to be set/unset", "mon", "r") COMMAND("mon feature set " @@ -750,7 +750,7 @@ COMMAND("osd crush rule rename " "rename crush rule to ", "osd", "rw") COMMAND("osd crush tree " - "name=shadow,type=CephChoices,strings=--show-shadow,req=false", + "name=show_shadow,type=CephBool,req=false", "dump crush buckets and items in a tree view", "osd", "r") COMMAND("osd crush ls name=node,type=CephString,goodchars=[A-Za-z0-9-_.]", @@ -1166,7 +1166,7 @@ COMMAND("osd force_recovery_stretch_mode " \ COMMAND("osd tier add " "name=pool,type=CephPoolname " "name=tierpool,type=CephPoolname " - "name=force_nonempty,type=CephChoices,strings=--force-nonempty,req=false", + "name=force_nonempty,type=CephBool,req=false", "add the tier (the second one) to base pool (the first one)", "osd", "rw") COMMAND("osd tier rm " @@ -1256,7 +1256,7 @@ COMMAND("mgr services", "mgr", "r") COMMAND("mgr module enable " "name=module,type=CephString " - "name=force,type=CephChoices,strings=--force,req=false", + "name=force,type=CephBool,req=false", "enable mgr module", "mgr", "rw") COMMAND("mgr module disable " "name=module,type=CephString", @@ -1352,7 +1352,7 @@ COMMAND_WITH_FLAG("connection scores reset", "mon", "rwx", FLAG(TELL)) COMMAND_WITH_FLAG("sync_force " - "name=validate,type=CephChoices,strings=--yes-i-really-mean-it,req=false", + "name=yes_i_really_mean_it,type=CephBool,req=false", "force sync of and clear monitor store", "mon", "rw", FLAG(TELL)) diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 5f02325bb089d..e0fb3786e879d 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -337,9 +337,15 @@ int Monitor::do_admin_command( } else if (command == "quorum_status") { _quorum_status(f, out); } else if (command == "sync_force") { - string validate; - if ((!cmd_getval(cmdmap, "validate", validate)) || - (validate != "--yes-i-really-mean-it")) { + bool validate = false; + if (!cmd_getval(cmdmap, "yes_i_really_mean_it", validate)) { + std::string v; + if (cmd_getval(cmdmap, "validate", v) && + v == "--yes-i-really-mean-it") { + validate = true; + } + } + if (!validate) { err << "are you SURE? this will mean the monitor store will be erased " "the next time the monitor is restarted. pass " "'--yes-i-really-mean-it' if you really do."; diff --git a/src/mon/MonmapMonitor.cc b/src/mon/MonmapMonitor.cc index daeb4b572fd7b..4fd3a94cf7749 100644 --- a/src/mon/MonmapMonitor.cc +++ b/src/mon/MonmapMonitor.cc @@ -397,11 +397,7 @@ bool MonmapMonitor::preprocess_command(MonOpRequestRef op) } else if (prefix == "mon feature ls") { bool list_with_value = false; - string with_value; - if (cmd_getval(cmdmap, "with_value", with_value) && - with_value == "--with-value") { - list_with_value = true; - } + cmd_getval_compat_cephbool(cmdmap, "with_value", list_with_value); MonMap *p = mon.monmap; diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 7e8c3450bc60a..d04a8f28d0573 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -6656,9 +6656,14 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) rs << "\n"; rdata.append(rs.str()); } else if (prefix == "osd crush tree") { - string shadow; - cmd_getval(cmdmap, "shadow", shadow); - bool show_shadow = shadow == "--show-shadow"; + bool show_shadow = false; + if (!cmd_getval_compat_cephbool(cmdmap, "show_shadow", show_shadow)) { + std::string shadow; + if (cmd_getval(cmdmap, "shadow", shadow) && + shadow == "--show-shadow") { + show_shadow = true; + } + } boost::scoped_ptr f(Formatter::create(format)); if (f) { f->open_object_section("crush_tree"); @@ -12961,11 +12966,11 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, } // make sure new tier is empty - string force_nonempty; - cmd_getval(cmdmap, "force_nonempty", force_nonempty); + bool force_nonempty = false; + cmd_getval_compat_cephbool(cmdmap, "force_nonempty", force_nonempty); const pool_stat_t *pstats = mon.mgrstatmon()->get_pool_stat(tierpool_id); if (pstats && pstats->stats.sum.num_objects != 0 && - force_nonempty != "--force-nonempty") { + !force_nonempty) { ss << "tier pool '" << tierpoolstr << "' is not empty; --force-nonempty to force"; err = -ENOTEMPTY; goto reply; @@ -12977,8 +12982,8 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, goto reply; } if ((!tp->removed_snaps.empty() || !tp->snaps.empty()) && - ((force_nonempty != "--force-nonempty") || - (!g_conf()->mon_debug_unsafe_allow_tier_with_nonempty_snaps))) { + (!force_nonempty || + !g_conf()->mon_debug_unsafe_allow_tier_with_nonempty_snaps)) { ss << "tier pool '" << tierpoolstr << "' has snapshot state; it cannot be added as a tier without breaking the pool"; err = -ENOTEMPTY; goto reply;