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