rf_dagdegrd.c revision 1.18 1 /* $NetBSD: rf_dagdegrd.c,v 1.18 2004/01/10 00:56:27 oster Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
5 *
6 * Author: Mark Holland, Daniel Stodolsky, William V. Courtright II
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 (at) 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 /*
30 * rf_dagdegrd.c
31 *
32 * code for creating degraded read DAGs
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: rf_dagdegrd.c,v 1.18 2004/01/10 00:56:27 oster Exp $");
37
38 #include <dev/raidframe/raidframevar.h>
39
40 #include "rf_archs.h"
41 #include "rf_raid.h"
42 #include "rf_dag.h"
43 #include "rf_dagutils.h"
44 #include "rf_dagfuncs.h"
45 #include "rf_debugMem.h"
46 #include "rf_general.h"
47 #include "rf_dagdegrd.h"
48
49
50 /******************************************************************************
51 *
52 * General comments on DAG creation:
53 *
54 * All DAGs in this file use roll-away error recovery. Each DAG has a single
55 * commit node, usually called "Cmt." If an error occurs before the Cmt node
56 * is reached, the execution engine will halt forward execution and work
57 * backward through the graph, executing the undo functions. Assuming that
58 * each node in the graph prior to the Cmt node are undoable and atomic - or -
59 * does not make changes to permanent state, the graph will fail atomically.
60 * If an error occurs after the Cmt node executes, the engine will roll-forward
61 * through the graph, blindly executing nodes until it reaches the end.
62 * If a graph reaches the end, it is assumed to have completed successfully.
63 *
64 * A graph has only 1 Cmt node.
65 *
66 */
67
68
69 /******************************************************************************
70 *
71 * The following wrappers map the standard DAG creation interface to the
72 * DAG creation routines. Additionally, these wrappers enable experimentation
73 * with new DAG structures by providing an extra level of indirection, allowing
74 * the DAG creation routines to be replaced at this single point.
75 */
76
77 void
78 rf_CreateRaidFiveDegradedReadDAG(RF_Raid_t *raidPtr,
79 RF_AccessStripeMap_t *asmap,
80 RF_DagHeader_t *dag_h,
81 void *bp,
82 RF_RaidAccessFlags_t flags,
83 RF_AllocListElem_t *allocList)
84 {
85 rf_CreateDegradedReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList,
86 &rf_xorRecoveryFuncs);
87 }
88
89
90 /******************************************************************************
91 *
92 * DAG creation code begins here
93 */
94
95
96 /******************************************************************************
97 * Create a degraded read DAG for RAID level 1
98 *
99 * Hdr -> Nil -> R(p/s)d -> Commit -> Trm
100 *
101 * The "Rd" node reads data from the surviving disk in the mirror pair
102 * Rpd - read of primary copy
103 * Rsd - read of secondary copy
104 *
105 * Parameters: raidPtr - description of the physical array
106 * asmap - logical & physical addresses for this access
107 * bp - buffer ptr (for holding write data)
108 * flags - general flags (e.g. disk locking)
109 * allocList - list of memory allocated in DAG creation
110 *****************************************************************************/
111
112 void
113 rf_CreateRaidOneDegradedReadDAG(RF_Raid_t *raidPtr,
114 RF_AccessStripeMap_t *asmap,
115 RF_DagHeader_t *dag_h,
116 void *bp,
117 RF_RaidAccessFlags_t flags,
118 RF_AllocListElem_t *allocList)
119 {
120 RF_DagNode_t *nodes, *rdNode, *blockNode, *commitNode, *termNode;
121 RF_StripeNum_t parityStripeID;
122 RF_ReconUnitNum_t which_ru;
123 RF_PhysDiskAddr_t *pda;
124 int useMirror, i;
125
126 useMirror = 0;
127 parityStripeID = rf_RaidAddressToParityStripeID(&(raidPtr->Layout),
128 asmap->raidAddress, &which_ru);
129 if (rf_dagDebug) {
130 printf("[Creating RAID level 1 degraded read DAG]\n");
131 }
132 dag_h->creator = "RaidOneDegradedReadDAG";
133 /* alloc the Wnd nodes and the Wmir node */
134 if (asmap->numDataFailed == 0)
135 useMirror = RF_FALSE;
136 else
137 useMirror = RF_TRUE;
138
139 /* total number of nodes = 1 + (block + commit + terminator) */
140 RF_MallocAndAdd(nodes, 4 * sizeof(RF_DagNode_t), (RF_DagNode_t *), allocList);
141 i = 0;
142 rdNode = &nodes[i];
143 i++;
144 blockNode = &nodes[i];
145 i++;
146 commitNode = &nodes[i];
147 i++;
148 termNode = &nodes[i];
149 i++;
150
151 /* this dag can not commit until the commit node is reached. errors
152 * prior to the commit point imply the dag has failed and must be
153 * retried */
154 dag_h->numCommitNodes = 1;
155 dag_h->numCommits = 0;
156 dag_h->numSuccedents = 1;
157
158 /* initialize the block, commit, and terminator nodes */
159 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
160 NULL, 1, 0, 0, 0, dag_h, "Nil", allocList);
161 rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
162 NULL, 1, 1, 0, 0, dag_h, "Cmt", allocList);
163 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc,
164 NULL, 0, 1, 0, 0, dag_h, "Trm", allocList);
165
166 pda = asmap->physInfo;
167 RF_ASSERT(pda != NULL);
168 /* parityInfo must describe entire parity unit */
169 RF_ASSERT(asmap->parityInfo->next == NULL);
170
171 /* initialize the data node */
172 if (!useMirror) {
173 /* read primary copy of data */
174 rf_InitNode(rdNode, rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc,
175 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Rpd", allocList);
176 rdNode->params[0].p = pda;
177 rdNode->params[1].p = pda->bufPtr;
178 rdNode->params[2].v = parityStripeID;
179 rdNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
180 which_ru);
181 } else {
182 /* read secondary copy of data */
183 rf_InitNode(rdNode, rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc,
184 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Rsd", allocList);
185 rdNode->params[0].p = asmap->parityInfo;
186 rdNode->params[1].p = pda->bufPtr;
187 rdNode->params[2].v = parityStripeID;
188 rdNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
189 which_ru);
190 }
191
192 /* connect header to block node */
193 RF_ASSERT(dag_h->numSuccedents == 1);
194 RF_ASSERT(blockNode->numAntecedents == 0);
195 dag_h->succedents[0] = blockNode;
196
197 /* connect block node to rdnode */
198 RF_ASSERT(blockNode->numSuccedents == 1);
199 RF_ASSERT(rdNode->numAntecedents == 1);
200 blockNode->succedents[0] = rdNode;
201 rdNode->antecedents[0] = blockNode;
202 rdNode->antType[0] = rf_control;
203
204 /* connect rdnode to commit node */
205 RF_ASSERT(rdNode->numSuccedents == 1);
206 RF_ASSERT(commitNode->numAntecedents == 1);
207 rdNode->succedents[0] = commitNode;
208 commitNode->antecedents[0] = rdNode;
209 commitNode->antType[0] = rf_control;
210
211 /* connect commit node to terminator */
212 RF_ASSERT(commitNode->numSuccedents == 1);
213 RF_ASSERT(termNode->numAntecedents == 1);
214 RF_ASSERT(termNode->numSuccedents == 0);
215 commitNode->succedents[0] = termNode;
216 termNode->antecedents[0] = commitNode;
217 termNode->antType[0] = rf_control;
218 }
219
220
221
222 /******************************************************************************
223 *
224 * creates a DAG to perform a degraded-mode read of data within one stripe.
225 * This DAG is as follows:
226 *
227 * Hdr -> Block -> Rud -> Xor -> Cmt -> T
228 * -> Rrd ->
229 * -> Rp -->
230 *
231 * Each R node is a successor of the L node
232 * One successor arc from each R node goes to C, and the other to X
233 * There is one Rud for each chunk of surviving user data requested by the
234 * user, and one Rrd for each chunk of surviving user data _not_ being read by
235 * the user
236 * R = read, ud = user data, rd = recovery (surviving) data, p = parity
237 * X = XOR, C = Commit, T = terminate
238 *
239 * The block node guarantees a single source node.
240 *
241 * Note: The target buffer for the XOR node is set to the actual user buffer
242 * where the failed data is supposed to end up. This buffer is zero'd by the
243 * code here. Thus, if you create a degraded read dag, use it, and then
244 * re-use, you have to be sure to zero the target buffer prior to the re-use.
245 *
246 * The recfunc argument at the end specifies the name and function used for
247 * the redundancy
248 * recovery function.
249 *
250 *****************************************************************************/
251
252 void
253 rf_CreateDegradedReadDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
254 RF_DagHeader_t *dag_h, void *bp,
255 RF_RaidAccessFlags_t flags,
256 RF_AllocListElem_t *allocList,
257 const RF_RedFuncs_t *recFunc)
258 {
259 RF_DagNode_t *nodes, *rudNodes, *rrdNodes, *xorNode, *blockNode;
260 RF_DagNode_t *commitNode, *rpNode, *termNode;
261 int nNodes, nRrdNodes, nRudNodes, nXorBufs, i;
262 int j, paramNum;
263 RF_SectorCount_t sectorsPerSU;
264 RF_ReconUnitNum_t which_ru;
265 char *overlappingPDAs;/* a temporary array of flags */
266 RF_AccessStripeMapHeader_t *new_asm_h[2];
267 RF_PhysDiskAddr_t *pda, *parityPDA;
268 RF_StripeNum_t parityStripeID;
269 RF_PhysDiskAddr_t *failedPDA;
270 RF_RaidLayout_t *layoutPtr;
271 char *rpBuf;
272
273 layoutPtr = &(raidPtr->Layout);
274 /* failedPDA points to the pda within the asm that targets the failed
275 * disk */
276 failedPDA = asmap->failedPDAs[0];
277 parityStripeID = rf_RaidAddressToParityStripeID(layoutPtr,
278 asmap->raidAddress, &which_ru);
279 sectorsPerSU = layoutPtr->sectorsPerStripeUnit;
280
281 if (rf_dagDebug) {
282 printf("[Creating degraded read DAG]\n");
283 }
284 RF_ASSERT(asmap->numDataFailed == 1);
285 dag_h->creator = "DegradedReadDAG";
286
287 /*
288 * generate two ASMs identifying the surviving data we need
289 * in order to recover the lost data
290 */
291
292 /* overlappingPDAs array must be zero'd */
293 RF_Malloc(overlappingPDAs, asmap->numStripeUnitsAccessed * sizeof(char), (char *));
294 rf_GenerateFailedAccessASMs(raidPtr, asmap, failedPDA, dag_h, new_asm_h, &nXorBufs,
295 &rpBuf, overlappingPDAs, allocList);
296
297 /*
298 * create all the nodes at once
299 *
300 * -1 because no access is generated for the failed pda
301 */
302 nRudNodes = asmap->numStripeUnitsAccessed - 1;
303 nRrdNodes = ((new_asm_h[0]) ? new_asm_h[0]->stripeMap->numStripeUnitsAccessed : 0) +
304 ((new_asm_h[1]) ? new_asm_h[1]->stripeMap->numStripeUnitsAccessed : 0);
305 nNodes = 5 + nRudNodes + nRrdNodes; /* lock, unlock, xor, Rp, Rud,
306 * Rrd */
307 RF_MallocAndAdd(nodes, nNodes * sizeof(RF_DagNode_t), (RF_DagNode_t *),
308 allocList);
309 i = 0;
310 blockNode = &nodes[i];
311 i++;
312 commitNode = &nodes[i];
313 i++;
314 xorNode = &nodes[i];
315 i++;
316 rpNode = &nodes[i];
317 i++;
318 termNode = &nodes[i];
319 i++;
320 rudNodes = &nodes[i];
321 i += nRudNodes;
322 rrdNodes = &nodes[i];
323 i += nRrdNodes;
324 RF_ASSERT(i == nNodes);
325
326 /* initialize nodes */
327 dag_h->numCommitNodes = 1;
328 dag_h->numCommits = 0;
329 /* this dag can not commit until the commit node is reached errors
330 * prior to the commit point imply the dag has failed */
331 dag_h->numSuccedents = 1;
332
333 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
334 NULL, nRudNodes + nRrdNodes + 1, 0, 0, 0, dag_h, "Nil", allocList);
335 rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
336 NULL, 1, 1, 0, 0, dag_h, "Cmt", allocList);
337 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc,
338 NULL, 0, 1, 0, 0, dag_h, "Trm", allocList);
339 rf_InitNode(xorNode, rf_wait, RF_FALSE, recFunc->simple, rf_NullNodeUndoFunc,
340 NULL, 1, nRudNodes + nRrdNodes + 1, 2 * nXorBufs + 2, 1, dag_h,
341 recFunc->SimpleName, allocList);
342
343 /* fill in the Rud nodes */
344 for (pda = asmap->physInfo, i = 0; i < nRudNodes; i++, pda = pda->next) {
345 if (pda == failedPDA) {
346 i--;
347 continue;
348 }
349 rf_InitNode(&rudNodes[i], rf_wait, RF_FALSE, rf_DiskReadFunc,
350 rf_DiskReadUndoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h,
351 "Rud", allocList);
352 RF_ASSERT(pda);
353 rudNodes[i].params[0].p = pda;
354 rudNodes[i].params[1].p = pda->bufPtr;
355 rudNodes[i].params[2].v = parityStripeID;
356 rudNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
357 }
358
359 /* fill in the Rrd nodes */
360 i = 0;
361 if (new_asm_h[0]) {
362 for (pda = new_asm_h[0]->stripeMap->physInfo;
363 i < new_asm_h[0]->stripeMap->numStripeUnitsAccessed;
364 i++, pda = pda->next) {
365 rf_InitNode(&rrdNodes[i], rf_wait, RF_FALSE, rf_DiskReadFunc,
366 rf_DiskReadUndoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0,
367 dag_h, "Rrd", allocList);
368 RF_ASSERT(pda);
369 rrdNodes[i].params[0].p = pda;
370 rrdNodes[i].params[1].p = pda->bufPtr;
371 rrdNodes[i].params[2].v = parityStripeID;
372 rrdNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
373 }
374 }
375 if (new_asm_h[1]) {
376 for (j = 0, pda = new_asm_h[1]->stripeMap->physInfo;
377 j < new_asm_h[1]->stripeMap->numStripeUnitsAccessed;
378 j++, pda = pda->next) {
379 rf_InitNode(&rrdNodes[i + j], rf_wait, RF_FALSE, rf_DiskReadFunc,
380 rf_DiskReadUndoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0,
381 dag_h, "Rrd", allocList);
382 RF_ASSERT(pda);
383 rrdNodes[i + j].params[0].p = pda;
384 rrdNodes[i + j].params[1].p = pda->bufPtr;
385 rrdNodes[i + j].params[2].v = parityStripeID;
386 rrdNodes[i + j].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
387 }
388 }
389 /* make a PDA for the parity unit */
390 RF_MallocAndAdd(parityPDA, sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList);
391 parityPDA->col = asmap->parityInfo->col;
392 parityPDA->startSector = ((asmap->parityInfo->startSector / sectorsPerSU)
393 * sectorsPerSU) + (failedPDA->startSector % sectorsPerSU);
394 parityPDA->numSector = failedPDA->numSector;
395
396 /* initialize the Rp node */
397 rf_InitNode(rpNode, rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc,
398 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Rp ", allocList);
399 rpNode->params[0].p = parityPDA;
400 rpNode->params[1].p = rpBuf;
401 rpNode->params[2].v = parityStripeID;
402 rpNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
403
404 /*
405 * the last and nastiest step is to assign all
406 * the parameters of the Xor node
407 */
408 paramNum = 0;
409 for (i = 0; i < nRrdNodes; i++) {
410 /* all the Rrd nodes need to be xored together */
411 xorNode->params[paramNum++] = rrdNodes[i].params[0];
412 xorNode->params[paramNum++] = rrdNodes[i].params[1];
413 }
414 for (i = 0; i < nRudNodes; i++) {
415 /* any Rud nodes that overlap the failed access need to be
416 * xored in */
417 if (overlappingPDAs[i]) {
418 RF_MallocAndAdd(pda, sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList);
419 memcpy((char *) pda, (char *) rudNodes[i].params[0].p, sizeof(RF_PhysDiskAddr_t));
420 rf_RangeRestrictPDA(raidPtr, failedPDA, pda, RF_RESTRICT_DOBUFFER, 0);
421 xorNode->params[paramNum++].p = pda;
422 xorNode->params[paramNum++].p = pda->bufPtr;
423 }
424 }
425 RF_Free(overlappingPDAs, asmap->numStripeUnitsAccessed * sizeof(char));
426
427 /* install parity pda as last set of params to be xor'd */
428 xorNode->params[paramNum++].p = parityPDA;
429 xorNode->params[paramNum++].p = rpBuf;
430
431 /*
432 * the last 2 params to the recovery xor node are
433 * the failed PDA and the raidPtr
434 */
435 xorNode->params[paramNum++].p = failedPDA;
436 xorNode->params[paramNum++].p = raidPtr;
437 RF_ASSERT(paramNum == 2 * nXorBufs + 2);
438
439 /*
440 * The xor node uses results[0] as the target buffer.
441 * Set pointer and zero the buffer. In the kernel, this
442 * may be a user buffer in which case we have to remap it.
443 */
444 xorNode->results[0] = failedPDA->bufPtr;
445 memset(failedPDA->bufPtr, 0, rf_RaidAddressToByte(raidPtr,
446 failedPDA->numSector));
447
448 /* connect nodes to form graph */
449 /* connect the header to the block node */
450 RF_ASSERT(dag_h->numSuccedents == 1);
451 RF_ASSERT(blockNode->numAntecedents == 0);
452 dag_h->succedents[0] = blockNode;
453
454 /* connect the block node to the read nodes */
455 RF_ASSERT(blockNode->numSuccedents == (1 + nRrdNodes + nRudNodes));
456 RF_ASSERT(rpNode->numAntecedents == 1);
457 blockNode->succedents[0] = rpNode;
458 rpNode->antecedents[0] = blockNode;
459 rpNode->antType[0] = rf_control;
460 for (i = 0; i < nRrdNodes; i++) {
461 RF_ASSERT(rrdNodes[i].numSuccedents == 1);
462 blockNode->succedents[1 + i] = &rrdNodes[i];
463 rrdNodes[i].antecedents[0] = blockNode;
464 rrdNodes[i].antType[0] = rf_control;
465 }
466 for (i = 0; i < nRudNodes; i++) {
467 RF_ASSERT(rudNodes[i].numSuccedents == 1);
468 blockNode->succedents[1 + nRrdNodes + i] = &rudNodes[i];
469 rudNodes[i].antecedents[0] = blockNode;
470 rudNodes[i].antType[0] = rf_control;
471 }
472
473 /* connect the read nodes to the xor node */
474 RF_ASSERT(xorNode->numAntecedents == (1 + nRrdNodes + nRudNodes));
475 RF_ASSERT(rpNode->numSuccedents == 1);
476 rpNode->succedents[0] = xorNode;
477 xorNode->antecedents[0] = rpNode;
478 xorNode->antType[0] = rf_trueData;
479 for (i = 0; i < nRrdNodes; i++) {
480 RF_ASSERT(rrdNodes[i].numSuccedents == 1);
481 rrdNodes[i].succedents[0] = xorNode;
482 xorNode->antecedents[1 + i] = &rrdNodes[i];
483 xorNode->antType[1 + i] = rf_trueData;
484 }
485 for (i = 0; i < nRudNodes; i++) {
486 RF_ASSERT(rudNodes[i].numSuccedents == 1);
487 rudNodes[i].succedents[0] = xorNode;
488 xorNode->antecedents[1 + nRrdNodes + i] = &rudNodes[i];
489 xorNode->antType[1 + nRrdNodes + i] = rf_trueData;
490 }
491
492 /* connect the xor node to the commit node */
493 RF_ASSERT(xorNode->numSuccedents == 1);
494 RF_ASSERT(commitNode->numAntecedents == 1);
495 xorNode->succedents[0] = commitNode;
496 commitNode->antecedents[0] = xorNode;
497 commitNode->antType[0] = rf_control;
498
499 /* connect the termNode to the commit node */
500 RF_ASSERT(commitNode->numSuccedents == 1);
501 RF_ASSERT(termNode->numAntecedents == 1);
502 RF_ASSERT(termNode->numSuccedents == 0);
503 commitNode->succedents[0] = termNode;
504 termNode->antType[0] = rf_control;
505 termNode->antecedents[0] = commitNode;
506 }
507
508 #if (RF_INCLUDE_CHAINDECLUSTER > 0)
509 /******************************************************************************
510 * Create a degraded read DAG for Chained Declustering
511 *
512 * Hdr -> Nil -> R(p/s)d -> Cmt -> Trm
513 *
514 * The "Rd" node reads data from the surviving disk in the mirror pair
515 * Rpd - read of primary copy
516 * Rsd - read of secondary copy
517 *
518 * Parameters: raidPtr - description of the physical array
519 * asmap - logical & physical addresses for this access
520 * bp - buffer ptr (for holding write data)
521 * flags - general flags (e.g. disk locking)
522 * allocList - list of memory allocated in DAG creation
523 *****************************************************************************/
524
525 void
526 rf_CreateRaidCDegradedReadDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
527 RF_DagHeader_t *dag_h, void *bp,
528 RF_RaidAccessFlags_t flags,
529 RF_AllocListElem_t *allocList)
530 {
531 RF_DagNode_t *nodes, *rdNode, *blockNode, *commitNode, *termNode;
532 RF_StripeNum_t parityStripeID;
533 int useMirror, i, shiftable;
534 RF_ReconUnitNum_t which_ru;
535 RF_PhysDiskAddr_t *pda;
536
537 if ((asmap->numDataFailed + asmap->numParityFailed) == 0) {
538 shiftable = RF_TRUE;
539 } else {
540 shiftable = RF_FALSE;
541 }
542 useMirror = 0;
543 parityStripeID = rf_RaidAddressToParityStripeID(&(raidPtr->Layout),
544 asmap->raidAddress, &which_ru);
545
546 if (rf_dagDebug) {
547 printf("[Creating RAID C degraded read DAG]\n");
548 }
549 dag_h->creator = "RaidCDegradedReadDAG";
550 /* alloc the Wnd nodes and the Wmir node */
551 if (asmap->numDataFailed == 0)
552 useMirror = RF_FALSE;
553 else
554 useMirror = RF_TRUE;
555
556 /* total number of nodes = 1 + (block + commit + terminator) */
557 RF_MallocAndAdd(nodes, 4 * sizeof(RF_DagNode_t), (RF_DagNode_t *), allocList);
558 i = 0;
559 rdNode = &nodes[i];
560 i++;
561 blockNode = &nodes[i];
562 i++;
563 commitNode = &nodes[i];
564 i++;
565 termNode = &nodes[i];
566 i++;
567
568 /*
569 * This dag can not commit until the commit node is reached.
570 * Errors prior to the commit point imply the dag has failed
571 * and must be retried.
572 */
573 dag_h->numCommitNodes = 1;
574 dag_h->numCommits = 0;
575 dag_h->numSuccedents = 1;
576
577 /* initialize the block, commit, and terminator nodes */
578 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
579 NULL, 1, 0, 0, 0, dag_h, "Nil", allocList);
580 rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
581 NULL, 1, 1, 0, 0, dag_h, "Cmt", allocList);
582 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc,
583 NULL, 0, 1, 0, 0, dag_h, "Trm", allocList);
584
585 pda = asmap->physInfo;
586 RF_ASSERT(pda != NULL);
587 /* parityInfo must describe entire parity unit */
588 RF_ASSERT(asmap->parityInfo->next == NULL);
589
590 /* initialize the data node */
591 if (!useMirror) {
592 rf_InitNode(rdNode, rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc,
593 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Rpd", allocList);
594 if (shiftable && rf_compute_workload_shift(raidPtr, pda)) {
595 /* shift this read to the next disk in line */
596 rdNode->params[0].p = asmap->parityInfo;
597 rdNode->params[1].p = pda->bufPtr;
598 rdNode->params[2].v = parityStripeID;
599 rdNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
600 } else {
601 /* read primary copy */
602 rdNode->params[0].p = pda;
603 rdNode->params[1].p = pda->bufPtr;
604 rdNode->params[2].v = parityStripeID;
605 rdNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
606 }
607 } else {
608 /* read secondary copy of data */
609 rf_InitNode(rdNode, rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc,
610 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Rsd", allocList);
611 rdNode->params[0].p = asmap->parityInfo;
612 rdNode->params[1].p = pda->bufPtr;
613 rdNode->params[2].v = parityStripeID;
614 rdNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
615 }
616
617 /* connect header to block node */
618 RF_ASSERT(dag_h->numSuccedents == 1);
619 RF_ASSERT(blockNode->numAntecedents == 0);
620 dag_h->succedents[0] = blockNode;
621
622 /* connect block node to rdnode */
623 RF_ASSERT(blockNode->numSuccedents == 1);
624 RF_ASSERT(rdNode->numAntecedents == 1);
625 blockNode->succedents[0] = rdNode;
626 rdNode->antecedents[0] = blockNode;
627 rdNode->antType[0] = rf_control;
628
629 /* connect rdnode to commit node */
630 RF_ASSERT(rdNode->numSuccedents == 1);
631 RF_ASSERT(commitNode->numAntecedents == 1);
632 rdNode->succedents[0] = commitNode;
633 commitNode->antecedents[0] = rdNode;
634 commitNode->antType[0] = rf_control;
635
636 /* connect commit node to terminator */
637 RF_ASSERT(commitNode->numSuccedents == 1);
638 RF_ASSERT(termNode->numAntecedents == 1);
639 RF_ASSERT(termNode->numSuccedents == 0);
640 commitNode->succedents[0] = termNode;
641 termNode->antecedents[0] = commitNode;
642 termNode->antType[0] = rf_control;
643 }
644 #endif /* (RF_INCLUDE_CHAINDECLUSTER > 0) */
645
646 #if (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0) || (RF_INCLUDE_EVENODD > 0)
647 /*
648 * XXX move this elsewhere?
649 */
650 void
651 rf_DD_GenerateFailedAccessASMs(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
652 RF_PhysDiskAddr_t **pdap, int *nNodep,
653 RF_PhysDiskAddr_t **pqpdap, int *nPQNodep,
654 RF_AllocListElem_t *allocList)
655 {
656 RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
657 int PDAPerDisk, i;
658 RF_SectorCount_t secPerSU = layoutPtr->sectorsPerStripeUnit;
659 int numDataCol = layoutPtr->numDataCol;
660 int state;
661 RF_SectorNum_t suoff, suend;
662 unsigned firstDataCol, napdas, count;
663 RF_SectorNum_t fone_start, fone_end, ftwo_start = 0, ftwo_end = 0;
664 RF_PhysDiskAddr_t *fone = asmap->failedPDAs[0], *ftwo = asmap->failedPDAs[1];
665 RF_PhysDiskAddr_t *pda_p;
666 RF_PhysDiskAddr_t *phys_p;
667 RF_RaidAddr_t sosAddr;
668
669 /* determine how many pda's we will have to generate per unaccess
670 * stripe. If there is only one failed data unit, it is one; if two,
671 * possibly two, depending wether they overlap. */
672
673 fone_start = rf_StripeUnitOffset(layoutPtr, fone->startSector);
674 fone_end = fone_start + fone->numSector;
675
676 #define CONS_PDA(if,start,num) \
677 pda_p->col = asmap->if->col; \
678 pda_p->startSector = ((asmap->if->startSector / secPerSU) * secPerSU) + start; \
679 pda_p->numSector = num; \
680 pda_p->next = NULL; \
681 RF_MallocAndAdd(pda_p->bufPtr,rf_RaidAddressToByte(raidPtr,num),(char *), allocList)
682
683 if (asmap->numDataFailed == 1) {
684 PDAPerDisk = 1;
685 state = 1;
686 RF_MallocAndAdd(*pqpdap, 2 * sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList);
687 pda_p = *pqpdap;
688 /* build p */
689 CONS_PDA(parityInfo, fone_start, fone->numSector);
690 pda_p->type = RF_PDA_TYPE_PARITY;
691 pda_p++;
692 /* build q */
693 CONS_PDA(qInfo, fone_start, fone->numSector);
694 pda_p->type = RF_PDA_TYPE_Q;
695 } else {
696 ftwo_start = rf_StripeUnitOffset(layoutPtr, ftwo->startSector);
697 ftwo_end = ftwo_start + ftwo->numSector;
698 if (fone->numSector + ftwo->numSector > secPerSU) {
699 PDAPerDisk = 1;
700 state = 2;
701 RF_MallocAndAdd(*pqpdap, 2 * sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList);
702 pda_p = *pqpdap;
703 CONS_PDA(parityInfo, 0, secPerSU);
704 pda_p->type = RF_PDA_TYPE_PARITY;
705 pda_p++;
706 CONS_PDA(qInfo, 0, secPerSU);
707 pda_p->type = RF_PDA_TYPE_Q;
708 } else {
709 PDAPerDisk = 2;
710 state = 3;
711 /* four of them, fone, then ftwo */
712 RF_MallocAndAdd(*pqpdap, 4 * sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList);
713 pda_p = *pqpdap;
714 CONS_PDA(parityInfo, fone_start, fone->numSector);
715 pda_p->type = RF_PDA_TYPE_PARITY;
716 pda_p++;
717 CONS_PDA(qInfo, fone_start, fone->numSector);
718 pda_p->type = RF_PDA_TYPE_Q;
719 pda_p++;
720 CONS_PDA(parityInfo, ftwo_start, ftwo->numSector);
721 pda_p->type = RF_PDA_TYPE_PARITY;
722 pda_p++;
723 CONS_PDA(qInfo, ftwo_start, ftwo->numSector);
724 pda_p->type = RF_PDA_TYPE_Q;
725 }
726 }
727 /* figure out number of nonaccessed pda */
728 napdas = PDAPerDisk * (numDataCol - asmap->numStripeUnitsAccessed - (ftwo == NULL ? 1 : 0));
729 *nPQNodep = PDAPerDisk;
730
731 /* sweep over the over accessed pda's, figuring out the number of
732 * additional pda's to generate. Of course, skip the failed ones */
733
734 count = 0;
735 for (pda_p = asmap->physInfo; pda_p; pda_p = pda_p->next) {
736 if ((pda_p == fone) || (pda_p == ftwo))
737 continue;
738 suoff = rf_StripeUnitOffset(layoutPtr, pda_p->startSector);
739 suend = suoff + pda_p->numSector;
740 switch (state) {
741 case 1: /* one failed PDA to overlap */
742 /* if a PDA doesn't contain the failed unit, it can
743 * only miss the start or end, not both */
744 if ((suoff > fone_start) || (suend < fone_end))
745 count++;
746 break;
747 case 2: /* whole stripe */
748 if (suoff) /* leak at begining */
749 count++;
750 if (suend < numDataCol) /* leak at end */
751 count++;
752 break;
753 case 3: /* two disjoint units */
754 if ((suoff > fone_start) || (suend < fone_end))
755 count++;
756 if ((suoff > ftwo_start) || (suend < ftwo_end))
757 count++;
758 break;
759 default:
760 RF_PANIC();
761 }
762 }
763
764 napdas += count;
765 *nNodep = napdas;
766 if (napdas == 0)
767 return; /* short circuit */
768
769 /* allocate up our list of pda's */
770
771 RF_MallocAndAdd(pda_p, napdas * sizeof(RF_PhysDiskAddr_t),
772 (RF_PhysDiskAddr_t *), allocList);
773 *pdap = pda_p;
774
775 /* linkem together */
776 for (i = 0; i < (napdas - 1); i++)
777 pda_p[i].next = pda_p + (i + 1);
778
779 /* march through the one's up to the first accessed disk */
780 firstDataCol = rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), asmap->physInfo->raidAddress) % numDataCol;
781 sosAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, asmap->raidAddress);
782 for (i = 0; i < firstDataCol; i++) {
783 if ((pda_p - (*pdap)) == napdas)
784 continue;
785 pda_p->type = RF_PDA_TYPE_DATA;
786 pda_p->raidAddress = sosAddr + (i * secPerSU);
787 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
788 /* skip over dead disks */
789 if (RF_DEAD_DISK(raidPtr->Disks[pda_p->col].status))
790 continue;
791 switch (state) {
792 case 1: /* fone */
793 pda_p->numSector = fone->numSector;
794 pda_p->raidAddress += fone_start;
795 pda_p->startSector += fone_start;
796 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
797 break;
798 case 2: /* full stripe */
799 pda_p->numSector = secPerSU;
800 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, secPerSU), (char *), allocList);
801 break;
802 case 3: /* two slabs */
803 pda_p->numSector = fone->numSector;
804 pda_p->raidAddress += fone_start;
805 pda_p->startSector += fone_start;
806 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
807 pda_p++;
808 pda_p->type = RF_PDA_TYPE_DATA;
809 pda_p->raidAddress = sosAddr + (i * secPerSU);
810 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
811 pda_p->numSector = ftwo->numSector;
812 pda_p->raidAddress += ftwo_start;
813 pda_p->startSector += ftwo_start;
814 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
815 break;
816 default:
817 RF_PANIC();
818 }
819 pda_p++;
820 }
821
822 /* march through the touched stripe units */
823 for (phys_p = asmap->physInfo; phys_p; phys_p = phys_p->next, i++) {
824 if ((phys_p == asmap->failedPDAs[0]) || (phys_p == asmap->failedPDAs[1]))
825 continue;
826 suoff = rf_StripeUnitOffset(layoutPtr, phys_p->startSector);
827 suend = suoff + phys_p->numSector;
828 switch (state) {
829 case 1: /* single buffer */
830 if (suoff > fone_start) {
831 RF_ASSERT(suend >= fone_end);
832 /* The data read starts after the mapped
833 * access, snip off the begining */
834 pda_p->numSector = suoff - fone_start;
835 pda_p->raidAddress = sosAddr + (i * secPerSU) + fone_start;
836 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
837 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
838 pda_p++;
839 }
840 if (suend < fone_end) {
841 RF_ASSERT(suoff <= fone_start);
842 /* The data read stops before the end of the
843 * failed access, extend */
844 pda_p->numSector = fone_end - suend;
845 pda_p->raidAddress = sosAddr + (i * secPerSU) + suend; /* off by one? */
846 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
847 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
848 pda_p++;
849 }
850 break;
851 case 2: /* whole stripe unit */
852 RF_ASSERT((suoff == 0) || (suend == secPerSU));
853 if (suend < secPerSU) { /* short read, snip from end
854 * on */
855 pda_p->numSector = secPerSU - suend;
856 pda_p->raidAddress = sosAddr + (i * secPerSU) + suend; /* off by one? */
857 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
858 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
859 pda_p++;
860 } else
861 if (suoff > 0) { /* short at front */
862 pda_p->numSector = suoff;
863 pda_p->raidAddress = sosAddr + (i * secPerSU);
864 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
865 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
866 pda_p++;
867 }
868 break;
869 case 3: /* two nonoverlapping failures */
870 if ((suoff > fone_start) || (suend < fone_end)) {
871 if (suoff > fone_start) {
872 RF_ASSERT(suend >= fone_end);
873 /* The data read starts after the
874 * mapped access, snip off the
875 * begining */
876 pda_p->numSector = suoff - fone_start;
877 pda_p->raidAddress = sosAddr + (i * secPerSU) + fone_start;
878 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
879 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
880 pda_p++;
881 }
882 if (suend < fone_end) {
883 RF_ASSERT(suoff <= fone_start);
884 /* The data read stops before the end
885 * of the failed access, extend */
886 pda_p->numSector = fone_end - suend;
887 pda_p->raidAddress = sosAddr + (i * secPerSU) + suend; /* off by one? */
888 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
889 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
890 pda_p++;
891 }
892 }
893 if ((suoff > ftwo_start) || (suend < ftwo_end)) {
894 if (suoff > ftwo_start) {
895 RF_ASSERT(suend >= ftwo_end);
896 /* The data read starts after the
897 * mapped access, snip off the
898 * begining */
899 pda_p->numSector = suoff - ftwo_start;
900 pda_p->raidAddress = sosAddr + (i * secPerSU) + ftwo_start;
901 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
902 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
903 pda_p++;
904 }
905 if (suend < ftwo_end) {
906 RF_ASSERT(suoff <= ftwo_start);
907 /* The data read stops before the end
908 * of the failed access, extend */
909 pda_p->numSector = ftwo_end - suend;
910 pda_p->raidAddress = sosAddr + (i * secPerSU) + suend; /* off by one? */
911 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
912 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
913 pda_p++;
914 }
915 }
916 break;
917 default:
918 RF_PANIC();
919 }
920 }
921
922 /* after the last accessed disk */
923 for (; i < numDataCol; i++) {
924 if ((pda_p - (*pdap)) == napdas)
925 continue;
926 pda_p->type = RF_PDA_TYPE_DATA;
927 pda_p->raidAddress = sosAddr + (i * secPerSU);
928 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
929 /* skip over dead disks */
930 if (RF_DEAD_DISK(raidPtr->Disks[pda_p->col].status))
931 continue;
932 switch (state) {
933 case 1: /* fone */
934 pda_p->numSector = fone->numSector;
935 pda_p->raidAddress += fone_start;
936 pda_p->startSector += fone_start;
937 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
938 break;
939 case 2: /* full stripe */
940 pda_p->numSector = secPerSU;
941 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, secPerSU), (char *), allocList);
942 break;
943 case 3: /* two slabs */
944 pda_p->numSector = fone->numSector;
945 pda_p->raidAddress += fone_start;
946 pda_p->startSector += fone_start;
947 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
948 pda_p++;
949 pda_p->type = RF_PDA_TYPE_DATA;
950 pda_p->raidAddress = sosAddr + (i * secPerSU);
951 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
952 pda_p->numSector = ftwo->numSector;
953 pda_p->raidAddress += ftwo_start;
954 pda_p->startSector += ftwo_start;
955 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
956 break;
957 default:
958 RF_PANIC();
959 }
960 pda_p++;
961 }
962
963 RF_ASSERT(pda_p - *pdap == napdas);
964 return;
965 }
966 #define INIT_DISK_NODE(node,name) \
967 rf_InitNode(node, rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc, rf_GenericWakeupFunc, 2,1,4,0, dag_h, name, allocList); \
968 (node)->succedents[0] = unblockNode; \
969 (node)->succedents[1] = recoveryNode; \
970 (node)->antecedents[0] = blockNode; \
971 (node)->antType[0] = rf_control
972
973 #define DISK_NODE_PARAMS(_node_,_p_) \
974 (_node_).params[0].p = _p_ ; \
975 (_node_).params[1].p = (_p_)->bufPtr; \
976 (_node_).params[2].v = parityStripeID; \
977 (_node_).params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru)
978
979 void
980 rf_DoubleDegRead(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
981 RF_DagHeader_t *dag_h, void *bp, RF_RaidAccessFlags_t flags,
982 RF_AllocListElem_t *allocList,
983 char *redundantReadNodeName, char *recoveryNodeName,
984 int (*recovFunc) (RF_DagNode_t *))
985 {
986 RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
987 RF_DagNode_t *nodes, *rudNodes, *rrdNodes, *recoveryNode, *blockNode,
988 *unblockNode, *rpNodes, *rqNodes, *termNode;
989 RF_PhysDiskAddr_t *pda, *pqPDAs;
990 RF_PhysDiskAddr_t *npdas;
991 int nNodes, nRrdNodes, nRudNodes, i;
992 RF_ReconUnitNum_t which_ru;
993 int nReadNodes, nPQNodes;
994 RF_PhysDiskAddr_t *failedPDA = asmap->failedPDAs[0];
995 RF_PhysDiskAddr_t *failedPDAtwo = asmap->failedPDAs[1];
996 RF_StripeNum_t parityStripeID = rf_RaidAddressToParityStripeID(layoutPtr, asmap->raidAddress, &which_ru);
997
998 if (rf_dagDebug)
999 printf("[Creating Double Degraded Read DAG]\n");
1000 rf_DD_GenerateFailedAccessASMs(raidPtr, asmap, &npdas, &nRrdNodes, &pqPDAs, &nPQNodes, allocList);
1001
1002 nRudNodes = asmap->numStripeUnitsAccessed - (asmap->numDataFailed);
1003 nReadNodes = nRrdNodes + nRudNodes + 2 * nPQNodes;
1004 nNodes = 4 /* block, unblock, recovery, term */ + nReadNodes;
1005
1006 RF_MallocAndAdd(nodes, nNodes * sizeof(RF_DagNode_t), (RF_DagNode_t *), allocList);
1007 i = 0;
1008 blockNode = &nodes[i];
1009 i += 1;
1010 unblockNode = &nodes[i];
1011 i += 1;
1012 recoveryNode = &nodes[i];
1013 i += 1;
1014 termNode = &nodes[i];
1015 i += 1;
1016 rudNodes = &nodes[i];
1017 i += nRudNodes;
1018 rrdNodes = &nodes[i];
1019 i += nRrdNodes;
1020 rpNodes = &nodes[i];
1021 i += nPQNodes;
1022 rqNodes = &nodes[i];
1023 i += nPQNodes;
1024 RF_ASSERT(i == nNodes);
1025
1026 dag_h->numSuccedents = 1;
1027 dag_h->succedents[0] = blockNode;
1028 dag_h->creator = "DoubleDegRead";
1029 dag_h->numCommits = 0;
1030 dag_h->numCommitNodes = 1; /* unblock */
1031
1032 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc, NULL, 0, 2, 0, 0, dag_h, "Trm", allocList);
1033 termNode->antecedents[0] = unblockNode;
1034 termNode->antType[0] = rf_control;
1035 termNode->antecedents[1] = recoveryNode;
1036 termNode->antType[1] = rf_control;
1037
1038 /* init the block and unblock nodes */
1039 /* The block node has all nodes except itself, unblock and recovery as
1040 * successors. Similarly for predecessors of the unblock. */
1041 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, nReadNodes, 0, 0, 0, dag_h, "Nil", allocList);
1042 rf_InitNode(unblockNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, 1, nReadNodes, 0, 0, dag_h, "Nil", allocList);
1043
1044 for (i = 0; i < nReadNodes; i++) {
1045 blockNode->succedents[i] = rudNodes + i;
1046 unblockNode->antecedents[i] = rudNodes + i;
1047 unblockNode->antType[i] = rf_control;
1048 }
1049 unblockNode->succedents[0] = termNode;
1050
1051 /* The recovery node has all the reads as predecessors, and the term
1052 * node as successors. It gets a pda as a param from each of the read
1053 * nodes plus the raidPtr. For each failed unit is has a result pda. */
1054 rf_InitNode(recoveryNode, rf_wait, RF_FALSE, recovFunc, rf_NullNodeUndoFunc, NULL,
1055 1, /* succesors */
1056 nReadNodes, /* preds */
1057 nReadNodes + 2, /* params */
1058 asmap->numDataFailed, /* results */
1059 dag_h, recoveryNodeName, allocList);
1060
1061 recoveryNode->succedents[0] = termNode;
1062 for (i = 0; i < nReadNodes; i++) {
1063 recoveryNode->antecedents[i] = rudNodes + i;
1064 recoveryNode->antType[i] = rf_trueData;
1065 }
1066
1067 /* build the read nodes, then come back and fill in recovery params
1068 * and results */
1069 pda = asmap->physInfo;
1070 for (i = 0; i < nRudNodes; pda = pda->next) {
1071 if ((pda == failedPDA) || (pda == failedPDAtwo))
1072 continue;
1073 INIT_DISK_NODE(rudNodes + i, "Rud");
1074 RF_ASSERT(pda);
1075 DISK_NODE_PARAMS(rudNodes[i], pda);
1076 i++;
1077 }
1078
1079 pda = npdas;
1080 for (i = 0; i < nRrdNodes; i++, pda = pda->next) {
1081 INIT_DISK_NODE(rrdNodes + i, "Rrd");
1082 RF_ASSERT(pda);
1083 DISK_NODE_PARAMS(rrdNodes[i], pda);
1084 }
1085
1086 /* redundancy pdas */
1087 pda = pqPDAs;
1088 INIT_DISK_NODE(rpNodes, "Rp");
1089 RF_ASSERT(pda);
1090 DISK_NODE_PARAMS(rpNodes[0], pda);
1091 pda++;
1092 INIT_DISK_NODE(rqNodes, redundantReadNodeName);
1093 RF_ASSERT(pda);
1094 DISK_NODE_PARAMS(rqNodes[0], pda);
1095 if (nPQNodes == 2) {
1096 pda++;
1097 INIT_DISK_NODE(rpNodes + 1, "Rp");
1098 RF_ASSERT(pda);
1099 DISK_NODE_PARAMS(rpNodes[1], pda);
1100 pda++;
1101 INIT_DISK_NODE(rqNodes + 1, redundantReadNodeName);
1102 RF_ASSERT(pda);
1103 DISK_NODE_PARAMS(rqNodes[1], pda);
1104 }
1105 /* fill in recovery node params */
1106 for (i = 0; i < nReadNodes; i++)
1107 recoveryNode->params[i] = rudNodes[i].params[0]; /* pda */
1108 recoveryNode->params[i++].p = (void *) raidPtr;
1109 recoveryNode->params[i++].p = (void *) asmap;
1110 recoveryNode->results[0] = failedPDA;
1111 if (asmap->numDataFailed == 2)
1112 recoveryNode->results[1] = failedPDAtwo;
1113
1114 /* zero fill the target data buffers? */
1115 }
1116
1117 #endif /* (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0) || (RF_INCLUDE_EVENODD > 0) */
1118