Merged in dalgaaf/jerasure/wip-da-coverity-rebase (pull request #21)
[UPDATED][Rebased #8] Fixes for SCA issuesmaster
commit
b8221e7d75
|
@ -62,6 +62,7 @@ same arguments, and encoder.c does error check.
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
|
@ -59,6 +59,7 @@ is the file name with "_k#" or "_m#" and then the extension.
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
Revision 1.0 - 2007: James S. Plank.
|
Revision 1.0 - 2007: James S. Plank.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
101
src/jerasure.c
101
src/jerasure.c
|
@ -245,6 +245,12 @@ int jerasure_matrix_decode(int k, int m, int w, int *matrix, int row_k_ones, int
|
||||||
|
|
||||||
if (edd > 0) {
|
if (edd > 0) {
|
||||||
tmpids = talloc(int, k);
|
tmpids = talloc(int, k);
|
||||||
|
if (!tmpids) {
|
||||||
|
free(erased);
|
||||||
|
free(dm_ids);
|
||||||
|
free(decoding_matrix);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
for (i = 0; i < k; i++) {
|
for (i = 0; i < k; i++) {
|
||||||
tmpids[i] = (i < lastdrive) ? i : i+1;
|
tmpids[i] = (i < lastdrive) ? i : i+1;
|
||||||
}
|
}
|
||||||
|
@ -273,9 +279,11 @@ int *jerasure_matrix_to_bitmatrix(int k, int m, int w, int *matrix)
|
||||||
int *bitmatrix;
|
int *bitmatrix;
|
||||||
int rowelts, rowindex, colindex, elt, i, j, l, x;
|
int rowelts, rowindex, colindex, elt, i, j, l, x;
|
||||||
|
|
||||||
bitmatrix = talloc(int, k*m*w*w);
|
|
||||||
if (matrix == NULL) { return NULL; }
|
if (matrix == NULL) { return NULL; }
|
||||||
|
|
||||||
|
bitmatrix = talloc(int, k*m*w*w);
|
||||||
|
if (!bitmatrix) return NULL;
|
||||||
|
|
||||||
rowelts = k * w;
|
rowelts = k * w;
|
||||||
rowindex = 0;
|
rowindex = 0;
|
||||||
|
|
||||||
|
@ -695,6 +703,12 @@ int jerasure_bitmatrix_decode(int k, int m, int w, int *bitmatrix, int row_k_one
|
||||||
|
|
||||||
if (edd > 0) {
|
if (edd > 0) {
|
||||||
tmpids = talloc(int, k);
|
tmpids = talloc(int, k);
|
||||||
|
if (!tmpids) {
|
||||||
|
free(erased);
|
||||||
|
free(dm_ids);
|
||||||
|
free(decoding_matrix);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
for (i = 0; i < k; i++) {
|
for (i = 0; i < k; i++) {
|
||||||
tmpids[i] = (i < lastdrive) ? i : i+1;
|
tmpids[i] = (i < lastdrive) ? i : i+1;
|
||||||
}
|
}
|
||||||
|
@ -746,6 +760,10 @@ static char **set_up_ptrs_for_scheduled_decoding(int k, int m, int *erasures, ch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ptrs = talloc(char *, k+m);
|
ptrs = talloc(char *, k+m);
|
||||||
|
if (!ptrs) {
|
||||||
|
free(erased);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
j = k;
|
j = k;
|
||||||
x = k;
|
x = k;
|
||||||
|
@ -835,9 +853,18 @@ static int **jerasure_generate_decoding_schedule(int k, int m, int w, int *bitma
|
||||||
}
|
}
|
||||||
|
|
||||||
row_ids = talloc(int, k+m);
|
row_ids = talloc(int, k+m);
|
||||||
|
if (!row_ids) return NULL;
|
||||||
ind_to_row = talloc(int, k+m);
|
ind_to_row = talloc(int, k+m);
|
||||||
|
if (!ind_to_row) {
|
||||||
|
free(row_ids);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (set_up_ids_for_scheduled_decoding(k, m, erasures, row_ids, ind_to_row) < 0) return NULL;
|
if (set_up_ids_for_scheduled_decoding(k, m, erasures, row_ids, ind_to_row) < 0) {
|
||||||
|
free(row_ids);
|
||||||
|
free(ind_to_row);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Now, we're going to create one decoding matrix which is going to
|
/* Now, we're going to create one decoding matrix which is going to
|
||||||
decode everything with one call. The hope is that the scheduler
|
decode everything with one call. The hope is that the scheduler
|
||||||
|
@ -845,6 +872,11 @@ static int **jerasure_generate_decoding_schedule(int k, int m, int w, int *bitma
|
||||||
number of erasures (ddf+cdf) */
|
number of erasures (ddf+cdf) */
|
||||||
|
|
||||||
real_decoding_matrix = talloc(int, k*w*(cdf+ddf)*w);
|
real_decoding_matrix = talloc(int, k*w*(cdf+ddf)*w);
|
||||||
|
if (!real_decoding_matrix) {
|
||||||
|
free(row_ids);
|
||||||
|
free(ind_to_row);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* First, if any data drives have failed, then initialize the first
|
/* First, if any data drives have failed, then initialize the first
|
||||||
ddf*w rows of the decoding matrix from the standard decoding
|
ddf*w rows of the decoding matrix from the standard decoding
|
||||||
|
@ -853,6 +885,11 @@ static int **jerasure_generate_decoding_schedule(int k, int m, int w, int *bitma
|
||||||
if (ddf > 0) {
|
if (ddf > 0) {
|
||||||
|
|
||||||
decoding_matrix = talloc(int, k*k*w*w);
|
decoding_matrix = talloc(int, k*k*w*w);
|
||||||
|
if (!decoding_matrix) {
|
||||||
|
free(row_ids);
|
||||||
|
free(ind_to_row);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
ptr = decoding_matrix;
|
ptr = decoding_matrix;
|
||||||
for (i = 0; i < k; i++) {
|
for (i = 0; i < k; i++) {
|
||||||
if (row_ids[i] == i) {
|
if (row_ids[i] == i) {
|
||||||
|
@ -866,6 +903,12 @@ static int **jerasure_generate_decoding_schedule(int k, int m, int w, int *bitma
|
||||||
ptr += (k*w*w);
|
ptr += (k*w*w);
|
||||||
}
|
}
|
||||||
inverse = talloc(int, k*k*w*w);
|
inverse = talloc(int, k*k*w*w);
|
||||||
|
if (!inverse) {
|
||||||
|
free(row_ids);
|
||||||
|
free(ind_to_row);
|
||||||
|
free(decoding_matrix);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
jerasure_invert_bitmatrix(decoding_matrix, inverse, k*w);
|
jerasure_invert_bitmatrix(decoding_matrix, inverse, k*w);
|
||||||
|
|
||||||
/* printf("\nMatrix to invert\n");
|
/* printf("\nMatrix to invert\n");
|
||||||
|
@ -1207,6 +1250,7 @@ int **jerasure_dumb_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix)
|
||||||
int index, optodo, i, j;
|
int index, optodo, i, j;
|
||||||
|
|
||||||
operations = talloc(int *, k*m*w*w+1);
|
operations = talloc(int *, k*m*w*w+1);
|
||||||
|
if (!operations) return NULL;
|
||||||
op = 0;
|
op = 0;
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
|
@ -1215,6 +1259,10 @@ int **jerasure_dumb_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix)
|
||||||
for (j = 0; j < k*w; j++) {
|
for (j = 0; j < k*w; j++) {
|
||||||
if (bitmatrix[index]) {
|
if (bitmatrix[index]) {
|
||||||
operations[op] = talloc(int, 5);
|
operations[op] = talloc(int, 5);
|
||||||
|
if (!operations[op]) {
|
||||||
|
// -ENOMEM
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
operations[op][4] = optodo;
|
operations[op][4] = optodo;
|
||||||
operations[op][0] = j/w;
|
operations[op][0] = j/w;
|
||||||
operations[op][1] = j%w;
|
operations[op][1] = j%w;
|
||||||
|
@ -1228,8 +1276,19 @@ int **jerasure_dumb_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
operations[op] = talloc(int, 5);
|
operations[op] = talloc(int, 5);
|
||||||
|
if (!operations[op]) {
|
||||||
|
// -ENOMEM
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
operations[op][0] = -1;
|
operations[op][0] = -1;
|
||||||
return operations;
|
return operations;
|
||||||
|
|
||||||
|
error:
|
||||||
|
for (i = 0; i <= op; i++) {
|
||||||
|
free(operations[op]);
|
||||||
|
}
|
||||||
|
free(operations);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int **jerasure_smart_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix)
|
int **jerasure_smart_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix)
|
||||||
|
@ -1246,12 +1305,35 @@ int **jerasure_smart_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix)
|
||||||
jerasure_print_bitmatrix(bitmatrix, m*w, k*w, w); */
|
jerasure_print_bitmatrix(bitmatrix, m*w, k*w, w); */
|
||||||
|
|
||||||
operations = talloc(int *, k*m*w*w+1);
|
operations = talloc(int *, k*m*w*w+1);
|
||||||
|
if (!operations) return NULL;
|
||||||
op = 0;
|
op = 0;
|
||||||
|
|
||||||
diff = talloc(int, m*w);
|
diff = talloc(int, m*w);
|
||||||
|
if (!diff) {
|
||||||
|
free(operations);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
from = talloc(int, m*w);
|
from = talloc(int, m*w);
|
||||||
|
if (!from) {
|
||||||
|
free(operations);
|
||||||
|
free(diff);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
flink = talloc(int, m*w);
|
flink = talloc(int, m*w);
|
||||||
|
if (!flink) {
|
||||||
|
free(operations);
|
||||||
|
free(diff);
|
||||||
|
free(from);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
blink = talloc(int, m*w);
|
blink = talloc(int, m*w);
|
||||||
|
if (!blink) {
|
||||||
|
free(operations);
|
||||||
|
free(diff);
|
||||||
|
free(from);
|
||||||
|
free(flink);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ptr = bitmatrix;
|
ptr = bitmatrix;
|
||||||
|
|
||||||
|
@ -1295,6 +1377,7 @@ int **jerasure_smart_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix)
|
||||||
for (j = 0; j < k*w; j++) {
|
for (j = 0; j < k*w; j++) {
|
||||||
if (ptr[j]) {
|
if (ptr[j]) {
|
||||||
operations[op] = talloc(int, 5);
|
operations[op] = talloc(int, 5);
|
||||||
|
if (!operations[op]) goto error;
|
||||||
operations[op][4] = optodo;
|
operations[op][4] = optodo;
|
||||||
operations[op][0] = j/w;
|
operations[op][0] = j/w;
|
||||||
operations[op][1] = j%w;
|
operations[op][1] = j%w;
|
||||||
|
@ -1306,6 +1389,7 @@ int **jerasure_smart_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
operations[op] = talloc(int, 5);
|
operations[op] = talloc(int, 5);
|
||||||
|
if (!operations[op]) goto error;
|
||||||
operations[op][4] = 0;
|
operations[op][4] = 0;
|
||||||
operations[op][0] = k+from[row]/w;
|
operations[op][0] = k+from[row]/w;
|
||||||
operations[op][1] = from[row]%w;
|
operations[op][1] = from[row]%w;
|
||||||
|
@ -1316,6 +1400,7 @@ int **jerasure_smart_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix)
|
||||||
for (j = 0; j < k*w; j++) {
|
for (j = 0; j < k*w; j++) {
|
||||||
if (ptr[j] ^ b1[j]) {
|
if (ptr[j] ^ b1[j]) {
|
||||||
operations[op] = talloc(int, 5);
|
operations[op] = talloc(int, 5);
|
||||||
|
if (!operations[op]) goto error;
|
||||||
operations[op][4] = 1;
|
operations[op][4] = 1;
|
||||||
operations[op][0] = j/w;
|
operations[op][0] = j/w;
|
||||||
operations[op][1] = j%w;
|
operations[op][1] = j%w;
|
||||||
|
@ -1343,6 +1428,7 @@ int **jerasure_smart_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix)
|
||||||
}
|
}
|
||||||
|
|
||||||
operations[op] = talloc(int, 5);
|
operations[op] = talloc(int, 5);
|
||||||
|
if (!operations[op]) goto error;
|
||||||
operations[op][0] = -1;
|
operations[op][0] = -1;
|
||||||
free(from);
|
free(from);
|
||||||
free(diff);
|
free(diff);
|
||||||
|
@ -1350,6 +1436,17 @@ int **jerasure_smart_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix)
|
||||||
free(flink);
|
free(flink);
|
||||||
|
|
||||||
return operations;
|
return operations;
|
||||||
|
|
||||||
|
error:
|
||||||
|
for (i = 0; i <= op; i++) {
|
||||||
|
free(operations[op]);
|
||||||
|
}
|
||||||
|
free(operations);
|
||||||
|
free(from);
|
||||||
|
free(diff);
|
||||||
|
free(blink);
|
||||||
|
free(flink);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void jerasure_bitmatrix_encode(int k, int m, int w, int *bitmatrix,
|
void jerasure_bitmatrix_encode(int k, int m, int w, int *bitmatrix,
|
||||||
|
|
Loading…
Reference in New Issue