mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-20 06:56:28 -05:00
Adds preliminary support for QuadParity.
This commit is contained in:
parent
a3d939d024
commit
f8303d2963
8 changed files with 1363 additions and 19 deletions
16
mktables.c
16
mktables.c
|
|
@ -98,6 +98,22 @@ int main(void)
|
|||
}
|
||||
printf("};\n\n");
|
||||
|
||||
/* 8^a */
|
||||
printf("const unsigned char __attribute__((aligned(256))) gfexp8[256] =\n");
|
||||
printf("{\n");
|
||||
v = 1;
|
||||
for(i=0;i<256;++i) {
|
||||
if (i % 8 == 0)
|
||||
printf("\t");
|
||||
printf("0x%02x,", v);
|
||||
v = gfmul(v, 8);
|
||||
if (i % 8 == 7)
|
||||
printf("\n");
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
/* 1/a */
|
||||
printf("const unsigned char __attribute__((aligned(256))) gfinv[256] =\n");
|
||||
printf("{\n");
|
||||
|
|
|
|||
24
raid.h
24
raid.h
|
|
@ -65,6 +65,26 @@ void raidTP_recov_2dataq(unsigned char** dptrs, unsigned diskmax, unsigned size,
|
|||
*/
|
||||
void raidTP_recov_3data(unsigned char** dptrs, unsigned diskmax, unsigned size, int faila, int failb, int failc, unsigned char* zero);
|
||||
|
||||
/*
|
||||
* Recover failure of one data block x using parity i.
|
||||
*/
|
||||
void raid_recov_1data(unsigned char** dptrs, unsigned diskmax, unsigned size, int x, int i, unsigned char* zero);
|
||||
|
||||
/*
|
||||
* Recover failure of two data blocks x,y using parity i,j.
|
||||
*/
|
||||
void raid_recov_2data(unsigned char** dptrs, unsigned diskmax, unsigned size, int x, int y, int i, int j, unsigned char* zero);
|
||||
|
||||
/*
|
||||
* Recover failure of three data blocks x,y,z using parity i,j,k.
|
||||
*/
|
||||
void raid_recov_3data(unsigned char** dptrs, unsigned diskmax, unsigned size, int x, int y, int z, int i, int j, int k, unsigned char* zero);
|
||||
|
||||
/*
|
||||
* Recover failure of four data blocks x,y,z,v using parity i,j,k,l.
|
||||
*/
|
||||
void raid_recov_4data(unsigned char** dptrs, unsigned diskmax, unsigned size, int x, int y, int z, int v, int i, int j, int k, int l, unsigned char* zero);
|
||||
|
||||
/**
|
||||
* Initializes the RAID system.
|
||||
*/
|
||||
|
|
@ -87,6 +107,10 @@ void raidTP_int32r2(unsigned char** dptr, unsigned diskmax, unsigned size);
|
|||
void raidTP_mmxr1(unsigned char** buffer, unsigned diskmax, unsigned size);
|
||||
void raidTP_sse2r1(unsigned char** dptr, unsigned diskmax, unsigned size);
|
||||
void raidTP_sse2r2(unsigned char** dptr, unsigned diskmax, unsigned size);
|
||||
void raidQP_int32r2(unsigned char** dptr, unsigned diskmax, unsigned size);
|
||||
void raidQP_mmxr1(unsigned char** buffer, unsigned diskmax, unsigned size);
|
||||
void raidQP_sse2r1(unsigned char** dptr, unsigned diskmax, unsigned size);
|
||||
void raidQP_sse2r2(unsigned char** buffer, unsigned diskmax, unsigned size);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
264
selftest.c
264
selftest.c
|
|
@ -374,6 +374,263 @@ static void raidTPtest(unsigned diskmax, unsigned block_size)
|
|||
free(buffer);
|
||||
}
|
||||
|
||||
static void raidQPtest(unsigned diskmax, unsigned block_size)
|
||||
{
|
||||
void* buffer_alloc;
|
||||
unsigned char** buffer;
|
||||
unsigned char* buffer_test0;
|
||||
unsigned char* buffer_test1;
|
||||
unsigned char* buffer_test2;
|
||||
unsigned char* buffer_test3;
|
||||
unsigned char* buffer_zero;
|
||||
unsigned char* buffer_bad;
|
||||
unsigned buffermax;
|
||||
unsigned i, j, k, l;
|
||||
unsigned n;
|
||||
|
||||
struct combo1 {
|
||||
int ignore[3];
|
||||
int use;
|
||||
} COMBO1[4] = {
|
||||
{ { 1, 2, 3 }, 0 },
|
||||
{ { 0, 2, 3 }, 1 },
|
||||
{ { 0, 1, 3 }, 2 },
|
||||
{ { 0, 1, 2 }, 3 }
|
||||
};
|
||||
|
||||
struct combo2 {
|
||||
int ignore[2];
|
||||
int use[2];
|
||||
} COMBO2[6] = {
|
||||
{ { 0, 1 }, { 2, 3 } },
|
||||
{ { 0, 2 }, { 1, 3 } },
|
||||
{ { 0, 3 }, { 1, 2 } },
|
||||
{ { 1, 2 }, { 0, 3 } },
|
||||
{ { 1, 3 }, { 0, 2 } },
|
||||
{ { 2, 3 }, { 0, 1 } }
|
||||
};
|
||||
|
||||
struct combo3 {
|
||||
int ignore;
|
||||
int use[3];
|
||||
} COMBO3[4] = {
|
||||
{ 0, { 1, 2, 3 } },
|
||||
{ 1, { 0, 2, 3 } },
|
||||
{ 2, { 0, 1, 3 } },
|
||||
{ 3, { 0, 1, 2 } }
|
||||
};
|
||||
|
||||
buffermax = diskmax + 4 + 4 + 1 + 1;
|
||||
|
||||
buffer = malloc_nofail_vector_align(buffermax, block_size, &buffer_alloc);
|
||||
|
||||
buffer_test0 = buffer[buffermax-6];
|
||||
buffer_test1 = buffer[buffermax-5];
|
||||
buffer_test2 = buffer[buffermax-4];
|
||||
buffer_test3 = buffer[buffermax-3];
|
||||
buffer_zero = buffer[buffermax-2];
|
||||
buffer_bad = buffer[buffermax-1];
|
||||
memset(buffer_zero, 0, block_size);
|
||||
memset(buffer_bad, 0xA5, block_size);
|
||||
|
||||
/* fill with random */
|
||||
for(i=0;i<diskmax;++i) {
|
||||
for(j=0;j<block_size;++j)
|
||||
buffer[i][j] = rand();
|
||||
}
|
||||
|
||||
/* compute the parity */
|
||||
raid_gen(4, buffer, diskmax, block_size);
|
||||
|
||||
/* check 4data */
|
||||
for(i=0;i<diskmax;++i) {
|
||||
for(j=i+1;j<diskmax;++j) {
|
||||
for(k=j+1;k<diskmax;++k) {
|
||||
for(l=k+1;l<diskmax;++l) {
|
||||
unsigned char* a;
|
||||
unsigned char* b;
|
||||
unsigned char* c;
|
||||
unsigned char* d;
|
||||
|
||||
/* save */
|
||||
a = buffer[i];
|
||||
b = buffer[j];
|
||||
c = buffer[k];
|
||||
d = buffer[l];
|
||||
|
||||
/* damage */
|
||||
buffer[i] = buffer_test0;
|
||||
buffer[j] = buffer_test1;
|
||||
buffer[k] = buffer_test2;
|
||||
buffer[l] = buffer_test3;
|
||||
|
||||
/* recover */
|
||||
raid_recov_4data(buffer, diskmax, block_size, i, j, k, l, 0, 1, 2, 3, buffer_zero);
|
||||
|
||||
/* check */
|
||||
if (memcmp(buffer_test0, a, block_size) != 0
|
||||
|| memcmp(buffer_test1, b, block_size) != 0
|
||||
|| memcmp(buffer_test2, c, block_size) != 0
|
||||
|| memcmp(buffer_test3, d, block_size) != 0
|
||||
) {
|
||||
fprintf(stderr, "Failed RAIDQP test\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* restore */
|
||||
buffer[i] = a;
|
||||
buffer[j] = b;
|
||||
buffer[k] = c;
|
||||
buffer[l] = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* check 3data */
|
||||
for(i=0;i<diskmax;++i) {
|
||||
for(j=i+1;j<diskmax;++j) {
|
||||
for(k=j+1;k<diskmax;++k) {
|
||||
for(n=0;n<4;++n) {
|
||||
unsigned char* a;
|
||||
unsigned char* b;
|
||||
unsigned char* c;
|
||||
unsigned char* p;
|
||||
|
||||
/* save */
|
||||
a = buffer[i];
|
||||
b = buffer[j];
|
||||
c = buffer[k];
|
||||
|
||||
/* damage */
|
||||
buffer[i] = buffer_test0;
|
||||
buffer[j] = buffer_test1;
|
||||
buffer[k] = buffer_test2;
|
||||
|
||||
/* ignore parity */
|
||||
l = diskmax + COMBO3[n].ignore;
|
||||
p = buffer[l];
|
||||
buffer[l] = buffer_bad;
|
||||
|
||||
/* recover ignoring p */
|
||||
raid_recov_3data(buffer, diskmax, block_size, i, j, k, COMBO3[n].use[0], COMBO3[n].use[1], COMBO3[n].use[2], buffer_zero);
|
||||
|
||||
/* check */
|
||||
if (memcmp(buffer_test0, a, block_size) != 0
|
||||
|| memcmp(buffer_test1, b, block_size) != 0
|
||||
|| memcmp(buffer_test2, c, block_size) != 0
|
||||
) {
|
||||
fprintf(stderr, "Failed RAIDQP test 1\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* restore parity */
|
||||
buffer[l] = p;
|
||||
|
||||
/* restore */
|
||||
buffer[i] = a;
|
||||
buffer[j] = b;
|
||||
buffer[k] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* check 2data */
|
||||
for(i=0;i<diskmax;++i) {
|
||||
for(j=i+1;j<diskmax;++j) {
|
||||
for(n=0;n<6;++n) {
|
||||
unsigned char* a;
|
||||
unsigned char* b;
|
||||
unsigned char* p;
|
||||
unsigned char* q;
|
||||
|
||||
/* save */
|
||||
a = buffer[i];
|
||||
b = buffer[j];
|
||||
|
||||
/* damage */
|
||||
buffer[i] = buffer_test0;
|
||||
buffer[j] = buffer_test1;
|
||||
|
||||
/* ignore parity */
|
||||
k = diskmax + COMBO2[n].ignore[0];
|
||||
l = diskmax + COMBO2[n].ignore[1];
|
||||
p = buffer[k];
|
||||
q = buffer[l];
|
||||
buffer[k] = buffer_bad;
|
||||
buffer[l] = buffer_bad;
|
||||
|
||||
/* recover */
|
||||
raid_recov_2data(buffer, diskmax, block_size, i, j, COMBO2[n].use[0], COMBO2[n].use[1], buffer_zero);
|
||||
|
||||
/* check */
|
||||
if (memcmp(buffer_test0, a, block_size) != 0
|
||||
|| memcmp(buffer_test1, b, block_size) != 0
|
||||
) {
|
||||
fprintf(stderr, "Failed RAIDQP test 1\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* restore parity */
|
||||
buffer[k] = p;
|
||||
buffer[l] = q;
|
||||
|
||||
/* restore */
|
||||
buffer[i] = a;
|
||||
buffer[j] = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* check 1data */
|
||||
for(n=0;n<4;++n) {
|
||||
for(i=0;i<diskmax;++i) {
|
||||
unsigned char* a;
|
||||
unsigned char* p;
|
||||
unsigned char* q;
|
||||
unsigned char* r;
|
||||
|
||||
/* save */
|
||||
a = buffer[i];
|
||||
|
||||
/* damage */
|
||||
buffer[i] = buffer_test0;
|
||||
|
||||
/* ignore parity */
|
||||
j = diskmax + COMBO1[n].ignore[0];
|
||||
k = diskmax + COMBO1[n].ignore[1];
|
||||
l = diskmax + COMBO1[n].ignore[2];
|
||||
p = buffer[j];
|
||||
q = buffer[k];
|
||||
r = buffer[l];
|
||||
buffer[j] = buffer_bad;
|
||||
buffer[k] = buffer_bad;
|
||||
buffer[l] = buffer_bad;
|
||||
|
||||
/* recover */
|
||||
raid_recov_1data(buffer, diskmax, block_size, i, COMBO1[n].use, buffer_zero);
|
||||
|
||||
/* check */
|
||||
if (memcmp(buffer_test0, a, block_size) != 0) {
|
||||
fprintf(stderr, "Failed RAIDQP test\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* restore parity */
|
||||
buffer[j] = p;
|
||||
buffer[k] = q;
|
||||
buffer[l] = r;
|
||||
|
||||
/* restore */
|
||||
buffer[i] = a;
|
||||
}
|
||||
}
|
||||
|
||||
free(buffer_alloc);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
#define HASH_TEST_MAX 512 /* tests are never longer than 512 bytes */
|
||||
|
||||
static void hashtest(void)
|
||||
|
|
@ -489,8 +746,9 @@ void selftest(int gui)
|
|||
|
||||
hashtest();
|
||||
crc32ctest();
|
||||
raid5test(33, 2048);
|
||||
raid6test(33, 2048);
|
||||
raidTPtest(33, 2048);
|
||||
raid5test(33, 1024);
|
||||
raid6test(33, 1024);
|
||||
raidTPtest(33, 1024);
|
||||
raidQPtest(21, 1024);
|
||||
}
|
||||
|
||||
|
|
|
|||
48
speed.c
48
speed.c
|
|
@ -66,10 +66,10 @@ void speed(void)
|
|||
void* buffer_alloc;
|
||||
unsigned char** buffer;
|
||||
|
||||
buffer = malloc_nofail_vector_align(diskmax + 3, block_size, &buffer_alloc);
|
||||
buffer = malloc_nofail_vector_align(diskmax + 4, block_size, &buffer_alloc);
|
||||
|
||||
/* initialize with fixed data */
|
||||
for(i=0;i<diskmax+3;++i) {
|
||||
for(i=0;i<diskmax+4;++i) {
|
||||
memset(buffer[i], i, block_size);
|
||||
}
|
||||
for(i=0;i<HASH_SIZE;++i)
|
||||
|
|
@ -161,6 +161,18 @@ void speed(void)
|
|||
printf("sse2x2");
|
||||
#else
|
||||
printf("sse2x1");
|
||||
#endif
|
||||
else if (cpu_has_mmx())
|
||||
printf("mmxx1");
|
||||
else
|
||||
printf("int32x2");
|
||||
printf("\n");
|
||||
printf("Expected fastest RAIDQP is ");
|
||||
if (cpu_has_sse2())
|
||||
#if defined(__x86_64__)
|
||||
printf("sse2x2");
|
||||
#else
|
||||
printf("sse2x1");
|
||||
#endif
|
||||
else if (cpu_has_mmx())
|
||||
printf("mmxx1");
|
||||
|
|
@ -325,6 +337,38 @@ void speed(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
SPEED_START {
|
||||
raidQP_int32r2(buffer, diskmax, block_size);
|
||||
} SPEED_STOP
|
||||
|
||||
printf("RAIDQP int32x2 %"PRIu64" [MB/s]\n", ds / dt);
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
if (cpu_has_mmx()) {
|
||||
SPEED_START {
|
||||
raidQP_mmxr1(buffer, diskmax, block_size);
|
||||
} SPEED_STOP
|
||||
|
||||
printf("RAIDQP mmxr1 %"PRIu64" [MB/s]\n", ds / dt);
|
||||
}
|
||||
|
||||
if (cpu_has_sse2()) {
|
||||
SPEED_START {
|
||||
raidQP_sse2r1(buffer, diskmax, block_size);
|
||||
} SPEED_STOP
|
||||
|
||||
printf("RAIDQP sse2x1 %"PRIu64" [MB/s]\n", ds / dt);
|
||||
|
||||
#if defined(__x86_64__)
|
||||
SPEED_START {
|
||||
raidQP_sse2r2(buffer, diskmax, block_size);
|
||||
} SPEED_STOP
|
||||
|
||||
printf("RAIDQP sse2x2 %"PRIu64" [MB/s]\n", ds / dt);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
free(buffer_alloc);
|
||||
free(buffer);
|
||||
}
|
||||
|
|
|
|||
5
state.c
5
state.c
|
|
@ -30,6 +30,7 @@ const char* lev_name(unsigned l)
|
|||
case 0 : return "Parity";
|
||||
case 1 : return "Q-Parity";
|
||||
case 2 : return "R-Parity";
|
||||
case 3 : return "S-Parity";
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -41,6 +42,7 @@ const char* lev_config_name(unsigned l)
|
|||
case 0 : return "parity";
|
||||
case 1 : return "q-parity";
|
||||
case 2 : return "r-parity";
|
||||
case 3 : return "s-parity";
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -328,7 +330,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
state->block_size *= 1024;
|
||||
} else if (strcmp(tag, "parity") == 0 || strcmp(tag, "q-parity") == 0 || strcmp(tag, "r-parity") == 0) {
|
||||
} else if (strcmp(tag, "parity") == 0 || strcmp(tag, "q-parity") == 0 || strcmp(tag, "r-parity") == 0 || strcmp(tag, "s-parity") == 0) {
|
||||
char device[PATH_MAX];
|
||||
char* slash;
|
||||
struct stat st;
|
||||
|
|
@ -338,6 +340,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co
|
|||
case 'p' : l = 0; break;
|
||||
case 'q' : l = 1; break;
|
||||
case 'r' : l = 2; break;
|
||||
case 's' : l = 3; break;
|
||||
default:
|
||||
fprintf(stderr, "Invalid '%s' specification in '%s' at line %u\n", tag, path, line);
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
|
|||
6
state.h
6
state.h
|
|
@ -24,15 +24,15 @@
|
|||
/**
|
||||
* Max level of parity supported.
|
||||
*/
|
||||
#define LEV_MAX 3
|
||||
#define LEV_MAX 4
|
||||
|
||||
/**
|
||||
* Returns the parity name: Parity, Q-Parity, R-Parity.
|
||||
* Returns the parity name: Parity, Q-Parity, R-Parity, S-Parity.
|
||||
*/
|
||||
const char* lev_name(unsigned level);
|
||||
|
||||
/**
|
||||
* Returns the parity name used in the config file: parity, q-parity, r-parity.
|
||||
* Returns the parity name used in the config file: parity, q-parity, r-parity, s-parity.
|
||||
*/
|
||||
const char* lev_config_name(unsigned level);
|
||||
|
||||
|
|
|
|||
36
tables.h
36
tables.h
|
|
@ -8795,6 +8795,42 @@ const unsigned char __attribute__((aligned(256))) gfexp4[256] =
|
|||
0x58, 0x7d, 0xe9, 0x83, 0x36, 0xd8, 0x47, 0x01,
|
||||
};
|
||||
|
||||
const unsigned char __attribute__((aligned(256))) gfexp8[256] =
|
||||
{
|
||||
0x01, 0x08, 0x40, 0x3a, 0xcd, 0x26, 0x2d, 0x75,
|
||||
0x8f, 0x0c, 0x60, 0x27, 0x25, 0x35, 0xb5, 0xc1,
|
||||
0x46, 0x0a, 0x50, 0xba, 0xb9, 0xa1, 0x61, 0x2f,
|
||||
0x65, 0x0f, 0x78, 0xe7, 0x6b, 0x7f, 0xdf, 0xb6,
|
||||
0xd9, 0x86, 0x44, 0x1a, 0xd0, 0xce, 0x3e, 0xed,
|
||||
0x3b, 0xc5, 0x66, 0x17, 0xb8, 0xa9, 0x21, 0x15,
|
||||
0xa8, 0x29, 0x55, 0x92, 0xe4, 0x73, 0xbf, 0x91,
|
||||
0xfc, 0xb3, 0xf1, 0xdb, 0x96, 0xc4, 0x6e, 0x57,
|
||||
0x82, 0x64, 0x07, 0x38, 0xdd, 0xa6, 0x59, 0xf2,
|
||||
0xc3, 0x56, 0x8a, 0x24, 0x3d, 0xf5, 0xfb, 0x8b,
|
||||
0x2c, 0x7d, 0xcf, 0x36, 0xad, 0x01, 0x08, 0x40,
|
||||
0x3a, 0xcd, 0x26, 0x2d, 0x75, 0x8f, 0x0c, 0x60,
|
||||
0x27, 0x25, 0x35, 0xb5, 0xc1, 0x46, 0x0a, 0x50,
|
||||
0xba, 0xb9, 0xa1, 0x61, 0x2f, 0x65, 0x0f, 0x78,
|
||||
0xe7, 0x6b, 0x7f, 0xdf, 0xb6, 0xd9, 0x86, 0x44,
|
||||
0x1a, 0xd0, 0xce, 0x3e, 0xed, 0x3b, 0xc5, 0x66,
|
||||
0x17, 0xb8, 0xa9, 0x21, 0x15, 0xa8, 0x29, 0x55,
|
||||
0x92, 0xe4, 0x73, 0xbf, 0x91, 0xfc, 0xb3, 0xf1,
|
||||
0xdb, 0x96, 0xc4, 0x6e, 0x57, 0x82, 0x64, 0x07,
|
||||
0x38, 0xdd, 0xa6, 0x59, 0xf2, 0xc3, 0x56, 0x8a,
|
||||
0x24, 0x3d, 0xf5, 0xfb, 0x8b, 0x2c, 0x7d, 0xcf,
|
||||
0x36, 0xad, 0x01, 0x08, 0x40, 0x3a, 0xcd, 0x26,
|
||||
0x2d, 0x75, 0x8f, 0x0c, 0x60, 0x27, 0x25, 0x35,
|
||||
0xb5, 0xc1, 0x46, 0x0a, 0x50, 0xba, 0xb9, 0xa1,
|
||||
0x61, 0x2f, 0x65, 0x0f, 0x78, 0xe7, 0x6b, 0x7f,
|
||||
0xdf, 0xb6, 0xd9, 0x86, 0x44, 0x1a, 0xd0, 0xce,
|
||||
0x3e, 0xed, 0x3b, 0xc5, 0x66, 0x17, 0xb8, 0xa9,
|
||||
0x21, 0x15, 0xa8, 0x29, 0x55, 0x92, 0xe4, 0x73,
|
||||
0xbf, 0x91, 0xfc, 0xb3, 0xf1, 0xdb, 0x96, 0xc4,
|
||||
0x6e, 0x57, 0x82, 0x64, 0x07, 0x38, 0xdd, 0xa6,
|
||||
0x59, 0xf2, 0xc3, 0x56, 0x8a, 0x24, 0x3d, 0xf5,
|
||||
0xfb, 0x8b, 0x2c, 0x7d, 0xcf, 0x36, 0xad, 0x01,
|
||||
};
|
||||
|
||||
const unsigned char __attribute__((aligned(256))) gfinv[256] =
|
||||
{
|
||||
/* note that the first element is not significative */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue