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