Adds complete Cauchy RAID support and removes the mixed Power RAID.

This commit is contained in:
Andrea Mazzoleni 2013-10-25 18:03:05 +02:00
parent 136af37e96
commit 9a5978eb22
20 changed files with 6111 additions and 72023 deletions

294
check.c
View file

@ -24,6 +24,7 @@
#include "parity.h"
#include "handle.h"
#include "raid.h"
#include "combos.h"
/****************************************************************************/
/* check */
@ -89,59 +90,6 @@ static int blockcmp(struct snapraid_state* state, int rehash, struct snapraid_bl
return 0;
}
/**
* Combinations of 1 of 4 elements.
*/
static const struct combo1 {
int a;
} COMBO1[] = {
{ 0 },
{ 1 },
{ 2 },
{ 3 },
};
/**
* Combinations of 2 of 4 elements.
*/
static const struct combo2 {
int a;
int b;
} COMBO2[] = {
{ 0, 1 },
{ 0, 2 },
{ 0, 3 },
{ 1, 2 },
{ 1, 3 },
{ 2, 3 }
};
/**
* Combinations of 3 of 4 elements.
*/
static const struct combo3 {
int a;
int b;
int c;
} COMBO3[] = {
{ 0, 1, 2 },
{ 0, 1, 3 },
{ 0, 2, 3 },
{ 1, 2, 3 }
};
/**
* Combinations of 4 of 4 elements.
*/
static const struct combo4 {
int a;
int b;
int c;
int d;
} COMBO4[] = {
{ 0, 1, 2, 3 },
};
/**
* Checks if the hash of at least one failed block is now matching.
*/
@ -164,7 +112,7 @@ static int is_hash_matching(struct snapraid_state* state, int rehash, unsigned d
/* if we checked something, and no block failed the check */
if (hash_checked && j==failed_count) {
/* recompute all the redundancy information */
raid_gen(RAID_POWER, state->level, buffer, diskmax, state->block_size);
raid_gen(state->level, buffer, diskmax, state->block_size);
return 1;
}
@ -177,12 +125,12 @@ static int is_hash_matching(struct snapraid_state* state, int rehash, unsigned d
static int is_parity_matching(struct snapraid_state* state, unsigned diskmax, unsigned i, unsigned char** buffer, unsigned char** buffer_recov)
{
/* recompute parity, note that we don't need parity over i */
raid_gen(RAID_POWER, i + 1, buffer, diskmax, state->block_size);
raid_gen(i + 1, buffer, diskmax, state->block_size);
/* if the recovered parity block matches */
if (memcmp(buffer[diskmax+i], buffer_recov[i], state->block_size) == 0) {
/* recompute all the redundancy information */
raid_gen(RAID_POWER, state->level, buffer, diskmax, state->block_size);
raid_gen(state->level, buffer, diskmax, state->block_size);
return 1;
}
@ -192,24 +140,33 @@ static int is_parity_matching(struct snapraid_state* state, unsigned diskmax, un
/**
* Repair errors.
* Returns <0 if failure for missing strategy, >0 if data is wrong and we cannot rebuild correctly, 0 on success.
* If success, the parity and qarity are computed in the buffer variable.
* If success, the parity are computed in the buffer variable.
*/
static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, unsigned diskmax, struct failed_struct* failed, unsigned* failed_map, unsigned failed_count, unsigned char** buffer, unsigned char** buffer_recov, unsigned char* buffer_zero)
{
unsigned i, j;
int error;
int has_hash;
int kind = RAID_POWER;
int d[LEV_MAX];
/* no fix required */
if (failed_count == 0) {
/* recompute only parity and qarity */
raid_gen(kind, state->level, buffer, diskmax, state->block_size);
/* recompute only the parity */
raid_gen(state->level, buffer, diskmax, state->block_size);
return 0;
}
/* if too many error, we don't have any strategy */
if (failed_count > state->level) {
return -1;
}
error = 0;
/* setup vector of failed disk indexes */
for(i=0;i<failed_count;++i)
d[i] = failed[failed_map[i]].index;
/* check if there is at least a failed block that can be checked for correctness using the hash */
/* if there isn't, we have to sacrifice a parity block to check that the result is correct */
has_hash = 0;
@ -218,158 +175,79 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u
has_hash = 1;
}
/* recover one block with hash */
if (failed_count == 1 && has_hash) {
for(i=0;i<sizeof(COMBO1)/sizeof(COMBO1[0]);++i) {
/* if we don't have an hash, but we have an extra parity */
if (!has_hash && failed_count < LEV_MAX) {
/* number of parity to use, the last one is used for checking and not for recovering */
unsigned l = failed_count + 1;
for(i=0;combo[l-1][i][0]>=0;++i) {
int* c = combo[l-1][i];
/* if parity is missing, do nothing */
if (buffer_recov[COMBO1[i].a] == 0)
for(j=0;j<l;++j) {
if (buffer_recov[c[j]] == 0)
break;
}
if (j != l)
continue;
/* copy the redundancy to use */
memcpy(buffer[diskmax+COMBO1[i].a], buffer_recov[COMBO1[i].a], state->block_size);
/* copy the parity to use, one less because the last is used for checking */
for(j=0;j<l-1;++j) {
memcpy(buffer[diskmax+c[j]], buffer_recov[c[j]], state->block_size);
}
/* recover data */
raid_recov_1data(kind, failed[failed_map[0]].index, COMBO1[i].a, buffer, diskmax, buffer_zero, state->block_size);
/* recover using one less parity */
raid_recov(l-1, d, c, buffer, diskmax, buffer_zero, state->block_size);
/* use the remaining parity to check the result */
if (is_parity_matching(state, diskmax, c[l-1], buffer, buffer_recov))
return 0;
/* log */
fprintf(stdlog, "parity_error:%u:", pos);
for(j=0;j<l;++j) {
if (j != 0)
fprintf(stdlog, "/");
fprintf(stdlog, "%s", lev_config_name(c[j]));
}
fprintf(stdlog, ": Data error\n");
++error;
}
}
if (has_hash && failed_count <= LEV_MAX) {
/* number of parities to use */
unsigned l = failed_count;
for(i=0;combo[l-1][i][0]>=0;++i) {
int* c = combo[l-1][i];
/* if parity is missing, do nothing */
for(j=0;j<l;++j) {
if (buffer_recov[c[j]] == 0)
break;
}
if (j != l)
continue;
/* copy the parity to use */
for(j=0;j<l;++j) {
memcpy(buffer[diskmax+c[j]], buffer_recov[c[j]], state->block_size);
}
/* recover */
raid_recov(l, d, c, buffer, diskmax, buffer_zero, state->block_size);
/* use the hash to check the result */
if (is_hash_matching(state, rehash, diskmax, failed, failed_map, failed_count, buffer, buffer_zero))
return 0;
fprintf(stdlog, "parity_error:%u:%s: Data error\n", pos, lev_config_name(COMBO1[i].a));
++error;
}
}
/* recover one block without hash */
if (failed_count == 1 && !has_hash) {
for(i=0;i<sizeof(COMBO2)/sizeof(COMBO2[0]);++i) {
/* if parity is missing, do nothing */
if (buffer_recov[COMBO2[i].a] == 0 || buffer_recov[COMBO2[i].b] == 0)
continue;
/* copy the redundancy to use */
memcpy(buffer[diskmax+COMBO2[i].a], buffer_recov[COMBO2[i].a], state->block_size);
/* recover data */
raid_recov_1data(kind, failed[failed_map[0]].index, COMBO2[i].a, buffer, diskmax, buffer_zero, state->block_size);
if (is_parity_matching(state, diskmax, COMBO2[i].b, buffer, buffer_recov))
return 0;
fprintf(stdlog, "parity_error:%u:%s/%s: Data error\n", pos, lev_config_name(COMBO2[i].a), lev_config_name(COMBO2[i].b));
++error;
}
}
/* recover two blocks with hash */
if (failed_count == 2 && has_hash) {
for(i=0;i<sizeof(COMBO2)/sizeof(COMBO2[0]);++i) {
/* if parity is missing, do nothing */
if (buffer_recov[COMBO2[i].a] == 0 || buffer_recov[COMBO2[i].b] == 0)
continue;
/* copy the redundancy to use */
memcpy(buffer[diskmax+COMBO2[i].a], buffer_recov[COMBO2[i].a], state->block_size);
memcpy(buffer[diskmax+COMBO2[i].b], buffer_recov[COMBO2[i].b], state->block_size);
/* recover data */
raid_recov_2data(kind, failed[failed_map[0]].index, failed[failed_map[1]].index, COMBO2[i].a, COMBO2[i].b, buffer, diskmax, buffer_zero, state->block_size);
if (is_hash_matching(state, rehash, diskmax, failed, failed_map, failed_count, buffer, buffer_zero))
return 0;
fprintf(stdlog, "parity_error:%u:%s/%s: Data error\n", pos, lev_config_name(COMBO2[i].a), lev_config_name(COMBO2[i].b));
++error;
}
}
/* recover two blocks without hash */
if (failed_count == 2 && !has_hash) {
for(i=0;i<sizeof(COMBO3)/sizeof(COMBO3[0]);++i) {
/* if parity is missing, do nothing */
if (buffer_recov[COMBO3[i].a] == 0 || buffer_recov[COMBO3[i].b] == 0 || buffer_recov[COMBO3[i].c] == 0)
continue;
/* copy the redundancy to use */
memcpy(buffer[diskmax+COMBO3[i].a], buffer_recov[COMBO3[i].a], state->block_size);
memcpy(buffer[diskmax+COMBO3[i].b], buffer_recov[COMBO3[i].b], state->block_size);
/* recover data */
raid_recov_2data(kind, failed[failed_map[0]].index, failed[failed_map[1]].index, COMBO3[i].a, COMBO3[i].b, buffer, diskmax, buffer_zero, state->block_size);
if (is_parity_matching(state, diskmax, COMBO3[i].c, buffer, buffer_recov))
return 0;
fprintf(stdlog, "parity_error:%u:%s/%s/%s: Data error\n", pos, lev_config_name(COMBO3[i].a), lev_config_name(COMBO3[i].b), lev_config_name(COMBO3[i].c));
++error;
}
}
/* recover three blocks with hash */
if (failed_count == 3 && has_hash) {
for(i=0;i<sizeof(COMBO3)/sizeof(COMBO3[0]);++i) {
/* if parity is missing, do nothing */
if (buffer_recov[COMBO3[i].a] == 0 || buffer_recov[COMBO3[i].b] == 0 || buffer_recov[COMBO3[i].c] == 0)
continue;
/* copy the redundancy to use */
memcpy(buffer[diskmax+COMBO3[i].a], buffer_recov[COMBO3[i].a], state->block_size);
memcpy(buffer[diskmax+COMBO3[i].b], buffer_recov[COMBO3[i].b], state->block_size);
memcpy(buffer[diskmax+COMBO3[i].c], buffer_recov[COMBO3[i].c], state->block_size);
/* recover data */
raid_recov_3data(kind, failed[failed_map[0]].index, failed[failed_map[1]].index, failed[failed_map[2]].index, COMBO3[i].a, COMBO3[i].b, COMBO3[i].c, buffer, diskmax, buffer_zero, state->block_size);
if (is_hash_matching(state, rehash, diskmax, failed, failed_map, failed_count, buffer, buffer_zero))
return 0;
fprintf(stdlog, "parity_error:%u:%s/%s/%s: Data error\n", pos, lev_config_name(COMBO3[i].a), lev_config_name(COMBO3[i].b), lev_config_name(COMBO3[i].c));
++error;
}
}
/* recover three blocks without hash */
if (failed_count == 3 && !has_hash) {
for(i=0;i<sizeof(COMBO4)/sizeof(COMBO4[0]);++i) {
/* if parity is missing, do nothing */
if (buffer_recov[COMBO4[i].a] == 0 || buffer_recov[COMBO4[i].b] == 0 || buffer_recov[COMBO4[i].c] == 0 || buffer_recov[COMBO4[i].d] == 0)
continue;
/* copy the redundancy to use */
memcpy(buffer[diskmax+COMBO4[i].a], buffer_recov[COMBO4[i].a], state->block_size);
memcpy(buffer[diskmax+COMBO4[i].b], buffer_recov[COMBO4[i].b], state->block_size);
memcpy(buffer[diskmax+COMBO4[i].c], buffer_recov[COMBO4[i].c], state->block_size);
/* recover data */
raid_recov_3data(kind, failed[failed_map[0]].index, failed[failed_map[1]].index, failed[failed_map[2]].index, COMBO4[i].a, COMBO4[i].b, COMBO4[i].c, buffer, diskmax, buffer_zero, state->block_size);
if (is_parity_matching(state, diskmax, COMBO4[i].d, buffer, buffer_recov))
return 0;
fprintf(stdlog, "parity_error:%u:%s/%s/%s/%s: Data error\n", pos, lev_config_name(COMBO4[i].a), lev_config_name(COMBO4[i].b), lev_config_name(COMBO4[i].c), lev_config_name(COMBO4[i].d));
++error;
}
}
/* recover four blocks with hash */
if (failed_count == 4 && has_hash) {
for(i=0;i<sizeof(COMBO4)/sizeof(COMBO4[0]);++i) {
/* if parity is missing, do nothing */
if (buffer_recov[COMBO4[i].a] == 0 || buffer_recov[COMBO4[i].b] == 0 || buffer_recov[COMBO4[i].c] == 0 || buffer_recov[COMBO4[i].d] == 0)
continue;
/* copy the redundancy to use */
memcpy(buffer[diskmax+COMBO4[i].a], buffer_recov[COMBO4[i].a], state->block_size);
memcpy(buffer[diskmax+COMBO4[i].b], buffer_recov[COMBO4[i].b], state->block_size);
memcpy(buffer[diskmax+COMBO4[i].c], buffer_recov[COMBO4[i].c], state->block_size);
memcpy(buffer[diskmax+COMBO4[i].d], buffer_recov[COMBO4[i].d], state->block_size);
/* recover data */
raid_recov_4data(kind, failed[failed_map[0]].index, failed[failed_map[1]].index, failed[failed_map[2]].index, failed[failed_map[3]].index, COMBO4[i].a, COMBO4[i].b, COMBO4[i].c, COMBO4[i].d, buffer, diskmax, buffer_zero, state->block_size);
if (is_hash_matching(state, rehash, diskmax, failed, failed_map, failed_count, buffer, buffer_zero))
return 0;
fprintf(stdlog, "parity_error:%u:%s/%s/%s/%s: Data error\n", pos, lev_config_name(COMBO4[i].a), lev_config_name(COMBO4[i].b), lev_config_name(COMBO4[i].c), lev_config_name(COMBO4[i].d));
/* log */
fprintf(stdlog, "parity_error:%u:", pos);
for(j=0;j<l;++j) {
if (j != 0)
fprintf(stdlog, "/");
fprintf(stdlog, "%s", lev_config_name(c[j]));
}
fprintf(stdlog, ": Data error\n");
++error;
}
}
@ -440,8 +318,8 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign
/* if nothing to fix */
if (!something_to_recover) {
/* recompute only parity and qarity */
raid_gen(RAID_POWER, state->level, buffer, diskmax, state->block_size);
/* recompute only the parity */
raid_gen(state->level, buffer, diskmax, state->block_size);
return 0;
}
@ -686,8 +564,10 @@ static int state_check_process(struct snapraid_state* state, int check, int fix,
/* keep track of the number of failed blocks */
failed_count = 0;
/* if we have to use the old hash */
/* get block specific info */
info = info_get(&state->infoarr, i);
/* if we have to use the old hash */
rehash = info_get_rehash(info);
/* for each disk, process the block */