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