diff --git a/Makefile.am b/Makefile.am index 660a0e9..5a22fb7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,6 +19,7 @@ include_HEADERS = \ include/erasurecode/erasurecode.h \ include/erasurecode/erasurecode_backend.h \ include/erasurecode/erasurecode_helpers.h \ + include/erasurecode/erasurecode_log.h \ include/erasurecode/erasurecode_preprocessing.h \ include/erasurecode/erasurecode_postprocessing.h \ include/erasurecode/erasurecode_stdinc.h \ diff --git a/include/erasurecode/erasurecode_helpers.h b/include/erasurecode/erasurecode_helpers.h index 0f72c16..33f777f 100644 --- a/include/erasurecode/erasurecode_helpers.h +++ b/include/erasurecode/erasurecode_helpers.h @@ -32,27 +32,6 @@ #include "erasurecode_backend.h" #include "erasurecode_stdinc.h" -/* ==~=*=~==~=*=~==~=*=~==~=*=~==~= Logging =~==~=*=~==~=*=~==~=*=~==~=*=~== */ - -#if __STDC_VERSION__ < 199901L - #if __GNUC__ >= 2 - #define __func__ __FUNCTION__ - #else - #define __func__ "" - #endif -#endif - -#define _LOG1(level, ...) \ - syslog (level, __VA_ARGS__) - -#define _LOG2(level, ...) \ - syslog (level, "%s:%d:%s\n", __FILE__, __LINE__, __VA_ARGS__) - -#define log_info(...) _LOG1(LOG_INFO, __VA_ARGS__) -#define log_warn(...) _LOG1(LOG_WARNING, __VA_ARGS__) -#define log_error(...) _LOG1(LOG_ERR, __VA_ARGS__) -#define log_debug(...) _LOG2(LOG_DEBUG, __VA_ARGS__) - /* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */ /** diff --git a/include/erasurecode/erasurecode_stdinc.h b/include/erasurecode/erasurecode_stdinc.h index 42697c0..ef9f916 100644 --- a/include/erasurecode/erasurecode_stdinc.h +++ b/include/erasurecode/erasurecode_stdinc.h @@ -26,6 +26,7 @@ #define _ERASURECODE_STDINC_H_ #include "config.h" +#include "erasurecode_log.h" #ifdef HAVE_SYSLOG_H #include diff --git a/include/erasurecode/galois.h b/include/erasurecode/galois.h index 54efb0f..f125278 100644 --- a/include/erasurecode/galois.h +++ b/include/erasurecode/galois.h @@ -82,14 +82,14 @@ void galois_w08_region_multiply(char *region, /* Region to multiply */ Otherwise region is overwritten */ int add); /* If (r2 != NULL && add) the produce is XOR'd with r2 */ -void galois_w16_region_multiply(char *region, /* Region to multiply */ +int galois_w16_region_multiply(char *region, /* Region to multiply */ int multby, /* Number to multiply by */ int nbytes, /* Number of bytes in region */ char *r2, /* If r2 != NULL, products go here. Otherwise region is overwritten */ int add); /* If (r2 != NULL && add) the produce is XOR'd with r2 */ -void galois_w32_region_multiply(char *region, /* Region to multiply */ +int galois_w32_region_multiply(char *region, /* Region to multiply */ int multby, /* Number to multiply by */ int nbytes, /* Number of bytes in region */ char *r2, /* If r2 != NULL, products go here. diff --git a/src/utils/chksum/galois.c b/src/utils/chksum/galois.c index cb04db7..9c4440e 100644 --- a/src/utils/chksum/galois.c +++ b/src/utils/chksum/galois.c @@ -44,11 +44,8 @@ Revision 1.0 - 2007: James S. Plank */ -#include -#include -#include -#include - +#include "erasurecode_log.h" +#include "erasurecode_stdinc.h" #include "galois.h" #ifdef HAVE_LIBGF_COMPLETE @@ -78,26 +75,26 @@ gf_t* galois_init_field(int w, gf_t *gfp; if (w <= 0 || w > 32) { - fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w); - exit(1); + log_error("ERROR -- cannot init default Galois field for w=%d\n", w); + return NULL; } gfp = (gf_t *) malloc(sizeof(gf_t)); if (!gfp) { - fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w); - exit(1); + log_error("ERROR -- cannot allocate memory for Galois field w=%d\n", w); + return NULL; } scratch_size = gf_scratch_size(w, mult_type, region_type, divide_type, arg1, arg2); if (!scratch_size) { - fprintf(stderr, "ERROR -- cannot get scratch size for base field w=%d\n", w); - exit(1); + log_error("ERROR -- cannot get scratch size for base field w=%d\n", w); + return NULL; } scratch_memory = malloc(scratch_size); if (!scratch_memory) { - fprintf(stderr, "ERROR -- cannot get scratch memory for base field w=%d\n", w); - exit(1); + log_error("ERROR -- cannot get scratch memory for base field w=%d\n", w); + return NULL; } if(!gf_init_hard(gfp, @@ -111,8 +108,8 @@ gf_t* galois_init_field(int w, NULL, scratch_memory)) { - fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w); - exit(1); + log_error("ERROR -- cannot init default Galois field for w=%d\n", w); + return NULL; } gfp_is_composite[w] = 0; @@ -130,26 +127,26 @@ gf_t* galois_init_composite_field(int w, gf_t *gfp; if (w <= 0 || w > 32) { - fprintf(stderr, "ERROR -- cannot init composite field for w=%d\n", w); - exit(1); + log_error("ERROR -- cannot init composite field for w=%d\n", w); + return NULL; } gfp = (gf_t *) malloc(sizeof(gf_t)); if (!gfp) { - fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w); - exit(1); + log_error("ERROR -- cannot allocate memory for Galois field w=%d\n", w); + return NULL; } scratch_size = gf_scratch_size(w, GF_MULT_COMPOSITE, region_type, divide_type, degree, 0); if (!scratch_size) { - fprintf(stderr, "ERROR -- cannot get scratch size for composite field w=%d\n", w); - exit(1); + log_error("ERROR -- cannot get scratch size for composite field w=%d\n", w); + return NULL; } scratch_memory = malloc(scratch_size); if (!scratch_memory) { - fprintf(stderr, "ERROR -- cannot get scratch memory for composite field w=%d\n", w); - exit(1); + log_error("ERROR -- cannot get scratch memory for composite field w=%d\n", w); + return NULL; } if(!gf_init_hard(gfp, @@ -163,8 +160,8 @@ gf_t* galois_init_composite_field(int w, base_gf, scratch_memory)) { - fprintf(stderr, "ERROR -- cannot init default composite field for w=%d\n", w); - exit(1); + log_error("ERROR -- cannot init default composite field for w=%d\n", w); + return NULL; } gfp_is_composite[w] = 1; return gfp; @@ -173,21 +170,21 @@ gf_t* galois_init_composite_field(int w, static void galois_init_default_field(int w) { if (w <= 0 || w > 32) { - fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w); - exit(1); + log_error("ERROR -- cannot init default Galois field for w=%d\n", w); + return NULL; } if (gfp_array[w] == NULL) { gfp_array[w] = (gf_t*)malloc(sizeof(gf_t)); if (gfp_array[w] == NULL) { - fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w); - exit(1); + log_error("ERROR -- cannot allocate memory for Galois field w=%d\n", w); + return NULL; } } if (!gf_init_easy(gfp_array[w], w)) { - fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w); - exit(1); + log_error("ERROR -- cannot init default Galois field for w=%d\n", w); + return NULL; } } @@ -224,13 +221,13 @@ static int is_valid_gf(gf_t *gf, int w) void galois_change_technique(gf_t *gf, int w) { if (w <= 0 || w > 32) { - fprintf(stderr, "ERROR -- cannot support Galois field for w=%d\n", w); - exit(1); + log_error("ERROR -- cannot support Galois field for w=%d\n", w); + return NULL; } if (!is_valid_gf(gf, w)) { - fprintf(stderr, "ERROR -- overriding with invalid Galois field for w=%d\n", w); - exit(1); + log_error("ERROR -- overriding with invalid Galois field for w=%d\n", w); + return NULL; } if (gfp_array[w] != NULL) { @@ -251,7 +248,7 @@ int galois_single_multiply(int x, int y, int w) if (w <= 32) { return gfp_array[w]->multiply.w32(gfp_array[w], x, y); } else { - fprintf(stderr, "ERROR -- Galois field not implemented for w=%d\n", w); + log_error("ERROR -- Galois field not implemented for w=%d\n", w); } } @@ -267,7 +264,7 @@ int galois_single_divide(int x, int y, int w) if (w <= 32) { return gfp_array[w]->divide.w32(gfp_array[w], x, y); } else { - fprintf(stderr, "ERROR -- Galois field not implemented for w=%d\n", w); + log_error("ERROR -- Galois field not implemented for w=%d\n", w); } } @@ -488,9 +485,9 @@ int galois_create_log_tables(int w) b = 1; for (j = 0; j < nwm1[w]; j++) { if (galois_log_tables[w][b] != nwm1[w]) { - fprintf(stderr, "Galois_create_log_tables Error: j=%d, b=%d, B->J[b]=%d, J->B[j]=%d (0%o)\n", + log_error("Galois_create_log_tables Error: j=%d, b=%d, B->J[b]=%d, J->B[j]=%d (0%o)\n", j, b, galois_log_tables[w][b], galois_ilog_tables[w][j], (b << 1) ^ prim_poly[w]); - exit(1); + return -1; } galois_log_tables[w][b] = j; galois_ilog_tables[w][j] = b; @@ -585,8 +582,8 @@ int galois_ilog(int value, int w) { if (galois_ilog_tables[w] == NULL) { if (galois_create_log_tables(w) < 0) { - fprintf(stderr, "Error: galois_ilog - w is too big. Sorry\n"); - exit(1); + log_error("Error: galois_ilog - w is too big. Sorry\n"); + return -1; } } return galois_ilog_tables[w][value]; @@ -596,8 +593,8 @@ int galois_log(int value, int w) { if (galois_log_tables[w] == NULL) { if (galois_create_log_tables(w) < 0) { - fprintf(stderr, "Error: galois_log - w is too big. Sorry\n"); - exit(1); + log_error("Error: galois_log - w is too big. Sorry\n"); + return -1; } } return galois_log_tables[w][value]; @@ -644,16 +641,16 @@ int galois_single_multiply(int x, int y, int w) if (mult_type[w] == TABLE) { if (galois_mult_tables[w] == NULL) { if (galois_create_mult_tables(w) < 0) { - fprintf(stderr, "ERROR -- cannot make multiplication tables for w=%d\n", w); - exit(1); + log_error("ERROR -- cannot make multiplication tables for w=%d\n", w); + return -1; } } return galois_mult_tables[w][(x<