From d318ebdd469e8868cc7300d310cb8c821e75dc4c Mon Sep 17 00:00:00 2001 From: roentgen Date: Fri, 9 Nov 2018 21:30:36 +0900 Subject: [PATCH 01/18] fixed may cause SEGV if EC used in among threads despite using the glob-lock --- install_deps.sh | 9 ++++----- src/lib.rs | 4 ---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/install_deps.sh b/install_deps.sh index 2f49927..e359f59 100755 --- a/install_deps.sh +++ b/install_deps.sh @@ -25,9 +25,9 @@ cd ../ # # jerasure # -git clone https://github.com/ceph/jerasure.git +git clone https://github.com/roentgen/jerasure.git cd jerasure/ -git checkout de1739c +git checkout 87f052e autoreconf --force --install CFLAGS="-I${BUILD_DIR}/include" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --disable-shared --enable-static --with-pic --prefix $BUILD_DIR make $MAKE_FLAGS install @@ -36,14 +36,13 @@ cd ../ # # liberasurecode # -git clone https://github.com/openstack/liberasurecode.git +git clone https://github.com/roentgen/liberasurecode.git cd liberasurecode/ -git checkout 1.5.0 +git checkout 8331347 ./autogen.sh CFLAGS="-I${BUILD_DIR}/jerasure/include -I${BUILD_DIR}/include" if [ "$(uname)" == "Darwin" ]; then CFLAGS="$CFLAGS -Wno-error=address-of-packed-member" fi CFLAGS=$CFLAGS LIBS="-lJerasure" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --disable-shared --with-pic --prefix $BUILD_DIR -patch -p1 < ../liberasurecode.patch # Applies a patch for building static library make $MAKE_FLAGS install diff --git a/src/lib.rs b/src/lib.rs index 928788d..3366715 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -171,10 +171,6 @@ impl Builder { parity_fragments: self.parity_fragments, desc, }).map_err(Error::from_error_code)?; - - // `SIGSEGV` may be raised if encodings are executed (in parallel) immediately after creation. - // To prevent it, sleeps the current thread for a little while. - std::thread::sleep(Duration::from_millis(10)); Ok(coder) }) } From 3c34cb0d8c64d6979b85866621e283e539c981fc Mon Sep 17 00:00:00 2001 From: roentgen Date: Fri, 9 Nov 2018 21:30:36 +0900 Subject: [PATCH 02/18] fixed may cause SEGV if EC used in among threads despite using the glob-lock --- install_deps.sh | 9 ++++----- src/lib.rs | 4 ---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/install_deps.sh b/install_deps.sh index 2f49927..e359f59 100755 --- a/install_deps.sh +++ b/install_deps.sh @@ -25,9 +25,9 @@ cd ../ # # jerasure # -git clone https://github.com/ceph/jerasure.git +git clone https://github.com/roentgen/jerasure.git cd jerasure/ -git checkout de1739c +git checkout 87f052e autoreconf --force --install CFLAGS="-I${BUILD_DIR}/include" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --disable-shared --enable-static --with-pic --prefix $BUILD_DIR make $MAKE_FLAGS install @@ -36,14 +36,13 @@ cd ../ # # liberasurecode # -git clone https://github.com/openstack/liberasurecode.git +git clone https://github.com/roentgen/liberasurecode.git cd liberasurecode/ -git checkout 1.5.0 +git checkout 8331347 ./autogen.sh CFLAGS="-I${BUILD_DIR}/jerasure/include -I${BUILD_DIR}/include" if [ "$(uname)" == "Darwin" ]; then CFLAGS="$CFLAGS -Wno-error=address-of-packed-member" fi CFLAGS=$CFLAGS LIBS="-lJerasure" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --disable-shared --with-pic --prefix $BUILD_DIR -patch -p1 < ../liberasurecode.patch # Applies a patch for building static library make $MAKE_FLAGS install diff --git a/src/lib.rs b/src/lib.rs index 928788d..3366715 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -171,10 +171,6 @@ impl Builder { parity_fragments: self.parity_fragments, desc, }).map_err(Error::from_error_code)?; - - // `SIGSEGV` may be raised if encodings are executed (in parallel) immediately after creation. - // To prevent it, sleeps the current thread for a little while. - std::thread::sleep(Duration::from_millis(10)); Ok(coder) }) } From c33931ede9aa3abc972283cd0045c1a18c4cae0e Mon Sep 17 00:00:00 2001 From: roentgen Date: Thu, 15 Nov 2018 21:17:35 +0900 Subject: [PATCH 03/18] heading for the frugalos/* repository --- install_deps.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install_deps.sh b/install_deps.sh index e359f59..f353f33 100755 --- a/install_deps.sh +++ b/install_deps.sh @@ -25,9 +25,9 @@ cd ../ # # jerasure # -git clone https://github.com/roentgen/jerasure.git +git clone https://github.com/frugalos/jerasure.git cd jerasure/ -git checkout 87f052e +git checkout c9851639f4830e516e48797832ec30fe82a43e28 autoreconf --force --install CFLAGS="-I${BUILD_DIR}/include" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --disable-shared --enable-static --with-pic --prefix $BUILD_DIR make $MAKE_FLAGS install @@ -36,13 +36,13 @@ cd ../ # # liberasurecode # -git clone https://github.com/roentgen/liberasurecode.git -cd liberasurecode/ -git checkout 8331347 +git clone https://github.com/frugalos/openstack_liberasurecode.git +cd openstack_liberasurecode/ +git checkout 240333686eeae71ea1b94669242a8a6f4f51e260 ./autogen.sh CFLAGS="-I${BUILD_DIR}/jerasure/include -I${BUILD_DIR}/include" if [ "$(uname)" == "Darwin" ]; then CFLAGS="$CFLAGS -Wno-error=address-of-packed-member" fi -CFLAGS=$CFLAGS LIBS="-lJerasure" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --disable-shared --with-pic --prefix $BUILD_DIR +CFLAGS=$CFLAGS LDFLAGS="-L${BUILD_DIR}/lib" ./configure --disable-shared --with-pic --prefix $BUILD_DIR make $MAKE_FLAGS install From 6d9b740ca9c52ee1d2536b93f939a26b9e6b6aa3 Mon Sep 17 00:00:00 2001 From: roentgen Date: Thu, 15 Nov 2018 22:57:16 +0900 Subject: [PATCH 04/18] fixed merge break --- install_deps.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/install_deps.sh b/install_deps.sh index 429e856..f353f33 100755 --- a/install_deps.sh +++ b/install_deps.sh @@ -44,9 +44,5 @@ CFLAGS="-I${BUILD_DIR}/jerasure/include -I${BUILD_DIR}/include" if [ "$(uname)" == "Darwin" ]; then CFLAGS="$CFLAGS -Wno-error=address-of-packed-member" fi -<<<<<<< HEAD CFLAGS=$CFLAGS LDFLAGS="-L${BUILD_DIR}/lib" ./configure --disable-shared --with-pic --prefix $BUILD_DIR -======= -CFLAGS=$CFLAGS LIBS="-lJerasure" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --disable-shared --with-pic --prefix $BUILD_DIR ->>>>>>> d318ebdd469e8868cc7300d310cb8c821e75dc4c make $MAKE_FLAGS install From 8d6a73b0c41407c9da75529a895111cef0bc5ad9 Mon Sep 17 00:00:00 2001 From: roentgen Date: Thu, 15 Nov 2018 23:50:03 +0900 Subject: [PATCH 05/18] enabled shared for libJerasure.so --- install_deps.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install_deps.sh b/install_deps.sh index f353f33..c551715 100755 --- a/install_deps.sh +++ b/install_deps.sh @@ -29,8 +29,9 @@ git clone https://github.com/frugalos/jerasure.git cd jerasure/ git checkout c9851639f4830e516e48797832ec30fe82a43e28 autoreconf --force --install -CFLAGS="-I${BUILD_DIR}/include" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --disable-shared --enable-static --with-pic --prefix $BUILD_DIR +CFLAGS="-I${BUILD_DIR}/include" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --enable-shared --enable-static --with-pic --prefix $BUILD_DIR make $MAKE_FLAGS install +ldconfig cd ../ # From 3d9aeb88fa73f3c6da377e6590086010a81b1d22 Mon Sep 17 00:00:00 2001 From: roentgen Date: Fri, 16 Nov 2018 18:02:13 +0900 Subject: [PATCH 06/18] changed revision --- install_deps.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/install_deps.sh b/install_deps.sh index c551715..9ca8e23 100755 --- a/install_deps.sh +++ b/install_deps.sh @@ -27,11 +27,10 @@ cd ../ # git clone https://github.com/frugalos/jerasure.git cd jerasure/ -git checkout c9851639f4830e516e48797832ec30fe82a43e28 +git checkout threadsafe autoreconf --force --install CFLAGS="-I${BUILD_DIR}/include" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --enable-shared --enable-static --with-pic --prefix $BUILD_DIR make $MAKE_FLAGS install -ldconfig cd ../ # @@ -39,7 +38,7 @@ cd ../ # git clone https://github.com/frugalos/openstack_liberasurecode.git cd openstack_liberasurecode/ -git checkout 240333686eeae71ea1b94669242a8a6f4f51e260 +git checkout threadsafe ./autogen.sh CFLAGS="-I${BUILD_DIR}/jerasure/include -I${BUILD_DIR}/include" if [ "$(uname)" == "Darwin" ]; then From 194f44ba3d6df233dff8d52dfd44fbd4616dba40 Mon Sep 17 00:00:00 2001 From: yuuya uezato Date: Mon, 19 Nov 2018 16:41:48 +0900 Subject: [PATCH 07/18] use openstack/liberasurecode in the dynamic-link mode instead of the static-link mode --- install_deps.sh | 12 +- liberasurecode.patch | 425 ------------------------------------------- src/c_api.rs | 8 +- src/lib.rs | 5 +- 4 files changed, 12 insertions(+), 438 deletions(-) delete mode 100644 liberasurecode.patch diff --git a/install_deps.sh b/install_deps.sh index 9ca8e23..32c6478 100755 --- a/install_deps.sh +++ b/install_deps.sh @@ -18,31 +18,29 @@ git clone https://github.com/ceph/gf-complete.git cd gf-complete/ git checkout a6862d1 ./autogen.sh -./configure --disable-shared --with-pic --prefix $BUILD_DIR +./configure --with-pic --prefix $BUILD_DIR make $MAKE_FLAGS install cd ../ # # jerasure # -git clone https://github.com/frugalos/jerasure.git +git clone -b threadsafe https://github.com/frugalos/jerasure.git cd jerasure/ -git checkout threadsafe autoreconf --force --install -CFLAGS="-I${BUILD_DIR}/include" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --enable-shared --enable-static --with-pic --prefix $BUILD_DIR +CFLAGS="-I${BUILD_DIR}/include" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --with-pic --prefix $BUILD_DIR make $MAKE_FLAGS install cd ../ # # liberasurecode # -git clone https://github.com/frugalos/openstack_liberasurecode.git +git clone -b threadsafe https://github.com/frugalos/openstack_liberasurecode.git cd openstack_liberasurecode/ -git checkout threadsafe ./autogen.sh CFLAGS="-I${BUILD_DIR}/jerasure/include -I${BUILD_DIR}/include" if [ "$(uname)" == "Darwin" ]; then CFLAGS="$CFLAGS -Wno-error=address-of-packed-member" fi -CFLAGS=$CFLAGS LDFLAGS="-L${BUILD_DIR}/lib" ./configure --disable-shared --with-pic --prefix $BUILD_DIR +CFLAGS=$CFLAGS LDFLAGS="-L${BUILD_DIR}/lib" ./configure --with-pic --prefix $BUILD_DIR make $MAKE_FLAGS install diff --git a/liberasurecode.patch b/liberasurecode.patch deleted file mode 100644 index 2e848b5..0000000 --- a/liberasurecode.patch +++ /dev/null @@ -1,425 +0,0 @@ -diff --git a/include/erasurecode/alg_sig.h b/include/erasurecode/alg_sig.h -index 52554a9..0a6863d 100644 ---- a/include/erasurecode/alg_sig.h -+++ b/include/erasurecode/alg_sig.h -@@ -44,7 +44,6 @@ typedef struct alg_sig_s - int gf_w; - int sig_len; - struct jerasure_mult_routines mult_routines; -- void *jerasure_sohandle; - int *tbl1_l; - int *tbl1_r; - int *tbl2_l; -diff --git a/src/backends/jerasure/jerasure_rs_cauchy.c b/src/backends/jerasure/jerasure_rs_cauchy.c -index 3a0365a..217413d 100644 ---- a/src/backends/jerasure/jerasure_rs_cauchy.c -+++ b/src/backends/jerasure/jerasure_rs_cauchy.c -@@ -28,6 +28,8 @@ - - #include - #include -+#include -+#include - - #include "erasurecode.h" - #include "erasurecode_backend.h" -@@ -268,87 +270,16 @@ static void * jerasure_rs_cauchy_init(struct ec_backend_args *args, - } - } - -- /* -- * ISO C forbids casting a void* to a function pointer. -- * Since dlsym return returns a void*, we use this union to -- * "transform" the void* to a function pointer. -- */ -- union { -- cauchy_original_coding_matrix_func initp; -- jerasure_matrix_to_bitmatrix_func matrixtobitmatrixp; -- jerasure_smart_bitmatrix_to_schedule_func matrixschedulep; -- galois_uninit_field_func uninitp; -- jerasure_bitmatrix_encode_func encodep; -- jerasure_bitmatrix_decode_func decodep; -- jerasure_erasures_to_erased_func erasedp; -- jerasure_make_decoding_bitmatrix_func decodematrixp; -- jerasure_bitmatrix_dotprod_func dotprodp; -- void *vptr; -- } func_handle = {.vptr = NULL}; -- - /* fill in function addresses */ -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_bitmatrix_encode"); -- desc->jerasure_bitmatrix_encode = func_handle.encodep; -- if (NULL == desc->jerasure_bitmatrix_encode) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_bitmatrix_decode"); -- desc->jerasure_bitmatrix_decode = func_handle.decodep; -- if (NULL == desc->jerasure_bitmatrix_decode) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "cauchy_original_coding_matrix"); -- desc->cauchy_original_coding_matrix = func_handle.initp; -- if (NULL == desc->cauchy_original_coding_matrix) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_matrix_to_bitmatrix"); -- desc->jerasure_matrix_to_bitmatrix = func_handle.matrixtobitmatrixp; -- if (NULL == desc->jerasure_matrix_to_bitmatrix) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_smart_bitmatrix_to_schedule"); -- desc->jerasure_smart_bitmatrix_to_schedule = func_handle.matrixschedulep; -- if (NULL == desc->jerasure_smart_bitmatrix_to_schedule) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_make_decoding_bitmatrix"); -- desc->jerasure_make_decoding_bitmatrix = func_handle.decodematrixp; -- if (NULL == desc->jerasure_make_decoding_bitmatrix) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_bitmatrix_dotprod"); -- desc->jerasure_bitmatrix_dotprod = func_handle.dotprodp; -- if (NULL == desc->jerasure_bitmatrix_dotprod) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_erasures_to_erased"); -- desc->jerasure_erasures_to_erased = func_handle.erasedp; -- if (NULL == desc->jerasure_erasures_to_erased) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "galois_uninit_field"); -- desc->galois_uninit_field = func_handle.uninitp; -- if (NULL == desc->galois_uninit_field) { -- goto error; -- } -+ desc->jerasure_bitmatrix_encode = jerasure_bitmatrix_encode; -+ desc->jerasure_bitmatrix_decode = jerasure_bitmatrix_decode; -+ desc->cauchy_original_coding_matrix = cauchy_original_coding_matrix; -+ desc->jerasure_matrix_to_bitmatrix = jerasure_matrix_to_bitmatrix; -+ desc->jerasure_smart_bitmatrix_to_schedule = jerasure_smart_bitmatrix_to_schedule; -+ desc->jerasure_make_decoding_bitmatrix = jerasure_make_decoding_bitmatrix; -+ desc->jerasure_bitmatrix_dotprod = jerasure_bitmatrix_dotprod; -+ desc->jerasure_erasures_to_erased = jerasure_erasures_to_erased; -+ desc->galois_uninit_field = (galois_uninit_field_func)galois_uninit_field; - - /* setup the Cauchy matrices and schedules */ - desc->matrix = desc->cauchy_original_coding_matrix(k, m, w); -diff --git a/src/backends/jerasure/jerasure_rs_vand.c b/src/backends/jerasure/jerasure_rs_vand.c -index 9395046..143e00f 100644 ---- a/src/backends/jerasure/jerasure_rs_vand.c -+++ b/src/backends/jerasure/jerasure_rs_vand.c -@@ -28,6 +28,8 @@ - - #include - #include -+#include -+#include - - #include "erasurecode.h" - #include "erasurecode_backend.h" -@@ -232,98 +234,40 @@ static void * jerasure_rs_vand_init(struct ec_backend_args *args, - } - } - -- /* -- * ISO C forbids casting a void* to a function pointer. -- * Since dlsym return returns a void*, we use this union to -- * "transform" the void* to a function pointer. -- */ -- union { -- reed_sol_vandermonde_coding_matrix_func initp; -- galois_uninit_field_func uninitp; -- jerasure_matrix_encode_func encodep; -- jerasure_matrix_decode_func decodep; -- jerasure_make_decoding_matrix_func decodematrixp; -- jerasure_erasures_to_erased_func erasep; -- jerasure_matrix_dotprod_func dotprodp; -- void *vptr; -- } func_handle = {.vptr = NULL}; -- -- - /* fill in function addresses */ -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_matrix_encode"); -- desc->jerasure_matrix_encode = func_handle.encodep; -- if (NULL == desc->jerasure_matrix_encode) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_matrix_decode"); -- desc->jerasure_matrix_decode = func_handle.decodep; -- if (NULL == desc->jerasure_matrix_decode) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_make_decoding_matrix"); -- desc->jerasure_make_decoding_matrix = func_handle.decodematrixp; -- if (NULL == desc->jerasure_make_decoding_matrix) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_matrix_dotprod"); -- desc->jerasure_matrix_dotprod = func_handle.dotprodp; -- if (NULL == desc->jerasure_matrix_dotprod) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "jerasure_erasures_to_erased"); -- desc->jerasure_erasures_to_erased = func_handle.erasep; -- if (NULL == desc->jerasure_erasures_to_erased) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "reed_sol_vandermonde_coding_matrix"); -- desc->reed_sol_vandermonde_coding_matrix = func_handle.initp; -- if (NULL == desc->reed_sol_vandermonde_coding_matrix) { -- goto error; -- } -- -- func_handle.vptr = NULL; -- func_handle.vptr = dlsym(backend_sohandle, "galois_uninit_field"); -- desc->galois_uninit_field = func_handle.uninitp; -- if (NULL == desc->galois_uninit_field) { -- goto error; -- } -+ desc->jerasure_matrix_encode = jerasure_matrix_encode; -+ desc->jerasure_matrix_decode = jerasure_matrix_decode; -+ desc->jerasure_make_decoding_matrix = jerasure_make_decoding_matrix; -+ desc->jerasure_matrix_dotprod = jerasure_matrix_dotprod; -+ desc->jerasure_erasures_to_erased = jerasure_erasures_to_erased; -+ desc->reed_sol_vandermonde_coding_matrix = reed_sol_vandermonde_coding_matrix; -+ desc->galois_uninit_field = (galois_uninit_field_func)galois_uninit_field; - - desc->matrix = desc->reed_sol_vandermonde_coding_matrix( - desc->k, desc->m, desc->w); - if (NULL == desc->matrix) { -- goto error; -+ goto error; - } - - return desc; - - error: - free(desc); -- -+ - return NULL; - } - - /** -- * Return the element-size, which is the number of bits stored -- * on a given device, per codeword. For Vandermonde, this is -- * 'w'. For somthing like cauchy, this is packetsize * w. -- * -+ * Return the element-size, which is the number of bits stored -+ * on a given device, per codeword. For Vandermonde, this is -+ * 'w'. For somthing like cauchy, this is packetsize * w. -+ * - * Returns the size in bits! - */ - static int - jerasure_rs_vand_element_size(void* desc) - { -- struct jerasure_rs_vand_descriptor *jerasure_desc = -+ struct jerasure_rs_vand_descriptor *jerasure_desc = - (struct jerasure_rs_vand_descriptor*)desc; - - /* Note that cauchy will return pyeclib_handle->w * PYECC_CAUCHY_PACKETSIZE * 8 */ -diff --git a/src/erasurecode.c b/src/erasurecode.c -index fb6d5de..4c3d024 100644 ---- a/src/erasurecode.c -+++ b/src/erasurecode.c -@@ -177,6 +177,9 @@ void* liberasurecode_backend_open(ec_backend_t instance) - { - if (NULL == instance) - return NULL; -+ if (strncmp(instance->common.soname, "libJerasure", 11) == 0) -+ return (void *)-1; -+ - /* Use RTLD_LOCAL to avoid symbol collisions */ - return dlopen(instance->common.soname, RTLD_LAZY | RTLD_LOCAL); - } -@@ -186,6 +189,9 @@ int liberasurecode_backend_close(ec_backend_t instance) - if (NULL == instance || NULL == instance->desc.backend_sohandle) - return 0; - -+ if (strncmp(instance->common.soname, "libJerasure", 11) == 0) -+ return 0; -+ - dlclose(instance->desc.backend_sohandle); - dlerror(); /* Clear any existing errors */ - -diff --git a/src/utils/chksum/alg_sig.c b/src/utils/chksum/alg_sig.c -index 86740e6..bee5fca 100644 ---- a/src/utils/chksum/alg_sig.c -+++ b/src/utils/chksum/alg_sig.c -@@ -27,52 +27,27 @@ - #include - #include - #include --#define GALOIS_SINGLE_MULTIPLY "galois_single_multiply" --#define GALOIS_UNINIT "galois_uninit_field" -+#include -+#define GALOIS_SINGLE_MULTIPLY galois_single_multiply -+#define GALOIS_UNINIT galois_uninit_field - - int valid_gf_w[] = { 8, 16, -1 }; - int valid_pairs[][2] = { { 8, 32}, {16, 32}, {16, 64}, {-1, -1} }; - --galois_single_multiply_func get_galois_multi_func(void *handle) { -- /* -- * ISO C forbids casting a void* to a function pointer. -- * Since dlsym return returns a void*, we use this union to -- * "transform" the void* to a function pointer. -- */ -- union { -- galois_single_multiply_func fptr; -- void *vptr; -- } func_handle = {.vptr = NULL}; -- func_handle.vptr = dlsym(handle, GALOIS_SINGLE_MULTIPLY); -- return func_handle.fptr; -+galois_single_multiply_func get_galois_multi_func() { -+ return (galois_single_multiply_func)GALOIS_SINGLE_MULTIPLY; - } - - void stub_galois_uninit_field(int w){} - --galois_uninit_field_func get_galois_uninit_func(void *handle) { -- /* -- * ISO C forbids casting a void* to a function pointer. -- * Since dlsym return returns a void*, we use this union to -- * "transform" the void* to a function pointer. -- */ -- union { -- galois_uninit_field_func fptr; -- void *vptr; -- } func_handle = {.vptr = NULL}; -- func_handle.vptr = dlsym(handle, GALOIS_UNINIT); -- return func_handle.fptr; --} -- -- --void *get_jerasure_sohandle() --{ -- return dlopen(JERASURE_SONAME, RTLD_LAZY | RTLD_LOCAL); -+galois_uninit_field_func get_galois_uninit_func() { -+ return (galois_uninit_field_func)GALOIS_UNINIT; - } - --int load_gf_functions(void *sohandle, struct jerasure_mult_routines *routines) -+int load_gf_functions(struct jerasure_mult_routines *routines) - { -- routines->galois_single_multiply = get_galois_multi_func(sohandle); -- routines->galois_uninit_field = get_galois_uninit_func(sohandle); -+ routines->galois_single_multiply = get_galois_multi_func(); -+ routines->galois_uninit_field = get_galois_uninit_func(); - if (NULL == routines->galois_single_multiply) { - return -1; - } -@@ -93,7 +68,7 @@ int load_gf_functions(void *sohandle, struct jerasure_mult_routines *routines) - } - - static --alg_sig_t *init_alg_sig_w8(void *jerasure_sohandle, int sig_len) -+alg_sig_t *init_alg_sig_w8(int sig_len) - { - alg_sig_t *alg_sig_handle; - int num_gf_lr_table_syms; -@@ -107,9 +82,7 @@ alg_sig_t *init_alg_sig_w8(void *jerasure_sohandle, int sig_len) - return NULL; - } - -- alg_sig_handle->jerasure_sohandle = jerasure_sohandle; -- -- if (load_gf_functions(alg_sig_handle->jerasure_sohandle, &(alg_sig_handle->mult_routines)) < 0) { -+ if (load_gf_functions(&(alg_sig_handle->mult_routines)) < 0) { - free(alg_sig_handle); - return NULL; - } -@@ -150,7 +123,7 @@ alg_sig_t *init_alg_sig_w8(void *jerasure_sohandle, int sig_len) - } - - static --alg_sig_t *init_alg_sig_w16(void *jerasure_sohandle, int sig_len) -+alg_sig_t *init_alg_sig_w16(int sig_len) - { - alg_sig_t *alg_sig_handle; - int num_gf_lr_table_syms; -@@ -159,18 +132,12 @@ alg_sig_t *init_alg_sig_w16(void *jerasure_sohandle, int sig_len) - int alpha = 2, beta = 4, gamma = 8; - int num_components = sig_len / w; - -- if (NULL == jerasure_sohandle) { -- return NULL; -- } -- - alg_sig_handle = (alg_sig_t *)malloc(sizeof(alg_sig_t)); - if (NULL == alg_sig_handle) { - return NULL; - } - -- alg_sig_handle->jerasure_sohandle = jerasure_sohandle; -- -- if (load_gf_functions(alg_sig_handle->jerasure_sohandle, &(alg_sig_handle->mult_routines)) < 0) { -+ if (load_gf_functions(&(alg_sig_handle->mult_routines)) < 0) { - free(alg_sig_handle); - return NULL; - } -@@ -216,15 +183,9 @@ alg_sig_t *init_alg_sig_w16(void *jerasure_sohandle, int sig_len) - alg_sig_t *init_alg_sig(int sig_len, int gf_w) - { - int i=0; -- void *jerasure_sohandle = get_jerasure_sohandle(); -- -- if (NULL == jerasure_sohandle) { -- fprintf (stderr, "Could not open Jerasure backend. Install Jerasure or fix LD_LIBRARY_PATH. Passing.\n"); -- return NULL; -- } - - while (valid_pairs[i][0] > -1) { -- if (gf_w == valid_pairs[i][0] && -+ if (gf_w == valid_pairs[i][0] && - sig_len == valid_pairs[i][1]) { - break; - } -@@ -236,9 +197,9 @@ alg_sig_t *init_alg_sig(int sig_len, int gf_w) - } - - if (gf_w == 8) { -- return init_alg_sig_w8(jerasure_sohandle, sig_len); -+ return init_alg_sig_w8(sig_len); - } else if (gf_w == 16) { -- return init_alg_sig_w16(jerasure_sohandle, sig_len); -+ return init_alg_sig_w16(sig_len); - } - return NULL; - } -@@ -254,7 +215,6 @@ void destroy_alg_sig(alg_sig_t* alg_sig_handle) - } - - alg_sig_handle->mult_routines.galois_uninit_field(alg_sig_handle->gf_w); -- dlclose(alg_sig_handle->jerasure_sohandle); - - int num_components = alg_sig_handle->sig_len / alg_sig_handle->gf_w; - diff --git a/src/c_api.rs b/src/c_api.rs index f7136d2..27a164a 100644 --- a/src/c_api.rs +++ b/src/c_api.rs @@ -43,10 +43,10 @@ pub const EINVALIDPARAMS: u32 = 206; pub const EBADHEADER: u32 = 207; pub const EINSUFFFRAGS: u32 = 208; -#[link(name = "erasurecode", kind = "static")] -#[link(name = "gf_complete", kind = "static")] -#[link(name = "Jerasure", kind = "static")] -#[link(name = "Xorcode", kind = "static")] +#[link(name = "erasurecode")] +#[link(name = "gf_complete")] +#[link(name = "Jerasure")] +#[link(name = "Xorcode")] extern "C" { /// Create a liberasurecode instance and return a descriptor /// for use with EC operations (encode, decode, reconstruct) diff --git a/src/lib.rs b/src/lib.rs index 3366715..642aaea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,7 +48,6 @@ extern crate libc; use std::num::NonZeroUsize; use std::slice; -use std::time::Duration; pub use result::{Error, Result}; @@ -291,7 +290,9 @@ impl ErasureCoder { } impl Drop for ErasureCoder { fn drop(&mut self) { - let _ = c_api::instance_destroy(self.desc); + with_global_lock(|| { + let _ = c_api::instance_destroy(self.desc); + }) } } From 149a047368aed89f08a6ed3f2afa4beafa40832d Mon Sep 17 00:00:00 2001 From: yuuya uezato Date: Mon, 19 Nov 2018 16:47:11 +0900 Subject: [PATCH 08/18] add LibErasureCodeRsVand on the basis of PR3 of frugalos/liberasurecode --- src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 642aaea..085b3fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,6 +62,9 @@ pub enum Backend { /// Cauchy base Read-Solomon erasure coding provided by `jerasure` library (default). JerasureRsCauchy, + + /// Read-Solomon erasure coding built-in `openstack/liberasurecode`. + LibErasureCodeRsVand, } impl Default for Backend { /// `Backend::JerasureRsCauchy`を返す. @@ -142,6 +145,7 @@ impl Builder { let backend_id = match self.backend { Backend::JerasureRsCauchy => c_api::EcBackendId::JERASURE_RS_CAUCHY, Backend::JerasureRsVand => c_api::EcBackendId::JERASURE_RS_VAND, + Backend::LibErasureCodeRsVand => c_api::EcBackendId::LIBERASURECODE_RS_VAND, }; let checksum_type = match self.checksum { Checksum::None => c_api::EcChecksumType::NONE, @@ -381,7 +385,13 @@ mod tests { #[test] fn various_params() { - for backend in [Backend::JerasureRsCauchy, Backend::JerasureRsVand].iter() { + for backend in [ + Backend::JerasureRsCauchy, + Backend::JerasureRsVand, + Backend::LibErasureCodeRsVand, + ] + .iter() + { for checksum in [Checksum::None, Checksum::Crc32, Checksum::Md5].iter() { for data_fragments in (3..6).map(non_zero) { for parity_fragments in (1..4).map(non_zero) { From f61578ee56f3f5f7f2372f8b330f2d3cdf5b91fe Mon Sep 17 00:00:00 2001 From: yuuya uezato Date: Mon, 19 Nov 2018 16:50:35 +0900 Subject: [PATCH 09/18] reflect the removal of a patch file --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 660a5de..6e2eccd 100644 --- a/build.rs +++ b/build.rs @@ -11,7 +11,7 @@ fn main() { let _ = fs::remove_dir_all(&build_dir); fs::create_dir(&build_dir).unwrap(); - for file in &["install_deps.sh", "liberasurecode.patch"] { + for file in &["install_deps.sh"] { fs::copy(file, build_dir.join(file)).unwrap(); } From cecbcef7fa235e5d9d4aaacd999a9adaea7a9c3e Mon Sep 17 00:00:00 2001 From: yuuya uezato Date: Mon, 19 Nov 2018 19:46:46 +0900 Subject: [PATCH 10/18] unlimit the number of cargo test threads --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 86931c4..831a8ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ before_script: - rustup component add clippy-preview script: - - cargo test -- --test-threads=1 + - cargo test - cargo clippy matrix: From 7ab9eb3345c5dcf863bd41ac85d2a0be357b2485 Mon Sep 17 00:00:00 2001 From: yuuya uezato Date: Mon, 26 Nov 2018 23:39:54 +0900 Subject: [PATCH 11/18] add a shell-script to install dependent libraries --- Cargo.toml | 4 +- install_dependent_libraries.sh | 69 ++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100755 install_dependent_libraries.sh diff --git a/Cargo.toml b/Cargo.toml index b75b56a..ab5897b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,8 @@ name = "liberasurecode" version = "1.0.2" authors = ["The FrugalOS Developers"] -links = "erasurecode" -build = "build.rs" +# links = "erasurecode" +# build = "build.rs" description = "A Rust wrapper for `openstack/liberasurecode`" homepage = "https://github.com/frugalos/liberasurecode" repository = "https://github.com/frugalos/liberasurecode" diff --git a/install_dependent_libraries.sh b/install_dependent_libraries.sh new file mode 100755 index 0000000..2c349aa --- /dev/null +++ b/install_dependent_libraries.sh @@ -0,0 +1,69 @@ +#! /usr/bin/env bash + +set -eux + +INSTALL_DIR="" + +if [ $# -eq 1 ] +then + INSTALL_DIR=$1 +else + echo "This script file requires a single argument where we install dependent libraries" + exit 1 +fi + +case $INSTALL_DIR in + /*) + echo "We install dependent libraries into $INSTALL_DIR." + ;; + *) + echo "You passed a relative path. Please use an absolute path." + exit 1 + ;; +esac + + +MAKE_FLAGS="" + +# Please try and add other distributions. +case "$(uname)" in + "Linux") MAKE_FLAGS="-j$(nproc)";; + "Darwin") MAKE_FLAGS="-j$(sysctl -n hw.ncpu)" +esac + +BUILD_DIR="build_working_directory" +mkdir $BUILD_DIR + +# +# gf-complete +# +git clone https://github.com/ceph/gf-complete.git $BUILD_DIR/gf-complete +cd $BUILD_DIR/gf-complete +git checkout a6862d1 +./autogen.sh +./configure --with-pic --prefix $INSTALL_DIR +make $MAKE_FLAGS install +cd ../.. + +# +# jerasure +# +git clone -b threadsafe https://github.com/frugalos/jerasure.git $BUILD_DIR/jerasure +cd $BUILD_DIR/jerasure +autoreconf --force --install +CFLAGS="-I${INSTALL_DIR}/include" LDFLAGS="-L${INSTALL_DIR}/lib" ./configure --with-pic --prefix $INSTALL_DIR +make $MAKE_FLAGS install +cd ../.. + +# +# liberasurecode +# +git clone -b threadsafe https://github.com/frugalos/openstack_liberasurecode.git $BUILD_DIR/openstack_liberasurecode +cd $BUILD_DIR/openstack_liberasurecode +./autogen.sh +CFLAGS="-I${INSTALL_DIR}/include -I${INSTALL_DIR}/include/jerasure" +if [ "$(uname)" == "Darwin" ]; then + CFLAGS="$CFLAGS -Wno-error=address-of-packed-member" +fi +CFLAGS=$CFLAGS LDFLAGS="-L${INSTALL_DIR}/lib" ./configure --with-pic --prefix $INSTALL_DIR +make $MAKE_FLAGS install From b1ff114e05c6803f698d2ea08d2cb7c005766adb Mon Sep 17 00:00:00 2001 From: yuuya uezato Date: Fri, 30 Nov 2018 20:12:11 +0900 Subject: [PATCH 12/18] change branches on which this branch depends to frugalos_dyn --- install_deps.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install_deps.sh b/install_deps.sh index 32c6478..049c581 100755 --- a/install_deps.sh +++ b/install_deps.sh @@ -25,7 +25,7 @@ cd ../ # # jerasure # -git clone -b threadsafe https://github.com/frugalos/jerasure.git +git clone -b frugalos_dyn https://github.com/frugalos/jerasure.git cd jerasure/ autoreconf --force --install CFLAGS="-I${BUILD_DIR}/include" LDFLAGS="-L${BUILD_DIR}/lib" ./configure --with-pic --prefix $BUILD_DIR @@ -35,7 +35,7 @@ cd ../ # # liberasurecode # -git clone -b threadsafe https://github.com/frugalos/openstack_liberasurecode.git +git clone -b frugalos_dyn https://github.com/frugalos/openstack_liberasurecode.git cd openstack_liberasurecode/ ./autogen.sh CFLAGS="-I${BUILD_DIR}/jerasure/include -I${BUILD_DIR}/include" From 75cc965a282522456df85f0eb634948885066dc3 Mon Sep 17 00:00:00 2001 From: yuuya uezato Date: Fri, 30 Nov 2018 21:07:44 +0900 Subject: [PATCH 13/18] use the environment variable FRUGALOS_DIR --- build.rs | 30 +++--------------------------- install_dependent_libraries.sh | 17 ++++++++--------- 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/build.rs b/build.rs index 6e2eccd..ddd268c 100644 --- a/build.rs +++ b/build.rs @@ -6,32 +6,8 @@ use std::process::{Command, Stdio}; fn main() { println!("cargo:rerun-if-changed=build.rs"); - let outdir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); - let build_dir = outdir.join("build"); - let _ = fs::remove_dir_all(&build_dir); - fs::create_dir(&build_dir).unwrap(); + let frugalos_dir: std::ffi::OsString = env::var_os("FRUGALOS_DIR").unwrap(); + let frugalos_dir: String = frugalos_dir.into_string().unwrap(); - for file in &["install_deps.sh"] { - fs::copy(file, build_dir.join(file)).unwrap(); - } - - match Command::new("./install_deps.sh") - .current_dir(&build_dir) - .stderr(Stdio::inherit()) - .output() - { - Err(e) => { - panic!("{}: {}", build_dir.display(), e); - } - Ok(output) => { - if !output.status.success() { - panic!( - "./install_deps.sh failed: exit-code={:?}", - output.status.code() - ); - } - } - } - - println!("cargo:rustc-link-search={}/lib", build_dir.display()); + println!("cargo:rustc-link-search={}/lib", frugalos_dir); } diff --git a/install_dependent_libraries.sh b/install_dependent_libraries.sh index 2c349aa..0d03cb0 100755 --- a/install_dependent_libraries.sh +++ b/install_dependent_libraries.sh @@ -4,24 +4,23 @@ set -eux INSTALL_DIR="" -if [ $# -eq 1 ] +if [ -z $FRUGALOS_DIR ] then - INSTALL_DIR=$1 -else - echo "This script file requires a single argument where we install dependent libraries" - exit 1 + echo "Please set the environment FRUGALOS_DIR to install auxiliary artifacts." + exit 1 fi +INSTALL_DIR=$FRUGALOS_DIR + case $INSTALL_DIR in /*) - echo "We install dependent libraries into $INSTALL_DIR." + echo "We install dependent artifacts into FRUGALOS_DIR=$FRUGALOS_DIR" ;; *) echo "You passed a relative path. Please use an absolute path." exit 1 ;; esac - MAKE_FLAGS="" @@ -48,7 +47,7 @@ cd ../.. # # jerasure # -git clone -b threadsafe https://github.com/frugalos/jerasure.git $BUILD_DIR/jerasure +git clone -b frugalos_dyn https://github.com/frugalos/jerasure.git $BUILD_DIR/jerasure cd $BUILD_DIR/jerasure autoreconf --force --install CFLAGS="-I${INSTALL_DIR}/include" LDFLAGS="-L${INSTALL_DIR}/lib" ./configure --with-pic --prefix $INSTALL_DIR @@ -58,7 +57,7 @@ cd ../.. # # liberasurecode # -git clone -b threadsafe https://github.com/frugalos/openstack_liberasurecode.git $BUILD_DIR/openstack_liberasurecode +git clone -b frugalos_dyn https://github.com/frugalos/openstack_liberasurecode.git $BUILD_DIR/openstack_liberasurecode cd $BUILD_DIR/openstack_liberasurecode ./autogen.sh CFLAGS="-I${INSTALL_DIR}/include -I${INSTALL_DIR}/include/jerasure" From 78918dd1e02b63fc9e6d065d59b48c7d54428858 Mon Sep 17 00:00:00 2001 From: yuuya uezato Date: Fri, 30 Nov 2018 23:14:35 +0900 Subject: [PATCH 14/18] delete unneeded lines --- build.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/build.rs b/build.rs index ddd268c..4730497 100644 --- a/build.rs +++ b/build.rs @@ -1,7 +1,4 @@ use std::env; -use std::fs; -use std::path::PathBuf; -use std::process::{Command, Stdio}; fn main() { println!("cargo:rerun-if-changed=build.rs"); From 6ae193b5f8556bc2229e2dda2016f93fdfbb54e4 Mon Sep 17 00:00:00 2001 From: yuuya uezato Date: Fri, 30 Nov 2018 23:20:49 +0900 Subject: [PATCH 15/18] fix .travis.yml --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 831a8ec..9f01a0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ rust: - nightly before_script: + - ./install_dependent_libraries.sh - rustup component add clippy-preview script: @@ -19,4 +20,6 @@ matrix: env: global: - - RUSTFLAGS="-D warnings" + - FRUGALOS_DIR=$TRAVIS_BUILD_DIR/frugalos_working_dir + - LD_LIBRARY_PATH=$FRUGALOS_DIR/lib + - RUSTFLAGS="-D warnings" From 7fcca4f8deb54fb15093f56b954be60df48b9d4f Mon Sep 17 00:00:00 2001 From: yuuya uezato Date: Fri, 30 Nov 2018 23:31:56 +0900 Subject: [PATCH 16/18] change libJerasure -> libFrugalosJerasure --- src/c_api.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c_api.rs b/src/c_api.rs index 27a164a..56868d5 100644 --- a/src/c_api.rs +++ b/src/c_api.rs @@ -45,7 +45,7 @@ pub const EINSUFFFRAGS: u32 = 208; #[link(name = "erasurecode")] #[link(name = "gf_complete")] -#[link(name = "Jerasure")] +#[link(name = "FrugalosJerasure")] #[link(name = "Xorcode")] extern "C" { /// Create a liberasurecode instance and return a descriptor From ce8ad6c506d7213422ec93f5eaa304f1ba28b9e6 Mon Sep 17 00:00:00 2001 From: Yuya Uezato Date: Fri, 30 Nov 2018 23:41:06 +0900 Subject: [PATCH 17/18] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 354a415..fd2f655 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,16 @@ For example, on Ubuntu, you can install those by executing the following command $ sudo apt install gcc git make automake autoconf libtool ``` +Before do `cargo build`, please set the two environment variables `FRUGALOS_DIR` and `LD_LIBRARY_PATH` +``` +FRUGALOS_DIR=/some/path/to/locate/generated/artifacts +LD_LIBRARY_PATH=$FRUGALOS_DIR/lib +``` +and do the following shell script to install auxiliary files +``` +./install_dependent_libraries.sh +``` + Examples -------- From 91b6d5cb2496fdd50f7c232c46ccd023ed1211fb Mon Sep 17 00:00:00 2001 From: Yuya Uezato Date: Tue, 4 Dec 2018 18:12:32 +0900 Subject: [PATCH 18/18] Update Cargo.toml --- Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ab5897b..9582eba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,6 @@ name = "liberasurecode" version = "1.0.2" authors = ["The FrugalOS Developers"] -# links = "erasurecode" -# build = "build.rs" description = "A Rust wrapper for `openstack/liberasurecode`" homepage = "https://github.com/frugalos/liberasurecode" repository = "https://github.com/frugalos/liberasurecode"