Home | History | Annotate | Line # | Download | only in raidframe
rf_parityloggingdags.c revision 1.6
      1 /*	$NetBSD: rf_parityloggingdags.c,v 1.6 2001/10/04 15:58:55 oster Exp $	*/
      2 /*
      3  * Copyright (c) 1995 Carnegie-Mellon University.
      4  * All rights reserved.
      5  *
      6  * Author: 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 #include "rf_archs.h"
     30 
     31 #if RF_INCLUDE_PARITYLOGGING > 0
     32 
     33 /*
     34   DAGs specific to parity logging are created here
     35  */
     36 
     37 #include <dev/raidframe/raidframevar.h>
     38 
     39 #include "rf_raid.h"
     40 #include "rf_dag.h"
     41 #include "rf_dagutils.h"
     42 #include "rf_dagfuncs.h"
     43 #include "rf_debugMem.h"
     44 #include "rf_paritylog.h"
     45 #include "rf_memchunk.h"
     46 #include "rf_general.h"
     47 
     48 #include "rf_parityloggingdags.h"
     49 
     50 /******************************************************************************
     51  *
     52  * creates a DAG to perform a large-write operation:
     53  *
     54  *         / Rod \     / Wnd \
     55  * H -- NIL- Rod - NIL - Wnd ------ NIL - T
     56  *         \ Rod /     \ Xor - Lpo /
     57  *
     58  * The writes are not done until the reads complete because if they were done in
     59  * parallel, a failure on one of the reads could leave the parity in an inconsistent
     60  * state, so that the retry with a new DAG would produce erroneous parity.
     61  *
     62  * Note:  this DAG has the nasty property that none of the buffers allocated for reading
     63  *        old data can be freed until the XOR node fires.  Need to fix this.
     64  *
     65  * The last two arguments are the number of faults tolerated, and function for the
     66  * redundancy calculation. The undo for the redundancy calc is assumed to be null
     67  *
     68  *****************************************************************************/
     69 
     70 void
     71 rf_CommonCreateParityLoggingLargeWriteDAG(
     72     RF_Raid_t * raidPtr,
     73     RF_AccessStripeMap_t * asmap,
     74     RF_DagHeader_t * dag_h,
     75     void *bp,
     76     RF_RaidAccessFlags_t flags,
     77     RF_AllocListElem_t * allocList,
     78     int nfaults,
     79     int (*redFunc) (RF_DagNode_t *))
     80 {
     81 	RF_DagNode_t *nodes, *wndNodes, *rodNodes = NULL, *syncNode, *xorNode,
     82 	       *lpoNode, *blockNode, *unblockNode, *termNode;
     83 	int     nWndNodes, nRodNodes, i;
     84 	RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
     85 	RF_AccessStripeMapHeader_t *new_asm_h[2];
     86 	int     nodeNum, asmNum;
     87 	RF_ReconUnitNum_t which_ru;
     88 	char   *sosBuffer, *eosBuffer;
     89 	RF_PhysDiskAddr_t *pda;
     90 	RF_StripeNum_t parityStripeID = rf_RaidAddressToParityStripeID(&(raidPtr->Layout), asmap->raidAddress, &which_ru);
     91 
     92 	if (rf_dagDebug)
     93 		printf("[Creating parity-logging large-write DAG]\n");
     94 	RF_ASSERT(nfaults == 1);/* this arch only single fault tolerant */
     95 	dag_h->creator = "ParityLoggingLargeWriteDAG";
     96 
     97 	/* alloc the Wnd nodes, the xor node, and the Lpo node */
     98 	nWndNodes = asmap->numStripeUnitsAccessed;
     99 	RF_CallocAndAdd(nodes, nWndNodes + 6, sizeof(RF_DagNode_t), (RF_DagNode_t *), allocList);
    100 	i = 0;
    101 	wndNodes = &nodes[i];
    102 	i += nWndNodes;
    103 	xorNode = &nodes[i];
    104 	i += 1;
    105 	lpoNode = &nodes[i];
    106 	i += 1;
    107 	blockNode = &nodes[i];
    108 	i += 1;
    109 	syncNode = &nodes[i];
    110 	i += 1;
    111 	unblockNode = &nodes[i];
    112 	i += 1;
    113 	termNode = &nodes[i];
    114 	i += 1;
    115 
    116 	dag_h->numCommitNodes = nWndNodes + 1;
    117 	dag_h->numCommits = 0;
    118 	dag_h->numSuccedents = 1;
    119 
    120 	rf_MapUnaccessedPortionOfStripe(raidPtr, layoutPtr, asmap, dag_h, new_asm_h, &nRodNodes, &sosBuffer, &eosBuffer, allocList);
    121 	if (nRodNodes > 0)
    122 		RF_CallocAndAdd(rodNodes, nRodNodes, sizeof(RF_DagNode_t), (RF_DagNode_t *), allocList);
    123 
    124 	/* begin node initialization */
    125 	rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, nRodNodes + 1, 0, 0, 0, dag_h, "Nil", allocList);
    126 	rf_InitNode(unblockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, 1, nWndNodes + 1, 0, 0, dag_h, "Nil", allocList);
    127 	rf_InitNode(syncNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, nWndNodes + 1, nRodNodes + 1, 0, 0, dag_h, "Nil", allocList);
    128 	rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc, NULL, 0, 1, 0, 0, dag_h, "Trm", allocList);
    129 
    130 	/* initialize the Rod nodes */
    131 	for (nodeNum = asmNum = 0; asmNum < 2; asmNum++) {
    132 		if (new_asm_h[asmNum]) {
    133 			pda = new_asm_h[asmNum]->stripeMap->physInfo;
    134 			while (pda) {
    135 				rf_InitNode(&rodNodes[nodeNum], rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Rod", allocList);
    136 				rodNodes[nodeNum].params[0].p = pda;
    137 				rodNodes[nodeNum].params[1].p = pda->bufPtr;
    138 				rodNodes[nodeNum].params[2].v = parityStripeID;
    139 				rodNodes[nodeNum].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    140 				nodeNum++;
    141 				pda = pda->next;
    142 			}
    143 		}
    144 	}
    145 	RF_ASSERT(nodeNum == nRodNodes);
    146 
    147 	/* initialize the wnd nodes */
    148 	pda = asmap->physInfo;
    149 	for (i = 0; i < nWndNodes; i++) {
    150 		rf_InitNode(&wndNodes[i], rf_wait, RF_TRUE, rf_DiskWriteFunc, rf_DiskWriteUndoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Wnd", allocList);
    151 		RF_ASSERT(pda != NULL);
    152 		wndNodes[i].params[0].p = pda;
    153 		wndNodes[i].params[1].p = pda->bufPtr;
    154 		wndNodes[i].params[2].v = parityStripeID;
    155 		wndNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    156 		pda = pda->next;
    157 	}
    158 
    159 	/* initialize the redundancy node */
    160 	rf_InitNode(xorNode, rf_wait, RF_TRUE, redFunc, rf_NullNodeUndoFunc, NULL, 1, 1, 2 * (nWndNodes + nRodNodes) + 1, 1, dag_h, "Xr ", allocList);
    161 	xorNode->flags |= RF_DAGNODE_FLAG_YIELD;
    162 	for (i = 0; i < nWndNodes; i++) {
    163 		xorNode->params[2 * i + 0] = wndNodes[i].params[0];	/* pda */
    164 		xorNode->params[2 * i + 1] = wndNodes[i].params[1];	/* buf ptr */
    165 	}
    166 	for (i = 0; i < nRodNodes; i++) {
    167 		xorNode->params[2 * (nWndNodes + i) + 0] = rodNodes[i].params[0];	/* pda */
    168 		xorNode->params[2 * (nWndNodes + i) + 1] = rodNodes[i].params[1];	/* buf ptr */
    169 	}
    170 	xorNode->params[2 * (nWndNodes + nRodNodes)].p = raidPtr;	/* xor node needs to get
    171 									 * at RAID information */
    172 
    173 	/* look for an Rod node that reads a complete SU.  If none, alloc a
    174 	 * buffer to receive the parity info. Note that we can't use a new
    175 	 * data buffer because it will not have gotten written when the xor
    176 	 * occurs. */
    177 	for (i = 0; i < nRodNodes; i++)
    178 		if (((RF_PhysDiskAddr_t *) rodNodes[i].params[0].p)->numSector == raidPtr->Layout.sectorsPerStripeUnit)
    179 			break;
    180 	if (i == nRodNodes) {
    181 		RF_CallocAndAdd(xorNode->results[0], 1, rf_RaidAddressToByte(raidPtr, raidPtr->Layout.sectorsPerStripeUnit), (void *), allocList);
    182 	} else {
    183 		xorNode->results[0] = rodNodes[i].params[1].p;
    184 	}
    185 
    186 	/* initialize the Lpo node */
    187 	rf_InitNode(lpoNode, rf_wait, RF_FALSE, rf_ParityLogOverwriteFunc, rf_ParityLogOverwriteUndoFunc, rf_GenericWakeupFunc, 1, 1, 2, 0, dag_h, "Lpo", allocList);
    188 
    189 	lpoNode->params[0].p = asmap->parityInfo;
    190 	lpoNode->params[1].p = xorNode->results[0];
    191 	RF_ASSERT(asmap->parityInfo->next == NULL);	/* parityInfo must
    192 							 * describe entire
    193 							 * parity unit */
    194 
    195 	/* connect nodes to form graph */
    196 
    197 	/* connect dag header to block node */
    198 	RF_ASSERT(dag_h->numSuccedents == 1);
    199 	RF_ASSERT(blockNode->numAntecedents == 0);
    200 	dag_h->succedents[0] = blockNode;
    201 
    202 	/* connect the block node to the Rod nodes */
    203 	RF_ASSERT(blockNode->numSuccedents == nRodNodes + 1);
    204 	for (i = 0; i < nRodNodes; i++) {
    205 		RF_ASSERT(rodNodes[i].numAntecedents == 1);
    206 		blockNode->succedents[i] = &rodNodes[i];
    207 		rodNodes[i].antecedents[0] = blockNode;
    208 		rodNodes[i].antType[0] = rf_control;
    209 	}
    210 
    211 	/* connect the block node to the sync node */
    212 	/* necessary if nRodNodes == 0 */
    213 	RF_ASSERT(syncNode->numAntecedents == nRodNodes + 1);
    214 	blockNode->succedents[nRodNodes] = syncNode;
    215 	syncNode->antecedents[0] = blockNode;
    216 	syncNode->antType[0] = rf_control;
    217 
    218 	/* connect the Rod nodes to the syncNode */
    219 	for (i = 0; i < nRodNodes; i++) {
    220 		rodNodes[i].succedents[0] = syncNode;
    221 		syncNode->antecedents[1 + i] = &rodNodes[i];
    222 		syncNode->antType[1 + i] = rf_control;
    223 	}
    224 
    225 	/* connect the sync node to the xor node */
    226 	RF_ASSERT(syncNode->numSuccedents == nWndNodes + 1);
    227 	RF_ASSERT(xorNode->numAntecedents == 1);
    228 	syncNode->succedents[0] = xorNode;
    229 	xorNode->antecedents[0] = syncNode;
    230 	xorNode->antType[0] = rf_trueData;	/* carry forward from sync */
    231 
    232 	/* connect the sync node to the Wnd nodes */
    233 	for (i = 0; i < nWndNodes; i++) {
    234 		RF_ASSERT(wndNodes->numAntecedents == 1);
    235 		syncNode->succedents[1 + i] = &wndNodes[i];
    236 		wndNodes[i].antecedents[0] = syncNode;
    237 		wndNodes[i].antType[0] = rf_control;
    238 	}
    239 
    240 	/* connect the xor node to the Lpo node */
    241 	RF_ASSERT(xorNode->numSuccedents == 1);
    242 	RF_ASSERT(lpoNode->numAntecedents == 1);
    243 	xorNode->succedents[0] = lpoNode;
    244 	lpoNode->antecedents[0] = xorNode;
    245 	lpoNode->antType[0] = rf_trueData;
    246 
    247 	/* connect the Wnd nodes to the unblock node */
    248 	RF_ASSERT(unblockNode->numAntecedents == nWndNodes + 1);
    249 	for (i = 0; i < nWndNodes; i++) {
    250 		RF_ASSERT(wndNodes->numSuccedents == 1);
    251 		wndNodes[i].succedents[0] = unblockNode;
    252 		unblockNode->antecedents[i] = &wndNodes[i];
    253 		unblockNode->antType[i] = rf_control;
    254 	}
    255 
    256 	/* connect the Lpo node to the unblock node */
    257 	RF_ASSERT(lpoNode->numSuccedents == 1);
    258 	lpoNode->succedents[0] = unblockNode;
    259 	unblockNode->antecedents[nWndNodes] = lpoNode;
    260 	unblockNode->antType[nWndNodes] = rf_control;
    261 
    262 	/* connect unblock node to terminator */
    263 	RF_ASSERT(unblockNode->numSuccedents == 1);
    264 	RF_ASSERT(termNode->numAntecedents == 1);
    265 	RF_ASSERT(termNode->numSuccedents == 0);
    266 	unblockNode->succedents[0] = termNode;
    267 	termNode->antecedents[0] = unblockNode;
    268 	termNode->antType[0] = rf_control;
    269 }
    270 
    271 
    272 
    273 
    274 /******************************************************************************
    275  *
    276  * creates a DAG to perform a small-write operation (either raid 5 or pq), which is as follows:
    277  *
    278  *                                     Header
    279  *                                       |
    280  *                                     Block
    281  *                                 / |  ... \   \
    282  *                                /  |       \   \
    283  *                             Rod  Rod      Rod  Rop
    284  *                             | \ /| \    / |  \/ |
    285  *                             |    |        |  /\ |
    286  *                             Wnd  Wnd      Wnd   X
    287  *                              |    \       /     |
    288  *                              |     \     /      |
    289  *                               \     \   /      Lpo
    290  *                                \     \ /       /
    291  *                                 +-> Unblock <-+
    292  *                                       |
    293  *                                       T
    294  *
    295  *
    296  * R = Read, W = Write, X = Xor, o = old, n = new, d = data, p = parity.
    297  * When the access spans a stripe unit boundary and is less than one SU in size, there will
    298  * be two Rop -- X -- Wnp branches.  I call this the "double-XOR" case.
    299  * The second output from each Rod node goes to the X node.  In the double-XOR
    300  * case, there are exactly 2 Rod nodes, and each sends one output to one X node.
    301  * There is one Rod -- Wnd -- T branch for each stripe unit being updated.
    302  *
    303  * The block and unblock nodes are unused.  See comment above CreateFaultFreeReadDAG.
    304  *
    305  * Note:  this DAG ignores all the optimizations related to making the RMWs atomic.
    306  *        it also has the nasty property that none of the buffers allocated for reading
    307  *        old data & parity can be freed until the XOR node fires.  Need to fix this.
    308  *
    309  * A null qfuncs indicates single fault tolerant
    310  *****************************************************************************/
    311 
    312 void
    313 rf_CommonCreateParityLoggingSmallWriteDAG(
    314     RF_Raid_t * raidPtr,
    315     RF_AccessStripeMap_t * asmap,
    316     RF_DagHeader_t * dag_h,
    317     void *bp,
    318     RF_RaidAccessFlags_t flags,
    319     RF_AllocListElem_t * allocList,
    320     RF_RedFuncs_t * pfuncs,
    321     RF_RedFuncs_t * qfuncs)
    322 {
    323 	RF_DagNode_t *xorNodes, *blockNode, *unblockNode, *nodes;
    324 	RF_DagNode_t *readDataNodes, *readParityNodes;
    325 	RF_DagNode_t *writeDataNodes, *lpuNodes;
    326 	RF_DagNode_t *unlockDataNodes = NULL, *termNode;
    327 	RF_PhysDiskAddr_t *pda = asmap->physInfo;
    328 	int     numDataNodes = asmap->numStripeUnitsAccessed;
    329 	int     numParityNodes = (asmap->parityInfo->next) ? 2 : 1;
    330 	int     i, j, nNodes, totalNumNodes;
    331 	RF_ReconUnitNum_t which_ru;
    332 	int     (*func) (RF_DagNode_t * node), (*undoFunc) (RF_DagNode_t * node);
    333 	int     (*qfunc) (RF_DagNode_t * node);
    334 	char   *name, *qname;
    335 	RF_StripeNum_t parityStripeID = rf_RaidAddressToParityStripeID(&(raidPtr->Layout), asmap->raidAddress, &which_ru);
    336 #ifdef RAID_DIAGNOSTIC
    337 	long    nfaults = qfuncs ? 2 : 1;
    338 #endif /* RAID_DIAGNOSTIC */
    339 	int     lu_flag = (rf_enableAtomicRMW) ? 1 : 0;	/* lock/unlock flag */
    340 
    341 	if (rf_dagDebug)
    342 		printf("[Creating parity-logging small-write DAG]\n");
    343 	RF_ASSERT(numDataNodes > 0);
    344 	RF_ASSERT(nfaults == 1);
    345 	dag_h->creator = "ParityLoggingSmallWriteDAG";
    346 
    347 	/* DAG creation occurs in three steps: 1. count the number of nodes in
    348 	 * the DAG 2. create the nodes 3. initialize the nodes 4. connect the
    349 	 * nodes */
    350 
    351 	/* Step 1. compute number of nodes in the graph */
    352 
    353 	/* number of nodes: a read and write for each data unit a redundancy
    354 	 * computation node for each parity node a read and Lpu for each
    355 	 * parity unit a block and unblock node (2) a terminator node if
    356 	 * atomic RMW an unlock node for each data unit, redundancy unit */
    357 	totalNumNodes = (2 * numDataNodes) + numParityNodes + (2 * numParityNodes) + 3;
    358 	if (lu_flag)
    359 		totalNumNodes += numDataNodes;
    360 
    361 	nNodes = numDataNodes + numParityNodes;
    362 
    363 	dag_h->numCommitNodes = numDataNodes + numParityNodes;
    364 	dag_h->numCommits = 0;
    365 	dag_h->numSuccedents = 1;
    366 
    367 	/* Step 2. create the nodes */
    368 	RF_CallocAndAdd(nodes, totalNumNodes, sizeof(RF_DagNode_t), (RF_DagNode_t *), allocList);
    369 	i = 0;
    370 	blockNode = &nodes[i];
    371 	i += 1;
    372 	unblockNode = &nodes[i];
    373 	i += 1;
    374 	readDataNodes = &nodes[i];
    375 	i += numDataNodes;
    376 	readParityNodes = &nodes[i];
    377 	i += numParityNodes;
    378 	writeDataNodes = &nodes[i];
    379 	i += numDataNodes;
    380 	lpuNodes = &nodes[i];
    381 	i += numParityNodes;
    382 	xorNodes = &nodes[i];
    383 	i += numParityNodes;
    384 	termNode = &nodes[i];
    385 	i += 1;
    386 	if (lu_flag) {
    387 		unlockDataNodes = &nodes[i];
    388 		i += numDataNodes;
    389 	}
    390 	RF_ASSERT(i == totalNumNodes);
    391 
    392 	/* Step 3. initialize the nodes */
    393 	/* initialize block node (Nil) */
    394 	rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, nNodes, 0, 0, 0, dag_h, "Nil", allocList);
    395 
    396 	/* initialize unblock node (Nil) */
    397 	rf_InitNode(unblockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, 1, nNodes, 0, 0, dag_h, "Nil", allocList);
    398 
    399 	/* initialize terminatory node (Trm) */
    400 	rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc, NULL, 0, 1, 0, 0, dag_h, "Trm", allocList);
    401 
    402 	/* initialize nodes which read old data (Rod) */
    403 	for (i = 0; i < numDataNodes; i++) {
    404 		rf_InitNode(&readDataNodes[i], rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc, rf_GenericWakeupFunc, nNodes, 1, 4, 0, dag_h, "Rod", allocList);
    405 		RF_ASSERT(pda != NULL);
    406 		readDataNodes[i].params[0].p = pda;	/* physical disk addr
    407 							 * desc */
    408 		readDataNodes[i].params[1].p = rf_AllocBuffer(raidPtr, dag_h, pda, allocList);	/* buffer to hold old
    409 												 * data */
    410 		readDataNodes[i].params[2].v = parityStripeID;
    411 		readDataNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, lu_flag, 0, which_ru);
    412 		pda = pda->next;
    413 		readDataNodes[i].propList[0] = NULL;
    414 		readDataNodes[i].propList[1] = NULL;
    415 	}
    416 
    417 	/* initialize nodes which read old parity (Rop) */
    418 	pda = asmap->parityInfo;
    419 	i = 0;
    420 	for (i = 0; i < numParityNodes; i++) {
    421 		RF_ASSERT(pda != NULL);
    422 		rf_InitNode(&readParityNodes[i], rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc, rf_GenericWakeupFunc, nNodes, 1, 4, 0, dag_h, "Rop", allocList);
    423 		readParityNodes[i].params[0].p = pda;
    424 		readParityNodes[i].params[1].p = rf_AllocBuffer(raidPtr, dag_h, pda, allocList);	/* buffer to hold old
    425 													 * parity */
    426 		readParityNodes[i].params[2].v = parityStripeID;
    427 		readParityNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    428 		readParityNodes[i].propList[0] = NULL;
    429 		pda = pda->next;
    430 	}
    431 
    432 	/* initialize nodes which write new data (Wnd) */
    433 	pda = asmap->physInfo;
    434 	for (i = 0; i < numDataNodes; i++) {
    435 		RF_ASSERT(pda != NULL);
    436 		rf_InitNode(&writeDataNodes[i], rf_wait, RF_TRUE, rf_DiskWriteFunc, rf_DiskWriteUndoFunc, rf_GenericWakeupFunc, 1, nNodes, 4, 0, dag_h, "Wnd", allocList);
    437 		writeDataNodes[i].params[0].p = pda;	/* physical disk addr
    438 							 * desc */
    439 		writeDataNodes[i].params[1].p = pda->bufPtr;	/* buffer holding new
    440 								 * data to be written */
    441 		writeDataNodes[i].params[2].v = parityStripeID;
    442 		writeDataNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    443 
    444 		if (lu_flag) {
    445 			/* initialize node to unlock the disk queue */
    446 			rf_InitNode(&unlockDataNodes[i], rf_wait, RF_FALSE, rf_DiskUnlockFunc, rf_DiskUnlockUndoFunc, rf_GenericWakeupFunc, 1, 1, 2, 0, dag_h, "Und", allocList);
    447 			unlockDataNodes[i].params[0].p = pda;	/* physical disk addr
    448 								 * desc */
    449 			unlockDataNodes[i].params[1].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, lu_flag, which_ru);
    450 		}
    451 		pda = pda->next;
    452 	}
    453 
    454 
    455 	/* initialize nodes which compute new parity */
    456 	/* we use the simple XOR func in the double-XOR case, and when we're
    457 	 * accessing only a portion of one stripe unit. the distinction
    458 	 * between the two is that the regular XOR func assumes that the
    459 	 * targbuf is a full SU in size, and examines the pda associated with
    460 	 * the buffer to decide where within the buffer to XOR the data,
    461 	 * whereas the simple XOR func just XORs the data into the start of
    462 	 * the buffer. */
    463 	if ((numParityNodes == 2) || ((numDataNodes == 1) && (asmap->totalSectorsAccessed < raidPtr->Layout.sectorsPerStripeUnit))) {
    464 		func = pfuncs->simple;
    465 		undoFunc = rf_NullNodeUndoFunc;
    466 		name = pfuncs->SimpleName;
    467 		if (qfuncs) {
    468 			qfunc = qfuncs->simple;
    469 			qname = qfuncs->SimpleName;
    470 		}
    471 	} else {
    472 		func = pfuncs->regular;
    473 		undoFunc = rf_NullNodeUndoFunc;
    474 		name = pfuncs->RegularName;
    475 		if (qfuncs) {
    476 			qfunc = qfuncs->regular;
    477 			qname = qfuncs->RegularName;
    478 		}
    479 	}
    480 	/* initialize the xor nodes: params are {pda,buf} from {Rod,Wnd,Rop}
    481 	 * nodes, and raidPtr  */
    482 	if (numParityNodes == 2) {	/* double-xor case */
    483 		for (i = 0; i < numParityNodes; i++) {
    484 			rf_InitNode(&xorNodes[i], rf_wait, RF_TRUE, func, undoFunc, NULL, 1, nNodes, 7, 1, dag_h, name, allocList);	/* no wakeup func for
    485 																	 * xor */
    486 			xorNodes[i].flags |= RF_DAGNODE_FLAG_YIELD;
    487 			xorNodes[i].params[0] = readDataNodes[i].params[0];
    488 			xorNodes[i].params[1] = readDataNodes[i].params[1];
    489 			xorNodes[i].params[2] = readParityNodes[i].params[0];
    490 			xorNodes[i].params[3] = readParityNodes[i].params[1];
    491 			xorNodes[i].params[4] = writeDataNodes[i].params[0];
    492 			xorNodes[i].params[5] = writeDataNodes[i].params[1];
    493 			xorNodes[i].params[6].p = raidPtr;
    494 			xorNodes[i].results[0] = readParityNodes[i].params[1].p;	/* use old parity buf as
    495 											 * target buf */
    496 		}
    497 	} else {
    498 		/* there is only one xor node in this case */
    499 		rf_InitNode(&xorNodes[0], rf_wait, RF_TRUE, func, undoFunc, NULL, 1, nNodes, (2 * (numDataNodes + numDataNodes + 1) + 1), 1, dag_h, name, allocList);
    500 		xorNodes[0].flags |= RF_DAGNODE_FLAG_YIELD;
    501 		for (i = 0; i < numDataNodes + 1; i++) {
    502 			/* set up params related to Rod and Rop nodes */
    503 			xorNodes[0].params[2 * i + 0] = readDataNodes[i].params[0];	/* pda */
    504 			xorNodes[0].params[2 * i + 1] = readDataNodes[i].params[1];	/* buffer pointer */
    505 		}
    506 		for (i = 0; i < numDataNodes; i++) {
    507 			/* set up params related to Wnd and Wnp nodes */
    508 			xorNodes[0].params[2 * (numDataNodes + 1 + i) + 0] = writeDataNodes[i].params[0];	/* pda */
    509 			xorNodes[0].params[2 * (numDataNodes + 1 + i) + 1] = writeDataNodes[i].params[1];	/* buffer pointer */
    510 		}
    511 		xorNodes[0].params[2 * (numDataNodes + numDataNodes + 1)].p = raidPtr;	/* xor node needs to get
    512 											 * at RAID information */
    513 		xorNodes[0].results[0] = readParityNodes[0].params[1].p;
    514 	}
    515 
    516 	/* initialize the log node(s) */
    517 	pda = asmap->parityInfo;
    518 	for (i = 0; i < numParityNodes; i++) {
    519 		RF_ASSERT(pda);
    520 		rf_InitNode(&lpuNodes[i], rf_wait, RF_FALSE, rf_ParityLogUpdateFunc, rf_ParityLogUpdateUndoFunc, rf_GenericWakeupFunc, 1, 1, 2, 0, dag_h, "Lpu", allocList);
    521 		lpuNodes[i].params[0].p = pda;	/* PhysDiskAddr of parity */
    522 		lpuNodes[i].params[1].p = xorNodes[i].results[0];	/* buffer pointer to
    523 									 * parity */
    524 		pda = pda->next;
    525 	}
    526 
    527 
    528 	/* Step 4. connect the nodes */
    529 
    530 	/* connect header to block node */
    531 	RF_ASSERT(dag_h->numSuccedents == 1);
    532 	RF_ASSERT(blockNode->numAntecedents == 0);
    533 	dag_h->succedents[0] = blockNode;
    534 
    535 	/* connect block node to read old data nodes */
    536 	RF_ASSERT(blockNode->numSuccedents == (numDataNodes + numParityNodes));
    537 	for (i = 0; i < numDataNodes; i++) {
    538 		blockNode->succedents[i] = &readDataNodes[i];
    539 		RF_ASSERT(readDataNodes[i].numAntecedents == 1);
    540 		readDataNodes[i].antecedents[0] = blockNode;
    541 		readDataNodes[i].antType[0] = rf_control;
    542 	}
    543 
    544 	/* connect block node to read old parity nodes */
    545 	for (i = 0; i < numParityNodes; i++) {
    546 		blockNode->succedents[numDataNodes + i] = &readParityNodes[i];
    547 		RF_ASSERT(readParityNodes[i].numAntecedents == 1);
    548 		readParityNodes[i].antecedents[0] = blockNode;
    549 		readParityNodes[i].antType[0] = rf_control;
    550 	}
    551 
    552 	/* connect read old data nodes to write new data nodes */
    553 	for (i = 0; i < numDataNodes; i++) {
    554 		RF_ASSERT(readDataNodes[i].numSuccedents == numDataNodes + numParityNodes);
    555 		for (j = 0; j < numDataNodes; j++) {
    556 			RF_ASSERT(writeDataNodes[j].numAntecedents == numDataNodes + numParityNodes);
    557 			readDataNodes[i].succedents[j] = &writeDataNodes[j];
    558 			writeDataNodes[j].antecedents[i] = &readDataNodes[i];
    559 			if (i == j)
    560 				writeDataNodes[j].antType[i] = rf_antiData;
    561 			else
    562 				writeDataNodes[j].antType[i] = rf_control;
    563 		}
    564 	}
    565 
    566 	/* connect read old data nodes to xor nodes */
    567 	for (i = 0; i < numDataNodes; i++)
    568 		for (j = 0; j < numParityNodes; j++) {
    569 			RF_ASSERT(xorNodes[j].numAntecedents == numDataNodes + numParityNodes);
    570 			readDataNodes[i].succedents[numDataNodes + j] = &xorNodes[j];
    571 			xorNodes[j].antecedents[i] = &readDataNodes[i];
    572 			xorNodes[j].antType[i] = rf_trueData;
    573 		}
    574 
    575 	/* connect read old parity nodes to write new data nodes */
    576 	for (i = 0; i < numParityNodes; i++) {
    577 		RF_ASSERT(readParityNodes[i].numSuccedents == numDataNodes + numParityNodes);
    578 		for (j = 0; j < numDataNodes; j++) {
    579 			readParityNodes[i].succedents[j] = &writeDataNodes[j];
    580 			writeDataNodes[j].antecedents[numDataNodes + i] = &readParityNodes[i];
    581 			writeDataNodes[j].antType[numDataNodes + i] = rf_control;
    582 		}
    583 	}
    584 
    585 	/* connect read old parity nodes to xor nodes */
    586 	for (i = 0; i < numParityNodes; i++)
    587 		for (j = 0; j < numParityNodes; j++) {
    588 			readParityNodes[i].succedents[numDataNodes + j] = &xorNodes[j];
    589 			xorNodes[j].antecedents[numDataNodes + i] = &readParityNodes[i];
    590 			xorNodes[j].antType[numDataNodes + i] = rf_trueData;
    591 		}
    592 
    593 	/* connect xor nodes to write new parity nodes */
    594 	for (i = 0; i < numParityNodes; i++) {
    595 		RF_ASSERT(xorNodes[i].numSuccedents == 1);
    596 		RF_ASSERT(lpuNodes[i].numAntecedents == 1);
    597 		xorNodes[i].succedents[0] = &lpuNodes[i];
    598 		lpuNodes[i].antecedents[0] = &xorNodes[i];
    599 		lpuNodes[i].antType[0] = rf_trueData;
    600 	}
    601 
    602 	for (i = 0; i < numDataNodes; i++) {
    603 		if (lu_flag) {
    604 			/* connect write new data nodes to unlock nodes */
    605 			RF_ASSERT(writeDataNodes[i].numSuccedents == 1);
    606 			RF_ASSERT(unlockDataNodes[i].numAntecedents == 1);
    607 			writeDataNodes[i].succedents[0] = &unlockDataNodes[i];
    608 			unlockDataNodes[i].antecedents[0] = &writeDataNodes[i];
    609 			unlockDataNodes[i].antType[0] = rf_control;
    610 
    611 			/* connect unlock nodes to unblock node */
    612 			RF_ASSERT(unlockDataNodes[i].numSuccedents == 1);
    613 			RF_ASSERT(unblockNode->numAntecedents == (numDataNodes + (nfaults * numParityNodes)));
    614 			unlockDataNodes[i].succedents[0] = unblockNode;
    615 			unblockNode->antecedents[i] = &unlockDataNodes[i];
    616 			unblockNode->antType[i] = rf_control;
    617 		} else {
    618 			/* connect write new data nodes to unblock node */
    619 			RF_ASSERT(writeDataNodes[i].numSuccedents == 1);
    620 			RF_ASSERT(unblockNode->numAntecedents == (numDataNodes + (nfaults * numParityNodes)));
    621 			writeDataNodes[i].succedents[0] = unblockNode;
    622 			unblockNode->antecedents[i] = &writeDataNodes[i];
    623 			unblockNode->antType[i] = rf_control;
    624 		}
    625 	}
    626 
    627 	/* connect write new parity nodes to unblock node */
    628 	for (i = 0; i < numParityNodes; i++) {
    629 		RF_ASSERT(lpuNodes[i].numSuccedents == 1);
    630 		lpuNodes[i].succedents[0] = unblockNode;
    631 		unblockNode->antecedents[numDataNodes + i] = &lpuNodes[i];
    632 		unblockNode->antType[numDataNodes + i] = rf_control;
    633 	}
    634 
    635 	/* connect unblock node to terminator */
    636 	RF_ASSERT(unblockNode->numSuccedents == 1);
    637 	RF_ASSERT(termNode->numAntecedents == 1);
    638 	RF_ASSERT(termNode->numSuccedents == 0);
    639 	unblockNode->succedents[0] = termNode;
    640 	termNode->antecedents[0] = unblockNode;
    641 	termNode->antType[0] = rf_control;
    642 }
    643 
    644 
    645 void
    646 rf_CreateParityLoggingSmallWriteDAG(
    647     RF_Raid_t * raidPtr,
    648     RF_AccessStripeMap_t * asmap,
    649     RF_DagHeader_t * dag_h,
    650     void *bp,
    651     RF_RaidAccessFlags_t flags,
    652     RF_AllocListElem_t * allocList,
    653     RF_RedFuncs_t * pfuncs,
    654     RF_RedFuncs_t * qfuncs)
    655 {
    656 	dag_h->creator = "ParityLoggingSmallWriteDAG";
    657 	rf_CommonCreateParityLoggingSmallWriteDAG(raidPtr, asmap, dag_h, bp, flags, allocList, &rf_xorFuncs, NULL);
    658 }
    659 
    660 
    661 void
    662 rf_CreateParityLoggingLargeWriteDAG(
    663     RF_Raid_t * raidPtr,
    664     RF_AccessStripeMap_t * asmap,
    665     RF_DagHeader_t * dag_h,
    666     void *bp,
    667     RF_RaidAccessFlags_t flags,
    668     RF_AllocListElem_t * allocList,
    669     int nfaults,
    670     int (*redFunc) (RF_DagNode_t *))
    671 {
    672 	dag_h->creator = "ParityLoggingSmallWriteDAG";
    673 	rf_CommonCreateParityLoggingLargeWriteDAG(raidPtr, asmap, dag_h, bp, flags, allocList, 1, rf_RegularXorFunc);
    674 }
    675 #endif				/* RF_INCLUDE_PARITYLOGGING > 0 */
    676