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
)));
22 struct raid6_calls raid6_call
;
24 char *dataptrs
[NDISKS
];
25 char data
[NDISKS
][PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
26 char recovi
[PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
27 char recovj
[PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
29 static void makedata(int start
, int stop
)
33 for (i
= start
; i
<= stop
; i
++) {
34 for (j
= 0; j
< PAGE_SIZE
; j
++)
37 dataptrs
[i
] = data
[i
];
41 static char disk_type(int d
)
53 static int test_disks(int i
, int j
)
57 memset(recovi
, 0xf0, PAGE_SIZE
);
58 memset(recovj
, 0xba, PAGE_SIZE
);
63 raid6_dual_recov(NDISKS
, PAGE_SIZE
, i
, j
, (void **)&dataptrs
);
65 erra
= memcmp(data
[i
], recovi
, PAGE_SIZE
);
66 errb
= memcmp(data
[j
], recovj
, PAGE_SIZE
);
68 if (i
< NDISKS
-2 && j
== NDISKS
-1) {
69 /* We don't implement the DQ failure scenario, since it's
70 equivalent to a RAID-5 failure (XOR, then recompute Q) */
73 printf("algo=%-8s faila=%3d(%c) failb=%3d(%c) %s\n",
77 (!erra
&& !errb
) ? "OK" :
79 !errb
? "ERRA" : "ERRAB");
82 dataptrs
[i
] = data
[i
];
83 dataptrs
[j
] = data
[j
];
88 int main(int argc
, char *argv
[])
90 const struct raid6_calls
*const *algo
;
91 const struct raid6_recov_calls
*const *ra
;
95 makedata(0, NDISKS
-1);
97 for (ra
= raid6_recov_algos
; *ra
; ra
++) {
98 if ((*ra
)->valid
&& !(*ra
)->valid())
101 raid6_2data_recov
= (*ra
)->data2
;
102 raid6_datap_recov
= (*ra
)->datap
;
104 printf("using recovery %s\n", (*ra
)->name
);
106 for (algo
= raid6_algos
; *algo
; algo
++) {
107 if ((*algo
)->valid
&& !(*algo
)->valid())
113 memset(data
[NDISKS
-2], 0xee, 2*PAGE_SIZE
);
115 /* Generate assumed good syndrome */
116 raid6_call
.gen_syndrome(NDISKS
, PAGE_SIZE
,
119 for (i
= 0; i
< NDISKS
-1; i
++)
120 for (j
= i
+1; j
< NDISKS
; j
++)
121 err
+= test_disks(i
, j
);
123 if (!raid6_call
.xor_syndrome
)
126 for (p1
= 0; p1
< NDISKS
-2; p1
++)
127 for (p2
= p1
; p2
< NDISKS
-2; p2
++) {
129 /* Simulate rmw run */
130 raid6_call
.xor_syndrome(NDISKS
, p1
, p2
, PAGE_SIZE
,
133 raid6_call
.xor_syndrome(NDISKS
, p1
, p2
, PAGE_SIZE
,
136 for (i
= 0; i
< NDISKS
-1; i
++)
137 for (j
= i
+1; j
< NDISKS
; j
++)
138 err
+= test_disks(i
, j
);
146 /* Pick the best algorithm test */
150 printf("\n*** ERRORS FOUND ***\n");