Blame view

crypto/async_tx/raid6test.c 6.49 KB
cb3c82992   Dan Williams   async_tx: raid6 r...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  /*
   * asynchronous raid6 recovery self test
   * Copyright (c) 2009, Intel Corporation.
   *
   * based on drivers/md/raid6test/test.c:
   * 	Copyright 2002-2007 H. Peter Anvin
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms and conditions of the GNU General Public License,
   * version 2, as published by the Free Software Foundation.
   *
   * This program is distributed in the hope it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   * more details.
   *
   * You should have received a copy of the GNU General Public License along with
   * this program; if not, write to the Free Software Foundation, Inc.,
   * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
   *
   */
  #include <linux/async_tx.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
23
  #include <linux/gfp.h>
b7f080cfe   Alexey Dobriyan   net: remove mm.h ...
24
  #include <linux/mm.h>
cb3c82992   Dan Williams   async_tx: raid6 r...
25
  #include <linux/random.h>
4bb33cc89   Paul Gortmaker   crypto: add modul...
26
  #include <linux/module.h>
cb3c82992   Dan Williams   async_tx: raid6 r...
27
28
29
  
  #undef pr
  #define pr(fmt, args...) pr_info("raid6test: " fmt, ##args)
09ec0f583   Dan Williams   raid6test: add ne...
30
  #define NDISKS 64 /* Including P and Q */
cb3c82992   Dan Williams   async_tx: raid6 r...
31
32
  
  static struct page *dataptrs[NDISKS];
1b6df6930   Dan Williams   raid6test: fix st...
33
  static addr_conv_t addr_conv[NDISKS];
cb3c82992   Dan Williams   async_tx: raid6 r...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  static struct page *data[NDISKS+3];
  static struct page *spare;
  static struct page *recovi;
  static struct page *recovj;
  
  static void callback(void *param)
  {
  	struct completion *cmp = param;
  
  	complete(cmp);
  }
  
  static void makedata(int disks)
  {
3ec39abdc   Akinobu Mita   raid6test: use pr...
48
  	int i;
cb3c82992   Dan Williams   async_tx: raid6 r...
49
50
  
  	for (i = 0; i < disks; i++) {
3ec39abdc   Akinobu Mita   raid6test: use pr...
51
  		prandom_bytes(page_address(data[i]), PAGE_SIZE);
cb3c82992   Dan Williams   async_tx: raid6 r...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  		dataptrs[i] = data[i];
  	}
  }
  
  static char disk_type(int d, int disks)
  {
  	if (d == disks - 2)
  		return 'P';
  	else if (d == disks - 1)
  		return 'Q';
  	else
  		return 'D';
  }
  
  /* Recover two failed blocks. */
  static void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, struct page **ptrs)
  {
  	struct async_submit_ctl submit;
cb3c82992   Dan Williams   async_tx: raid6 r...
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  	struct completion cmp;
  	struct dma_async_tx_descriptor *tx = NULL;
  	enum sum_check_flags result = ~0;
  
  	if (faila > failb)
  		swap(faila, failb);
  
  	if (failb == disks-1) {
  		if (faila == disks-2) {
  			/* P+Q failure.  Just rebuild the syndrome. */
  			init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
  			tx = async_gen_syndrome(ptrs, 0, disks, bytes, &submit);
  		} else {
  			struct page *blocks[disks];
  			struct page *dest;
  			int count = 0;
  			int i;
  
  			/* data+Q failure.  Reconstruct data from P,
  			 * then rebuild syndrome
  			 */
  			for (i = disks; i-- ; ) {
  				if (i == faila || i == failb)
  					continue;
  				blocks[count++] = ptrs[i];
  			}
  			dest = ptrs[faila];
  			init_async_submit(&submit, ASYNC_TX_XOR_ZERO_DST, NULL,
  					  NULL, NULL, addr_conv);
  			tx = async_xor(dest, blocks, 0, count, bytes, &submit);
  
  			init_async_submit(&submit, 0, tx, NULL, NULL, addr_conv);
  			tx = async_gen_syndrome(ptrs, 0, disks, bytes, &submit);
  		}
  	} else {
  		if (failb == disks-2) {
  			/* data+P failure. */
  			init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
  			tx = async_raid6_datap_recov(disks, bytes, faila, ptrs, &submit);
  		} else {
  			/* data+data failure. */
  			init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
  			tx = async_raid6_2data_recov(disks, bytes, faila, failb, ptrs, &submit);
  		}
  	}
  	init_completion(&cmp);
  	init_async_submit(&submit, ASYNC_TX_ACK, tx, callback, &cmp, addr_conv);
  	tx = async_syndrome_val(ptrs, 0, disks, bytes, &result, spare, &submit);
  	async_tx_issue_pending(tx);
  
  	if (wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)) == 0)
  		pr("%s: timeout! (faila: %d failb: %d disks: %d)
  ",
  		   __func__, faila, failb, disks);
  
  	if (result != 0)
  		pr("%s: validation failure! faila: %d failb: %d sum_check_flags: %x
  ",
  		   __func__, faila, failb, result);
  }
  
  static int test_disks(int i, int j, int disks)
  {
  	int erra, errb;
  
  	memset(page_address(recovi), 0xf0, PAGE_SIZE);
  	memset(page_address(recovj), 0xba, PAGE_SIZE);
  
  	dataptrs[i] = recovi;
  	dataptrs[j] = recovj;
  
  	raid6_dual_recov(disks, PAGE_SIZE, i, j, dataptrs);
  
  	erra = memcmp(page_address(data[i]), page_address(recovi), PAGE_SIZE);
  	errb = memcmp(page_address(data[j]), page_address(recovj), PAGE_SIZE);
  
  	pr("%s(%d, %d): faila=%3d(%c)  failb=%3d(%c)  %s
  ",
  	   __func__, i, j, i, disk_type(i, disks), j, disk_type(j, disks),
  	   (!erra && !errb) ? "OK" : !erra ? "ERRB" : !errb ? "ERRA" : "ERRAB");
  
  	dataptrs[i] = data[i];
  	dataptrs[j] = data[j];
  
  	return erra || errb;
  }
  
  static int test(int disks, int *tests)
  {
cb3c82992   Dan Williams   async_tx: raid6 r...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  	struct dma_async_tx_descriptor *tx;
  	struct async_submit_ctl submit;
  	struct completion cmp;
  	int err = 0;
  	int i, j;
  
  	recovi = data[disks];
  	recovj = data[disks+1];
  	spare  = data[disks+2];
  
  	makedata(disks);
  
  	/* Nuke syndromes */
  	memset(page_address(data[disks-2]), 0xee, PAGE_SIZE);
  	memset(page_address(data[disks-1]), 0xee, PAGE_SIZE);
  
  	/* Generate assumed good syndrome */
  	init_completion(&cmp);
  	init_async_submit(&submit, ASYNC_TX_ACK, NULL, callback, &cmp, addr_conv);
  	tx = async_gen_syndrome(dataptrs, 0, disks, PAGE_SIZE, &submit);
  	async_tx_issue_pending(tx);
  
  	if (wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)) == 0) {
  		pr("error: initial gen_syndrome(%d) timed out
  ", disks);
  		return 1;
  	}
  
  	pr("testing the %d-disk case...
  ", disks);
  	for (i = 0; i < disks-1; i++)
  		for (j = i+1; j < disks; j++) {
  			(*tests)++;
  			err += test_disks(i, j, disks);
  		}
  
  	return err;
  }
  
  
  static int raid6_test(void)
  {
  	int err = 0;
  	int tests = 0;
  	int i;
  
  	for (i = 0; i < NDISKS+3; i++) {
  		data[i] = alloc_page(GFP_KERNEL);
  		if (!data[i]) {
  			while (i--)
  				put_page(data[i]);
  			return -ENOMEM;
  		}
  	}
  
  	/* the 4-disk and 5-disk cases are special for the recovery code */
  	if (NDISKS > 4)
  		err += test(4, &tests);
  	if (NDISKS > 5)
  		err += test(5, &tests);
e02a0e47a   Dan Williams   async_tx: expand ...
219
220
221
222
223
224
225
  	/* the 11 and 12 disk cases are special for ioatdma (p-disabled
  	 * q-continuation without extended descriptor)
  	 */
  	if (NDISKS > 12) {
  		err += test(11, &tests);
  		err += test(12, &tests);
  	}
09ec0f583   Dan Williams   raid6test: add ne...
226
227
228
229
230
231
232
  
  	/* the 24 disk case is special for ioatdma as it is the boudary point
  	 * at which it needs to switch from 8-source ops to 16-source
  	 * ops for continuation (assumes DMA_HAS_PQ_CONTINUE is not set)
  	 */
  	if (NDISKS > 24)
  		err += test(24, &tests);
cb3c82992   Dan Williams   async_tx: raid6 r...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
  	err += test(NDISKS, &tests);
  
  	pr("
  ");
  	pr("complete (%d tests, %d failure%s)
  ",
  	   tests, err, err == 1 ? "" : "s");
  
  	for (i = 0; i < NDISKS+3; i++)
  		put_page(data[i]);
  
  	return 0;
  }
  
  static void raid6_test_exit(void)
  {
  }
  
  /* when compiled-in wait for drivers to load first (assumes dma drivers
   * are also compliled-in)
   */
  late_initcall(raid6_test);
  module_exit(raid6_test_exit);
  MODULE_AUTHOR("Dan Williams <dan.j.williams@intel.com>");
  MODULE_DESCRIPTION("asynchronous RAID-6 recovery self tests");
  MODULE_LICENSE("GPL");