mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Add new raid_check() and raid_scan() functions
They are aimed to find the broken blocks using the extra redundancy information.
This commit is contained in:
parent
b0891290eb
commit
7bdee2c1d9
4 changed files with 130 additions and 2 deletions
|
|
@ -259,6 +259,49 @@ static int raid_test_rec_dataonly(int nr, int *id, int *ip, int nd, int np, size
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan test.
|
||||
*/
|
||||
static int raid_test_scan(int nr, int *ir, int nd, int np, size_t size, void **v, void **ref)
|
||||
{
|
||||
int i, j, ret;
|
||||
void *t[TEST_COUNT + RAID_PARITY_MAX];
|
||||
int is[RAID_PARITY_MAX];
|
||||
|
||||
/* setup data and parity vector */
|
||||
for (i = 0, j = 0; i < nd + np; ++i) {
|
||||
if (j < nr && ir[j] == i) {
|
||||
/* this block is bad */
|
||||
t[i] = v[i];
|
||||
++j;
|
||||
|
||||
/* make it really bad */
|
||||
memset(t[i], i, size);
|
||||
} else {
|
||||
/* this block is used for recovering */
|
||||
t[i] = ref[i];
|
||||
}
|
||||
}
|
||||
|
||||
ret = raid_scan(is, nd, np, size, t);
|
||||
|
||||
/* compare identified bad blocks */
|
||||
if (ret != nr) {
|
||||
/* LCOV_EXCL_START */
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
for (i = 0; i < nr; ++i) {
|
||||
if (ir[i] != is[i]) {
|
||||
/* LCOV_EXCL_START */
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Basic functionality self test.
|
||||
*/
|
||||
|
|
@ -385,6 +428,23 @@ int raid_selftest(void)
|
|||
goto bail;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
/* scan test with broken data and parity */
|
||||
for (i = 0; i < np / 2; ++i) {
|
||||
/* bad data */
|
||||
ir[i] = i;
|
||||
}
|
||||
for (i = 0; i < (np - 1) / 2; ++i) {
|
||||
/* bad parity */
|
||||
ir[np / 2 + i] = nd + i;
|
||||
}
|
||||
|
||||
ret = raid_test_scan(np - 1, ir, nd, np, size, v, ref);
|
||||
if (ret != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
goto bail;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
bail:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue