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