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