1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/async_tx.h>
23#include <linux/gfp.h>
24#include <linux/mm.h>
25#include <linux/random.h>
26#include <linux/module.h>
27
28#undef pr
29#define pr(fmt, args...) pr_info("raid6test: " fmt, ##args)
30
31#define NDISKS 64
32
33static struct page *dataptrs[NDISKS];
34static addr_conv_t addr_conv[NDISKS];
35static struct page *data[NDISKS+3];
36static struct page *spare;
37static struct page *recovi;
38static struct page *recovj;
39
40static void callback(void *param)
41{
42 struct completion *cmp = param;
43
44 complete(cmp);
45}
46
47static void makedata(int disks)
48{
49 int i;
50
51 for (i = 0; i < disks; i++) {
52 prandom_bytes(page_address(data[i]), PAGE_SIZE);
53 dataptrs[i] = data[i];
54 }
55}
56
57static char disk_type(int d, int disks)
58{
59 if (d == disks - 2)
60 return 'P';
61 else if (d == disks - 1)
62 return 'Q';
63 else
64 return 'D';
65}
66
67
68static void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, struct page **ptrs)
69{
70 struct async_submit_ctl submit;
71 struct completion cmp;
72 struct dma_async_tx_descriptor *tx = NULL;
73 enum sum_check_flags result = ~0;
74
75 if (faila > failb)
76 swap(faila, failb);
77
78 if (failb == disks-1) {
79 if (faila == disks-2) {
80
81 init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
82 tx = async_gen_syndrome(ptrs, 0, disks, bytes, &submit);
83 } else {
84 struct page *blocks[NDISKS];
85 struct page *dest;
86 int count = 0;
87 int i;
88
89 BUG_ON(disks > NDISKS);
90
91
92
93
94 for (i = disks; i-- ; ) {
95 if (i == faila || i == failb)
96 continue;
97 blocks[count++] = ptrs[i];
98 }
99 dest = ptrs[faila];
100 init_async_submit(&submit, ASYNC_TX_XOR_ZERO_DST, NULL,
101 NULL, NULL, addr_conv);
102 tx = async_xor(dest, blocks, 0, count, bytes, &submit);
103
104 init_async_submit(&submit, 0, tx, NULL, NULL, addr_conv);
105 tx = async_gen_syndrome(ptrs, 0, disks, bytes, &submit);
106 }
107 } else {
108 if (failb == disks-2) {
109
110 init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
111 tx = async_raid6_datap_recov(disks, bytes, faila, ptrs, &submit);
112 } else {
113
114 init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
115 tx = async_raid6_2data_recov(disks, bytes, faila, failb, ptrs, &submit);
116 }
117 }
118 init_completion(&cmp);
119 init_async_submit(&submit, ASYNC_TX_ACK, tx, callback, &cmp, addr_conv);
120 tx = async_syndrome_val(ptrs, 0, disks, bytes, &result, spare, &submit);
121 async_tx_issue_pending(tx);
122
123 if (wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)) == 0)
124 pr("%s: timeout! (faila: %d failb: %d disks: %d)\n",
125 __func__, faila, failb, disks);
126
127 if (result != 0)
128 pr("%s: validation failure! faila: %d failb: %d sum_check_flags: %x\n",
129 __func__, faila, failb, result);
130}
131
132static int test_disks(int i, int j, int disks)
133{
134 int erra, errb;
135
136 memset(page_address(recovi), 0xf0, PAGE_SIZE);
137 memset(page_address(recovj), 0xba, PAGE_SIZE);
138
139 dataptrs[i] = recovi;
140 dataptrs[j] = recovj;
141
142 raid6_dual_recov(disks, PAGE_SIZE, i, j, dataptrs);
143
144 erra = memcmp(page_address(data[i]), page_address(recovi), PAGE_SIZE);
145 errb = memcmp(page_address(data[j]), page_address(recovj), PAGE_SIZE);
146
147 pr("%s(%d, %d): faila=%3d(%c) failb=%3d(%c) %s\n",
148 __func__, i, j, i, disk_type(i, disks), j, disk_type(j, disks),
149 (!erra && !errb) ? "OK" : !erra ? "ERRB" : !errb ? "ERRA" : "ERRAB");
150
151 dataptrs[i] = data[i];
152 dataptrs[j] = data[j];
153
154 return erra || errb;
155}
156
157static int test(int disks, int *tests)
158{
159 struct dma_async_tx_descriptor *tx;
160 struct async_submit_ctl submit;
161 struct completion cmp;
162 int err = 0;
163 int i, j;
164
165 recovi = data[disks];
166 recovj = data[disks+1];
167 spare = data[disks+2];
168
169 makedata(disks);
170
171
172 memset(page_address(data[disks-2]), 0xee, PAGE_SIZE);
173 memset(page_address(data[disks-1]), 0xee, PAGE_SIZE);
174
175
176 init_completion(&cmp);
177 init_async_submit(&submit, ASYNC_TX_ACK, NULL, callback, &cmp, addr_conv);
178 tx = async_gen_syndrome(dataptrs, 0, disks, PAGE_SIZE, &submit);
179 async_tx_issue_pending(tx);
180
181 if (wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)) == 0) {
182 pr("error: initial gen_syndrome(%d) timed out\n", disks);
183 return 1;
184 }
185
186 pr("testing the %d-disk case...\n", disks);
187 for (i = 0; i < disks-1; i++)
188 for (j = i+1; j < disks; j++) {
189 (*tests)++;
190 err += test_disks(i, j, disks);
191 }
192
193 return err;
194}
195
196
197static int raid6_test(void)
198{
199 int err = 0;
200 int tests = 0;
201 int i;
202
203 for (i = 0; i < NDISKS+3; i++) {
204 data[i] = alloc_page(GFP_KERNEL);
205 if (!data[i]) {
206 while (i--)
207 put_page(data[i]);
208 return -ENOMEM;
209 }
210 }
211
212
213 if (NDISKS > 4)
214 err += test(4, &tests);
215 if (NDISKS > 5)
216 err += test(5, &tests);
217
218
219
220 if (NDISKS > 12) {
221 err += test(11, &tests);
222 err += test(12, &tests);
223 }
224
225
226
227
228
229 if (NDISKS > 24)
230 err += test(24, &tests);
231
232 err += test(NDISKS, &tests);
233
234 pr("\n");
235 pr("complete (%d tests, %d failure%s)\n",
236 tests, err, err == 1 ? "" : "s");
237
238 for (i = 0; i < NDISKS+3; i++)
239 put_page(data[i]);
240
241 return 0;
242}
243
244static void raid6_test_exit(void)
245{
246}
247
248
249
250
251late_initcall(raid6_test);
252module_exit(raid6_test_exit);
253MODULE_AUTHOR("Dan Williams <dan.j.williams@intel.com>");
254MODULE_DESCRIPTION("asynchronous RAID-6 recovery self tests");
255MODULE_LICENSE("GPL");
256