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