xref: /netbsd-src/sys/dev/raidframe/rf_pqdeg.c (revision bada23909e740596d0a3785a73bd3583a9807fb8)
1 /*	$NetBSD: rf_pqdeg.c,v 1.3 1999/02/05 00:06:15 oster Exp $	*/
2 /*
3  * Copyright (c) 1995 Carnegie-Mellon University.
4  * All rights reserved.
5  *
6  * Author: Daniel Stodolsky
7  *
8  * Permission to use, copy, modify and distribute this software and
9  * its documentation is hereby granted, provided that both the copyright
10  * notice and this permission notice appear in all copies of the
11  * software, derivative works or modified versions, and any portions
12  * thereof, and that both notices appear in supporting documentation.
13  *
14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17  *
18  * Carnegie Mellon requests users of this software to return to
19  *
20  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
21  *  School of Computer Science
22  *  Carnegie Mellon University
23  *  Pittsburgh PA 15213-3890
24  *
25  * any improvements or extensions that they make and grant Carnegie the
26  * rights to redistribute these changes.
27  */
28 
29 #include "rf_archs.h"
30 
31 #if (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0)
32 
33 #include "rf_types.h"
34 #include "rf_raid.h"
35 #include "rf_dag.h"
36 #include "rf_dagutils.h"
37 #include "rf_dagfuncs.h"
38 #include "rf_dagffrd.h"
39 #include "rf_dagffwr.h"
40 #include "rf_dagdegrd.h"
41 #include "rf_dagdegwr.h"
42 #include "rf_threadid.h"
43 #include "rf_etimer.h"
44 #include "rf_pqdeg.h"
45 #include "rf_general.h"
46 #include "rf_pqdegdags.h"
47 #include "rf_pq.h"
48 
49 /*
50    Degraded mode dag functions for P+Q calculations.
51 
52    The following nomenclature is used.
53 
54    PQ_<D><P><Q>_Create{Large,Small}<Write|Read>DAG
55 
56    where <D><P><Q> are single digits representing the number of failed
57    data units <D> (0,1,2), parity units <P> (0,1), and Q units <Q>, effecting
58    the I/O. The reads have only  PQ_<D><P><Q>_CreateReadDAG variants, while
59    the single fault writes have both large and small write versions. (Single fault
60    PQ is equivalent to normal mode raid 5 in many aspects.
61 
62    Some versions degenerate into the same case, and are grouped together below.
63 */
64 
65 /* Reads, single failure
66 
67    we have parity, so we can do a raid 5
68    reconstruct read.
69 */
70 
71 RF_CREATE_DAG_FUNC_DECL(rf_PQ_100_CreateReadDAG)
72 {
73 	rf_CreateDegradedReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList, &rf_pRecoveryFuncs);
74 }
75 /* Reads double failure  */
76 
77 /*
78    Q is lost, but not parity
79    so we can a raid 5 reconstruct read.
80 */
81 
82 RF_CREATE_DAG_FUNC_DECL(rf_PQ_101_CreateReadDAG)
83 {
84 	rf_CreateDegradedReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList, &rf_pRecoveryFuncs);
85 }
86 /*
87   parity is lost, so we need to
88   do a reconstruct read and recompute
89   the data with Q.
90 */
91 
92 RF_CREATE_DAG_FUNC_DECL(rf_PQ_110_CreateReadDAG)
93 {
94 	RF_PhysDiskAddr_t *temp;
95 	/* swap P and Q pointers to fake out the DegradedReadDAG code */
96 	temp = asmap->parityInfo;
97 	asmap->parityInfo = asmap->qInfo;
98 	asmap->qInfo = temp;
99 	rf_CreateDegradedReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList, &rf_qRecoveryFuncs);
100 }
101 /*
102   Two data units are dead in this stripe, so we will need read
103   both P and Q to reconstruct the data. Note that only
104   one data unit we are reading may actually be missing.
105 */
106 RF_CREATE_DAG_FUNC_DECL(rf_CreateDoubleDegradedReadDAG)
107 {
108 	rf_PQ_DoubleDegRead(raidPtr, asmap, dag_h, bp, flags, allocList);
109 }
110 RF_CREATE_DAG_FUNC_DECL(rf_PQ_200_CreateReadDAG)
111 {
112 	rf_CreateDoubleDegradedReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList);
113 }
114 /* Writes, single failure */
115 
116 RF_CREATE_DAG_FUNC_DECL(rf_PQ_100_CreateWriteDAG)
117 {
118 	if (asmap->numStripeUnitsAccessed != 1 &&
119 	    asmap->failedPDAs[0]->numSector != raidPtr->Layout.sectorsPerStripeUnit)
120 		RF_PANIC();
121 	rf_CommonCreateSimpleDegradedWriteDAG(raidPtr, asmap, dag_h, bp, flags,
122 	    allocList, 2, (int (*) ()) rf_Degraded_100_PQFunc, RF_FALSE);
123 }
124 /* Dead  P - act like a RAID 5 small write with parity = Q */
125 RF_CREATE_DAG_FUNC_DECL(rf_PQ_010_CreateSmallWriteDAG)
126 {
127 	RF_PhysDiskAddr_t *temp;
128 	/* swap P and Q pointers to fake out the DegradedReadDAG code */
129 	temp = asmap->parityInfo;
130 	asmap->parityInfo = asmap->qInfo;
131 	asmap->qInfo = temp;
132 	rf_CommonCreateSmallWriteDAG(raidPtr, asmap, dag_h, bp, flags, allocList, &rf_qFuncs, NULL);
133 }
134 /* Dead Q - act like a RAID 5 small write */
135 RF_CREATE_DAG_FUNC_DECL(rf_PQ_001_CreateSmallWriteDAG)
136 {
137 	rf_CommonCreateSmallWriteDAG(raidPtr, asmap, dag_h, bp, flags, allocList, &rf_pFuncs, NULL);
138 }
139 /* Dead P - act like a RAID 5 large write but for Q */
140 RF_CREATE_DAG_FUNC_DECL(rf_PQ_010_CreateLargeWriteDAG)
141 {
142 	RF_PhysDiskAddr_t *temp;
143 	/* swap P and Q pointers to fake out the code */
144 	temp = asmap->parityInfo;
145 	asmap->parityInfo = asmap->qInfo;
146 	asmap->qInfo = temp;
147 	rf_CommonCreateLargeWriteDAG(raidPtr, asmap, dag_h, bp, flags, allocList, 1, rf_RegularQFunc, RF_FALSE);
148 }
149 /* Dead Q - act like a RAID 5 large write */
150 RF_CREATE_DAG_FUNC_DECL(rf_PQ_001_CreateLargeWriteDAG)
151 {
152 	rf_CommonCreateLargeWriteDAG(raidPtr, asmap, dag_h, bp, flags, allocList, 1, rf_RegularPFunc, RF_FALSE);
153 }
154 
155 
156 /*
157  * writes, double failure
158  */
159 
160 /*
161  * Lost P & Q - do a nonredundant write
162  */
163 RF_CREATE_DAG_FUNC_DECL(rf_PQ_011_CreateWriteDAG)
164 {
165 	rf_CreateNonRedundantWriteDAG(raidPtr, asmap, dag_h, bp, flags, allocList,
166 	    RF_IO_TYPE_WRITE);
167 }
168 /*
169    In the two cases below,
170    A nasty case arises when the write a (strict) portion of a failed stripe unit
171    and parts of another su. For now, we do not support this.
172 */
173 
174 /*
175   Lost Data and  P - do a Q write.
176 */
177 RF_CREATE_DAG_FUNC_DECL(rf_PQ_110_CreateWriteDAG)
178 {
179 	RF_PhysDiskAddr_t *temp;
180 
181 	if (asmap->numStripeUnitsAccessed != 1 &&
182 	    asmap->failedPDAs[0]->numSector != raidPtr->Layout.sectorsPerStripeUnit) {
183 		RF_PANIC();
184 	}
185 	/* swap P and Q to fake out parity code */
186 	temp = asmap->parityInfo;
187 	asmap->parityInfo = asmap->qInfo;
188 	asmap->qInfo = temp;
189 	rf_CommonCreateSimpleDegradedWriteDAG(raidPtr, asmap, dag_h, bp, flags,
190 	    allocList, 1, (int (*) ()) rf_PQ_DegradedWriteQFunc, RF_FALSE);
191 	/* is the regular Q func the right one to call? */
192 }
193 /*
194    Lost Data and Q - do degraded mode P write
195 */
196 RF_CREATE_DAG_FUNC_DECL(rf_PQ_101_CreateWriteDAG)
197 {
198 	if (asmap->numStripeUnitsAccessed != 1 &&
199 	    asmap->failedPDAs[0]->numSector != raidPtr->Layout.sectorsPerStripeUnit)
200 		RF_PANIC();
201 	rf_CommonCreateSimpleDegradedWriteDAG(raidPtr, asmap, dag_h, bp, flags,
202 	    allocList, 1, rf_RecoveryXorFunc, RF_FALSE);
203 }
204 #endif				/* (RF_INCLUDE_DECL_PQ > 0) ||
205 				 * (RF_INCLUDE_RAID6 > 0) */
206