diff options
author | Tushar Gohad <tushar.gohad@intel.com> | 2014-08-20 17:23:01 -0700 |
---|---|---|
committer | Tushar Gohad <tushar.gohad@intel.com> | 2014-08-20 17:32:31 -0700 |
commit | 29d7bda5f56c2edfca1e4ae89a896d58c59e85bd (patch) | |
tree | 3dab00d3a8d124c5c661e4ebcf076155e3511397 | |
parent | d251ed8f98abcbd90eb1f81a09da93d54427efd7 (diff) | |
download | liberasurecode-29d7bda5f56c2edfca1e4ae89a896d58c59e85bd.tar.gz |
Make style consistent (formatting, variable defs)
Signed-off-by: Tushar Gohad <tushar.gohad@intel.com>
-rw-r--r-- | src/erasurecode.c | 32 | ||||
-rw-r--r-- | test/liberasurecode_test.c | 97 |
2 files changed, 66 insertions, 63 deletions
diff --git a/src/erasurecode.c b/src/erasurecode.c index fea3250..c9bf0ad 100644 --- a/src/erasurecode.c +++ b/src/erasurecode.c @@ -192,7 +192,8 @@ int liberasurecode_backend_open(ec_backend_t instance) return 0; /* Use RTLD_LOCAL to avoid symbol collisions */ - instance->desc.backend_sohandle = dlopen(instance->common.soname, RTLD_LAZY | RTLD_LOCAL); + instance->desc.backend_sohandle = dlopen(instance->common.soname, + RTLD_LAZY | RTLD_LOCAL); if (NULL == instance->desc.backend_sohandle) { print_dlerror(__func__); return -EBACKENDNOTAVAIL; @@ -322,8 +323,8 @@ int liberasurecode_instance_create(const char *backend_name, } /* Call private init() for the backend */ - instance->desc.backend_desc = instance->common.ops->init(&instance->args, - instance->desc.backend_sohandle); + instance->desc.backend_desc = instance->common.ops->init( + &instance->args, instance->desc.backend_sohandle); if (NULL == instance->desc.backend_desc) { free (instance); return -EBACKENDINITERR; @@ -379,7 +380,9 @@ int liberasurecode_instance_destroy(int desc) * fragments (char *), allocated by liberasurecode_encode * @return 0 in success; -error otherwise */ -int liberasurecode_encode_cleanup(int desc, char **encoded_data, char **encoded_parity) +int liberasurecode_encode_cleanup(int desc, + char **encoded_data, + char **encoded_parity) { int i, k, m; ec_backend_t instance = liberasurecode_backend_instance_get_by_desc(desc); @@ -744,7 +747,8 @@ int liberasurecode_reconstruct_fragment(int desc, * Separate the fragments into data and parity. Also determine which * pieces are missing. */ - ret = get_fragment_partition(k, m, available_fragments, num_fragments, data, parity, missing_idxs); + ret = get_fragment_partition(k, m, available_fragments, num_fragments, + data, parity, missing_idxs); if (ret < 0) { log_error("Could not properly partition the fragments!"); @@ -752,12 +756,14 @@ int liberasurecode_reconstruct_fragment(int desc, } /* - * Preparing the fragments for reconstruction. This will alloc aligned buffers when unaligned buffers - * were passed in available_fragments. It passes back a bitmap telling us which buffers need to - * be freed by us (realloc_bm). - * + * Preparing the fragments for reconstruction. This will alloc aligned + * buffers when unaligned buffers were passed in available_fragments. + * It passes back a bitmap telling us which buffers need to be freed by + * us (realloc_bm). */ - ret = prepare_fragments_for_decode(k, m, data, parity, missing_idxs, &orig_data_size, &blocksize, fragment_len, &realloc_bm); + ret = prepare_fragments_for_decode(k, m, data, parity, missing_idxs, + &orig_data_size, &blocksize, + fragment_len, &realloc_bm); if (ret < 0) { log_error("Could not prepare fragments for reconstruction!"); goto out; @@ -787,7 +793,8 @@ int liberasurecode_reconstruct_fragment(int desc, fragment_ptr = parity[destination_idx - k]; } init_fragment_header(fragment_ptr); - add_fragment_metadata(fragment_ptr, destination_idx, orig_data_size, blocksize); + add_fragment_metadata(fragment_ptr, destination_idx, orig_data_size, + blocksize); /* * Copy the reconstructed fragment to the output buffer @@ -855,7 +862,8 @@ int liberasurecode_fragments_needed(int desc, /* call the backend fragments_needed function passing it desc instance */ ret = instance->common.ops->fragments_needed( - instance->desc.backend_desc, fragments_to_reconstruct, fragments_needed); + instance->desc.backend_desc, + fragments_to_reconstruct, fragments_needed); out_error: return ret; diff --git a/test/liberasurecode_test.c b/test/liberasurecode_test.c index f82a87b..a90701c 100644 --- a/test/liberasurecode_test.c +++ b/test/liberasurecode_test.c @@ -53,13 +53,11 @@ int *create_skips_array(struct ec_args *args, int skip) int num = args->k + args->m; size_t array_size = sizeof(int) * num; int *buf = malloc(array_size); - if (buf == NULL) - { + if (buf == NULL) { return NULL; } memset(buf, 0, array_size); - if (skip >= 0 && skip < num) - { + if (skip >= 0 && skip < num) { buf[skip] = 1; } return buf; @@ -80,8 +78,7 @@ static int create_frags_array(char ***array, //add data frags int i = 0; char **ptr = *array; - for (i = 0; i < args->k; i++) - { + for (i = 0; i < args->k; i++) { if (data[i] == NULL || skips[i] == 1) { continue; @@ -90,10 +87,8 @@ static int create_frags_array(char ***array, num_frags++; } //add parity frags - for (i = 0; i < args->m; i++) - { - if (parity[i] == NULL || skips[i + args->k] == 1) - { + for (i = 0; i < args->m; i++) { + if (parity[i] == NULL || skips[i + args->k] == 1) { continue; } *ptr++ = parity[i]; @@ -109,8 +104,9 @@ static void test_liberasurecode_supported_backends() const char **supported_ec_backends = liberasurecode_supported_backends(&num_backends); - for (i = 0; i < num_backends; i++) + for (i = 0; i < num_backends; i++) { printf("%s\n", supported_ec_backends[i]); + } } static void test_liberasurecode_supported_checksum_types() @@ -121,8 +117,9 @@ static void test_liberasurecode_supported_checksum_types() liberasurecode_supported_checksum_types(&num_checksum_types); assert(num_checksum_types == CHKSUM_TYPES_MAX); - for (i = 0; i < CHKSUM_TYPES_MAX; i++) + for (i = 0; i < CHKSUM_TYPES_MAX; i++) { printf("%s\n", supported_checksum_types[i]); + } } static void test_create_and_destroy_backend( @@ -151,6 +148,9 @@ static void encode_decode_test_impl(const char *backend, 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; desc = liberasurecode_instance_create(backend, args); if (-EBACKENDNOTAVAIL == desc) { @@ -165,25 +165,25 @@ static void encode_decode_test_impl(const char *backend, &encoded_data, &encoded_parity, &encoded_fragment_len); assert(0 == rc); - char **avail_frags = NULL; - int num_avail_frags = create_frags_array(&avail_frags, encoded_data, - encoded_parity, args, skip); + num_avail_frags = create_frags_array(&avail_frags, encoded_data, + encoded_parity, args, skip); assert(num_avail_frags != -1); - rc = liberasurecode_decode(desc, avail_frags, - num_avail_frags, encoded_fragment_len, &decoded_data, &decoded_data_len); + rc = liberasurecode_decode(desc, avail_frags, num_avail_frags, + encoded_fragment_len, &decoded_data, + &decoded_data_len); assert(0 == rc); assert(decoded_data_len == orig_data_size); assert(memcmp(decoded_data, orig_data, orig_data_size) == 0); - if (desc) + if (desc) { assert(0 == liberasurecode_instance_destroy(desc)); + } + free(orig_data); - if (avail_frags != NULL) - { + if (avail_frags != NULL) { int idx = 0; - for (idx = 0; idx < num_avail_frags; idx++) - { + for (idx = 0; idx < num_avail_frags; idx++) { free(avail_frags[idx]); } free(avail_frags); @@ -204,6 +204,12 @@ static void reconstruct_test_impl(const char *backend, uint64_t decoded_data_len = 0; char *decoded_data = NULL; + char **avail_frags = NULL; + int num_avail_frags = 0; + + int i = 0; + char *out = NULL; + desc = liberasurecode_instance_create(backend, args); if (-EBACKENDNOTAVAIL == desc) { fprintf (stderr, "Backend library not available!\n"); @@ -216,24 +222,19 @@ static void reconstruct_test_impl(const char *backend, rc = liberasurecode_encode(desc, orig_data, orig_data_size, &encoded_data, &encoded_parity, &encoded_fragment_len); assert(rc == 0); - char **avail_frags = NULL; - int num_avail_frags = create_frags_array(&avail_frags, encoded_data, + num_avail_frags = create_frags_array(&avail_frags, encoded_data, encoded_parity, args, skip); - int i = 0; - char *out = malloc(encoded_fragment_len); + out = malloc(encoded_fragment_len); assert(out != NULL); for (i = 0; i < num_fragments; i++) { - if (skip[i] == 0) - { + if (skip[i] == 0) { continue; } char *cmp = NULL; - if (i < args->k) - { + if (i < args->k) { cmp = encoded_data[i]; } - else - { + else { cmp = encoded_parity[i - args->k]; } memset(out, 0, encoded_fragment_len); @@ -278,12 +279,10 @@ static void test_decode_with_missing_multi_data(const char *backend, { int max_num_missing = args->hd; int i,j; - for (i = 0; i < args->k - max_num_missing + 1; i++) - { + for (i = 0; i < args->k - max_num_missing + 1; i++) { int *skip = create_skips_array(args,-1); assert(skip != NULL); - for (j = i; j < i + max_num_missing; j++) - { + for (j = i; j < i + max_num_missing; j++) { skip[j]=1; } encode_decode_test_impl(backend, args, skip); @@ -296,12 +295,10 @@ static void test_decode_with_missing_multi_parity(const char *backend, { int i,j; int max_num_missing = args->hd; - for (i = args->k; i < args->k + args->m - max_num_missing + 1; i++) - { + for (i = args->k; i < args->k + args->m - max_num_missing + 1; i++) { int *skip = create_skips_array(args,-1); assert(skip != NULL); - for (j = i; j < i + max_num_missing; j++) - { + for (j = i; j < i + max_num_missing; j++) { skip[j]=1; } encode_decode_test_impl(backend, args, skip); @@ -315,12 +312,10 @@ static void test_decode_with_missing_multi_data_parity(const char *backend, int i,j; int max_num_missing = args->hd; int start = args->k - max_num_missing + 1; - for (i = start; i < start + max_num_missing -1; i++) - { + for (i = start; i < start + max_num_missing -1; i++) { int *skip = create_skips_array(args,-1); assert(skip != NULL); - for (j = i; j < i + max_num_missing; j++) - { + for (j = i; j < i + max_num_missing; j++) { skip[j]=1; } encode_decode_test_impl(backend, args, skip); @@ -341,8 +336,7 @@ static void test_simple_reconstruct(const char *backend, struct ec_args *args) { int i = 0; - for (i = 0; i < args->k + args->m; i++) - { + for (i = 0; i < args->k + args->m; i++) { int *skip = create_skips_array(args,i); assert(skip != NULL); reconstruct_test_impl(backend, args, skip); @@ -401,11 +395,12 @@ struct testcase testcases[] = { test_create_and_destroy_backend, "jerasure_rs_cauchy", &jerasure_rs_cauchy_args, .skip = false}, - // Flat XOR tests - {"simple_encode_flat_xor_hd", + // NULL backend tests + {"simple_encode_null", test_simple_encode_decode, "null", &null_args, - .skip = true}, + .skip = false}, + // Flat XOR backend tests {"simple_encode_flat_xor_hd", test_simple_encode_decode, "flat_xor_hd", &flat_xor_hd_args, @@ -434,7 +429,7 @@ struct testcase testcases[] = { test_simple_reconstruct, "flat_xor_hd", &flat_xor_hd_args, .skip = false}, - // Jerasure RS Vand tests + // Jerasure RS Vand backend tests {"simple_encode_jerasure_rs_vand", test_simple_encode_decode, "jerasure_rs_vand", &jerasure_rs_vand_args, @@ -459,7 +454,7 @@ struct testcase testcases[] = { test_simple_reconstruct, "jerasure_rs_vand", &jerasure_rs_vand_args, .skip = false}, - // Jerasure RS Cauchy tests + // Jerasure RS Cauchy backend tests {"simple_encode_jerasureFlat XOR tests_rs_cauchy", test_simple_encode_decode, "jerasure_rs_cauchy", &jerasure_rs_cauchy_args, |