From de62572c61a70785a93071b66e02cd136473ff42 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Sun, 16 Mar 2014 12:14:30 +0100 Subject: [PATCH] erasure-code: remove dependency to the global context Instead of relying on derr to display error messages, add them to an ostream parameter given in argument to load() and factory(). The erasure code convenience library no longer depends on the global context that is indirectly referenced by debug.h Signed-off-by: Loic Dachary --- src/erasure-code/ErasureCodePlugin.cc | 39 ++++++++++----------------- src/erasure-code/ErasureCodePlugin.h | 6 +++-- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/erasure-code/ErasureCodePlugin.cc b/src/erasure-code/ErasureCodePlugin.cc index 786808f12f298..a76d6140ccab9 100644 --- a/src/erasure-code/ErasureCodePlugin.cc +++ b/src/erasure-code/ErasureCodePlugin.cc @@ -14,21 +14,11 @@ * */ -#include "common/debug.h" - +#include #include #include "ErasureCodePlugin.h" -#define dout_subsys ceph_subsys_osd -#undef dout_prefix -#define dout_prefix _prefix(_dout) - -static ostream& _prefix(std::ostream* _dout) -{ - return *_dout << "ErasureCodePlugin: "; -} - #define PLUGIN_PREFIX "libec_" #define PLUGIN_SUFFIX ".so" #define PLUGIN_INIT_FUNCTION "__erasure_code_init" @@ -75,14 +65,15 @@ ErasureCodePlugin *ErasureCodePluginRegistry::get(const std::string &name) int ErasureCodePluginRegistry::factory(const std::string &plugin_name, const map ¶meters, - ErasureCodeInterfaceRef *erasure_code) + ErasureCodeInterfaceRef *erasure_code, + ostream &ss) { Mutex::Locker l(lock); ErasureCodePlugin *plugin = get(plugin_name); if (plugin == 0) { int r = 0; loading = true; - r = load(plugin_name, parameters, &plugin); + r = load(plugin_name, parameters, &plugin, ss); loading = false; if (r != 0) return r; @@ -93,18 +84,16 @@ int ErasureCodePluginRegistry::factory(const std::string &plugin_name, int ErasureCodePluginRegistry::load(const std::string &plugin_name, const map ¶meters, - ErasureCodePlugin **plugin) + ErasureCodePlugin **plugin, + ostream &ss) { assert(parameters.count("directory") != 0); std::string fname = parameters.find("directory")->second + "/" PLUGIN_PREFIX + plugin_name + PLUGIN_SUFFIX; - dout(10) << "load " << plugin_name << " from " << fname << dendl; - void *library = dlopen(fname.c_str(), RTLD_NOW); if (!library) { - derr << "load dlopen(" << fname - << "): " << dlerror() << dendl; + ss << "load dlopen(" << fname << "): " << dlerror(); return -EIO; } @@ -114,23 +103,23 @@ int ErasureCodePluginRegistry::load(const std::string &plugin_name, std::string name = plugin_name; int r = erasure_code_init(name.c_str()); if (r != 0) { - derr << "erasure_code_init(" << plugin_name - << "): " << strerror(-r) << dendl; + ss << "erasure_code_init(" << plugin_name + << "): " << strerror(-r); dlclose(library); return r; } } else { - derr << "load dlsym(" << fname - << ", " << PLUGIN_INIT_FUNCTION - << "): " << dlerror() << dendl; + ss << "load dlsym(" << fname + << ", " << PLUGIN_INIT_FUNCTION + << "): " << dlerror(); dlclose(library); return -ENOENT; } *plugin = get(plugin_name); if (*plugin == 0) { - derr << "load " << PLUGIN_INIT_FUNCTION << "()" - << "did not register " << plugin_name << dendl; + ss << "load " << PLUGIN_INIT_FUNCTION << "()" + << "did not register " << plugin_name; dlclose(library); return -EBADF; } diff --git a/src/erasure-code/ErasureCodePlugin.h b/src/erasure-code/ErasureCodePlugin.h index f3c96c093cffa..e891079c7f3b2 100644 --- a/src/erasure-code/ErasureCodePlugin.h +++ b/src/erasure-code/ErasureCodePlugin.h @@ -56,14 +56,16 @@ namespace ceph { int factory(const std::string &plugin, const map ¶meters, - ErasureCodeInterfaceRef *erasure_code); + ErasureCodeInterfaceRef *erasure_code, + ostream &ss); int add(const std::string &name, ErasureCodePlugin *plugin); ErasureCodePlugin *get(const std::string &name); int load(const std::string &plugin_name, const map ¶meters, - ErasureCodePlugin **plugin); + ErasureCodePlugin **plugin, + ostream &ss); }; } -- 2.39.5