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"
40int isa_l_encode(
void *desc,
char **data,
char **parity,
43 isa_l_descriptor *isa_l_desc = (isa_l_descriptor*) desc;
45 unsigned char *g_tbls = isa_l_desc->encode_tables;
46 int k = isa_l_desc->k;
47 int m = isa_l_desc->m;
50 isa_l_desc->ec_encode_data(blocksize, k, m, g_tbls, (
unsigned char**)data,
51 (
unsigned char**)parity);
57 int i = 0, j = 0, l = 0;
59 unsigned char *decode_matrix = malloc(
sizeof(
unsigned char) * k * k);
60 struct ec_bm missing_bm = NEW_BM;
61 convert_list_to_bitmap(missing_idxs, &missing_bm);
63 while (i < k && l < n) {
64 if (!bm_get_value(&missing_bm, l)) {
65 for (j = 0; j < k; j++) {
66 decode_matrix[(k * i) + j] = encode_matrix[(k * l) + j];
86 unsigned char *decode_inverse,
87 unsigned char* encode_matrix,
91 struct ec_bm missing_bm = NEW_BM;
92 convert_list_to_bitmap(missing_idxs, &missing_bm);
93 int num_missing_elements = get_num_missing_elements(missing_idxs);
94 unsigned char *inverse_rows = (
unsigned char*)malloc(
sizeof(
unsigned
95 char*) * k * num_missing_elements);
99 if (NULL == inverse_rows) {
103 memset(inverse_rows, 0,
sizeof(
unsigned
104 char*) * k * num_missing_elements);
109 for (i = 0; i < k; i++) {
110 if (bm_get_value(&missing_bm, i)) {
111 for (j = 0; j < k; j++) {
112 inverse_rows[(l * k) + j] = decode_inverse[(i * k) + j];
132 for (i = k; i < n; i++) {
134 if (bm_get_value(&missing_bm, i)) {
136 int d_idx_unavail = 0;
137 for (j = 0; j < k; j++) {
139 if (!bm_get_value(&missing_bm, j)) {
140 inverse_rows[(l * k) + d_idx_avail] ^= encode_matrix[(i * k) + j];
143 mult_and_xor_row(&inverse_rows[l * k],
144 &inverse_rows[d_idx_unavail * k],
145 encode_matrix[(i * k) + j],
158int isa_l_decode(
void *desc,
char **data,
char **parity,
159 int *missing_idxs,
int blocksize)
161 isa_l_descriptor *isa_l_desc = (isa_l_descriptor*)desc;
163 unsigned char *g_tbls = NULL;
164 unsigned char *decode_matrix = NULL;
165 unsigned char *decode_inverse = NULL;
166 unsigned char *inverse_rows = NULL;
167 unsigned char **decoded_elements = NULL;
168 unsigned char **available_fragments = NULL;
169 int k = isa_l_desc->k;
170 int m = isa_l_desc->m;
175 int num_missing_elements = get_num_missing_elements(missing_idxs);
176 struct ec_bm missing_bm = NEW_BM;
177 convert_list_to_bitmap(missing_idxs, &missing_bm);
181 if (NULL == decode_matrix) {
185 decode_inverse = (
unsigned char*)malloc(
sizeof(
unsigned char) * k * k);
187 if (NULL == decode_inverse) {
191 int im_ret = isa_l_desc->gf_invert_matrix(decode_matrix, decode_inverse, k);
197 g_tbls = malloc(
sizeof(
unsigned char) * (k * m * 32));
198 if (NULL == g_tbls) {
202 inverse_rows =
get_inverse_rows(k, m, decode_inverse, isa_l_desc->matrix, missing_idxs, isa_l_desc->gf_mul);
204 decoded_elements = (
unsigned char**)malloc(
sizeof(
unsigned char*)*num_missing_elements);
205 if (NULL == decoded_elements) {
209 available_fragments = (
unsigned char**)malloc(
sizeof(
unsigned char*)*k);
210 if (NULL == available_fragments) {
215 for (i = 0; i < n; i++) {
216 if (bm_get_value(&missing_bm, i)) {
223 available_fragments[j] = (
unsigned char*)data[i];
225 available_fragments[j] = (
unsigned char*)parity[i-k];
232 for (i = 0; i < k; i++) {
233 if (bm_get_value(&missing_bm, i)) {
234 decoded_elements[j] = (
unsigned char*)data[i];
238 for (i = k; i < n; i++) {
239 if (bm_get_value(&missing_bm, i)) {
240 decoded_elements[j] = (
unsigned char*)parity[i - k];
245 isa_l_desc->ec_init_tables(k, num_missing_elements, inverse_rows, g_tbls);
247 isa_l_desc->ec_encode_data(blocksize, k, num_missing_elements, g_tbls, (
unsigned char**)available_fragments,
248 (
unsigned char**)decoded_elements);
255 free(decode_inverse);
257 free(decoded_elements);
258 free(available_fragments);
264int isa_l_reconstruct(
void *desc,
char **data,
char **parity,
265 int *missing_idxs,
int destination_idx,
int blocksize)
267 isa_l_descriptor *isa_l_desc = (isa_l_descriptor*) desc;
268 unsigned char *g_tbls = NULL;
269 unsigned char *decode_matrix = NULL;
270 unsigned char *decode_inverse = NULL;
271 unsigned char *inverse_rows = NULL;
272 unsigned char *reconstruct_buf = NULL;
273 unsigned char **available_fragments = NULL;
274 int k = isa_l_desc->k;
275 int m = isa_l_desc->m;
279 struct ec_bm missing_bm = NEW_BM;
280 convert_list_to_bitmap(missing_idxs, &missing_bm);
281 int inverse_row = -1;
289 if (NULL == decode_matrix) {
293 decode_inverse = (
unsigned char*)malloc(
sizeof(
unsigned char) * k * k);
295 if (NULL == decode_inverse) {
299 int im_ret = isa_l_desc->gf_invert_matrix(decode_matrix, decode_inverse, k);
307 inverse_rows =
get_inverse_rows(k, m, decode_inverse, isa_l_desc->matrix, missing_idxs, isa_l_desc->gf_mul);
310 g_tbls = malloc(
sizeof(
unsigned char) * (k * m * 32));
311 if (NULL == g_tbls) {
318 available_fragments = (
unsigned char**)malloc(
sizeof(
unsigned char*)*k);
319 if (NULL == available_fragments) {
324 for (i = 0; i < n; i++) {
325 if (bm_get_value(&missing_bm, i)) {
332 available_fragments[j] = (
unsigned char*)data[i];
334 available_fragments[j] = (
unsigned char*)parity[i-k];
343 for (i = 0; i < n; i++) {
344 if (bm_get_value(&missing_bm, i)) {
345 if (i == destination_idx) {
347 reconstruct_buf = (
unsigned char*)data[i];
349 reconstruct_buf = (
unsigned char*)parity[i-k];
361 isa_l_desc->ec_init_tables(k, 1, &inverse_rows[inverse_row * k], g_tbls);
363 isa_l_desc->ec_encode_data(blocksize, k, 1, g_tbls, (
unsigned char**)available_fragments,
364 (
unsigned char**)&reconstruct_buf);
370 free(decode_inverse);
372 free(available_fragments);
378int isa_l_min_fragments(
void *desc,
int *missing_idxs,
379 int *fragments_to_exclude,
int *fragments_needed)
381 isa_l_descriptor *isa_l_desc = (isa_l_descriptor*)desc;
383 struct ec_bm exclude_bm = NEW_BM, missing_bm = NEW_BM;
384 convert_list_to_bitmap(fragments_to_exclude, &exclude_bm);
385 convert_list_to_bitmap(missing_idxs, &missing_bm);
386 bm_combine_or(&exclude_bm, &missing_bm);
391 for (i = 0; i < (isa_l_desc->k + isa_l_desc->m); i++) {
392 if (!bm_get_value(&missing_bm, i)) {
393 fragments_needed[j] = i;
396 if (j == isa_l_desc->k) {
398 fragments_needed[j] = -1;
413int isa_l_element_size(
void* desc)
419int isa_l_exit(
void *desc)
421 isa_l_descriptor *isa_l_desc = NULL;
423 isa_l_desc = (isa_l_descriptor*) desc;
425 free(isa_l_desc->encode_tables);
426 free(isa_l_desc->matrix);
434void * isa_l_common_init(struct ec_backend_args *args,
void *backend_sohandle,
435 const
char* gen_matrix_func_name)
437 isa_l_descriptor *desc = NULL;
439 desc = (isa_l_descriptor *)malloc(
sizeof(isa_l_descriptor));
444 desc->k = args->uargs.k;
445 desc->m = args->uargs.m;
446 if (args->uargs.w <= 0)
447 args->uargs.w = ISA_L_W;
448 desc->w = args->uargs.w;
452 long long max_symbols = 1LL << desc->w;
453 if ((desc->k + desc->m) > max_symbols) {
464 ec_encode_data_func encodep;
465 ec_init_tables_func init_tablesp;
466 gf_gen_encoding_matrix_func gen_matrixp;
467 gf_invert_matrix_func invert_matrixp;
470 } func_handle = {.vptr = NULL};
473 func_handle.vptr = NULL;
474 func_handle.vptr = dlsym(backend_sohandle,
"ec_encode_data");
475 desc->ec_encode_data = func_handle.encodep;
476 if (NULL == desc->ec_encode_data) {
480 func_handle.vptr = NULL;
481 func_handle.vptr = dlsym(backend_sohandle,
"ec_init_tables");
482 desc->ec_init_tables = func_handle.init_tablesp;
483 if (NULL == desc->ec_init_tables) {
487 func_handle.vptr = NULL;
488 func_handle.vptr = dlsym(backend_sohandle, gen_matrix_func_name);
489 desc->gf_gen_encoding_matrix = func_handle.gen_matrixp;
490 if (NULL == desc->gf_gen_encoding_matrix) {
494 func_handle.vptr = NULL;
495 func_handle.vptr = dlsym(backend_sohandle,
"gf_invert_matrix");
496 desc->gf_invert_matrix = func_handle.invert_matrixp;
497 if (NULL == desc->gf_invert_matrix) {
501 func_handle.vptr = NULL;
502 func_handle.vptr = dlsym(backend_sohandle,
"gf_mul");
503 desc->gf_mul = func_handle.gf_mulp;
504 if (NULL == desc->gf_mul) {
508 desc->matrix = malloc(
sizeof(
char) * desc->k * (desc->k + desc->m));
509 if (NULL == desc->matrix) {
517 desc->gf_gen_encoding_matrix(desc->matrix, desc->k + desc->m, desc->k);
523 desc->encode_tables = malloc(
sizeof(
unsigned char) *
524 (desc->k * desc->m * 32));
525 if (NULL == desc->encode_tables) {
529 desc->ec_init_tables(desc->k, desc->m,
530 &desc->matrix[desc->k * desc->k],
531 desc->encode_tables);
static unsigned char * isa_l_get_decode_matrix(int k, int m, unsigned char *encode_matrix, int *missing_idxs)
__attribute__((visibility("internal")))
Return the element-size, which is the number of bits stored on a given device, per codeword.
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)