From 2ba00bd2e8d9919cefb069cfd9dd7bdd3117e8b1 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Tue, 8 Apr 2014 00:20:29 +0200 Subject: [PATCH] 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 --- .../jerasure/ErasureCodePluginJerasure.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/erasure-code/jerasure/ErasureCodePluginJerasure.cc b/src/erasure-code/jerasure/ErasureCodePluginJerasure.cc index b5da3c05183ae..3d5d3e61d753f 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()); } -- 2.39.5