1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
/*
* Copyright(c) 2007 Yuri Tikhonov <yur@emcraft.com>
*
* Developed for DENX Software Engineering GmbH
*
* Asynchronous RAID-6 recovery calculations ASYNC_TX API.
*
* based on async_xor.c code written by:
* Dan Williams <dan.j.williams@intel.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that 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/kernel.h>
#include <linux/interrupt.h>
#include <linux/dma-mapping.h>
#include <linux/raid/xor.h>
#include <linux/async_tx.h>
#include "../drivers/md/raid6.h"
/**
* async_r6_dd_recov - attempt to calculate two data misses using dma engines.
* @disks: number of disks in the RAID-6 array
* @bytes: size of strip
* @faila: first failed drive index
* @failb: second failed drive index
* @ptrs: array of pointers to strips (last two must be p and q, respectively)
* @flags: ASYNC_TX_ACK, ASYNC_TX_DEP_ACK
* @depend_tx: depends on the result of this transaction.
* @cb: function to call when the operation completes
* @cb_param: parameter to pass to the callback routine
*/
struct dma_async_tx_descriptor *
async_r6_dd_recov(int disks, size_t bytes, int faila, int failb,
struct page **ptrs, enum async_tx_flags flags,
struct dma_async_tx_descriptor *depend_tx,
dma_async_tx_callback cb, void *cb_param)
{
struct dma_async_tx_descriptor *tx = NULL;
struct page *lptrs[disks];
unsigned char lcoef[disks-4];
int i = 0, k = 0, fc = -1;
uint8_t bc[2];
dma_async_tx_callback lcb = NULL;
void *lcb_param = NULL;
/* Assume that failb > faila */
if (faila > failb) {
fc = faila;
faila = failb;
failb = fc;
}
/* Try to compute missed data asynchronously. */
if (disks == 4) {
/*
* Pxy and Qxy are zero in this case so we already have
* P+Pxy and Q+Qxy in P and Q strips respectively.
*/
tx = depend_tx;
lcb = cb;
lcb_param = cb_param;
goto do_mult;
}
/*
* (1) Calculate Qxy and Pxy:
* Qxy = A(0)*D(0) + ... + A(n-1)*D(n-1) + A(n+1)*D(n+1) + ... +
* A(m-1)*D(m-1) + A(m+1)*D(m+1) + ... + A(disks-1)*D(disks-1),
* where n = faila, m = failb.
*/
for (i = 0, k = 0; i < disks - 2; i++) {
if (i != faila && i != failb) {
lptrs[k] = ptrs[i];
lcoef[k] = raid6_gfexp[i];
k++;
}
}
lptrs[k] = ptrs[faila];
lptrs[k+1] = ptrs[failb];
tx = async_pq(lptrs, lcoef, 0, k, bytes,
ASYNC_TX_PQ_ZERO_P | ASYNC_TX_PQ_ZERO_Q |
ASYNC_TX_ASYNC_ONLY, depend_tx, NULL, NULL);
if (!tx) {
/* Here may go to the synchronous variant */
if (flags & ASYNC_TX_ASYNC_ONLY)
return NULL;
goto ddr_sync;
}
/*
* The following operations will 'damage' P/Q strips;
* so now we condemned to move in an asynchronous way.
*/
/* (2) Calculate Q+Qxy */
lptrs[0] = ptrs[failb];
lptrs[1] = ptrs[disks-1];
lptrs[2] = NULL;
tx = async_pq(lptrs, NULL, 0, 1, bytes, ASYNC_TX_DEP_ACK,
tx, NULL, NULL);
/* (3) Calculate P+Pxy */
lptrs[0] = ptrs[faila];
lptrs[1] = ptrs[disks-2];
lptrs[2] = NULL;
tx = async_pq(lptrs, NULL, 0, 1, bytes, ASYNC_TX_DEP_ACK,
tx, NULL, NULL);
do_mult:
/*
* (4) Compute (P+Pxy) * Bxy. Compute (Q+Qxy) * Cxy. XOR them and get
* faila.
* B = (2^(y-x))*((2^(y-x) + {01})^(-1))
* C = (2^(-x))*((2^(y-x) + {01})^(-1))
* B * [p] + C * [q] -> [failb]
*/
bc[0] = raid6_gfexi[failb-faila];
bc[1] = raid6_gfinv[raid6_gfexp[faila]^raid6_gfexp[failb]];
lptrs[0] = ptrs[disks - 2];
lptrs[1] = ptrs[disks - 1];
lptrs[2] = NULL;
lptrs[3] = ptrs[failb];
tx = async_pq(lptrs, bc, 0, 2, bytes,
ASYNC_TX_PQ_ZERO_Q | ASYNC_TX_DEP_ACK,
tx, NULL, NULL);
/* (5) Compute failed Dy using recovered [failb] and P+Pnm in [p] */
lptrs[0] = ptrs[disks-2];
lptrs[1] = ptrs[failb];
lptrs[2] = ptrs[faila];
lptrs[3] = NULL;
tx = async_pq(lptrs, NULL, 0, 2, bytes,
ASYNC_TX_PQ_ZERO_P | ASYNC_TX_DEP_ACK,
tx, lcb, lcb_param);
if (disks == 4)
return tx;
/* (6) Restore the parities back */
flags |= ASYNC_TX_DEP_ACK;
memcpy(lptrs, ptrs, (disks - 2) * sizeof(struct page *));
lptrs[disks - 2] = ptrs[disks-2];
lptrs[disks - 1] = ptrs[disks-1];
return async_gen_syndrome(lptrs, 0, disks - 2, bytes, flags,
tx, cb, cb_param);
ddr_sync:
{
void **sptrs = (void **)lptrs;
/*
* Failed to compute asynchronously, do it in
* synchronous manner
*/
/* wait for any prerequisite operations */
async_tx_quiesce(&depend_tx);
i = disks;
while (i--)
sptrs[i] = kmap(ptrs[i]);
raid6_2data_recov(disks, bytes, faila, failb, sptrs);
i = disks;
while (i--)
kunmap(ptrs[i]);
async_tx_sync_epilog(cb, cb_param);
}
return tx;
}
EXPORT_SYMBOL_GPL(async_r6_dd_recov);
/**
* async_r6_dp_recov - attempt to calculate one data miss using dma engines.
* @disks: number of disks in the RAID-6 array
* @bytes: size of strip
* @faila: failed drive index
* @ptrs: array of pointers to strips (last two must be p and q, respectively)
* @flags: ASYNC_TX_ACK, ASYNC_TX_DEP_ACK
* @depend_tx: depends on the result of this transaction.
* @cb: function to call when the operation completes
* @cb_param: parameter to pass to the callback routine
*/
struct dma_async_tx_descriptor *
async_r6_dp_recov(int disks, size_t bytes, int faila, struct page **ptrs,
enum async_tx_flags flags, struct dma_async_tx_descriptor *depend_tx,
dma_async_tx_callback cb, void *cb_param)
{
struct dma_async_tx_descriptor *tx = NULL;
struct page *lptrs[disks];
unsigned char lcoef[disks-2];
int i = 0, k = 0;
/* Try compute missed data asynchronously. */
/*
* (1) Calculate Qn + Q:
* Qn = A(0)*D(0) + .. + A(n-1)*D(n-1) + A(n+1)*D(n+1) + ..,
* where n = faila;
* then subtract Qn from Q and place result to Pn.
*/
for (i = 0; i < disks - 2; i++) {
if (i != faila) {
lptrs[k] = ptrs[i];
lcoef[k++] = raid6_gfexp[i];
}
}
lptrs[k] = ptrs[disks-1]; /* Q-parity */
lcoef[k++] = 1;
lptrs[k] = NULL;
lptrs[k+1] = ptrs[disks-2];
tx = async_pq(lptrs, lcoef, 0, k, bytes,
ASYNC_TX_PQ_ZERO_Q | ASYNC_TX_ASYNC_ONLY,
depend_tx, NULL, NULL);
if (!tx) {
if (flags & ASYNC_TX_ASYNC_ONLY)
return NULL;
goto dpr_sync;
}
/*
* (2) Compute missed Dn:
* Dn = (Q + Qn) * [A(n)^(-1)]
*/
lptrs[0] = ptrs[disks-2];
lptrs[1] = NULL;
lptrs[2] = ptrs[faila];
return async_pq(lptrs, (u8 *)&raid6_gfexp[faila ? 255-faila : 0], 0, 1,
bytes, ASYNC_TX_DEP_ACK | ASYNC_TX_PQ_ZERO_Q,
tx, cb, cb_param);
dpr_sync:
{
void **sptrs = (void **) lptrs;
/*
* Failed to compute asynchronously, do it in
* synchronous manner
*/
/* wait for any prerequisite operations */
async_tx_quiesce(&depend_tx);
i = disks;
while (i--)
sptrs[i] = kmap(ptrs[i]);
raid6_datap_recov(disks, bytes, faila, (void *)sptrs);
i = disks;
while (i--)
kunmap(ptrs[i]);
async_tx_sync_epilog(cb, cb_param);
}
return tx;
}
EXPORT_SYMBOL_GPL(async_r6_dp_recov);
static int __init async_r6recov_init(void)
{
return 0;
}
static void __exit async_r6recov_exit(void)
{
do { } while (0);
}
module_init(async_r6recov_init);
module_exit(async_r6recov_exit);
MODULE_AUTHOR("Yuri Tikhonov <yur@emcraft.com>");
MODULE_DESCRIPTION("asynchronous RAID-6 recovery api");
MODULE_LICENSE("GPL");
|