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