You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
4.1 KiB
130 lines
4.1 KiB
10 years ago
|
/*
|
||
|
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
10 years ago
|
#include <string.h>
|
||
10 years ago
|
|
||
|
#include <erasure-code.h>
|
||
10 years ago
|
#include "common.h"
|
||
10 years ago
|
|
||
10 years ago
|
static
|
||
|
int32_t _minio_src_index_in_error (int r, int32_t *error_index)
|
||
10 years ago
|
{
|
||
|
int i;
|
||
10 years ago
|
for (i = 0; error_index[i] != -1; i++) {
|
||
|
if (error_index[i] == r) {
|
||
10 years ago
|
// true
|
||
10 years ago
|
return 1;
|
||
|
}
|
||
|
}
|
||
|
// false
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
10 years ago
|
int32_t minio_get_source_target (int errs, int k, int m,
|
||
|
int32_t *error_index,
|
||
|
uint32_t *decode_index,
|
||
|
uint8_t **buffs,
|
||
|
uint8_t ***source,
|
||
|
uint8_t ***target)
|
||
10 years ago
|
{
|
||
10 years ago
|
int i;
|
||
|
uint8_t *tmp_source[k];
|
||
|
uint8_t *tmp_target[m];
|
||
|
|
||
|
memset (tmp_source, 0, k);
|
||
|
memset (tmp_target, 0, m);
|
||
|
|
||
|
for (i = 0; i < k; i++) {
|
||
|
tmp_source[i] = (uint8_t *) buffs[decode_index[i]];
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
for (i = 0; i < m; i++) {
|
||
|
if (i < errs)
|
||
|
tmp_target[i] = (uint8_t *) buffs[error_index[i]];
|
||
|
}
|
||
|
|
||
10 years ago
|
*source = tmp_source;
|
||
|
*target = tmp_target;
|
||
10 years ago
|
|
||
|
return 0;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
/*
|
||
|
Generate decode matrix during the decoding phase
|
||
|
*/
|
||
|
|
||
10 years ago
|
int minio_init_decoder (int32_t *error_index,
|
||
|
int k, int n, int errs,
|
||
|
uint8_t *encode_matrix,
|
||
|
uint8_t **decode_matrix,
|
||
|
uint8_t **decode_tbls,
|
||
|
uint32_t **decode_index)
|
||
10 years ago
|
{
|
||
|
int i, j, r, s, l, z;
|
||
10 years ago
|
uint8_t input_matrix[k * n];
|
||
|
uint8_t inverse_matrix[k * n];
|
||
|
uint8_t tmp_decode_matrix[k * n];
|
||
|
uint8_t tmp_decode_tbls[k * n * 32];
|
||
|
uint32_t tmp_decode_index[k];
|
||
10 years ago
|
|
||
|
for (i = 0, r = 0; i < k; i++, r++) {
|
||
10 years ago
|
while (_minio_src_index_in_error(r, error_index))
|
||
10 years ago
|
r++;
|
||
|
for (j = 0; j < k; j++) {
|
||
|
input_matrix[k * i + j] = encode_matrix[k * r + j];
|
||
|
}
|
||
10 years ago
|
tmp_decode_index[i] = r;
|
||
10 years ago
|
}
|
||
|
|
||
|
// Not all Vandermonde matrix can be inverted
|
||
|
if (gf_invert_matrix(input_matrix, inverse_matrix, k) < 0) {
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
for (l = 0; l < errs; l++) {
|
||
10 years ago
|
if (error_index[l] < k) {
|
||
10 years ago
|
// decoding matrix elements for data chunks
|
||
|
for (j = 0; j < k; j++) {
|
||
10 years ago
|
tmp_decode_matrix[k * l + j] =
|
||
10 years ago
|
inverse_matrix[k *
|
||
10 years ago
|
error_index[l] + j];
|
||
10 years ago
|
}
|
||
|
} else {
|
||
|
int s = 0;
|
||
|
// decoding matrix element for coding chunks
|
||
|
for (i = 0; i < k; i++) {
|
||
|
s = 0;
|
||
|
for (j = 0; j < k; j++) {
|
||
|
s ^= gf_mul(inverse_matrix[j * k + i],
|
||
|
encode_matrix[k *
|
||
10 years ago
|
error_index[l] + j]);
|
||
10 years ago
|
}
|
||
10 years ago
|
tmp_decode_matrix[k * l + i] = s;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
ec_init_tables (k, errs, tmp_decode_matrix, tmp_decode_tbls);
|
||
10 years ago
|
|
||
|
*decode_matrix = tmp_decode_matrix;
|
||
|
*decode_tbls = tmp_decode_tbls;
|
||
10 years ago
|
*decode_index = tmp_decode_index;
|
||
|
|
||
10 years ago
|
return 0;
|
||
|
}
|