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