Fix raid_selftest() parity bounds and dispatch in Vandermonde mode

This commit is contained in:
Andrea Mazzoleni 2026-08-20 20:38:19 +02:00
parent fa9a5ac7fa
commit 52ea1bd035
3 changed files with 42 additions and 7 deletions

View file

@ -1097,7 +1097,6 @@ static void test_stream(void)
} }
} }
void selftest(void) void selftest(void)
{ {
log_tag("selftest:\n"); log_tag("selftest:\n");
@ -1127,9 +1126,24 @@ void selftest(void)
test_wnmatch(); test_wnmatch();
test_parse_smartctl(); test_parse_smartctl();
test_smart_ignore(); test_smart_ignore();
raid_mode(RAID_MODE_CAUCHY_RAID);
if (raid_selftest() != 0) { if (raid_selftest() != 0) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
log_fatal(EINTERNAL, "Failed SELF test\n"); log_fatal(EINTERNAL, "Failed SELF Cauchy RAID test\n");
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
raid_mode(RAID_MODE_CAUCHY_AES);
if (raid_selftest() != 0) {
/* LCOV_EXCL_START */
log_fatal(EINTERNAL, "Failed SELF Cauchy AES test\n");
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
raid_mode(RAID_MODE_VANDERMONDE_RAID);
if (raid_selftest() != 0) {
/* LCOV_EXCL_START */
log_fatal(EINTERNAL, "Failed SELF Vandermonde RAID test\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
@ -1212,7 +1226,7 @@ void selftest(void)
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
/* Verify raid_mode get/set behavior */ /* verify raid_mode get/set behavior */
int cur = raid_mode(RAID_MODE_GET); int cur = raid_mode(RAID_MODE_GET);
int prev = raid_mode(RAID_MODE_CAUCHY_AES); int prev = raid_mode(RAID_MODE_CAUCHY_AES);
if (prev != cur) { if (prev != cur) {
@ -1227,6 +1241,8 @@ void selftest(void)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
raid_mode(prev);
/* restore default mode */
raid_mode(RAID_MODE_CAUCHY_RAID);
} }

View file

@ -564,11 +564,18 @@ int raid_selftest(void)
int ir[RAID_PARITY_MAX]; int ir[RAID_PARITY_MAX];
int ip[RAID_PARITY_MAX]; int ip[RAID_PARITY_MAX];
int i, np; int i, np;
int np_max;
int ret = 0; int ret = 0;
/* ensure to have enough space for data */ /* ensure to have enough space for data */
BUG_ON(nd * size > 65536); BUG_ON(nd * size > 65536);
/* vandermonde mode only supports up to 3 parity rows */
if (raid_mode_active == RAID_MODE_VANDERMONDE_RAID)
np_max = 3;
else
np_max = RAID_PARITY_MAX;
v = raid_malloc_vector(nv, size, &v_alloc); v = raid_malloc_vector(nv, size, &v_alloc);
if (!v) { if (!v) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
@ -584,14 +591,14 @@ int raid_selftest(void)
ref[i] = ((uint8_t *)raid_gfmul) + size * i; ref[i] = ((uint8_t *)raid_gfmul) + size * i;
/* setup reference parity */ /* setup reference parity */
for (i = 0; i < RAID_PARITY_MAX; ++i) for (i = 0; i < np_max; ++i)
ref[nd + i] = v[nd + RAID_PARITY_MAX + i]; ref[nd + i] = v[nd + RAID_PARITY_MAX + i];
/* compute reference parity */ /* compute reference parity */
raid_gen_ref(nd, RAID_PARITY_MAX, size, ref); raid_gen_ref(nd, np_max, size, ref);
/* test for each parity level */ /* test for each parity level */
for (np = 1; np <= RAID_PARITY_MAX; ++np) { for (np = 1; np <= np_max; ++np) {
/* test parity generation */ /* test parity generation */
ret = raid_test_par(nd, np, size, v, ref); ret = raid_test_par(nd, np, size, v, ref);
if (ret != 0) { if (ret != 0) {

View file

@ -29,6 +29,7 @@ int main(void)
goto bail; goto bail;
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
raid_mode(RAID_MODE_CAUCHY_RAID);
if (raid_selftest() != 0) { if (raid_selftest() != 0) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
goto bail; goto bail;
@ -41,12 +42,23 @@ int main(void)
goto bail; goto bail;
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
raid_mode(RAID_MODE_CAUCHY_AES);
if (raid_selftest() != 0) { if (raid_selftest() != 0) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
goto bail; goto bail;
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
printf("Test Vandermonde RAID\n");
raid_mode(RAID_MODE_VANDERMONDE_RAID);
if (raid_selftest() != 0) {
/* LCOV_EXCL_START */
goto bail;
/* LCOV_EXCL_STOP */
}
raid_mode(RAID_MODE_CAUCHY_RAID);
printf("OK\n"); printf("OK\n");
return 0; return 0;