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