diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 2dfcd46d025b1..08b1721cc6590 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -71,6 +71,8 @@ libcommon_internal_la_SOURCES = \ common/TracepointProvider.cc \ common/PluginRegistry.cc +common/PluginRegistry.cc: ./ceph_ver.h + if ENABLE_SERVER libcommon_internal_la_SOURCES += \ common/xattr.c \ diff --git a/src/common/PluginRegistry.cc b/src/common/PluginRegistry.cc index dbf20fa302803..fb02d4a45a5da 100644 --- a/src/common/PluginRegistry.cc +++ b/src/common/PluginRegistry.cc @@ -29,7 +29,7 @@ #define PLUGIN_PREFIX "libceph_" #define PLUGIN_SUFFIX ".so" #define PLUGIN_INIT_FUNCTION "__ceph_plugin_init" -#define PLUGIN_VERSION_FUNCTION "__ceph_version" +#define PLUGIN_VERSION_FUNCTION "__ceph_plugin_version" #define dout_subsys ceph_subsys_context @@ -67,7 +67,7 @@ int PluginRegistry::remove(const std::string& type, const std::string& name) plugins.find(type); if (i == plugins.end()) return -ENOENT; - std::map::iterator j = i->second.find(type); + std::map::iterator j = i->second.find(name); if (j == i->second.end()) return -ENOENT; @@ -97,6 +97,19 @@ int PluginRegistry::add(const std::string& type, return 0; } +Plugin *PluginRegistry::get_with_load(const std::string& type, + const std::string& name) +{ + Mutex::Locker l(lock); + Plugin* ret = get(type, name); + if (!ret) { + int err = load(type, name); + if (err == 0) + ret = get(type, name); + } + return ret; +} + Plugin *PluginRegistry::get(const std::string& type, const std::string& name) { @@ -106,10 +119,10 @@ Plugin *PluginRegistry::get(const std::string& type, std::map::iterator j; std::map >::iterator i = plugins.find(type); - if (i == plugins.end()) + if (i == plugins.end()) goto out; - j = i->second.find(type); - if (j == i->second.end()) + j = i->second.find(name); + if (j == i->second.end()) goto out; ret = j->second; @@ -123,7 +136,7 @@ int PluginRegistry::load(const std::string &type, const std::string &name) { assert(lock.is_locked()); - ldout(cct, 10) << __func__ << " " << type << " " << name << dendl; + ldout(cct, 1) << __func__ << " " << type << " " << name << dendl; std::string fname = cct->_conf->plugin_dir + "/" + type + "/" PLUGIN_PREFIX + name + PLUGIN_SUFFIX; @@ -137,6 +150,7 @@ int PluginRegistry::load(const std::string &type, const char * (*code_version)() = (const char *(*)())dlsym(library, PLUGIN_VERSION_FUNCTION); if (code_version == NULL) { + lderr(cct) << __func__ << " code_version == NULL" << dlerror() << dendl; return -EXDEV; } if (code_version() != string(CEPH_GIT_NICE_VER)) { diff --git a/src/common/PluginRegistry.h b/src/common/PluginRegistry.h index b54fc6d3c1a1d..6757ce10a85f6 100644 --- a/src/common/PluginRegistry.h +++ b/src/common/PluginRegistry.h @@ -16,7 +16,7 @@ */ #ifndef CEPH_COMMON_PLUGINREGISTRY_H -#define CEPH_COMMON_PLUGINREGISTERY_H +#define CEPH_COMMON_PLUGINREGISTRY_H #include #include @@ -58,6 +58,7 @@ namespace ceph { Plugin *factory); int remove(const std::string& type, const std::string& name); Plugin *get(const std::string& type, const std::string& name); + Plugin *get_with_load(const std::string& type, const std::string& name); int load(const std::string& type, const std::string& name); diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 71a00eca674f7..b3f0c7ea47eaf 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -416,7 +416,7 @@ CephContext::CephContext(uint32_t module_type_, int init_flags_) _crypto_aes(NULL), _lockdep_obs(NULL), _cct_perf(NULL), - plugin_registry(NULL) + _plugin_registry(NULL) { ceph_spin_init(&_service_thread_lock); ceph_spin_init(&_associated_objs_lock); @@ -593,6 +593,11 @@ uint32_t CephContext::get_module_type() const return _module_type; } +int CephContext::get_init_flags() const +{ + return _init_flags; +} + PerfCountersCollection *CephContext::get_perfcounters_collection() { return _perf_counters_collection;