1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* -*- linux-c -*- ------------------------------------------------------- *
4 * Copyright 2002 H. Peter Anvin - All Rights Reserved
6 * ----------------------------------------------------------------------- */
11 * RAID-6 data recovery in dual failure mode. In single failure mode,
12 * use the RAID-5 algorithm (or, in the case of Q failure, just reconstruct
16 #include <linux/raid/pq.h>
18 /* Recover two failed data blocks. */
19 static void raid6_2data_recov_intx1(int disks
, size_t bytes
, int faila
,
20 int failb
, void **ptrs
)
24 const u8
*pbmul
; /* P multiplier table for B data */
25 const u8
*qmul
; /* Q multiplier table (for both) */
27 p
= (u8
*)ptrs
[disks
-2];
28 q
= (u8
*)ptrs
[disks
-1];
30 /* Compute syndrome with zero for the missing data pages
31 Use the dead data pages as temporary storage for
32 delta p and delta q */
33 dp
= (u8
*)ptrs
[faila
];
34 ptrs
[faila
] = (void *)raid6_empty_zero_page
;
36 dq
= (u8
*)ptrs
[failb
];
37 ptrs
[failb
] = (void *)raid6_empty_zero_page
;
40 raid6_call
.gen_syndrome(disks
, bytes
, ptrs
);
42 /* Restore pointer table */
48 /* Now, pick the proper data tables */
49 pbmul
= raid6_gfmul
[raid6_gfexi
[failb
-faila
]];
50 qmul
= raid6_gfmul
[raid6_gfinv
[raid6_gfexp
[faila
]^raid6_gfexp
[failb
]]];
56 *dq
++ = db
= pbmul
[px
] ^ qx
; /* Reconstructed B */
57 *dp
++ = db
^ px
; /* Reconstructed A */
62 /* Recover failure of one data block plus the P block */
63 static void raid6_datap_recov_intx1(int disks
, size_t bytes
, int faila
,
67 const u8
*qmul
; /* Q multiplier table */
69 p
= (u8
*)ptrs
[disks
-2];
70 q
= (u8
*)ptrs
[disks
-1];
72 /* Compute syndrome with zero for the missing data page
73 Use the dead data page as temporary storage for delta q */
74 dq
= (u8
*)ptrs
[faila
];
75 ptrs
[faila
] = (void *)raid6_empty_zero_page
;
78 raid6_call
.gen_syndrome(disks
, bytes
, ptrs
);
80 /* Restore pointer table */
84 /* Now, pick the proper data tables */
85 qmul
= raid6_gfmul
[raid6_gfinv
[raid6_gfexp
[faila
]]];
89 *p
++ ^= *dq
= qmul
[*q
^ *dq
];
95 const struct raid6_recov_calls raid6_recov_intx1
= {
96 .data2
= raid6_2data_recov_intx1
,
97 .datap
= raid6_datap_recov_intx1
,
106 /* Recover two failed blocks. */
107 void raid6_dual_recov(int disks
, size_t bytes
, int faila
, int failb
, void **ptrs
)
109 if ( faila
> failb
) {
115 if ( failb
== disks
-1 ) {
116 if ( faila
== disks
-2 ) {
117 /* P+Q failure. Just rebuild the syndrome. */
118 raid6_call
.gen_syndrome(disks
, bytes
, ptrs
);
120 /* data+Q failure. Reconstruct data from P,
121 then rebuild syndrome. */
122 /* NOT IMPLEMENTED - equivalent to RAID-5 */
125 if ( failb
== disks
-2 ) {
126 /* data+P failure. */
127 raid6_datap_recov(disks
, bytes
, faila
, ptrs
);
129 /* data+data failure. */
130 raid6_2data_recov(disks
, bytes
, faila
, failb
, ptrs
);