rf_dagdegwr.c revision 1.22 1 /* $NetBSD: rf_dagdegwr.c,v 1.22 2004/03/21 03:22:08 oster Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
5 *
6 * Author: Mark Holland, Daniel Stodolsky, 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 * rf_dagdegwr.c
31 *
32 * code for creating degraded write DAGs
33 *
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: rf_dagdegwr.c,v 1.22 2004/03/21 03:22:08 oster Exp $");
38
39 #include <dev/raidframe/raidframevar.h>
40
41 #include "rf_raid.h"
42 #include "rf_dag.h"
43 #include "rf_dagutils.h"
44 #include "rf_dagfuncs.h"
45 #include "rf_debugMem.h"
46 #include "rf_general.h"
47 #include "rf_dagdegwr.h"
48 #include "rf_map.h"
49
50
51 /******************************************************************************
52 *
53 * General comments on DAG creation:
54 *
55 * All DAGs in this file use roll-away error recovery. Each DAG has a single
56 * commit node, usually called "Cmt." If an error occurs before the Cmt node
57 * is reached, the execution engine will halt forward execution and work
58 * backward through the graph, executing the undo functions. Assuming that
59 * each node in the graph prior to the Cmt node are undoable and atomic - or -
60 * does not make changes to permanent state, the graph will fail atomically.
61 * If an error occurs after the Cmt node executes, the engine will roll-forward
62 * through the graph, blindly executing nodes until it reaches the end.
63 * If a graph reaches the end, it is assumed to have completed successfully.
64 *
65 * A graph has only 1 Cmt node.
66 *
67 */
68
69
70 /******************************************************************************
71 *
72 * The following wrappers map the standard DAG creation interface to the
73 * DAG creation routines. Additionally, these wrappers enable experimentation
74 * with new DAG structures by providing an extra level of indirection, allowing
75 * the DAG creation routines to be replaced at this single point.
76 */
77
78 static
79 RF_CREATE_DAG_FUNC_DECL(rf_CreateSimpleDegradedWriteDAG)
80 {
81 rf_CommonCreateSimpleDegradedWriteDAG(raidPtr, asmap, dag_h, bp,
82 flags, allocList, 1, rf_RecoveryXorFunc, RF_TRUE);
83 }
84
85 void
86 rf_CreateDegradedWriteDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
87 RF_DagHeader_t *dag_h, void *bp,
88 RF_RaidAccessFlags_t flags,
89 RF_AllocListElem_t *allocList)
90 {
91
92 RF_ASSERT(asmap->numDataFailed == 1);
93 dag_h->creator = "DegradedWriteDAG";
94
95 /*
96 * if the access writes only a portion of the failed unit, and also
97 * writes some portion of at least one surviving unit, we create two
98 * DAGs, one for the failed component and one for the non-failed
99 * component, and do them sequentially. Note that the fact that we're
100 * accessing only a portion of the failed unit indicates that the
101 * access either starts or ends in the failed unit, and hence we need
102 * create only two dags. This is inefficient in that the same data or
103 * parity can get read and written twice using this structure. I need
104 * to fix this to do the access all at once.
105 */
106 RF_ASSERT(!(asmap->numStripeUnitsAccessed != 1 &&
107 asmap->failedPDAs[0]->numSector !=
108 raidPtr->Layout.sectorsPerStripeUnit));
109 rf_CreateSimpleDegradedWriteDAG(raidPtr, asmap, dag_h, bp, flags,
110 allocList);
111 }
112
113
114
115 /******************************************************************************
116 *
117 * DAG creation code begins here
118 */
119
120
121
122 /******************************************************************************
123 *
124 * CommonCreateSimpleDegradedWriteDAG -- creates a DAG to do a degraded-mode
125 * write, which is as follows
126 *
127 * / {Wnq} --\
128 * hdr -> blockNode -> Rod -> Xor -> Cmt -> Wnp ----> unblock -> term
129 * \ {Rod} / \ Wnd ---/
130 * \ {Wnd} -/
131 *
132 * commit nodes: Xor, Wnd
133 *
134 * IMPORTANT:
135 * This DAG generator does not work for double-degraded archs since it does not
136 * generate Q
137 *
138 * This dag is essentially identical to the large-write dag, except that the
139 * write to the failed data unit is suppressed.
140 *
141 * IMPORTANT: this dag does not work in the case where the access writes only
142 * a portion of the failed unit, and also writes some portion of at least one
143 * surviving SU. this case is handled in CreateDegradedWriteDAG above.
144 *
145 * The block & unblock nodes are leftovers from a previous version. They
146 * do nothing, but I haven't deleted them because it would be a tremendous
147 * effort to put them back in.
148 *
149 * This dag is used whenever a one of the data units in a write has failed.
150 * If it is the parity unit that failed, the nonredundant write dag (below)
151 * is used.
152 *****************************************************************************/
153
154 void
155 rf_CommonCreateSimpleDegradedWriteDAG(RF_Raid_t *raidPtr,
156 RF_AccessStripeMap_t *asmap,
157 RF_DagHeader_t *dag_h, void *bp,
158 RF_RaidAccessFlags_t flags,
159 RF_AllocListElem_t *allocList,
160 int nfaults,
161 int (*redFunc) (RF_DagNode_t *),
162 int allowBufferRecycle)
163 {
164 int nNodes, nRrdNodes, nWndNodes, nXorBufs, i, j, paramNum,
165 rdnodesFaked;
166 RF_DagNode_t *blockNode, *unblockNode, *wnpNode, *wnqNode, *termNode;
167 RF_DagNode_t *wndNodes, *rrdNodes, *xorNode, *commitNode;
168 RF_DagNode_t *tmpNode, *tmpwndNode, *tmprrdNode;
169 RF_SectorCount_t sectorsPerSU;
170 RF_ReconUnitNum_t which_ru;
171 char *xorTargetBuf = NULL; /* the target buffer for the XOR
172 * operation */
173 char overlappingPDAs[RF_MAXCOL];/* a temporary array of flags */
174 RF_AccessStripeMapHeader_t *new_asm_h[2];
175 RF_PhysDiskAddr_t *pda, *parityPDA;
176 RF_StripeNum_t parityStripeID;
177 RF_PhysDiskAddr_t *failedPDA;
178 RF_RaidLayout_t *layoutPtr;
179
180 layoutPtr = &(raidPtr->Layout);
181 parityStripeID = rf_RaidAddressToParityStripeID(layoutPtr, asmap->raidAddress,
182 &which_ru);
183 sectorsPerSU = layoutPtr->sectorsPerStripeUnit;
184 /* failedPDA points to the pda within the asm that targets the failed
185 * disk */
186 failedPDA = asmap->failedPDAs[0];
187
188 #if RF_DEBUG_DAG
189 if (rf_dagDebug)
190 printf("[Creating degraded-write DAG]\n");
191 #endif
192
193 RF_ASSERT(asmap->numDataFailed == 1);
194 dag_h->creator = "SimpleDegradedWriteDAG";
195
196 /*
197 * Generate two ASMs identifying the surviving data
198 * we need in order to recover the lost data.
199 */
200 /* overlappingPDAs array must be zero'd */
201 memset(overlappingPDAs, 0, RF_MAXCOL);
202 rf_GenerateFailedAccessASMs(raidPtr, asmap, failedPDA, dag_h, new_asm_h,
203 &nXorBufs, NULL, overlappingPDAs, allocList);
204
205 /* create all the nodes at once */
206 nWndNodes = asmap->numStripeUnitsAccessed - 1; /* no access is
207 * generated for the
208 * failed pda */
209
210 nRrdNodes = ((new_asm_h[0]) ? new_asm_h[0]->stripeMap->numStripeUnitsAccessed : 0) +
211 ((new_asm_h[1]) ? new_asm_h[1]->stripeMap->numStripeUnitsAccessed : 0);
212 /*
213 * XXX
214 *
215 * There's a bug with a complete stripe overwrite- that means 0 reads
216 * of old data, and the rest of the DAG generation code doesn't like
217 * that. A release is coming, and I don't wanna risk breaking a critical
218 * DAG generator, so here's what I'm gonna do- if there's no read nodes,
219 * I'm gonna fake there being a read node, and I'm gonna swap in a
220 * no-op node in its place (to make all the link-up code happy).
221 * This should be fixed at some point. --jimz
222 */
223 if (nRrdNodes == 0) {
224 nRrdNodes = 1;
225 rdnodesFaked = 1;
226 } else {
227 rdnodesFaked = 0;
228 }
229 /* lock, unlock, xor, Wnd, Rrd, W(nfaults) */
230 nNodes = 5 + nfaults + nWndNodes + nRrdNodes;
231
232 blockNode = rf_AllocDAGNode();
233 blockNode->list_next = dag_h->nodes;
234 dag_h->nodes = blockNode;
235
236 commitNode = rf_AllocDAGNode();
237 commitNode->list_next = dag_h->nodes;
238 dag_h->nodes = commitNode;
239
240 unblockNode = rf_AllocDAGNode();
241 unblockNode->list_next = dag_h->nodes;
242 dag_h->nodes = unblockNode;
243
244 termNode = rf_AllocDAGNode();
245 termNode->list_next = dag_h->nodes;
246 dag_h->nodes = termNode;
247
248 xorNode = rf_AllocDAGNode();
249 xorNode->list_next = dag_h->nodes;
250 dag_h->nodes = xorNode;
251
252 wnpNode = rf_AllocDAGNode();
253 wnpNode->list_next = dag_h->nodes;
254 dag_h->nodes = wnpNode;
255
256 for (i = 0; i < nWndNodes; i++) {
257 tmpNode = rf_AllocDAGNode();
258 tmpNode->list_next = dag_h->nodes;
259 dag_h->nodes = tmpNode;
260 }
261 wndNodes = dag_h->nodes;
262
263 for (i = 0; i < nRrdNodes; i++) {
264 tmpNode = rf_AllocDAGNode();
265 tmpNode->list_next = dag_h->nodes;
266 dag_h->nodes = tmpNode;
267 }
268 rrdNodes = dag_h->nodes;
269
270 #if (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0)
271 if (nfaults == 2) {
272 wnqNode = rf_AllocDAGNode();
273 wnqNode->list_next = dag_h->nodes;
274 dag_h->nodes = wnqNode;
275 } else {
276 #endif
277 wnqNode = NULL;
278 #if (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0)
279 }
280 #endif
281 RF_ASSERT(i == nNodes);
282
283 /* this dag can not commit until all rrd and xor Nodes have completed */
284 dag_h->numCommitNodes = 1;
285 dag_h->numCommits = 0;
286 dag_h->numSuccedents = 1;
287
288 RF_ASSERT(nRrdNodes > 0);
289 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
290 NULL, nRrdNodes, 0, 0, 0, dag_h, "Nil", allocList);
291 rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
292 NULL, nWndNodes + nfaults, 1, 0, 0, dag_h, "Cmt", allocList);
293 rf_InitNode(unblockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
294 NULL, 1, nWndNodes + nfaults, 0, 0, dag_h, "Nil", allocList);
295 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc,
296 NULL, 0, 1, 0, 0, dag_h, "Trm", allocList);
297 rf_InitNode(xorNode, rf_wait, RF_FALSE, redFunc, rf_NullNodeUndoFunc, NULL, 1,
298 nRrdNodes, 2 * nXorBufs + 2, nfaults, dag_h, "Xrc", allocList);
299
300 /*
301 * Fill in the Rrd nodes. If any of the rrd buffers are the same size as
302 * the failed buffer, save a pointer to it so we can use it as the target
303 * of the XOR. The pdas in the rrd nodes have been range-restricted, so if
304 * a buffer is the same size as the failed buffer, it must also be at the
305 * same alignment within the SU.
306 */
307 i = 0;
308 tmprrdNode = rrdNodes;
309 if (new_asm_h[0]) {
310 for (i = 0, pda = new_asm_h[0]->stripeMap->physInfo;
311 i < new_asm_h[0]->stripeMap->numStripeUnitsAccessed;
312 i++, pda = pda->next) {
313 rf_InitNode(tmprrdNode, rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc,
314 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Rrd", allocList);
315 RF_ASSERT(pda);
316 tmprrdNode->params[0].p = pda;
317 tmprrdNode->params[1].p = pda->bufPtr;
318 tmprrdNode->params[2].v = parityStripeID;
319 tmprrdNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
320 tmprrdNode = tmprrdNode->list_next;
321 }
322 }
323 /* i now equals the number of stripe units accessed in new_asm_h[0] */
324 /* Note that for tmprrdNode, this means a continuation from above, so no need to
325 assign it anything.. */
326 if (new_asm_h[1]) {
327 for (j = 0, pda = new_asm_h[1]->stripeMap->physInfo;
328 j < new_asm_h[1]->stripeMap->numStripeUnitsAccessed;
329 j++, pda = pda->next) {
330 rf_InitNode(tmprrdNode, rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc,
331 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Rrd", allocList);
332 RF_ASSERT(pda);
333 tmprrdNode->params[0].p = pda;
334 tmprrdNode->params[1].p = pda->bufPtr;
335 tmprrdNode->params[2].v = parityStripeID;
336 tmprrdNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
337 if (allowBufferRecycle && (pda->numSector == failedPDA->numSector))
338 xorTargetBuf = pda->bufPtr;
339 tmprrdNode = tmprrdNode->list_next;
340 }
341 }
342 if (rdnodesFaked) {
343 /*
344 * This is where we'll init that fake noop read node
345 * (XXX should the wakeup func be different?)
346 */
347 /* node that rrdNodes will just be a single node... */
348 rf_InitNode(rrdNodes, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
349 NULL, 1, 1, 0, 0, dag_h, "RrN", allocList);
350 }
351 /*
352 * Make a PDA for the parity unit. The parity PDA should start at
353 * the same offset into the SU as the failed PDA.
354 */
355 /* Danner comment: I don't think this copy is really necessary. We are
356 * in one of two cases here. (1) The entire failed unit is written.
357 * Then asmap->parityInfo will describe the entire parity. (2) We are
358 * only writing a subset of the failed unit and nothing else. Then the
359 * asmap->parityInfo describes the failed unit and the copy can also
360 * be avoided. */
361
362 parityPDA = rf_AllocPhysDiskAddr();
363 parityPDA->next = dag_h->pda_cleanup_list;
364 dag_h->pda_cleanup_list = parityPDA;
365 parityPDA->col = asmap->parityInfo->col;
366 parityPDA->startSector = ((asmap->parityInfo->startSector / sectorsPerSU)
367 * sectorsPerSU) + (failedPDA->startSector % sectorsPerSU);
368 parityPDA->numSector = failedPDA->numSector;
369
370 if (!xorTargetBuf) {
371 xorTargetBuf = rf_AllocBuffer(raidPtr, dag_h,
372 rf_RaidAddressToByte(raidPtr, failedPDA->numSector));
373 }
374 /* init the Wnp node */
375 rf_InitNode(wnpNode, rf_wait, RF_FALSE, rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
376 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Wnp", allocList);
377 wnpNode->params[0].p = parityPDA;
378 wnpNode->params[1].p = xorTargetBuf;
379 wnpNode->params[2].v = parityStripeID;
380 wnpNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
381
382 #if (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0)
383 /* fill in the Wnq Node */
384 if (nfaults == 2) {
385 {
386 RF_MallocAndAdd(parityPDA, sizeof(RF_PhysDiskAddr_t),
387 (RF_PhysDiskAddr_t *), allocList);
388 parityPDA->col = asmap->qInfo->col;
389 parityPDA->startSector = ((asmap->qInfo->startSector / sectorsPerSU)
390 * sectorsPerSU) + (failedPDA->startSector % sectorsPerSU);
391 parityPDA->numSector = failedPDA->numSector;
392
393 rf_InitNode(wnqNode, rf_wait, RF_FALSE, rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
394 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Wnq", allocList);
395 wnqNode->params[0].p = parityPDA;
396 RF_MallocAndAdd(xorNode->results[1],
397 rf_RaidAddressToByte(raidPtr, failedPDA->numSector), (char *), allocList);
398 wnqNode->params[1].p = xorNode->results[1];
399 wnqNode->params[2].v = parityStripeID;
400 wnqNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
401 }
402 }
403 #endif
404 /* fill in the Wnd nodes */
405 tmpwndNode = wndNodes;
406 for (pda = asmap->physInfo, i = 0; i < nWndNodes; i++, pda = pda->next) {
407 if (pda == failedPDA) {
408 i--;
409 continue;
410 }
411 rf_InitNode(tmpwndNode, rf_wait, RF_FALSE, rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
412 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Wnd", allocList);
413 RF_ASSERT(pda);
414 tmpwndNode->params[0].p = pda;
415 tmpwndNode->params[1].p = pda->bufPtr;
416 tmpwndNode->params[2].v = parityStripeID;
417 tmpwndNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
418 tmpwndNode = tmpwndNode->list_next;
419 }
420
421 /* fill in the results of the xor node */
422 xorNode->results[0] = xorTargetBuf;
423
424 /* fill in the params of the xor node */
425
426 paramNum = 0;
427 if (rdnodesFaked == 0) {
428 tmprrdNode = rrdNodes;
429 for (i = 0; i < nRrdNodes; i++) {
430 /* all the Rrd nodes need to be xored together */
431 xorNode->params[paramNum++] = tmprrdNode->params[0];
432 xorNode->params[paramNum++] = tmprrdNode->params[1];
433 tmprrdNode = tmprrdNode->list_next;
434 }
435 }
436 tmpwndNode = wndNodes;
437 for (i = 0; i < nWndNodes; i++) {
438 /* any Wnd nodes that overlap the failed access need to be
439 * xored in */
440 if (overlappingPDAs[i]) {
441 pda = rf_AllocPhysDiskAddr();
442 memcpy((char *) pda, (char *) tmpwndNode->params[0].p, sizeof(RF_PhysDiskAddr_t));
443 /* add it into the pda_cleanup_list *after* the copy, TYVM */
444 pda->next = dag_h->pda_cleanup_list;
445 dag_h->pda_cleanup_list = pda;
446 rf_RangeRestrictPDA(raidPtr, failedPDA, pda, RF_RESTRICT_DOBUFFER, 0);
447 xorNode->params[paramNum++].p = pda;
448 xorNode->params[paramNum++].p = pda->bufPtr;
449 }
450 tmpwndNode = tmpwndNode->list_next;
451 }
452
453 /*
454 * Install the failed PDA into the xor param list so that the
455 * new data gets xor'd in.
456 */
457 xorNode->params[paramNum++].p = failedPDA;
458 xorNode->params[paramNum++].p = failedPDA->bufPtr;
459
460 /*
461 * The last 2 params to the recovery xor node are always the failed
462 * PDA and the raidPtr. install the failedPDA even though we have just
463 * done so above. This allows us to use the same XOR function for both
464 * degraded reads and degraded writes.
465 */
466 xorNode->params[paramNum++].p = failedPDA;
467 xorNode->params[paramNum++].p = raidPtr;
468 RF_ASSERT(paramNum == 2 * nXorBufs + 2);
469
470 /*
471 * Code to link nodes begins here
472 */
473
474 /* link header to block node */
475 RF_ASSERT(blockNode->numAntecedents == 0);
476 dag_h->succedents[0] = blockNode;
477
478 /* link block node to rd nodes */
479 RF_ASSERT(blockNode->numSuccedents == nRrdNodes);
480 tmprrdNode = rrdNodes;
481 for (i = 0; i < nRrdNodes; i++) {
482 RF_ASSERT(tmprrdNode->numAntecedents == 1);
483 blockNode->succedents[i] = tmprrdNode;
484 tmprrdNode->antecedents[0] = blockNode;
485 tmprrdNode->antType[0] = rf_control;
486 tmprrdNode = tmprrdNode->list_next;
487 }
488
489 /* link read nodes to xor node */
490 RF_ASSERT(xorNode->numAntecedents == nRrdNodes);
491 tmprrdNode = rrdNodes;
492 for (i = 0; i < nRrdNodes; i++) {
493 RF_ASSERT(tmprrdNode->numSuccedents == 1);
494 tmprrdNode->succedents[0] = xorNode;
495 xorNode->antecedents[i] = tmprrdNode;
496 xorNode->antType[i] = rf_trueData;
497 tmprrdNode = tmprrdNode->list_next;
498 }
499
500 /* link xor node to commit node */
501 RF_ASSERT(xorNode->numSuccedents == 1);
502 RF_ASSERT(commitNode->numAntecedents == 1);
503 xorNode->succedents[0] = commitNode;
504 commitNode->antecedents[0] = xorNode;
505 commitNode->antType[0] = rf_control;
506
507 /* link commit node to wnd nodes */
508 RF_ASSERT(commitNode->numSuccedents == nfaults + nWndNodes);
509 tmpwndNode = wndNodes;
510 for (i = 0; i < nWndNodes; i++) {
511 RF_ASSERT(tmpwndNode->numAntecedents == 1);
512 commitNode->succedents[i] = tmpwndNode;
513 tmpwndNode->antecedents[0] = commitNode;
514 tmpwndNode->antType[0] = rf_control;
515 tmpwndNode = tmpwndNode->list_next;
516 }
517
518 /* link the commit node to wnp, wnq nodes */
519 RF_ASSERT(wnpNode->numAntecedents == 1);
520 commitNode->succedents[nWndNodes] = wnpNode;
521 wnpNode->antecedents[0] = commitNode;
522 wnpNode->antType[0] = rf_control;
523 #if (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0)
524 if (nfaults == 2) {
525 RF_ASSERT(wnqNode->numAntecedents == 1);
526 commitNode->succedents[nWndNodes + 1] = wnqNode;
527 wnqNode->antecedents[0] = commitNode;
528 wnqNode->antType[0] = rf_control;
529 }
530 #endif
531 /* link write new data nodes to unblock node */
532 RF_ASSERT(unblockNode->numAntecedents == (nWndNodes + nfaults));
533 tmpwndNode = wndNodes;
534 for (i = 0; i < nWndNodes; i++) {
535 RF_ASSERT(tmpwndNode->numSuccedents == 1);
536 tmpwndNode->succedents[0] = unblockNode;
537 unblockNode->antecedents[i] = tmpwndNode;
538 unblockNode->antType[i] = rf_control;
539 tmpwndNode = tmpwndNode->list_next;
540 }
541
542 /* link write new parity node to unblock node */
543 RF_ASSERT(wnpNode->numSuccedents == 1);
544 wnpNode->succedents[0] = unblockNode;
545 unblockNode->antecedents[nWndNodes] = wnpNode;
546 unblockNode->antType[nWndNodes] = rf_control;
547
548 #if (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0)
549 /* link write new q node to unblock node */
550 if (nfaults == 2) {
551 RF_ASSERT(wnqNode->numSuccedents == 1);
552 wnqNode->succedents[0] = unblockNode;
553 unblockNode->antecedents[nWndNodes + 1] = wnqNode;
554 unblockNode->antType[nWndNodes + 1] = rf_control;
555 }
556 #endif
557 /* link unblock node to term node */
558 RF_ASSERT(unblockNode->numSuccedents == 1);
559 RF_ASSERT(termNode->numAntecedents == 1);
560 RF_ASSERT(termNode->numSuccedents == 0);
561 unblockNode->succedents[0] = termNode;
562 termNode->antecedents[0] = unblockNode;
563 termNode->antType[0] = rf_control;
564 }
565 #define CONS_PDA(if,start,num) \
566 pda_p->col = asmap->if->col; \
567 pda_p->startSector = ((asmap->if->startSector / secPerSU) * secPerSU) + start; \
568 pda_p->numSector = num; \
569 pda_p->next = NULL; \
570 RF_MallocAndAdd(pda_p->bufPtr,rf_RaidAddressToByte(raidPtr,num),(char *), allocList)
571 #if (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_EVENODD > 0)
572 void
573 rf_WriteGenerateFailedAccessASMs(
574 RF_Raid_t * raidPtr,
575 RF_AccessStripeMap_t * asmap,
576 RF_PhysDiskAddr_t ** pdap,
577 int *nNodep,
578 RF_PhysDiskAddr_t ** pqpdap,
579 int *nPQNodep,
580 RF_AllocListElem_t * allocList)
581 {
582 RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
583 int PDAPerDisk, i;
584 RF_SectorCount_t secPerSU = layoutPtr->sectorsPerStripeUnit;
585 int numDataCol = layoutPtr->numDataCol;
586 int state;
587 unsigned napdas;
588 RF_SectorNum_t fone_start, fone_end, ftwo_start = 0, ftwo_end;
589 RF_PhysDiskAddr_t *fone = asmap->failedPDAs[0], *ftwo = asmap->failedPDAs[1];
590 RF_PhysDiskAddr_t *pda_p;
591 RF_RaidAddr_t sosAddr;
592
593 /* determine how many pda's we will have to generate per unaccess
594 * stripe. If there is only one failed data unit, it is one; if two,
595 * possibly two, depending wether they overlap. */
596
597 fone_start = rf_StripeUnitOffset(layoutPtr, fone->startSector);
598 fone_end = fone_start + fone->numSector;
599
600 if (asmap->numDataFailed == 1) {
601 PDAPerDisk = 1;
602 state = 1;
603 RF_MallocAndAdd(*pqpdap, 2 * sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList);
604 pda_p = *pqpdap;
605 /* build p */
606 CONS_PDA(parityInfo, fone_start, fone->numSector);
607 pda_p->type = RF_PDA_TYPE_PARITY;
608 pda_p++;
609 /* build q */
610 CONS_PDA(qInfo, fone_start, fone->numSector);
611 pda_p->type = RF_PDA_TYPE_Q;
612 } else {
613 ftwo_start = rf_StripeUnitOffset(layoutPtr, ftwo->startSector);
614 ftwo_end = ftwo_start + ftwo->numSector;
615 if (fone->numSector + ftwo->numSector > secPerSU) {
616 PDAPerDisk = 1;
617 state = 2;
618 RF_MallocAndAdd(*pqpdap, 2 * sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList);
619 pda_p = *pqpdap;
620 CONS_PDA(parityInfo, 0, secPerSU);
621 pda_p->type = RF_PDA_TYPE_PARITY;
622 pda_p++;
623 CONS_PDA(qInfo, 0, secPerSU);
624 pda_p->type = RF_PDA_TYPE_Q;
625 } else {
626 PDAPerDisk = 2;
627 state = 3;
628 /* four of them, fone, then ftwo */
629 RF_MallocAndAdd(*pqpdap, 4 * sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList);
630 pda_p = *pqpdap;
631 CONS_PDA(parityInfo, fone_start, fone->numSector);
632 pda_p->type = RF_PDA_TYPE_PARITY;
633 pda_p++;
634 CONS_PDA(qInfo, fone_start, fone->numSector);
635 pda_p->type = RF_PDA_TYPE_Q;
636 pda_p++;
637 CONS_PDA(parityInfo, ftwo_start, ftwo->numSector);
638 pda_p->type = RF_PDA_TYPE_PARITY;
639 pda_p++;
640 CONS_PDA(qInfo, ftwo_start, ftwo->numSector);
641 pda_p->type = RF_PDA_TYPE_Q;
642 }
643 }
644 /* figure out number of nonaccessed pda */
645 napdas = PDAPerDisk * (numDataCol - 2);
646 *nPQNodep = PDAPerDisk;
647
648 *nNodep = napdas;
649 if (napdas == 0)
650 return; /* short circuit */
651
652 /* allocate up our list of pda's */
653
654 RF_MallocAndAdd(pda_p, napdas * sizeof(RF_PhysDiskAddr_t),
655 (RF_PhysDiskAddr_t *), allocList);
656 *pdap = pda_p;
657
658 /* linkem together */
659 for (i = 0; i < (napdas - 1); i++)
660 pda_p[i].next = pda_p + (i + 1);
661
662 sosAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, asmap->raidAddress);
663 for (i = 0; i < numDataCol; i++) {
664 if ((pda_p - (*pdap)) == napdas)
665 continue;
666 pda_p->type = RF_PDA_TYPE_DATA;
667 pda_p->raidAddress = sosAddr + (i * secPerSU);
668 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
669 /* skip over dead disks */
670 if (RF_DEAD_DISK(raidPtr->Disks[pda_p->col].status))
671 continue;
672 switch (state) {
673 case 1: /* fone */
674 pda_p->numSector = fone->numSector;
675 pda_p->raidAddress += fone_start;
676 pda_p->startSector += fone_start;
677 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
678 break;
679 case 2: /* full stripe */
680 pda_p->numSector = secPerSU;
681 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, secPerSU), (char *), allocList);
682 break;
683 case 3: /* two slabs */
684 pda_p->numSector = fone->numSector;
685 pda_p->raidAddress += fone_start;
686 pda_p->startSector += fone_start;
687 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
688 pda_p++;
689 pda_p->type = RF_PDA_TYPE_DATA;
690 pda_p->raidAddress = sosAddr + (i * secPerSU);
691 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0);
692 pda_p->numSector = ftwo->numSector;
693 pda_p->raidAddress += ftwo_start;
694 pda_p->startSector += ftwo_start;
695 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList);
696 break;
697 default:
698 RF_PANIC();
699 }
700 pda_p++;
701 }
702
703 RF_ASSERT(pda_p - *pdap == napdas);
704 return;
705 }
706 #define DISK_NODE_PDA(node) ((node)->params[0].p)
707
708 #define DISK_NODE_PARAMS(_node_,_p_) \
709 (_node_).params[0].p = _p_ ; \
710 (_node_).params[1].p = (_p_)->bufPtr; \
711 (_node_).params[2].v = parityStripeID; \
712 (_node_).params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru)
713
714 void
715 rf_DoubleDegSmallWrite(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
716 RF_DagHeader_t *dag_h, void *bp,
717 RF_RaidAccessFlags_t flags,
718 RF_AllocListElem_t *allocList,
719 char *redundantReadNodeName,
720 char *redundantWriteNodeName,
721 char *recoveryNodeName,
722 int (*recovFunc) (RF_DagNode_t *))
723 {
724 RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
725 RF_DagNode_t *nodes, *wudNodes, *rrdNodes, *recoveryNode, *blockNode,
726 *unblockNode, *rpNodes, *rqNodes, *wpNodes, *wqNodes, *termNode;
727 RF_PhysDiskAddr_t *pda, *pqPDAs;
728 RF_PhysDiskAddr_t *npdas;
729 int nWriteNodes, nNodes, nReadNodes, nRrdNodes, nWudNodes, i;
730 RF_ReconUnitNum_t which_ru;
731 int nPQNodes;
732 RF_StripeNum_t parityStripeID = rf_RaidAddressToParityStripeID(layoutPtr, asmap->raidAddress, &which_ru);
733
734 /* simple small write case - First part looks like a reconstruct-read
735 * of the failed data units. Then a write of all data units not
736 * failed. */
737
738
739 /* Hdr | ------Block- / / \ Rrd Rrd ... Rrd Rp Rq \ \
740 * / -------PQ----- / \ \ Wud Wp WQ \ | /
741 * --Unblock- | T
742 *
743 * Rrd = read recovery data (potentially none) Wud = write user data
744 * (not incl. failed disks) Wp = Write P (could be two) Wq = Write Q
745 * (could be two)
746 *
747 */
748
749 rf_WriteGenerateFailedAccessASMs(raidPtr, asmap, &npdas, &nRrdNodes, &pqPDAs, &nPQNodes, allocList);
750
751 RF_ASSERT(asmap->numDataFailed == 1);
752
753 nWudNodes = asmap->numStripeUnitsAccessed - (asmap->numDataFailed);
754 nReadNodes = nRrdNodes + 2 * nPQNodes;
755 nWriteNodes = nWudNodes + 2 * nPQNodes;
756 nNodes = 4 + nReadNodes + nWriteNodes;
757
758 RF_MallocAndAdd(nodes, nNodes * sizeof(RF_DagNode_t), (RF_DagNode_t *), allocList);
759 blockNode = nodes;
760 unblockNode = blockNode + 1;
761 termNode = unblockNode + 1;
762 recoveryNode = termNode + 1;
763 rrdNodes = recoveryNode + 1;
764 rpNodes = rrdNodes + nRrdNodes;
765 rqNodes = rpNodes + nPQNodes;
766 wudNodes = rqNodes + nPQNodes;
767 wpNodes = wudNodes + nWudNodes;
768 wqNodes = wpNodes + nPQNodes;
769
770 dag_h->creator = "PQ_DDSimpleSmallWrite";
771 dag_h->numSuccedents = 1;
772 dag_h->succedents[0] = blockNode;
773 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc, NULL, 0, 1, 0, 0, dag_h, "Trm", allocList);
774 termNode->antecedents[0] = unblockNode;
775 termNode->antType[0] = rf_control;
776
777 /* init the block and unblock nodes */
778 /* The block node has all the read nodes as successors */
779 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, nReadNodes, 0, 0, 0, dag_h, "Nil", allocList);
780 for (i = 0; i < nReadNodes; i++)
781 blockNode->succedents[i] = rrdNodes + i;
782
783 /* The unblock node has all the writes as successors */
784 rf_InitNode(unblockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, 1, nWriteNodes, 0, 0, dag_h, "Nil", allocList);
785 for (i = 0; i < nWriteNodes; i++) {
786 unblockNode->antecedents[i] = wudNodes + i;
787 unblockNode->antType[i] = rf_control;
788 }
789 unblockNode->succedents[0] = termNode;
790
791 #define INIT_READ_NODE(node,name) \
792 rf_InitNode(node, rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, name, allocList); \
793 (node)->succedents[0] = recoveryNode; \
794 (node)->antecedents[0] = blockNode; \
795 (node)->antType[0] = rf_control;
796
797 /* build the read nodes */
798 pda = npdas;
799 for (i = 0; i < nRrdNodes; i++, pda = pda->next) {
800 INIT_READ_NODE(rrdNodes + i, "rrd");
801 DISK_NODE_PARAMS(rrdNodes[i], pda);
802 }
803
804 /* read redundancy pdas */
805 pda = pqPDAs;
806 INIT_READ_NODE(rpNodes, "Rp");
807 RF_ASSERT(pda);
808 DISK_NODE_PARAMS(rpNodes[0], pda);
809 pda++;
810 INIT_READ_NODE(rqNodes, redundantReadNodeName);
811 RF_ASSERT(pda);
812 DISK_NODE_PARAMS(rqNodes[0], pda);
813 if (nPQNodes == 2) {
814 pda++;
815 INIT_READ_NODE(rpNodes + 1, "Rp");
816 RF_ASSERT(pda);
817 DISK_NODE_PARAMS(rpNodes[1], pda);
818 pda++;
819 INIT_READ_NODE(rqNodes + 1, redundantReadNodeName);
820 RF_ASSERT(pda);
821 DISK_NODE_PARAMS(rqNodes[1], pda);
822 }
823 /* the recovery node has all reads as precedessors and all writes as
824 * successors. It generates a result for every write P or write Q
825 * node. As parameters, it takes a pda per read and a pda per stripe
826 * of user data written. It also takes as the last params the raidPtr
827 * and asm. For results, it takes PDA for P & Q. */
828
829
830 rf_InitNode(recoveryNode, rf_wait, RF_FALSE, recovFunc, rf_NullNodeUndoFunc, NULL,
831 nWriteNodes, /* succesors */
832 nReadNodes, /* preds */
833 nReadNodes + nWudNodes + 3, /* params */
834 2 * nPQNodes, /* results */
835 dag_h, recoveryNodeName, allocList);
836
837
838
839 for (i = 0; i < nReadNodes; i++) {
840 recoveryNode->antecedents[i] = rrdNodes + i;
841 recoveryNode->antType[i] = rf_control;
842 recoveryNode->params[i].p = DISK_NODE_PDA(rrdNodes + i);
843 }
844 for (i = 0; i < nWudNodes; i++) {
845 recoveryNode->succedents[i] = wudNodes + i;
846 }
847 recoveryNode->params[nReadNodes + nWudNodes].p = asmap->failedPDAs[0];
848 recoveryNode->params[nReadNodes + nWudNodes + 1].p = raidPtr;
849 recoveryNode->params[nReadNodes + nWudNodes + 2].p = asmap;
850
851 for (; i < nWriteNodes; i++)
852 recoveryNode->succedents[i] = wudNodes + i;
853
854 pda = pqPDAs;
855 recoveryNode->results[0] = pda;
856 pda++;
857 recoveryNode->results[1] = pda;
858 if (nPQNodes == 2) {
859 pda++;
860 recoveryNode->results[2] = pda;
861 pda++;
862 recoveryNode->results[3] = pda;
863 }
864 /* fill writes */
865 #define INIT_WRITE_NODE(node,name) \
866 rf_InitNode(node, rf_wait, RF_FALSE, rf_DiskWriteFunc, rf_DiskWriteUndoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, name, allocList); \
867 (node)->succedents[0] = unblockNode; \
868 (node)->antecedents[0] = recoveryNode; \
869 (node)->antType[0] = rf_control;
870
871 pda = asmap->physInfo;
872 for (i = 0; i < nWudNodes; i++) {
873 INIT_WRITE_NODE(wudNodes + i, "Wd");
874 DISK_NODE_PARAMS(wudNodes[i], pda);
875 recoveryNode->params[nReadNodes + i].p = DISK_NODE_PDA(wudNodes + i);
876 pda = pda->next;
877 }
878 /* write redundancy pdas */
879 pda = pqPDAs;
880 INIT_WRITE_NODE(wpNodes, "Wp");
881 RF_ASSERT(pda);
882 DISK_NODE_PARAMS(wpNodes[0], pda);
883 pda++;
884 INIT_WRITE_NODE(wqNodes, "Wq");
885 RF_ASSERT(pda);
886 DISK_NODE_PARAMS(wqNodes[0], pda);
887 if (nPQNodes == 2) {
888 pda++;
889 INIT_WRITE_NODE(wpNodes + 1, "Wp");
890 RF_ASSERT(pda);
891 DISK_NODE_PARAMS(wpNodes[1], pda);
892 pda++;
893 INIT_WRITE_NODE(wqNodes + 1, "Wq");
894 RF_ASSERT(pda);
895 DISK_NODE_PARAMS(wqNodes[1], pda);
896 }
897 }
898 #endif /* (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_EVENODD > 0) */
899