#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
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;
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)
{
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;
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;
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)) {
*/
#ifndef CEPH_COMMON_PLUGINREGISTRY_H
-#define CEPH_COMMON_PLUGINREGISTERY_H
+#define CEPH_COMMON_PLUGINREGISTRY_H
#include <string>
#include <map>
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);