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