1 /* $NetBSD: rf_reconstruct.c,v 1.28 2001/06/14 02:35:56 oster Exp $ */ 2 /* 3 * Copyright (c) 1995 Carnegie-Mellon University. 4 * All rights reserved. 5 * 6 * Author: Mark Holland 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_reconstruct.c -- code to perform on-line reconstruction 32 * 33 ************************************************************/ 34 35 #include "rf_types.h" 36 #include <sys/time.h> 37 #include <sys/buf.h> 38 #include <sys/errno.h> 39 40 #include <sys/types.h> 41 #include <sys/param.h> 42 #include <sys/systm.h> 43 #include <sys/proc.h> 44 #include <sys/ioctl.h> 45 #include <sys/fcntl.h> 46 #include <sys/vnode.h> 47 48 49 #include "rf_raid.h" 50 #include "rf_reconutil.h" 51 #include "rf_revent.h" 52 #include "rf_reconbuffer.h" 53 #include "rf_acctrace.h" 54 #include "rf_etimer.h" 55 #include "rf_dag.h" 56 #include "rf_desc.h" 57 #include "rf_general.h" 58 #include "rf_freelist.h" 59 #include "rf_debugprint.h" 60 #include "rf_driver.h" 61 #include "rf_utils.h" 62 #include "rf_shutdown.h" 63 64 #include "rf_kintf.h" 65 66 /* setting these to -1 causes them to be set to their default values if not set by debug options */ 67 68 #define Dprintf(s) if (rf_reconDebug) rf_debug_printf(s,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL) 69 #define Dprintf1(s,a) if (rf_reconDebug) rf_debug_printf(s,(void *)((unsigned long)a),NULL,NULL,NULL,NULL,NULL,NULL,NULL) 70 #define Dprintf2(s,a,b) if (rf_reconDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),NULL,NULL,NULL,NULL,NULL,NULL) 71 #define Dprintf3(s,a,b,c) if (rf_reconDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),(void *)((unsigned long)c),NULL,NULL,NULL,NULL,NULL) 72 #define Dprintf4(s,a,b,c,d) if (rf_reconDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),(void *)((unsigned long)c),(void *)((unsigned long)d),NULL,NULL,NULL,NULL) 73 #define Dprintf5(s,a,b,c,d,e) if (rf_reconDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),(void *)((unsigned long)c),(void *)((unsigned long)d),(void *)((unsigned long)e),NULL,NULL,NULL) 74 #define Dprintf6(s,a,b,c,d,e,f) if (rf_reconDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),(void *)((unsigned long)c),(void *)((unsigned long)d),(void *)((unsigned long)e),(void *)((unsigned long)f),NULL,NULL) 75 #define Dprintf7(s,a,b,c,d,e,f,g) if (rf_reconDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),(void *)((unsigned long)c),(void *)((unsigned long)d),(void *)((unsigned long)e),(void *)((unsigned long)f),(void *)((unsigned long)g),NULL) 76 77 #define DDprintf1(s,a) if (rf_reconDebug) rf_debug_printf(s,(void *)((unsigned long)a),NULL,NULL,NULL,NULL,NULL,NULL,NULL) 78 #define DDprintf2(s,a,b) if (rf_reconDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),NULL,NULL,NULL,NULL,NULL,NULL) 79 80 static RF_FreeList_t *rf_recond_freelist; 81 #define RF_MAX_FREE_RECOND 4 82 #define RF_RECOND_INC 1 83 84 static RF_RaidReconDesc_t * 85 AllocRaidReconDesc(RF_Raid_t * raidPtr, 86 RF_RowCol_t row, RF_RowCol_t col, RF_RaidDisk_t * spareDiskPtr, 87 int numDisksDone, RF_RowCol_t srow, RF_RowCol_t scol); 88 static void FreeReconDesc(RF_RaidReconDesc_t * reconDesc); 89 static int 90 ProcessReconEvent(RF_Raid_t * raidPtr, RF_RowCol_t frow, 91 RF_ReconEvent_t * event); 92 static int 93 IssueNextReadRequest(RF_Raid_t * raidPtr, RF_RowCol_t row, 94 RF_RowCol_t col); 95 static int TryToRead(RF_Raid_t * raidPtr, RF_RowCol_t row, RF_RowCol_t col); 96 static int 97 ComputePSDiskOffsets(RF_Raid_t * raidPtr, RF_StripeNum_t psid, 98 RF_RowCol_t row, RF_RowCol_t col, RF_SectorNum_t * outDiskOffset, 99 RF_SectorNum_t * outFailedDiskSectorOffset, RF_RowCol_t * spRow, 100 RF_RowCol_t * spCol, RF_SectorNum_t * spOffset); 101 static int IssueNextWriteRequest(RF_Raid_t * raidPtr, RF_RowCol_t row); 102 static int ReconReadDoneProc(void *arg, int status); 103 static int ReconWriteDoneProc(void *arg, int status); 104 static void 105 CheckForNewMinHeadSep(RF_Raid_t * raidPtr, RF_RowCol_t row, 106 RF_HeadSepLimit_t hsCtr); 107 static int 108 CheckHeadSeparation(RF_Raid_t * raidPtr, RF_PerDiskReconCtrl_t * ctrl, 109 RF_RowCol_t row, RF_RowCol_t col, RF_HeadSepLimit_t hsCtr, 110 RF_ReconUnitNum_t which_ru); 111 static int 112 CheckForcedOrBlockedReconstruction(RF_Raid_t * raidPtr, 113 RF_ReconParityStripeStatus_t * pssPtr, RF_PerDiskReconCtrl_t * ctrl, 114 RF_RowCol_t row, RF_RowCol_t col, RF_StripeNum_t psid, 115 RF_ReconUnitNum_t which_ru); 116 static void ForceReconReadDoneProc(void *arg, int status); 117 118 static void rf_ShutdownReconstruction(void *); 119 120 struct RF_ReconDoneProc_s { 121 void (*proc) (RF_Raid_t *, void *); 122 void *arg; 123 RF_ReconDoneProc_t *next; 124 }; 125 126 static RF_FreeList_t *rf_rdp_freelist; 127 #define RF_MAX_FREE_RDP 4 128 #define RF_RDP_INC 1 129 130 static void 131 SignalReconDone(RF_Raid_t * raidPtr) 132 { 133 RF_ReconDoneProc_t *p; 134 135 RF_LOCK_MUTEX(raidPtr->recon_done_proc_mutex); 136 for (p = raidPtr->recon_done_procs; p; p = p->next) { 137 p->proc(raidPtr, p->arg); 138 } 139 RF_UNLOCK_MUTEX(raidPtr->recon_done_proc_mutex); 140 } 141 142 int 143 rf_RegisterReconDoneProc( 144 RF_Raid_t * raidPtr, 145 void (*proc) (RF_Raid_t *, void *), 146 void *arg, 147 RF_ReconDoneProc_t ** handlep) 148 { 149 RF_ReconDoneProc_t *p; 150 151 RF_FREELIST_GET(rf_rdp_freelist, p, next, (RF_ReconDoneProc_t *)); 152 if (p == NULL) 153 return (ENOMEM); 154 p->proc = proc; 155 p->arg = arg; 156 RF_LOCK_MUTEX(raidPtr->recon_done_proc_mutex); 157 p->next = raidPtr->recon_done_procs; 158 raidPtr->recon_done_procs = p; 159 RF_UNLOCK_MUTEX(raidPtr->recon_done_proc_mutex); 160 if (handlep) 161 *handlep = p; 162 return (0); 163 } 164 /************************************************************************** 165 * 166 * sets up the parameters that will be used by the reconstruction process 167 * currently there are none, except for those that the layout-specific 168 * configuration (e.g. rf_ConfigureDeclustered) routine sets up. 169 * 170 * in the kernel, we fire off the recon thread. 171 * 172 **************************************************************************/ 173 static void 174 rf_ShutdownReconstruction(ignored) 175 void *ignored; 176 { 177 RF_FREELIST_DESTROY(rf_recond_freelist, next, (RF_RaidReconDesc_t *)); 178 RF_FREELIST_DESTROY(rf_rdp_freelist, next, (RF_ReconDoneProc_t *)); 179 } 180 181 int 182 rf_ConfigureReconstruction(listp) 183 RF_ShutdownList_t **listp; 184 { 185 int rc; 186 187 RF_FREELIST_CREATE(rf_recond_freelist, RF_MAX_FREE_RECOND, 188 RF_RECOND_INC, sizeof(RF_RaidReconDesc_t)); 189 if (rf_recond_freelist == NULL) 190 return (ENOMEM); 191 RF_FREELIST_CREATE(rf_rdp_freelist, RF_MAX_FREE_RDP, 192 RF_RDP_INC, sizeof(RF_ReconDoneProc_t)); 193 if (rf_rdp_freelist == NULL) { 194 RF_FREELIST_DESTROY(rf_recond_freelist, next, (RF_RaidReconDesc_t *)); 195 return (ENOMEM); 196 } 197 rc = rf_ShutdownCreate(listp, rf_ShutdownReconstruction, NULL); 198 if (rc) { 199 RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n", 200 __FILE__, __LINE__, rc); 201 rf_ShutdownReconstruction(NULL); 202 return (rc); 203 } 204 return (0); 205 } 206 207 static RF_RaidReconDesc_t * 208 AllocRaidReconDesc(raidPtr, row, col, spareDiskPtr, numDisksDone, srow, scol) 209 RF_Raid_t *raidPtr; 210 RF_RowCol_t row; 211 RF_RowCol_t col; 212 RF_RaidDisk_t *spareDiskPtr; 213 int numDisksDone; 214 RF_RowCol_t srow; 215 RF_RowCol_t scol; 216 { 217 218 RF_RaidReconDesc_t *reconDesc; 219 220 RF_FREELIST_GET(rf_recond_freelist, reconDesc, next, (RF_RaidReconDesc_t *)); 221 222 reconDesc->raidPtr = raidPtr; 223 reconDesc->row = row; 224 reconDesc->col = col; 225 reconDesc->spareDiskPtr = spareDiskPtr; 226 reconDesc->numDisksDone = numDisksDone; 227 reconDesc->srow = srow; 228 reconDesc->scol = scol; 229 reconDesc->state = 0; 230 reconDesc->next = NULL; 231 232 return (reconDesc); 233 } 234 235 static void 236 FreeReconDesc(reconDesc) 237 RF_RaidReconDesc_t *reconDesc; 238 { 239 #if RF_RECON_STATS > 0 240 printf("RAIDframe: %lu recon event waits, %lu recon delays\n", 241 (long) reconDesc->numReconEventWaits, (long) reconDesc->numReconExecDelays); 242 #endif /* RF_RECON_STATS > 0 */ 243 printf("RAIDframe: %lu max exec ticks\n", 244 (long) reconDesc->maxReconExecTicks); 245 #if (RF_RECON_STATS > 0) || defined(KERNEL) 246 printf("\n"); 247 #endif /* (RF_RECON_STATS > 0) || KERNEL */ 248 RF_FREELIST_FREE(rf_recond_freelist, reconDesc, next); 249 } 250 251 252 /***************************************************************************** 253 * 254 * primary routine to reconstruct a failed disk. This should be called from 255 * within its own thread. It won't return until reconstruction completes, 256 * fails, or is aborted. 257 *****************************************************************************/ 258 int 259 rf_ReconstructFailedDisk(raidPtr, row, col) 260 RF_Raid_t *raidPtr; 261 RF_RowCol_t row; 262 RF_RowCol_t col; 263 { 264 RF_LayoutSW_t *lp; 265 int rc; 266 267 lp = raidPtr->Layout.map; 268 if (lp->SubmitReconBuffer) { 269 /* 270 * The current infrastructure only supports reconstructing one 271 * disk at a time for each array. 272 */ 273 RF_LOCK_MUTEX(raidPtr->mutex); 274 while (raidPtr->reconInProgress) { 275 RF_WAIT_COND(raidPtr->waitForReconCond, raidPtr->mutex); 276 } 277 raidPtr->reconInProgress++; 278 RF_UNLOCK_MUTEX(raidPtr->mutex); 279 rc = rf_ReconstructFailedDiskBasic(raidPtr, row, col); 280 RF_LOCK_MUTEX(raidPtr->mutex); 281 raidPtr->reconInProgress--; 282 RF_UNLOCK_MUTEX(raidPtr->mutex); 283 } else { 284 RF_ERRORMSG1("RECON: no way to reconstruct failed disk for arch %c\n", 285 lp->parityConfig); 286 rc = EIO; 287 } 288 RF_SIGNAL_COND(raidPtr->waitForReconCond); 289 wakeup(&raidPtr->waitForReconCond); /* XXX Methinks this will be 290 * needed at some point... GO */ 291 return (rc); 292 } 293 294 int 295 rf_ReconstructFailedDiskBasic(raidPtr, row, col) 296 RF_Raid_t *raidPtr; 297 RF_RowCol_t row; 298 RF_RowCol_t col; 299 { 300 RF_ComponentLabel_t c_label; 301 RF_RaidDisk_t *spareDiskPtr = NULL; 302 RF_RaidReconDesc_t *reconDesc; 303 RF_RowCol_t srow, scol; 304 int numDisksDone = 0, rc; 305 306 /* first look for a spare drive onto which to reconstruct the data */ 307 /* spare disk descriptors are stored in row 0. This may have to 308 * change eventually */ 309 310 RF_LOCK_MUTEX(raidPtr->mutex); 311 RF_ASSERT(raidPtr->Disks[row][col].status == rf_ds_failed); 312 313 if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) { 314 if (raidPtr->status[row] != rf_rs_degraded) { 315 RF_ERRORMSG2("Unable to reconstruct disk at row %d col %d because status not degraded\n", row, col); 316 RF_UNLOCK_MUTEX(raidPtr->mutex); 317 return (EINVAL); 318 } 319 srow = row; 320 scol = (-1); 321 } else { 322 srow = 0; 323 for (scol = raidPtr->numCol; scol < raidPtr->numCol + raidPtr->numSpare; scol++) { 324 if (raidPtr->Disks[srow][scol].status == rf_ds_spare) { 325 spareDiskPtr = &raidPtr->Disks[srow][scol]; 326 spareDiskPtr->status = rf_ds_used_spare; 327 break; 328 } 329 } 330 if (!spareDiskPtr) { 331 RF_ERRORMSG2("Unable to reconstruct disk at row %d col %d because no spares are available\n", row, col); 332 RF_UNLOCK_MUTEX(raidPtr->mutex); 333 return (ENOSPC); 334 } 335 printf("RECON: initiating reconstruction on row %d col %d -> spare at row %d col %d\n", row, col, srow, scol); 336 } 337 RF_UNLOCK_MUTEX(raidPtr->mutex); 338 339 reconDesc = AllocRaidReconDesc((void *) raidPtr, row, col, spareDiskPtr, numDisksDone, srow, scol); 340 raidPtr->reconDesc = (void *) reconDesc; 341 #if RF_RECON_STATS > 0 342 reconDesc->hsStallCount = 0; 343 reconDesc->numReconExecDelays = 0; 344 reconDesc->numReconEventWaits = 0; 345 #endif /* RF_RECON_STATS > 0 */ 346 reconDesc->reconExecTimerRunning = 0; 347 reconDesc->reconExecTicks = 0; 348 reconDesc->maxReconExecTicks = 0; 349 rc = rf_ContinueReconstructFailedDisk(reconDesc); 350 351 if (!rc) { 352 /* fix up the component label */ 353 /* Don't actually need the read here.. */ 354 raidread_component_label( 355 raidPtr->raid_cinfo[srow][scol].ci_dev, 356 raidPtr->raid_cinfo[srow][scol].ci_vp, 357 &c_label); 358 359 raid_init_component_label( raidPtr, &c_label); 360 c_label.row = row; 361 c_label.column = col; 362 c_label.clean = RF_RAID_DIRTY; 363 c_label.status = rf_ds_optimal; 364 c_label.partitionSize = raidPtr->Disks[srow][scol].partitionSize; 365 366 /* We've just done a rebuild based on all the other 367 disks, so at this point the parity is known to be 368 clean, even if it wasn't before. */ 369 370 /* XXX doesn't hold for RAID 6!!*/ 371 372 raidPtr->parity_good = RF_RAID_CLEAN; 373 374 /* XXXX MORE NEEDED HERE */ 375 376 raidwrite_component_label( 377 raidPtr->raid_cinfo[srow][scol].ci_dev, 378 raidPtr->raid_cinfo[srow][scol].ci_vp, 379 &c_label); 380 381 } 382 return (rc); 383 } 384 385 /* 386 387 Allow reconstructing a disk in-place -- i.e. component /dev/sd2e goes AWOL, 388 and you don't get a spare until the next Monday. With this function 389 (and hot-swappable drives) you can now put your new disk containing 390 /dev/sd2e on the bus, scsictl it alive, and then use raidctl(8) to 391 rebuild the data "on the spot". 392 393 */ 394 395 int 396 rf_ReconstructInPlace(raidPtr, row, col) 397 RF_Raid_t *raidPtr; 398 RF_RowCol_t row; 399 RF_RowCol_t col; 400 { 401 RF_RaidDisk_t *spareDiskPtr = NULL; 402 RF_RaidReconDesc_t *reconDesc; 403 RF_LayoutSW_t *lp; 404 RF_RaidDisk_t *badDisk; 405 RF_ComponentLabel_t c_label; 406 int numDisksDone = 0, rc; 407 struct partinfo dpart; 408 struct vnode *vp; 409 struct vattr va; 410 struct proc *proc; 411 int retcode; 412 int ac; 413 414 lp = raidPtr->Layout.map; 415 if (lp->SubmitReconBuffer) { 416 /* 417 * The current infrastructure only supports reconstructing one 418 * disk at a time for each array. 419 */ 420 RF_LOCK_MUTEX(raidPtr->mutex); 421 if ((raidPtr->Disks[row][col].status == rf_ds_optimal) && 422 (raidPtr->numFailures > 0)) { 423 /* XXX 0 above shouldn't be constant!!! */ 424 /* some component other than this has failed. 425 Let's not make things worse than they already 426 are... */ 427 printf("RAIDFRAME: Unable to reconstruct to disk at:\n"); 428 printf(" Row: %d Col: %d Too many failures.\n", 429 row, col); 430 RF_UNLOCK_MUTEX(raidPtr->mutex); 431 return (EINVAL); 432 } 433 if (raidPtr->Disks[row][col].status == rf_ds_reconstructing) { 434 printf("RAIDFRAME: Unable to reconstruct to disk at:\n"); 435 printf(" Row: %d Col: %d Reconstruction already occuring!\n", row, col); 436 437 RF_UNLOCK_MUTEX(raidPtr->mutex); 438 return (EINVAL); 439 } 440 441 442 if (raidPtr->Disks[row][col].status != rf_ds_failed) { 443 /* "It's gone..." */ 444 raidPtr->numFailures++; 445 raidPtr->Disks[row][col].status = rf_ds_failed; 446 raidPtr->status[row] = rf_rs_degraded; 447 rf_update_component_labels(raidPtr, 448 RF_NORMAL_COMPONENT_UPDATE); 449 } 450 451 while (raidPtr->reconInProgress) { 452 RF_WAIT_COND(raidPtr->waitForReconCond, raidPtr->mutex); 453 } 454 455 raidPtr->reconInProgress++; 456 457 458 /* first look for a spare drive onto which to reconstruct 459 the data. spare disk descriptors are stored in row 0. 460 This may have to change eventually */ 461 462 /* Actually, we don't care if it's failed or not... 463 On a RAID set with correct parity, this function 464 should be callable on any component without ill affects. */ 465 /* RF_ASSERT(raidPtr->Disks[row][col].status == rf_ds_failed); 466 */ 467 468 if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) { 469 RF_ERRORMSG2("Unable to reconstruct to disk at row %d col %d: operation not supported for RF_DISTRIBUTE_SPARE\n", row, col); 470 471 raidPtr->reconInProgress--; 472 RF_UNLOCK_MUTEX(raidPtr->mutex); 473 return (EINVAL); 474 } 475 476 /* XXX need goop here to see if the disk is alive, 477 and, if not, make it so... */ 478 479 480 481 badDisk = &raidPtr->Disks[row][col]; 482 483 proc = raidPtr->engine_thread; 484 485 /* This device may have been opened successfully the 486 first time. Close it before trying to open it again.. */ 487 488 if (raidPtr->raid_cinfo[row][col].ci_vp != NULL) { 489 printf("Closed the open device: %s\n", 490 raidPtr->Disks[row][col].devname); 491 vp = raidPtr->raid_cinfo[row][col].ci_vp; 492 ac = raidPtr->Disks[row][col].auto_configured; 493 rf_close_component(raidPtr, vp, ac); 494 raidPtr->raid_cinfo[row][col].ci_vp = NULL; 495 } 496 /* note that this disk was *not* auto_configured (any longer)*/ 497 raidPtr->Disks[row][col].auto_configured = 0; 498 499 printf("About to (re-)open the device for rebuilding: %s\n", 500 raidPtr->Disks[row][col].devname); 501 502 retcode = raidlookup(raidPtr->Disks[row][col].devname, 503 proc, &vp); 504 505 if (retcode) { 506 printf("raid%d: rebuilding: raidlookup on device: %s failed: %d!\n",raidPtr->raidid, 507 raidPtr->Disks[row][col].devname, retcode); 508 509 /* XXX the component isn't responding properly... 510 must be still dead :-( */ 511 raidPtr->reconInProgress--; 512 RF_UNLOCK_MUTEX(raidPtr->mutex); 513 return(retcode); 514 515 } else { 516 517 /* Ok, so we can at least do a lookup... 518 How about actually getting a vp for it? */ 519 520 if ((retcode = VOP_GETATTR(vp, &va, proc->p_ucred, 521 proc)) != 0) { 522 raidPtr->reconInProgress--; 523 RF_UNLOCK_MUTEX(raidPtr->mutex); 524 return(retcode); 525 } 526 retcode = VOP_IOCTL(vp, DIOCGPART, (caddr_t) & dpart, 527 FREAD, proc->p_ucred, proc); 528 if (retcode) { 529 raidPtr->reconInProgress--; 530 RF_UNLOCK_MUTEX(raidPtr->mutex); 531 return(retcode); 532 } 533 raidPtr->Disks[row][col].blockSize = 534 dpart.disklab->d_secsize; 535 536 raidPtr->Disks[row][col].numBlocks = 537 dpart.part->p_size - rf_protectedSectors; 538 539 raidPtr->raid_cinfo[row][col].ci_vp = vp; 540 raidPtr->raid_cinfo[row][col].ci_dev = va.va_rdev; 541 542 raidPtr->Disks[row][col].dev = va.va_rdev; 543 544 /* we allow the user to specify that only a 545 fraction of the disks should be used this is 546 just for debug: it speeds up 547 * the parity scan */ 548 raidPtr->Disks[row][col].numBlocks = 549 raidPtr->Disks[row][col].numBlocks * 550 rf_sizePercentage / 100; 551 } 552 553 554 555 spareDiskPtr = &raidPtr->Disks[row][col]; 556 spareDiskPtr->status = rf_ds_used_spare; 557 558 printf("RECON: initiating in-place reconstruction on\n"); 559 printf(" row %d col %d -> spare at row %d col %d\n", 560 row, col, row, col); 561 562 RF_UNLOCK_MUTEX(raidPtr->mutex); 563 564 reconDesc = AllocRaidReconDesc((void *) raidPtr, row, col, 565 spareDiskPtr, numDisksDone, 566 row, col); 567 raidPtr->reconDesc = (void *) reconDesc; 568 #if RF_RECON_STATS > 0 569 reconDesc->hsStallCount = 0; 570 reconDesc->numReconExecDelays = 0; 571 reconDesc->numReconEventWaits = 0; 572 #endif /* RF_RECON_STATS > 0 */ 573 reconDesc->reconExecTimerRunning = 0; 574 reconDesc->reconExecTicks = 0; 575 reconDesc->maxReconExecTicks = 0; 576 rc = rf_ContinueReconstructFailedDisk(reconDesc); 577 578 RF_LOCK_MUTEX(raidPtr->mutex); 579 raidPtr->reconInProgress--; 580 RF_UNLOCK_MUTEX(raidPtr->mutex); 581 582 } else { 583 RF_ERRORMSG1("RECON: no way to reconstruct failed disk for arch %c\n", 584 lp->parityConfig); 585 rc = EIO; 586 } 587 RF_LOCK_MUTEX(raidPtr->mutex); 588 589 if (!rc) { 590 /* Need to set these here, as at this point it'll be claiming 591 that the disk is in rf_ds_spared! But we know better :-) */ 592 593 raidPtr->Disks[row][col].status = rf_ds_optimal; 594 raidPtr->status[row] = rf_rs_optimal; 595 596 /* fix up the component label */ 597 /* Don't actually need the read here.. */ 598 raidread_component_label(raidPtr->raid_cinfo[row][col].ci_dev, 599 raidPtr->raid_cinfo[row][col].ci_vp, 600 &c_label); 601 602 raid_init_component_label(raidPtr, &c_label); 603 604 c_label.row = row; 605 c_label.column = col; 606 607 /* We've just done a rebuild based on all the other 608 disks, so at this point the parity is known to be 609 clean, even if it wasn't before. */ 610 611 /* XXX doesn't hold for RAID 6!!*/ 612 613 raidPtr->parity_good = RF_RAID_CLEAN; 614 615 raidwrite_component_label(raidPtr->raid_cinfo[row][col].ci_dev, 616 raidPtr->raid_cinfo[row][col].ci_vp, 617 &c_label); 618 619 } 620 RF_UNLOCK_MUTEX(raidPtr->mutex); 621 RF_SIGNAL_COND(raidPtr->waitForReconCond); 622 wakeup(&raidPtr->waitForReconCond); 623 return (rc); 624 } 625 626 627 int 628 rf_ContinueReconstructFailedDisk(reconDesc) 629 RF_RaidReconDesc_t *reconDesc; 630 { 631 RF_Raid_t *raidPtr = reconDesc->raidPtr; 632 RF_RowCol_t row = reconDesc->row; 633 RF_RowCol_t col = reconDesc->col; 634 RF_RowCol_t srow = reconDesc->srow; 635 RF_RowCol_t scol = reconDesc->scol; 636 RF_ReconMap_t *mapPtr; 637 638 RF_ReconEvent_t *event; 639 struct timeval etime, elpsd; 640 unsigned long xor_s, xor_resid_us; 641 int retcode, i, ds; 642 643 switch (reconDesc->state) { 644 645 646 case 0: 647 648 raidPtr->accumXorTimeUs = 0; 649 650 /* create one trace record per physical disk */ 651 RF_Malloc(raidPtr->recon_tracerecs, raidPtr->numCol * sizeof(RF_AccTraceEntry_t), (RF_AccTraceEntry_t *)); 652 653 /* quiesce the array prior to starting recon. this is needed 654 * to assure no nasty interactions with pending user writes. 655 * We need to do this before we change the disk or row status. */ 656 reconDesc->state = 1; 657 658 Dprintf("RECON: begin request suspend\n"); 659 retcode = rf_SuspendNewRequestsAndWait(raidPtr); 660 Dprintf("RECON: end request suspend\n"); 661 rf_StartUserStats(raidPtr); /* zero out the stats kept on 662 * user accs */ 663 664 /* fall through to state 1 */ 665 666 case 1: 667 668 RF_LOCK_MUTEX(raidPtr->mutex); 669 670 /* create the reconstruction control pointer and install it in 671 * the right slot */ 672 raidPtr->reconControl[row] = rf_MakeReconControl(reconDesc, row, col, srow, scol); 673 mapPtr = raidPtr->reconControl[row]->reconMap; 674 raidPtr->status[row] = rf_rs_reconstructing; 675 raidPtr->Disks[row][col].status = rf_ds_reconstructing; 676 raidPtr->Disks[row][col].spareRow = srow; 677 raidPtr->Disks[row][col].spareCol = scol; 678 679 RF_UNLOCK_MUTEX(raidPtr->mutex); 680 681 RF_GETTIME(raidPtr->reconControl[row]->starttime); 682 683 /* now start up the actual reconstruction: issue a read for 684 * each surviving disk */ 685 686 reconDesc->numDisksDone = 0; 687 for (i = 0; i < raidPtr->numCol; i++) { 688 if (i != col) { 689 /* find and issue the next I/O on the 690 * indicated disk */ 691 if (IssueNextReadRequest(raidPtr, row, i)) { 692 Dprintf2("RECON: done issuing for r%d c%d\n", row, i); 693 reconDesc->numDisksDone++; 694 } 695 } 696 } 697 698 case 2: 699 Dprintf("RECON: resume requests\n"); 700 rf_ResumeNewRequests(raidPtr); 701 702 703 reconDesc->state = 3; 704 705 case 3: 706 707 /* process reconstruction events until all disks report that 708 * they've completed all work */ 709 mapPtr = raidPtr->reconControl[row]->reconMap; 710 711 712 713 while (reconDesc->numDisksDone < raidPtr->numCol - 1) { 714 715 event = rf_GetNextReconEvent(reconDesc, row, (void (*) (void *)) rf_ContinueReconstructFailedDisk, reconDesc); 716 RF_ASSERT(event); 717 718 if (ProcessReconEvent(raidPtr, row, event)) 719 reconDesc->numDisksDone++; 720 raidPtr->reconControl[row]->numRUsTotal = 721 mapPtr->totalRUs; 722 raidPtr->reconControl[row]->numRUsComplete = 723 mapPtr->totalRUs - 724 rf_UnitsLeftToReconstruct(mapPtr); 725 726 raidPtr->reconControl[row]->percentComplete = 727 (raidPtr->reconControl[row]->numRUsComplete * 100 / raidPtr->reconControl[row]->numRUsTotal); 728 if (rf_prReconSched) { 729 rf_PrintReconSchedule(raidPtr->reconControl[row]->reconMap, &(raidPtr->reconControl[row]->starttime)); 730 } 731 } 732 733 734 735 reconDesc->state = 4; 736 737 738 case 4: 739 mapPtr = raidPtr->reconControl[row]->reconMap; 740 if (rf_reconDebug) { 741 printf("RECON: all reads completed\n"); 742 } 743 /* at this point all the reads have completed. We now wait 744 * for any pending writes to complete, and then we're done */ 745 746 while (rf_UnitsLeftToReconstruct(raidPtr->reconControl[row]->reconMap) > 0) { 747 748 event = rf_GetNextReconEvent(reconDesc, row, (void (*) (void *)) rf_ContinueReconstructFailedDisk, reconDesc); 749 RF_ASSERT(event); 750 751 (void) ProcessReconEvent(raidPtr, row, event); /* ignore return code */ 752 raidPtr->reconControl[row]->percentComplete = 100 - (rf_UnitsLeftToReconstruct(mapPtr) * 100 / mapPtr->totalRUs); 753 if (rf_prReconSched) { 754 rf_PrintReconSchedule(raidPtr->reconControl[row]->reconMap, &(raidPtr->reconControl[row]->starttime)); 755 } 756 } 757 reconDesc->state = 5; 758 759 case 5: 760 /* Success: mark the dead disk as reconstructed. We quiesce 761 * the array here to assure no nasty interactions with pending 762 * user accesses when we free up the psstatus structure as 763 * part of FreeReconControl() */ 764 765 reconDesc->state = 6; 766 767 retcode = rf_SuspendNewRequestsAndWait(raidPtr); 768 rf_StopUserStats(raidPtr); 769 rf_PrintUserStats(raidPtr); /* print out the stats on user 770 * accs accumulated during 771 * recon */ 772 773 /* fall through to state 6 */ 774 case 6: 775 776 777 778 RF_LOCK_MUTEX(raidPtr->mutex); 779 raidPtr->numFailures--; 780 ds = (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE); 781 raidPtr->Disks[row][col].status = (ds) ? rf_ds_dist_spared : rf_ds_spared; 782 raidPtr->status[row] = (ds) ? rf_rs_reconfigured : rf_rs_optimal; 783 RF_UNLOCK_MUTEX(raidPtr->mutex); 784 RF_GETTIME(etime); 785 RF_TIMEVAL_DIFF(&(raidPtr->reconControl[row]->starttime), &etime, &elpsd); 786 787 /* XXX -- why is state 7 different from state 6 if there is no 788 * return() here? -- XXX Note that I set elpsd above & use it 789 * below, so if you put a return here you'll have to fix this. 790 * (also, FreeReconControl is called below) */ 791 792 case 7: 793 794 rf_ResumeNewRequests(raidPtr); 795 796 printf("Reconstruction of disk at row %d col %d completed\n", 797 row, col); 798 xor_s = raidPtr->accumXorTimeUs / 1000000; 799 xor_resid_us = raidPtr->accumXorTimeUs % 1000000; 800 printf("Recon time was %d.%06d seconds, accumulated XOR time was %ld us (%ld.%06ld)\n", 801 (int) elpsd.tv_sec, (int) elpsd.tv_usec, raidPtr->accumXorTimeUs, xor_s, xor_resid_us); 802 printf(" (start time %d sec %d usec, end time %d sec %d usec)\n", 803 (int) raidPtr->reconControl[row]->starttime.tv_sec, 804 (int) raidPtr->reconControl[row]->starttime.tv_usec, 805 (int) etime.tv_sec, (int) etime.tv_usec); 806 807 #if RF_RECON_STATS > 0 808 printf("Total head-sep stall count was %d\n", 809 (int) reconDesc->hsStallCount); 810 #endif /* RF_RECON_STATS > 0 */ 811 rf_FreeReconControl(raidPtr, row); 812 RF_Free(raidPtr->recon_tracerecs, raidPtr->numCol * sizeof(RF_AccTraceEntry_t)); 813 FreeReconDesc(reconDesc); 814 815 } 816 817 SignalReconDone(raidPtr); 818 return (0); 819 } 820 /***************************************************************************** 821 * do the right thing upon each reconstruction event. 822 * returns nonzero if and only if there is nothing left unread on the 823 * indicated disk 824 *****************************************************************************/ 825 static int 826 ProcessReconEvent(raidPtr, frow, event) 827 RF_Raid_t *raidPtr; 828 RF_RowCol_t frow; 829 RF_ReconEvent_t *event; 830 { 831 int retcode = 0, submitblocked; 832 RF_ReconBuffer_t *rbuf; 833 RF_SectorCount_t sectorsPerRU; 834 835 Dprintf1("RECON: ProcessReconEvent type %d\n", event->type); 836 switch (event->type) { 837 838 /* a read I/O has completed */ 839 case RF_REVENT_READDONE: 840 rbuf = raidPtr->reconControl[frow]->perDiskInfo[event->col].rbuf; 841 Dprintf3("RECON: READDONE EVENT: row %d col %d psid %ld\n", 842 frow, event->col, rbuf->parityStripeID); 843 Dprintf7("RECON: done read psid %ld buf %lx %02x %02x %02x %02x %02x\n", 844 rbuf->parityStripeID, rbuf->buffer, rbuf->buffer[0] & 0xff, rbuf->buffer[1] & 0xff, 845 rbuf->buffer[2] & 0xff, rbuf->buffer[3] & 0xff, rbuf->buffer[4] & 0xff); 846 rf_FreeDiskQueueData((RF_DiskQueueData_t *) rbuf->arg); 847 submitblocked = rf_SubmitReconBuffer(rbuf, 0, 0); 848 Dprintf1("RECON: submitblocked=%d\n", submitblocked); 849 if (!submitblocked) 850 retcode = IssueNextReadRequest(raidPtr, frow, event->col); 851 break; 852 853 /* a write I/O has completed */ 854 case RF_REVENT_WRITEDONE: 855 if (rf_floatingRbufDebug) { 856 rf_CheckFloatingRbufCount(raidPtr, 1); 857 } 858 sectorsPerRU = raidPtr->Layout.sectorsPerStripeUnit * raidPtr->Layout.SUsPerRU; 859 rbuf = (RF_ReconBuffer_t *) event->arg; 860 rf_FreeDiskQueueData((RF_DiskQueueData_t *) rbuf->arg); 861 Dprintf3("RECON: WRITEDONE EVENT: psid %d ru %d (%d %% complete)\n", 862 rbuf->parityStripeID, rbuf->which_ru, raidPtr->reconControl[frow]->percentComplete); 863 rf_ReconMapUpdate(raidPtr, raidPtr->reconControl[frow]->reconMap, 864 rbuf->failedDiskSectorOffset, rbuf->failedDiskSectorOffset + sectorsPerRU - 1); 865 rf_RemoveFromActiveReconTable(raidPtr, frow, rbuf->parityStripeID, rbuf->which_ru); 866 867 if (rbuf->type == RF_RBUF_TYPE_FLOATING) { 868 RF_LOCK_MUTEX(raidPtr->reconControl[frow]->rb_mutex); 869 raidPtr->numFullReconBuffers--; 870 rf_ReleaseFloatingReconBuffer(raidPtr, frow, rbuf); 871 RF_UNLOCK_MUTEX(raidPtr->reconControl[frow]->rb_mutex); 872 } else 873 if (rbuf->type == RF_RBUF_TYPE_FORCED) 874 rf_FreeReconBuffer(rbuf); 875 else 876 RF_ASSERT(0); 877 break; 878 879 case RF_REVENT_BUFCLEAR: /* A buffer-stall condition has been 880 * cleared */ 881 Dprintf2("RECON: BUFCLEAR EVENT: row %d col %d\n", frow, event->col); 882 submitblocked = rf_SubmitReconBuffer(raidPtr->reconControl[frow]->perDiskInfo[event->col].rbuf, 0, (int) (long) event->arg); 883 RF_ASSERT(!submitblocked); /* we wouldn't have gotten the 884 * BUFCLEAR event if we 885 * couldn't submit */ 886 retcode = IssueNextReadRequest(raidPtr, frow, event->col); 887 break; 888 889 case RF_REVENT_BLOCKCLEAR: /* A user-write reconstruction 890 * blockage has been cleared */ 891 DDprintf2("RECON: BLOCKCLEAR EVENT: row %d col %d\n", frow, event->col); 892 retcode = TryToRead(raidPtr, frow, event->col); 893 break; 894 895 case RF_REVENT_HEADSEPCLEAR: /* A max-head-separation 896 * reconstruction blockage has been 897 * cleared */ 898 Dprintf2("RECON: HEADSEPCLEAR EVENT: row %d col %d\n", frow, event->col); 899 retcode = TryToRead(raidPtr, frow, event->col); 900 break; 901 902 /* a buffer has become ready to write */ 903 case RF_REVENT_BUFREADY: 904 Dprintf2("RECON: BUFREADY EVENT: row %d col %d\n", frow, event->col); 905 retcode = IssueNextWriteRequest(raidPtr, frow); 906 if (rf_floatingRbufDebug) { 907 rf_CheckFloatingRbufCount(raidPtr, 1); 908 } 909 break; 910 911 /* we need to skip the current RU entirely because it got 912 * recon'd while we were waiting for something else to happen */ 913 case RF_REVENT_SKIP: 914 DDprintf2("RECON: SKIP EVENT: row %d col %d\n", frow, event->col); 915 retcode = IssueNextReadRequest(raidPtr, frow, event->col); 916 break; 917 918 /* a forced-reconstruction read access has completed. Just 919 * submit the buffer */ 920 case RF_REVENT_FORCEDREADDONE: 921 rbuf = (RF_ReconBuffer_t *) event->arg; 922 rf_FreeDiskQueueData((RF_DiskQueueData_t *) rbuf->arg); 923 DDprintf2("RECON: FORCEDREADDONE EVENT: row %d col %d\n", frow, event->col); 924 submitblocked = rf_SubmitReconBuffer(rbuf, 1, 0); 925 RF_ASSERT(!submitblocked); 926 break; 927 928 default: 929 RF_PANIC(); 930 } 931 rf_FreeReconEventDesc(event); 932 return (retcode); 933 } 934 /***************************************************************************** 935 * 936 * find the next thing that's needed on the indicated disk, and issue 937 * a read request for it. We assume that the reconstruction buffer 938 * associated with this process is free to receive the data. If 939 * reconstruction is blocked on the indicated RU, we issue a 940 * blockage-release request instead of a physical disk read request. 941 * If the current disk gets too far ahead of the others, we issue a 942 * head-separation wait request and return. 943 * 944 * ctrl->{ru_count, curPSID, diskOffset} and 945 * rbuf->failedDiskSectorOffset are maintained to point to the unit 946 * we're currently accessing. Note that this deviates from the 947 * standard C idiom of having counters point to the next thing to be 948 * accessed. This allows us to easily retry when we're blocked by 949 * head separation or reconstruction-blockage events. 950 * 951 * returns nonzero if and only if there is nothing left unread on the 952 * indicated disk 953 * 954 *****************************************************************************/ 955 static int 956 IssueNextReadRequest(raidPtr, row, col) 957 RF_Raid_t *raidPtr; 958 RF_RowCol_t row; 959 RF_RowCol_t col; 960 { 961 RF_PerDiskReconCtrl_t *ctrl = &raidPtr->reconControl[row]->perDiskInfo[col]; 962 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout; 963 RF_ReconBuffer_t *rbuf = ctrl->rbuf; 964 RF_ReconUnitCount_t RUsPerPU = layoutPtr->SUsPerPU / layoutPtr->SUsPerRU; 965 RF_SectorCount_t sectorsPerRU = layoutPtr->sectorsPerStripeUnit * layoutPtr->SUsPerRU; 966 int do_new_check = 0, retcode = 0, status; 967 968 /* if we are currently the slowest disk, mark that we have to do a new 969 * check */ 970 if (ctrl->headSepCounter <= raidPtr->reconControl[row]->minHeadSepCounter) 971 do_new_check = 1; 972 973 while (1) { 974 975 ctrl->ru_count++; 976 if (ctrl->ru_count < RUsPerPU) { 977 ctrl->diskOffset += sectorsPerRU; 978 rbuf->failedDiskSectorOffset += sectorsPerRU; 979 } else { 980 ctrl->curPSID++; 981 ctrl->ru_count = 0; 982 /* code left over from when head-sep was based on 983 * parity stripe id */ 984 if (ctrl->curPSID >= raidPtr->reconControl[row]->lastPSID) { 985 CheckForNewMinHeadSep(raidPtr, row, ++(ctrl->headSepCounter)); 986 return (1); /* finito! */ 987 } 988 /* find the disk offsets of the start of the parity 989 * stripe on both the current disk and the failed 990 * disk. skip this entire parity stripe if either disk 991 * does not appear in the indicated PS */ 992 status = ComputePSDiskOffsets(raidPtr, ctrl->curPSID, row, col, &ctrl->diskOffset, &rbuf->failedDiskSectorOffset, 993 &rbuf->spRow, &rbuf->spCol, &rbuf->spOffset); 994 if (status) { 995 ctrl->ru_count = RUsPerPU - 1; 996 continue; 997 } 998 } 999 rbuf->which_ru = ctrl->ru_count; 1000 1001 /* skip this RU if it's already been reconstructed */ 1002 if (rf_CheckRUReconstructed(raidPtr->reconControl[row]->reconMap, rbuf->failedDiskSectorOffset)) { 1003 Dprintf2("Skipping psid %ld ru %d: already reconstructed\n", ctrl->curPSID, ctrl->ru_count); 1004 continue; 1005 } 1006 break; 1007 } 1008 ctrl->headSepCounter++; 1009 if (do_new_check) 1010 CheckForNewMinHeadSep(raidPtr, row, ctrl->headSepCounter); /* update min if needed */ 1011 1012 1013 /* at this point, we have definitely decided what to do, and we have 1014 * only to see if we can actually do it now */ 1015 rbuf->parityStripeID = ctrl->curPSID; 1016 rbuf->which_ru = ctrl->ru_count; 1017 bzero((char *) &raidPtr->recon_tracerecs[col], sizeof(raidPtr->recon_tracerecs[col])); 1018 raidPtr->recon_tracerecs[col].reconacc = 1; 1019 RF_ETIMER_START(raidPtr->recon_tracerecs[col].recon_timer); 1020 retcode = TryToRead(raidPtr, row, col); 1021 return (retcode); 1022 } 1023 1024 /* 1025 * tries to issue the next read on the indicated disk. We may be 1026 * blocked by (a) the heads being too far apart, or (b) recon on the 1027 * indicated RU being blocked due to a write by a user thread. In 1028 * this case, we issue a head-sep or blockage wait request, which will 1029 * cause this same routine to be invoked again later when the blockage 1030 * has cleared. 1031 */ 1032 1033 static int 1034 TryToRead(raidPtr, row, col) 1035 RF_Raid_t *raidPtr; 1036 RF_RowCol_t row; 1037 RF_RowCol_t col; 1038 { 1039 RF_PerDiskReconCtrl_t *ctrl = &raidPtr->reconControl[row]->perDiskInfo[col]; 1040 RF_SectorCount_t sectorsPerRU = raidPtr->Layout.sectorsPerStripeUnit * raidPtr->Layout.SUsPerRU; 1041 RF_StripeNum_t psid = ctrl->curPSID; 1042 RF_ReconUnitNum_t which_ru = ctrl->ru_count; 1043 RF_DiskQueueData_t *req; 1044 int status, created = 0; 1045 RF_ReconParityStripeStatus_t *pssPtr; 1046 1047 /* if the current disk is too far ahead of the others, issue a 1048 * head-separation wait and return */ 1049 if (CheckHeadSeparation(raidPtr, ctrl, row, col, ctrl->headSepCounter, which_ru)) 1050 return (0); 1051 RF_LOCK_PSS_MUTEX(raidPtr, row, psid); 1052 pssPtr = rf_LookupRUStatus(raidPtr, raidPtr->reconControl[row]->pssTable, psid, which_ru, RF_PSS_CREATE, &created); 1053 1054 /* if recon is blocked on the indicated parity stripe, issue a 1055 * block-wait request and return. this also must mark the indicated RU 1056 * in the stripe as under reconstruction if not blocked. */ 1057 status = CheckForcedOrBlockedReconstruction(raidPtr, pssPtr, ctrl, row, col, psid, which_ru); 1058 if (status == RF_PSS_RECON_BLOCKED) { 1059 Dprintf2("RECON: Stalling psid %ld ru %d: recon blocked\n", psid, which_ru); 1060 goto out; 1061 } else 1062 if (status == RF_PSS_FORCED_ON_WRITE) { 1063 rf_CauseReconEvent(raidPtr, row, col, NULL, RF_REVENT_SKIP); 1064 goto out; 1065 } 1066 /* make one last check to be sure that the indicated RU didn't get 1067 * reconstructed while we were waiting for something else to happen. 1068 * This is unfortunate in that it causes us to make this check twice 1069 * in the normal case. Might want to make some attempt to re-work 1070 * this so that we only do this check if we've definitely blocked on 1071 * one of the above checks. When this condition is detected, we may 1072 * have just created a bogus status entry, which we need to delete. */ 1073 if (rf_CheckRUReconstructed(raidPtr->reconControl[row]->reconMap, ctrl->rbuf->failedDiskSectorOffset)) { 1074 Dprintf2("RECON: Skipping psid %ld ru %d: prior recon after stall\n", psid, which_ru); 1075 if (created) 1076 rf_PSStatusDelete(raidPtr, raidPtr->reconControl[row]->pssTable, pssPtr); 1077 rf_CauseReconEvent(raidPtr, row, col, NULL, RF_REVENT_SKIP); 1078 goto out; 1079 } 1080 /* found something to read. issue the I/O */ 1081 Dprintf5("RECON: Read for psid %ld on row %d col %d offset %ld buf %lx\n", 1082 psid, row, col, ctrl->diskOffset, ctrl->rbuf->buffer); 1083 RF_ETIMER_STOP(raidPtr->recon_tracerecs[col].recon_timer); 1084 RF_ETIMER_EVAL(raidPtr->recon_tracerecs[col].recon_timer); 1085 raidPtr->recon_tracerecs[col].specific.recon.recon_start_to_fetch_us = 1086 RF_ETIMER_VAL_US(raidPtr->recon_tracerecs[col].recon_timer); 1087 RF_ETIMER_START(raidPtr->recon_tracerecs[col].recon_timer); 1088 1089 /* should be ok to use a NULL proc pointer here, all the bufs we use 1090 * should be in kernel space */ 1091 req = rf_CreateDiskQueueData(RF_IO_TYPE_READ, ctrl->diskOffset, sectorsPerRU, ctrl->rbuf->buffer, psid, which_ru, 1092 ReconReadDoneProc, (void *) ctrl, NULL, &raidPtr->recon_tracerecs[col], (void *) raidPtr, 0, NULL); 1093 1094 RF_ASSERT(req); /* XXX -- fix this -- XXX */ 1095 1096 ctrl->rbuf->arg = (void *) req; 1097 rf_DiskIOEnqueue(&raidPtr->Queues[row][col], req, RF_IO_RECON_PRIORITY); 1098 pssPtr->issued[col] = 1; 1099 1100 out: 1101 RF_UNLOCK_PSS_MUTEX(raidPtr, row, psid); 1102 return (0); 1103 } 1104 1105 1106 /* 1107 * given a parity stripe ID, we want to find out whether both the 1108 * current disk and the failed disk exist in that parity stripe. If 1109 * not, we want to skip this whole PS. If so, we want to find the 1110 * disk offset of the start of the PS on both the current disk and the 1111 * failed disk. 1112 * 1113 * this works by getting a list of disks comprising the indicated 1114 * parity stripe, and searching the list for the current and failed 1115 * disks. Once we've decided they both exist in the parity stripe, we 1116 * need to decide whether each is data or parity, so that we'll know 1117 * which mapping function to call to get the corresponding disk 1118 * offsets. 1119 * 1120 * this is kind of unpleasant, but doing it this way allows the 1121 * reconstruction code to use parity stripe IDs rather than physical 1122 * disks address to march through the failed disk, which greatly 1123 * simplifies a lot of code, as well as eliminating the need for a 1124 * reverse-mapping function. I also think it will execute faster, 1125 * since the calls to the mapping module are kept to a minimum. 1126 * 1127 * ASSUMES THAT THE STRIPE IDENTIFIER IDENTIFIES THE DISKS COMPRISING 1128 * THE STRIPE IN THE CORRECT ORDER */ 1129 1130 1131 static int 1132 ComputePSDiskOffsets( 1133 RF_Raid_t * raidPtr, /* raid descriptor */ 1134 RF_StripeNum_t psid, /* parity stripe identifier */ 1135 RF_RowCol_t row, /* row and column of disk to find the offsets 1136 * for */ 1137 RF_RowCol_t col, 1138 RF_SectorNum_t * outDiskOffset, 1139 RF_SectorNum_t * outFailedDiskSectorOffset, 1140 RF_RowCol_t * spRow, /* OUT: row,col of spare unit for failed unit */ 1141 RF_RowCol_t * spCol, 1142 RF_SectorNum_t * spOffset) 1143 { /* OUT: offset into disk containing spare unit */ 1144 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout; 1145 RF_RowCol_t fcol = raidPtr->reconControl[row]->fcol; 1146 RF_RaidAddr_t sosRaidAddress; /* start-of-stripe */ 1147 RF_RowCol_t *diskids; 1148 u_int i, j, k, i_offset, j_offset; 1149 RF_RowCol_t prow, pcol; 1150 int testcol, testrow; 1151 RF_RowCol_t stripe; 1152 RF_SectorNum_t poffset; 1153 char i_is_parity = 0, j_is_parity = 0; 1154 RF_RowCol_t stripeWidth = layoutPtr->numDataCol + layoutPtr->numParityCol; 1155 1156 /* get a listing of the disks comprising that stripe */ 1157 sosRaidAddress = rf_ParityStripeIDToRaidAddress(layoutPtr, psid); 1158 (layoutPtr->map->IdentifyStripe) (raidPtr, sosRaidAddress, &diskids, &stripe); 1159 RF_ASSERT(diskids); 1160 1161 /* reject this entire parity stripe if it does not contain the 1162 * indicated disk or it does not contain the failed disk */ 1163 if (row != stripe) 1164 goto skipit; 1165 for (i = 0; i < stripeWidth; i++) { 1166 if (col == diskids[i]) 1167 break; 1168 } 1169 if (i == stripeWidth) 1170 goto skipit; 1171 for (j = 0; j < stripeWidth; j++) { 1172 if (fcol == diskids[j]) 1173 break; 1174 } 1175 if (j == stripeWidth) { 1176 goto skipit; 1177 } 1178 /* find out which disk the parity is on */ 1179 (layoutPtr->map->MapParity) (raidPtr, sosRaidAddress, &prow, &pcol, &poffset, RF_DONT_REMAP); 1180 1181 /* find out if either the current RU or the failed RU is parity */ 1182 /* also, if the parity occurs in this stripe prior to the data and/or 1183 * failed col, we need to decrement i and/or j */ 1184 for (k = 0; k < stripeWidth; k++) 1185 if (diskids[k] == pcol) 1186 break; 1187 RF_ASSERT(k < stripeWidth); 1188 i_offset = i; 1189 j_offset = j; 1190 if (k < i) 1191 i_offset--; 1192 else 1193 if (k == i) { 1194 i_is_parity = 1; 1195 i_offset = 0; 1196 } /* set offsets to zero to disable multiply 1197 * below */ 1198 if (k < j) 1199 j_offset--; 1200 else 1201 if (k == j) { 1202 j_is_parity = 1; 1203 j_offset = 0; 1204 } 1205 /* at this point, [ij]_is_parity tells us whether the [current,failed] 1206 * disk is parity at the start of this RU, and, if data, "[ij]_offset" 1207 * tells us how far into the stripe the [current,failed] disk is. */ 1208 1209 /* call the mapping routine to get the offset into the current disk, 1210 * repeat for failed disk. */ 1211 if (i_is_parity) 1212 layoutPtr->map->MapParity(raidPtr, sosRaidAddress + i_offset * layoutPtr->sectorsPerStripeUnit, &testrow, &testcol, outDiskOffset, RF_DONT_REMAP); 1213 else 1214 layoutPtr->map->MapSector(raidPtr, sosRaidAddress + i_offset * layoutPtr->sectorsPerStripeUnit, &testrow, &testcol, outDiskOffset, RF_DONT_REMAP); 1215 1216 RF_ASSERT(row == testrow && col == testcol); 1217 1218 if (j_is_parity) 1219 layoutPtr->map->MapParity(raidPtr, sosRaidAddress + j_offset * layoutPtr->sectorsPerStripeUnit, &testrow, &testcol, outFailedDiskSectorOffset, RF_DONT_REMAP); 1220 else 1221 layoutPtr->map->MapSector(raidPtr, sosRaidAddress + j_offset * layoutPtr->sectorsPerStripeUnit, &testrow, &testcol, outFailedDiskSectorOffset, RF_DONT_REMAP); 1222 RF_ASSERT(row == testrow && fcol == testcol); 1223 1224 /* now locate the spare unit for the failed unit */ 1225 if (layoutPtr->map->flags & RF_DISTRIBUTE_SPARE) { 1226 if (j_is_parity) 1227 layoutPtr->map->MapParity(raidPtr, sosRaidAddress + j_offset * layoutPtr->sectorsPerStripeUnit, spRow, spCol, spOffset, RF_REMAP); 1228 else 1229 layoutPtr->map->MapSector(raidPtr, sosRaidAddress + j_offset * layoutPtr->sectorsPerStripeUnit, spRow, spCol, spOffset, RF_REMAP); 1230 } else { 1231 *spRow = raidPtr->reconControl[row]->spareRow; 1232 *spCol = raidPtr->reconControl[row]->spareCol; 1233 *spOffset = *outFailedDiskSectorOffset; 1234 } 1235 1236 return (0); 1237 1238 skipit: 1239 Dprintf3("RECON: Skipping psid %ld: nothing needed from r%d c%d\n", 1240 psid, row, col); 1241 return (1); 1242 } 1243 /* this is called when a buffer has become ready to write to the replacement disk */ 1244 static int 1245 IssueNextWriteRequest(raidPtr, row) 1246 RF_Raid_t *raidPtr; 1247 RF_RowCol_t row; 1248 { 1249 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout; 1250 RF_SectorCount_t sectorsPerRU = layoutPtr->sectorsPerStripeUnit * layoutPtr->SUsPerRU; 1251 RF_RowCol_t fcol = raidPtr->reconControl[row]->fcol; 1252 RF_ReconBuffer_t *rbuf; 1253 RF_DiskQueueData_t *req; 1254 1255 rbuf = rf_GetFullReconBuffer(raidPtr->reconControl[row]); 1256 RF_ASSERT(rbuf); /* there must be one available, or we wouldn't 1257 * have gotten the event that sent us here */ 1258 RF_ASSERT(rbuf->pssPtr); 1259 1260 rbuf->pssPtr->writeRbuf = rbuf; 1261 rbuf->pssPtr = NULL; 1262 1263 Dprintf7("RECON: New write (r %d c %d offs %d) for psid %ld ru %d (failed disk offset %ld) buf %lx\n", 1264 rbuf->spRow, rbuf->spCol, rbuf->spOffset, rbuf->parityStripeID, 1265 rbuf->which_ru, rbuf->failedDiskSectorOffset, rbuf->buffer); 1266 Dprintf6("RECON: new write psid %ld %02x %02x %02x %02x %02x\n", 1267 rbuf->parityStripeID, rbuf->buffer[0] & 0xff, rbuf->buffer[1] & 0xff, 1268 rbuf->buffer[2] & 0xff, rbuf->buffer[3] & 0xff, rbuf->buffer[4] & 0xff); 1269 1270 /* should be ok to use a NULL b_proc here b/c all addrs should be in 1271 * kernel space */ 1272 req = rf_CreateDiskQueueData(RF_IO_TYPE_WRITE, rbuf->spOffset, 1273 sectorsPerRU, rbuf->buffer, 1274 rbuf->parityStripeID, rbuf->which_ru, 1275 ReconWriteDoneProc, (void *) rbuf, NULL, 1276 &raidPtr->recon_tracerecs[fcol], 1277 (void *) raidPtr, 0, NULL); 1278 1279 RF_ASSERT(req); /* XXX -- fix this -- XXX */ 1280 1281 rbuf->arg = (void *) req; 1282 rf_DiskIOEnqueue(&raidPtr->Queues[rbuf->spRow][rbuf->spCol], req, RF_IO_RECON_PRIORITY); 1283 1284 return (0); 1285 } 1286 1287 /* 1288 * this gets called upon the completion of a reconstruction read 1289 * operation the arg is a pointer to the per-disk reconstruction 1290 * control structure for the process that just finished a read. 1291 * 1292 * called at interrupt context in the kernel, so don't do anything 1293 * illegal here. 1294 */ 1295 static int 1296 ReconReadDoneProc(arg, status) 1297 void *arg; 1298 int status; 1299 { 1300 RF_PerDiskReconCtrl_t *ctrl = (RF_PerDiskReconCtrl_t *) arg; 1301 RF_Raid_t *raidPtr = ctrl->reconCtrl->reconDesc->raidPtr; 1302 1303 if (status) { 1304 /* 1305 * XXX 1306 */ 1307 printf("Recon read failed!\n"); 1308 RF_PANIC(); 1309 } 1310 RF_ETIMER_STOP(raidPtr->recon_tracerecs[ctrl->col].recon_timer); 1311 RF_ETIMER_EVAL(raidPtr->recon_tracerecs[ctrl->col].recon_timer); 1312 raidPtr->recon_tracerecs[ctrl->col].specific.recon.recon_fetch_to_return_us = 1313 RF_ETIMER_VAL_US(raidPtr->recon_tracerecs[ctrl->col].recon_timer); 1314 RF_ETIMER_START(raidPtr->recon_tracerecs[ctrl->col].recon_timer); 1315 1316 rf_CauseReconEvent(raidPtr, ctrl->row, ctrl->col, NULL, RF_REVENT_READDONE); 1317 return (0); 1318 } 1319 /* this gets called upon the completion of a reconstruction write operation. 1320 * the arg is a pointer to the rbuf that was just written 1321 * 1322 * called at interrupt context in the kernel, so don't do anything illegal here. 1323 */ 1324 static int 1325 ReconWriteDoneProc(arg, status) 1326 void *arg; 1327 int status; 1328 { 1329 RF_ReconBuffer_t *rbuf = (RF_ReconBuffer_t *) arg; 1330 1331 Dprintf2("Reconstruction completed on psid %ld ru %d\n", rbuf->parityStripeID, rbuf->which_ru); 1332 if (status) { 1333 printf("Recon write failed!\n"); /* fprintf(stderr,"Recon 1334 * write failed!\n"); */ 1335 RF_PANIC(); 1336 } 1337 rf_CauseReconEvent((RF_Raid_t *) rbuf->raidPtr, rbuf->row, rbuf->col, arg, RF_REVENT_WRITEDONE); 1338 return (0); 1339 } 1340 1341 1342 /* 1343 * computes a new minimum head sep, and wakes up anyone who needs to 1344 * be woken as a result 1345 */ 1346 static void 1347 CheckForNewMinHeadSep(raidPtr, row, hsCtr) 1348 RF_Raid_t *raidPtr; 1349 RF_RowCol_t row; 1350 RF_HeadSepLimit_t hsCtr; 1351 { 1352 RF_ReconCtrl_t *reconCtrlPtr = raidPtr->reconControl[row]; 1353 RF_HeadSepLimit_t new_min; 1354 RF_RowCol_t i; 1355 RF_CallbackDesc_t *p; 1356 RF_ASSERT(hsCtr >= reconCtrlPtr->minHeadSepCounter); /* from the definition 1357 * of a minimum */ 1358 1359 1360 RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex); 1361 1362 new_min = ~(1L << (8 * sizeof(long) - 1)); /* 0x7FFF....FFF */ 1363 for (i = 0; i < raidPtr->numCol; i++) 1364 if (i != reconCtrlPtr->fcol) { 1365 if (reconCtrlPtr->perDiskInfo[i].headSepCounter < new_min) 1366 new_min = reconCtrlPtr->perDiskInfo[i].headSepCounter; 1367 } 1368 /* set the new minimum and wake up anyone who can now run again */ 1369 if (new_min != reconCtrlPtr->minHeadSepCounter) { 1370 reconCtrlPtr->minHeadSepCounter = new_min; 1371 Dprintf1("RECON: new min head pos counter val is %ld\n", new_min); 1372 while (reconCtrlPtr->headSepCBList) { 1373 if (reconCtrlPtr->headSepCBList->callbackArg.v > new_min) 1374 break; 1375 p = reconCtrlPtr->headSepCBList; 1376 reconCtrlPtr->headSepCBList = p->next; 1377 p->next = NULL; 1378 rf_CauseReconEvent(raidPtr, p->row, p->col, NULL, RF_REVENT_HEADSEPCLEAR); 1379 rf_FreeCallbackDesc(p); 1380 } 1381 1382 } 1383 RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex); 1384 } 1385 1386 /* 1387 * checks to see that the maximum head separation will not be violated 1388 * if we initiate a reconstruction I/O on the indicated disk. 1389 * Limiting the maximum head separation between two disks eliminates 1390 * the nasty buffer-stall conditions that occur when one disk races 1391 * ahead of the others and consumes all of the floating recon buffers. 1392 * This code is complex and unpleasant but it's necessary to avoid 1393 * some very nasty, albeit fairly rare, reconstruction behavior. 1394 * 1395 * returns non-zero if and only if we have to stop working on the 1396 * indicated disk due to a head-separation delay. 1397 */ 1398 static int 1399 CheckHeadSeparation( 1400 RF_Raid_t * raidPtr, 1401 RF_PerDiskReconCtrl_t * ctrl, 1402 RF_RowCol_t row, 1403 RF_RowCol_t col, 1404 RF_HeadSepLimit_t hsCtr, 1405 RF_ReconUnitNum_t which_ru) 1406 { 1407 RF_ReconCtrl_t *reconCtrlPtr = raidPtr->reconControl[row]; 1408 RF_CallbackDesc_t *cb, *p, *pt; 1409 int retval = 0; 1410 1411 /* if we're too far ahead of the slowest disk, stop working on this 1412 * disk until the slower ones catch up. We do this by scheduling a 1413 * wakeup callback for the time when the slowest disk has caught up. 1414 * We define "caught up" with 20% hysteresis, i.e. the head separation 1415 * must have fallen to at most 80% of the max allowable head 1416 * separation before we'll wake up. 1417 * 1418 */ 1419 RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex); 1420 if ((raidPtr->headSepLimit >= 0) && 1421 ((ctrl->headSepCounter - reconCtrlPtr->minHeadSepCounter) > raidPtr->headSepLimit)) { 1422 Dprintf6("raid%d: RECON: head sep stall: row %d col %d hsCtr %ld minHSCtr %ld limit %ld\n", 1423 raidPtr->raidid, row, col, ctrl->headSepCounter, 1424 reconCtrlPtr->minHeadSepCounter, 1425 raidPtr->headSepLimit); 1426 cb = rf_AllocCallbackDesc(); 1427 /* the minHeadSepCounter value we have to get to before we'll 1428 * wake up. build in 20% hysteresis. */ 1429 cb->callbackArg.v = (ctrl->headSepCounter - raidPtr->headSepLimit + raidPtr->headSepLimit / 5); 1430 cb->row = row; 1431 cb->col = col; 1432 cb->next = NULL; 1433 1434 /* insert this callback descriptor into the sorted list of 1435 * pending head-sep callbacks */ 1436 p = reconCtrlPtr->headSepCBList; 1437 if (!p) 1438 reconCtrlPtr->headSepCBList = cb; 1439 else 1440 if (cb->callbackArg.v < p->callbackArg.v) { 1441 cb->next = reconCtrlPtr->headSepCBList; 1442 reconCtrlPtr->headSepCBList = cb; 1443 } else { 1444 for (pt = p, p = p->next; p && (p->callbackArg.v < cb->callbackArg.v); pt = p, p = p->next); 1445 cb->next = p; 1446 pt->next = cb; 1447 } 1448 retval = 1; 1449 #if RF_RECON_STATS > 0 1450 ctrl->reconCtrl->reconDesc->hsStallCount++; 1451 #endif /* RF_RECON_STATS > 0 */ 1452 } 1453 RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex); 1454 1455 return (retval); 1456 } 1457 /* 1458 * checks to see if reconstruction has been either forced or blocked 1459 * by a user operation. if forced, we skip this RU entirely. else if 1460 * blocked, put ourselves on the wait list. else return 0. 1461 * 1462 * ASSUMES THE PSS MUTEX IS LOCKED UPON ENTRY 1463 */ 1464 static int 1465 CheckForcedOrBlockedReconstruction( 1466 RF_Raid_t * raidPtr, 1467 RF_ReconParityStripeStatus_t * pssPtr, 1468 RF_PerDiskReconCtrl_t * ctrl, 1469 RF_RowCol_t row, 1470 RF_RowCol_t col, 1471 RF_StripeNum_t psid, 1472 RF_ReconUnitNum_t which_ru) 1473 { 1474 RF_CallbackDesc_t *cb; 1475 int retcode = 0; 1476 1477 if ((pssPtr->flags & RF_PSS_FORCED_ON_READ) || (pssPtr->flags & RF_PSS_FORCED_ON_WRITE)) 1478 retcode = RF_PSS_FORCED_ON_WRITE; 1479 else 1480 if (pssPtr->flags & RF_PSS_RECON_BLOCKED) { 1481 Dprintf4("RECON: row %d col %d blocked at psid %ld ru %d\n", row, col, psid, which_ru); 1482 cb = rf_AllocCallbackDesc(); /* append ourselves to 1483 * the blockage-wait 1484 * list */ 1485 cb->row = row; 1486 cb->col = col; 1487 cb->next = pssPtr->blockWaitList; 1488 pssPtr->blockWaitList = cb; 1489 retcode = RF_PSS_RECON_BLOCKED; 1490 } 1491 if (!retcode) 1492 pssPtr->flags |= RF_PSS_UNDER_RECON; /* mark this RU as under 1493 * reconstruction */ 1494 1495 return (retcode); 1496 } 1497 /* 1498 * if reconstruction is currently ongoing for the indicated stripeID, 1499 * reconstruction is forced to completion and we return non-zero to 1500 * indicate that the caller must wait. If not, then reconstruction is 1501 * blocked on the indicated stripe and the routine returns zero. If 1502 * and only if we return non-zero, we'll cause the cbFunc to get 1503 * invoked with the cbArg when the reconstruction has completed. 1504 */ 1505 int 1506 rf_ForceOrBlockRecon(raidPtr, asmap, cbFunc, cbArg) 1507 RF_Raid_t *raidPtr; 1508 RF_AccessStripeMap_t *asmap; 1509 void (*cbFunc) (RF_Raid_t *, void *); 1510 void *cbArg; 1511 { 1512 RF_RowCol_t row = asmap->physInfo->row; /* which row of the array 1513 * we're working on */ 1514 RF_StripeNum_t stripeID = asmap->stripeID; /* the stripe ID we're 1515 * forcing recon on */ 1516 RF_SectorCount_t sectorsPerRU = raidPtr->Layout.sectorsPerStripeUnit * raidPtr->Layout.SUsPerRU; /* num sects in one RU */ 1517 RF_ReconParityStripeStatus_t *pssPtr; /* a pointer to the parity 1518 * stripe status structure */ 1519 RF_StripeNum_t psid; /* parity stripe id */ 1520 RF_SectorNum_t offset, fd_offset; /* disk offset, failed-disk 1521 * offset */ 1522 RF_RowCol_t *diskids; 1523 RF_RowCol_t stripe; 1524 RF_ReconUnitNum_t which_ru; /* RU within parity stripe */ 1525 RF_RowCol_t fcol, diskno, i; 1526 RF_ReconBuffer_t *new_rbuf; /* ptr to newly allocated rbufs */ 1527 RF_DiskQueueData_t *req;/* disk I/O req to be enqueued */ 1528 RF_CallbackDesc_t *cb; 1529 int created = 0, nPromoted; 1530 1531 psid = rf_MapStripeIDToParityStripeID(&raidPtr->Layout, stripeID, &which_ru); 1532 1533 RF_LOCK_PSS_MUTEX(raidPtr, row, psid); 1534 1535 pssPtr = rf_LookupRUStatus(raidPtr, raidPtr->reconControl[row]->pssTable, psid, which_ru, RF_PSS_CREATE | RF_PSS_RECON_BLOCKED, &created); 1536 1537 /* if recon is not ongoing on this PS, just return */ 1538 if (!(pssPtr->flags & RF_PSS_UNDER_RECON)) { 1539 RF_UNLOCK_PSS_MUTEX(raidPtr, row, psid); 1540 return (0); 1541 } 1542 /* otherwise, we have to wait for reconstruction to complete on this 1543 * RU. */ 1544 /* In order to avoid waiting for a potentially large number of 1545 * low-priority accesses to complete, we force a normal-priority (i.e. 1546 * not low-priority) reconstruction on this RU. */ 1547 if (!(pssPtr->flags & RF_PSS_FORCED_ON_WRITE) && !(pssPtr->flags & RF_PSS_FORCED_ON_READ)) { 1548 DDprintf1("Forcing recon on psid %ld\n", psid); 1549 pssPtr->flags |= RF_PSS_FORCED_ON_WRITE; /* mark this RU as under 1550 * forced recon */ 1551 pssPtr->flags &= ~RF_PSS_RECON_BLOCKED; /* clear the blockage 1552 * that we just set */ 1553 fcol = raidPtr->reconControl[row]->fcol; 1554 1555 /* get a listing of the disks comprising the indicated stripe */ 1556 (raidPtr->Layout.map->IdentifyStripe) (raidPtr, asmap->raidAddress, &diskids, &stripe); 1557 RF_ASSERT(row == stripe); 1558 1559 /* For previously issued reads, elevate them to normal 1560 * priority. If the I/O has already completed, it won't be 1561 * found in the queue, and hence this will be a no-op. For 1562 * unissued reads, allocate buffers and issue new reads. The 1563 * fact that we've set the FORCED bit means that the regular 1564 * recon procs will not re-issue these reqs */ 1565 for (i = 0; i < raidPtr->Layout.numDataCol + raidPtr->Layout.numParityCol; i++) 1566 if ((diskno = diskids[i]) != fcol) { 1567 if (pssPtr->issued[diskno]) { 1568 nPromoted = rf_DiskIOPromote(&raidPtr->Queues[row][diskno], psid, which_ru); 1569 if (rf_reconDebug && nPromoted) 1570 printf("raid%d: promoted read from row %d col %d\n", raidPtr->raidid, row, diskno); 1571 } else { 1572 new_rbuf = rf_MakeReconBuffer(raidPtr, row, diskno, RF_RBUF_TYPE_FORCED); /* create new buf */ 1573 ComputePSDiskOffsets(raidPtr, psid, row, diskno, &offset, &fd_offset, 1574 &new_rbuf->spRow, &new_rbuf->spCol, &new_rbuf->spOffset); /* find offsets & spare 1575 * location */ 1576 new_rbuf->parityStripeID = psid; /* fill in the buffer */ 1577 new_rbuf->which_ru = which_ru; 1578 new_rbuf->failedDiskSectorOffset = fd_offset; 1579 new_rbuf->priority = RF_IO_NORMAL_PRIORITY; 1580 1581 /* use NULL b_proc b/c all addrs 1582 * should be in kernel space */ 1583 req = rf_CreateDiskQueueData(RF_IO_TYPE_READ, offset + which_ru * sectorsPerRU, sectorsPerRU, new_rbuf->buffer, 1584 psid, which_ru, (int (*) (void *, int)) ForceReconReadDoneProc, (void *) new_rbuf, NULL, 1585 NULL, (void *) raidPtr, 0, NULL); 1586 1587 RF_ASSERT(req); /* XXX -- fix this -- 1588 * XXX */ 1589 1590 new_rbuf->arg = req; 1591 rf_DiskIOEnqueue(&raidPtr->Queues[row][diskno], req, RF_IO_NORMAL_PRIORITY); /* enqueue the I/O */ 1592 Dprintf3("raid%d: Issued new read req on row %d col %d\n", raidPtr->raidid, row, diskno); 1593 } 1594 } 1595 /* if the write is sitting in the disk queue, elevate its 1596 * priority */ 1597 if (rf_DiskIOPromote(&raidPtr->Queues[row][fcol], psid, which_ru)) 1598 printf("raid%d: promoted write to row %d col %d\n", 1599 raidPtr->raidid, row, fcol); 1600 } 1601 /* install a callback descriptor to be invoked when recon completes on 1602 * this parity stripe. */ 1603 cb = rf_AllocCallbackDesc(); 1604 /* XXX the following is bogus.. These functions don't really match!! 1605 * GO */ 1606 cb->callbackFunc = (void (*) (RF_CBParam_t)) cbFunc; 1607 cb->callbackArg.p = (void *) cbArg; 1608 cb->next = pssPtr->procWaitList; 1609 pssPtr->procWaitList = cb; 1610 DDprintf2("raid%d: Waiting for forced recon on psid %ld\n", 1611 raidPtr->raidid, psid); 1612 1613 RF_UNLOCK_PSS_MUTEX(raidPtr, row, psid); 1614 return (1); 1615 } 1616 /* called upon the completion of a forced reconstruction read. 1617 * all we do is schedule the FORCEDREADONE event. 1618 * called at interrupt context in the kernel, so don't do anything illegal here. 1619 */ 1620 static void 1621 ForceReconReadDoneProc(arg, status) 1622 void *arg; 1623 int status; 1624 { 1625 RF_ReconBuffer_t *rbuf = arg; 1626 1627 if (status) { 1628 printf("Forced recon read failed!\n"); /* fprintf(stderr,"Forced 1629 * recon read 1630 * failed!\n"); */ 1631 RF_PANIC(); 1632 } 1633 rf_CauseReconEvent((RF_Raid_t *) rbuf->raidPtr, rbuf->row, rbuf->col, (void *) rbuf, RF_REVENT_FORCEDREADDONE); 1634 } 1635 /* releases a block on the reconstruction of the indicated stripe */ 1636 int 1637 rf_UnblockRecon(raidPtr, asmap) 1638 RF_Raid_t *raidPtr; 1639 RF_AccessStripeMap_t *asmap; 1640 { 1641 RF_RowCol_t row = asmap->origRow; 1642 RF_StripeNum_t stripeID = asmap->stripeID; 1643 RF_ReconParityStripeStatus_t *pssPtr; 1644 RF_ReconUnitNum_t which_ru; 1645 RF_StripeNum_t psid; 1646 int created = 0; 1647 RF_CallbackDesc_t *cb; 1648 1649 psid = rf_MapStripeIDToParityStripeID(&raidPtr->Layout, stripeID, &which_ru); 1650 RF_LOCK_PSS_MUTEX(raidPtr, row, psid); 1651 pssPtr = rf_LookupRUStatus(raidPtr, raidPtr->reconControl[row]->pssTable, psid, which_ru, RF_PSS_NONE, &created); 1652 1653 /* When recon is forced, the pss desc can get deleted before we get 1654 * back to unblock recon. But, this can _only_ happen when recon is 1655 * forced. It would be good to put some kind of sanity check here, but 1656 * how to decide if recon was just forced or not? */ 1657 if (!pssPtr) { 1658 /* printf("Warning: no pss descriptor upon unblock on psid %ld 1659 * RU %d\n",psid,which_ru); */ 1660 if (rf_reconDebug || rf_pssDebug) 1661 printf("Warning: no pss descriptor upon unblock on psid %ld RU %d\n", (long) psid, which_ru); 1662 goto out; 1663 } 1664 pssPtr->blockCount--; 1665 Dprintf3("raid%d: unblocking recon on psid %ld: blockcount is %d\n", 1666 raidPtr->raidid, psid, pssPtr->blockCount); 1667 if (pssPtr->blockCount == 0) { /* if recon blockage has been released */ 1668 1669 /* unblock recon before calling CauseReconEvent in case 1670 * CauseReconEvent causes us to try to issue a new read before 1671 * returning here. */ 1672 pssPtr->flags &= ~RF_PSS_RECON_BLOCKED; 1673 1674 1675 while (pssPtr->blockWaitList) { 1676 /* spin through the block-wait list and 1677 release all the waiters */ 1678 cb = pssPtr->blockWaitList; 1679 pssPtr->blockWaitList = cb->next; 1680 cb->next = NULL; 1681 rf_CauseReconEvent(raidPtr, cb->row, cb->col, NULL, RF_REVENT_BLOCKCLEAR); 1682 rf_FreeCallbackDesc(cb); 1683 } 1684 if (!(pssPtr->flags & RF_PSS_UNDER_RECON)) { 1685 /* if no recon was requested while recon was blocked */ 1686 rf_PSStatusDelete(raidPtr, raidPtr->reconControl[row]->pssTable, pssPtr); 1687 } 1688 } 1689 out: 1690 RF_UNLOCK_PSS_MUTEX(raidPtr, row, psid); 1691 return (0); 1692 } 1693