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