1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* -*- linux-c -*- ------------------------------------------------------- *
4 * Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
6 * ----------------------------------------------------------------------- */
11 * Test RAID-6 recovery with various algorithms
17 #include <linux/raid/pq.h>
19 #define NDISKS 16 /* Including P and Q */
21 const char raid6_empty_zero_page
[PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
23 char *dataptrs
[NDISKS
];
24 char data
[NDISKS
][PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
25 char recovi
[PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
26 char recovj
[PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
28 static void makedata(int start
, int stop
)
32 for (i
= start
; i
<= stop
; i
++) {
33 for (j
= 0; j
< PAGE_SIZE
; j
++)
36 dataptrs
[i
] = data
[i
];
40 static char disk_type(int d
)
52 static int test_disks(int i
, int j
)
56 memset(recovi
, 0xf0, PAGE_SIZE
);
57 memset(recovj
, 0xba, PAGE_SIZE
);
62 raid6_dual_recov(NDISKS
, PAGE_SIZE
, i
, j
, (void **)&dataptrs
);
64 erra
= memcmp(data
[i
], recovi
, PAGE_SIZE
);
65 errb
= memcmp(data
[j
], recovj
, PAGE_SIZE
);
67 if (i
< NDISKS
-2 && j
== NDISKS
-1) {
68 /* We don't implement the DQ failure scenario, since it's
69 equivalent to a RAID-5 failure (XOR, then recompute Q) */
72 printf("algo=%-8s faila=%3d(%c) failb=%3d(%c) %s\n",
76 (!erra
&& !errb
) ? "OK" :
78 !errb
? "ERRA" : "ERRAB");
81 dataptrs
[i
] = data
[i
];
82 dataptrs
[j
] = data
[j
];
87 int main(int argc
, char *argv
[])
89 const struct raid6_calls
*const *algo
;
90 const struct raid6_recov_calls
*const *ra
;
94 makedata(0, NDISKS
-1);
96 for (ra
= raid6_recov_algos
; *ra
; ra
++) {
97 if ((*ra
)->valid
&& !(*ra
)->valid())
100 raid6_2data_recov
= (*ra
)->data2
;
101 raid6_datap_recov
= (*ra
)->datap
;
103 printf("using recovery %s\n", (*ra
)->name
);
105 for (algo
= raid6_algos
; *algo
; algo
++) {
106 if ((*algo
)->valid
&& !(*algo
)->valid())
112 memset(data
[NDISKS
-2], 0xee, 2*PAGE_SIZE
);
114 /* Generate assumed good syndrome */
115 raid6_call
.gen_syndrome(NDISKS
, PAGE_SIZE
,
118 for (i
= 0; i
< NDISKS
-1; i
++)
119 for (j
= i
+1; j
< NDISKS
; j
++)
120 err
+= test_disks(i
, j
);
122 if (!raid6_call
.xor_syndrome
)
125 for (p1
= 0; p1
< NDISKS
-2; p1
++)
126 for (p2
= p1
; p2
< NDISKS
-2; p2
++) {
128 /* Simulate rmw run */
129 raid6_call
.xor_syndrome(NDISKS
, p1
, p2
, PAGE_SIZE
,
132 raid6_call
.xor_syndrome(NDISKS
, p1
, p2
, PAGE_SIZE
,
135 for (i
= 0; i
< NDISKS
-1; i
++)
136 for (j
= i
+1; j
< NDISKS
; j
++)
137 err
+= test_disks(i
, j
);
145 /* Pick the best algorithm test */
149 printf("\n*** ERRORS FOUND ***\n");