Skip to content

Commit

Permalink
erasure-code: add directory to plugin init functions
Browse files Browse the repository at this point in the history
The prototype of the init functions of erasure coded plugins is changed
from

   int __erasure_code_init(char *plugin_name)

to

   int __erasure_code_init(char *plugin_name, char *directory)

The jerasure plugin will find optimized variants in this directory and
load them. The load() and preload() functions of
ErasureCodePluginRegistry only use a directory instead of a more generic
parameters map. The parameters map was only used for the directory entry
anyway.

Signed-off-by: Loic Dachary <[email protected]>
  • Loading branch information
Loic Dachary committed Aug 28, 2014
1 parent 39bcb43 commit 487105d
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion doc/dev/osd_internals/erasure_coding/developer_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ key=value pairs stored in an `erasure code profile`_.
$ ceph osd pool create ecpool 12 12 erasure myprofile

The *plugin* is dynamically loaded from *directory* and expected to
implement the *int __erasure_code_init(char *plugin_name)* function
implement the *int __erasure_code_init(char *plugin_name, char *directory)* function
which is responsible for registering an object derived from *ErasureCodePlugin*
in the registry. The `ErasureCodePluginExample <https://github.com/ceph/ceph/blob/v0.78/src/test/erasure-code/ErasureCodePluginExample.cc>`_ plugin reads:

Expand Down
20 changes: 9 additions & 11 deletions src/erasure-code/ErasureCodePlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ int ErasureCodePluginRegistry::factory(const std::string &plugin_name,
plugin = get(plugin_name);
if (plugin == 0) {
loading = true;
r = load(plugin_name, parameters, &plugin, ss);
assert(parameters.count("directory") != 0);
r = load(plugin_name, parameters.find("directory")->second, &plugin, ss);
loading = false;
if (r != 0)
return r;
Expand All @@ -89,27 +90,26 @@ int ErasureCodePluginRegistry::factory(const std::string &plugin_name,
}

int ErasureCodePluginRegistry::load(const std::string &plugin_name,
const map<std::string,std::string> &parameters,
const std::string &directory,
ErasureCodePlugin **plugin,
ostream &ss)
{
assert(parameters.count("directory") != 0);
std::string fname = parameters.find("directory")->second
+ "/" PLUGIN_PREFIX
std::string fname = directory + "/" PLUGIN_PREFIX
+ plugin_name + PLUGIN_SUFFIX;
void *library = dlopen(fname.c_str(), RTLD_NOW);
if (!library) {
ss << "load dlopen(" << fname << "): " << dlerror();
return -EIO;
}

int (*erasure_code_init)(const char *) =
(int (*)(const char *))dlsym(library, PLUGIN_INIT_FUNCTION);
int (*erasure_code_init)(const char *, const char *) =
(int (*)(const char *, const char *))dlsym(library, PLUGIN_INIT_FUNCTION);
if (erasure_code_init) {
std::string name = plugin_name;
int r = erasure_code_init(name.c_str());
int r = erasure_code_init(name.c_str(), directory.c_str());
if (r != 0) {
ss << "erasure_code_init(" << plugin_name
<< "," << directory
<< "): " << cpp_strerror(r);
dlclose(library);
return r;
Expand Down Expand Up @@ -141,15 +141,13 @@ int ErasureCodePluginRegistry::preload(const std::string &plugins,
const std::string &directory,
ostream &ss)
{
map<string,string> profile;
profile["directory"] = directory;
list<string> plugins_list;
get_str_list(plugins, plugins_list);
for (list<string>::iterator i = plugins_list.begin();
i != plugins_list.end();
i++) {
ErasureCodePlugin *plugin;
int r = load(*i, profile, &plugin, ss);
int r = load(*i, directory, &plugin, ss);
if (r)
return r;
}
Expand Down
4 changes: 2 additions & 2 deletions src/erasure-code/ErasureCodePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "ErasureCodeInterface.h"

extern "C" {
int __erasure_code_init(char *plugin_name);
int __erasure_code_init(char *plugin_name, char *directory);
}

namespace ceph {
Expand Down Expand Up @@ -64,7 +64,7 @@ namespace ceph {
ErasureCodePlugin *get(const std::string &name);

int load(const std::string &plugin_name,
const map<std::string,std::string> &parameters,
const std::string &directory,
ErasureCodePlugin **plugin,
ostream &ss);

Expand Down
2 changes: 1 addition & 1 deletion src/erasure-code/isa/ErasureCodePluginIsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ErasureCodePluginIsa : public ErasureCodePlugin {

// -----------------------------------------------------------------------------

int __erasure_code_init(char *plugin_name)
int __erasure_code_init(char *plugin_name, char *directory)
{
ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
return instance.add(plugin_name, new ErasureCodePluginIsa());
Expand Down
2 changes: 1 addition & 1 deletion src/erasure-code/jerasure/ErasureCodePluginJerasure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extern gf_t *gfp_array[];
extern int gfp_is_composite[];
}

int __erasure_code_init(char *plugin_name)
int __erasure_code_init(char *plugin_name, char *directory)
{
ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
int w[] = { 4, 8, 16, 32 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ErasureCodePluginSelectJerasure : public ErasureCodePlugin {
}
};

int __erasure_code_init(char *plugin_name)
int __erasure_code_init(char *plugin_name, char *directory)
{
ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
return instance.add(plugin_name, new ErasureCodePluginSelectJerasure());
Expand Down
2 changes: 1 addition & 1 deletion src/test/erasure-code/ErasureCodePluginExample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ErasureCodePluginExample : public ErasureCodePlugin {
}
};

int __erasure_code_init(char *plugin_name)
int __erasure_code_init(char *plugin_name, char *directory)
{
ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
return instance.add(plugin_name, new ErasureCodePluginExample());
Expand Down
2 changes: 1 addition & 1 deletion src/test/erasure-code/ErasureCodePluginFailToInitialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <errno.h>
#include "erasure-code/ErasureCodePlugin.h"

int __erasure_code_init(char *plugin_name)
int __erasure_code_init(char *plugin_name, char *directory)
{
return -ESRCH;
}
2 changes: 1 addition & 1 deletion src/test/erasure-code/ErasureCodePluginFailToRegister.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "erasure-code/ErasureCodePlugin.h"

int __erasure_code_init(char *plugin_name)
int __erasure_code_init(char *plugin_name, char *directory)
{
return 0;
}
2 changes: 1 addition & 1 deletion src/test/erasure-code/ErasureCodePluginHangs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <unistd.h>
#include "erasure-code/ErasureCodePlugin.h"

int __erasure_code_init(char *plugin_name)
int __erasure_code_init(char *plugin_name, char *directory)
{
sleep(1000);
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// missing int __erasure_code_init(char *plugin_name) {}
// missing int __erasure_code_init(char *plugin_name, char *directory) {}

// avoid warnings about library containing no symbols
int __this_is_an_used_variable_to_avoid_warnings;
5 changes: 3 additions & 2 deletions src/test/erasure-code/TestErasureCodePlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ TEST_F(ErasureCodePluginRegistryTest, factory_mutex) {
TEST_F(ErasureCodePluginRegistryTest, all)
{
map<std::string,std::string> parameters;
parameters["directory"] = ".libs";
string directory(".libs");
parameters["directory"] = directory;
ErasureCodeInterfaceRef erasure_code;
ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
stringstream ss;
Expand All @@ -91,7 +92,7 @@ TEST_F(ErasureCodePluginRegistryTest, all)
EXPECT_EQ(0, instance.factory("example", parameters, &erasure_code, ss));
EXPECT_TRUE(erasure_code);
ErasureCodePlugin *plugin = 0;
EXPECT_EQ(-EEXIST, instance.load("example", parameters, &plugin, ss));
EXPECT_EQ(-EEXIST, instance.load("example", directory, &plugin, ss));
}

int main(int argc, char **argv) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/erasure-code/TestJerasurePluginGeneric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <errno.h>
#include "erasure-code/ErasureCodePlugin.h"

int __erasure_code_init(char *plugin_name)
int __erasure_code_init(char *plugin_name, char *directory)
{
return -111;
}
2 changes: 1 addition & 1 deletion src/test/erasure-code/TestJerasurePluginSSE3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <errno.h>
#include "erasure-code/ErasureCodePlugin.h"

int __erasure_code_init(char *plugin_name)
int __erasure_code_init(char *plugin_name, char *directory)
{
return -333;
}
2 changes: 1 addition & 1 deletion src/test/erasure-code/TestJerasurePluginSSE4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <errno.h>
#include "erasure-code/ErasureCodePlugin.h"

int __erasure_code_init(char *plugin_name)
int __erasure_code_init(char *plugin_name, char *directory)
{
return -444;
}

0 comments on commit 487105d

Please sign in to comment.