33 #include "erasurecode.h"
34 #include "erasurecode_backend.h"
35 #include "erasurecode_helpers.h"
36 #include "erasurecode_helpers_ext.h"
37 #include "isa_l_common.h"
42 isa_l_descriptor *isa_l_desc = (isa_l_descriptor*) desc;
44 unsigned char *g_tbls = isa_l_desc->encode_tables;
45 int k = isa_l_desc->k;
46 int m = isa_l_desc->m;
49 isa_l_desc->ec_encode_data(blocksize, k, m, g_tbls, (
unsigned char**)data,
50 (
unsigned char**)parity);
56 int i = 0, j = 0, l = 0;
58 unsigned char *decode_matrix = malloc(
sizeof(
unsigned char) * k * k);
59 uint64_t missing_bm = convert_list_to_bitmap(missing_idxs);
61 while (i < k && l < n) {
62 if (((1 << l) & missing_bm) == 0) {
63 for (j = 0; j < k; j++) {
64 decode_matrix[(k * i) + j] = encode_matrix[(k * l) + j];
83 while (missing_idxs[i] > -1) {
91 unsigned char *from_row,
98 for (i = 0; i < num_elems; i++) {
99 to_row[i] ^= gf_mul(val, from_row[i]);
109 unsigned char *decode_inverse,
110 unsigned char* encode_matrix,
114 uint64_t missing_bm = convert_list_to_bitmap(missing_idxs);
116 unsigned char *inverse_rows = (
unsigned char*)malloc(
sizeof(
unsigned
117 char*) * k * num_missing_elements);
121 if (NULL == inverse_rows) {
125 memset(inverse_rows, 0,
sizeof(
unsigned
126 char*) * k * num_missing_elements);
131 for (i = 0; i < k; i++) {
132 if ((1 << i) & missing_bm) {
133 for (j = 0; j < k; j++) {
134 inverse_rows[(l * k) + j] = decode_inverse[(i * k) + j];
154 for (i = k; i < n; i++) {
156 if ((1 << i) & missing_bm) {
158 int d_idx_unavail = 0;
159 for (j = 0; j < k; j++) {
161 if (((1 << j) & missing_bm) == 0) {
162 inverse_rows[(l * k) + d_idx_avail] ^= encode_matrix[(i * k) + j];
166 &inverse_rows[d_idx_unavail * k],
167 encode_matrix[(i * k) + j],
180 int *missing_idxs,
int blocksize)
182 isa_l_descriptor *isa_l_desc = (isa_l_descriptor*)desc;
184 unsigned char *g_tbls = NULL;
185 unsigned char *decode_matrix = NULL;
186 unsigned char *decode_inverse = NULL;
187 unsigned char *inverse_rows = NULL;
188 unsigned char **decoded_elements = NULL;
189 unsigned char **available_fragments = NULL;
190 int k = isa_l_desc->k;
191 int m = isa_l_desc->m;
197 uint64_t missing_bm = convert_list_to_bitmap(missing_idxs);
201 if (NULL == decode_matrix) {
205 decode_inverse = (
unsigned char*)malloc(
sizeof(
unsigned char) * k * k);
207 if (NULL == decode_inverse) {
211 int im_ret = isa_l_desc->gf_invert_matrix(decode_matrix, decode_inverse, k);
217 g_tbls = malloc(
sizeof(
unsigned char) * (k * m * 32));
218 if (NULL == g_tbls) {
222 inverse_rows =
get_inverse_rows(k, m, decode_inverse, isa_l_desc->matrix, missing_idxs, isa_l_desc->gf_mul);
224 decoded_elements = (
unsigned char**)malloc(
sizeof(
unsigned char*)*num_missing_elements);
225 if (NULL == decoded_elements) {
229 available_fragments = (
unsigned char**)malloc(
sizeof(
unsigned char*)*k);
230 if (NULL == available_fragments) {
235 for (i = 0; i < n; i++) {
236 if (missing_bm & (1 << i)) {
243 available_fragments[j] = (
unsigned char*)data[i];
245 available_fragments[j] = (
unsigned char*)parity[i-k];
252 for (i = 0; i < k; i++) {
253 if (missing_bm & (1 << i)) {
254 decoded_elements[j] = (
unsigned char*)data[i];
258 for (i = k; i < n; i++) {
259 if (missing_bm & (1 << i)) {
260 decoded_elements[j] = (
unsigned char*)parity[i - k];
265 isa_l_desc->ec_init_tables(k, num_missing_elements, inverse_rows, g_tbls);
267 isa_l_desc->ec_encode_data(blocksize, k, num_missing_elements, g_tbls, (
unsigned char**)available_fragments,
268 (
unsigned char**)decoded_elements);
275 free(decode_inverse);
277 free(decoded_elements);
278 free(available_fragments);
284 int *missing_idxs,
int destination_idx,
int blocksize)
286 isa_l_descriptor *isa_l_desc = (isa_l_descriptor*) desc;
287 unsigned char *g_tbls = NULL;
288 unsigned char *decode_matrix = NULL;
289 unsigned char *decode_inverse = NULL;
290 unsigned char *inverse_rows = NULL;
291 unsigned char *reconstruct_buf = NULL;
292 unsigned char **available_fragments = NULL;
293 int k = isa_l_desc->k;
294 int m = isa_l_desc->m;
298 uint64_t missing_bm = convert_list_to_bitmap(missing_idxs);
299 int inverse_row = -1;
307 if (NULL == decode_matrix) {
311 decode_inverse = (
unsigned char*)malloc(
sizeof(
unsigned char) * k * k);
313 if (NULL == decode_inverse) {
317 int im_ret = isa_l_desc->gf_invert_matrix(decode_matrix, decode_inverse, k);
325 inverse_rows =
get_inverse_rows(k, m, decode_inverse, isa_l_desc->matrix, missing_idxs, isa_l_desc->gf_mul);
328 g_tbls = malloc(
sizeof(
unsigned char) * (k * m * 32));
329 if (NULL == g_tbls) {
336 available_fragments = (
unsigned char**)malloc(
sizeof(
unsigned char*)*k);
337 if (NULL == available_fragments) {
342 for (i = 0; i < n; i++) {
343 if (missing_bm & (1 << i)) {
350 available_fragments[j] = (
unsigned char*)data[i];
352 available_fragments[j] = (
unsigned char*)parity[i-k];
361 for (i = 0; i < n; i++) {
362 if (missing_bm & (1 << i)) {
363 if (i == destination_idx) {
365 reconstruct_buf = (
unsigned char*)data[i];
367 reconstruct_buf = (
unsigned char*)parity[i-k];
379 isa_l_desc->ec_init_tables(k, 1, &inverse_rows[inverse_row * k], g_tbls);
381 isa_l_desc->ec_encode_data(blocksize, k, 1, g_tbls, (
unsigned char**)available_fragments,
382 (
unsigned char**)&reconstruct_buf);
388 free(decode_inverse);
390 free(available_fragments);
396 int *fragments_to_exclude,
int *fragments_needed)
398 isa_l_descriptor *isa_l_desc = (isa_l_descriptor*)desc;
400 uint64_t exclude_bm = convert_list_to_bitmap(fragments_to_exclude);
401 uint64_t missing_bm = convert_list_to_bitmap(missing_idxs) | exclude_bm;
406 for (i = 0; i < (isa_l_desc->k + isa_l_desc->m); i++) {
407 if (!(missing_bm & (1 << i))) {
408 fragments_needed[j] = i;
411 if (j == isa_l_desc->k) {
413 fragments_needed[j] = -1;
434 isa_l_descriptor *isa_l_desc = NULL;
436 isa_l_desc = (isa_l_descriptor*) desc;
438 free(isa_l_desc->encode_tables);
439 free(isa_l_desc->matrix);
447 const char* gen_matrix_func_name)
449 isa_l_descriptor *desc = NULL;
451 desc = (isa_l_descriptor *)malloc(
sizeof(isa_l_descriptor));
456 desc->k = args->uargs.k;
457 desc->m = args->uargs.m;
458 if (args->uargs.w <= 0)
459 args->uargs.w = ISA_L_W;
460 desc->w = args->uargs.w;
464 long long max_symbols = 1LL << desc->w;
465 if ((desc->k + desc->m) > max_symbols) {
476 ec_encode_data_func encodep;
477 ec_init_tables_func init_tablesp;
478 gf_gen_encoding_matrix_func gen_matrixp;
479 gf_invert_matrix_func invert_matrixp;
482 } func_handle = {.vptr = NULL};
485 func_handle.vptr = NULL;
486 func_handle.vptr = dlsym(backend_sohandle,
"ec_encode_data");
487 desc->ec_encode_data = func_handle.encodep;
488 if (NULL == desc->ec_encode_data) {
492 func_handle.vptr = NULL;
493 func_handle.vptr = dlsym(backend_sohandle,
"ec_init_tables");
494 desc->ec_init_tables = func_handle.init_tablesp;
495 if (NULL == desc->ec_init_tables) {
499 func_handle.vptr = NULL;
500 func_handle.vptr = dlsym(backend_sohandle, gen_matrix_func_name);
501 desc->gf_gen_encoding_matrix = func_handle.gen_matrixp;
502 if (NULL == desc->gf_gen_encoding_matrix) {
506 func_handle.vptr = NULL;
507 func_handle.vptr = dlsym(backend_sohandle,
"gf_invert_matrix");
508 desc->gf_invert_matrix = func_handle.invert_matrixp;
509 if (NULL == desc->gf_invert_matrix) {
513 func_handle.vptr = NULL;
514 func_handle.vptr = dlsym(backend_sohandle,
"gf_mul");
515 desc->gf_mul = func_handle.gf_mulp;
516 if (NULL == desc->gf_mul) {
520 desc->matrix = malloc(
sizeof(
char) * desc->k * (desc->k + desc->m));
521 if (NULL == desc->matrix) {
529 desc->gf_gen_encoding_matrix(desc->matrix, desc->k + desc->m, desc->k);
535 desc->encode_tables = malloc(
sizeof(
unsigned char) *
536 (desc->k * desc->m * 32));
537 if (NULL == desc->encode_tables) {
541 desc->ec_init_tables(desc->k, desc->m,
542 &desc->matrix[desc->k * desc->k],
543 desc->encode_tables);