rf_parityscan.c revision 1.1 1 1.1 oster /* $NetBSD: rf_parityscan.c,v 1.1 1998/11/13 04:20:32 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
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 *
31 1.1 oster * rf_parityscan.c -- misc utilities related to parity verification
32 1.1 oster *
33 1.1 oster *****************************************************************************/
34 1.1 oster
35 1.1 oster /*
36 1.1 oster * :
37 1.1 oster * Log: rf_parityscan.c,v
38 1.1 oster * Revision 1.47 1996/08/20 20:35:01 jimz
39 1.1 oster * change diagnostic string in rewrite
40 1.1 oster *
41 1.1 oster * Revision 1.46 1996/08/20 20:03:19 jimz
42 1.1 oster * fixed parity rewrite to actually use arch-specific parity stuff
43 1.1 oster * (this ever worked... how?)
44 1.1 oster *
45 1.1 oster * Revision 1.45 1996/08/16 17:41:25 jimz
46 1.1 oster * allow rewrite parity on any fault-tolerant arch
47 1.1 oster *
48 1.1 oster * Revision 1.44 1996/07/28 20:31:39 jimz
49 1.1 oster * i386netbsd port
50 1.1 oster * true/false fixup
51 1.1 oster *
52 1.1 oster * Revision 1.43 1996/07/27 23:36:08 jimz
53 1.1 oster * Solaris port of simulator
54 1.1 oster *
55 1.1 oster * Revision 1.42 1996/07/22 21:12:01 jimz
56 1.1 oster * clean up parity scan status printing
57 1.1 oster *
58 1.1 oster * Revision 1.41 1996/07/22 19:52:16 jimz
59 1.1 oster * switched node params to RF_DagParam_t, a union of
60 1.1 oster * a 64-bit int and a void *, for better portability
61 1.1 oster * attempted hpux port, but failed partway through for
62 1.1 oster * lack of a single C compiler capable of compiling all
63 1.1 oster * source files
64 1.1 oster *
65 1.1 oster * Revision 1.40 1996/07/13 00:00:59 jimz
66 1.1 oster * sanitized generalized reconstruction architecture
67 1.1 oster * cleaned up head sep, rbuf problems
68 1.1 oster *
69 1.1 oster * Revision 1.39 1996/07/09 21:44:26 jimz
70 1.1 oster * fix bogus return code in VerifyParityBasic when a stripe can't be corrected
71 1.1 oster *
72 1.1 oster * Revision 1.38 1996/06/20 17:56:57 jimz
73 1.1 oster * update VerifyParity to check complete AccessStripeMaps
74 1.1 oster *
75 1.1 oster * Revision 1.37 1996/06/19 22:23:01 jimz
76 1.1 oster * parity verification is now a layout-configurable thing
77 1.1 oster * not all layouts currently support it (correctly, anyway)
78 1.1 oster *
79 1.1 oster * Revision 1.36 1996/06/09 02:36:46 jimz
80 1.1 oster * lots of little crufty cleanup- fixup whitespace
81 1.1 oster * issues, comment #ifdefs, improve typing in some
82 1.1 oster * places (esp size-related)
83 1.1 oster *
84 1.1 oster * Revision 1.35 1996/06/07 22:26:27 jimz
85 1.1 oster * type-ify which_ru (RF_ReconUnitNum_t)
86 1.1 oster *
87 1.1 oster * Revision 1.34 1996/06/07 21:33:04 jimz
88 1.1 oster * begin using consistent types for sector numbers,
89 1.1 oster * stripe numbers, row+col numbers, recon unit numbers
90 1.1 oster *
91 1.1 oster * Revision 1.33 1996/06/05 18:06:02 jimz
92 1.1 oster * Major code cleanup. The Great Renaming is now done.
93 1.1 oster * Better modularity. Better typing. Fixed a bunch of
94 1.1 oster * synchronization bugs. Made a lot of global stuff
95 1.1 oster * per-desc or per-array. Removed dead code.
96 1.1 oster *
97 1.1 oster * Revision 1.32 1996/06/02 17:31:48 jimz
98 1.1 oster * Moved a lot of global stuff into array structure, where it belongs.
99 1.1 oster * Fixed up paritylogging, pss modules in this manner. Some general
100 1.1 oster * code cleanup. Removed lots of dead code, some dead files.
101 1.1 oster *
102 1.1 oster * Revision 1.31 1996/05/31 22:26:54 jimz
103 1.1 oster * fix a lot of mapping problems, memory allocation problems
104 1.1 oster * found some weird lock issues, fixed 'em
105 1.1 oster * more code cleanup
106 1.1 oster *
107 1.1 oster * Revision 1.30 1996/05/30 23:22:16 jimz
108 1.1 oster * bugfixes of serialization, timing problems
109 1.1 oster * more cleanup
110 1.1 oster *
111 1.1 oster * Revision 1.29 1996/05/30 12:59:18 jimz
112 1.1 oster * make etimer happier, more portable
113 1.1 oster *
114 1.1 oster * Revision 1.28 1996/05/30 11:29:41 jimz
115 1.1 oster * Numerous bug fixes. Stripe lock release code disagreed with the taking code
116 1.1 oster * about when stripes should be locked (I made it consistent: no parity, no lock)
117 1.1 oster * There was a lot of extra serialization of I/Os which I've removed- a lot of
118 1.1 oster * it was to calculate values for the cache code, which is no longer with us.
119 1.1 oster * More types, function, macro cleanup. Added code to properly quiesce the array
120 1.1 oster * on shutdown. Made a lot of stuff array-specific which was (bogusly) general
121 1.1 oster * before. Fixed memory allocation, freeing bugs.
122 1.1 oster *
123 1.1 oster * Revision 1.27 1996/05/27 18:56:37 jimz
124 1.1 oster * more code cleanup
125 1.1 oster * better typing
126 1.1 oster * compiles in all 3 environments
127 1.1 oster *
128 1.1 oster * Revision 1.26 1996/05/24 22:17:04 jimz
129 1.1 oster * continue code + namespace cleanup
130 1.1 oster * typed a bunch of flags
131 1.1 oster *
132 1.1 oster * Revision 1.25 1996/05/24 04:28:55 jimz
133 1.1 oster * release cleanup ckpt
134 1.1 oster *
135 1.1 oster * Revision 1.24 1996/05/23 21:46:35 jimz
136 1.1 oster * checkpoint in code cleanup (release prep)
137 1.1 oster * lots of types, function names have been fixed
138 1.1 oster *
139 1.1 oster * Revision 1.23 1996/05/23 00:33:23 jimz
140 1.1 oster * code cleanup: move all debug decls to rf_options.c, all extern
141 1.1 oster * debug decls to rf_options.h, all debug vars preceded by rf_
142 1.1 oster *
143 1.1 oster * Revision 1.22 1996/05/18 19:51:34 jimz
144 1.1 oster * major code cleanup- fix syntax, make some types consistent,
145 1.1 oster * add prototypes, clean out dead code, et cetera
146 1.1 oster *
147 1.1 oster * Revision 1.21 1996/05/08 21:01:24 jimz
148 1.1 oster * fixed up enum type names that were conflicting with other
149 1.1 oster * enums and function names (ie, "panic")
150 1.1 oster * future naming trends will be towards RF_ and rf_ for
151 1.1 oster * everything raidframe-related
152 1.1 oster *
153 1.1 oster * Revision 1.20 1995/12/12 18:10:06 jimz
154 1.1 oster * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
155 1.1 oster * fix 80-column brain damage in comments
156 1.1 oster *
157 1.1 oster * Revision 1.19 1995/11/30 16:16:49 wvcii
158 1.1 oster * added copyright info
159 1.1 oster *
160 1.1 oster * Revision 1.18 1995/11/19 16:32:19 wvcii
161 1.1 oster * eliminated initialization of dag header fields which no longer exist
162 1.1 oster * (numDags, numDagsDone, firstHdr)
163 1.1 oster *
164 1.1 oster * Revision 1.17 1995/11/07 16:23:36 wvcii
165 1.1 oster * added comments, asserts, and prototypes
166 1.1 oster * encoded commit point nodes, barrier, and antecedents types into dags
167 1.1 oster *
168 1.1 oster */
169 1.1 oster
170 1.1 oster #include "rf_types.h"
171 1.1 oster #include "rf_raid.h"
172 1.1 oster #include "rf_dag.h"
173 1.1 oster #include "rf_dagfuncs.h"
174 1.1 oster #include "rf_dagutils.h"
175 1.1 oster #include "rf_mcpair.h"
176 1.1 oster #include "rf_general.h"
177 1.1 oster #include "rf_engine.h"
178 1.1 oster #include "rf_parityscan.h"
179 1.1 oster #include "rf_map.h"
180 1.1 oster #include "rf_sys.h"
181 1.1 oster
182 1.1 oster /*****************************************************************************************
183 1.1 oster *
184 1.1 oster * walk through the entire arry and write new parity.
185 1.1 oster * This works by creating two DAGs, one to read a stripe of data and one to
186 1.1 oster * write new parity. The first is executed, the data is xored together, and
187 1.1 oster * then the second is executed. To avoid constantly building and tearing down
188 1.1 oster * the DAGs, we create them a priori and fill them in with the mapping
189 1.1 oster * information as we go along.
190 1.1 oster *
191 1.1 oster * there should never be more than one thread running this.
192 1.1 oster *
193 1.1 oster ****************************************************************************************/
194 1.1 oster
195 1.1 oster int rf_RewriteParity(raidPtr)
196 1.1 oster RF_Raid_t *raidPtr;
197 1.1 oster {
198 1.1 oster RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
199 1.1 oster RF_AccessStripeMapHeader_t *asm_h;
200 1.1 oster int old_pctg, new_pctg, rc;
201 1.1 oster RF_PhysDiskAddr_t pda;
202 1.1 oster RF_SectorNum_t i;
203 1.1 oster
204 1.1 oster pda.startSector = 0;
205 1.1 oster pda.numSector = raidPtr->Layout.sectorsPerStripeUnit;
206 1.1 oster old_pctg = -1;
207 1.1 oster
208 1.1 oster /* rf_verifyParityDebug=1; */
209 1.1 oster for (i=0; i<raidPtr->totalSectors; i+=layoutPtr->dataSectorsPerStripe) {
210 1.1 oster asm_h = rf_MapAccess(raidPtr, i, layoutPtr->dataSectorsPerStripe, NULL, RF_DONT_REMAP);
211 1.1 oster rc = rf_VerifyParity(raidPtr, asm_h->stripeMap, 1, 0);
212 1.1 oster /* printf("Parity verified: rc=%d\n",rc); */
213 1.1 oster switch (rc) {
214 1.1 oster case RF_PARITY_OKAY:
215 1.1 oster case RF_PARITY_CORRECTED:
216 1.1 oster break;
217 1.1 oster case RF_PARITY_BAD:
218 1.1 oster printf("Parity bad during correction\n");
219 1.1 oster RF_PANIC();
220 1.1 oster break;
221 1.1 oster case RF_PARITY_COULD_NOT_CORRECT:
222 1.1 oster printf("Could not correct bad parity\n");
223 1.1 oster RF_PANIC();
224 1.1 oster break;
225 1.1 oster case RF_PARITY_COULD_NOT_VERIFY:
226 1.1 oster printf("Could not verify parity\n");
227 1.1 oster RF_PANIC();
228 1.1 oster break;
229 1.1 oster default:
230 1.1 oster printf("Bad rc=%d from VerifyParity in RewriteParity\n", rc);
231 1.1 oster RF_PANIC();
232 1.1 oster }
233 1.1 oster rf_FreeAccessStripeMap(asm_h);
234 1.1 oster new_pctg = i*1000/raidPtr->totalSectors;
235 1.1 oster if (new_pctg != old_pctg) {
236 1.1 oster #ifndef KERNEL
237 1.1 oster fprintf(stderr,"\rParity rewrite: %d.%d%% complete",
238 1.1 oster new_pctg/10, new_pctg%10);
239 1.1 oster fflush(stderr);
240 1.1 oster #endif /* !KERNEL */
241 1.1 oster }
242 1.1 oster old_pctg = new_pctg;
243 1.1 oster }
244 1.1 oster #ifndef KERNEL
245 1.1 oster fprintf(stderr,"\rParity rewrite: 100.0%% complete\n");
246 1.1 oster #endif /* !KERNEL */
247 1.1 oster #if 1
248 1.1 oster return(0); /* XXX nothing was here.. GO */
249 1.1 oster #endif
250 1.1 oster }
251 1.1 oster
252 1.1 oster /*****************************************************************************************
253 1.1 oster *
254 1.1 oster * verify that the parity in a particular stripe is correct.
255 1.1 oster * we validate only the range of parity defined by parityPDA, since
256 1.1 oster * this is all we have locked. The way we do this is to create an asm
257 1.1 oster * that maps the whole stripe and then range-restrict it to the parity
258 1.1 oster * region defined by the parityPDA.
259 1.1 oster *
260 1.1 oster ****************************************************************************************/
261 1.1 oster int rf_VerifyParity(raidPtr, aasm, correct_it, flags)
262 1.1 oster RF_Raid_t *raidPtr;
263 1.1 oster RF_AccessStripeMap_t *aasm;
264 1.1 oster int correct_it;
265 1.1 oster RF_RaidAccessFlags_t flags;
266 1.1 oster {
267 1.1 oster RF_PhysDiskAddr_t *parityPDA;
268 1.1 oster RF_AccessStripeMap_t *doasm;
269 1.1 oster RF_LayoutSW_t *lp;
270 1.1 oster int lrc, rc;
271 1.1 oster
272 1.1 oster lp = raidPtr->Layout.map;
273 1.1 oster if (lp->faultsTolerated == 0) {
274 1.1 oster /*
275 1.1 oster * There isn't any parity. Call it "okay."
276 1.1 oster */
277 1.1 oster return(RF_PARITY_OKAY);
278 1.1 oster }
279 1.1 oster rc = RF_PARITY_OKAY;
280 1.1 oster if (lp->VerifyParity) {
281 1.1 oster for(doasm=aasm;doasm;doasm=doasm->next) {
282 1.1 oster for(parityPDA=doasm->parityInfo;parityPDA;parityPDA=parityPDA->next) {
283 1.1 oster lrc = lp->VerifyParity(raidPtr, doasm->raidAddress, parityPDA,
284 1.1 oster correct_it, flags);
285 1.1 oster if (lrc > rc) {
286 1.1 oster /* see rf_parityscan.h for why this works */
287 1.1 oster rc = lrc;
288 1.1 oster }
289 1.1 oster }
290 1.1 oster }
291 1.1 oster }
292 1.1 oster else {
293 1.1 oster rc = RF_PARITY_COULD_NOT_VERIFY;
294 1.1 oster }
295 1.1 oster return(rc);
296 1.1 oster }
297 1.1 oster
298 1.1 oster int rf_VerifyParityBasic(raidPtr, raidAddr, parityPDA, correct_it, flags)
299 1.1 oster RF_Raid_t *raidPtr;
300 1.1 oster RF_RaidAddr_t raidAddr;
301 1.1 oster RF_PhysDiskAddr_t *parityPDA;
302 1.1 oster int correct_it;
303 1.1 oster RF_RaidAccessFlags_t flags;
304 1.1 oster {
305 1.1 oster RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
306 1.1 oster RF_RaidAddr_t startAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, raidAddr);
307 1.1 oster RF_SectorCount_t numsector = parityPDA->numSector;
308 1.1 oster int numbytes = rf_RaidAddressToByte(raidPtr, numsector);
309 1.1 oster int bytesPerStripe = numbytes * layoutPtr->numDataCol;
310 1.1 oster RF_DagHeader_t *rd_dag_h, *wr_dag_h; /* read, write dag */
311 1.1 oster RF_DagNode_t *blockNode, *unblockNode, *wrBlock, *wrUnblock;
312 1.1 oster RF_AccessStripeMapHeader_t *asm_h;
313 1.1 oster RF_AccessStripeMap_t *asmap;
314 1.1 oster RF_AllocListElem_t *alloclist;
315 1.1 oster RF_PhysDiskAddr_t *pda;
316 1.1 oster char *pbuf, *buf, *end_p, *p;
317 1.1 oster int i, retcode;
318 1.1 oster RF_ReconUnitNum_t which_ru;
319 1.1 oster RF_StripeNum_t psID = rf_RaidAddressToParityStripeID(layoutPtr, raidAddr, &which_ru);
320 1.1 oster int stripeWidth = layoutPtr->numDataCol + layoutPtr->numParityCol;
321 1.1 oster RF_AccTraceEntry_t tracerec;
322 1.1 oster RF_MCPair_t *mcpair;
323 1.1 oster
324 1.1 oster retcode = RF_PARITY_OKAY;
325 1.1 oster
326 1.1 oster mcpair = rf_AllocMCPair();
327 1.1 oster rf_MakeAllocList(alloclist);
328 1.1 oster RF_MallocAndAdd(buf, numbytes * (layoutPtr->numDataCol + layoutPtr->numParityCol), (char *), alloclist);
329 1.1 oster RF_CallocAndAdd(pbuf, 1, numbytes, (char *), alloclist); /* use calloc to make sure buffer is zeroed */
330 1.1 oster end_p = buf + bytesPerStripe;
331 1.1 oster
332 1.1 oster rd_dag_h = rf_MakeSimpleDAG(raidPtr, stripeWidth, numbytes, buf, rf_DiskReadFunc, rf_DiskReadUndoFunc,
333 1.1 oster "Rod", alloclist, flags, RF_IO_NORMAL_PRIORITY);
334 1.1 oster blockNode = rd_dag_h->succedents[0];
335 1.1 oster unblockNode = blockNode->succedents[0]->succedents[0];
336 1.1 oster
337 1.1 oster /* map the stripe and fill in the PDAs in the dag */
338 1.1 oster asm_h = rf_MapAccess(raidPtr, startAddr, layoutPtr->dataSectorsPerStripe, buf, RF_DONT_REMAP);
339 1.1 oster asmap = asm_h->stripeMap;
340 1.1 oster
341 1.1 oster for (pda=asmap->physInfo,i=0; i<layoutPtr->numDataCol; i++,pda=pda->next) {
342 1.1 oster RF_ASSERT(pda);
343 1.1 oster rf_RangeRestrictPDA(raidPtr, parityPDA, pda, 0, 1);
344 1.1 oster RF_ASSERT(pda->numSector != 0);
345 1.1 oster if (rf_TryToRedirectPDA(raidPtr, pda, 0)) goto out; /* no way to verify parity if disk is dead. return w/ good status */
346 1.1 oster blockNode->succedents[i]->params[0].p = pda;
347 1.1 oster blockNode->succedents[i]->params[2].v = psID;
348 1.1 oster blockNode->succedents[i]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
349 1.1 oster }
350 1.1 oster
351 1.1 oster RF_ASSERT(!asmap->parityInfo->next);
352 1.1 oster rf_RangeRestrictPDA(raidPtr, parityPDA, asmap->parityInfo, 0, 1);
353 1.1 oster RF_ASSERT(asmap->parityInfo->numSector != 0);
354 1.1 oster if (rf_TryToRedirectPDA(raidPtr, asmap->parityInfo, 1))
355 1.1 oster goto out;
356 1.1 oster blockNode->succedents[layoutPtr->numDataCol]->params[0].p = asmap->parityInfo;
357 1.1 oster
358 1.1 oster /* fire off the DAG */
359 1.1 oster bzero((char *)&tracerec,sizeof(tracerec));
360 1.1 oster rd_dag_h->tracerec = &tracerec;
361 1.1 oster
362 1.1 oster if (rf_verifyParityDebug) {
363 1.1 oster printf("Parity verify read dag:\n");
364 1.1 oster rf_PrintDAGList(rd_dag_h);
365 1.1 oster }
366 1.1 oster
367 1.1 oster RF_LOCK_MUTEX(mcpair->mutex);
368 1.1 oster mcpair->flag = 0;
369 1.1 oster rf_DispatchDAG(rd_dag_h, (void (*)(void *))rf_MCPairWakeupFunc,
370 1.1 oster (void *) mcpair);
371 1.1 oster while (!mcpair->flag)
372 1.1 oster RF_WAIT_COND(mcpair->cond, mcpair->mutex);
373 1.1 oster RF_UNLOCK_MUTEX(mcpair->mutex);
374 1.1 oster if (rd_dag_h->status != rf_enable) {
375 1.1 oster RF_ERRORMSG("Unable to verify parity: can't read the stripe\n");
376 1.1 oster retcode = RF_PARITY_COULD_NOT_VERIFY;
377 1.1 oster goto out;
378 1.1 oster }
379 1.1 oster
380 1.1 oster for (p=buf; p<end_p; p+=numbytes) {
381 1.1 oster rf_bxor(p, pbuf, numbytes, NULL);
382 1.1 oster }
383 1.1 oster for (i=0; i<numbytes; i++) {
384 1.1 oster #if 0
385 1.1 oster if (pbuf[i]!=0 || buf[bytesPerStripe+i]!=0) {
386 1.1 oster printf("Bytes: %d %d %d\n",i,pbuf[i],buf[bytesPerStripe+i]);
387 1.1 oster }
388 1.1 oster #endif
389 1.1 oster if (pbuf[i] != buf[bytesPerStripe+i]) {
390 1.1 oster if (!correct_it)
391 1.1 oster RF_ERRORMSG3("Parity verify error: byte %d of parity is 0x%x should be 0x%x\n",
392 1.1 oster i,(u_char) buf[bytesPerStripe+i],(u_char) pbuf[i]);
393 1.1 oster retcode = RF_PARITY_BAD;
394 1.1 oster break;
395 1.1 oster }
396 1.1 oster }
397 1.1 oster
398 1.1 oster if (retcode && correct_it) {
399 1.1 oster wr_dag_h = rf_MakeSimpleDAG(raidPtr, 1, numbytes, pbuf, rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
400 1.1 oster "Wnp", alloclist, flags, RF_IO_NORMAL_PRIORITY);
401 1.1 oster wrBlock = wr_dag_h->succedents[0]; wrUnblock = wrBlock->succedents[0]->succedents[0];
402 1.1 oster wrBlock->succedents[0]->params[0].p = asmap->parityInfo;
403 1.1 oster wrBlock->succedents[0]->params[2].v = psID;
404 1.1 oster wrBlock->succedents[0]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
405 1.1 oster bzero((char *)&tracerec,sizeof(tracerec));
406 1.1 oster wr_dag_h->tracerec = &tracerec;
407 1.1 oster if (rf_verifyParityDebug) {
408 1.1 oster printf("Parity verify write dag:\n");
409 1.1 oster rf_PrintDAGList(wr_dag_h);
410 1.1 oster }
411 1.1 oster RF_LOCK_MUTEX(mcpair->mutex);
412 1.1 oster mcpair->flag = 0;
413 1.1 oster rf_DispatchDAG(wr_dag_h, (void (*)(void *))rf_MCPairWakeupFunc,
414 1.1 oster (void *) mcpair);
415 1.1 oster while (!mcpair->flag)
416 1.1 oster RF_WAIT_COND(mcpair->cond, mcpair->mutex);
417 1.1 oster RF_UNLOCK_MUTEX(mcpair->mutex);
418 1.1 oster if (wr_dag_h->status != rf_enable) {
419 1.1 oster RF_ERRORMSG("Unable to correct parity in VerifyParity: can't write the stripe\n");
420 1.1 oster retcode = RF_PARITY_COULD_NOT_CORRECT;
421 1.1 oster }
422 1.1 oster rf_FreeDAG(wr_dag_h);
423 1.1 oster if (retcode == RF_PARITY_BAD)
424 1.1 oster retcode = RF_PARITY_CORRECTED;
425 1.1 oster }
426 1.1 oster
427 1.1 oster out:
428 1.1 oster rf_FreeAccessStripeMap(asm_h);
429 1.1 oster rf_FreeAllocList(alloclist);
430 1.1 oster rf_FreeDAG(rd_dag_h);
431 1.1 oster rf_FreeMCPair(mcpair);
432 1.1 oster return(retcode);
433 1.1 oster }
434 1.1 oster
435 1.1 oster int rf_TryToRedirectPDA(raidPtr, pda, parity)
436 1.1 oster RF_Raid_t *raidPtr;
437 1.1 oster RF_PhysDiskAddr_t *pda;
438 1.1 oster int parity;
439 1.1 oster {
440 1.1 oster if (raidPtr->Disks[pda->row][pda->col].status == rf_ds_reconstructing) {
441 1.1 oster if (rf_CheckRUReconstructed(raidPtr->reconControl[pda->row]->reconMap, pda->startSector)) {
442 1.1 oster if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
443 1.1 oster RF_RowCol_t or = pda->row, oc = pda->col;
444 1.1 oster RF_SectorNum_t os = pda->startSector;
445 1.1 oster if (parity) {
446 1.1 oster (raidPtr->Layout.map->MapParity)(raidPtr, pda->raidAddress, &pda->row, &pda->col, &pda->startSector, RF_REMAP);
447 1.1 oster if (rf_verifyParityDebug) printf("VerifyParity: Redir P r %d c %d sect %ld -> r %d c %d sect %ld\n",
448 1.1 oster or,oc,(long)os,pda->row,pda->col,(long)pda->startSector);
449 1.1 oster } else {
450 1.1 oster (raidPtr->Layout.map->MapSector)(raidPtr, pda->raidAddress, &pda->row, &pda->col, &pda->startSector, RF_REMAP);
451 1.1 oster if (rf_verifyParityDebug) printf("VerifyParity: Redir D r %d c %d sect %ld -> r %d c %d sect %ld\n",
452 1.1 oster or,oc,(long)os,pda->row,pda->col,(long)pda->startSector);
453 1.1 oster }
454 1.1 oster } else {
455 1.1 oster RF_RowCol_t spRow = raidPtr->Disks[pda->row][pda->col].spareRow;
456 1.1 oster RF_RowCol_t spCol = raidPtr->Disks[pda->row][pda->col].spareCol;
457 1.1 oster pda->row = spRow;
458 1.1 oster pda->col = spCol;
459 1.1 oster }
460 1.1 oster }
461 1.1 oster }
462 1.1 oster if (RF_DEAD_DISK(raidPtr->Disks[pda->row][pda->col].status)) return(1);
463 1.1 oster return(0);
464 1.1 oster }
465 1.1 oster
466 1.1 oster /*****************************************************************************************
467 1.1 oster *
468 1.1 oster * currently a stub.
469 1.1 oster *
470 1.1 oster * takes as input an ASM describing a write operation and containing one failure, and
471 1.1 oster * verifies that the parity was correctly updated to reflect the write.
472 1.1 oster *
473 1.1 oster * if it's a data unit that's failed, we read the other data units in the stripe and
474 1.1 oster * the parity unit, XOR them together, and verify that we get the data intended for
475 1.1 oster * the failed disk. Since it's easy, we also validate that the right data got written
476 1.1 oster * to the surviving data disks.
477 1.1 oster *
478 1.1 oster * If it's the parity that failed, there's really no validation we can do except the
479 1.1 oster * above verification that the right data got written to all disks. This is because
480 1.1 oster * the new data intended for the failed disk is supplied in the ASM, but this is of
481 1.1 oster * course not the case for the new parity.
482 1.1 oster *
483 1.1 oster ****************************************************************************************/
484 1.1 oster int rf_VerifyDegrModeWrite(raidPtr, asmh)
485 1.1 oster RF_Raid_t *raidPtr;
486 1.1 oster RF_AccessStripeMapHeader_t *asmh;
487 1.1 oster {
488 1.1 oster return(0);
489 1.1 oster }
490 1.1 oster
491 1.1 oster /* creates a simple DAG with a header, a block-recon node at level 1,
492 1.1 oster * nNodes nodes at level 2, an unblock-recon node at level 3, and
493 1.1 oster * a terminator node at level 4. The stripe address field in
494 1.1 oster * the block and unblock nodes are not touched, nor are the pda
495 1.1 oster * fields in the second-level nodes, so they must be filled in later.
496 1.1 oster *
497 1.1 oster * commit point is established at unblock node - this means that any
498 1.1 oster * failure during dag execution causes the dag to fail
499 1.1 oster */
500 1.1 oster RF_DagHeader_t *rf_MakeSimpleDAG(raidPtr, nNodes, bytesPerSU, databuf, doFunc, undoFunc, name, alloclist, flags, priority)
501 1.1 oster RF_Raid_t *raidPtr;
502 1.1 oster int nNodes;
503 1.1 oster int bytesPerSU;
504 1.1 oster char *databuf;
505 1.1 oster int (*doFunc)(RF_DagNode_t *node);
506 1.1 oster int (*undoFunc)(RF_DagNode_t *node);
507 1.1 oster char *name; /* node names at the second level */
508 1.1 oster RF_AllocListElem_t *alloclist;
509 1.1 oster RF_RaidAccessFlags_t flags;
510 1.1 oster int priority;
511 1.1 oster {
512 1.1 oster RF_DagHeader_t *dag_h;
513 1.1 oster RF_DagNode_t *nodes, *termNode, *blockNode, *unblockNode;
514 1.1 oster int i;
515 1.1 oster
516 1.1 oster /* create the nodes, the block & unblock nodes, and the terminator node */
517 1.1 oster RF_CallocAndAdd(nodes, nNodes+3, sizeof(RF_DagNode_t), (RF_DagNode_t *), alloclist);
518 1.1 oster blockNode = &nodes[nNodes];
519 1.1 oster unblockNode = blockNode+1;
520 1.1 oster termNode = unblockNode+1;
521 1.1 oster
522 1.1 oster dag_h = rf_AllocDAGHeader();
523 1.1 oster dag_h->raidPtr = (void *) raidPtr;
524 1.1 oster dag_h->allocList = NULL; /* we won't use this alloc list */
525 1.1 oster dag_h->status = rf_enable;
526 1.1 oster dag_h->numSuccedents = 1;
527 1.1 oster dag_h->creator = "SimpleDAG";
528 1.1 oster
529 1.1 oster /* this dag can not commit until the unblock node is reached
530 1.1 oster * errors prior to the commit point imply the dag has failed
531 1.1 oster */
532 1.1 oster dag_h->numCommitNodes = 1;
533 1.1 oster dag_h->numCommits = 0;
534 1.1 oster
535 1.1 oster dag_h->succedents[0] = blockNode;
536 1.1 oster rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, nNodes, 0, 0, 0, dag_h, "Nil", alloclist);
537 1.1 oster rf_InitNode(unblockNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, 1, nNodes, 0, 0, dag_h, "Nil", alloclist);
538 1.1 oster unblockNode->succedents[0] = termNode;
539 1.1 oster for (i=0; i<nNodes; i++) {
540 1.1 oster blockNode->succedents[i] = unblockNode->antecedents[i] = &nodes[i];
541 1.1 oster unblockNode->antType[i] = rf_control;
542 1.1 oster rf_InitNode(&nodes[i], rf_wait, RF_FALSE, doFunc, undoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, name, alloclist);
543 1.1 oster nodes[i].succedents[0] = unblockNode;
544 1.1 oster nodes[i].antecedents[0] = blockNode;
545 1.1 oster nodes[i].antType[0] = rf_control;
546 1.1 oster nodes[i].params[1].p = (databuf + (i*bytesPerSU));
547 1.1 oster }
548 1.1 oster rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc, NULL, 0, 1, 0, 0, dag_h, "Trm", alloclist);
549 1.1 oster termNode->antecedents[0] = unblockNode;
550 1.1 oster termNode->antType[0] = rf_control;
551 1.1 oster return(dag_h);
552 1.1 oster }
553