diff --git a/src/mgr/MgrStandby.cc b/src/mgr/MgrStandby.cc index 335e134141abd..8aaaefccfbf5b 100644 --- a/src/mgr/MgrStandby.cc +++ b/src/mgr/MgrStandby.cc @@ -152,8 +152,7 @@ void MgrStandby::send_beacon() assert(lock.is_locked_by_me()); dout(1) << state_str() << dendl; - std::list modules; - py_module_registry.get_modules(&modules); + std::list modules = py_module_registry.get_modules(); // Construct a list of the info about each loaded module // which we will transmit to the monitor. diff --git a/src/mgr/PyModuleRegistry.cc b/src/mgr/PyModuleRegistry.cc index 9a8b2684931c4..76ad1577075fa 100644 --- a/src/mgr/PyModuleRegistry.cc +++ b/src/mgr/PyModuleRegistry.cc @@ -69,8 +69,7 @@ int PyModuleRegistry::init(const MgrMap &map) std::list failed_modules; - std::set module_names; - list_modules(&module_names); + std::set module_names = probe_modules(); // Load python code for (const auto& module_name : module_names) { dout(1) << "Loading python module '" << module_name << "'" << dendl; @@ -221,14 +220,16 @@ void PyModuleRegistry::shutdown() Py_Finalize(); } -static void _list_modules( - const std::string path, - std::set *modules) +std::set PyModuleRegistry::probe_modules() const { + std::string path = g_conf->get_val("mgr_module_path"); + DIR *dir = opendir(path.c_str()); if (!dir) { - return; + return {}; } + + std::set modules_out; struct dirent *entry = NULL; while ((entry = readdir(dir)) != NULL) { string n(entry->d_name); @@ -239,17 +240,13 @@ static void _list_modules( string initfn = fn + "/module.py"; r = ::stat(initfn.c_str(), &st); if (r == 0) { - modules->insert(n); + modules_out.insert(n); } } } closedir(dir); -} -void PyModuleRegistry::list_modules(std::set *modules) -{ - g_conf->with_val("mgr_module_path", - &_list_modules, modules); + return modules_out; } int PyModuleRegistry::handle_command( diff --git a/src/mgr/PyModuleRegistry.h b/src/mgr/PyModuleRegistry.h index 1064c19b15137..1f5a910d04670 100644 --- a/src/mgr/PyModuleRegistry.h +++ b/src/mgr/PyModuleRegistry.h @@ -54,17 +54,27 @@ class PyModuleRegistry // before ClusterState exists. MgrMap mgr_map; + /** + * Discover python modules from local disk + */ + std::set probe_modules() const; + public: static std::string config_prefix; - void list_modules(std::set *modules); - - void get_modules(std::list *modules_out) + /** + * Get references to all modules (whether they have loaded and/or + * errored) or not. + */ + std::list get_modules() const { Mutex::Locker l(lock); + std::list modules_out; for (const auto &i : modules) { - modules_out->push_back(i.second); + modules_out.push_back(i.second); } + + return modules_out; } PyModuleRegistry(LogChannelRef clog_)