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 = NULL;
45 int k = isa_l_desc->k;
46 int m = isa_l_desc->m;
49 g_tbls = malloc(
sizeof(
unsigned char) * (k * m * 32));
54 isa_l_desc->ec_init_tables(k, m, &isa_l_desc->matrix[k * k], g_tbls);
57 isa_l_desc->ec_encode_data(blocksize, k, m, g_tbls, (
unsigned char**)data,
58 (
unsigned char**)parity);
65 int i = 0, j = 0, l = 0;
67 unsigned char *decode_matrix = malloc(
sizeof(
unsigned char) * k * k);
68 uint64_t missing_bm = convert_list_to_bitmap(missing_idxs);
70 while (i < k && l < n) {
71 if (((1 << l) & missing_bm) == 0) {
72 for (j = 0; j < k; j++) {
73 decode_matrix[(k * i) + j] = encode_matrix[(k * l) + j];
92 while (missing_idxs[i] > -1) {
100 unsigned char *from_row,
107 for (i = 0; i < num_elems; i++) {
108 to_row[i] ^= gf_mul(val, from_row[i]);
118 unsigned char *decode_inverse,
119 unsigned char* encode_matrix,
123 uint64_t missing_bm = convert_list_to_bitmap(missing_idxs);
125 unsigned char *inverse_rows = (
unsigned char*)malloc(
sizeof(
unsigned
126 char*) * k * num_missing_elements);
130 if (NULL == inverse_rows) {
134 memset(inverse_rows, 0,
sizeof(
unsigned
135 char*) * k * num_missing_elements);
140 for (i = 0; i < k; i++) {
141 if ((1 << i) & missing_bm) {
142 for (j = 0; j < k; j++) {
143 inverse_rows[(l * k) + j] = decode_inverse[(i * k) + j];
163 for (i = k; i < n; i++) {
165 if ((1 << i) & missing_bm) {
167 int d_idx_unavail = 0;
168 for (j = 0; j < k; j++) {
170 if (((1 << j) & missing_bm) == 0) {
171 inverse_rows[(l * k) + d_idx_avail] ^= encode_matrix[(i * k) + j];
175 &inverse_rows[d_idx_unavail * k],
176 encode_matrix[(i * k) + j],
189 int *missing_idxs,
int blocksize)
191 isa_l_descriptor *isa_l_desc = (isa_l_descriptor*)desc;
193 unsigned char *g_tbls = NULL;
194 unsigned char *decode_matrix = NULL;
195 unsigned char *decode_inverse = NULL;
196 unsigned char *inverse_rows = NULL;
197 unsigned char **decoded_elements = NULL;
198 unsigned char **available_fragments = NULL;
199 int k = isa_l_desc->k;
200 int m = isa_l_desc->m;
206 uint64_t missing_bm = convert_list_to_bitmap(missing_idxs);
210 if (NULL == decode_matrix) {
214 decode_inverse = (
unsigned char*)malloc(
sizeof(
unsigned char) * k * k);
216 if (NULL == decode_inverse) {
220 int im_ret = isa_l_desc->gf_invert_matrix(decode_matrix, decode_inverse, k);
226 g_tbls = malloc(
sizeof(
unsigned char) * (k * m * 32));
227 if (NULL == g_tbls) {
231 inverse_rows =
get_inverse_rows(k, m, decode_inverse, isa_l_desc->matrix, missing_idxs, isa_l_desc->gf_mul);
233 decoded_elements = (
unsigned char**)malloc(
sizeof(
unsigned char*)*num_missing_elements);
234 if (NULL == decoded_elements) {
238 available_fragments = (
unsigned char**)malloc(
sizeof(
unsigned char*)*k);
239 if (NULL == available_fragments) {
244 for (i = 0; i < n; i++) {
245 if (missing_bm & (1 << i)) {
252 available_fragments[j] = (
unsigned char*)data[i];
254 available_fragments[j] = (
unsigned char*)parity[i-k];
261 for (i = 0; i < k; i++) {
262 if (missing_bm & (1 << i)) {
263 decoded_elements[j] = (
unsigned char*)data[i];
267 for (i = k; i < n; i++) {
268 if (missing_bm & (1 << i)) {
269 decoded_elements[j] = (
unsigned char*)parity[i - k];
274 isa_l_desc->ec_init_tables(k, num_missing_elements, inverse_rows, g_tbls);
276 isa_l_desc->ec_encode_data(blocksize, k, num_missing_elements, g_tbls, (
unsigned char**)available_fragments,
277 (
unsigned char**)decoded_elements);
284 free(decode_inverse);
286 free(decoded_elements);
287 free(available_fragments);
293 int *missing_idxs,
int destination_idx,
int blocksize)
295 isa_l_descriptor *isa_l_desc = (isa_l_descriptor*) desc;
296 unsigned char *g_tbls = NULL;
297 unsigned char *decode_matrix = NULL;
298 unsigned char *decode_inverse = NULL;
299 unsigned char *inverse_rows = NULL;
300 unsigned char *reconstruct_buf = NULL;
301 unsigned char **available_fragments = NULL;
302 int k = isa_l_desc->k;
303 int m = isa_l_desc->m;
307 uint64_t missing_bm = convert_list_to_bitmap(missing_idxs);
308 int inverse_row = -1;
316 if (NULL == decode_matrix) {
320 decode_inverse = (
unsigned char*)malloc(
sizeof(
unsigned char) * k * k);
322 if (NULL == decode_inverse) {
326 int im_ret = isa_l_desc->gf_invert_matrix(decode_matrix, decode_inverse, k);
334 inverse_rows =
get_inverse_rows(k, m, decode_inverse, isa_l_desc->matrix, missing_idxs, isa_l_desc->gf_mul);
337 g_tbls = malloc(
sizeof(
unsigned char) * (k * m * 32));
338 if (NULL == g_tbls) {
345 available_fragments = (
unsigned char**)malloc(
sizeof(
unsigned char*)*k);
346 if (NULL == available_fragments) {
351 for (i = 0; i < n; i++) {
352 if (missing_bm & (1 << i)) {
359 available_fragments[j] = (
unsigned char*)data[i];
361 available_fragments[j] = (
unsigned char*)parity[i-k];
370 for (i = 0; i < n; i++) {
371 if (missing_bm & (1 << i)) {
372 if (i == destination_idx) {
374 reconstruct_buf = (
unsigned char*)data[i];
376 reconstruct_buf = (
unsigned char*)parity[i-k];
388 isa_l_desc->ec_init_tables(k, 1, &inverse_rows[inverse_row * k], g_tbls);
390 isa_l_desc->ec_encode_data(blocksize, k, 1, g_tbls, (
unsigned char**)available_fragments,
391 (
unsigned char**)&reconstruct_buf);
397 free(decode_inverse);
399 free(available_fragments);
405 int *fragments_to_exclude,
int *fragments_needed)
407 isa_l_descriptor *isa_l_desc = (isa_l_descriptor*)desc;
409 uint64_t exclude_bm = convert_list_to_bitmap(fragments_to_exclude);
410 uint64_t missing_bm = convert_list_to_bitmap(missing_idxs) | exclude_bm;
415 for (i = 0; i < (isa_l_desc->k + isa_l_desc->m); i++) {
416 if (!(missing_bm & (1 << i))) {
417 fragments_needed[j] = i;
420 if (j == isa_l_desc->k) {
422 fragments_needed[j] = -1;
443 isa_l_descriptor *isa_l_desc = NULL;
445 isa_l_desc = (isa_l_descriptor*) desc;
454 const char* gen_matrix_func_name)
456 isa_l_descriptor *desc = NULL;
458 desc = (isa_l_descriptor *)malloc(
sizeof(isa_l_descriptor));
463 desc->k = args->uargs.k;
464 desc->m = args->uargs.m;
465 if (args->uargs.w <= 0)
466 args->uargs.w = ISA_L_W;
467 desc->w = args->uargs.w;
471 long long max_symbols = 1LL << desc->w;
472 if ((desc->k + desc->m) > max_symbols) {
483 ec_encode_data_func encodep;
484 ec_init_tables_func init_tablesp;
485 gf_gen_encoding_matrix_func gen_matrixp;
486 gf_invert_matrix_func invert_matrixp;
489 } func_handle = {.vptr = NULL};
492 func_handle.vptr = NULL;
493 func_handle.vptr = dlsym(backend_sohandle,
"ec_encode_data");
494 desc->ec_encode_data = func_handle.encodep;
495 if (NULL == desc->ec_encode_data) {
499 func_handle.vptr = NULL;
500 func_handle.vptr = dlsym(backend_sohandle,
"ec_init_tables");
501 desc->ec_init_tables = func_handle.init_tablesp;
502 if (NULL == desc->ec_init_tables) {
506 func_handle.vptr = NULL;
507 func_handle.vptr = dlsym(backend_sohandle, gen_matrix_func_name);
508 desc->gf_gen_encoding_matrix = func_handle.gen_matrixp;
509 if (NULL == desc->gf_gen_encoding_matrix) {
513 func_handle.vptr = NULL;
514 func_handle.vptr = dlsym(backend_sohandle,
"gf_invert_matrix");
515 desc->gf_invert_matrix = func_handle.invert_matrixp;
516 if (NULL == desc->gf_invert_matrix) {
520 func_handle.vptr = NULL;
521 func_handle.vptr = dlsym(backend_sohandle,
"gf_mul");
522 desc->gf_mul = func_handle.gf_mulp;
523 if (NULL == desc->gf_mul) {
527 desc->matrix = malloc(
sizeof(
char) * desc->k * (desc->k + desc->m));
528 if (NULL == desc->matrix) {
536 desc->gf_gen_encoding_matrix(desc->matrix, desc->k + desc->m, desc->k);
static unsigned char * isa_l_get_decode_matrix(int k, int m, unsigned char *encode_matrix, int *missing_idxs)
int isa_l_reconstruct(void *desc, char **data, char **parity, int *missing_idxs, int destination_idx, int blocksize)
static unsigned char * get_inverse_rows(int k, int m, unsigned char *decode_inverse, unsigned char *encode_matrix, int *missing_idxs, gf_mul_func gf_mul)
int isa_l_min_fragments(void *desc, int *missing_idxs, int *fragments_to_exclude, int *fragments_needed)
void * isa_l_common_init(struct ec_backend_args *args, void *backend_sohandle, const char *gen_matrix_func_name)
int isa_l_exit(void *desc)
int isa_l_encode(void *desc, char **data, char **parity, int blocksize)
static void mult_and_xor_row(unsigned char *to_row, unsigned char *from_row, unsigned char val, int num_elems, gf_mul_func gf_mul)
int isa_l_decode(void *desc, char **data, char **parity, int *missing_idxs, int blocksize)
int isa_l_element_size(void *desc)
Return the element-size, which is the number of bits stored on a given device, per codeword...
static int get_num_missing_elements(int *missing_idxs)