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