rf_raid1.c revision 1.15 1 /* $NetBSD: rf_raid1.c,v 1.15 2003/12/30 21:59:03 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.15 2003/12/30 21:59:03 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 RF_ERRORMSG("Multiple disks failed in a single group! Aborting I/O operation.\n");
182 *createFunc = NULL;
183 return;
184 }
185 if (asmap->numDataFailed + asmap->numParityFailed) {
186 /*
187 * We've got a fault. Re-map to spare space, iff applicable.
188 * Shouldn't the arch-independent code do this for us?
189 * Anyway, it turns out if we don't do this here, then when
190 * we're reconstructing, writes go only to the surviving
191 * original disk, and aren't reflected on the reconstructed
192 * spare. Oops. --jimz
193 */
194 failedPDA = asmap->failedPDAs[0];
195 fcol = failedPDA->col;
196 rstat = raidPtr->status;
197 prior_recon = (rstat == rf_rs_reconfigured) || (
198 (rstat == rf_rs_reconstructing) ?
199 rf_CheckRUReconstructed(raidPtr->reconControl->reconMap, failedPDA->startSector) : 0
200 );
201 if (prior_recon) {
202 oc = fcol;
203 oo = failedPDA->startSector;
204 /*
205 * If we did distributed sparing, we'd monkey with that here.
206 * But we don't, so we'll
207 */
208 failedPDA->col = raidPtr->Disks[fcol].spareCol;
209 /*
210 * Redirect other components, iff necessary. This looks
211 * pretty suspicious to me, but it's what the raid5
212 * DAG select does.
213 */
214 if (asmap->parityInfo->next) {
215 if (failedPDA == asmap->parityInfo) {
216 failedPDA->next->col = failedPDA->col;
217 } else {
218 if (failedPDA == asmap->parityInfo->next) {
219 asmap->parityInfo->col = failedPDA->col;
220 }
221 }
222 }
223 if (rf_dagDebug || rf_mapDebug) {
224 printf("raid%d: Redirected type '%c' c %d o %ld -> c %d o %ld\n",
225 raidPtr->raidid, type, oc,
226 (long) oo,
227 failedPDA->col,
228 (long) failedPDA->startSector);
229 }
230 asmap->numDataFailed = asmap->numParityFailed = 0;
231 }
232 }
233 if (type == RF_IO_TYPE_READ) {
234 if (asmap->numDataFailed == 0)
235 *createFunc = (RF_VoidFuncPtr) rf_CreateMirrorIdleReadDAG;
236 else
237 *createFunc = (RF_VoidFuncPtr) rf_CreateRaidOneDegradedReadDAG;
238 } else {
239 *createFunc = (RF_VoidFuncPtr) rf_CreateRaidOneWriteDAG;
240 }
241 }
242
243 int
244 rf_VerifyParityRAID1(RF_Raid_t *raidPtr, RF_RaidAddr_t raidAddr,
245 RF_PhysDiskAddr_t *parityPDA, int correct_it,
246 RF_RaidAccessFlags_t flags)
247 {
248 int nbytes, bcount, stripeWidth, ret, i, j, nbad, *bbufs;
249 RF_DagNode_t *blockNode, *wrBlock;
250 RF_DagHeader_t *rd_dag_h, *wr_dag_h;
251 RF_AccessStripeMapHeader_t *asm_h;
252 RF_AllocListElem_t *allocList;
253 RF_AccTraceEntry_t tracerec;
254 RF_ReconUnitNum_t which_ru;
255 RF_RaidLayout_t *layoutPtr;
256 RF_AccessStripeMap_t *aasm;
257 RF_SectorCount_t nsector;
258 RF_RaidAddr_t startAddr;
259 char *buf, *buf1, *buf2;
260 RF_PhysDiskAddr_t *pda;
261 RF_StripeNum_t psID;
262 RF_MCPair_t *mcpair;
263
264 layoutPtr = &raidPtr->Layout;
265 startAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, raidAddr);
266 nsector = parityPDA->numSector;
267 nbytes = rf_RaidAddressToByte(raidPtr, nsector);
268 psID = rf_RaidAddressToParityStripeID(layoutPtr, raidAddr, &which_ru);
269
270 asm_h = NULL;
271 rd_dag_h = wr_dag_h = NULL;
272 mcpair = NULL;
273
274 ret = RF_PARITY_COULD_NOT_VERIFY;
275
276 rf_MakeAllocList(allocList);
277 if (allocList == NULL)
278 return (RF_PARITY_COULD_NOT_VERIFY);
279 mcpair = rf_AllocMCPair();
280 if (mcpair == NULL)
281 goto done;
282 RF_ASSERT(layoutPtr->numDataCol == layoutPtr->numParityCol);
283 stripeWidth = layoutPtr->numDataCol + layoutPtr->numParityCol;
284 bcount = nbytes * (layoutPtr->numDataCol + layoutPtr->numParityCol);
285 RF_MallocAndAdd(buf, bcount, (char *), allocList);
286 if (buf == NULL)
287 goto done;
288 #if RF_DEBUG_VERIFYPARITY
289 if (rf_verifyParityDebug) {
290 printf("raid%d: RAID1 parity verify: buf=%lx bcount=%d (%lx - %lx)\n",
291 raidPtr->raidid, (long) buf, bcount, (long) buf,
292 (long) buf + bcount);
293 }
294 #endif
295 /*
296 * Generate a DAG which will read the entire stripe- then we can
297 * just compare data chunks versus "parity" chunks.
298 */
299
300 rd_dag_h = rf_MakeSimpleDAG(raidPtr, stripeWidth, nbytes, buf,
301 rf_DiskReadFunc, rf_DiskReadUndoFunc, "Rod", allocList, flags,
302 RF_IO_NORMAL_PRIORITY);
303 if (rd_dag_h == NULL)
304 goto done;
305 blockNode = rd_dag_h->succedents[0];
306
307 /*
308 * Map the access to physical disk addresses (PDAs)- this will
309 * get us both a list of data addresses, and "parity" addresses
310 * (which are really mirror copies).
311 */
312 asm_h = rf_MapAccess(raidPtr, startAddr, layoutPtr->dataSectorsPerStripe,
313 buf, RF_DONT_REMAP);
314 aasm = asm_h->stripeMap;
315
316 buf1 = buf;
317 /*
318 * Loop through the data blocks, setting up read nodes for each.
319 */
320 for (pda = aasm->physInfo, i = 0; i < layoutPtr->numDataCol; i++, pda = pda->next) {
321 RF_ASSERT(pda);
322
323 rf_RangeRestrictPDA(raidPtr, parityPDA, pda, 0, 1);
324
325 RF_ASSERT(pda->numSector != 0);
326 if (rf_TryToRedirectPDA(raidPtr, pda, 0)) {
327 /* cannot verify parity with dead disk */
328 goto done;
329 }
330 pda->bufPtr = buf1;
331 blockNode->succedents[i]->params[0].p = pda;
332 blockNode->succedents[i]->params[1].p = buf1;
333 blockNode->succedents[i]->params[2].v = psID;
334 blockNode->succedents[i]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
335 buf1 += nbytes;
336 }
337 RF_ASSERT(pda == NULL);
338 /*
339 * keep i, buf1 running
340 *
341 * Loop through parity blocks, setting up read nodes for each.
342 */
343 for (pda = aasm->parityInfo; i < layoutPtr->numDataCol + layoutPtr->numParityCol; i++, pda = pda->next) {
344 RF_ASSERT(pda);
345 rf_RangeRestrictPDA(raidPtr, parityPDA, pda, 0, 1);
346 RF_ASSERT(pda->numSector != 0);
347 if (rf_TryToRedirectPDA(raidPtr, pda, 0)) {
348 /* cannot verify parity with dead disk */
349 goto done;
350 }
351 pda->bufPtr = buf1;
352 blockNode->succedents[i]->params[0].p = pda;
353 blockNode->succedents[i]->params[1].p = buf1;
354 blockNode->succedents[i]->params[2].v = psID;
355 blockNode->succedents[i]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
356 buf1 += nbytes;
357 }
358 RF_ASSERT(pda == NULL);
359
360 memset((char *) &tracerec, 0, sizeof(tracerec));
361 rd_dag_h->tracerec = &tracerec;
362
363 #if 0
364 if (rf_verifyParityDebug > 1) {
365 printf("raid%d: RAID1 parity verify read dag:\n",
366 raidPtr->raidid);
367 rf_PrintDAGList(rd_dag_h);
368 }
369 #endif
370 RF_LOCK_MUTEX(mcpair->mutex);
371 mcpair->flag = 0;
372 rf_DispatchDAG(rd_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
373 (void *) mcpair);
374 while (mcpair->flag == 0) {
375 RF_WAIT_MCPAIR(mcpair);
376 }
377 RF_UNLOCK_MUTEX(mcpair->mutex);
378
379 if (rd_dag_h->status != rf_enable) {
380 RF_ERRORMSG("Unable to verify raid1 parity: can't read stripe\n");
381 ret = RF_PARITY_COULD_NOT_VERIFY;
382 goto done;
383 }
384 /*
385 * buf1 is the beginning of the data blocks chunk
386 * buf2 is the beginning of the parity blocks chunk
387 */
388 buf1 = buf;
389 buf2 = buf + (nbytes * layoutPtr->numDataCol);
390 ret = RF_PARITY_OKAY;
391 /*
392 * bbufs is "bad bufs"- an array whose entries are the data
393 * column numbers where we had miscompares. (That is, column 0
394 * and column 1 of the array are mirror copies, and are considered
395 * "data column 0" for this purpose).
396 */
397 RF_MallocAndAdd(bbufs, layoutPtr->numParityCol * sizeof(int), (int *),
398 allocList);
399 nbad = 0;
400 /*
401 * Check data vs "parity" (mirror copy).
402 */
403 for (i = 0; i < layoutPtr->numDataCol; i++) {
404 #if RF_DEBUG_VERIFYPARITY
405 if (rf_verifyParityDebug) {
406 printf("raid%d: RAID1 parity verify %d bytes: i=%d buf1=%lx buf2=%lx buf=%lx\n",
407 raidPtr->raidid, nbytes, i, (long) buf1,
408 (long) buf2, (long) buf);
409 }
410 #endif
411 ret = memcmp(buf1, buf2, nbytes);
412 if (ret) {
413 #if RF_DEBUG_VERIFYPARITY
414 if (rf_verifyParityDebug > 1) {
415 for (j = 0; j < nbytes; j++) {
416 if (buf1[j] != buf2[j])
417 break;
418 }
419 printf("psid=%ld j=%d\n", (long) psID, j);
420 printf("buf1 %02x %02x %02x %02x %02x\n", buf1[0] & 0xff,
421 buf1[1] & 0xff, buf1[2] & 0xff, buf1[3] & 0xff, buf1[4] & 0xff);
422 printf("buf2 %02x %02x %02x %02x %02x\n", buf2[0] & 0xff,
423 buf2[1] & 0xff, buf2[2] & 0xff, buf2[3] & 0xff, buf2[4] & 0xff);
424 }
425 if (rf_verifyParityDebug) {
426 printf("raid%d: RAID1: found bad parity, i=%d\n", raidPtr->raidid, i);
427 }
428 #endif
429 /*
430 * Parity is bad. Keep track of which columns were bad.
431 */
432 if (bbufs)
433 bbufs[nbad] = i;
434 nbad++;
435 ret = RF_PARITY_BAD;
436 }
437 buf1 += nbytes;
438 buf2 += nbytes;
439 }
440
441 if ((ret != RF_PARITY_OKAY) && correct_it) {
442 ret = RF_PARITY_COULD_NOT_CORRECT;
443 #if RF_DEBUG_VERIFYPARITY
444 if (rf_verifyParityDebug) {
445 printf("raid%d: RAID1 parity verify: parity not correct\n", raidPtr->raidid);
446 }
447 #endif
448 if (bbufs == NULL)
449 goto done;
450 /*
451 * Make a DAG with one write node for each bad unit. We'll simply
452 * write the contents of the data unit onto the parity unit for
453 * correction. (It's possible that the mirror copy was the correct
454 * copy, and that we're spooging good data by writing bad over it,
455 * but there's no way we can know that.
456 */
457 wr_dag_h = rf_MakeSimpleDAG(raidPtr, nbad, nbytes, buf,
458 rf_DiskWriteFunc, rf_DiskWriteUndoFunc, "Wnp", allocList, flags,
459 RF_IO_NORMAL_PRIORITY);
460 if (wr_dag_h == NULL)
461 goto done;
462 wrBlock = wr_dag_h->succedents[0];
463 /*
464 * Fill in a write node for each bad compare.
465 */
466 for (i = 0; i < nbad; i++) {
467 j = i + layoutPtr->numDataCol;
468 pda = blockNode->succedents[j]->params[0].p;
469 pda->bufPtr = blockNode->succedents[i]->params[1].p;
470 wrBlock->succedents[i]->params[0].p = pda;
471 wrBlock->succedents[i]->params[1].p = pda->bufPtr;
472 wrBlock->succedents[i]->params[2].v = psID;
473 wrBlock->succedents[0]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
474 }
475 memset((char *) &tracerec, 0, sizeof(tracerec));
476 wr_dag_h->tracerec = &tracerec;
477 #if 0
478 if (rf_verifyParityDebug > 1) {
479 printf("Parity verify write dag:\n");
480 rf_PrintDAGList(wr_dag_h);
481 }
482 #endif
483 RF_LOCK_MUTEX(mcpair->mutex);
484 mcpair->flag = 0;
485 /* fire off the write DAG */
486 rf_DispatchDAG(wr_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
487 (void *) mcpair);
488 while (!mcpair->flag) {
489 RF_WAIT_COND(mcpair->cond, mcpair->mutex);
490 }
491 RF_UNLOCK_MUTEX(mcpair->mutex);
492 if (wr_dag_h->status != rf_enable) {
493 RF_ERRORMSG("Unable to correct RAID1 parity in VerifyParity\n");
494 goto done;
495 }
496 ret = RF_PARITY_CORRECTED;
497 }
498 done:
499 /*
500 * All done. We might've gotten here without doing part of the function,
501 * so cleanup what we have to and return our running status.
502 */
503 if (asm_h)
504 rf_FreeAccessStripeMap(asm_h);
505 if (rd_dag_h)
506 rf_FreeDAG(rd_dag_h);
507 if (wr_dag_h)
508 rf_FreeDAG(wr_dag_h);
509 if (mcpair)
510 rf_FreeMCPair(mcpair);
511 rf_FreeAllocList(allocList);
512 #if RF_DEBUG_VERIFYPARITY
513 if (rf_verifyParityDebug) {
514 printf("raid%d: RAID1 parity verify, returning %d\n",
515 raidPtr->raidid, ret);
516 }
517 #endif
518 return (ret);
519 }
520
521 /* rbuf - the recon buffer to submit
522 * keep_it - whether we can keep this buffer or we have to return it
523 * use_committed - whether to use a committed or an available recon buffer
524 */
525
526 int
527 rf_SubmitReconBufferRAID1(RF_ReconBuffer_t *rbuf, int keep_it,
528 int use_committed)
529 {
530 RF_ReconParityStripeStatus_t *pssPtr;
531 RF_ReconCtrl_t *reconCtrlPtr;
532 int retcode, created;
533 RF_CallbackDesc_t *cb, *p;
534 RF_ReconBuffer_t *t;
535 RF_Raid_t *raidPtr;
536 caddr_t ta;
537
538 retcode = 0;
539 created = 0;
540
541 raidPtr = rbuf->raidPtr;
542 reconCtrlPtr = raidPtr->reconControl;
543
544 RF_ASSERT(rbuf);
545 RF_ASSERT(rbuf->col != reconCtrlPtr->fcol);
546
547 #if RF_DEBUG_RECON
548 if (rf_reconbufferDebug) {
549 printf("raid%d: RAID1 reconbuffer submission c%d psid %ld ru%d (failed offset %ld)\n",
550 raidPtr->raidid, rbuf->col,
551 (long) rbuf->parityStripeID, rbuf->which_ru,
552 (long) rbuf->failedDiskSectorOffset);
553 }
554 #endif
555 if (rf_reconDebug) {
556 printf("RAID1 reconbuffer submit psid %ld buf %lx\n",
557 (long) rbuf->parityStripeID, (long) rbuf->buffer);
558 printf("RAID1 psid %ld %02x %02x %02x %02x %02x\n",
559 (long) rbuf->parityStripeID,
560 rbuf->buffer[0], rbuf->buffer[1], rbuf->buffer[2], rbuf->buffer[3],
561 rbuf->buffer[4]);
562 }
563 RF_LOCK_PSS_MUTEX(raidPtr, rbuf->parityStripeID);
564
565 RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
566
567 pssPtr = rf_LookupRUStatus(raidPtr, reconCtrlPtr->pssTable,
568 rbuf->parityStripeID, rbuf->which_ru, RF_PSS_NONE, &created);
569 RF_ASSERT(pssPtr); /* if it didn't exist, we wouldn't have gotten
570 * an rbuf for it */
571
572 /*
573 * Since this is simple mirroring, the first submission for a stripe is also
574 * treated as the last.
575 */
576
577 t = NULL;
578 if (keep_it) {
579 #if RF_DEBUG_RECON
580 if (rf_reconbufferDebug) {
581 printf("raid%d: RAID1 rbuf submission: keeping rbuf\n",
582 raidPtr->raidid);
583 }
584 #endif
585 t = rbuf;
586 } else {
587 if (use_committed) {
588 #if RF_DEBUG_RECON
589 if (rf_reconbufferDebug) {
590 printf("raid%d: RAID1 rbuf submission: using committed rbuf\n", raidPtr->raidid);
591 }
592 #endif
593 t = reconCtrlPtr->committedRbufs;
594 RF_ASSERT(t);
595 reconCtrlPtr->committedRbufs = t->next;
596 t->next = NULL;
597 } else
598 if (reconCtrlPtr->floatingRbufs) {
599 #if RF_DEBUG_RECON
600 if (rf_reconbufferDebug) {
601 printf("raid%d: RAID1 rbuf submission: using floating rbuf\n", raidPtr->raidid);
602 }
603 #endif
604 t = reconCtrlPtr->floatingRbufs;
605 reconCtrlPtr->floatingRbufs = t->next;
606 t->next = NULL;
607 }
608 }
609 if (t == NULL) {
610 #if RF_DEBUG_RECON
611 if (rf_reconbufferDebug) {
612 printf("raid%d: RAID1 rbuf submission: waiting for rbuf\n", raidPtr->raidid);
613 }
614 #endif
615 RF_ASSERT((keep_it == 0) && (use_committed == 0));
616 raidPtr->procsInBufWait++;
617 if ((raidPtr->procsInBufWait == (raidPtr->numCol - 1))
618 && (raidPtr->numFullReconBuffers == 0)) {
619 /* ruh-ro */
620 RF_ERRORMSG("Buffer wait deadlock\n");
621 rf_PrintPSStatusTable(raidPtr);
622 RF_PANIC();
623 }
624 pssPtr->flags |= RF_PSS_BUFFERWAIT;
625 cb = rf_AllocCallbackDesc();
626 cb->col = rbuf->col;
627 cb->callbackArg.v = rbuf->parityStripeID;
628 cb->callbackArg2.v = rbuf->which_ru;
629 cb->next = NULL;
630 if (reconCtrlPtr->bufferWaitList == NULL) {
631 /* we are the wait list- lucky us */
632 reconCtrlPtr->bufferWaitList = cb;
633 } else {
634 /* append to wait list */
635 for (p = reconCtrlPtr->bufferWaitList; p->next; p = p->next);
636 p->next = cb;
637 }
638 retcode = 1;
639 goto out;
640 }
641 if (t != rbuf) {
642 t->col = reconCtrlPtr->fcol;
643 t->parityStripeID = rbuf->parityStripeID;
644 t->which_ru = rbuf->which_ru;
645 t->failedDiskSectorOffset = rbuf->failedDiskSectorOffset;
646 t->spCol = rbuf->spCol;
647 t->spOffset = rbuf->spOffset;
648 /* Swap buffers. DANCE! */
649 ta = t->buffer;
650 t->buffer = rbuf->buffer;
651 rbuf->buffer = ta;
652 }
653 /*
654 * Use the rbuf we've been given as the target.
655 */
656 RF_ASSERT(pssPtr->rbuf == NULL);
657 pssPtr->rbuf = t;
658
659 t->count = 1;
660 /*
661 * Below, we use 1 for numDataCol (which is equal to the count in the
662 * previous line), so we'll always be done.
663 */
664 rf_CheckForFullRbuf(raidPtr, reconCtrlPtr, pssPtr, 1);
665
666 out:
667 RF_UNLOCK_PSS_MUTEX(raidPtr, rbuf->parityStripeID);
668 RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
669 #if RF_DEBUG_RECON
670 if (rf_reconbufferDebug) {
671 printf("raid%d: RAID1 rbuf submission: returning %d\n",
672 raidPtr->raidid, retcode);
673 }
674 #endif
675 return (retcode);
676 }
677