]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: PluginRegistry modification 6696/head
authorVed-vampir <akiselyova@mirantis.com>
Wed, 25 Nov 2015 08:05:24 +0000 (11:05 +0300)
committerVed-vampir <akiselyova@mirantis.com>
Wed, 2 Dec 2015 11:00:52 +0000 (14:00 +0300)
src/common/Makefile.am
src/common/PluginRegistry.cc
src/common/PluginRegistry.h
src/common/ceph_context.cc

index 2dfcd46d025b1cc58aca4a0f41340ed8a405ea65..08b1721cc659022070ed81eb1ee3478a706b6874 100644 (file)
@@ -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 \
index dbf20fa302803c79c64628e09fde4b5163d0316a..fb02d4a45a5da851328ebbaf95ed946ee084085d 100644 (file)
@@ -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<std::string,Plugin*>::iterator j = i->second.find(type);
+  std::map<std::string,Plugin*>::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<std::string,Plugin*>::iterator j;
   std::map<std::string,map<std::string,Plugin*> >::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)) {
index b54fc6d3c1a1d12b7d65adf1ca594e31304c921b..6757ce10a85f61466bb3adfee880401b5cb092a6 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef CEPH_COMMON_PLUGINREGISTRY_H
-#define CEPH_COMMON_PLUGINREGISTERY_H
+#define CEPH_COMMON_PLUGINREGISTRY_H
 
 #include <string>
 #include <map>
@@ -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);
index 71a00eca674f7b79fee29f7f14d444f6bc6bfa99..b3f0c7ea47eaf51d7516efe8986282dec936c5cb 100644 (file)
@@ -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;