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