1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright 2002 H. Peter Anvin - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
16 * RAID-6 data recovery in dual failure mode. In single failure mode,
17 * use the RAID-5 algorithm (or, in the case of Q failure, just reconstruct
21 #include <linux/export.h>
22 #include <linux/raid/pq.h>
24 /* Recover two failed data blocks. */
25 void raid6_2data_recov(int disks
, size_t bytes
, int faila
, int failb
,
30 const u8
*pbmul
; /* P multiplier table for B data */
31 const u8
*qmul
; /* Q multiplier table (for both) */
33 p
= (u8
*)ptrs
[disks
-2];
34 q
= (u8
*)ptrs
[disks
-1];
36 /* Compute syndrome with zero for the missing data pages
37 Use the dead data pages as temporary storage for
38 delta p and delta q */
39 dp
= (u8
*)ptrs
[faila
];
40 ptrs
[faila
] = (void *)raid6_empty_zero_page
;
42 dq
= (u8
*)ptrs
[failb
];
43 ptrs
[failb
] = (void *)raid6_empty_zero_page
;
46 raid6_call
.gen_syndrome(disks
, bytes
, ptrs
);
48 /* Restore pointer table */
54 /* Now, pick the proper data tables */
55 pbmul
= raid6_gfmul
[raid6_gfexi
[failb
-faila
]];
56 qmul
= raid6_gfmul
[raid6_gfinv
[raid6_gfexp
[faila
]^raid6_gfexp
[failb
]]];
62 *dq
++ = db
= pbmul
[px
] ^ qx
; /* Reconstructed B */
63 *dp
++ = db
^ px
; /* Reconstructed A */
67 EXPORT_SYMBOL_GPL(raid6_2data_recov
);
69 /* Recover failure of one data block plus the P block */
70 void raid6_datap_recov(int disks
, size_t bytes
, int faila
, void **ptrs
)
73 const u8
*qmul
; /* Q multiplier table */
75 p
= (u8
*)ptrs
[disks
-2];
76 q
= (u8
*)ptrs
[disks
-1];
78 /* Compute syndrome with zero for the missing data page
79 Use the dead data page as temporary storage for delta q */
80 dq
= (u8
*)ptrs
[faila
];
81 ptrs
[faila
] = (void *)raid6_empty_zero_page
;
84 raid6_call
.gen_syndrome(disks
, bytes
, ptrs
);
86 /* Restore pointer table */
90 /* Now, pick the proper data tables */
91 qmul
= raid6_gfmul
[raid6_gfinv
[raid6_gfexp
[faila
]]];
95 *p
++ ^= *dq
= qmul
[*q
^ *dq
];
99 EXPORT_SYMBOL_GPL(raid6_datap_recov
);
104 /* Recover two failed blocks. */
105 void raid6_dual_recov(int disks
, size_t bytes
, int faila
, int failb
, void **ptrs
)
107 if ( faila
> failb
) {
113 if ( failb
== disks
-1 ) {
114 if ( faila
== disks
-2 ) {
115 /* P+Q failure. Just rebuild the syndrome. */
116 raid6_call
.gen_syndrome(disks
, bytes
, ptrs
);
118 /* data+Q failure. Reconstruct data from P,
119 then rebuild syndrome. */
120 /* NOT IMPLEMENTED - equivalent to RAID-5 */
123 if ( failb
== disks
-2 ) {
124 /* data+P failure. */
125 raid6_datap_recov(disks
, bytes
, faila
, ptrs
);
127 /* data+data failure. */
128 raid6_2data_recov(disks
, bytes
, faila
, failb
, ptrs
);