From: John Spray Date: Mon, 23 Apr 2018 21:15:22 +0000 (-0400) Subject: mgr: handle commands sent to unavailable modules X-Git-Tag: v13.1.0~132^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=b1e8d63bf787dea415eabda99def9d7e4aff4f9d;p=ceph.git mgr: handle commands sent to unavailable modules There are some up-front checks in DaemonServer but it shouldn't assume that its checks are necessarily going to match the choices about how ActivePyModules composes its ::modules member, so let's have some extra checks to avoid risk of crashing mgr on commands sent to unhealthy/unloaded modules. Signed-off-by: John Spray --- diff --git a/src/mgr/ActivePyModule.cc b/src/mgr/ActivePyModule.cc index 185ef44542884..2f52dd622620a 100644 --- a/src/mgr/ActivePyModule.cc +++ b/src/mgr/ActivePyModule.cc @@ -110,6 +110,13 @@ int ActivePyModule::handle_command( assert(ss != nullptr); assert(ds != nullptr); + if (pClassInstance == nullptr) { + // Not the friendliest error string, but we could only + // hit this in quite niche cases, if at all. + *ss << "Module not instantiated"; + return -EINVAL; + } + Gil gil(py_module->pMyThreadState, true); PyFormatter f; diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index cc604d175a9eb..4cb8a0883a9e2 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -756,9 +756,14 @@ int ActivePyModules::handle_command( std::stringstream *ss) { lock.Lock(); - auto mod = modules.at(module_name).get(); + auto mod_iter = modules.find(module_name); + if (mod_iter == modules.end()) { + *ss << "Module '" << module_name << "' is not available"; + return -ENOENT; + } + lock.Unlock(); - return mod->handle_command(cmdmap, ds, ss); + return mod_iter->second->handle_command(cmdmap, ds, ss); } void ActivePyModules::get_health_checks(health_check_map_t *checks)