From a7677c76a54bdbc68ea9ba60efe7cec013d5afda Mon Sep 17 00:00:00 2001 From: Gu Zhongyan Date: Tue, 3 Apr 2018 10:42:45 +0800 Subject: [PATCH] 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 --- src/mon/MgrMap.h | 17 +++++++++++++++++ src/mon/MgrMonitor.cc | 13 +++++++++++++ 2 files changed, 30 insertions(+) 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!"; -- 2.47.3