From: Gu Zhongyan Date: Tue, 3 Apr 2018 02:42:45 +0000 (+0800) Subject: mon,mgr: improve 'mgr module disable/enable' cmds X-Git-Tag: v13.1.0~148^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F21188%2Fhead;p=ceph.git mon,mgr: improve 'mgr module disable/enable' cmds 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 --- diff --git a/src/mon/MgrMap.h b/src/mon/MgrMap.h index 98d9b331dc9..865e6a5841d 100644 --- a/src/mon/MgrMap.h +++ b/src/mon/MgrMap.h @@ -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; diff --git a/src/mon/MgrMonitor.cc b/src/mon/MgrMonitor.cc index 28861e31350..084f0a9dad5 100644 --- a/src/mon/MgrMonitor.cc +++ b/src/mon/MgrMonitor.cc @@ -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!";