summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Dachary <loic@dachary.org>2013-08-28 18:48:40 +0200
committerLoic Dachary <loic@dachary.org>2013-09-10 16:46:23 +0200
commit647188c4e1cd082e2d499e4db540719b17deaeb2 (patch)
tree29e8bf63844f79a5f5a137b2bc5d4505a927c385
parente9e53912503259326a7877bda31c4360302c2c34 (diff)
downloadceph-647188c4e1cd082e2d499e4db540719b17deaeb2.tar.gz
ErasureCodeJerasure: plugin
Create the class matching the string found in the erasure-code-technique parameter, using the same strings are the original {encoder,decoder}.c examples from Jerasure-1.2A. Registers the plugin in ErasureCodePluginRegistry. https://github.com/dachary/ceph/tree/wip-5879 refs #5879 Signed-off-by: Loic Dachary <loic@dachary.org>
-rw-r--r--src/osd/ErasureCodePluginJerasure/ErasureCodePluginJerasure.cc70
-rw-r--r--src/osd/ErasureCodePluginJerasure/Makefile.am1
-rw-r--r--src/test/Makefile.am9
-rw-r--r--src/test/osd/TestErasureCodePluginJerasure.cc67
4 files changed, 147 insertions, 0 deletions
diff --git a/src/osd/ErasureCodePluginJerasure/ErasureCodePluginJerasure.cc b/src/osd/ErasureCodePluginJerasure/ErasureCodePluginJerasure.cc
new file mode 100644
index 00000000000..d5cb1cd6c93
--- /dev/null
+++ b/src/osd/ErasureCodePluginJerasure/ErasureCodePluginJerasure.cc
@@ -0,0 +1,70 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
+ *
+ * Author: Loic Dachary <loic@dachary.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+#include "common/debug.h"
+#include "osd/ErasureCodePlugin.h"
+#include "ErasureCodeJerasure.h"
+
+#define dout_subsys ceph_subsys_osd
+#undef dout_prefix
+#define dout_prefix _prefix(_dout)
+
+static ostream& _prefix(std::ostream* _dout)
+{
+ return *_dout << "ErasureCodePluginJerasure: ";
+}
+
+class ErasureCodePluginJerasure : public ErasureCodePlugin {
+public:
+ virtual int factory(const map<std::string,std::string> &parameters,
+ ErasureCodeInterfaceRef *erasure_code) {
+ ErasureCodeJerasure *interface;
+ std::string t;
+ if (parameters.find("erasure-code-technique") != parameters.end())
+ t = parameters.find("erasure-code-technique")->second;
+ if (t == "reed_sol_van") {
+ interface = new ErasureCodeJerasureReedSolomonVandermonde();
+ } else if (t == "reed_sol_r6_op") {
+ interface = new ErasureCodeJerasureReedSolomonRAID6();
+ } else if (t == "cauchy_orig") {
+ interface = new ErasureCodeJerasureCauchyOrig();
+ } else if (t == "cauchy_good") {
+ interface = new ErasureCodeJerasureCauchyGood();
+ } else if (t == "liberation") {
+ interface = new ErasureCodeJerasureLiberation();
+ } else if (t == "blaum_roth") {
+ interface = new ErasureCodeJerasureBlaumRoth();
+ } else if (t == "liber8tion") {
+ interface = new ErasureCodeJerasureLiber8tion();
+ } else {
+ derr << "technique=" << t << " is not a valid coding technique. "
+ << " Choose one of the following: "
+ << "reed_sol_van, reed_sol_r6_op, cauchy_orig, "
+ << "cauchy_good, liberation, blaum_roth, liber8tion"
+ << dendl;
+ return -ENOENT;
+ }
+ interface->init(parameters);
+ *erasure_code = ErasureCodeInterfaceRef(interface);
+ return 0;
+ }
+};
+
+int __erasure_code_init(char *plugin_name)
+{
+ ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
+ return instance.add(plugin_name, new ErasureCodePluginJerasure());
+}
diff --git a/src/osd/ErasureCodePluginJerasure/Makefile.am b/src/osd/ErasureCodePluginJerasure/Makefile.am
index 8549d91a886..b31fb1c0785 100644
--- a/src/osd/ErasureCodePluginJerasure/Makefile.am
+++ b/src/osd/ErasureCodePluginJerasure/Makefile.am
@@ -1,5 +1,6 @@
# jerasure plugin
libec_jerasure_la_SOURCES = \
+ osd/ErasureCodePluginJerasure/ErasureCodePluginJerasure.cc \
osd/ErasureCodePluginJerasure/ErasureCodeJerasure.cc \
osd/ErasureCodePluginJerasure/cauchy.c \
osd/ErasureCodePluginJerasure/galois.c \
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index 7f0dc88b8a0..059e2d30f41 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -338,6 +338,15 @@ unittest_erasure_code_jerasure_LDADD += -ldl
endif
check_PROGRAMS += unittest_erasure_code_jerasure
+unittest_erasure_code_plugin_jerasure_SOURCES = \
+ test/osd/TestErasureCodePluginJerasure.cc
+unittest_erasure_code_plugin_jerasure_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
+unittest_erasure_code_plugin_jerasure_LDADD = $(LIBOSD) $(LIBCOMMON) $(UNITTEST_LDADD) $(CEPH_GLOBAL)
+if LINUX
+unittest_erasure_code_plugin_jerasure_LDADD += -ldl
+endif
+check_PROGRAMS += unittest_erasure_code_plugin_jerasure
+
unittest_erasure_code_example_SOURCES = test/osd/TestErasureCodeExample.cc
noinst_HEADERS += test/osd/ErasureCodeExample.h
unittest_erasure_code_example_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
diff --git a/src/test/osd/TestErasureCodePluginJerasure.cc b/src/test/osd/TestErasureCodePluginJerasure.cc
new file mode 100644
index 00000000000..fe819c71a39
--- /dev/null
+++ b/src/test/osd/TestErasureCodePluginJerasure.cc
@@ -0,0 +1,67 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
+ *
+ * Author: Loic Dachary <loic@dachary.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <errno.h>
+#include "global/global_init.h"
+#include "osd/ErasureCodePlugin.h"
+#include "common/ceph_argparse.h"
+#include "global/global_context.h"
+#include "gtest/gtest.h"
+
+TEST(ErasureCodePlugin, factory)
+{
+ ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
+ map<std::string,std::string> parameters;
+ parameters["erasure-code-directory"] = ".libs";
+ {
+ ErasureCodeInterfaceRef erasure_code;
+ EXPECT_FALSE(erasure_code);
+ EXPECT_EQ(-ENOENT, instance.factory("jerasure", parameters, &erasure_code));
+ EXPECT_FALSE(erasure_code);
+ }
+ const char *techniques[] = {
+ "reed_sol_van",
+ "reed_sol_r6_op",
+ "cauchy_orig",
+ "cauchy_good",
+ "liberation",
+ "blaum_roth",
+ "liber8tion",
+ 0
+ };
+ for(const char **technique = techniques; *technique; technique++) {
+ ErasureCodeInterfaceRef erasure_code;
+ parameters["erasure-code-technique"] = *technique;
+ EXPECT_FALSE(erasure_code);
+ EXPECT_EQ(0, instance.factory("jerasure", parameters, &erasure_code));
+ EXPECT_TRUE(erasure_code);
+ }
+}
+
+int main(int argc, char **argv) {
+ vector<const char*> args;
+ argv_to_vec(argc, (const char **)argv, args);
+
+ global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(g_ceph_context);
+
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+
+// Local Variables:
+// compile-command: "cd ../.. ; make -j4 && make unittest_erasure_code_jerasure_plugin && valgrind --tool=memcheck ./unittest_erasure_code_jerasure_plugin --gtest_filter=*.* --log-to-stderr=true --debug-osd=20"
+// End: