mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-04 13:50:09 -05:00
Generates combinations at runtime.
This commit is contained in:
parent
fafa641b42
commit
fae56fd9af
6 changed files with 217 additions and 486 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
bin_PROGRAMS = snapraid
|
bin_PROGRAMS = snapraid
|
||||||
check_PROGRAMS = mktest
|
check_PROGRAMS = mktest
|
||||||
EXTRA_PROGRAMS = mktables mkcombos
|
EXTRA_PROGRAMS = mktables
|
||||||
|
|
||||||
snapraid_SOURCES = \
|
snapraid_SOURCES = \
|
||||||
snapraid.c \
|
snapraid.c \
|
||||||
|
|
@ -31,9 +31,6 @@ snapraid_SOURCES = \
|
||||||
mktables_SOURCES = \
|
mktables_SOURCES = \
|
||||||
mktables.c
|
mktables.c
|
||||||
|
|
||||||
mkcombos_SOURCES = \
|
|
||||||
mkcombos.c
|
|
||||||
|
|
||||||
noinst_HEADERS = \
|
noinst_HEADERS = \
|
||||||
portable.h \
|
portable.h \
|
||||||
snapraid.h \
|
snapraid.h \
|
||||||
|
|
@ -63,8 +60,8 @@ noinst_HEADERS = \
|
||||||
fnmatch.h \
|
fnmatch.h \
|
||||||
cpu.h \
|
cpu.h \
|
||||||
raid.h \
|
raid.h \
|
||||||
|
combo.h \
|
||||||
tables.h \
|
tables.h \
|
||||||
combos.h \
|
|
||||||
import.h \
|
import.h \
|
||||||
mingw.h \
|
mingw.h \
|
||||||
unix.h
|
unix.h
|
||||||
|
|
|
||||||
95
check.c
95
check.c
|
|
@ -24,7 +24,7 @@
|
||||||
#include "parity.h"
|
#include "parity.h"
|
||||||
#include "handle.h"
|
#include "handle.h"
|
||||||
#include "raid.h"
|
#include "raid.h"
|
||||||
#include "combos.h"
|
#include "combo.h"
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
/* check */
|
/* check */
|
||||||
|
|
@ -144,10 +144,11 @@ static int is_parity_matching(struct snapraid_state* state, unsigned diskmax, un
|
||||||
*/
|
*/
|
||||||
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)
|
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;
|
unsigned i, n;
|
||||||
int error;
|
int error;
|
||||||
int has_hash;
|
int has_hash;
|
||||||
int d[LEV_MAX];
|
int d[LEV_MAX];
|
||||||
|
int p[LEV_MAX];
|
||||||
|
|
||||||
/* no fix required */
|
/* no fix required */
|
||||||
if (failed_count == 0) {
|
if (failed_count == 0) {
|
||||||
|
|
@ -157,7 +158,8 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if too many error, we don't have any strategy */
|
/* if too many error, we don't have any strategy */
|
||||||
if (failed_count > state->level) {
|
n = state->level;
|
||||||
|
if (failed_count > n) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,71 +172,74 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u
|
||||||
/* check if there is at least a failed block that can be checked for correctness using the hash */
|
/* 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 */
|
/* if there isn't, we have to sacrifice a parity block to check that the result is correct */
|
||||||
has_hash = 0;
|
has_hash = 0;
|
||||||
for(j=0;j<failed_count;++j) {
|
for(i=0;i<failed_count;++i) {
|
||||||
if (block_has_updated_hash(failed[failed_map[j]].block)) /* if the block can be checked */
|
if (block_has_updated_hash(failed[failed_map[i]].block)) /* if the block can be checked */
|
||||||
has_hash = 1;
|
has_hash = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we don't have an hash, but we have an extra parity */
|
/* if we don't have a hash, but we have an extra parity */
|
||||||
if (!has_hash && failed_count < LEV_MAX) {
|
/* (strictly-less failures than number of parities) */
|
||||||
/* number of parity to use, the last one is used for checking and not for recovering */
|
if (!has_hash && failed_count < n) {
|
||||||
unsigned l = failed_count + 1;
|
/* number of parity to use, one more to check the recovering */
|
||||||
for(i=0;combo[l-1][i][0]>=0;++i) {
|
unsigned r = failed_count + 1;
|
||||||
int* c = combo[l-1][i];
|
|
||||||
|
|
||||||
/* if parity is missing, do nothing */
|
/* all combinations (r of n) parities */
|
||||||
for(j=0;j<l;++j) {
|
combination_first(r, n, p);
|
||||||
if (buffer_recov[c[j]] == 0)
|
do {
|
||||||
|
/* if a parity is missing, do nothing */
|
||||||
|
for(i=0;i<r;++i) {
|
||||||
|
if (buffer_recov[p[i]] == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j != l)
|
if (i != r)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* copy the parity to use, one less because the last is used for checking */
|
/* copy the parities to use, one less because the last is used for checking */
|
||||||
for(j=0;j<l-1;++j) {
|
for(i=0;i<r-1;++i)
|
||||||
memcpy(buffer[diskmax+c[j]], buffer_recov[c[j]], state->block_size);
|
memcpy(buffer[diskmax+p[i]], buffer_recov[p[i]], state->block_size);
|
||||||
}
|
|
||||||
|
|
||||||
/* recover using one less parity */
|
/* recover using one less parity, the p[r-1] one */
|
||||||
raid_recov(l-1, d, c, buffer, diskmax, buffer_zero, state->block_size);
|
raid_recov(r-1, d, p, buffer, diskmax, buffer_zero, state->block_size);
|
||||||
|
|
||||||
/* use the remaining parity to check the result */
|
/* use the remaining p[r-1] parity to check the result */
|
||||||
if (is_parity_matching(state, diskmax, c[l-1], buffer, buffer_recov))
|
if (is_parity_matching(state, diskmax, p[r-1], buffer, buffer_recov))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* log */
|
/* log */
|
||||||
fprintf(stdlog, "parity_error:%u:", pos);
|
fprintf(stdlog, "parity_error:%u:", pos);
|
||||||
for(j=0;j<l;++j) {
|
for(i=0;i<r;++i) {
|
||||||
if (j != 0)
|
if (i != 0)
|
||||||
fprintf(stdlog, "/");
|
fprintf(stdlog, "/");
|
||||||
fprintf(stdlog, "%s", lev_config_name(c[j]));
|
fprintf(stdlog, "%s", lev_config_name(p[i]));
|
||||||
}
|
}
|
||||||
fprintf(stdlog, ": Data error\n");
|
fprintf(stdlog, ": Data error\n");
|
||||||
++error;
|
++error;
|
||||||
}
|
} while (combination_next(r, n, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_hash && failed_count <= LEV_MAX) {
|
/* if we have a hash, and enough parities */
|
||||||
/* number of parities to use */
|
/* (less-or-equal failures than number of parities) */
|
||||||
unsigned l = failed_count;
|
if (has_hash && failed_count <= n) {
|
||||||
for(i=0;combo[l-1][i][0]>=0;++i) {
|
/* number of parities to use equal at the number of failures */
|
||||||
int* c = combo[l-1][i];
|
unsigned r = failed_count;
|
||||||
|
|
||||||
/* if parity is missing, do nothing */
|
/* all combinations (r of n) parities */
|
||||||
for(j=0;j<l;++j) {
|
combination_first(r, n, p);
|
||||||
if (buffer_recov[c[j]] == 0)
|
do {
|
||||||
|
/* if a parity is missing, do nothing */
|
||||||
|
for(i=0;i<r;++i) {
|
||||||
|
if (buffer_recov[p[i]] == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j != l)
|
if (i != r)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* copy the parity to use */
|
/* copy the parities to use */
|
||||||
for(j=0;j<l;++j) {
|
for(i=0;i<r;++i)
|
||||||
memcpy(buffer[diskmax+c[j]], buffer_recov[c[j]], state->block_size);
|
memcpy(buffer[diskmax+p[i]], buffer_recov[p[i]], state->block_size);
|
||||||
}
|
|
||||||
|
|
||||||
/* recover */
|
/* recover */
|
||||||
raid_recov(l, d, c, buffer, diskmax, buffer_zero, state->block_size);
|
raid_recov(r, d, p, buffer, diskmax, buffer_zero, state->block_size);
|
||||||
|
|
||||||
/* use the hash to check the result */
|
/* use the hash to check the result */
|
||||||
if (is_hash_matching(state, rehash, diskmax, failed, failed_map, failed_count, buffer, buffer_zero))
|
if (is_hash_matching(state, rehash, diskmax, failed, failed_map, failed_count, buffer, buffer_zero))
|
||||||
|
|
@ -242,14 +247,14 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u
|
||||||
|
|
||||||
/* log */
|
/* log */
|
||||||
fprintf(stdlog, "parity_error:%u:", pos);
|
fprintf(stdlog, "parity_error:%u:", pos);
|
||||||
for(j=0;j<l;++j) {
|
for(i=0;i<r;++i) {
|
||||||
if (j != 0)
|
if (i != 0)
|
||||||
fprintf(stdlog, "/");
|
fprintf(stdlog, "/");
|
||||||
fprintf(stdlog, "%s", lev_config_name(c[j]));
|
fprintf(stdlog, "%s", lev_config_name(p[i]));
|
||||||
}
|
}
|
||||||
fprintf(stdlog, ": Data error\n");
|
fprintf(stdlog, ": Data error\n");
|
||||||
++error;
|
++error;
|
||||||
}
|
} while (combination_next(r, n, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return the number of failed attempts, or -1 if no strategy */
|
/* return the number of failed attempts, or -1 if no strategy */
|
||||||
|
|
|
||||||
90
combo.h
Normal file
90
combo.h
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Andrea Mazzoleni
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __COMBO_H
|
||||||
|
#define __COMBO_H
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the first combination of r of n elements.
|
||||||
|
*
|
||||||
|
* Typical use is with combination_next() in the form :
|
||||||
|
*
|
||||||
|
* int i[R];
|
||||||
|
* combination_first(R, N, i);
|
||||||
|
* do {
|
||||||
|
* code using i[0], i[1], ..., i[R-1]
|
||||||
|
* } while (combination_next(R, N, i));
|
||||||
|
*
|
||||||
|
* It's equivalent at the code :
|
||||||
|
*
|
||||||
|
* for(i[0]=0;i[0]<N-(R-1);++i[0])
|
||||||
|
* for(i[1]=i[0]+1;i[1]<N-(R-2);++i[1])
|
||||||
|
* ...
|
||||||
|
* for(i[R-2]=i[R-3]+1;i[R-2]<N-1;++i[R-2])
|
||||||
|
* for(i[R-1]=i[R-2]+1;i[R-1]<N;++i[R-1])
|
||||||
|
* code using i[0], i[1], ..., i[R-1]
|
||||||
|
*/
|
||||||
|
static inline void combination_first(unsigned r, unsigned n, int* c)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
(void)n; /* unused, but kept for clarity */
|
||||||
|
assert(0 < r && r <= n);
|
||||||
|
|
||||||
|
for(i=0;i<r;++i)
|
||||||
|
c[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the next combination of r of n elements.
|
||||||
|
* Return ==0 when finished.
|
||||||
|
*/
|
||||||
|
static inline int combination_next(unsigned r, unsigned n, int* c)
|
||||||
|
{
|
||||||
|
unsigned i = r - 1; /* present position */
|
||||||
|
int h = n; /* high limit for this position */
|
||||||
|
|
||||||
|
recurse:
|
||||||
|
/* next element at position i */
|
||||||
|
++c[i];
|
||||||
|
|
||||||
|
/* if the position has reached the max */
|
||||||
|
if (c[i] >= h) {
|
||||||
|
|
||||||
|
/* if we are at the first level, we have finished */
|
||||||
|
if (i == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* increase the previous position */
|
||||||
|
--i;
|
||||||
|
--h;
|
||||||
|
goto recurse;
|
||||||
|
}
|
||||||
|
|
||||||
|
++i;
|
||||||
|
|
||||||
|
/* initialize all the next positions, if any */
|
||||||
|
while (i < r) {
|
||||||
|
c[i] = c[i-1] + 1; /* each position start at the next value of the previous one */
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
111
combos.h
111
combos.h
|
|
@ -1,111 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2013 Andrea Mazzoleni
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Combinations of 6 elements.
|
|
||||||
* Ends is marked with first element as -1.
|
|
||||||
*/
|
|
||||||
static int combo[][32][8] = {
|
|
||||||
/* combinations of 1 of 6 elements */
|
|
||||||
{
|
|
||||||
{ 0 },
|
|
||||||
{ 1 },
|
|
||||||
{ 2 },
|
|
||||||
{ 3 },
|
|
||||||
{ 4 },
|
|
||||||
{ 5 },
|
|
||||||
{ -1 }
|
|
||||||
},
|
|
||||||
/* combinations of 2 of 6 elements */
|
|
||||||
{
|
|
||||||
{ 0, 1 },
|
|
||||||
{ 0, 2 },
|
|
||||||
{ 0, 3 },
|
|
||||||
{ 0, 4 },
|
|
||||||
{ 0, 5 },
|
|
||||||
{ 1, 2 },
|
|
||||||
{ 1, 3 },
|
|
||||||
{ 1, 4 },
|
|
||||||
{ 1, 5 },
|
|
||||||
{ 2, 3 },
|
|
||||||
{ 2, 4 },
|
|
||||||
{ 2, 5 },
|
|
||||||
{ 3, 4 },
|
|
||||||
{ 3, 5 },
|
|
||||||
{ 4, 5 },
|
|
||||||
{ -1 }
|
|
||||||
},
|
|
||||||
/* combinations of 3 of 6 elements */
|
|
||||||
{
|
|
||||||
{ 0, 1, 2 },
|
|
||||||
{ 0, 1, 3 },
|
|
||||||
{ 0, 1, 4 },
|
|
||||||
{ 0, 1, 5 },
|
|
||||||
{ 0, 2, 3 },
|
|
||||||
{ 0, 2, 4 },
|
|
||||||
{ 0, 2, 5 },
|
|
||||||
{ 0, 3, 4 },
|
|
||||||
{ 0, 3, 5 },
|
|
||||||
{ 0, 4, 5 },
|
|
||||||
{ 1, 2, 3 },
|
|
||||||
{ 1, 2, 4 },
|
|
||||||
{ 1, 2, 5 },
|
|
||||||
{ 1, 3, 4 },
|
|
||||||
{ 1, 3, 5 },
|
|
||||||
{ 1, 4, 5 },
|
|
||||||
{ 2, 3, 4 },
|
|
||||||
{ 2, 3, 5 },
|
|
||||||
{ 2, 4, 5 },
|
|
||||||
{ 3, 4, 5 },
|
|
||||||
{ -1 }
|
|
||||||
},
|
|
||||||
/* combinations of 4 of 6 elements */
|
|
||||||
{
|
|
||||||
{ 0, 1, 2, 3 },
|
|
||||||
{ 0, 1, 2, 4 },
|
|
||||||
{ 0, 1, 2, 5 },
|
|
||||||
{ 0, 1, 3, 4 },
|
|
||||||
{ 0, 1, 3, 5 },
|
|
||||||
{ 0, 1, 4, 5 },
|
|
||||||
{ 0, 2, 3, 4 },
|
|
||||||
{ 0, 2, 3, 5 },
|
|
||||||
{ 0, 2, 4, 5 },
|
|
||||||
{ 0, 3, 4, 5 },
|
|
||||||
{ 1, 2, 3, 4 },
|
|
||||||
{ 1, 2, 3, 5 },
|
|
||||||
{ 1, 2, 4, 5 },
|
|
||||||
{ 1, 3, 4, 5 },
|
|
||||||
{ 2, 3, 4, 5 },
|
|
||||||
{ -1 }
|
|
||||||
},
|
|
||||||
/* combinations of 5 of 6 elements */
|
|
||||||
{
|
|
||||||
{ 0, 1, 2, 3, 4 },
|
|
||||||
{ 0, 1, 2, 3, 5 },
|
|
||||||
{ 0, 1, 2, 4, 5 },
|
|
||||||
{ 0, 1, 3, 4, 5 },
|
|
||||||
{ 0, 2, 3, 4, 5 },
|
|
||||||
{ 1, 2, 3, 4, 5 },
|
|
||||||
{ -1 }
|
|
||||||
},
|
|
||||||
/* combinations of 6 of 6 elements */
|
|
||||||
{
|
|
||||||
{ 0, 1, 2, 3, 4, 5 },
|
|
||||||
{ -1 }
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
98
mkcombos.c
98
mkcombos.c
|
|
@ -1,98 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2013 Andrea Mazzoleni
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
unsigned combo(unsigned mask, unsigned pick, unsigned from, unsigned to, unsigned* map)
|
|
||||||
{
|
|
||||||
unsigned i;
|
|
||||||
unsigned count;
|
|
||||||
|
|
||||||
if (pick == 0) {
|
|
||||||
map[0] = mask;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
for(i=from;i<=to;++i)
|
|
||||||
count += combo(mask | (1 << i), pick - 1, i + 1, to, map + count);
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_combo(unsigned n)
|
|
||||||
{
|
|
||||||
unsigned map[10000];
|
|
||||||
unsigned count;
|
|
||||||
unsigned i, j, k;
|
|
||||||
|
|
||||||
printf("/**\n");
|
|
||||||
printf(" * Combinations of %u elements.\n", n);
|
|
||||||
printf(" * Ends is marked with first element as -1.\n");
|
|
||||||
printf(" */\n");
|
|
||||||
printf("static int combo[][32][8] = {\n"); /* fixed value 32/8, change them if changing maximum n */
|
|
||||||
|
|
||||||
for(i=1;i<=n;++i) {
|
|
||||||
count = combo(0, i, 0, n - 1, map);
|
|
||||||
|
|
||||||
printf("\t/* combinations of %u of %u elements */\n", i, n);
|
|
||||||
printf("\t{\n");
|
|
||||||
for(j=0;j<count;++j) {
|
|
||||||
unsigned mask = map[j];
|
|
||||||
printf("\t\t{ ");
|
|
||||||
for(k=0;mask;++k) {
|
|
||||||
if (mask & 1) {
|
|
||||||
printf("%u", k);
|
|
||||||
mask >>= 1;
|
|
||||||
if (mask)
|
|
||||||
printf(", ");
|
|
||||||
} else {
|
|
||||||
mask >>= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf(" },\n");
|
|
||||||
}
|
|
||||||
printf("\t\t{ -1 }\n");
|
|
||||||
printf("\t},\n");
|
|
||||||
}
|
|
||||||
printf("};\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
printf("/*\n");
|
|
||||||
printf(" * Copyright (C) 2013 Andrea Mazzoleni\n");
|
|
||||||
printf(" *\n");
|
|
||||||
printf(" * This program is free software: you can redistribute it and/or modify\n");
|
|
||||||
printf(" * it under the terms of the GNU General Public License as published by\n");
|
|
||||||
printf(" * the Free Software Foundation, either version 2 of the License, or\n");
|
|
||||||
printf(" * (at your option) any later version.\n");
|
|
||||||
printf(" *\n");
|
|
||||||
printf(" * This program is distributed in the hope that it will be useful,\n");
|
|
||||||
printf(" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
|
|
||||||
printf(" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
|
|
||||||
printf(" * GNU General Public License for more details.\n");
|
|
||||||
printf(" *\n");
|
|
||||||
printf(" * You should have received a copy of the GNU General Public License\n");
|
|
||||||
printf(" * along with this program. If not, see <http://www.gnu.org/licenses/>.\n");
|
|
||||||
printf(" */\n");
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
print_combo(6);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
298
selftest.c
298
selftest.c
|
|
@ -23,7 +23,7 @@
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "elem.h"
|
#include "elem.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "combos.h"
|
#include "combo.h"
|
||||||
|
|
||||||
struct hash_test_vector {
|
struct hash_test_vector {
|
||||||
const char* data;
|
const char* data;
|
||||||
|
|
@ -47,7 +47,40 @@ static struct hash_test_vector TEST_SPOOKY2[] = {
|
||||||
{ 0, 0, { 0 } }
|
{ 0, 0, { 0 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void recovtest(int diskmax, unsigned block_size)
|
/**
|
||||||
|
* Binomial coefficient of n over r.
|
||||||
|
*/
|
||||||
|
static unsigned bc(unsigned n, unsigned r)
|
||||||
|
{
|
||||||
|
if (r == 0 || n == r)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return bc(n - 1, r - 1) + bc(n - 1, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void combotest(void)
|
||||||
|
{
|
||||||
|
unsigned r;
|
||||||
|
unsigned count;
|
||||||
|
int p[LEV_MAX];
|
||||||
|
|
||||||
|
/* all parities */
|
||||||
|
for(r=1;r<=LEV_MAX;++r) {
|
||||||
|
/* count combination (r of LEV_MAX) parities */
|
||||||
|
count = 0;
|
||||||
|
combination_first(r, LEV_MAX, p);
|
||||||
|
do {
|
||||||
|
++count;
|
||||||
|
} while (combination_next(r, LEV_MAX, p));
|
||||||
|
|
||||||
|
if (count != bc(LEV_MAX, r)) {
|
||||||
|
fprintf(stderr, "Failed COMBO test\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void recovtest(unsigned diskmax, unsigned block_size)
|
||||||
{
|
{
|
||||||
void* buffer_alloc;
|
void* buffer_alloc;
|
||||||
unsigned char** buffer;
|
unsigned char** buffer;
|
||||||
|
|
@ -60,8 +93,10 @@ static void recovtest(int diskmax, unsigned block_size)
|
||||||
unsigned char* waste;
|
unsigned char* waste;
|
||||||
unsigned buffermax;
|
unsigned buffermax;
|
||||||
int d[LEV_MAX];
|
int d[LEV_MAX];
|
||||||
int i;
|
int p[LEV_MAX];
|
||||||
|
unsigned i;
|
||||||
unsigned j;
|
unsigned j;
|
||||||
|
unsigned r;
|
||||||
|
|
||||||
buffermax = diskmax + LEV_MAX * 2 + 2;
|
buffermax = diskmax + LEV_MAX * 2 + 2;
|
||||||
|
|
||||||
|
|
@ -93,232 +128,45 @@ static void recovtest(int diskmax, unsigned block_size)
|
||||||
for(i=0;i<LEV_MAX;++i)
|
for(i=0;i<LEV_MAX;++i)
|
||||||
parity[i] = waste;
|
parity[i] = waste;
|
||||||
|
|
||||||
/* check 6data */
|
/* all parity levels */
|
||||||
for(d[0]=0;d[0]<diskmax;++d[0]) {
|
for(r=1;r<=LEV_MAX;++r) {
|
||||||
for(d[1]=d[0]+1;d[1]<diskmax;++d[1]) {
|
|
||||||
for(d[2]=d[1]+1;d[2]<diskmax;++d[2]) {
|
|
||||||
for(d[3]=d[2]+1;d[3]<diskmax;++d[3]) {
|
|
||||||
for(d[4]=d[3]+1;d[4]<diskmax;++d[4]) {
|
|
||||||
for(d[5]=d[4]+1;d[5]<diskmax;++d[5]) {
|
|
||||||
for(i=0;combo[5][i][0]>=0;++i) {
|
|
||||||
/* set */
|
|
||||||
for(j=0;j<6;++j) {
|
|
||||||
/* remove the missing data */
|
|
||||||
data_save[j] = data[d[j]];
|
|
||||||
data[d[j]] = test[j];
|
|
||||||
/* set the parity to use */
|
|
||||||
parity[combo[5][i][j]] = parity_save[combo[5][i][j]];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* recover */
|
/* all combinations (r of diskmax) disks */
|
||||||
raid_recov(6, d, combo[5][i], buffer, diskmax, zero, block_size);
|
combination_first(r, diskmax, d);
|
||||||
|
do {
|
||||||
|
|
||||||
/* check */
|
/* all combinations (r of LEV_MAX) parities */
|
||||||
for(j=0;j<6;++j) {
|
combination_first(r, LEV_MAX, p);
|
||||||
if (memcmp(test[j], data_save[j], block_size) != 0) {
|
do {
|
||||||
fprintf(stderr, "Failed RAID test\n");
|
/* set */
|
||||||
exit(EXIT_FAILURE);
|
for(i=0;i<r;++i) {
|
||||||
|
/* remove the missing data */
|
||||||
|
data_save[i] = data[d[i]];
|
||||||
|
data[d[i]] = test[i];
|
||||||
|
/* set the parity to use */
|
||||||
|
parity[p[i]] = parity_save[p[i]];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* restore */
|
/* recover */
|
||||||
for(j=0;j<6;++j) {
|
raid_recov(r, d, p, buffer, diskmax, zero, block_size);
|
||||||
/* restore the data */
|
|
||||||
data[d[j]] = data_save[j];
|
|
||||||
/* restore the parity */
|
|
||||||
parity[combo[5][i][j]] = waste;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check 5data */
|
/* check */
|
||||||
for(d[0]=0;d[0]<diskmax;++d[0]) {
|
for(i=0;i<r;++i) {
|
||||||
for(d[1]=d[0]+1;d[1]<diskmax;++d[1]) {
|
if (memcmp(test[i], data_save[i], block_size) != 0) {
|
||||||
for(d[2]=d[1]+1;d[2]<diskmax;++d[2]) {
|
fprintf(stderr, "Failed RECOV test\n");
|
||||||
for(d[3]=d[2]+1;d[3]<diskmax;++d[3]) {
|
exit(EXIT_FAILURE);
|
||||||
for(d[4]=d[3]+1;d[4]<diskmax;++d[4]) {
|
}
|
||||||
for(i=0;combo[4][i][0]>=0;++i) {
|
|
||||||
/* set */
|
|
||||||
for(j=0;j<5;++j) {
|
|
||||||
/* remove the missing data */
|
|
||||||
data_save[j] = data[d[j]];
|
|
||||||
data[d[j]] = test[j];
|
|
||||||
/* set the parity to use */
|
|
||||||
parity[combo[4][i][j]] = parity_save[combo[4][i][j]];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* recover */
|
|
||||||
raid_recov(5, d, combo[4][i], buffer, diskmax, zero, block_size);
|
|
||||||
|
|
||||||
/* check */
|
|
||||||
for(j=0;j<5;++j) {
|
|
||||||
if (memcmp(test[j], data_save[j], block_size) != 0) {
|
|
||||||
fprintf(stderr, "Failed RAID test\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* restore */
|
/* restore */
|
||||||
for(j=0;j<5;++j) {
|
for(i=0;i<r;++i) {
|
||||||
/* restore the data */
|
/* restore the data */
|
||||||
data[d[j]] = data_save[j];
|
data[d[i]] = data_save[i];
|
||||||
/* restore the parity */
|
/* restore the parity */
|
||||||
parity[combo[4][i][j]] = waste;
|
parity[p[i]] = waste;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check 4data */
|
|
||||||
for(d[0]=0;d[0]<diskmax;++d[0]) {
|
|
||||||
for(d[1]=d[0]+1;d[1]<diskmax;++d[1]) {
|
|
||||||
for(d[2]=d[1]+1;d[2]<diskmax;++d[2]) {
|
|
||||||
for(d[3]=d[2]+1;d[3]<diskmax;++d[3]) {
|
|
||||||
for(i=0;combo[3][i][0]>=0;++i) {
|
|
||||||
/* set */
|
|
||||||
for(j=0;j<4;++j) {
|
|
||||||
/* remove the missing data */
|
|
||||||
data_save[j] = data[d[j]];
|
|
||||||
data[d[j]] = test[j];
|
|
||||||
/* set the parity to use */
|
|
||||||
parity[combo[3][i][j]] = parity_save[combo[3][i][j]];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* recover */
|
|
||||||
raid_recov(4, d, combo[3][i], buffer, diskmax, zero, block_size);
|
|
||||||
|
|
||||||
/* check */
|
|
||||||
for(j=0;j<4;++j) {
|
|
||||||
if (memcmp(test[j], data_save[j], block_size) != 0) {
|
|
||||||
fprintf(stderr, "Failed RAID test\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
}
|
} while (combination_next(r, LEV_MAX, p));
|
||||||
|
} while (combination_next(r, diskmax, d));
|
||||||
/* restore */
|
|
||||||
for(j=0;j<4;++j) {
|
|
||||||
/* restore the data */
|
|
||||||
data[d[j]] = data_save[j];
|
|
||||||
/* restore the parity */
|
|
||||||
parity[combo[3][i][j]] = waste;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check 3data */
|
|
||||||
for(d[0]=0;d[0]<diskmax;++d[0]) {
|
|
||||||
for(d[1]=d[0]+1;d[1]<diskmax;++d[1]) {
|
|
||||||
for(d[2]=d[1]+1;d[2]<diskmax;++d[2]) {
|
|
||||||
for(i=0;combo[2][i][0]>=0;++i) {
|
|
||||||
/* set */
|
|
||||||
for(j=0;j<3;++j) {
|
|
||||||
/* remove the missing data */
|
|
||||||
data_save[j] = data[d[j]];
|
|
||||||
data[d[j]] = test[j];
|
|
||||||
/* set the parity to use */
|
|
||||||
parity[combo[2][i][j]] = parity_save[combo[2][i][j]];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* recover */
|
|
||||||
raid_recov(3, d, combo[2][i], buffer, diskmax, zero, block_size);
|
|
||||||
|
|
||||||
/* check */
|
|
||||||
for(j=0;j<3;++j) {
|
|
||||||
if (memcmp(test[j], data_save[j], block_size) != 0) {
|
|
||||||
fprintf(stderr, "Failed RAID test\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* restore */
|
|
||||||
for(j=0;j<3;++j) {
|
|
||||||
/* restore the data */
|
|
||||||
data[d[j]] = data_save[j];
|
|
||||||
/* restore the parity */
|
|
||||||
parity[combo[2][i][j]] = waste;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check 2data */
|
|
||||||
for(d[0]=0;d[0]<diskmax;++d[0]) {
|
|
||||||
for(d[1]=d[0]+1;d[1]<diskmax;++d[1]) {
|
|
||||||
for(i=0;combo[1][i][0]>=0;++i) {
|
|
||||||
/* set */
|
|
||||||
for(j=0;j<2;++j) {
|
|
||||||
/* remove the missing data */
|
|
||||||
data_save[j] = data[d[j]];
|
|
||||||
data[d[j]] = test[j];
|
|
||||||
/* set the parity to use */
|
|
||||||
parity[combo[1][i][j]] = parity_save[combo[1][i][j]];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* recover */
|
|
||||||
raid_recov(2, d, combo[1][i], buffer, diskmax, zero, block_size);
|
|
||||||
|
|
||||||
/* check */
|
|
||||||
for(j=0;j<2;++j) {
|
|
||||||
if (memcmp(test[j], data_save[j], block_size) != 0) {
|
|
||||||
fprintf(stderr, "Failed RAID test\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* restore */
|
|
||||||
for(j=0;j<2;++j) {
|
|
||||||
/* restore the data */
|
|
||||||
data[d[j]] = data_save[j];
|
|
||||||
/* restore the parity */
|
|
||||||
parity[combo[1][i][j]] = waste;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check 1data */
|
|
||||||
for(d[0]=0;d[0]<diskmax;++d[0]) {
|
|
||||||
for(i=0;combo[0][i][0]>=0;++i) {
|
|
||||||
/* set */
|
|
||||||
for(j=0;j<1;++j) {
|
|
||||||
/* remove the missing data */
|
|
||||||
data_save[j] = data[d[j]];
|
|
||||||
data[d[j]] = test[j];
|
|
||||||
/* set the parity to use */
|
|
||||||
parity[combo[0][i][j]] = parity_save[combo[0][i][j]];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* recover */
|
|
||||||
raid_recov(1, d, combo[0][i], buffer, diskmax, zero, block_size);
|
|
||||||
|
|
||||||
/* check */
|
|
||||||
for(j=0;j<1;++j) {
|
|
||||||
if (memcmp(test[j], data_save[j], block_size) != 0) {
|
|
||||||
fprintf(stderr, "Failed RAID test\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* restore */
|
|
||||||
for(j=0;j<1;++j) {
|
|
||||||
/* restore the data */
|
|
||||||
data[d[j]] = data_save[j];
|
|
||||||
/* restore the parity */
|
|
||||||
parity[combo[0][i][j]] = waste;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buffer_alloc);
|
free(buffer_alloc);
|
||||||
|
|
@ -396,7 +244,7 @@ static void gentest(unsigned diskmax, unsigned block_size)
|
||||||
/* check it */
|
/* check it */
|
||||||
for(i=0;i<LEV_MAX;++i) {
|
for(i=0;i<LEV_MAX;++i) {
|
||||||
if (memcmp(buffer[diskmax + LEV_MAX + i], buffer[diskmax + i], block_size) != 0) {
|
if (memcmp(buffer[diskmax + LEV_MAX + i], buffer[diskmax + i], block_size) != 0) {
|
||||||
fprintf(stderr, "Failed RAID test\n");
|
fprintf(stderr, "Failed GEN test\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -519,7 +367,7 @@ void selftest()
|
||||||
|
|
||||||
hashtest();
|
hashtest();
|
||||||
crc32ctest();
|
crc32ctest();
|
||||||
gentest(64, 256);
|
combotest();
|
||||||
recovtest(16, 64);
|
gentest(32, 256);
|
||||||
|
recovtest(16, 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue