From: Loic Dachary Date: Mon, 7 Apr 2014 22:20:29 +0000 (+0200) Subject: erasure-code: thread-safe initialization of gf-complete X-Git-Tag: v0.80-rc1~83^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F1621%2Fhead;p=ceph.git erasure-code: thread-safe initialization of gf-complete 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 --- diff --git a/src/erasure-code/jerasure/ErasureCodePluginJerasure.cc b/src/erasure-code/jerasure/ErasureCodePluginJerasure.cc index b5da3c05183a..3d5d3e61d753 100644 --- a/src/erasure-code/jerasure/ErasureCodePluginJerasure.cc +++ b/src/erasure-code/jerasure/ErasureCodePluginJerasure.cc @@ -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()); }