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