]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ErasureCodeJerasure: plugin 538/head
authorLoic Dachary <loic@dachary.org>
Wed, 28 Aug 2013 16:48:40 +0000 (18:48 +0200)
committerLoic Dachary <loic@dachary.org>
Tue, 10 Sep 2013 14:46:23 +0000 (16:46 +0200)
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>
src/osd/ErasureCodePluginJerasure/ErasureCodePluginJerasure.cc [new file with mode: 0644]
src/osd/ErasureCodePluginJerasure/Makefile.am
src/test/Makefile.am
src/test/osd/TestErasureCodePluginJerasure.cc [new file with mode: 0644]

diff --git a/src/osd/ErasureCodePluginJerasure/ErasureCodePluginJerasure.cc b/src/osd/ErasureCodePluginJerasure/ErasureCodePluginJerasure.cc
new file mode 100644 (file)
index 0000000..d5cb1cd
--- /dev/null
@@ -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());
+}
index 8549d91a8861623ee3f31a0075470648ab14e761..b31fb1c0785b52cc6cfb21cda6b4544a3d39841a 100644 (file)
@@ -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 \
index 7f0dc88b8a0e1d48c76b43755edcb70acb04f5fc..059e2d30f418572d8872ece0474d3e36a46ce1a7 100644 (file)
@@ -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 (file)
index 0000000..fe819c7
--- /dev/null
@@ -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: