]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
erasure_code: implement ceph_erasure_code to assert the existence of a plugin
authorLoic Dachary <loic-201408@dachary.org>
Tue, 23 Sep 2014 12:37:57 +0000 (14:37 +0200)
committerLoic Dachary <ldachary@redhat.com>
Tue, 25 Nov 2014 15:31:35 +0000 (16:31 +0100)
This is handy when scripting in the context of teuthology and only
conditionally run tests for the isa plugin, for instance.

Signed-off-by: Loic Dachary <loic-201408@dachary.org>
(cherry picked from commit efe121d9f2028c312eef2650d32ccf0cbc828edb)

src/test/erasure-code/ceph_erasure_code.cc

index 0d39a8b6479d590f8d20d33c42c4800ce3423848..895178dfa4f3109ad40b5907d841dce82ed309fb 100644 (file)
@@ -4,6 +4,7 @@
  * Ceph distributed storage system
  *
  * Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
+ * Copyright (C) 2014 Red Hat <contact@redhat.com>
  *
  * Author: Loic Dachary <loic@dachary.org>
  *
@@ -39,6 +40,8 @@ class ErasureCodeCommand {
 public:
   int setup(int argc, char** argv);
   int run();
+  int plugin_exists();
+  int display_information();
 };
 
 int ErasureCodeCommand::setup(int argc, char** argv) {
@@ -58,6 +61,8 @@ int ErasureCodeCommand::setup(int argc, char** argv) {
     ("get_chunk_count", "display get_chunk_count()")
     ("parameter,P", po::value<vector<string> >(),
      "parameters")
+    ("plugin_exists", po::value<string>(),
+     "succeeds if the plugin given in argument exists and can be loaded")
     ;
 
   po::parsed_options parsed =
@@ -107,17 +112,37 @@ int ErasureCodeCommand::setup(int argc, char** argv) {
 
   if (parameters.count("directory") == 0)
     parameters["directory"] = ".libs";
-  if (parameters.count("plugin") == 0) {
-    cerr << "--parameter plugin=<plugin> is mandatory" << endl;
-    return 1;
-  }
 
   return 0;
 }
 
 int ErasureCodeCommand::run() {
+  if (vm.count("plugin_exists"))
+    return plugin_exists();
+  else
+    return display_information();
+}
+
+int ErasureCodeCommand::plugin_exists() {
+  ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
+  ErasureCodePlugin *plugin = 0;
+  Mutex::Locker l(instance.lock);
+  stringstream ss;
+  int code = instance.load(vm["plugin_exists"].as<string>(), parameters["directory"], &plugin, ss);
+  if (code)
+    cerr << ss.str() << endl;
+  return code;
+}
+
+int ErasureCodeCommand::display_information() {
   ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
   ErasureCodeInterfaceRef erasure_code;
+
+  if (parameters.count("plugin") == 0) {
+    cerr << "--parameter plugin=<plugin> is mandatory" << endl;
+    return 1;
+  }
+
   int code = instance.factory(parameters["plugin"],
                              parameters,
                              &erasure_code, cerr);
@@ -155,7 +180,7 @@ int main(int argc, char** argv) {
  * Local Variables:
  * compile-command: "cd ../.. ; make -j4 &&
  *   make -j4 ceph_erasure_code &&
- *   valgrind --tool=memcheck --leak-check=full \
+ *   libtool --mode=execute valgrind --tool=memcheck --leak-check=full \
  *      ./ceph_erasure_code \
  *      --parameter plugin=jerasure \
  *      --parameter directory=.libs \