1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
5 * This file is part of the Linux kernel, and is made available under
6 * the terms of the GNU General Public License version 2 or (at your
7 * option) any later version; incorporated herein by reference.
9 * ----------------------------------------------------------------------- */
14 * Test RAID-6 recovery with various algorithms
20 #include <linux/raid/pq.h>
22 #define NDISKS 16 /* Including P and Q */
24 const char raid6_empty_zero_page
[PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
25 struct raid6_calls raid6_call
;
27 char *dataptrs
[NDISKS
];
28 char data
[NDISKS
][PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
29 char recovi
[PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
30 char recovj
[PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
32 static void makedata(int start
, int stop
)
36 for (i
= start
; i
<= stop
; i
++) {
37 for (j
= 0; j
< PAGE_SIZE
; j
++)
40 dataptrs
[i
] = data
[i
];
44 static char disk_type(int d
)
56 static int test_disks(int i
, int j
)
60 memset(recovi
, 0xf0, PAGE_SIZE
);
61 memset(recovj
, 0xba, PAGE_SIZE
);
66 raid6_dual_recov(NDISKS
, PAGE_SIZE
, i
, j
, (void **)&dataptrs
);
68 erra
= memcmp(data
[i
], recovi
, PAGE_SIZE
);
69 errb
= memcmp(data
[j
], recovj
, PAGE_SIZE
);
71 if (i
< NDISKS
-2 && j
== NDISKS
-1) {
72 /* We don't implement the DQ failure scenario, since it's
73 equivalent to a RAID-5 failure (XOR, then recompute Q) */
76 printf("algo=%-8s faila=%3d(%c) failb=%3d(%c) %s\n",
80 (!erra
&& !errb
) ? "OK" :
82 !errb
? "ERRA" : "ERRAB");
85 dataptrs
[i
] = data
[i
];
86 dataptrs
[j
] = data
[j
];
91 int main(int argc
, char *argv
[])
93 const struct raid6_calls
*const *algo
;
94 const struct raid6_recov_calls
*const *ra
;
98 makedata(0, NDISKS
-1);
100 for (ra
= raid6_recov_algos
; *ra
; ra
++) {
101 if ((*ra
)->valid
&& !(*ra
)->valid())
104 raid6_2data_recov
= (*ra
)->data2
;
105 raid6_datap_recov
= (*ra
)->datap
;
107 printf("using recovery %s\n", (*ra
)->name
);
109 for (algo
= raid6_algos
; *algo
; algo
++) {
110 if ((*algo
)->valid
&& !(*algo
)->valid())
116 memset(data
[NDISKS
-2], 0xee, 2*PAGE_SIZE
);
118 /* Generate assumed good syndrome */
119 raid6_call
.gen_syndrome(NDISKS
, PAGE_SIZE
,
122 for (i
= 0; i
< NDISKS
-1; i
++)
123 for (j
= i
+1; j
< NDISKS
; j
++)
124 err
+= test_disks(i
, j
);
126 if (!raid6_call
.xor_syndrome
)
129 for (p1
= 0; p1
< NDISKS
-2; p1
++)
130 for (p2
= p1
; p2
< NDISKS
-2; p2
++) {
132 /* Simulate rmw run */
133 raid6_call
.xor_syndrome(NDISKS
, p1
, p2
, PAGE_SIZE
,
136 raid6_call
.xor_syndrome(NDISKS
, p1
, p2
, PAGE_SIZE
,
139 for (i
= 0; i
< NDISKS
-1; i
++)
140 for (j
= i
+1; j
< NDISKS
; j
++)
141 err
+= test_disks(i
, j
);
149 /* Pick the best algorithm test */
153 printf("\n*** ERRORS FOUND ***\n");