2 * asynchronous raid6 recovery self test
3 * Copyright (c) 2009, Intel Corporation.
5 * based on drivers/md/raid6test/test.c:
6 * Copyright 2002-2007 H. Peter Anvin
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <linux/async_tx.h>
23 #include <linux/gfp.h>
25 #include <linux/random.h>
26 #include <linux/module.h>
29 #define pr(fmt, args...) pr_info("raid6test: " fmt, ##args)
31 #define NDISKS 16 /* Including P and Q */
33 static struct page *dataptrs[NDISKS];
34 static addr_conv_t addr_conv[NDISKS];
35 static struct page *data[NDISKS+3];
36 static struct page *spare;
37 static struct page *recovi;
38 static struct page *recovj;
40 static void callback(void *param)
42 struct completion *cmp = param;
47 static void makedata(int disks)
51 for (i = 0; i < disks; i++) {
52 prandom_bytes(page_address(data[i]), PAGE_SIZE);
53 dataptrs[i] = data[i];
57 static char disk_type(int d, int disks)
61 else if (d == disks - 1)
67 /* Recover two failed blocks. */
68 static void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, struct page **ptrs)
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;
78 if (failb == disks-1) {
79 if (faila == disks-2) {
80 /* P+Q failure. Just rebuild the syndrome. */
81 init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
82 tx = async_gen_syndrome(ptrs, 0, disks, bytes, &submit);
84 struct page *blocks[disks];
89 /* data+Q failure. Reconstruct data from P,
90 * then rebuild syndrome
92 for (i = disks; i-- ; ) {
93 if (i == faila || i == failb)
95 blocks[count++] = ptrs[i];
98 init_async_submit(&submit, ASYNC_TX_XOR_ZERO_DST, NULL,
99 NULL, NULL, addr_conv);
100 tx = async_xor(dest, blocks, 0, count, bytes, &submit);
102 init_async_submit(&submit, 0, tx, NULL, NULL, addr_conv);
103 tx = async_gen_syndrome(ptrs, 0, disks, bytes, &submit);
106 if (failb == disks-2) {
107 /* data+P failure. */
108 init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
109 tx = async_raid6_datap_recov(disks, bytes, faila, ptrs, &submit);
111 /* data+data failure. */
112 init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
113 tx = async_raid6_2data_recov(disks, bytes, faila, failb, ptrs, &submit);
116 init_completion(&cmp);
117 init_async_submit(&submit, ASYNC_TX_ACK, tx, callback, &cmp, addr_conv);
118 tx = async_syndrome_val(ptrs, 0, disks, bytes, &result, spare, &submit);
119 async_tx_issue_pending(tx);
121 if (wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)) == 0)
122 pr("%s: timeout! (faila: %d failb: %d disks: %d)\n",
123 __func__, faila, failb, disks);
126 pr("%s: validation failure! faila: %d failb: %d sum_check_flags: %x\n",
127 __func__, faila, failb, result);
130 static int test_disks(int i, int j, int disks)
134 memset(page_address(recovi), 0xf0, PAGE_SIZE);
135 memset(page_address(recovj), 0xba, PAGE_SIZE);
137 dataptrs[i] = recovi;
138 dataptrs[j] = recovj;
140 raid6_dual_recov(disks, PAGE_SIZE, i, j, dataptrs);
142 erra = memcmp(page_address(data[i]), page_address(recovi), PAGE_SIZE);
143 errb = memcmp(page_address(data[j]), page_address(recovj), PAGE_SIZE);
145 pr("%s(%d, %d): faila=%3d(%c) failb=%3d(%c) %s\n",
146 __func__, i, j, i, disk_type(i, disks), j, disk_type(j, disks),
147 (!erra && !errb) ? "OK" : !erra ? "ERRB" : !errb ? "ERRA" : "ERRAB");
149 dataptrs[i] = data[i];
150 dataptrs[j] = data[j];
155 static int test(int disks, int *tests)
157 struct dma_async_tx_descriptor *tx;
158 struct async_submit_ctl submit;
159 struct completion cmp;
163 recovi = data[disks];
164 recovj = data[disks+1];
165 spare = data[disks+2];
170 memset(page_address(data[disks-2]), 0xee, PAGE_SIZE);
171 memset(page_address(data[disks-1]), 0xee, PAGE_SIZE);
173 /* Generate assumed good syndrome */
174 init_completion(&cmp);
175 init_async_submit(&submit, ASYNC_TX_ACK, NULL, callback, &cmp, addr_conv);
176 tx = async_gen_syndrome(dataptrs, 0, disks, PAGE_SIZE, &submit);
177 async_tx_issue_pending(tx);
179 if (wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)) == 0) {
180 pr("error: initial gen_syndrome(%d) timed out\n", disks);
184 pr("testing the %d-disk case...\n", disks);
185 for (i = 0; i < disks-1; i++)
186 for (j = i+1; j < disks; j++) {
188 err += test_disks(i, j, disks);
195 static int raid6_test(void)
201 for (i = 0; i < NDISKS+3; i++) {
202 data[i] = alloc_page(GFP_KERNEL);
210 /* the 4-disk and 5-disk cases are special for the recovery code */
212 err += test(4, &tests);
214 err += test(5, &tests);
215 /* the 11 and 12 disk cases are special for ioatdma (p-disabled
216 * q-continuation without extended descriptor)
219 err += test(11, &tests);
220 err += test(12, &tests);
222 err += test(NDISKS, &tests);
225 pr("complete (%d tests, %d failure%s)\n",
226 tests, err, err == 1 ? "" : "s");
228 for (i = 0; i < NDISKS+3; i++)
234 static void raid6_test_exit(void)
238 /* when compiled-in wait for drivers to load first (assumes dma drivers
239 * are also compliled-in)
241 late_initcall(raid6_test);
242 module_exit(raid6_test_exit);
243 MODULE_AUTHOR("Dan Williams <dan.j.williams@intel.com>");
244 MODULE_DESCRIPTION("asynchronous RAID-6 recovery self tests");
245 MODULE_LICENSE("GPL");