rf_raid1.c revision 1.18 1 /* $NetBSD: rf_raid1.c,v 1.18 2004/02/29 23:03:30 oster Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
5 *
6 * Author: William V. Courtright II
7 *
8 * Permission to use, copy, modify and distribute this software and
9 * its documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
27 */
28
29 /*****************************************************************************
30 *
31 * rf_raid1.c -- implements RAID Level 1
32 *
33 *****************************************************************************/
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: rf_raid1.c,v 1.18 2004/02/29 23:03:30 oster Exp $");
37
38 #include "rf_raid.h"
39 #include "rf_raid1.h"
40 #include "rf_dag.h"
41 #include "rf_dagffrd.h"
42 #include "rf_dagffwr.h"
43 #include "rf_dagdegrd.h"
44 #include "rf_dagutils.h"
45 #include "rf_dagfuncs.h"
46 #include "rf_diskqueue.h"
47 #include "rf_general.h"
48 #include "rf_utils.h"
49 #include "rf_parityscan.h"
50 #include "rf_mcpair.h"
51 #include "rf_layout.h"
52 #include "rf_map.h"
53 #include "rf_engine.h"
54 #include "rf_reconbuffer.h"
55
56 typedef struct RF_Raid1ConfigInfo_s {
57 RF_RowCol_t **stripeIdentifier;
58 } RF_Raid1ConfigInfo_t;
59 /* start of day code specific to RAID level 1 */
60 int
61 rf_ConfigureRAID1(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr,
62 RF_Config_t *cfgPtr)
63 {
64 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
65 RF_Raid1ConfigInfo_t *info;
66 RF_RowCol_t i;
67
68 /* create a RAID level 1 configuration structure */
69 RF_MallocAndAdd(info, sizeof(RF_Raid1ConfigInfo_t), (RF_Raid1ConfigInfo_t *), raidPtr->cleanupList);
70 if (info == NULL)
71 return (ENOMEM);
72 layoutPtr->layoutSpecificInfo = (void *) info;
73
74 /* ... and fill it in. */
75 info->stripeIdentifier = rf_make_2d_array(raidPtr->numCol / 2, 2, raidPtr->cleanupList);
76 if (info->stripeIdentifier == NULL)
77 return (ENOMEM);
78 for (i = 0; i < (raidPtr->numCol / 2); i++) {
79 info->stripeIdentifier[i][0] = (2 * i);
80 info->stripeIdentifier[i][1] = (2 * i) + 1;
81 }
82
83 /* this implementation of RAID level 1 uses one row of numCol disks
84 * and allows multiple (numCol / 2) stripes per row. A stripe
85 * consists of a single data unit and a single parity (mirror) unit.
86 * stripe id = raidAddr / stripeUnitSize */
87 raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * (raidPtr->numCol / 2) * layoutPtr->sectorsPerStripeUnit;
88 layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk * (raidPtr->numCol / 2);
89 layoutPtr->dataSectorsPerStripe = layoutPtr->sectorsPerStripeUnit;
90 layoutPtr->numDataCol = 1;
91 layoutPtr->numParityCol = 1;
92 return (0);
93 }
94
95
96 /* returns the physical disk location of the primary copy in the mirror pair */
97 void
98 rf_MapSectorRAID1(RF_Raid_t *raidPtr, RF_RaidAddr_t raidSector,
99 RF_RowCol_t *col, RF_SectorNum_t *diskSector, int remap)
100 {
101 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
102 RF_RowCol_t mirrorPair = SUID % (raidPtr->numCol / 2);
103
104 *col = 2 * mirrorPair;
105 *diskSector = ((SUID / (raidPtr->numCol / 2)) * raidPtr->Layout.sectorsPerStripeUnit) + (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
106 }
107
108
109 /* Map Parity
110 *
111 * returns the physical disk location of the secondary copy in the mirror
112 * pair
113 */
114 void
115 rf_MapParityRAID1(RF_Raid_t *raidPtr, RF_RaidAddr_t raidSector,
116 RF_RowCol_t *col, RF_SectorNum_t *diskSector, int remap)
117 {
118 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
119 RF_RowCol_t mirrorPair = SUID % (raidPtr->numCol / 2);
120
121 *col = (2 * mirrorPair) + 1;
122
123 *diskSector = ((SUID / (raidPtr->numCol / 2)) * raidPtr->Layout.sectorsPerStripeUnit) + (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
124 }
125
126
127 /* IdentifyStripeRAID1
128 *
129 * returns a list of disks for a given redundancy group
130 */
131 void
132 rf_IdentifyStripeRAID1(RF_Raid_t *raidPtr, RF_RaidAddr_t addr,
133 RF_RowCol_t **diskids)
134 {
135 RF_StripeNum_t stripeID = rf_RaidAddressToStripeID(&raidPtr->Layout, addr);
136 RF_Raid1ConfigInfo_t *info = raidPtr->Layout.layoutSpecificInfo;
137 RF_ASSERT(stripeID >= 0);
138 RF_ASSERT(addr >= 0);
139 *diskids = info->stripeIdentifier[stripeID % (raidPtr->numCol / 2)];
140 RF_ASSERT(*diskids);
141 }
142
143
144 /* MapSIDToPSIDRAID1
145 *
146 * maps a logical stripe to a stripe in the redundant array
147 */
148 void
149 rf_MapSIDToPSIDRAID1(RF_RaidLayout_t *layoutPtr, RF_StripeNum_t stripeID,
150 RF_StripeNum_t *psID, RF_ReconUnitNum_t *which_ru)
151 {
152 *which_ru = 0;
153 *psID = stripeID;
154 }
155
156
157
158 /******************************************************************************
159 * select a graph to perform a single-stripe access
160 *
161 * Parameters: raidPtr - description of the physical array
162 * type - type of operation (read or write) requested
163 * asmap - logical & physical addresses for this access
164 * createFunc - name of function to use to create the graph
165 *****************************************************************************/
166
167 void
168 rf_RAID1DagSelect(RF_Raid_t *raidPtr, RF_IoType_t type,
169 RF_AccessStripeMap_t *asmap, RF_VoidFuncPtr *createFunc)
170 {
171 RF_RowCol_t fcol, oc;
172 RF_PhysDiskAddr_t *failedPDA;
173 int prior_recon;
174 RF_RowStatus_t rstat;
175 RF_SectorNum_t oo;
176
177
178 RF_ASSERT(RF_IO_IS_R_OR_W(type));
179
180 if (asmap->numDataFailed + asmap->numParityFailed > 1) {
181 if (rf_dagDebug)
182 RF_ERRORMSG("Multiple disks failed in a single group! Aborting I/O operation.\n");
183 *createFunc = NULL;
184 return;
185 }
186 if (asmap->numDataFailed + asmap->numParityFailed) {
187 /*
188 * We've got a fault. Re-map to spare space, iff applicable.
189 * Shouldn't the arch-independent code do this for us?
190 * Anyway, it turns out if we don't do this here, then when
191 * we're reconstructing, writes go only to the surviving
192 * original disk, and aren't reflected on the reconstructed
193 * spare. Oops. --jimz
194 */
195 failedPDA = asmap->failedPDAs[0];
196 fcol = failedPDA->col;
197 rstat = raidPtr->status;
198 prior_recon = (rstat == rf_rs_reconfigured) || (
199 (rstat == rf_rs_reconstructing) ?
200 rf_CheckRUReconstructed(raidPtr->reconControl->reconMap, failedPDA->startSector) : 0
201 );
202 if (prior_recon) {
203 oc = fcol;
204 oo = failedPDA->startSector;
205 /*
206 * If we did distributed sparing, we'd monkey with that here.
207 * But we don't, so we'll
208 */
209 failedPDA->col = raidPtr->Disks[fcol].spareCol;
210 /*
211 * Redirect other components, iff necessary. This looks
212 * pretty suspicious to me, but it's what the raid5
213 * DAG select does.
214 */
215 if (asmap->parityInfo->next) {
216 if (failedPDA == asmap->parityInfo) {
217 failedPDA->next->col = failedPDA->col;
218 } else {
219 if (failedPDA == asmap->parityInfo->next) {
220 asmap->parityInfo->col = failedPDA->col;
221 }
222 }
223 }
224 if (rf_dagDebug || rf_mapDebug) {
225 printf("raid%d: Redirected type '%c' c %d o %ld -> c %d o %ld\n",
226 raidPtr->raidid, type, oc,
227 (long) oo,
228 failedPDA->col,
229 (long) failedPDA->startSector);
230 }
231 asmap->numDataFailed = asmap->numParityFailed = 0;
232 }
233 }
234 if (type == RF_IO_TYPE_READ) {
235 if (asmap->numDataFailed == 0)
236 *createFunc = (RF_VoidFuncPtr) rf_CreateMirrorIdleReadDAG;
237 else
238 *createFunc = (RF_VoidFuncPtr) rf_CreateRaidOneDegradedReadDAG;
239 } else {
240 *createFunc = (RF_VoidFuncPtr) rf_CreateRaidOneWriteDAG;
241 }
242 }
243
244 int
245 rf_VerifyParityRAID1(RF_Raid_t *raidPtr, RF_RaidAddr_t raidAddr,
246 RF_PhysDiskAddr_t *parityPDA, int correct_it,
247 RF_RaidAccessFlags_t flags)
248 {
249 int nbytes, bcount, stripeWidth, ret, i, j, nbad, *bbufs;
250 RF_DagNode_t *blockNode, *wrBlock;
251 RF_DagHeader_t *rd_dag_h, *wr_dag_h;
252 RF_AccessStripeMapHeader_t *asm_h;
253 RF_AllocListElem_t *allocList;
254 RF_AccTraceEntry_t tracerec;
255 RF_ReconUnitNum_t which_ru;
256 RF_RaidLayout_t *layoutPtr;
257 RF_AccessStripeMap_t *aasm;
258 RF_SectorCount_t nsector;
259 RF_RaidAddr_t startAddr;
260 char *buf, *buf1, *buf2;
261 RF_PhysDiskAddr_t *pda;
262 RF_StripeNum_t psID;
263 RF_MCPair_t *mcpair;
264
265 layoutPtr = &raidPtr->Layout;
266 startAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, raidAddr);
267 nsector = parityPDA->numSector;
268 nbytes = rf_RaidAddressToByte(raidPtr, nsector);
269 psID = rf_RaidAddressToParityStripeID(layoutPtr, raidAddr, &which_ru);
270
271 asm_h = NULL;
272 rd_dag_h = wr_dag_h = NULL;
273 mcpair = NULL;
274
275 ret = RF_PARITY_COULD_NOT_VERIFY;
276
277 rf_MakeAllocList(allocList);
278 if (allocList == NULL)
279 return (RF_PARITY_COULD_NOT_VERIFY);
280 mcpair = rf_AllocMCPair();
281 if (mcpair == NULL)
282 goto done;
283 RF_ASSERT(layoutPtr->numDataCol == layoutPtr->numParityCol);
284 stripeWidth = layoutPtr->numDataCol + layoutPtr->numParityCol;
285 bcount = nbytes * (layoutPtr->numDataCol + layoutPtr->numParityCol);
286 RF_MallocAndAdd(buf, bcount, (char *), allocList);
287 if (buf == NULL)
288 goto done;
289 #if RF_DEBUG_VERIFYPARITY
290 if (rf_verifyParityDebug) {
291 printf("raid%d: RAID1 parity verify: buf=%lx bcount=%d (%lx - %lx)\n",
292 raidPtr->raidid, (long) buf, bcount, (long) buf,
293 (long) buf + bcount);
294 }
295 #endif
296 /*
297 * Generate a DAG which will read the entire stripe- then we can
298 * just compare data chunks versus "parity" chunks.
299 */
300
301 rd_dag_h = rf_MakeSimpleDAG(raidPtr, stripeWidth, nbytes, buf,
302 rf_DiskReadFunc, rf_DiskReadUndoFunc, "Rod", allocList, flags,
303 RF_IO_NORMAL_PRIORITY);
304 if (rd_dag_h == NULL)
305 goto done;
306 blockNode = rd_dag_h->succedents[0];
307
308 /*
309 * Map the access to physical disk addresses (PDAs)- this will
310 * get us both a list of data addresses, and "parity" addresses
311 * (which are really mirror copies).
312 */
313 asm_h = rf_MapAccess(raidPtr, startAddr, layoutPtr->dataSectorsPerStripe,
314 buf, RF_DONT_REMAP);
315 aasm = asm_h->stripeMap;
316
317 buf1 = buf;
318 /*
319 * Loop through the data blocks, setting up read nodes for each.
320 */
321 for (pda = aasm->physInfo, i = 0; i < layoutPtr->numDataCol; i++, pda = pda->next) {
322 RF_ASSERT(pda);
323
324 rf_RangeRestrictPDA(raidPtr, parityPDA, pda, 0, 1);
325
326 RF_ASSERT(pda->numSector != 0);
327 if (rf_TryToRedirectPDA(raidPtr, pda, 0)) {
328 /* cannot verify parity with dead disk */
329 goto done;
330 }
331 pda->bufPtr = buf1;
332 blockNode->succedents[i]->params[0].p = pda;
333 blockNode->succedents[i]->params[1].p = buf1;
334 blockNode->succedents[i]->params[2].v = psID;
335 blockNode->succedents[i]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
336 buf1 += nbytes;
337 }
338 RF_ASSERT(pda == NULL);
339 /*
340 * keep i, buf1 running
341 *
342 * Loop through parity blocks, setting up read nodes for each.
343 */
344 for (pda = aasm->parityInfo; i < layoutPtr->numDataCol + layoutPtr->numParityCol; i++, pda = pda->next) {
345 RF_ASSERT(pda);
346 rf_RangeRestrictPDA(raidPtr, parityPDA, pda, 0, 1);
347 RF_ASSERT(pda->numSector != 0);
348 if (rf_TryToRedirectPDA(raidPtr, pda, 0)) {
349 /* cannot verify parity with dead disk */
350 goto done;
351 }
352 pda->bufPtr = buf1;
353 blockNode->succedents[i]->params[0].p = pda;
354 blockNode->succedents[i]->params[1].p = buf1;
355 blockNode->succedents[i]->params[2].v = psID;
356 blockNode->succedents[i]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
357 buf1 += nbytes;
358 }
359 RF_ASSERT(pda == NULL);
360
361 memset((char *) &tracerec, 0, sizeof(tracerec));
362 rd_dag_h->tracerec = &tracerec;
363
364 #if 0
365 if (rf_verifyParityDebug > 1) {
366 printf("raid%d: RAID1 parity verify read dag:\n",
367 raidPtr->raidid);
368 rf_PrintDAGList(rd_dag_h);
369 }
370 #endif
371 RF_LOCK_MUTEX(mcpair->mutex);
372 mcpair->flag = 0;
373 RF_UNLOCK_MUTEX(mcpair->mutex);
374
375 rf_DispatchDAG(rd_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
376 (void *) mcpair);
377
378 RF_LOCK_MUTEX(mcpair->mutex);
379 while (mcpair->flag == 0) {
380 RF_WAIT_MCPAIR(mcpair);
381 }
382 RF_UNLOCK_MUTEX(mcpair->mutex);
383
384 if (rd_dag_h->status != rf_enable) {
385 RF_ERRORMSG("Unable to verify raid1 parity: can't read stripe\n");
386 ret = RF_PARITY_COULD_NOT_VERIFY;
387 goto done;
388 }
389 /*
390 * buf1 is the beginning of the data blocks chunk
391 * buf2 is the beginning of the parity blocks chunk
392 */
393 buf1 = buf;
394 buf2 = buf + (nbytes * layoutPtr->numDataCol);
395 ret = RF_PARITY_OKAY;
396 /*
397 * bbufs is "bad bufs"- an array whose entries are the data
398 * column numbers where we had miscompares. (That is, column 0
399 * and column 1 of the array are mirror copies, and are considered
400 * "data column 0" for this purpose).
401 */
402 RF_MallocAndAdd(bbufs, layoutPtr->numParityCol * sizeof(int), (int *),
403 allocList);
404 nbad = 0;
405 /*
406 * Check data vs "parity" (mirror copy).
407 */
408 for (i = 0; i < layoutPtr->numDataCol; i++) {
409 #if RF_DEBUG_VERIFYPARITY
410 if (rf_verifyParityDebug) {
411 printf("raid%d: RAID1 parity verify %d bytes: i=%d buf1=%lx buf2=%lx buf=%lx\n",
412 raidPtr->raidid, nbytes, i, (long) buf1,
413 (long) buf2, (long) buf);
414 }
415 #endif
416 ret = memcmp(buf1, buf2, nbytes);
417 if (ret) {
418 #if RF_DEBUG_VERIFYPARITY
419 if (rf_verifyParityDebug > 1) {
420 for (j = 0; j < nbytes; j++) {
421 if (buf1[j] != buf2[j])
422 break;
423 }
424 printf("psid=%ld j=%d\n", (long) psID, j);
425 printf("buf1 %02x %02x %02x %02x %02x\n", buf1[0] & 0xff,
426 buf1[1] & 0xff, buf1[2] & 0xff, buf1[3] & 0xff, buf1[4] & 0xff);
427 printf("buf2 %02x %02x %02x %02x %02x\n", buf2[0] & 0xff,
428 buf2[1] & 0xff, buf2[2] & 0xff, buf2[3] & 0xff, buf2[4] & 0xff);
429 }
430 if (rf_verifyParityDebug) {
431 printf("raid%d: RAID1: found bad parity, i=%d\n", raidPtr->raidid, i);
432 }
433 #endif
434 /*
435 * Parity is bad. Keep track of which columns were bad.
436 */
437 if (bbufs)
438 bbufs[nbad] = i;
439 nbad++;
440 ret = RF_PARITY_BAD;
441 }
442 buf1 += nbytes;
443 buf2 += nbytes;
444 }
445
446 if ((ret != RF_PARITY_OKAY) && correct_it) {
447 ret = RF_PARITY_COULD_NOT_CORRECT;
448 #if RF_DEBUG_VERIFYPARITY
449 if (rf_verifyParityDebug) {
450 printf("raid%d: RAID1 parity verify: parity not correct\n", raidPtr->raidid);
451 }
452 #endif
453 if (bbufs == NULL)
454 goto done;
455 /*
456 * Make a DAG with one write node for each bad unit. We'll simply
457 * write the contents of the data unit onto the parity unit for
458 * correction. (It's possible that the mirror copy was the correct
459 * copy, and that we're spooging good data by writing bad over it,
460 * but there's no way we can know that.
461 */
462 wr_dag_h = rf_MakeSimpleDAG(raidPtr, nbad, nbytes, buf,
463 rf_DiskWriteFunc, rf_DiskWriteUndoFunc, "Wnp", allocList, flags,
464 RF_IO_NORMAL_PRIORITY);
465 if (wr_dag_h == NULL)
466 goto done;
467 wrBlock = wr_dag_h->succedents[0];
468 /*
469 * Fill in a write node for each bad compare.
470 */
471 for (i = 0; i < nbad; i++) {
472 j = i + layoutPtr->numDataCol;
473 pda = blockNode->succedents[j]->params[0].p;
474 pda->bufPtr = blockNode->succedents[i]->params[1].p;
475 wrBlock->succedents[i]->params[0].p = pda;
476 wrBlock->succedents[i]->params[1].p = pda->bufPtr;
477 wrBlock->succedents[i]->params[2].v = psID;
478 wrBlock->succedents[0]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
479 }
480 memset((char *) &tracerec, 0, sizeof(tracerec));
481 wr_dag_h->tracerec = &tracerec;
482 #if 0
483 if (rf_verifyParityDebug > 1) {
484 printf("Parity verify write dag:\n");
485 rf_PrintDAGList(wr_dag_h);
486 }
487 #endif
488 RF_LOCK_MUTEX(mcpair->mutex);
489 mcpair->flag = 0;
490 /* fire off the write DAG */
491 rf_DispatchDAG(wr_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
492 (void *) mcpair);
493 while (!mcpair->flag) {
494 RF_WAIT_COND(mcpair->cond, mcpair->mutex);
495 }
496 RF_UNLOCK_MUTEX(mcpair->mutex);
497 if (wr_dag_h->status != rf_enable) {
498 RF_ERRORMSG("Unable to correct RAID1 parity in VerifyParity\n");
499 goto done;
500 }
501 ret = RF_PARITY_CORRECTED;
502 }
503 done:
504 /*
505 * All done. We might've gotten here without doing part of the function,
506 * so cleanup what we have to and return our running status.
507 */
508 if (asm_h)
509 rf_FreeAccessStripeMap(asm_h);
510 if (rd_dag_h)
511 rf_FreeDAG(rd_dag_h);
512 if (wr_dag_h)
513 rf_FreeDAG(wr_dag_h);
514 if (mcpair)
515 rf_FreeMCPair(mcpair);
516 rf_FreeAllocList(allocList);
517 #if RF_DEBUG_VERIFYPARITY
518 if (rf_verifyParityDebug) {
519 printf("raid%d: RAID1 parity verify, returning %d\n",
520 raidPtr->raidid, ret);
521 }
522 #endif
523 return (ret);
524 }
525
526 /* rbuf - the recon buffer to submit
527 * keep_it - whether we can keep this buffer or we have to return it
528 * use_committed - whether to use a committed or an available recon buffer
529 */
530
531 int
532 rf_SubmitReconBufferRAID1(RF_ReconBuffer_t *rbuf, int keep_it,
533 int use_committed)
534 {
535 RF_ReconParityStripeStatus_t *pssPtr;
536 RF_ReconCtrl_t *reconCtrlPtr;
537 int retcode, created;
538 RF_CallbackDesc_t *cb, *p;
539 RF_ReconBuffer_t *t;
540 RF_Raid_t *raidPtr;
541 caddr_t ta;
542
543 retcode = 0;
544 created = 0;
545
546 raidPtr = rbuf->raidPtr;
547 reconCtrlPtr = raidPtr->reconControl;
548
549 RF_ASSERT(rbuf);
550 RF_ASSERT(rbuf->col != reconCtrlPtr->fcol);
551
552 #if RF_DEBUG_RECON
553 if (rf_reconbufferDebug) {
554 printf("raid%d: RAID1 reconbuffer submission c%d psid %ld ru%d (failed offset %ld)\n",
555 raidPtr->raidid, rbuf->col,
556 (long) rbuf->parityStripeID, rbuf->which_ru,
557 (long) rbuf->failedDiskSectorOffset);
558 }
559 #endif
560 if (rf_reconDebug) {
561 printf("RAID1 reconbuffer submit psid %ld buf %lx\n",
562 (long) rbuf->parityStripeID, (long) rbuf->buffer);
563 printf("RAID1 psid %ld %02x %02x %02x %02x %02x\n",
564 (long) rbuf->parityStripeID,
565 rbuf->buffer[0], rbuf->buffer[1], rbuf->buffer[2], rbuf->buffer[3],
566 rbuf->buffer[4]);
567 }
568 RF_LOCK_PSS_MUTEX(raidPtr, rbuf->parityStripeID);
569
570 RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
571
572 pssPtr = rf_LookupRUStatus(raidPtr, reconCtrlPtr->pssTable,
573 rbuf->parityStripeID, rbuf->which_ru, RF_PSS_NONE, &created);
574 RF_ASSERT(pssPtr); /* if it didn't exist, we wouldn't have gotten
575 * an rbuf for it */
576
577 /*
578 * Since this is simple mirroring, the first submission for a stripe is also
579 * treated as the last.
580 */
581
582 t = NULL;
583 if (keep_it) {
584 #if RF_DEBUG_RECON
585 if (rf_reconbufferDebug) {
586 printf("raid%d: RAID1 rbuf submission: keeping rbuf\n",
587 raidPtr->raidid);
588 }
589 #endif
590 t = rbuf;
591 } else {
592 if (use_committed) {
593 #if RF_DEBUG_RECON
594 if (rf_reconbufferDebug) {
595 printf("raid%d: RAID1 rbuf submission: using committed rbuf\n", raidPtr->raidid);
596 }
597 #endif
598 t = reconCtrlPtr->committedRbufs;
599 RF_ASSERT(t);
600 reconCtrlPtr->committedRbufs = t->next;
601 t->next = NULL;
602 } else
603 if (reconCtrlPtr->floatingRbufs) {
604 #if RF_DEBUG_RECON
605 if (rf_reconbufferDebug) {
606 printf("raid%d: RAID1 rbuf submission: using floating rbuf\n", raidPtr->raidid);
607 }
608 #endif
609 t = reconCtrlPtr->floatingRbufs;
610 reconCtrlPtr->floatingRbufs = t->next;
611 t->next = NULL;
612 }
613 }
614 if (t == NULL) {
615 #if RF_DEBUG_RECON
616 if (rf_reconbufferDebug) {
617 printf("raid%d: RAID1 rbuf submission: waiting for rbuf\n", raidPtr->raidid);
618 }
619 #endif
620 RF_ASSERT((keep_it == 0) && (use_committed == 0));
621 raidPtr->procsInBufWait++;
622 if ((raidPtr->procsInBufWait == (raidPtr->numCol - 1))
623 && (raidPtr->numFullReconBuffers == 0)) {
624 /* ruh-ro */
625 RF_ERRORMSG("Buffer wait deadlock\n");
626 rf_PrintPSStatusTable(raidPtr);
627 RF_PANIC();
628 }
629 pssPtr->flags |= RF_PSS_BUFFERWAIT;
630 cb = rf_AllocCallbackDesc();
631 cb->col = rbuf->col;
632 cb->callbackArg.v = rbuf->parityStripeID;
633 cb->callbackArg2.v = rbuf->which_ru;
634 cb->next = NULL;
635 if (reconCtrlPtr->bufferWaitList == NULL) {
636 /* we are the wait list- lucky us */
637 reconCtrlPtr->bufferWaitList = cb;
638 } else {
639 /* append to wait list */
640 for (p = reconCtrlPtr->bufferWaitList; p->next; p = p->next);
641 p->next = cb;
642 }
643 retcode = 1;
644 goto out;
645 }
646 if (t != rbuf) {
647 t->col = reconCtrlPtr->fcol;
648 t->parityStripeID = rbuf->parityStripeID;
649 t->which_ru = rbuf->which_ru;
650 t->failedDiskSectorOffset = rbuf->failedDiskSectorOffset;
651 t->spCol = rbuf->spCol;
652 t->spOffset = rbuf->spOffset;
653 /* Swap buffers. DANCE! */
654 ta = t->buffer;
655 t->buffer = rbuf->buffer;
656 rbuf->buffer = ta;
657 }
658 /*
659 * Use the rbuf we've been given as the target.
660 */
661 RF_ASSERT(pssPtr->rbuf == NULL);
662 pssPtr->rbuf = t;
663
664 t->count = 1;
665 /*
666 * Below, we use 1 for numDataCol (which is equal to the count in the
667 * previous line), so we'll always be done.
668 */
669 rf_CheckForFullRbuf(raidPtr, reconCtrlPtr, pssPtr, 1);
670
671 out:
672 RF_UNLOCK_PSS_MUTEX(raidPtr, rbuf->parityStripeID);
673 RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
674 #if RF_DEBUG_RECON
675 if (rf_reconbufferDebug) {
676 printf("raid%d: RAID1 rbuf submission: returning %d\n",
677 raidPtr->raidid, retcode);
678 }
679 #endif
680 return (retcode);
681 }
682