Skip to content

Commit

Permalink
ex: Allow erasure list in any order in ec example
Browse files Browse the repository at this point in the history
Previous gf_gen_decode_matrix_simple() assumed that all source errors
were listed first before any erasures in parity.  Generalized to work
in any order.

Change-Id: I31b9c0c0db5d0155473424ccd0ecdcdd787ef71f
Signed-off-by: Greg Tucker <greg.b.tucker@intel.com>
  • Loading branch information
gbtucker committed May 25, 2018
1 parent 19f2c46 commit 9edac47
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions examples/ec/ec_simple_example.c
Expand Up @@ -99,10 +99,9 @@ int main(int argc, char *argv[])
break;
case 'r':
srand(atoi(optarg));
k = rand() % MMAX;
k++; // Pick k (1 to MMAX)
p = rand() % (MMAX - k);
p++; // Pick p (1 to MMAX - k)
k = (rand() % (MMAX - 1)) + 1; // Pick k {1 to MMAX - 1}
p = (rand() % (MMAX - k)) + 1; // Pick p {1 to MMAX - k}

for (i = 0; i < k + p && nerrs < p; i++)
if (rand() & 1)
frag_err_list[nerrs++] = i;
Expand Down Expand Up @@ -255,21 +254,23 @@ static int gf_gen_decode_matrix_simple(u8 * encode_matrix,
return -1;

// Get decode matrix with only wanted recovery rows
for (i = 0; i < nsrcerrs; i++) {
for (j = 0; j < k; j++) {
decode_matrix[k * i + j] = invert_matrix[k * frag_err_list[i] + j];
}
for (i = 0; i < nerrs; i++) {
if (frag_err_list[i] < k) // A src err
for (j = 0; j < k; j++)
decode_matrix[k * i + j] =
invert_matrix[k * frag_err_list[i] + j];
}

// For non-src (parity) erasures need to multiply encode matrix * invert
for (p = nsrcerrs; p < nerrs; p++) {
for (i = 0; i < k; i++) {
s = 0;
for (j = 0; j < k; j++)
s ^= gf_mul(invert_matrix[j * k + i],
encode_matrix[k * frag_err_list[p] + j]);

decode_matrix[k * p + i] = s;
for (p = 0; p < nerrs; p++) {
if (frag_err_list[p] >= k) { // A parity err
for (i = 0; i < k; i++) {
s = 0;
for (j = 0; j < k; j++)
s ^= gf_mul(invert_matrix[j * k + i],
encode_matrix[k * frag_err_list[p] + j]);
decode_matrix[k * p + i] = s;
}
}
}
return 0;
Expand Down

0 comments on commit 9edac47

Please sign in to comment.