]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonCommands: convert some CephChoices to CephBool
authorSage Weil <sage@newdream.net>
Sun, 23 May 2021 14:47:35 +0000 (10:47 -0400)
committerSage Weil <sage@newdream.net>
Fri, 4 Jun 2021 20:56:17 +0000 (16:56 -0400)
These are old bool options that never got converted to CephBool.

Signed-off-by: Sage Weil <sage@newdream.net>
src/common/cmdparse.cc
src/common/cmdparse.h
src/mon/MgrMonitor.cc
src/mon/MonCommands.h
src/mon/Monitor.cc
src/mon/MonmapMonitor.cc
src/mon/OSDMonitor.cc

index 03f634123eb1683e423cea7f6f81ee9c2c028a5f..9b296f8fbf4e050c95b742f94b6c55085011b52a 100644 (file)
@@ -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;
+  }
+}
+
 }
index 112c24930532188ca35c5f62c9bf4a793f791cb4..4d5160d3333b24bbb656421cfdcef80157017e5b 100644 (file)
@@ -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 <typename T>
 bool cmd_getval(const cmdmap_t& cmdmap,
                const std::string& k, T& val)
index 4c9cfb6efd9db46532688a853d54be2dd9654d7d..f3647ca29c5d11ed562b259dda7ba8134744869a 100644 (file)
@@ -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)";
index e10a4129f085b8373cbaa24d3ef304ac5efe4c21..2ca0d0e8f1c405c4d35444f4214b18aa1ab4178c 100644 (file)
@@ -474,7 +474,7 @@ COMMAND_WITH_FLAG("mon remove "
        "remove monitor named <name>", "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 <srcname> to <dstname>",
         "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 <tierpool> (the second one) to base pool <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))
index 5f02325bb089d64c60a678c27317546564c00ad2..e0fb3786e879d392aad6f904140ac52f9ab14882 100644 (file)
@@ -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.";
index daeb4b572fd7b84fd77ca4a89308012364cedb33..4fd3a94cf77495696b85d2916e459877239e4aec 100644 (file)
@@ -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;
 
index 7e8c3450bc60adabb970799889c89f150f12cfb4..d04a8f28d0573578dad665b3a8df24c4b6875eec 100644 (file)
@@ -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<Formatter> 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;