]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
erasure-code: thread-safe initialization of gf-complete 1621/head
authorLoic Dachary <loic@dachary.org>
Mon, 7 Apr 2014 22:20:29 +0000 (00:20 +0200)
committerLoic Dachary <loic@dachary.org>
Tue, 8 Apr 2014 07:47:33 +0000 (09:47 +0200)
Instead of relying on an implicit initialization happening during
encoding/decoding with galois.c:galois_init_default_field, call
gf.c:gf_init_easy for each w values when the plugin is loaded.

Loading the plugin is protected against race conditions by a lock.

It does not cover all possible uses of gf-complete but it is enough for
the ceph jerasure plugin.

http://tracker.ceph.com/issues/7914 fixes #7914

Signed-off-by: Loic Dachary <loic@dachary.org>
src/erasure-code/jerasure/ErasureCodePluginJerasure.cc

index b5da3c05183ae85c2af4ff5b3c37f5b97d61f340..3d5d3e61d753fa281a1ab9d2dc207891aa9475fd 100644 (file)
@@ -63,8 +63,27 @@ public:
   }
 };
 
+extern "C" {
+#include "galois.h"
+
+extern gf_t *gfp_array[];
+extern int  gfp_is_composite[];
+}
+
 int __erasure_code_init(char *plugin_name)
 {
   ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
+  int w[] = { 4, 8, 16, 32 };
+  for(int i = 0; i < 4; i++) {
+    if (gfp_array[w[i]] == NULL) {
+      gfp_array[w[i]] = (gf_t*)malloc(sizeof(gf_t));
+      assert(gfp_array[w[i]]);
+      gfp_is_composite[w[i]] = 0;
+      if (!gf_init_easy(gfp_array[w[i]], w[i])) {
+       derr << "failed to gf_init_easy(" << w[i] << ")" << dendl;
+       return -EINVAL;
+      }
+    }
+  }
   return instance.add(plugin_name, new ErasureCodePluginJerasure());
 }