Skip to content

Commit

Permalink
common: PluginRegistry modification
Browse files Browse the repository at this point in the history
  • Loading branch information
Ved-vampir committed Dec 2, 2015
1 parent 5eb64dd commit dc2b176
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
26 changes: 20 additions & 6 deletions src/common/PluginRegistry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion src/common/PluginRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

#ifndef CEPH_COMMON_PLUGINREGISTRY_H
#define CEPH_COMMON_PLUGINREGISTERY_H
#define CEPH_COMMON_PLUGINREGISTRY_H

#include <string>
#include <map>
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/common/ceph_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dc2b176

Please sign in to comment.