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