]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon,mgr: improve 'mgr module disable/enable' cmds 21188/head
authorGu Zhongyan <guzhongyan@360.cn>
Tue, 3 Apr 2018 02:42:45 +0000 (10:42 +0800)
committerGu Zhongyan <guzhongyan@360.cn>
Mon, 23 Apr 2018 01:35:06 +0000 (09:35 +0800)
when running those cmds, check if the module do exist
or is disabled already.
also check if the module is enabled already.

Signed-off-by: Gu Zhongyan <guzhongyan@360.cn>
src/mon/MgrMap.h
src/mon/MgrMonitor.cc

index 98d9b331dc96456624ca6b1d2ac155cda4bff341..865e6a5841d1b3916dc3d5efe84a4e21c232b02b 100644 (file)
@@ -193,6 +193,23 @@ public:
     throw std::logic_error(oss.str());
   }
 
+  bool module_enabled(const std::string& module_name) const
+  {
+    return modules.find(module_name) != modules.end();
+  }
+
+  bool any_supports_module(const std::string& module) const {
+    if (have_module(module)) {
+      return true;
+    }
+    for (auto& p : standbys) {
+      if (p.second.have_module(module)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   bool have_name(const string& name) const {
     if (active_name == name) {
       return true;
index 28861e313508f56c079266f15acd0e37aeed1f0d..084f0a9dad546a9f72696b6ff100bb4ef2c903ad 100644 (file)
@@ -897,6 +897,11 @@ bool MgrMonitor::prepare_command(MonOpRequestRef op)
       goto out;
     }
 
+    if (pending_map.module_enabled(module)) {
+      ss << "module '" << module << "' is already enabled";
+      r = 0;
+      goto out;
+    }
     pending_map.modules.insert(module);
   } else if (prefix == "mgr module disable") {
     string module;
@@ -905,6 +910,14 @@ bool MgrMonitor::prepare_command(MonOpRequestRef op)
       r = -EINVAL;
       goto out;
     }
+    if (!pending_map.module_enabled(module)) {
+      ss << "module '" << module << "' is already disabled";
+      r = 0;
+      goto out;
+    }
+    if (!pending_map.any_supports_module(module)) {
+      ss << "module '" << module << "' does not exist";
+    }
     pending_map.modules.erase(module);
   } else {
     ss << "Command '" << prefix << "' not implemented!";