summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Lambert <eric_lambert@xyratex.com>2014-09-10 17:13:45 -0700
committerEric Lambert <eric_lambert@xyratex.com>2014-09-10 17:13:45 -0700
commit512353f8be456f9f8045faafbdb3356a4dbdb8ad (patch)
tree7081b07e838b6def308551c237411c1101fd0925
parentcafa07b224255874a80b776fa5574971fbaabca3 (diff)
downloadliberasurecode-512353f8be456f9f8045faafbdb3356a4dbdb8ad.tar.gz
Compile in pedantic mode and fail compilation on warnings. Also cleanup all existing warnings.
-rw-r--r--configure.ac4
-rw-r--r--include/erasurecode/alg_sig.h4
-rw-r--r--include/erasurecode/erasurecode.h21
-rw-r--r--include/erasurecode/erasurecode_helpers.h2
-rw-r--r--include/erasurecode/erasurecode_postprocessing.h6
-rw-r--r--include/xor_codes/xor_code.h4
-rw-r--r--src/backends/jerasure/jerasure_rs_cauchy.c90
-rw-r--r--src/backends/jerasure/jerasure_rs_vand.c68
-rw-r--r--src/backends/null/null.c68
-rw-r--r--src/backends/xor/flat_xor_hd.c21
-rw-r--r--src/builtin/null_code/null_code.c2
-rw-r--r--src/builtin/xor_codes/xor_hd_code.c1
-rw-r--r--src/erasurecode.c26
-rw-r--r--src/erasurecode_helpers.c4
-rw-r--r--src/erasurecode_postprocessing.c2
-rw-r--r--src/utils/chksum/alg_sig.c21
-rw-r--r--test/builtin/xor_codes/test_xor_hd_code.c10
-rw-r--r--test/libec_slap.c16
-rw-r--r--test/liberasurecode_test.c5
-rw-r--r--test/utils/chksum/test_alg_sig.c1
20 files changed, 225 insertions, 151 deletions
diff --git a/configure.ac b/configure.ac
index 80e1ab4..4b5e6e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,11 +42,11 @@ esac],[debug=false])
if test x$debug = xtrue ; then
DEBUG=1
CXXFLAGS=""
- CFLAGS="-O0 -ggdb -g3 -Werror -D_GNU_SOURCE=1"
+ CFLAGS="-O0 -ggdb -g3 -Werror -D_GNU_SOURCE=1 -Wall -pedantic -std=c99"
else
DEBUG=0
CXXFLAGS=""
- CFLAGS="-O2 -g -Werror -D_GNU_SOURCE=1"
+ CFLAGS="-O2 -g -Werror -D_GNU_SOURCE=1 -Wall -pedantic -std=c99"
fi
AC_ARG_ENABLE([gcov],
diff --git a/include/erasurecode/alg_sig.h b/include/erasurecode/alg_sig.h
index eba9ed4..9c97ec0 100644
--- a/include/erasurecode/alg_sig.h
+++ b/include/erasurecode/alg_sig.h
@@ -25,8 +25,10 @@
#ifndef _ALG_SIG_H
#define _ALG_SIG_H
+typedef int (*galois_single_multiply_func)(int, int, int);
+
struct jerasure_mult_routines {
- int (*galois_single_multiply)(int, int, int);
+ galois_single_multiply_func galois_single_multiply;
};
#define JERASURE_SONAME "libJerasure.dylib"
diff --git a/include/erasurecode/erasurecode.h b/include/erasurecode/erasurecode.h
index 97a2c65..c63c7dd 100644
--- a/include/erasurecode/erasurecode.h
+++ b/include/erasurecode/erasurecode.h
@@ -47,17 +47,6 @@ typedef enum {
EC_BACKENDS_MAX,
} ec_backend_id_t;
-#ifndef EC_BACKENDS_SUPPORTED
-#define EC_BACKENDS_SUPPORTED
-/* Supported EC backends */
-static const char *ec_backend_names[EC_BACKENDS_MAX] = {
- "null",
- "jerasure_rs_vand",
- "jerasure_rs_cauchy",
- "flat_xor_hd",
-};
-#endif // EC_BACKENDS_SUPPORTED
-
/* ~=*=~==~=*=~= EC Fragment metadata - supported checksum types ~=*=~==~=*=~ */
/* Checksum types supported for fragment metadata stored in each fragment */
@@ -68,16 +57,6 @@ typedef enum {
CHKSUM_TYPES_MAX,
} ec_checksum_type_t;
-#ifndef EC_CHKSUM_TYPES_SUPPORTED
-#define EC_CHKSUM_TYPES_SUPPORTED
-/* Supported EC backends */
-static const char *ec_chksum_types[CHKSUM_TYPES_MAX] = {
- "none",
- "crc32",
- "md5",
-};
-#endif // EC_CHKSUM_TYPES_SUPPORTED
-
/* =~=*=~==~=*=~== EC Arguments - Common and backend-specific =~=*=~==~=*=~== */
/**
diff --git a/include/erasurecode/erasurecode_helpers.h b/include/erasurecode/erasurecode_helpers.h
index 428460f..60d871f 100644
--- a/include/erasurecode/erasurecode_helpers.h
+++ b/include/erasurecode/erasurecode_helpers.h
@@ -135,7 +135,7 @@ int get_fragment_payload_size(char *buf);
int set_orig_data_size(char *buf, int orig_data_size);
int get_orig_data_size(char *buf);
int validate_fragment(char *buf);
-int set_checksum(char *buf, int chksum);
+int set_checksum(char *buf, int blocksize);
int get_checksum(char *buf);
/* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */
diff --git a/include/erasurecode/erasurecode_postprocessing.h b/include/erasurecode/erasurecode_postprocessing.h
index b6c7b2f..e57ccca 100644
--- a/include/erasurecode/erasurecode_postprocessing.h
+++ b/include/erasurecode/erasurecode_postprocessing.h
@@ -30,7 +30,11 @@
#define _ERASURECODE_POSTPROCESSING_H_
int finalize_fragments_after_encode(ec_backend_t instance,
- int k, int m, int blocksize,
+ int k, int m, int blocksize, uint64_t orig_data_size,
char **encoded_data, char **encoded_parity);
+void add_fragment_metadata(char *fragment,
+ int idx, uint64_t orig_data_size, int blocksize,
+ int add_chksum);
+
#endif
diff --git a/include/xor_codes/xor_code.h b/include/xor_codes/xor_code.h
index 8a4a528..7eaf39a 100644
--- a/include/xor_codes/xor_code.h
+++ b/include/xor_codes/xor_code.h
@@ -54,8 +54,8 @@ typedef struct xor_code_s
int k;
int m;
int hd;
- int *parity_bms;
- int *data_bms;
+ unsigned int *parity_bms;
+ unsigned int *data_bms;
int (*decode)(struct xor_code_s *code_desc, char **data, char **parity, int *missing_idxs, int blocksize, int decode_parity);
void (*encode)(struct xor_code_s *code_desc, char **data, char **parity, int blocksize);
int (*fragments_needed)(struct xor_code_s *code_desc, int *missing_idxs, int *fragments_to_exclude, int *fragments_needed);
diff --git a/src/backends/jerasure/jerasure_rs_cauchy.c b/src/backends/jerasure/jerasure_rs_cauchy.c
index 40a6f11..042166a 100644
--- a/src/backends/jerasure/jerasure_rs_cauchy.c
+++ b/src/backends/jerasure/jerasure_rs_cauchy.c
@@ -37,6 +37,17 @@
struct ec_backend_op_stubs jerasure_rs_cauchy_ops;
struct ec_backend jerasure_rs_cauchy;
+typedef int* (*cauchy_original_coding_matrix_func)(int, int, int);
+typedef int* (*jerasure_matrix_to_bitmatrix_func)(int, int, int, int *);
+typedef int** (*jerasure_smart_bitmatrix_to_schedule_func)(int, int, int, int *);
+typedef void (*jerasure_bitmatrix_encode_func)(int, int, int, int *, char **, char **, int, int);
+typedef int (*jerasure_bitmatrix_decode_func)(int, int, int, int *, int, int *,char **, char **, int, int);
+typedef int * (*jerasure_erasures_to_erased_func)(int, int, int *);
+typedef int (*jerasure_make_decoding_bitmatrix_func)(int, int, int, int *, int *, int *, int *);
+typedef void (*jerasure_bitmatrix_dotprod_func)(int, int, int *, int *, int,char **, char **, int, int);
+
+
+
/*
* ToDo (KMG): Should we make this a parameter, or is that
* exposing too much b.s. to the client?
@@ -45,22 +56,22 @@ struct ec_backend jerasure_rs_cauchy;
struct jerasure_rs_cauchy_descriptor {
/* calls required for init */
- int * (*cauchy_original_coding_matrix)(int, int, int);
- int * (*jerasure_matrix_to_bitmatrix)(int, int, int, int*);
- int ** (*jerasure_smart_bitmatrix_to_schedule)(int, int, int, int*);
-
+ cauchy_original_coding_matrix_func cauchy_original_coding_matrix;
+ jerasure_matrix_to_bitmatrix_func jerasure_matrix_to_bitmatrix;
+ jerasure_smart_bitmatrix_to_schedule_func jerasure_smart_bitmatrix_to_schedule;
+
/* calls required for encode */
- void (*jerasure_bitmatrix_encode)(int, int, int, int *, char **, char **, int, int);
+ jerasure_bitmatrix_encode_func jerasure_bitmatrix_encode;
/* calls required for decode */
- int (*jerasure_bitmatrix_decode)(int, int, int, int *, int, int *,char **, char **, int, int);
+ jerasure_bitmatrix_decode_func jerasure_bitmatrix_decode;
/* calls required for reconstruct */
- int * (*jerasure_erasures_to_erased)(int, int, int *);
- int (*jerasure_make_decoding_bitmatrix)(int, int, int, int *, int *, int *, int *);
- void (*jerasure_bitmatrix_dotprod)(int, int, int *, int *, int,char **, char **, int, int);
+ jerasure_erasures_to_erased_func jerasure_erasures_to_erased;
+ jerasure_make_decoding_bitmatrix_func jerasure_make_decoding_bitmatrix;
+ jerasure_bitmatrix_dotprod_func jerasure_bitmatrix_dotprod;
/* fields needed to hold state */
int *matrix;
@@ -93,7 +104,7 @@ static int jerasure_rs_cauchy_decode(void *desc, char **data, char **parity,
(struct jerasure_rs_cauchy_descriptor*)desc;
/* FIXME - make jerasure_matrix_decode return a value */
- jerasure_desc->jerasure_bitmatrix_decode(jerasure_desc->k,
+ return jerasure_desc->jerasure_bitmatrix_decode(jerasure_desc->k,
jerasure_desc->m,
jerasure_desc->w,
jerasure_desc->bitmatrix,
@@ -181,7 +192,6 @@ static int jerasure_rs_cauchy_min_fragments(void *desc, int *missing_idxs,
}
}
-out:
return ret;
}
@@ -221,52 +231,77 @@ static void * jerasure_rs_cauchy_init(struct ec_backend_args *args,
goto error;
}
}
+
+ /*
+ * 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;
+ 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 */
- desc->jerasure_bitmatrix_encode = dlsym(
- backend_sohandle, "jerasure_bitmatrix_encode");
+ 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;
}
- desc->jerasure_bitmatrix_decode = dlsym(
- backend_sohandle, "jerasure_bitmatrix_decode");
+ 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;
}
- desc->cauchy_original_coding_matrix = dlsym(
- backend_sohandle, "cauchy_original_coding_matrix");
+ 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;
}
- desc->jerasure_matrix_to_bitmatrix = dlsym(
- backend_sohandle, "jerasure_matrix_to_bitmatrix");
+ 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;
}
- desc->jerasure_smart_bitmatrix_to_schedule = dlsym(
- backend_sohandle, "jerasure_smart_bitmatrix_to_schedule");
+ 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;
}
- desc->jerasure_make_decoding_bitmatrix = dlsym(
- backend_sohandle, "jerasure_make_decoding_bitmatrix");
+ 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;
}
- desc->jerasure_bitmatrix_dotprod = dlsym(
- backend_sohandle, "jerasure_bitmatrix_dotprod");
+ 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;
}
- desc->jerasure_erasures_to_erased = dlsym(
- backend_sohandle, "jerasure_erasures_to_erased");
+ 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;
}
@@ -324,6 +359,7 @@ static int jerasure_rs_cauchy_exit(void *desc)
free(jerasure_desc->schedule);
}
free(desc);
+ return 0;
}
struct ec_backend_op_stubs jerasure_rs_cauchy_op_stubs = {
diff --git a/src/backends/jerasure/jerasure_rs_vand.c b/src/backends/jerasure/jerasure_rs_vand.c
index 3392a24..5866cd5 100644
--- a/src/backends/jerasure/jerasure_rs_vand.c
+++ b/src/backends/jerasure/jerasure_rs_vand.c
@@ -37,20 +37,27 @@
struct ec_backend_op_stubs jerasure_rs_vand_ops;
struct ec_backend jerasure_rs_vand;
+typedef int* (*reed_sol_vandermonde_coding_matrix_func)(int, int, int);
+typedef void (*jerasure_matrix_encode_func)(int, int, int, int*, char **, char **, int);
+typedef int (*jerasure_matrix_decode_func)(int, int, int, int *, int, int*, char **, char **, int);
+typedef int (*jerasure_make_decoding_matrix_func)(int, int, int, int *, int *, int *, int *);
+typedef int * (*jerasure_erasures_to_erased_func)(int, int, int *);
+typedef void (*jerasure_matrix_dotprod_func)(int, int, int *,int *, int,char **, char **, int);
+
struct jerasure_rs_vand_descriptor {
/* calls required for init */
- int * (*reed_sol_vandermonde_coding_matrix)(int, int, int);
+ reed_sol_vandermonde_coding_matrix_func reed_sol_vandermonde_coding_matrix;
/* calls required for encode */
- void (*jerasure_matrix_encode)(int, int, int, int*, char **, char **, int);
+ jerasure_matrix_encode_func jerasure_matrix_encode;
/* calls required for decode */
- int (*jerasure_matrix_decode)(int, int, int, int *, int, int*, char **, char **, int);
+ jerasure_matrix_decode_func jerasure_matrix_decode;
/* calls required for reconstruct */
- int (*jerasure_make_decoding_matrix)(int, int, int, int *, int *, int *, int *);
- int * (*jerasure_erasures_to_erased)(int, int, int *);
- void (*jerasure_matrix_dotprod)(int, int, int *,int *, int,char **, char **, int);
+ jerasure_make_decoding_matrix_func jerasure_make_decoding_matrix;
+ jerasure_erasures_to_erased_func jerasure_erasures_to_erased;
+ jerasure_matrix_dotprod_func jerasure_matrix_dotprod;
/* fields needed to hold state */
int *matrix;
@@ -161,7 +168,6 @@ static int jerasure_rs_vand_min_fragments(void *desc, int *missing_idxs,
}
}
-out:
return ret;
}
@@ -198,39 +204,61 @@ 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;
+ 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 */
- desc->jerasure_matrix_encode = dlsym(
- backend_sohandle, "jerasure_matrix_encode");
+ 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;
}
- desc->jerasure_matrix_decode = dlsym(
- backend_sohandle, "jerasure_matrix_decode");
+ 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;
}
- desc->jerasure_make_decoding_matrix = dlsym(
- backend_sohandle, "jerasure_make_decoding_matrix");
+ 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;
}
- desc->jerasure_matrix_dotprod = dlsym(
- backend_sohandle, "jerasure_matrix_dotprod");
+ 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;
}
- desc->jerasure_erasures_to_erased = dlsym(
- backend_sohandle, "jerasure_erasures_to_erased");
+ 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;
}
- desc->reed_sol_vandermonde_coding_matrix = dlsym(
- backend_sohandle, "reed_sol_vandermonde_coding_matrix");
+ 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;
}
@@ -273,6 +301,8 @@ static int jerasure_rs_vand_exit(void *desc)
jerasure_desc = (struct jerasure_rs_vand_descriptor*) desc;
free(jerasure_desc);
+
+ return 0;
}
struct ec_backend_op_stubs jerasure_rs_vand_op_stubs = {
diff --git a/src/backends/null/null.c b/src/backends/null/null.c
index ab4215f..f71312c 100644
--- a/src/backends/null/null.c
+++ b/src/backends/null/null.c
@@ -36,25 +36,27 @@
struct ec_backend null;
struct ec_backend_op_stubs null_ops;
+typedef void* (*init_null_code_func)(int, int, int);
+typedef int (*null_code_encode_func)(void *, char **, char **, int);
+typedef int (*null_code_decode_func)(void *, char **, char **, int *, int, int);
+typedef int (*null_reconstruct_func)(char **, int, uint64_t, int, char *);
+typedef int (*null_code_fragments_needed_func)(void *, int *, int *, int *);
+
struct null_descriptor {
/* calls required for init */
- void* (*init_null_code)(int k, int m, int hd);
+ init_null_code_func init_null_code;
/* calls required for encode */
- int (*null_code_encode)(void *code_desc, char **data, char **parity,
- int blocksize);
+ null_code_encode_func null_code_encode;
/* calls required for decode */
- int (*null_code_decode)(void *code_desc, char **data, char **parity,
- int *missing_idxs, int blocksize, int decode_parity);
+ null_code_decode_func null_code_decode;
/* calls required for reconstruct */
- int (*null_reconstruct)(char **available_fragments, int num_fragments,
- uint64_t fragment_len, int destination_idx, char* out_fragment);
+ null_reconstruct_func null_reconstruct;
/* set of fragments needed to reconstruct at a minimum */
- int (*null_code_fragments_needed)(void *code_desc, int *missing_idxs,
- int *fragments_to_exclude, int *fragments_needed);
+ null_code_fragments_needed_func null_code_fragments_needed;
/* fields needed to hold state */
int *matrix;
@@ -68,32 +70,24 @@ struct null_descriptor {
static int null_encode(void *desc, char **data, char **parity, int blocksize)
{
- struct null_descriptor *xdesc = (struct null_descriptor *) desc;
-
return 0;
}
static int null_decode(void *desc, char **data, char **parity,
int *missing_idxs, int blocksize)
{
- struct null_descriptor *xdesc = (struct null_descriptor *) desc;
-
return 0;
}
static int null_reconstruct(void *desc, char **data, char **parity,
int *missing_idxs, int destination_idx, int blocksize)
{
- struct null_descriptor *xdesc = (struct null_descriptor *) desc;
-
return 0;
}
static int null_min_fragments(void *desc, int *missing_idxs,
int *fragments_to_exclude, int *fragments_needed)
{
- struct null_descriptor *xdesc = (struct null_descriptor *) desc;
-
return 0;
}
@@ -143,33 +137,52 @@ static void * null_init(struct ec_backend_args *args, void *backend_sohandle)
}
}
+ /*
+ * 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 {
+ init_null_code_func initp;
+ null_code_encode_func encodep;
+ null_code_decode_func decodep;
+ null_reconstruct_func reconp;
+ null_code_fragments_needed_func fragsneededp;
+ void *vptr;
+ } func_handle = {.vptr = NULL};
+
/* fill in function addresses */
- xdesc->init_null_code = dlsym(
- backend_sohandle, "null_code_init");
+ func_handle.vptr = NULL;
+ func_handle.vptr = dlsym(backend_sohandle, "null_code_init");
+ xdesc->init_null_code = func_handle.initp;
if (NULL == xdesc->init_null_code) {
goto error;
}
- xdesc->null_code_encode = dlsym(
- backend_sohandle, "null_code_encode");
+ func_handle.vptr = NULL;
+ func_handle.vptr = dlsym(backend_sohandle, "null_code_encode");
+ xdesc->null_code_encode = func_handle.encodep;
if (NULL == xdesc->null_code_encode) {
goto error;
}
- xdesc->null_code_decode = dlsym(
- backend_sohandle, "null_code_decode");
+ func_handle.vptr = NULL;
+ func_handle.vptr = dlsym(backend_sohandle, "null_code_decode");
+ xdesc->null_code_decode = func_handle.decodep;
if (NULL == xdesc->null_code_decode) {
goto error;
}
- xdesc->null_reconstruct = dlsym(
- backend_sohandle, "null_reconstruct");
+ func_handle.vptr = NULL;
+ func_handle.vptr = dlsym(backend_sohandle, "null_reconstruct");
+ xdesc->null_reconstruct = func_handle.reconp;
if (NULL == xdesc->null_reconstruct) {
goto error;
}
- xdesc->null_code_fragments_needed = dlsym(
- backend_sohandle, "null_code_fragments_needed");
+ func_handle.vptr = NULL;
+ func_handle.vptr = dlsym(backend_sohandle, "null_code_fragments_needed");
+ xdesc->null_code_fragments_needed = func_handle.fragsneededp;
if (NULL == xdesc->null_code_fragments_needed) {
goto error;
}
@@ -187,6 +200,7 @@ static int null_exit(void *desc)
struct null_descriptor *xdesc = (struct null_descriptor *) desc;
free (xdesc);
+ return 0;
}
struct ec_backend_op_stubs null_op_stubs = {
diff --git a/src/backends/xor/flat_xor_hd.c b/src/backends/xor/flat_xor_hd.c
index a9faf2c..289f36e 100644
--- a/src/backends/xor/flat_xor_hd.c
+++ b/src/backends/xor/flat_xor_hd.c
@@ -37,16 +37,17 @@
struct ec_backend_op_stubs flat_xor_hd_ops;
struct ec_backend flat_xor_hd;
+typedef xor_code_t* (*init_xor_hd_code_func)(int, int, int);
+typedef void (*xor_code_encode_func)(xor_code_t *, char **, char **, int);
+typedef int (*xor_code_decode_func)(xor_code_t *, char **, char **, int *, int, int);
+typedef int (*xor_hd_fragments_needed_func)(xor_code_t *, int *, int *, int *);
+
struct flat_xor_hd_descriptor {
xor_code_t *xor_desc;
-
- xor_code_t* (*init_xor_hd_code)(int k, int m, int hd);
- void (*xor_code_encode)(xor_code_t *code_desc, char **data, char **parity,
- int blocksize);
- int (*xor_hd_decode)(xor_code_t *code_desc, char **data, char **parity,
- int *missing_idxs, int blocksize, int decode_parity);
- int (*xor_hd_fragments_needed)(xor_code_t *code_desc, int *missing_idxs,
- int *fragments_to_exclude, int *fragments_needed);
+ init_xor_hd_code_func init_xor_hd_code;
+ xor_code_encode_func xor_code_encode;
+ xor_code_decode_func xor_code_decode;
+ xor_hd_fragments_needed_func xor_hd_fragments_needed;
};
#define DEFAULT_W 32
@@ -59,6 +60,7 @@ static int flat_xor_hd_encode(void *desc,
xor_code_t *xor_desc = (xor_code_t *) xdesc->xor_desc;
xor_desc->encode(xor_desc, data, parity, blocksize);
+ return 0;
}
static int flat_xor_hd_decode(void *desc,
@@ -69,7 +71,7 @@ static int flat_xor_hd_decode(void *desc,
(struct flat_xor_hd_descriptor *) desc;
xor_code_t *xor_desc = (xor_code_t *) xdesc->xor_desc;
- xor_desc->decode(xor_desc, data, parity, missing_idxs, blocksize, 1);
+ return xor_desc->decode(xor_desc, data, parity, missing_idxs, blocksize, 1);
}
static int flat_xor_hd_reconstruct(void *desc,
@@ -145,6 +147,7 @@ static int flat_xor_hd_exit(void *desc)
free (bdesc->xor_desc);
free (bdesc);
+ return 0;
}
struct ec_backend_op_stubs flat_xor_hd_op_stubs = {
diff --git a/src/builtin/null_code/null_code.c b/src/builtin/null_code/null_code.c
index 8dfa542..0357df6 100644
--- a/src/builtin/null_code/null_code.c
+++ b/src/builtin/null_code/null_code.c
@@ -26,12 +26,14 @@
* vi: set noai tw=79 ts=4 sw=4:
*/
+#include <stdlib.h>
#include <stdint.h>
/* calls required for init */
void* null_code_init(int k, int m, int hd)
{
/* add your code here */
+ return NULL;
}
/* calls required for encode */
diff --git a/src/builtin/xor_codes/xor_hd_code.c b/src/builtin/xor_codes/xor_hd_code.c
index 9407c75..d072099 100644
--- a/src/builtin/xor_codes/xor_hd_code.c
+++ b/src/builtin/xor_codes/xor_hd_code.c
@@ -58,7 +58,6 @@ static int fragments_needed_two_data(xor_code_t *code_desc, int *missing_data, i
// Verify that missing_data[2] == -1?
int data_index = missing_data[0];
int parity_index = index_of_connected_parity(code_desc, data_index, missing_parity, missing_data);
- int i;
int ret;
if (parity_index < 0) {
diff --git a/src/erasurecode.c b/src/erasurecode.c
index 4e6bd95..f4d7cab 100644
--- a/src/erasurecode.c
+++ b/src/erasurecode.c
@@ -31,7 +31,9 @@
#include "erasurecode_backend.h"
#include "erasurecode_helpers.h"
#include "erasurecode_preprocessing.h"
+#include "erasurecode_postprocessing.h"
#include "erasurecode_stdinc.h"
+#include "erasurecode/alg_sig.h"
/* =~=*=~==~=*=~==~=*=~= Supported EC backends =~=*=~==~=*=~==~=*=~==~=*=~== */
@@ -41,6 +43,12 @@ extern struct ec_backend_common backend_flat_xor_hd;
extern struct ec_backend_common backend_jerasure_rs_vand;
extern struct ec_backend_common backend_jerasure_rs_cauchy;
+static const char *ec_chksum_types[CHKSUM_TYPES_MAX] = {
+ "none",
+ "crc32",
+ "md5",
+};
+
ec_backend_t ec_backends_supported[] = {
(ec_backend_t) &backend_null,
(ec_backend_t) &backend_jerasure_rs_vand,
@@ -171,9 +179,8 @@ int liberasurecode_backend_instance_unregister(ec_backend_t instance)
} else {
goto exit;
}
-
-register_out:
rwlock_unlock(&active_instances_rwlock);
+
exit:
return rc;
}
@@ -192,7 +199,6 @@ static void print_dlerror(const char *caller)
/* Generic dlopen/dlclose routines */
int liberasurecode_backend_open(ec_backend_t instance)
{
- void *handle = NULL;
if (instance && NULL != instance->desc.backend_sohandle)
return 0;
@@ -440,13 +446,10 @@ int liberasurecode_encode(int desc,
char ***encoded_data, char ***encoded_parity, /* output */
uint64_t *fragment_len) /* output */
{
- int i;
int k, m;
int ret = 0; /* return code */
int blocksize = 0; /* length of each of k data elements */
- int data_len; /* data len to write to fragment headers */
- int aligned_data_len; /* EC algorithm compatible data length */
if (orig_data == NULL) {
log_error("Pointer to data buffer is null!");
@@ -541,7 +544,6 @@ out:
*/
int liberasurecode_decode_cleanup(int desc, char *data)
{
- int i;
ec_backend_t instance = liberasurecode_backend_instance_get_by_desc(desc);
if (NULL == instance) {
return -EBACKENDNOTAVAIL;
@@ -572,7 +574,7 @@ int liberasurecode_decode(int desc,
int i, j;
int ret = 0;
- int k, m;
+ int k = -1, m = -1;
int orig_data_size = 0;
int blocksize = 0;
@@ -762,13 +764,13 @@ int liberasurecode_reconstruct_fragment(int desc,
char **parity = NULL;
int *missing_idxs = NULL;
char *fragment_ptr = NULL;
- int k;
- int m;
+ int k = -1;
+ int m = -1;
int i;
- int j;
uint64_t realloc_bm = 0;
char **data_segments = NULL;
char **parity_segments = NULL;
+ int set_chksum = 1;
ec_backend_t instance = liberasurecode_backend_instance_get_by_desc(desc);
if (NULL == instance) {
@@ -863,7 +865,7 @@ int liberasurecode_reconstruct_fragment(int desc,
}
init_fragment_header(fragment_ptr);
add_fragment_metadata(fragment_ptr, destination_idx, orig_data_size,
- blocksize);
+ blocksize, !set_chksum);
/*
* Copy the reconstructed fragment to the output buffer
diff --git a/src/erasurecode_helpers.c b/src/erasurecode_helpers.c
index 7861ac1..d4484ce 100644
--- a/src/erasurecode_helpers.c
+++ b/src/erasurecode_helpers.c
@@ -31,6 +31,7 @@
#include "erasurecode_backend.h"
#include "erasurecode_helpers.h"
#include "erasurecode_stdinc.h"
+#include "erasurecode/alg_sig.h"
/* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */
@@ -169,7 +170,6 @@ uint64_t get_fragment_size(char *buf)
int get_aligned_data_size(ec_backend_t instance, int data_len)
{
int k = instance->args.uargs.k;
- int m = instance->args.uargs.m;
int w = instance->args.uargs.w;
int word_size = w / 8;
int alignment_multiple;
@@ -341,7 +341,7 @@ int validate_fragment(char *buf)
/* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */
-inline int set_chksum(char *buf, int blocksize)
+inline int set_checksum(char *buf, int blocksize)
{
fragment_header_t* header = (fragment_header_t*) buf;
char *data = get_data_ptr_from_fragment(buf);
diff --git a/src/erasurecode_postprocessing.c b/src/erasurecode_postprocessing.c
index d8b4005..864d474 100644
--- a/src/erasurecode_postprocessing.c
+++ b/src/erasurecode_postprocessing.c
@@ -38,7 +38,7 @@ void add_fragment_metadata(char *fragment,
set_orig_data_size(fragment, orig_data_size);
set_fragment_payload_size(fragment, blocksize);
if (add_chksum) {
- set_chksum(fragment, blocksize);
+ set_checksum(fragment, blocksize);
}
}
diff --git a/src/utils/chksum/alg_sig.c b/src/utils/chksum/alg_sig.c
index bfaa4a1..07a9683 100644
--- a/src/utils/chksum/alg_sig.c
+++ b/src/utils/chksum/alg_sig.c
@@ -27,10 +27,25 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#define GALOIS_SINGLE_MULTIPLY "galois_single_multiply"
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;
+}
+
void *get_jerasure_sohandle()
{
return dlopen(JERASURE_SONAME, RTLD_LAZY | RTLD_LOCAL);
@@ -38,7 +53,7 @@ void *get_jerasure_sohandle()
int load_gf_functions(void *sohandle, struct jerasure_mult_routines *routines)
{
- routines->galois_single_multiply = dlsym(sohandle, "galois_single_multiply");
+ routines->galois_single_multiply = get_galois_multi_func(sohandle);
if (NULL == routines->galois_single_multiply) {
return -1;
}
@@ -54,7 +69,6 @@ alg_sig_t *init_alg_sig_w8(void *jerasure_sohandle, int sig_len)
int w = 8;
int alpha = 2, beta = 4, gamma = 8;
int num_components = sig_len / w;
- struct jerasure_mult_routines g_jerasure_mult_routines;
alg_sig_handle = (alg_sig_t *)malloc(sizeof(alg_sig_t));
if (NULL == alg_sig_handle) {
@@ -226,10 +240,7 @@ void destroy_alg_sig(alg_sig_t* alg_sig_handle)
static
int compute_w8_alg_sig_32(alg_sig_t *alg_sig_handle, char *buf, int len, char *sig)
{
- int bit_mask;
int i;
- int alpha = 2, beta = 4, gamma = 8;
- int w = 8;
if (len == 0) {
bzero(sig, 4);
diff --git a/test/builtin/xor_codes/test_xor_hd_code.c b/test/builtin/xor_codes/test_xor_hd_code.c
index f6d9db2..497b052 100644
--- a/test/builtin/xor_codes/test_xor_hd_code.c
+++ b/test/builtin/xor_codes/test_xor_hd_code.c
@@ -29,7 +29,7 @@
#include <xor_code.h>
#include "test_xor_hd_code.h"
-void fill_buffer(unsigned char *buf, int size, int seed)
+void fill_buffer(char *buf, int size, int seed)
{
int i;
@@ -79,7 +79,7 @@ int test_hd_code(xor_code_t *code_desc, int num_failure_combs, int failure_combs
parity = (char**)malloc(code_desc->m * sizeof(char*));
fragments_needed = (int*)malloc(code_desc->k*code_desc->m*sizeof(int));
if (!fragments_needed) {
- fprintf(stderr, "Could not allocate memory for fragments %d\n", i);
+ fprintf(stderr, "Could not allocate memory for fragments\n");
exit(2);
}
@@ -178,15 +178,15 @@ int test_hd_code(xor_code_t *code_desc, int num_failure_combs, int failure_combs
code_desc->decode(code_desc, data, parity, missing_idxs, blocksize, 1);
- if (missing_idxs[0] > -1 && missing_idxs[0] < code_desc->k && check_buffer(data[missing_idx_0], blocksize, missing_idx_0) < 0) {
+ if (missing_idxs[0] > -1 && missing_idxs[0] < code_desc->k && check_buffer((unsigned char *)data[missing_idx_0], blocksize, missing_idx_0) < 0) {
fprintf(stderr, "Decode did not work: %d (%d %d %d)!\n", missing_idxs[0], missing_idxs[0], missing_idxs[1], missing_idxs[2]);
exit(2);
}
- if (missing_idxs[1] > -1 && missing_idxs[1] < code_desc->k && check_buffer(data[missing_idx_1], blocksize, missing_idx_1) < 0) {
+ if (missing_idxs[1] > -1 && missing_idxs[1] < code_desc->k && check_buffer((unsigned char *)data[missing_idx_1], blocksize, missing_idx_1) < 0) {
fprintf(stderr, "Decode did not work: %d (%d %d %d)!\n", missing_idxs[1], missing_idxs[0], missing_idxs[1], missing_idxs[2]);
exit(2);
}
- if (missing_idxs[2] > -1 && missing_idxs[2] < code_desc->k && check_buffer(data[missing_idx_2], blocksize, missing_idx_2) < 0) {
+ if (missing_idxs[2] > -1 && missing_idxs[2] < code_desc->k && check_buffer((unsigned char *)data[missing_idx_2], blocksize, missing_idx_2) < 0) {
fprintf(stderr, "Decode did not work: %d (%d %d %d)!\n", missing_idxs[2], missing_idxs[0], missing_idxs[1], missing_idxs[2]);
exit(2);
}
diff --git a/test/libec_slap.c b/test/libec_slap.c
index 3c5426c..bf1ec21 100644
--- a/test/libec_slap.c
+++ b/test/libec_slap.c
@@ -67,7 +67,7 @@ void print_mask(unsigned long mask)
fprintf(stderr,"\n");
}
-void missing_mask_to_array(unsigned long mask, unsigned int *missing)
+void missing_mask_to_array(long mask, int *missing)
{
unsigned int i = 0;
unsigned long pos = 1;
@@ -100,7 +100,6 @@ static int create_frags_array_set(struct frag_array_set *set,
unsigned int num_frags = 0;
unsigned long i = 0;
fragment_header_t *header = NULL;
- char **ptr = NULL;
size_t size = (num_data_frags + num_parity_frags) * sizeof(char *);
char **array = malloc(size);
@@ -142,9 +141,9 @@ out:
return rc;
}
-static void fill_buffer(unsigned char *buf, size_t size, int seed)
+static void fill_buffer(char *buf, size_t size, int seed)
{
- size_t i;
+ int i;
buf[0] = seed;
for (i=1; i < size; i++) {
@@ -169,13 +168,10 @@ static int test_hd_code(struct ec_args *args,
char **encoded_parity = NULL;
uint64_t encoded_fragment_len = 0;
int rc = 0;
- int num_fragments = args->k + args->m;
- char **available_frags = NULL;
char *out_data = NULL;
uint64_t out_data_len = 0;
unsigned long mask = 0;
int desc = -1;
- unsigned int num_available_frags = 0;
struct frag_array_set frags; //MOVE ME
srand(time(NULL));
@@ -186,17 +182,17 @@ static int test_hd_code(struct ec_args *args,
fragments_needed = (int*)malloc(args->k*args->m*sizeof(int));
if (!fragments_needed) {
- fprintf(stderr, "Could not allocate memory for fragments %d\n", i);
+ fprintf(stderr, "Could not allocate memory for fragments\n");
exit(2);
}
memset(fragments_needed, 0, args->k*args->m*sizeof(int));
err = posix_memalign((void **) &data, 16, blocksize * args->k);
if (err != 0 || !data) {
- fprintf(stderr, "Could not allocate memory for data %d\n", i);
+ fprintf(stderr, "Could not allocate memory for data\n");
exit(1);
}
- fill_buffer(data, blocksize * args->k, i);
+ fill_buffer(data, blocksize * args->k, 0);
parity = (char**)malloc(args->m * sizeof(char*));
for (i=0; i < args->m; i++) {
diff --git a/test/liberasurecode_test.c b/test/liberasurecode_test.c
index ecb7006..13e5925 100644
--- a/test/liberasurecode_test.c
+++ b/test/liberasurecode_test.c
@@ -406,7 +406,6 @@ static void encode_decode_test_impl(const char *backend,
char *orig_data = NULL;
char **encoded_data = NULL, **encoded_parity = NULL;
uint64_t encoded_fragment_len = 0;
- int num_fragments = args-> k + args->m;
uint64_t decoded_data_len = 0;
char *decoded_data = NULL;
size_t frag_header_size = sizeof(fragment_header_t);
@@ -438,7 +437,7 @@ static void encode_decode_test_impl(const char *backend,
assert(metadata.idx == i);
assert(metadata.size == encoded_fragment_len - frag_header_size);
assert(metadata.orig_data_size == orig_data_size);
- unsigned char *data_ptr = frag + frag_header_size;
+ char *data_ptr = frag + frag_header_size;
int cmp_size = remaining >= metadata.size ? metadata.size : remaining;
assert(memcmp(data_ptr, orig_data_ptr, cmp_size) == 0);
remaining -= cmp_size;
@@ -480,8 +479,6 @@ static void reconstruct_test_impl(const char *backend,
char **encoded_data = NULL, **encoded_parity = NULL;
uint64_t encoded_fragment_len = 0;
int num_fragments = args-> k + args->m;
- uint64_t decoded_data_len = 0;
- char *decoded_data = NULL;
char **avail_frags = NULL;
int num_avail_frags = 0;
int i = 0;
diff --git a/test/utils/chksum/test_alg_sig.c b/test/utils/chksum/test_alg_sig.c
index a0ddf4b..5314548 100644
--- a/test/utils/chksum/test_alg_sig.c
+++ b/test/utils/chksum/test_alg_sig.c
@@ -75,7 +75,6 @@ int check_parity_of_sigs(char **sigs, int num_data, int size)
ret = 1;
}
-out:
free(parity_sig);
return ret;