blob: 3bebbabdb51004bb7d66d8eed659f50afca29f5c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* -*- linux-c -*- ------------------------------------------------------- *
2 *
H. Peter Anvin66c811e2008-02-06 01:39:48 -08003 * Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
H. Peter Anvin66c811e2008-02-06 01:39:48 -08005 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * ----------------------------------------------------------------------- */
10
11/*
12 * raid6test.c
13 *
14 * Test RAID-6 recovery with various algorithms
15 */
16
17#include <stdlib.h>
18#include <stdio.h>
19#include <string.h>
Dan Williamsf701d582009-03-31 15:09:39 +110020#include <linux/raid/pq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#define NDISKS 16 /* Including P and Q */
23
24const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256)));
25struct raid6_calls raid6_call;
26
27char *dataptrs[NDISKS];
28char data[NDISKS][PAGE_SIZE];
29char recovi[PAGE_SIZE], recovj[PAGE_SIZE];
30
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +110031static void makedata(int start, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
33 int i, j;
34
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +110035 for (i = start; i <= stop; i++) {
H. Peter Anvin66c811e2008-02-06 01:39:48 -080036 for (j = 0; j < PAGE_SIZE; j++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 data[i][j] = rand();
H. Peter Anvin66c811e2008-02-06 01:39:48 -080038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 dataptrs[i] = data[i];
40 }
41}
42
H. Peter Anvin66c811e2008-02-06 01:39:48 -080043static char disk_type(int d)
44{
45 switch (d) {
46 case NDISKS-2:
47 return 'P';
48 case NDISKS-1:
49 return 'Q';
50 default:
51 return 'D';
52 }
53}
54
55static int test_disks(int i, int j)
56{
57 int erra, errb;
58
59 memset(recovi, 0xf0, PAGE_SIZE);
60 memset(recovj, 0xba, PAGE_SIZE);
61
62 dataptrs[i] = recovi;
63 dataptrs[j] = recovj;
64
65 raid6_dual_recov(NDISKS, PAGE_SIZE, i, j, (void **)&dataptrs);
66
67 erra = memcmp(data[i], recovi, PAGE_SIZE);
68 errb = memcmp(data[j], recovj, PAGE_SIZE);
69
70 if (i < NDISKS-2 && j == NDISKS-1) {
71 /* We don't implement the DQ failure scenario, since it's
72 equivalent to a RAID-5 failure (XOR, then recompute Q) */
73 erra = errb = 0;
74 } else {
75 printf("algo=%-8s faila=%3d(%c) failb=%3d(%c) %s\n",
76 raid6_call.name,
77 i, disk_type(i),
78 j, disk_type(j),
79 (!erra && !errb) ? "OK" :
80 !erra ? "ERRB" :
81 !errb ? "ERRA" : "ERRAB");
82 }
83
84 dataptrs[i] = data[i];
85 dataptrs[j] = data[j];
86
87 return erra || errb;
88}
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090int main(int argc, char *argv[])
91{
H. Peter Anvin66c811e2008-02-06 01:39:48 -080092 const struct raid6_calls *const *algo;
Jim Kukunas2dbf7082012-05-22 13:54:23 +100093 const struct raid6_recov_calls *const *ra;
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +110094 int i, j, p1, p2;
H. Peter Anvin66c811e2008-02-06 01:39:48 -080095 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +110097 makedata(0, NDISKS-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Jim Kukunas2dbf7082012-05-22 13:54:23 +100099 for (ra = raid6_recov_algos; *ra; ra++) {
100 if ((*ra)->valid && !(*ra)->valid())
101 continue;
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +1100102
Jim Kukunas2dbf7082012-05-22 13:54:23 +1000103 raid6_2data_recov = (*ra)->data2;
104 raid6_datap_recov = (*ra)->datap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Jim Kukunas2dbf7082012-05-22 13:54:23 +1000106 printf("using recovery %s\n", (*ra)->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Jim Kukunas2dbf7082012-05-22 13:54:23 +1000108 for (algo = raid6_algos; *algo; algo++) {
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +1100109 if ((*algo)->valid && !(*algo)->valid())
110 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +1100112 raid6_call = **algo;
Jim Kukunas2dbf7082012-05-22 13:54:23 +1000113
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +1100114 /* Nuke syndromes */
115 memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE);
Jim Kukunas2dbf7082012-05-22 13:54:23 +1000116
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +1100117 /* Generate assumed good syndrome */
118 raid6_call.gen_syndrome(NDISKS, PAGE_SIZE,
119 (void **)&dataptrs);
120
121 for (i = 0; i < NDISKS-1; i++)
122 for (j = i+1; j < NDISKS; j++)
123 err += test_disks(i, j);
124
125 if (!raid6_call.xor_syndrome)
126 continue;
127
128 for (p1 = 0; p1 < NDISKS-2; p1++)
129 for (p2 = p1; p2 < NDISKS-2; p2++) {
130
131 /* Simulate rmw run */
132 raid6_call.xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
133 (void **)&dataptrs);
134 makedata(p1, p2);
135 raid6_call.xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
136 (void **)&dataptrs);
137
138 for (i = 0; i < NDISKS-1; i++)
139 for (j = i+1; j < NDISKS; j++)
140 err += test_disks(i, j);
141 }
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
144 printf("\n");
145 }
146
147 printf("\n");
148 /* Pick the best algorithm test */
149 raid6_select_algo();
150
H. Peter Anvin66c811e2008-02-06 01:39:48 -0800151 if (err)
152 printf("\n*** ERRORS FOUND ***\n");
153
154 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}