Home | History | Annotate | Line # | Download | only in raidframe
rf_dagffwr.c revision 1.14
      1  1.14  oster /*	$NetBSD: rf_dagffwr.c,v 1.14 2004/01/06 03:27:13 oster Exp $	*/
      2   1.1  oster /*
      3   1.1  oster  * Copyright (c) 1995 Carnegie-Mellon University.
      4   1.1  oster  * All rights reserved.
      5   1.1  oster  *
      6   1.1  oster  * Author: Mark Holland, Daniel Stodolsky, William V. Courtright II
      7   1.1  oster  *
      8   1.1  oster  * Permission to use, copy, modify and distribute this software and
      9   1.1  oster  * its documentation is hereby granted, provided that both the copyright
     10   1.1  oster  * notice and this permission notice appear in all copies of the
     11   1.1  oster  * software, derivative works or modified versions, and any portions
     12   1.1  oster  * thereof, and that both notices appear in supporting documentation.
     13   1.1  oster  *
     14   1.1  oster  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15   1.1  oster  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16   1.1  oster  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17   1.1  oster  *
     18   1.1  oster  * Carnegie Mellon requests users of this software to return to
     19   1.1  oster  *
     20   1.1  oster  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21   1.1  oster  *  School of Computer Science
     22   1.1  oster  *  Carnegie Mellon University
     23   1.1  oster  *  Pittsburgh PA 15213-3890
     24   1.1  oster  *
     25   1.1  oster  * any improvements or extensions that they make and grant Carnegie the
     26   1.1  oster  * rights to redistribute these changes.
     27   1.1  oster  */
     28   1.1  oster 
     29   1.1  oster /*
     30   1.1  oster  * rf_dagff.c
     31   1.1  oster  *
     32   1.1  oster  * code for creating fault-free DAGs
     33   1.1  oster  *
     34   1.1  oster  */
     35   1.7  lukem 
     36   1.7  lukem #include <sys/cdefs.h>
     37  1.14  oster __KERNEL_RCSID(0, "$NetBSD: rf_dagffwr.c,v 1.14 2004/01/06 03:27:13 oster Exp $");
     38   1.1  oster 
     39   1.6  oster #include <dev/raidframe/raidframevar.h>
     40   1.6  oster 
     41   1.1  oster #include "rf_raid.h"
     42   1.1  oster #include "rf_dag.h"
     43   1.1  oster #include "rf_dagutils.h"
     44   1.1  oster #include "rf_dagfuncs.h"
     45   1.1  oster #include "rf_debugMem.h"
     46   1.1  oster #include "rf_dagffrd.h"
     47   1.1  oster #include "rf_general.h"
     48   1.1  oster #include "rf_dagffwr.h"
     49   1.1  oster 
     50   1.1  oster /******************************************************************************
     51   1.1  oster  *
     52   1.1  oster  * General comments on DAG creation:
     53   1.3  oster  *
     54   1.1  oster  * All DAGs in this file use roll-away error recovery.  Each DAG has a single
     55   1.1  oster  * commit node, usually called "Cmt."  If an error occurs before the Cmt node
     56   1.1  oster  * is reached, the execution engine will halt forward execution and work
     57   1.1  oster  * backward through the graph, executing the undo functions.  Assuming that
     58   1.1  oster  * each node in the graph prior to the Cmt node are undoable and atomic - or -
     59   1.1  oster  * does not make changes to permanent state, the graph will fail atomically.
     60   1.1  oster  * If an error occurs after the Cmt node executes, the engine will roll-forward
     61   1.1  oster  * through the graph, blindly executing nodes until it reaches the end.
     62   1.1  oster  * If a graph reaches the end, it is assumed to have completed successfully.
     63   1.1  oster  *
     64   1.1  oster  * A graph has only 1 Cmt node.
     65   1.1  oster  *
     66   1.1  oster  */
     67   1.1  oster 
     68   1.1  oster 
     69   1.1  oster /******************************************************************************
     70   1.1  oster  *
     71   1.1  oster  * The following wrappers map the standard DAG creation interface to the
     72   1.1  oster  * DAG creation routines.  Additionally, these wrappers enable experimentation
     73   1.1  oster  * with new DAG structures by providing an extra level of indirection, allowing
     74   1.1  oster  * the DAG creation routines to be replaced at this single point.
     75   1.1  oster  */
     76   1.1  oster 
     77   1.1  oster 
     78   1.3  oster void
     79  1.13  oster rf_CreateNonRedundantWriteDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
     80  1.13  oster 			      RF_DagHeader_t *dag_h, void *bp,
     81  1.13  oster 			      RF_RaidAccessFlags_t flags,
     82  1.13  oster 			      RF_AllocListElem_t *allocList,
     83  1.13  oster 			      RF_IoType_t type)
     84   1.1  oster {
     85   1.3  oster 	rf_CreateNonredundantDAG(raidPtr, asmap, dag_h, bp, flags, allocList,
     86  1.14  oster 				 RF_IO_TYPE_WRITE);
     87   1.1  oster }
     88   1.1  oster 
     89   1.3  oster void
     90  1.13  oster rf_CreateRAID0WriteDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
     91  1.13  oster 		       RF_DagHeader_t *dag_h, void *bp,
     92  1.13  oster 		       RF_RaidAccessFlags_t flags,
     93  1.13  oster 		       RF_AllocListElem_t *allocList,
     94  1.13  oster 		       RF_IoType_t type)
     95   1.1  oster {
     96   1.3  oster 	rf_CreateNonredundantDAG(raidPtr, asmap, dag_h, bp, flags, allocList,
     97  1.14  oster 				 RF_IO_TYPE_WRITE);
     98   1.1  oster }
     99   1.1  oster 
    100   1.3  oster void
    101  1.13  oster rf_CreateSmallWriteDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
    102  1.13  oster 		       RF_DagHeader_t *dag_h, void *bp,
    103  1.13  oster 		       RF_RaidAccessFlags_t flags,
    104  1.13  oster 		       RF_AllocListElem_t *allocList)
    105   1.1  oster {
    106   1.3  oster 	/* "normal" rollaway */
    107  1.14  oster 	rf_CommonCreateSmallWriteDAG(raidPtr, asmap, dag_h, bp, flags,
    108  1.14  oster 				     allocList, &rf_xorFuncs, NULL);
    109   1.1  oster }
    110   1.1  oster 
    111   1.3  oster void
    112  1.13  oster rf_CreateLargeWriteDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
    113  1.13  oster 		       RF_DagHeader_t *dag_h, void *bp,
    114  1.13  oster 		       RF_RaidAccessFlags_t flags,
    115  1.13  oster 		       RF_AllocListElem_t *allocList)
    116   1.1  oster {
    117   1.3  oster 	/* "normal" rollaway */
    118  1.14  oster 	rf_CommonCreateLargeWriteDAG(raidPtr, asmap, dag_h, bp, flags,
    119  1.14  oster 				     allocList, 1, rf_RegularXorFunc, RF_TRUE);
    120   1.1  oster }
    121   1.1  oster 
    122   1.1  oster 
    123   1.1  oster /******************************************************************************
    124   1.1  oster  *
    125   1.1  oster  * DAG creation code begins here
    126   1.1  oster  */
    127   1.1  oster 
    128   1.1  oster 
    129   1.1  oster /******************************************************************************
    130   1.1  oster  *
    131   1.1  oster  * creates a DAG to perform a large-write operation:
    132   1.1  oster  *
    133   1.1  oster  *           / Rod \           / Wnd \
    134   1.1  oster  * H -- block- Rod - Xor - Cmt - Wnd --- T
    135   1.1  oster  *           \ Rod /          \  Wnp /
    136   1.1  oster  *                             \[Wnq]/
    137   1.1  oster  *
    138   1.1  oster  * The XOR node also does the Q calculation in the P+Q architecture.
    139   1.1  oster  * All nodes are before the commit node (Cmt) are assumed to be atomic and
    140   1.1  oster  * undoable - or - they make no changes to permanent state.
    141   1.1  oster  *
    142   1.1  oster  * Rod = read old data
    143   1.1  oster  * Cmt = commit node
    144   1.1  oster  * Wnp = write new parity
    145   1.1  oster  * Wnd = write new data
    146   1.1  oster  * Wnq = write new "q"
    147   1.1  oster  * [] denotes optional segments in the graph
    148   1.1  oster  *
    149   1.1  oster  * Parameters:  raidPtr   - description of the physical array
    150   1.1  oster  *              asmap     - logical & physical addresses for this access
    151   1.1  oster  *              bp        - buffer ptr (holds write data)
    152   1.3  oster  *              flags     - general flags (e.g. disk locking)
    153   1.1  oster  *              allocList - list of memory allocated in DAG creation
    154   1.1  oster  *              nfaults   - number of faults array can tolerate
    155   1.1  oster  *                          (equal to # redundancy units in stripe)
    156   1.1  oster  *              redfuncs  - list of redundancy generating functions
    157   1.1  oster  *
    158   1.1  oster  *****************************************************************************/
    159   1.1  oster 
    160   1.3  oster void
    161  1.13  oster rf_CommonCreateLargeWriteDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
    162  1.13  oster 			     RF_DagHeader_t *dag_h, void *bp,
    163  1.13  oster 			     RF_RaidAccessFlags_t flags,
    164  1.13  oster 			     RF_AllocListElem_t *allocList,
    165  1.13  oster 			     int nfaults, int (*redFunc) (RF_DagNode_t *),
    166  1.13  oster 			     int allowBufferRecycle)
    167   1.1  oster {
    168   1.3  oster 	RF_DagNode_t *nodes, *wndNodes, *rodNodes, *xorNode, *wnpNode;
    169   1.3  oster 	RF_DagNode_t *wnqNode, *blockNode, *commitNode, *termNode;
    170   1.3  oster 	int     nWndNodes, nRodNodes, i, nodeNum, asmNum;
    171   1.3  oster 	RF_AccessStripeMapHeader_t *new_asm_h[2];
    172   1.3  oster 	RF_StripeNum_t parityStripeID;
    173   1.3  oster 	char   *sosBuffer, *eosBuffer;
    174   1.3  oster 	RF_ReconUnitNum_t which_ru;
    175   1.3  oster 	RF_RaidLayout_t *layoutPtr;
    176   1.3  oster 	RF_PhysDiskAddr_t *pda;
    177   1.3  oster 
    178   1.3  oster 	layoutPtr = &(raidPtr->Layout);
    179  1.14  oster 	parityStripeID = rf_RaidAddressToParityStripeID(layoutPtr,
    180  1.14  oster 							asmap->raidAddress,
    181  1.14  oster 							&which_ru);
    182   1.3  oster 
    183   1.3  oster 	if (rf_dagDebug) {
    184   1.3  oster 		printf("[Creating large-write DAG]\n");
    185   1.3  oster 	}
    186   1.3  oster 	dag_h->creator = "LargeWriteDAG";
    187   1.3  oster 
    188   1.3  oster 	dag_h->numCommitNodes = 1;
    189   1.3  oster 	dag_h->numCommits = 0;
    190   1.3  oster 	dag_h->numSuccedents = 1;
    191   1.3  oster 
    192   1.3  oster 	/* alloc the nodes: Wnd, xor, commit, block, term, and  Wnp */
    193   1.3  oster 	nWndNodes = asmap->numStripeUnitsAccessed;
    194  1.12  oster 	RF_MallocAndAdd(nodes,
    195  1.12  oster 			(nWndNodes + 4 + nfaults) * sizeof(RF_DagNode_t),
    196  1.12  oster 			(RF_DagNode_t *), allocList);
    197   1.3  oster 	i = 0;
    198   1.3  oster 	wndNodes = &nodes[i];
    199   1.3  oster 	i += nWndNodes;
    200   1.3  oster 	xorNode = &nodes[i];
    201   1.3  oster 	i += 1;
    202   1.3  oster 	wnpNode = &nodes[i];
    203   1.3  oster 	i += 1;
    204   1.3  oster 	blockNode = &nodes[i];
    205   1.3  oster 	i += 1;
    206   1.3  oster 	commitNode = &nodes[i];
    207   1.3  oster 	i += 1;
    208   1.3  oster 	termNode = &nodes[i];
    209   1.3  oster 	i += 1;
    210   1.3  oster 	if (nfaults == 2) {
    211   1.3  oster 		wnqNode = &nodes[i];
    212   1.3  oster 		i += 1;
    213   1.3  oster 	} else {
    214   1.3  oster 		wnqNode = NULL;
    215   1.3  oster 	}
    216  1.14  oster 	rf_MapUnaccessedPortionOfStripe(raidPtr, layoutPtr, asmap, dag_h,
    217  1.14  oster 					new_asm_h, &nRodNodes, &sosBuffer,
    218  1.14  oster 					&eosBuffer, allocList);
    219   1.3  oster 	if (nRodNodes > 0) {
    220  1.12  oster 		RF_MallocAndAdd(rodNodes, nRodNodes * sizeof(RF_DagNode_t),
    221  1.12  oster 				(RF_DagNode_t *), allocList);
    222   1.3  oster 	} else {
    223   1.3  oster 		rodNodes = NULL;
    224   1.3  oster 	}
    225   1.3  oster 
    226   1.3  oster 	/* begin node initialization */
    227   1.3  oster 	if (nRodNodes > 0) {
    228  1.14  oster 		rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc,
    229  1.14  oster 			    rf_NullNodeUndoFunc, NULL, nRodNodes, 0, 0, 0,
    230  1.14  oster 			    dag_h, "Nil", allocList);
    231   1.3  oster 	} else {
    232  1.14  oster 		rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc,
    233  1.14  oster 			    rf_NullNodeUndoFunc, NULL, 1, 0, 0, 0,
    234  1.14  oster 			    dag_h, "Nil", allocList);
    235   1.3  oster 	}
    236   1.3  oster 
    237  1.14  oster 	rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc,
    238  1.14  oster 		    rf_NullNodeUndoFunc, NULL, nWndNodes + nfaults, 1, 0, 0,
    239  1.14  oster 		    dag_h, "Cmt", allocList);
    240  1.14  oster 	rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc,
    241  1.14  oster 		    rf_TerminateUndoFunc, NULL, 0, nWndNodes + nfaults, 0, 0,
    242  1.14  oster 		    dag_h, "Trm", allocList);
    243   1.3  oster 
    244   1.3  oster 	/* initialize the Rod nodes */
    245   1.3  oster 	for (nodeNum = asmNum = 0; asmNum < 2; asmNum++) {
    246   1.3  oster 		if (new_asm_h[asmNum]) {
    247   1.3  oster 			pda = new_asm_h[asmNum]->stripeMap->physInfo;
    248   1.3  oster 			while (pda) {
    249  1.14  oster 				rf_InitNode(&rodNodes[nodeNum], rf_wait,
    250  1.14  oster 					    RF_FALSE, rf_DiskReadFunc,
    251  1.14  oster 					    rf_DiskReadUndoFunc,
    252  1.14  oster 					    rf_GenericWakeupFunc,
    253  1.14  oster 					    1, 1, 4, 0, dag_h,
    254  1.14  oster 					    "Rod", allocList);
    255   1.3  oster 				rodNodes[nodeNum].params[0].p = pda;
    256   1.3  oster 				rodNodes[nodeNum].params[1].p = pda->bufPtr;
    257   1.3  oster 				rodNodes[nodeNum].params[2].v = parityStripeID;
    258   1.3  oster 				rodNodes[nodeNum].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
    259   1.3  oster 				    0, 0, which_ru);
    260   1.3  oster 				nodeNum++;
    261   1.3  oster 				pda = pda->next;
    262   1.3  oster 			}
    263   1.3  oster 		}
    264   1.3  oster 	}
    265   1.3  oster 	RF_ASSERT(nodeNum == nRodNodes);
    266   1.3  oster 
    267   1.3  oster 	/* initialize the wnd nodes */
    268   1.3  oster 	pda = asmap->physInfo;
    269   1.3  oster 	for (i = 0; i < nWndNodes; i++) {
    270  1.14  oster 		rf_InitNode(&wndNodes[i], rf_wait, RF_FALSE,
    271  1.14  oster 			    rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
    272  1.14  oster 			    rf_GenericWakeupFunc, 1, 1, 4, 0,
    273  1.14  oster 			    dag_h, "Wnd", allocList);
    274   1.3  oster 		RF_ASSERT(pda != NULL);
    275   1.3  oster 		wndNodes[i].params[0].p = pda;
    276   1.3  oster 		wndNodes[i].params[1].p = pda->bufPtr;
    277   1.3  oster 		wndNodes[i].params[2].v = parityStripeID;
    278   1.3  oster 		wndNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    279   1.3  oster 		pda = pda->next;
    280   1.3  oster 	}
    281   1.3  oster 
    282   1.3  oster 	/* initialize the redundancy node */
    283   1.3  oster 	if (nRodNodes > 0) {
    284  1.14  oster 		rf_InitNode(xorNode, rf_wait, RF_FALSE, redFunc,
    285  1.14  oster 			    rf_NullNodeUndoFunc, NULL, 1,
    286  1.14  oster 			    nRodNodes, 2 * (nWndNodes + nRodNodes) + 1,
    287  1.14  oster 			    nfaults, dag_h, "Xr ", allocList);
    288   1.3  oster 	} else {
    289  1.14  oster 		rf_InitNode(xorNode, rf_wait, RF_FALSE, redFunc,
    290  1.14  oster 			    rf_NullNodeUndoFunc, NULL, 1,
    291  1.14  oster 			    1, 2 * (nWndNodes + nRodNodes) + 1,
    292  1.14  oster 			    nfaults, dag_h, "Xr ", allocList);
    293   1.3  oster 	}
    294   1.3  oster 	xorNode->flags |= RF_DAGNODE_FLAG_YIELD;
    295   1.3  oster 	for (i = 0; i < nWndNodes; i++) {
    296  1.14  oster 		/* pda */
    297  1.14  oster 		xorNode->params[2 * i + 0] = wndNodes[i].params[0];
    298  1.14  oster 		/* buf ptr */
    299  1.14  oster 		xorNode->params[2 * i + 1] = wndNodes[i].params[1];
    300   1.3  oster 	}
    301   1.3  oster 	for (i = 0; i < nRodNodes; i++) {
    302  1.14  oster 		/* pda */
    303  1.14  oster 		xorNode->params[2 * (nWndNodes + i) + 0] = rodNodes[i].params[0];
    304  1.14  oster 		/* buf ptr */
    305  1.14  oster 		xorNode->params[2 * (nWndNodes + i) + 1] = rodNodes[i].params[1];
    306   1.3  oster 	}
    307   1.3  oster 	/* xor node needs to get at RAID information */
    308   1.3  oster 	xorNode->params[2 * (nWndNodes + nRodNodes)].p = raidPtr;
    309   1.3  oster 
    310   1.3  oster 	/*
    311  1.14  oster          * Look for an Rod node that reads a complete SU. If none,
    312  1.14  oster          * alloc a buffer to receive the parity info. Note that we
    313  1.14  oster          * can't use a new data buffer because it will not have gotten
    314  1.14  oster          * written when the xor occurs.  */
    315   1.3  oster 	if (allowBufferRecycle) {
    316   1.3  oster 		for (i = 0; i < nRodNodes; i++) {
    317   1.3  oster 			if (((RF_PhysDiskAddr_t *) rodNodes[i].params[0].p)->numSector == raidPtr->Layout.sectorsPerStripeUnit)
    318   1.3  oster 				break;
    319   1.3  oster 		}
    320   1.3  oster 	}
    321   1.3  oster 	if ((!allowBufferRecycle) || (i == nRodNodes)) {
    322  1.12  oster 		RF_MallocAndAdd(xorNode->results[0],
    323  1.12  oster 				rf_RaidAddressToByte(raidPtr, raidPtr->Layout.sectorsPerStripeUnit),
    324  1.12  oster 				(void *), allocList);
    325   1.3  oster 	} else {
    326   1.3  oster 		xorNode->results[0] = rodNodes[i].params[1].p;
    327   1.3  oster 	}
    328   1.3  oster 
    329   1.3  oster 	/* initialize the Wnp node */
    330  1.14  oster 	rf_InitNode(wnpNode, rf_wait, RF_FALSE, rf_DiskWriteFunc,
    331  1.14  oster 		    rf_DiskWriteUndoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0,
    332  1.14  oster 		    dag_h, "Wnp", allocList);
    333   1.3  oster 	wnpNode->params[0].p = asmap->parityInfo;
    334   1.3  oster 	wnpNode->params[1].p = xorNode->results[0];
    335   1.3  oster 	wnpNode->params[2].v = parityStripeID;
    336   1.3  oster 	wnpNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    337   1.3  oster 	/* parityInfo must describe entire parity unit */
    338   1.3  oster 	RF_ASSERT(asmap->parityInfo->next == NULL);
    339   1.3  oster 
    340   1.3  oster 	if (nfaults == 2) {
    341   1.3  oster 		/*
    342   1.3  oster 	         * We never try to recycle a buffer for the Q calcuation
    343   1.3  oster 	         * in addition to the parity. This would cause two buffers
    344   1.3  oster 	         * to get smashed during the P and Q calculation, guaranteeing
    345   1.3  oster 	         * one would be wrong.
    346   1.3  oster 	         */
    347  1.12  oster 		RF_MallocAndAdd(xorNode->results[1],
    348  1.12  oster 				rf_RaidAddressToByte(raidPtr, raidPtr->Layout.sectorsPerStripeUnit),
    349  1.12  oster 				(void *), allocList);
    350  1.14  oster 		rf_InitNode(wnqNode, rf_wait, RF_FALSE, rf_DiskWriteFunc,
    351  1.14  oster 			    rf_DiskWriteUndoFunc, rf_GenericWakeupFunc,
    352  1.14  oster 			    1, 1, 4, 0, dag_h, "Wnq", allocList);
    353   1.3  oster 		wnqNode->params[0].p = asmap->qInfo;
    354   1.3  oster 		wnqNode->params[1].p = xorNode->results[1];
    355   1.3  oster 		wnqNode->params[2].v = parityStripeID;
    356   1.3  oster 		wnqNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    357   1.3  oster 		/* parityInfo must describe entire parity unit */
    358   1.3  oster 		RF_ASSERT(asmap->parityInfo->next == NULL);
    359   1.3  oster 	}
    360   1.3  oster 	/*
    361   1.3  oster          * Connect nodes to form graph.
    362   1.3  oster          */
    363   1.3  oster 
    364   1.3  oster 	/* connect dag header to block node */
    365   1.3  oster 	RF_ASSERT(blockNode->numAntecedents == 0);
    366   1.3  oster 	dag_h->succedents[0] = blockNode;
    367   1.3  oster 
    368   1.3  oster 	if (nRodNodes > 0) {
    369   1.3  oster 		/* connect the block node to the Rod nodes */
    370   1.3  oster 		RF_ASSERT(blockNode->numSuccedents == nRodNodes);
    371   1.3  oster 		RF_ASSERT(xorNode->numAntecedents == nRodNodes);
    372   1.3  oster 		for (i = 0; i < nRodNodes; i++) {
    373   1.3  oster 			RF_ASSERT(rodNodes[i].numAntecedents == 1);
    374   1.3  oster 			blockNode->succedents[i] = &rodNodes[i];
    375   1.3  oster 			rodNodes[i].antecedents[0] = blockNode;
    376   1.3  oster 			rodNodes[i].antType[0] = rf_control;
    377   1.3  oster 
    378   1.3  oster 			/* connect the Rod nodes to the Xor node */
    379   1.3  oster 			RF_ASSERT(rodNodes[i].numSuccedents == 1);
    380   1.3  oster 			rodNodes[i].succedents[0] = xorNode;
    381   1.3  oster 			xorNode->antecedents[i] = &rodNodes[i];
    382   1.3  oster 			xorNode->antType[i] = rf_trueData;
    383   1.3  oster 		}
    384   1.3  oster 	} else {
    385   1.3  oster 		/* connect the block node to the Xor node */
    386   1.3  oster 		RF_ASSERT(blockNode->numSuccedents == 1);
    387   1.3  oster 		RF_ASSERT(xorNode->numAntecedents == 1);
    388   1.3  oster 		blockNode->succedents[0] = xorNode;
    389   1.3  oster 		xorNode->antecedents[0] = blockNode;
    390   1.3  oster 		xorNode->antType[0] = rf_control;
    391   1.3  oster 	}
    392   1.3  oster 
    393   1.3  oster 	/* connect the xor node to the commit node */
    394   1.3  oster 	RF_ASSERT(xorNode->numSuccedents == 1);
    395   1.3  oster 	RF_ASSERT(commitNode->numAntecedents == 1);
    396   1.3  oster 	xorNode->succedents[0] = commitNode;
    397   1.3  oster 	commitNode->antecedents[0] = xorNode;
    398   1.3  oster 	commitNode->antType[0] = rf_control;
    399   1.3  oster 
    400   1.3  oster 	/* connect the commit node to the write nodes */
    401   1.3  oster 	RF_ASSERT(commitNode->numSuccedents == nWndNodes + nfaults);
    402   1.3  oster 	for (i = 0; i < nWndNodes; i++) {
    403   1.3  oster 		RF_ASSERT(wndNodes->numAntecedents == 1);
    404   1.3  oster 		commitNode->succedents[i] = &wndNodes[i];
    405   1.3  oster 		wndNodes[i].antecedents[0] = commitNode;
    406   1.3  oster 		wndNodes[i].antType[0] = rf_control;
    407   1.3  oster 	}
    408   1.3  oster 	RF_ASSERT(wnpNode->numAntecedents == 1);
    409   1.3  oster 	commitNode->succedents[nWndNodes] = wnpNode;
    410   1.3  oster 	wnpNode->antecedents[0] = commitNode;
    411   1.3  oster 	wnpNode->antType[0] = rf_trueData;
    412   1.3  oster 	if (nfaults == 2) {
    413   1.3  oster 		RF_ASSERT(wnqNode->numAntecedents == 1);
    414   1.3  oster 		commitNode->succedents[nWndNodes + 1] = wnqNode;
    415   1.3  oster 		wnqNode->antecedents[0] = commitNode;
    416   1.3  oster 		wnqNode->antType[0] = rf_trueData;
    417   1.3  oster 	}
    418   1.3  oster 	/* connect the write nodes to the term node */
    419   1.3  oster 	RF_ASSERT(termNode->numAntecedents == nWndNodes + nfaults);
    420   1.3  oster 	RF_ASSERT(termNode->numSuccedents == 0);
    421   1.3  oster 	for (i = 0; i < nWndNodes; i++) {
    422   1.3  oster 		RF_ASSERT(wndNodes->numSuccedents == 1);
    423   1.3  oster 		wndNodes[i].succedents[0] = termNode;
    424   1.3  oster 		termNode->antecedents[i] = &wndNodes[i];
    425   1.3  oster 		termNode->antType[i] = rf_control;
    426   1.3  oster 	}
    427   1.3  oster 	RF_ASSERT(wnpNode->numSuccedents == 1);
    428   1.3  oster 	wnpNode->succedents[0] = termNode;
    429   1.3  oster 	termNode->antecedents[nWndNodes] = wnpNode;
    430   1.3  oster 	termNode->antType[nWndNodes] = rf_control;
    431   1.3  oster 	if (nfaults == 2) {
    432   1.3  oster 		RF_ASSERT(wnqNode->numSuccedents == 1);
    433   1.3  oster 		wnqNode->succedents[0] = termNode;
    434   1.3  oster 		termNode->antecedents[nWndNodes + 1] = wnqNode;
    435   1.3  oster 		termNode->antType[nWndNodes + 1] = rf_control;
    436   1.3  oster 	}
    437   1.1  oster }
    438   1.1  oster /******************************************************************************
    439   1.1  oster  *
    440   1.1  oster  * creates a DAG to perform a small-write operation (either raid 5 or pq),
    441   1.1  oster  * which is as follows:
    442   1.1  oster  *
    443   1.1  oster  * Hdr -> Nil -> Rop -> Xor -> Cmt ----> Wnp [Unp] --> Trm
    444   1.1  oster  *            \- Rod X      /     \----> Wnd [Und]-/
    445   1.1  oster  *           [\- Rod X     /       \---> Wnd [Und]-/]
    446   1.1  oster  *           [\- Roq -> Q /         \--> Wnq [Unq]-/]
    447   1.1  oster  *
    448   1.1  oster  * Rop = read old parity
    449   1.1  oster  * Rod = read old data
    450   1.1  oster  * Roq = read old "q"
    451   1.1  oster  * Cmt = commit node
    452   1.1  oster  * Und = unlock data disk
    453   1.1  oster  * Unp = unlock parity disk
    454   1.1  oster  * Unq = unlock q disk
    455   1.1  oster  * Wnp = write new parity
    456   1.1  oster  * Wnd = write new data
    457   1.1  oster  * Wnq = write new "q"
    458   1.1  oster  * [ ] denotes optional segments in the graph
    459   1.1  oster  *
    460   1.1  oster  * Parameters:  raidPtr   - description of the physical array
    461   1.1  oster  *              asmap     - logical & physical addresses for this access
    462   1.1  oster  *              bp        - buffer ptr (holds write data)
    463   1.3  oster  *              flags     - general flags (e.g. disk locking)
    464   1.1  oster  *              allocList - list of memory allocated in DAG creation
    465   1.1  oster  *              pfuncs    - list of parity generating functions
    466   1.1  oster  *              qfuncs    - list of q generating functions
    467   1.1  oster  *
    468   1.1  oster  * A null qfuncs indicates single fault tolerant
    469   1.1  oster  *****************************************************************************/
    470   1.1  oster 
    471   1.3  oster void
    472  1.13  oster rf_CommonCreateSmallWriteDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
    473  1.13  oster 			     RF_DagHeader_t *dag_h, void *bp,
    474  1.13  oster 			     RF_RaidAccessFlags_t flags,
    475  1.13  oster 			     RF_AllocListElem_t *allocList,
    476  1.13  oster 			     const RF_RedFuncs_t *pfuncs,
    477  1.13  oster 			     const RF_RedFuncs_t *qfuncs)
    478   1.1  oster {
    479   1.3  oster 	RF_DagNode_t *readDataNodes, *readParityNodes, *readQNodes, *termNode;
    480   1.3  oster 	RF_DagNode_t *unlockDataNodes, *unlockParityNodes, *unlockQNodes;
    481   1.3  oster 	RF_DagNode_t *xorNodes, *qNodes, *blockNode, *commitNode, *nodes;
    482   1.3  oster 	RF_DagNode_t *writeDataNodes, *writeParityNodes, *writeQNodes;
    483   1.3  oster 	int     i, j, nNodes, totalNumNodes, lu_flag;
    484   1.3  oster 	RF_ReconUnitNum_t which_ru;
    485   1.3  oster 	int     (*func) (RF_DagNode_t *), (*undoFunc) (RF_DagNode_t *);
    486   1.3  oster 	int     (*qfunc) (RF_DagNode_t *);
    487   1.3  oster 	int     numDataNodes, numParityNodes;
    488   1.3  oster 	RF_StripeNum_t parityStripeID;
    489   1.3  oster 	RF_PhysDiskAddr_t *pda;
    490   1.3  oster 	char   *name, *qname;
    491   1.3  oster 	long    nfaults;
    492   1.3  oster 
    493   1.3  oster 	nfaults = qfuncs ? 2 : 1;
    494   1.3  oster 	lu_flag = (rf_enableAtomicRMW) ? 1 : 0;	/* lock/unlock flag */
    495   1.3  oster 
    496   1.3  oster 	parityStripeID = rf_RaidAddressToParityStripeID(&(raidPtr->Layout),
    497   1.3  oster 	    asmap->raidAddress, &which_ru);
    498   1.3  oster 	pda = asmap->physInfo;
    499   1.3  oster 	numDataNodes = asmap->numStripeUnitsAccessed;
    500   1.3  oster 	numParityNodes = (asmap->parityInfo->next) ? 2 : 1;
    501   1.3  oster 
    502   1.3  oster 	if (rf_dagDebug) {
    503   1.3  oster 		printf("[Creating small-write DAG]\n");
    504   1.3  oster 	}
    505   1.3  oster 	RF_ASSERT(numDataNodes > 0);
    506   1.3  oster 	dag_h->creator = "SmallWriteDAG";
    507   1.3  oster 
    508   1.3  oster 	dag_h->numCommitNodes = 1;
    509   1.3  oster 	dag_h->numCommits = 0;
    510   1.3  oster 	dag_h->numSuccedents = 1;
    511   1.3  oster 
    512   1.3  oster 	/*
    513   1.3  oster          * DAG creation occurs in four steps:
    514   1.3  oster          * 1. count the number of nodes in the DAG
    515   1.3  oster          * 2. create the nodes
    516   1.3  oster          * 3. initialize the nodes
    517   1.3  oster          * 4. connect the nodes
    518   1.3  oster          */
    519   1.3  oster 
    520   1.3  oster 	/*
    521   1.3  oster          * Step 1. compute number of nodes in the graph
    522   1.3  oster          */
    523   1.3  oster 
    524  1.14  oster 	/* number of nodes: a read and write for each data unit a
    525  1.14  oster 	 * redundancy computation node for each parity node (nfaults *
    526  1.14  oster 	 * nparity) a read and write for each parity unit a block and
    527  1.14  oster 	 * commit node (2) a terminate node if atomic RMW an unlock
    528  1.14  oster 	 * node for each data unit, redundancy unit */
    529   1.3  oster 	totalNumNodes = (2 * numDataNodes) + (nfaults * numParityNodes)
    530   1.3  oster 	    + (nfaults * 2 * numParityNodes) + 3;
    531   1.3  oster 	if (lu_flag) {
    532   1.3  oster 		totalNumNodes += (numDataNodes + (nfaults * numParityNodes));
    533   1.3  oster 	}
    534   1.3  oster 	/*
    535   1.3  oster          * Step 2. create the nodes
    536   1.3  oster          */
    537  1.12  oster 	RF_MallocAndAdd(nodes, totalNumNodes * sizeof(RF_DagNode_t),
    538  1.12  oster 			(RF_DagNode_t *), allocList);
    539   1.3  oster 	i = 0;
    540   1.3  oster 	blockNode = &nodes[i];
    541   1.3  oster 	i += 1;
    542   1.3  oster 	commitNode = &nodes[i];
    543   1.3  oster 	i += 1;
    544   1.3  oster 	readDataNodes = &nodes[i];
    545   1.3  oster 	i += numDataNodes;
    546   1.3  oster 	readParityNodes = &nodes[i];
    547   1.3  oster 	i += numParityNodes;
    548   1.3  oster 	writeDataNodes = &nodes[i];
    549   1.3  oster 	i += numDataNodes;
    550   1.3  oster 	writeParityNodes = &nodes[i];
    551   1.3  oster 	i += numParityNodes;
    552   1.3  oster 	xorNodes = &nodes[i];
    553   1.3  oster 	i += numParityNodes;
    554   1.3  oster 	termNode = &nodes[i];
    555   1.3  oster 	i += 1;
    556   1.3  oster 	if (lu_flag) {
    557   1.3  oster 		unlockDataNodes = &nodes[i];
    558   1.3  oster 		i += numDataNodes;
    559   1.3  oster 		unlockParityNodes = &nodes[i];
    560   1.3  oster 		i += numParityNodes;
    561   1.3  oster 	} else {
    562   1.3  oster 		unlockDataNodes = unlockParityNodes = NULL;
    563   1.3  oster 	}
    564   1.3  oster 	if (nfaults == 2) {
    565   1.3  oster 		readQNodes = &nodes[i];
    566   1.3  oster 		i += numParityNodes;
    567   1.3  oster 		writeQNodes = &nodes[i];
    568   1.3  oster 		i += numParityNodes;
    569   1.3  oster 		qNodes = &nodes[i];
    570   1.3  oster 		i += numParityNodes;
    571   1.3  oster 		if (lu_flag) {
    572   1.3  oster 			unlockQNodes = &nodes[i];
    573   1.3  oster 			i += numParityNodes;
    574   1.3  oster 		} else {
    575   1.3  oster 			unlockQNodes = NULL;
    576   1.3  oster 		}
    577   1.3  oster 	} else {
    578   1.3  oster 		readQNodes = writeQNodes = qNodes = unlockQNodes = NULL;
    579   1.3  oster 	}
    580   1.3  oster 	RF_ASSERT(i == totalNumNodes);
    581   1.3  oster 
    582   1.3  oster 	/*
    583   1.3  oster          * Step 3. initialize the nodes
    584   1.3  oster          */
    585   1.3  oster 	/* initialize block node (Nil) */
    586   1.3  oster 	nNodes = numDataNodes + (nfaults * numParityNodes);
    587  1.14  oster 	rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc,
    588  1.14  oster 		    rf_NullNodeUndoFunc, NULL, nNodes, 0, 0, 0,
    589  1.14  oster 		    dag_h, "Nil", allocList);
    590   1.3  oster 
    591   1.3  oster 	/* initialize commit node (Cmt) */
    592  1.14  oster 	rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc,
    593  1.14  oster 		    rf_NullNodeUndoFunc, NULL, nNodes,
    594  1.14  oster 		    (nfaults * numParityNodes), 0, 0, dag_h, "Cmt", allocList);
    595   1.3  oster 
    596   1.3  oster 	/* initialize terminate node (Trm) */
    597  1.14  oster 	rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc,
    598  1.14  oster 		    rf_TerminateUndoFunc, NULL, 0, nNodes, 0, 0,
    599  1.14  oster 		    dag_h, "Trm", allocList);
    600   1.3  oster 
    601   1.3  oster 	/* initialize nodes which read old data (Rod) */
    602   1.3  oster 	for (i = 0; i < numDataNodes; i++) {
    603  1.14  oster 		rf_InitNode(&readDataNodes[i], rf_wait, RF_FALSE,
    604  1.14  oster 			    rf_DiskReadFunc, rf_DiskReadUndoFunc,
    605  1.14  oster 			    rf_GenericWakeupFunc, (nfaults * numParityNodes),
    606  1.14  oster 			    1, 4, 0, dag_h, "Rod", allocList);
    607   1.3  oster 		RF_ASSERT(pda != NULL);
    608   1.3  oster 		/* physical disk addr desc */
    609   1.3  oster 		readDataNodes[i].params[0].p = pda;
    610   1.3  oster 		/* buffer to hold old data */
    611   1.3  oster 		readDataNodes[i].params[1].p = rf_AllocBuffer(raidPtr,
    612   1.3  oster 		    dag_h, pda, allocList);
    613   1.3  oster 		readDataNodes[i].params[2].v = parityStripeID;
    614   1.3  oster 		readDataNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
    615   1.3  oster 		    lu_flag, 0, which_ru);
    616   1.3  oster 		pda = pda->next;
    617   1.3  oster 		for (j = 0; j < readDataNodes[i].numSuccedents; j++) {
    618   1.3  oster 			readDataNodes[i].propList[j] = NULL;
    619   1.3  oster 		}
    620   1.3  oster 	}
    621   1.3  oster 
    622   1.3  oster 	/* initialize nodes which read old parity (Rop) */
    623   1.3  oster 	pda = asmap->parityInfo;
    624   1.3  oster 	i = 0;
    625   1.3  oster 	for (i = 0; i < numParityNodes; i++) {
    626   1.3  oster 		RF_ASSERT(pda != NULL);
    627  1.14  oster 		rf_InitNode(&readParityNodes[i], rf_wait, RF_FALSE,
    628  1.14  oster 			    rf_DiskReadFunc, rf_DiskReadUndoFunc,
    629  1.14  oster 			    rf_GenericWakeupFunc, numParityNodes, 1, 4, 0,
    630  1.14  oster 			    dag_h, "Rop", allocList);
    631   1.3  oster 		readParityNodes[i].params[0].p = pda;
    632   1.3  oster 		/* buffer to hold old parity */
    633   1.3  oster 		readParityNodes[i].params[1].p = rf_AllocBuffer(raidPtr,
    634   1.3  oster 		    dag_h, pda, allocList);
    635   1.3  oster 		readParityNodes[i].params[2].v = parityStripeID;
    636   1.3  oster 		readParityNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
    637   1.3  oster 		    lu_flag, 0, which_ru);
    638   1.3  oster 		pda = pda->next;
    639   1.3  oster 		for (j = 0; j < readParityNodes[i].numSuccedents; j++) {
    640   1.3  oster 			readParityNodes[i].propList[0] = NULL;
    641   1.3  oster 		}
    642   1.3  oster 	}
    643   1.3  oster 
    644   1.3  oster 	/* initialize nodes which read old Q (Roq) */
    645   1.3  oster 	if (nfaults == 2) {
    646   1.3  oster 		pda = asmap->qInfo;
    647   1.3  oster 		for (i = 0; i < numParityNodes; i++) {
    648   1.3  oster 			RF_ASSERT(pda != NULL);
    649  1.14  oster 			rf_InitNode(&readQNodes[i], rf_wait, RF_FALSE,
    650  1.14  oster 				    rf_DiskReadFunc, rf_DiskReadUndoFunc,
    651  1.14  oster 				    rf_GenericWakeupFunc, numParityNodes,
    652  1.14  oster 				    1, 4, 0, dag_h, "Roq", allocList);
    653   1.3  oster 			readQNodes[i].params[0].p = pda;
    654   1.3  oster 			/* buffer to hold old Q */
    655  1.14  oster 			readQNodes[i].params[1].p = rf_AllocBuffer(raidPtr,
    656  1.14  oster 								   dag_h, pda,
    657  1.14  oster 								   allocList);
    658   1.3  oster 			readQNodes[i].params[2].v = parityStripeID;
    659   1.3  oster 			readQNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
    660   1.3  oster 			    lu_flag, 0, which_ru);
    661   1.3  oster 			pda = pda->next;
    662   1.3  oster 			for (j = 0; j < readQNodes[i].numSuccedents; j++) {
    663   1.3  oster 				readQNodes[i].propList[0] = NULL;
    664   1.3  oster 			}
    665   1.3  oster 		}
    666   1.3  oster 	}
    667   1.3  oster 	/* initialize nodes which write new data (Wnd) */
    668   1.3  oster 	pda = asmap->physInfo;
    669   1.3  oster 	for (i = 0; i < numDataNodes; i++) {
    670   1.3  oster 		RF_ASSERT(pda != NULL);
    671  1.14  oster 		rf_InitNode(&writeDataNodes[i], rf_wait, RF_FALSE,
    672  1.14  oster 			    rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
    673  1.14  oster 			    rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h,
    674  1.14  oster 			    "Wnd", allocList);
    675   1.3  oster 		/* physical disk addr desc */
    676   1.3  oster 		writeDataNodes[i].params[0].p = pda;
    677   1.3  oster 		/* buffer holding new data to be written */
    678   1.3  oster 		writeDataNodes[i].params[1].p = pda->bufPtr;
    679   1.3  oster 		writeDataNodes[i].params[2].v = parityStripeID;
    680   1.3  oster 		writeDataNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
    681   1.3  oster 		    0, 0, which_ru);
    682   1.3  oster 		if (lu_flag) {
    683   1.3  oster 			/* initialize node to unlock the disk queue */
    684  1.14  oster 			rf_InitNode(&unlockDataNodes[i], rf_wait, RF_FALSE,
    685  1.14  oster 				    rf_DiskUnlockFunc, rf_DiskUnlockUndoFunc,
    686  1.14  oster 				    rf_GenericWakeupFunc, 1, 1, 2, 0, dag_h,
    687  1.14  oster 				    "Und", allocList);
    688   1.3  oster 			/* physical disk addr desc */
    689   1.3  oster 			unlockDataNodes[i].params[0].p = pda;
    690   1.3  oster 			unlockDataNodes[i].params[1].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
    691   1.3  oster 			    0, lu_flag, which_ru);
    692   1.3  oster 		}
    693   1.3  oster 		pda = pda->next;
    694   1.3  oster 	}
    695   1.3  oster 
    696   1.3  oster 	/*
    697   1.3  oster          * Initialize nodes which compute new parity and Q.
    698   1.3  oster          */
    699   1.3  oster 	/*
    700   1.3  oster          * We use the simple XOR func in the double-XOR case, and when
    701  1.14  oster          * we're accessing only a portion of one stripe unit. The
    702  1.14  oster          * distinction between the two is that the regular XOR func
    703  1.14  oster          * assumes that the targbuf is a full SU in size, and examines
    704  1.14  oster          * the pda associated with the buffer to decide where within
    705  1.14  oster          * the buffer to XOR the data, whereas the simple XOR func
    706  1.14  oster          * just XORs the data into the start of the buffer.  */
    707   1.3  oster 	if ((numParityNodes == 2) || ((numDataNodes == 1)
    708  1.14  oster 		&& (asmap->totalSectorsAccessed <
    709  1.14  oster 		    raidPtr->Layout.sectorsPerStripeUnit))) {
    710   1.3  oster 		func = pfuncs->simple;
    711   1.3  oster 		undoFunc = rf_NullNodeUndoFunc;
    712   1.3  oster 		name = pfuncs->SimpleName;
    713   1.3  oster 		if (qfuncs) {
    714   1.3  oster 			qfunc = qfuncs->simple;
    715   1.3  oster 			qname = qfuncs->SimpleName;
    716   1.3  oster 		} else {
    717   1.3  oster 			qfunc = NULL;
    718   1.3  oster 			qname = NULL;
    719   1.3  oster 		}
    720   1.3  oster 	} else {
    721   1.3  oster 		func = pfuncs->regular;
    722   1.3  oster 		undoFunc = rf_NullNodeUndoFunc;
    723   1.3  oster 		name = pfuncs->RegularName;
    724   1.3  oster 		if (qfuncs) {
    725   1.3  oster 			qfunc = qfuncs->regular;
    726   1.3  oster 			qname = qfuncs->RegularName;
    727   1.3  oster 		} else {
    728   1.3  oster 			qfunc = NULL;
    729   1.3  oster 			qname = NULL;
    730   1.3  oster 		}
    731   1.3  oster 	}
    732   1.3  oster 	/*
    733   1.3  oster          * Initialize the xor nodes: params are {pda,buf}
    734   1.3  oster          * from {Rod,Wnd,Rop} nodes, and raidPtr
    735   1.3  oster          */
    736   1.3  oster 	if (numParityNodes == 2) {
    737   1.3  oster 		/* double-xor case */
    738   1.3  oster 		for (i = 0; i < numParityNodes; i++) {
    739   1.3  oster 			/* note: no wakeup func for xor */
    740  1.14  oster 			rf_InitNode(&xorNodes[i], rf_wait, RF_FALSE, func,
    741  1.14  oster 				    undoFunc, NULL, 1,
    742  1.14  oster 				    (numDataNodes + numParityNodes),
    743  1.14  oster 				    7, 1, dag_h, name, allocList);
    744   1.3  oster 			xorNodes[i].flags |= RF_DAGNODE_FLAG_YIELD;
    745   1.3  oster 			xorNodes[i].params[0] = readDataNodes[i].params[0];
    746   1.3  oster 			xorNodes[i].params[1] = readDataNodes[i].params[1];
    747   1.3  oster 			xorNodes[i].params[2] = readParityNodes[i].params[0];
    748   1.3  oster 			xorNodes[i].params[3] = readParityNodes[i].params[1];
    749   1.3  oster 			xorNodes[i].params[4] = writeDataNodes[i].params[0];
    750   1.3  oster 			xorNodes[i].params[5] = writeDataNodes[i].params[1];
    751   1.3  oster 			xorNodes[i].params[6].p = raidPtr;
    752   1.3  oster 			/* use old parity buf as target buf */
    753   1.3  oster 			xorNodes[i].results[0] = readParityNodes[i].params[1].p;
    754   1.3  oster 			if (nfaults == 2) {
    755   1.3  oster 				/* note: no wakeup func for qor */
    756  1.14  oster 				rf_InitNode(&qNodes[i], rf_wait, RF_FALSE,
    757  1.14  oster 					    qfunc, undoFunc, NULL, 1,
    758  1.14  oster 					    (numDataNodes + numParityNodes),
    759  1.14  oster 					    7, 1, dag_h, qname, allocList);
    760   1.3  oster 				qNodes[i].params[0] = readDataNodes[i].params[0];
    761   1.3  oster 				qNodes[i].params[1] = readDataNodes[i].params[1];
    762   1.3  oster 				qNodes[i].params[2] = readQNodes[i].params[0];
    763   1.3  oster 				qNodes[i].params[3] = readQNodes[i].params[1];
    764   1.3  oster 				qNodes[i].params[4] = writeDataNodes[i].params[0];
    765   1.3  oster 				qNodes[i].params[5] = writeDataNodes[i].params[1];
    766   1.3  oster 				qNodes[i].params[6].p = raidPtr;
    767   1.3  oster 				/* use old Q buf as target buf */
    768   1.3  oster 				qNodes[i].results[0] = readQNodes[i].params[1].p;
    769   1.3  oster 			}
    770   1.3  oster 		}
    771   1.3  oster 	} else {
    772   1.3  oster 		/* there is only one xor node in this case */
    773  1.14  oster 		rf_InitNode(&xorNodes[0], rf_wait, RF_FALSE, func,
    774  1.14  oster 			    undoFunc, NULL, 1, (numDataNodes + numParityNodes),
    775  1.14  oster 			    (2 * (numDataNodes + numDataNodes + 1) + 1), 1,
    776  1.14  oster 			    dag_h, name, allocList);
    777   1.3  oster 		xorNodes[0].flags |= RF_DAGNODE_FLAG_YIELD;
    778   1.3  oster 		for (i = 0; i < numDataNodes + 1; i++) {
    779   1.3  oster 			/* set up params related to Rod and Rop nodes */
    780   1.3  oster 			xorNodes[0].params[2 * i + 0] = readDataNodes[i].params[0];	/* pda */
    781   1.3  oster 			xorNodes[0].params[2 * i + 1] = readDataNodes[i].params[1];	/* buffer ptr */
    782   1.3  oster 		}
    783   1.3  oster 		for (i = 0; i < numDataNodes; i++) {
    784   1.3  oster 			/* set up params related to Wnd and Wnp nodes */
    785   1.3  oster 			xorNodes[0].params[2 * (numDataNodes + 1 + i) + 0] =	/* pda */
    786   1.3  oster 			    writeDataNodes[i].params[0];
    787   1.3  oster 			xorNodes[0].params[2 * (numDataNodes + 1 + i) + 1] =	/* buffer ptr */
    788   1.3  oster 			    writeDataNodes[i].params[1];
    789   1.3  oster 		}
    790   1.3  oster 		/* xor node needs to get at RAID information */
    791   1.3  oster 		xorNodes[0].params[2 * (numDataNodes + numDataNodes + 1)].p = raidPtr;
    792   1.3  oster 		xorNodes[0].results[0] = readParityNodes[0].params[1].p;
    793   1.3  oster 		if (nfaults == 2) {
    794  1.14  oster 			rf_InitNode(&qNodes[0], rf_wait, RF_FALSE, qfunc,
    795  1.14  oster 				    undoFunc, NULL, 1,
    796  1.14  oster 				    (numDataNodes + numParityNodes),
    797  1.14  oster 				    (2 * (numDataNodes + numDataNodes + 1) + 1), 1,
    798  1.14  oster 				    dag_h, qname, allocList);
    799   1.3  oster 			for (i = 0; i < numDataNodes; i++) {
    800   1.3  oster 				/* set up params related to Rod */
    801   1.3  oster 				qNodes[0].params[2 * i + 0] = readDataNodes[i].params[0];	/* pda */
    802   1.3  oster 				qNodes[0].params[2 * i + 1] = readDataNodes[i].params[1];	/* buffer ptr */
    803   1.3  oster 			}
    804   1.3  oster 			/* and read old q */
    805   1.3  oster 			qNodes[0].params[2 * numDataNodes + 0] =	/* pda */
    806   1.3  oster 			    readQNodes[0].params[0];
    807   1.3  oster 			qNodes[0].params[2 * numDataNodes + 1] =	/* buffer ptr */
    808   1.3  oster 			    readQNodes[0].params[1];
    809   1.3  oster 			for (i = 0; i < numDataNodes; i++) {
    810   1.3  oster 				/* set up params related to Wnd nodes */
    811   1.3  oster 				qNodes[0].params[2 * (numDataNodes + 1 + i) + 0] =	/* pda */
    812   1.3  oster 				    writeDataNodes[i].params[0];
    813   1.3  oster 				qNodes[0].params[2 * (numDataNodes + 1 + i) + 1] =	/* buffer ptr */
    814   1.3  oster 				    writeDataNodes[i].params[1];
    815   1.3  oster 			}
    816   1.3  oster 			/* xor node needs to get at RAID information */
    817   1.3  oster 			qNodes[0].params[2 * (numDataNodes + numDataNodes + 1)].p = raidPtr;
    818   1.3  oster 			qNodes[0].results[0] = readQNodes[0].params[1].p;
    819   1.3  oster 		}
    820   1.3  oster 	}
    821   1.3  oster 
    822   1.3  oster 	/* initialize nodes which write new parity (Wnp) */
    823   1.3  oster 	pda = asmap->parityInfo;
    824   1.3  oster 	for (i = 0; i < numParityNodes; i++) {
    825  1.14  oster 		rf_InitNode(&writeParityNodes[i], rf_wait, RF_FALSE,
    826  1.14  oster 			    rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
    827  1.14  oster 			    rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h,
    828  1.14  oster 			    "Wnp", allocList);
    829   1.3  oster 		RF_ASSERT(pda != NULL);
    830   1.3  oster 		writeParityNodes[i].params[0].p = pda;	/* param 1 (bufPtr)
    831   1.3  oster 							 * filled in by xor node */
    832   1.3  oster 		writeParityNodes[i].params[1].p = xorNodes[i].results[0];	/* buffer pointer for
    833   1.3  oster 										 * parity write
    834   1.3  oster 										 * operation */
    835   1.3  oster 		writeParityNodes[i].params[2].v = parityStripeID;
    836   1.3  oster 		writeParityNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
    837   1.3  oster 		    0, 0, which_ru);
    838   1.3  oster 		if (lu_flag) {
    839   1.3  oster 			/* initialize node to unlock the disk queue */
    840  1.14  oster 			rf_InitNode(&unlockParityNodes[i], rf_wait, RF_FALSE,
    841  1.14  oster 				    rf_DiskUnlockFunc, rf_DiskUnlockUndoFunc,
    842  1.14  oster 				    rf_GenericWakeupFunc, 1, 1, 2, 0, dag_h,
    843  1.14  oster 				    "Unp", allocList);
    844   1.3  oster 			unlockParityNodes[i].params[0].p = pda;	/* physical disk addr
    845   1.3  oster 								 * desc */
    846   1.3  oster 			unlockParityNodes[i].params[1].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
    847   1.3  oster 			    0, lu_flag, which_ru);
    848   1.3  oster 		}
    849   1.3  oster 		pda = pda->next;
    850   1.3  oster 	}
    851   1.3  oster 
    852   1.3  oster 	/* initialize nodes which write new Q (Wnq) */
    853   1.3  oster 	if (nfaults == 2) {
    854   1.3  oster 		pda = asmap->qInfo;
    855   1.3  oster 		for (i = 0; i < numParityNodes; i++) {
    856  1.14  oster 			rf_InitNode(&writeQNodes[i], rf_wait, RF_FALSE,
    857  1.14  oster 				    rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
    858  1.14  oster 				    rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h,
    859  1.14  oster 				    "Wnq", allocList);
    860   1.3  oster 			RF_ASSERT(pda != NULL);
    861   1.3  oster 			writeQNodes[i].params[0].p = pda;	/* param 1 (bufPtr)
    862   1.3  oster 								 * filled in by xor node */
    863   1.3  oster 			writeQNodes[i].params[1].p = qNodes[i].results[0];	/* buffer pointer for
    864   1.3  oster 										 * parity write
    865   1.3  oster 										 * operation */
    866   1.3  oster 			writeQNodes[i].params[2].v = parityStripeID;
    867   1.3  oster 			writeQNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
    868   1.3  oster 			    0, 0, which_ru);
    869   1.3  oster 			if (lu_flag) {
    870   1.3  oster 				/* initialize node to unlock the disk queue */
    871  1.14  oster 				rf_InitNode(&unlockQNodes[i], rf_wait,
    872  1.14  oster 					    RF_FALSE, rf_DiskUnlockFunc,
    873  1.14  oster 					    rf_DiskUnlockUndoFunc,
    874  1.14  oster 					    rf_GenericWakeupFunc, 1, 1, 2, 0,
    875  1.14  oster 					    dag_h, "Unq", allocList);
    876   1.3  oster 				unlockQNodes[i].params[0].p = pda;	/* physical disk addr
    877   1.3  oster 									 * desc */
    878   1.3  oster 				unlockQNodes[i].params[1].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY,
    879   1.3  oster 				    0, lu_flag, which_ru);
    880   1.3  oster 			}
    881   1.3  oster 			pda = pda->next;
    882   1.3  oster 		}
    883   1.3  oster 	}
    884   1.3  oster 	/*
    885   1.3  oster          * Step 4. connect the nodes.
    886   1.3  oster          */
    887   1.3  oster 
    888   1.3  oster 	/* connect header to block node */
    889   1.3  oster 	dag_h->succedents[0] = blockNode;
    890   1.3  oster 
    891   1.3  oster 	/* connect block node to read old data nodes */
    892   1.3  oster 	RF_ASSERT(blockNode->numSuccedents == (numDataNodes + (numParityNodes * nfaults)));
    893   1.3  oster 	for (i = 0; i < numDataNodes; i++) {
    894   1.3  oster 		blockNode->succedents[i] = &readDataNodes[i];
    895   1.3  oster 		RF_ASSERT(readDataNodes[i].numAntecedents == 1);
    896   1.3  oster 		readDataNodes[i].antecedents[0] = blockNode;
    897   1.3  oster 		readDataNodes[i].antType[0] = rf_control;
    898   1.3  oster 	}
    899   1.3  oster 
    900   1.3  oster 	/* connect block node to read old parity nodes */
    901   1.3  oster 	for (i = 0; i < numParityNodes; i++) {
    902   1.3  oster 		blockNode->succedents[numDataNodes + i] = &readParityNodes[i];
    903   1.3  oster 		RF_ASSERT(readParityNodes[i].numAntecedents == 1);
    904   1.3  oster 		readParityNodes[i].antecedents[0] = blockNode;
    905   1.3  oster 		readParityNodes[i].antType[0] = rf_control;
    906   1.3  oster 	}
    907   1.3  oster 
    908   1.3  oster 	/* connect block node to read old Q nodes */
    909   1.3  oster 	if (nfaults == 2) {
    910   1.3  oster 		for (i = 0; i < numParityNodes; i++) {
    911   1.3  oster 			blockNode->succedents[numDataNodes + numParityNodes + i] = &readQNodes[i];
    912   1.3  oster 			RF_ASSERT(readQNodes[i].numAntecedents == 1);
    913   1.3  oster 			readQNodes[i].antecedents[0] = blockNode;
    914   1.3  oster 			readQNodes[i].antType[0] = rf_control;
    915   1.3  oster 		}
    916   1.3  oster 	}
    917   1.3  oster 	/* connect read old data nodes to xor nodes */
    918   1.3  oster 	for (i = 0; i < numDataNodes; i++) {
    919   1.3  oster 		RF_ASSERT(readDataNodes[i].numSuccedents == (nfaults * numParityNodes));
    920   1.3  oster 		for (j = 0; j < numParityNodes; j++) {
    921   1.3  oster 			RF_ASSERT(xorNodes[j].numAntecedents == numDataNodes + numParityNodes);
    922   1.3  oster 			readDataNodes[i].succedents[j] = &xorNodes[j];
    923   1.3  oster 			xorNodes[j].antecedents[i] = &readDataNodes[i];
    924   1.3  oster 			xorNodes[j].antType[i] = rf_trueData;
    925   1.3  oster 		}
    926   1.3  oster 	}
    927   1.3  oster 
    928   1.3  oster 	/* connect read old data nodes to q nodes */
    929   1.3  oster 	if (nfaults == 2) {
    930   1.3  oster 		for (i = 0; i < numDataNodes; i++) {
    931   1.3  oster 			for (j = 0; j < numParityNodes; j++) {
    932   1.3  oster 				RF_ASSERT(qNodes[j].numAntecedents == numDataNodes + numParityNodes);
    933   1.3  oster 				readDataNodes[i].succedents[numParityNodes + j] = &qNodes[j];
    934   1.3  oster 				qNodes[j].antecedents[i] = &readDataNodes[i];
    935   1.3  oster 				qNodes[j].antType[i] = rf_trueData;
    936   1.3  oster 			}
    937   1.3  oster 		}
    938   1.3  oster 	}
    939   1.3  oster 	/* connect read old parity nodes to xor nodes */
    940   1.3  oster 	for (i = 0; i < numParityNodes; i++) {
    941   1.3  oster 		RF_ASSERT(readParityNodes[i].numSuccedents == numParityNodes);
    942   1.3  oster 		for (j = 0; j < numParityNodes; j++) {
    943   1.3  oster 			readParityNodes[i].succedents[j] = &xorNodes[j];
    944   1.3  oster 			xorNodes[j].antecedents[numDataNodes + i] = &readParityNodes[i];
    945   1.3  oster 			xorNodes[j].antType[numDataNodes + i] = rf_trueData;
    946   1.3  oster 		}
    947   1.3  oster 	}
    948   1.3  oster 
    949   1.3  oster 	/* connect read old q nodes to q nodes */
    950   1.3  oster 	if (nfaults == 2) {
    951   1.3  oster 		for (i = 0; i < numParityNodes; i++) {
    952   1.3  oster 			RF_ASSERT(readParityNodes[i].numSuccedents == numParityNodes);
    953   1.3  oster 			for (j = 0; j < numParityNodes; j++) {
    954   1.3  oster 				readQNodes[i].succedents[j] = &qNodes[j];
    955   1.3  oster 				qNodes[j].antecedents[numDataNodes + i] = &readQNodes[i];
    956   1.3  oster 				qNodes[j].antType[numDataNodes + i] = rf_trueData;
    957   1.3  oster 			}
    958   1.3  oster 		}
    959   1.3  oster 	}
    960   1.3  oster 	/* connect xor nodes to commit node */
    961   1.3  oster 	RF_ASSERT(commitNode->numAntecedents == (nfaults * numParityNodes));
    962   1.3  oster 	for (i = 0; i < numParityNodes; i++) {
    963   1.3  oster 		RF_ASSERT(xorNodes[i].numSuccedents == 1);
    964   1.3  oster 		xorNodes[i].succedents[0] = commitNode;
    965   1.3  oster 		commitNode->antecedents[i] = &xorNodes[i];
    966   1.3  oster 		commitNode->antType[i] = rf_control;
    967   1.3  oster 	}
    968   1.3  oster 
    969   1.3  oster 	/* connect q nodes to commit node */
    970   1.3  oster 	if (nfaults == 2) {
    971   1.3  oster 		for (i = 0; i < numParityNodes; i++) {
    972   1.3  oster 			RF_ASSERT(qNodes[i].numSuccedents == 1);
    973   1.3  oster 			qNodes[i].succedents[0] = commitNode;
    974   1.3  oster 			commitNode->antecedents[i + numParityNodes] = &qNodes[i];
    975   1.3  oster 			commitNode->antType[i + numParityNodes] = rf_control;
    976   1.3  oster 		}
    977   1.3  oster 	}
    978   1.3  oster 	/* connect commit node to write nodes */
    979   1.3  oster 	RF_ASSERT(commitNode->numSuccedents == (numDataNodes + (nfaults * numParityNodes)));
    980   1.3  oster 	for (i = 0; i < numDataNodes; i++) {
    981   1.3  oster 		RF_ASSERT(writeDataNodes[i].numAntecedents == 1);
    982   1.3  oster 		commitNode->succedents[i] = &writeDataNodes[i];
    983   1.3  oster 		writeDataNodes[i].antecedents[0] = commitNode;
    984   1.3  oster 		writeDataNodes[i].antType[0] = rf_trueData;
    985   1.3  oster 	}
    986   1.3  oster 	for (i = 0; i < numParityNodes; i++) {
    987   1.3  oster 		RF_ASSERT(writeParityNodes[i].numAntecedents == 1);
    988   1.3  oster 		commitNode->succedents[i + numDataNodes] = &writeParityNodes[i];
    989   1.3  oster 		writeParityNodes[i].antecedents[0] = commitNode;
    990   1.3  oster 		writeParityNodes[i].antType[0] = rf_trueData;
    991   1.3  oster 	}
    992   1.3  oster 	if (nfaults == 2) {
    993   1.3  oster 		for (i = 0; i < numParityNodes; i++) {
    994   1.3  oster 			RF_ASSERT(writeQNodes[i].numAntecedents == 1);
    995   1.3  oster 			commitNode->succedents[i + numDataNodes + numParityNodes] = &writeQNodes[i];
    996   1.3  oster 			writeQNodes[i].antecedents[0] = commitNode;
    997   1.3  oster 			writeQNodes[i].antType[0] = rf_trueData;
    998   1.3  oster 		}
    999   1.3  oster 	}
   1000   1.3  oster 	RF_ASSERT(termNode->numAntecedents == (numDataNodes + (nfaults * numParityNodes)));
   1001   1.3  oster 	RF_ASSERT(termNode->numSuccedents == 0);
   1002   1.3  oster 	for (i = 0; i < numDataNodes; i++) {
   1003   1.3  oster 		if (lu_flag) {
   1004   1.3  oster 			/* connect write new data nodes to unlock nodes */
   1005   1.3  oster 			RF_ASSERT(writeDataNodes[i].numSuccedents == 1);
   1006   1.3  oster 			RF_ASSERT(unlockDataNodes[i].numAntecedents == 1);
   1007   1.3  oster 			writeDataNodes[i].succedents[0] = &unlockDataNodes[i];
   1008   1.3  oster 			unlockDataNodes[i].antecedents[0] = &writeDataNodes[i];
   1009   1.3  oster 			unlockDataNodes[i].antType[0] = rf_control;
   1010   1.3  oster 
   1011   1.3  oster 			/* connect unlock nodes to term node */
   1012   1.3  oster 			RF_ASSERT(unlockDataNodes[i].numSuccedents == 1);
   1013   1.3  oster 			unlockDataNodes[i].succedents[0] = termNode;
   1014   1.3  oster 			termNode->antecedents[i] = &unlockDataNodes[i];
   1015   1.3  oster 			termNode->antType[i] = rf_control;
   1016   1.3  oster 		} else {
   1017   1.3  oster 			/* connect write new data nodes to term node */
   1018   1.3  oster 			RF_ASSERT(writeDataNodes[i].numSuccedents == 1);
   1019   1.3  oster 			RF_ASSERT(termNode->numAntecedents == (numDataNodes + (nfaults * numParityNodes)));
   1020   1.3  oster 			writeDataNodes[i].succedents[0] = termNode;
   1021   1.3  oster 			termNode->antecedents[i] = &writeDataNodes[i];
   1022   1.3  oster 			termNode->antType[i] = rf_control;
   1023   1.3  oster 		}
   1024   1.3  oster 	}
   1025   1.3  oster 
   1026   1.3  oster 	for (i = 0; i < numParityNodes; i++) {
   1027   1.3  oster 		if (lu_flag) {
   1028   1.3  oster 			/* connect write new parity nodes to unlock nodes */
   1029   1.3  oster 			RF_ASSERT(writeParityNodes[i].numSuccedents == 1);
   1030   1.3  oster 			RF_ASSERT(unlockParityNodes[i].numAntecedents == 1);
   1031   1.3  oster 			writeParityNodes[i].succedents[0] = &unlockParityNodes[i];
   1032   1.3  oster 			unlockParityNodes[i].antecedents[0] = &writeParityNodes[i];
   1033   1.3  oster 			unlockParityNodes[i].antType[0] = rf_control;
   1034   1.3  oster 
   1035   1.3  oster 			/* connect unlock nodes to term node */
   1036   1.3  oster 			RF_ASSERT(unlockParityNodes[i].numSuccedents == 1);
   1037   1.3  oster 			unlockParityNodes[i].succedents[0] = termNode;
   1038   1.3  oster 			termNode->antecedents[numDataNodes + i] = &unlockParityNodes[i];
   1039   1.3  oster 			termNode->antType[numDataNodes + i] = rf_control;
   1040   1.3  oster 		} else {
   1041   1.3  oster 			RF_ASSERT(writeParityNodes[i].numSuccedents == 1);
   1042   1.3  oster 			writeParityNodes[i].succedents[0] = termNode;
   1043   1.3  oster 			termNode->antecedents[numDataNodes + i] = &writeParityNodes[i];
   1044   1.3  oster 			termNode->antType[numDataNodes + i] = rf_control;
   1045   1.3  oster 		}
   1046   1.3  oster 	}
   1047   1.3  oster 
   1048   1.3  oster 	if (nfaults == 2) {
   1049   1.3  oster 		for (i = 0; i < numParityNodes; i++) {
   1050   1.3  oster 			if (lu_flag) {
   1051   1.3  oster 				/* connect write new Q nodes to unlock nodes */
   1052   1.3  oster 				RF_ASSERT(writeQNodes[i].numSuccedents == 1);
   1053   1.3  oster 				RF_ASSERT(unlockQNodes[i].numAntecedents == 1);
   1054   1.3  oster 				writeQNodes[i].succedents[0] = &unlockQNodes[i];
   1055   1.3  oster 				unlockQNodes[i].antecedents[0] = &writeQNodes[i];
   1056   1.3  oster 				unlockQNodes[i].antType[0] = rf_control;
   1057   1.3  oster 
   1058   1.3  oster 				/* connect unlock nodes to unblock node */
   1059   1.3  oster 				RF_ASSERT(unlockQNodes[i].numSuccedents == 1);
   1060   1.3  oster 				unlockQNodes[i].succedents[0] = termNode;
   1061   1.3  oster 				termNode->antecedents[numDataNodes + numParityNodes + i] = &unlockQNodes[i];
   1062   1.3  oster 				termNode->antType[numDataNodes + numParityNodes + i] = rf_control;
   1063   1.3  oster 			} else {
   1064   1.3  oster 				RF_ASSERT(writeQNodes[i].numSuccedents == 1);
   1065   1.3  oster 				writeQNodes[i].succedents[0] = termNode;
   1066   1.3  oster 				termNode->antecedents[numDataNodes + numParityNodes + i] = &writeQNodes[i];
   1067   1.3  oster 				termNode->antType[numDataNodes + numParityNodes + i] = rf_control;
   1068   1.3  oster 			}
   1069   1.3  oster 		}
   1070   1.3  oster 	}
   1071   1.1  oster }
   1072   1.1  oster 
   1073   1.1  oster 
   1074   1.1  oster /******************************************************************************
   1075   1.1  oster  * create a write graph (fault-free or degraded) for RAID level 1
   1076   1.1  oster  *
   1077   1.1  oster  * Hdr -> Commit -> Wpd -> Nil -> Trm
   1078   1.1  oster  *               -> Wsd ->
   1079   1.1  oster  *
   1080   1.1  oster  * The "Wpd" node writes data to the primary copy in the mirror pair
   1081   1.1  oster  * The "Wsd" node writes data to the secondary copy in the mirror pair
   1082   1.1  oster  *
   1083   1.1  oster  * Parameters:  raidPtr   - description of the physical array
   1084   1.1  oster  *              asmap     - logical & physical addresses for this access
   1085   1.1  oster  *              bp        - buffer ptr (holds write data)
   1086   1.3  oster  *              flags     - general flags (e.g. disk locking)
   1087   1.1  oster  *              allocList - list of memory allocated in DAG creation
   1088   1.1  oster  *****************************************************************************/
   1089   1.1  oster 
   1090   1.3  oster void
   1091  1.13  oster rf_CreateRaidOneWriteDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
   1092  1.13  oster 			 RF_DagHeader_t *dag_h, void *bp,
   1093  1.13  oster 			 RF_RaidAccessFlags_t flags,
   1094  1.13  oster 			 RF_AllocListElem_t *allocList)
   1095   1.1  oster {
   1096   1.3  oster 	RF_DagNode_t *unblockNode, *termNode, *commitNode;
   1097   1.3  oster 	RF_DagNode_t *nodes, *wndNode, *wmirNode;
   1098   1.3  oster 	int     nWndNodes, nWmirNodes, i;
   1099   1.3  oster 	RF_ReconUnitNum_t which_ru;
   1100   1.3  oster 	RF_PhysDiskAddr_t *pda, *pdaP;
   1101   1.3  oster 	RF_StripeNum_t parityStripeID;
   1102   1.3  oster 
   1103   1.3  oster 	parityStripeID = rf_RaidAddressToParityStripeID(&(raidPtr->Layout),
   1104   1.3  oster 	    asmap->raidAddress, &which_ru);
   1105   1.3  oster 	if (rf_dagDebug) {
   1106   1.3  oster 		printf("[Creating RAID level 1 write DAG]\n");
   1107   1.3  oster 	}
   1108   1.3  oster 	dag_h->creator = "RaidOneWriteDAG";
   1109   1.3  oster 
   1110   1.3  oster 	/* 2 implies access not SU aligned */
   1111   1.3  oster 	nWmirNodes = (asmap->parityInfo->next) ? 2 : 1;
   1112   1.3  oster 	nWndNodes = (asmap->physInfo->next) ? 2 : 1;
   1113   1.3  oster 
   1114   1.3  oster 	/* alloc the Wnd nodes and the Wmir node */
   1115   1.3  oster 	if (asmap->numDataFailed == 1)
   1116   1.3  oster 		nWndNodes--;
   1117   1.3  oster 	if (asmap->numParityFailed == 1)
   1118   1.3  oster 		nWmirNodes--;
   1119   1.3  oster 
   1120   1.3  oster 	/* total number of nodes = nWndNodes + nWmirNodes + (commit + unblock
   1121   1.3  oster 	 * + terminator) */
   1122  1.12  oster 	RF_MallocAndAdd(nodes,
   1123  1.12  oster 			(nWndNodes + nWmirNodes + 3) * sizeof(RF_DagNode_t),
   1124  1.12  oster 			(RF_DagNode_t *), allocList);
   1125   1.3  oster 	i = 0;
   1126   1.3  oster 	wndNode = &nodes[i];
   1127   1.3  oster 	i += nWndNodes;
   1128   1.3  oster 	wmirNode = &nodes[i];
   1129   1.3  oster 	i += nWmirNodes;
   1130   1.3  oster 	commitNode = &nodes[i];
   1131   1.3  oster 	i += 1;
   1132   1.3  oster 	unblockNode = &nodes[i];
   1133   1.3  oster 	i += 1;
   1134   1.3  oster 	termNode = &nodes[i];
   1135   1.3  oster 	i += 1;
   1136   1.3  oster 	RF_ASSERT(i == (nWndNodes + nWmirNodes + 3));
   1137   1.3  oster 
   1138   1.3  oster 	/* this dag can commit immediately */
   1139   1.3  oster 	dag_h->numCommitNodes = 1;
   1140   1.3  oster 	dag_h->numCommits = 0;
   1141   1.3  oster 	dag_h->numSuccedents = 1;
   1142   1.3  oster 
   1143   1.3  oster 	/* initialize the commit, unblock, and term nodes */
   1144  1.14  oster 	rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc,
   1145  1.14  oster 		    rf_NullNodeUndoFunc, NULL, (nWndNodes + nWmirNodes),
   1146  1.14  oster 		    0, 0, 0, dag_h, "Cmt", allocList);
   1147  1.14  oster 	rf_InitNode(unblockNode, rf_wait, RF_FALSE, rf_NullNodeFunc,
   1148  1.14  oster 		    rf_NullNodeUndoFunc, NULL, 1, (nWndNodes + nWmirNodes),
   1149  1.14  oster 		    0, 0, dag_h, "Nil", allocList);
   1150  1.14  oster 	rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc,
   1151  1.14  oster 		    rf_TerminateUndoFunc, NULL, 0, 1, 0, 0,
   1152  1.14  oster 		    dag_h, "Trm", allocList);
   1153   1.3  oster 
   1154   1.3  oster 	/* initialize the wnd nodes */
   1155   1.3  oster 	if (nWndNodes > 0) {
   1156   1.3  oster 		pda = asmap->physInfo;
   1157   1.3  oster 		for (i = 0; i < nWndNodes; i++) {
   1158  1.14  oster 			rf_InitNode(&wndNode[i], rf_wait, RF_FALSE,
   1159  1.14  oster 				    rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
   1160  1.14  oster 				    rf_GenericWakeupFunc, 1, 1, 4, 0,
   1161  1.14  oster 				    dag_h, "Wpd", allocList);
   1162   1.3  oster 			RF_ASSERT(pda != NULL);
   1163   1.3  oster 			wndNode[i].params[0].p = pda;
   1164   1.3  oster 			wndNode[i].params[1].p = pda->bufPtr;
   1165   1.3  oster 			wndNode[i].params[2].v = parityStripeID;
   1166   1.3  oster 			wndNode[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
   1167   1.3  oster 			pda = pda->next;
   1168   1.3  oster 		}
   1169   1.3  oster 		RF_ASSERT(pda == NULL);
   1170   1.3  oster 	}
   1171   1.3  oster 	/* initialize the mirror nodes */
   1172   1.3  oster 	if (nWmirNodes > 0) {
   1173   1.3  oster 		pda = asmap->physInfo;
   1174   1.3  oster 		pdaP = asmap->parityInfo;
   1175   1.3  oster 		for (i = 0; i < nWmirNodes; i++) {
   1176  1.14  oster 			rf_InitNode(&wmirNode[i], rf_wait, RF_FALSE,
   1177  1.14  oster 				    rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
   1178  1.14  oster 				    rf_GenericWakeupFunc, 1, 1, 4, 0,
   1179  1.14  oster 				    dag_h, "Wsd", allocList);
   1180   1.3  oster 			RF_ASSERT(pda != NULL);
   1181   1.3  oster 			wmirNode[i].params[0].p = pdaP;
   1182   1.3  oster 			wmirNode[i].params[1].p = pda->bufPtr;
   1183   1.3  oster 			wmirNode[i].params[2].v = parityStripeID;
   1184   1.3  oster 			wmirNode[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
   1185   1.3  oster 			pda = pda->next;
   1186   1.3  oster 			pdaP = pdaP->next;
   1187   1.3  oster 		}
   1188   1.3  oster 		RF_ASSERT(pda == NULL);
   1189   1.3  oster 		RF_ASSERT(pdaP == NULL);
   1190   1.3  oster 	}
   1191   1.3  oster 	/* link the header node to the commit node */
   1192   1.3  oster 	RF_ASSERT(dag_h->numSuccedents == 1);
   1193   1.3  oster 	RF_ASSERT(commitNode->numAntecedents == 0);
   1194   1.3  oster 	dag_h->succedents[0] = commitNode;
   1195   1.3  oster 
   1196   1.3  oster 	/* link the commit node to the write nodes */
   1197   1.3  oster 	RF_ASSERT(commitNode->numSuccedents == (nWndNodes + nWmirNodes));
   1198   1.3  oster 	for (i = 0; i < nWndNodes; i++) {
   1199   1.3  oster 		RF_ASSERT(wndNode[i].numAntecedents == 1);
   1200   1.3  oster 		commitNode->succedents[i] = &wndNode[i];
   1201   1.3  oster 		wndNode[i].antecedents[0] = commitNode;
   1202   1.3  oster 		wndNode[i].antType[0] = rf_control;
   1203   1.3  oster 	}
   1204   1.3  oster 	for (i = 0; i < nWmirNodes; i++) {
   1205   1.3  oster 		RF_ASSERT(wmirNode[i].numAntecedents == 1);
   1206   1.3  oster 		commitNode->succedents[i + nWndNodes] = &wmirNode[i];
   1207   1.3  oster 		wmirNode[i].antecedents[0] = commitNode;
   1208   1.3  oster 		wmirNode[i].antType[0] = rf_control;
   1209   1.3  oster 	}
   1210   1.3  oster 
   1211   1.3  oster 	/* link the write nodes to the unblock node */
   1212   1.3  oster 	RF_ASSERT(unblockNode->numAntecedents == (nWndNodes + nWmirNodes));
   1213   1.3  oster 	for (i = 0; i < nWndNodes; i++) {
   1214   1.3  oster 		RF_ASSERT(wndNode[i].numSuccedents == 1);
   1215   1.3  oster 		wndNode[i].succedents[0] = unblockNode;
   1216   1.3  oster 		unblockNode->antecedents[i] = &wndNode[i];
   1217   1.3  oster 		unblockNode->antType[i] = rf_control;
   1218   1.3  oster 	}
   1219   1.3  oster 	for (i = 0; i < nWmirNodes; i++) {
   1220   1.3  oster 		RF_ASSERT(wmirNode[i].numSuccedents == 1);
   1221   1.3  oster 		wmirNode[i].succedents[0] = unblockNode;
   1222   1.3  oster 		unblockNode->antecedents[i + nWndNodes] = &wmirNode[i];
   1223   1.3  oster 		unblockNode->antType[i + nWndNodes] = rf_control;
   1224   1.3  oster 	}
   1225   1.3  oster 
   1226   1.3  oster 	/* link the unblock node to the term node */
   1227   1.3  oster 	RF_ASSERT(unblockNode->numSuccedents == 1);
   1228   1.3  oster 	RF_ASSERT(termNode->numAntecedents == 1);
   1229   1.3  oster 	RF_ASSERT(termNode->numSuccedents == 0);
   1230   1.3  oster 	unblockNode->succedents[0] = termNode;
   1231   1.3  oster 	termNode->antecedents[0] = unblockNode;
   1232   1.3  oster 	termNode->antType[0] = rf_control;
   1233   1.1  oster }
   1234