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