rf_paritylogging.c revision 1.1 1 1.1 oster /* $NetBSD: rf_paritylogging.c,v 1.1 1998/11/13 04:20:32 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: William V. Courtright II
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 * Log: rf_paritylogging.c,v
31 1.1 oster * Revision 1.42 1996/11/05 21:10:40 jimz
32 1.1 oster * failed pda generalization
33 1.1 oster *
34 1.1 oster * Revision 1.41 1996/07/31 16:56:18 jimz
35 1.1 oster * dataBytesPerStripe, sectorsPerDisk init arch-indep.
36 1.1 oster *
37 1.1 oster * Revision 1.40 1996/07/28 20:31:39 jimz
38 1.1 oster * i386netbsd port
39 1.1 oster * true/false fixup
40 1.1 oster *
41 1.1 oster * Revision 1.39 1996/07/18 22:57:14 jimz
42 1.1 oster * port simulator to AIX
43 1.1 oster *
44 1.1 oster * Revision 1.38 1996/07/13 00:00:59 jimz
45 1.1 oster * sanitized generalized reconstruction architecture
46 1.1 oster * cleaned up head sep, rbuf problems
47 1.1 oster *
48 1.1 oster * Revision 1.37 1996/06/17 03:24:14 jimz
49 1.1 oster * switch to new shutdown function typing
50 1.1 oster *
51 1.1 oster * Revision 1.36 1996/06/14 23:15:38 jimz
52 1.1 oster * attempt to deal with thread GC problem
53 1.1 oster *
54 1.1 oster * Revision 1.35 1996/06/11 13:48:30 jimz
55 1.1 oster * get it to compile in-kernel
56 1.1 oster *
57 1.1 oster * Revision 1.34 1996/06/11 10:16:35 jimz
58 1.1 oster * Check return values on array configuration- back out if failed.
59 1.1 oster * Reorder shutdown to avoid using deallocated resources.
60 1.1 oster * Get rid of bogus join op in shutdown.
61 1.1 oster *
62 1.1 oster * Revision 1.33 1996/06/10 18:29:17 wvcii
63 1.1 oster * fixed bug in rf_IdentifyStripeParityLogging
64 1.1 oster * - added array initialization
65 1.1 oster *
66 1.1 oster * Revision 1.32 1996/06/10 11:55:47 jimz
67 1.1 oster * Straightened out some per-array/not-per-array distinctions, fixed
68 1.1 oster * a couple bugs related to confusion. Added shutdown lists. Removed
69 1.1 oster * layout shutdown function (now subsumed by shutdown lists).
70 1.1 oster *
71 1.1 oster * Revision 1.31 1996/06/07 22:26:27 jimz
72 1.1 oster * type-ify which_ru (RF_ReconUnitNum_t)
73 1.1 oster *
74 1.1 oster * Revision 1.30 1996/06/07 21:33:04 jimz
75 1.1 oster * begin using consistent types for sector numbers,
76 1.1 oster * stripe numbers, row+col numbers, recon unit numbers
77 1.1 oster *
78 1.1 oster * Revision 1.29 1996/06/05 18:06:02 jimz
79 1.1 oster * Major code cleanup. The Great Renaming is now done.
80 1.1 oster * Better modularity. Better typing. Fixed a bunch of
81 1.1 oster * synchronization bugs. Made a lot of global stuff
82 1.1 oster * per-desc or per-array. Removed dead code.
83 1.1 oster *
84 1.1 oster * Revision 1.28 1996/06/03 23:28:26 jimz
85 1.1 oster * more bugfixes
86 1.1 oster * check in tree to sync for IPDS runs with current bugfixes
87 1.1 oster * there still may be a problem with threads in the script test
88 1.1 oster * getting I/Os stuck- not trivially reproducible (runs ~50 times
89 1.1 oster * in a row without getting stuck)
90 1.1 oster *
91 1.1 oster * Revision 1.27 1996/06/02 17:31:48 jimz
92 1.1 oster * Moved a lot of global stuff into array structure, where it belongs.
93 1.1 oster * Fixed up paritylogging, pss modules in this manner. Some general
94 1.1 oster * code cleanup. Removed lots of dead code, some dead files.
95 1.1 oster *
96 1.1 oster * Revision 1.26 1996/05/31 22:26:54 jimz
97 1.1 oster * fix a lot of mapping problems, memory allocation problems
98 1.1 oster * found some weird lock issues, fixed 'em
99 1.1 oster * more code cleanup
100 1.1 oster *
101 1.1 oster * Revision 1.25 1996/05/30 23:22:16 jimz
102 1.1 oster * bugfixes of serialization, timing problems
103 1.1 oster * more cleanup
104 1.1 oster *
105 1.1 oster * Revision 1.24 1996/05/27 18:56:37 jimz
106 1.1 oster * more code cleanup
107 1.1 oster * better typing
108 1.1 oster * compiles in all 3 environments
109 1.1 oster *
110 1.1 oster * Revision 1.23 1996/05/24 22:17:04 jimz
111 1.1 oster * continue code + namespace cleanup
112 1.1 oster * typed a bunch of flags
113 1.1 oster *
114 1.1 oster * Revision 1.22 1996/05/24 01:59:45 jimz
115 1.1 oster * another checkpoint in code cleanup for release
116 1.1 oster * time to sync kernel tree
117 1.1 oster *
118 1.1 oster * Revision 1.21 1996/05/23 21:46:35 jimz
119 1.1 oster * checkpoint in code cleanup (release prep)
120 1.1 oster * lots of types, function names have been fixed
121 1.1 oster *
122 1.1 oster * Revision 1.20 1996/05/23 00:33:23 jimz
123 1.1 oster * code cleanup: move all debug decls to rf_options.c, all extern
124 1.1 oster * debug decls to rf_options.h, all debug vars preceded by rf_
125 1.1 oster *
126 1.1 oster * Revision 1.19 1996/05/20 16:16:30 jimz
127 1.1 oster * switch to rf_{mutex,cond}_{init,destroy}
128 1.1 oster *
129 1.1 oster * Revision 1.18 1996/05/18 19:51:34 jimz
130 1.1 oster * major code cleanup- fix syntax, make some types consistent,
131 1.1 oster * add prototypes, clean out dead code, et cetera
132 1.1 oster *
133 1.1 oster * Revision 1.17 1996/05/03 19:47:11 wvcii
134 1.1 oster * added includes of new dag library
135 1.1 oster *
136 1.1 oster * Revision 1.16 1995/12/12 18:10:06 jimz
137 1.1 oster * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
138 1.1 oster * fix 80-column brain damage in comments
139 1.1 oster *
140 1.1 oster * Revision 1.15 1995/12/06 20:57:43 wvcii
141 1.1 oster * added prototypes
142 1.1 oster * reintegration of logs on shutdown now conditional on forceParityLogReint
143 1.1 oster *
144 1.1 oster * Revision 1.14 1995/11/30 16:06:42 wvcii
145 1.1 oster * added copyright info
146 1.1 oster *
147 1.1 oster * Revision 1.13 1995/11/17 19:01:29 wvcii
148 1.1 oster * added prototyping to MapParity
149 1.1 oster *
150 1.1 oster * Revision 1.12 1995/11/07 15:36:03 wvcii
151 1.1 oster * changed ParityLoggingDagSelect prototype
152 1.1 oster * function no longer returns numHdrSucc, numTermAnt
153 1.1 oster *
154 1.1 oster * Revision 1.11 1995/10/08 20:42:54 wvcii
155 1.1 oster * lots of random debugging - debugging incomplete
156 1.1 oster *
157 1.1 oster * Revision 1.10 1995/09/07 01:26:55 jimz
158 1.1 oster * Achive basic compilation in kernel. Kernel functionality
159 1.1 oster * is not guaranteed at all, but it'll compile. Mostly. I hope.
160 1.1 oster *
161 1.1 oster * Revision 1.9 1995/09/06 19:21:17 wvcii
162 1.1 oster * explicit shutdown (forced reintegration) for simulator version
163 1.1 oster *
164 1.1 oster * Revision 1.8 1995/07/08 18:19:16 rachad
165 1.1 oster * Parity verifies can not be done in the simulator.
166 1.1 oster *
167 1.1 oster * Revision 1.7 1995/07/07 00:17:20 wvcii
168 1.1 oster * this version free from deadlock, fails parity verification
169 1.1 oster *
170 1.1 oster * Revision 1.6 1995/06/23 13:39:59 robby
171 1.1 oster * updeated to prototypes in rf_layout.h
172 1.1 oster *
173 1.1 oster * Revision 1.5 1995/06/09 13:14:56 wvcii
174 1.1 oster * code is now nonblocking
175 1.1 oster *
176 1.1 oster * Revision 1.4 95/06/01 17:02:23 wvcii
177 1.1 oster * code debug
178 1.1 oster *
179 1.1 oster * Revision 1.3 95/05/31 13:08:57 wvcii
180 1.1 oster * code debug
181 1.1 oster *
182 1.1 oster * Revision 1.2 95/05/21 15:35:00 wvcii
183 1.1 oster * code debug
184 1.1 oster *
185 1.1 oster *
186 1.1 oster *
187 1.1 oster */
188 1.1 oster
189 1.1 oster /*
190 1.1 oster parity logging configuration, dag selection, and mapping is implemented here
191 1.1 oster */
192 1.1 oster
193 1.1 oster #include "rf_archs.h"
194 1.1 oster
195 1.1 oster #if RF_INCLUDE_PARITYLOGGING > 0
196 1.1 oster
197 1.1 oster #include "rf_types.h"
198 1.1 oster #include "rf_raid.h"
199 1.1 oster #include "rf_dag.h"
200 1.1 oster #include "rf_dagutils.h"
201 1.1 oster #include "rf_dagfuncs.h"
202 1.1 oster #include "rf_dagffrd.h"
203 1.1 oster #include "rf_dagffwr.h"
204 1.1 oster #include "rf_dagdegrd.h"
205 1.1 oster #include "rf_dagdegwr.h"
206 1.1 oster #include "rf_threadid.h"
207 1.1 oster #include "rf_paritylog.h"
208 1.1 oster #include "rf_paritylogDiskMgr.h"
209 1.1 oster #include "rf_paritylogging.h"
210 1.1 oster #include "rf_parityloggingdags.h"
211 1.1 oster #include "rf_general.h"
212 1.1 oster #include "rf_map.h"
213 1.1 oster #include "rf_utils.h"
214 1.1 oster #include "rf_shutdown.h"
215 1.1 oster
216 1.1 oster typedef struct RF_ParityLoggingConfigInfo_s {
217 1.1 oster RF_RowCol_t **stripeIdentifier; /* filled in at config time & used by IdentifyStripe */
218 1.1 oster } RF_ParityLoggingConfigInfo_t;
219 1.1 oster
220 1.1 oster static void FreeRegionInfo(RF_Raid_t *raidPtr, RF_RegionId_t regionID);
221 1.1 oster static void rf_ShutdownParityLogging(RF_ThreadArg_t arg);
222 1.1 oster static void rf_ShutdownParityLoggingRegionInfo(RF_ThreadArg_t arg);
223 1.1 oster static void rf_ShutdownParityLoggingPool(RF_ThreadArg_t arg);
224 1.1 oster static void rf_ShutdownParityLoggingRegionBufferPool(RF_ThreadArg_t arg);
225 1.1 oster static void rf_ShutdownParityLoggingParityBufferPool(RF_ThreadArg_t arg);
226 1.1 oster static void rf_ShutdownParityLoggingDiskQueue(RF_ThreadArg_t arg);
227 1.1 oster
228 1.1 oster int rf_ConfigureParityLogging(
229 1.1 oster RF_ShutdownList_t **listp,
230 1.1 oster RF_Raid_t *raidPtr,
231 1.1 oster RF_Config_t *cfgPtr)
232 1.1 oster {
233 1.1 oster int i, j, startdisk, rc;
234 1.1 oster RF_SectorCount_t totalLogCapacity, fragmentation, lastRegionCapacity;
235 1.1 oster RF_SectorCount_t parityBufferCapacity, maxRegionParityRange;
236 1.1 oster RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
237 1.1 oster RF_ParityLoggingConfigInfo_t *info;
238 1.1 oster RF_ParityLog_t *l=NULL, *next;
239 1.1 oster caddr_t lHeapPtr;
240 1.1 oster
241 1.1 oster /*
242 1.1 oster * We create multiple entries on the shutdown list here, since
243 1.1 oster * this configuration routine is fairly complicated in and of
244 1.1 oster * itself, and this makes backing out of a failed configuration
245 1.1 oster * much simpler.
246 1.1 oster */
247 1.1 oster
248 1.1 oster raidPtr->numSectorsPerLog = RF_DEFAULT_NUM_SECTORS_PER_LOG;
249 1.1 oster
250 1.1 oster /* create a parity logging configuration structure */
251 1.1 oster RF_MallocAndAdd(info, sizeof(RF_ParityLoggingConfigInfo_t), (RF_ParityLoggingConfigInfo_t *), raidPtr->cleanupList);
252 1.1 oster if (info == NULL)
253 1.1 oster return(ENOMEM);
254 1.1 oster layoutPtr->layoutSpecificInfo = (void *) info;
255 1.1 oster
256 1.1 oster RF_ASSERT(raidPtr->numRow == 1);
257 1.1 oster
258 1.1 oster /* the stripe identifier must identify the disks in each stripe,
259 1.1 oster * IN THE ORDER THAT THEY APPEAR IN THE STRIPE.
260 1.1 oster */
261 1.1 oster info->stripeIdentifier = rf_make_2d_array((raidPtr->numCol), (raidPtr->numCol), raidPtr->cleanupList);
262 1.1 oster if (info->stripeIdentifier == NULL)
263 1.1 oster return(ENOMEM);
264 1.1 oster
265 1.1 oster startdisk = 0;
266 1.1 oster for (i=0; i<(raidPtr->numCol); i++)
267 1.1 oster {
268 1.1 oster for (j=0; j<(raidPtr->numCol); j++)
269 1.1 oster {
270 1.1 oster info->stripeIdentifier[i][j] = (startdisk + j) % (raidPtr->numCol - 1);
271 1.1 oster }
272 1.1 oster if ((--startdisk) < 0)
273 1.1 oster startdisk = raidPtr->numCol-1-1;
274 1.1 oster }
275 1.1 oster
276 1.1 oster /* fill in the remaining layout parameters */
277 1.1 oster layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
278 1.1 oster layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
279 1.1 oster layoutPtr->numParityCol = 1;
280 1.1 oster layoutPtr->numParityLogCol = 1;
281 1.1 oster layoutPtr->numDataCol = raidPtr->numCol - layoutPtr->numParityCol - layoutPtr->numParityLogCol;
282 1.1 oster layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
283 1.1 oster layoutPtr->dataStripeUnitsPerDisk = layoutPtr->stripeUnitsPerDisk;
284 1.1 oster raidPtr->sectorsPerDisk = layoutPtr->stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit;
285 1.1 oster
286 1.1 oster raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
287 1.1 oster
288 1.1 oster /* configure parity log parameters
289 1.1 oster
290 1.1 oster parameter comment/constraints
291 1.1 oster ---------------- -------------------
292 1.1 oster * numParityRegions all regions (except possibly last) of equal size
293 1.1 oster * totalInCoreLogCapacity amount of memory in bytes available for in-core logs (default 1 MB)
294 1.1 oster # numSectorsPerLog capacity of an in-core log in sectors (1 disk track)
295 1.1 oster numParityLogs total number of in-core logs, should be at least numParityRegions
296 1.1 oster regionLogCapacity size of a region log (except possibly last one) in sectors
297 1.1 oster totalLogCapacity total amount of log space in sectors
298 1.1 oster
299 1.1 oster * denotes a user settable parameter.
300 1.1 oster # logs are fixed to be the size of a disk track, value #defined in rf_paritylog.h
301 1.1 oster
302 1.1 oster */
303 1.1 oster
304 1.1 oster totalLogCapacity = layoutPtr->stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit * layoutPtr->numParityLogCol;
305 1.1 oster raidPtr->regionLogCapacity = totalLogCapacity / rf_numParityRegions;
306 1.1 oster if (rf_parityLogDebug)
307 1.1 oster printf("bytes per sector %d\n", raidPtr->bytesPerSector);
308 1.1 oster
309 1.1 oster /* reduce fragmentation within a disk region by adjusting the number of regions
310 1.1 oster in an attempt to allow an integral number of logs to fit into a disk region */
311 1.1 oster fragmentation = raidPtr->regionLogCapacity % raidPtr->numSectorsPerLog;
312 1.1 oster if (fragmentation > 0)
313 1.1 oster for (i = 1; i < (raidPtr->numSectorsPerLog / 2); i++)
314 1.1 oster {
315 1.1 oster if (((totalLogCapacity / (rf_numParityRegions + i)) % raidPtr->numSectorsPerLog) < fragmentation)
316 1.1 oster {
317 1.1 oster rf_numParityRegions++;
318 1.1 oster raidPtr->regionLogCapacity = totalLogCapacity / rf_numParityRegions;
319 1.1 oster fragmentation = raidPtr->regionLogCapacity % raidPtr->numSectorsPerLog;
320 1.1 oster }
321 1.1 oster if (((totalLogCapacity / (rf_numParityRegions - i)) % raidPtr->numSectorsPerLog) < fragmentation)
322 1.1 oster {
323 1.1 oster rf_numParityRegions--;
324 1.1 oster raidPtr->regionLogCapacity = totalLogCapacity / rf_numParityRegions;
325 1.1 oster fragmentation = raidPtr->regionLogCapacity % raidPtr->numSectorsPerLog;
326 1.1 oster }
327 1.1 oster }
328 1.1 oster /* ensure integral number of regions per log */
329 1.1 oster raidPtr->regionLogCapacity = (raidPtr->regionLogCapacity / raidPtr->numSectorsPerLog) * raidPtr->numSectorsPerLog;
330 1.1 oster
331 1.1 oster raidPtr->numParityLogs = rf_totalInCoreLogCapacity / (raidPtr->bytesPerSector * raidPtr->numSectorsPerLog);
332 1.1 oster /* to avoid deadlock, must ensure that enough logs exist for each region to have one simultaneously */
333 1.1 oster if (raidPtr->numParityLogs < rf_numParityRegions)
334 1.1 oster raidPtr->numParityLogs = rf_numParityRegions;
335 1.1 oster
336 1.1 oster /* create region information structs */
337 1.1 oster RF_Malloc(raidPtr->regionInfo, (rf_numParityRegions * sizeof(RF_RegionInfo_t)), (RF_RegionInfo_t *));
338 1.1 oster if (raidPtr->regionInfo == NULL)
339 1.1 oster return(ENOMEM);
340 1.1 oster
341 1.1 oster /* last region may not be full capacity */
342 1.1 oster lastRegionCapacity = raidPtr->regionLogCapacity;
343 1.1 oster while ((rf_numParityRegions - 1) * raidPtr->regionLogCapacity + lastRegionCapacity > totalLogCapacity)
344 1.1 oster lastRegionCapacity = lastRegionCapacity - raidPtr->numSectorsPerLog;
345 1.1 oster
346 1.1 oster raidPtr->regionParityRange = raidPtr->sectorsPerDisk / rf_numParityRegions;
347 1.1 oster maxRegionParityRange = raidPtr->regionParityRange;
348 1.1 oster
349 1.1 oster /* i can't remember why this line is in the code -wvcii 6/30/95 */
350 1.1 oster /* if (raidPtr->sectorsPerDisk % rf_numParityRegions > 0)
351 1.1 oster regionParityRange++; */
352 1.1 oster
353 1.1 oster /* build pool of unused parity logs */
354 1.1 oster RF_Malloc(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector, (caddr_t));
355 1.1 oster if (raidPtr->parityLogBufferHeap == NULL)
356 1.1 oster return(ENOMEM);
357 1.1 oster lHeapPtr = raidPtr->parityLogBufferHeap;
358 1.1 oster rc = rf_mutex_init(&raidPtr->parityLogPool.mutex);
359 1.1 oster if (rc) {
360 1.1 oster RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
361 1.1 oster __LINE__, rc);
362 1.1 oster RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
363 1.1 oster return(ENOMEM);
364 1.1 oster }
365 1.1 oster for (i = 0; i < raidPtr->numParityLogs; i++)
366 1.1 oster {
367 1.1 oster if (i == 0)
368 1.1 oster {
369 1.1 oster RF_Calloc(raidPtr->parityLogPool.parityLogs, 1, sizeof(RF_ParityLog_t), (RF_ParityLog_t *));
370 1.1 oster if (raidPtr->parityLogPool.parityLogs == NULL) {
371 1.1 oster RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
372 1.1 oster return(ENOMEM);
373 1.1 oster }
374 1.1 oster l = raidPtr->parityLogPool.parityLogs;
375 1.1 oster }
376 1.1 oster else
377 1.1 oster {
378 1.1 oster RF_Calloc(l->next, 1, sizeof(RF_ParityLog_t), (RF_ParityLog_t *));
379 1.1 oster if (l->next == NULL) {
380 1.1 oster RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
381 1.1 oster for(l=raidPtr->parityLogPool.parityLogs;l;l=next) {
382 1.1 oster next = l->next;
383 1.1 oster if (l->records)
384 1.1 oster RF_Free(l->records, (raidPtr->numSectorsPerLog * sizeof(RF_ParityLogRecord_t)));
385 1.1 oster RF_Free(l, sizeof(RF_ParityLog_t));
386 1.1 oster }
387 1.1 oster return(ENOMEM);
388 1.1 oster }
389 1.1 oster l = l->next;
390 1.1 oster }
391 1.1 oster l->bufPtr = lHeapPtr;
392 1.1 oster lHeapPtr += raidPtr->numSectorsPerLog * raidPtr->bytesPerSector;
393 1.1 oster RF_Malloc(l->records, (raidPtr->numSectorsPerLog * sizeof(RF_ParityLogRecord_t)), (RF_ParityLogRecord_t *));
394 1.1 oster if (l->records == NULL) {
395 1.1 oster RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
396 1.1 oster for(l=raidPtr->parityLogPool.parityLogs;l;l=next) {
397 1.1 oster next = l->next;
398 1.1 oster if (l->records)
399 1.1 oster RF_Free(l->records, (raidPtr->numSectorsPerLog * sizeof(RF_ParityLogRecord_t)));
400 1.1 oster RF_Free(l, sizeof(RF_ParityLog_t));
401 1.1 oster }
402 1.1 oster return(ENOMEM);
403 1.1 oster }
404 1.1 oster }
405 1.1 oster rc = rf_ShutdownCreate(listp, rf_ShutdownParityLoggingPool, raidPtr);
406 1.1 oster if (rc) {
407 1.1 oster RF_ERRORMSG3("Unable to create shutdown entry file %s line %d rc=%d\n", __FILE__,
408 1.1 oster __LINE__, rc);
409 1.1 oster rf_ShutdownParityLoggingPool(raidPtr);
410 1.1 oster return(rc);
411 1.1 oster }
412 1.1 oster
413 1.1 oster /* build pool of region buffers */
414 1.1 oster rc = rf_mutex_init(&raidPtr->regionBufferPool.mutex);
415 1.1 oster if (rc) {
416 1.1 oster RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
417 1.1 oster __LINE__, rc);
418 1.1 oster return(ENOMEM);
419 1.1 oster }
420 1.1 oster rc = rf_cond_init(&raidPtr->regionBufferPool.cond);
421 1.1 oster if (rc) {
422 1.1 oster RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n", __FILE__,
423 1.1 oster __LINE__, rc);
424 1.1 oster rf_mutex_destroy(&raidPtr->regionBufferPool.mutex);
425 1.1 oster return(ENOMEM);
426 1.1 oster }
427 1.1 oster raidPtr->regionBufferPool.bufferSize = raidPtr->regionLogCapacity * raidPtr->bytesPerSector;
428 1.1 oster printf("regionBufferPool.bufferSize %d\n",raidPtr->regionBufferPool.bufferSize);
429 1.1 oster raidPtr->regionBufferPool.totalBuffers = 1; /* for now, only one region at a time may be reintegrated */
430 1.1 oster raidPtr->regionBufferPool.availableBuffers = raidPtr->regionBufferPool.totalBuffers;
431 1.1 oster raidPtr->regionBufferPool.availBuffersIndex = 0;
432 1.1 oster raidPtr->regionBufferPool.emptyBuffersIndex = 0;
433 1.1 oster RF_Malloc(raidPtr->regionBufferPool.buffers, raidPtr->regionBufferPool.totalBuffers * sizeof(caddr_t), (caddr_t *));
434 1.1 oster if (raidPtr->regionBufferPool.buffers == NULL) {
435 1.1 oster rf_mutex_destroy(&raidPtr->regionBufferPool.mutex);
436 1.1 oster rf_cond_destroy(&raidPtr->regionBufferPool.cond);
437 1.1 oster return(ENOMEM);
438 1.1 oster }
439 1.1 oster for (i = 0; i < raidPtr->regionBufferPool.totalBuffers; i++) {
440 1.1 oster RF_Malloc(raidPtr->regionBufferPool.buffers[i], raidPtr->regionBufferPool.bufferSize * sizeof(char), (caddr_t));
441 1.1 oster if (raidPtr->regionBufferPool.buffers == NULL) {
442 1.1 oster rf_mutex_destroy(&raidPtr->regionBufferPool.mutex);
443 1.1 oster rf_cond_destroy(&raidPtr->regionBufferPool.cond);
444 1.1 oster for(j=0;j<i;j++) {
445 1.1 oster RF_Free(raidPtr->regionBufferPool.buffers[i], raidPtr->regionBufferPool.bufferSize * sizeof(char));
446 1.1 oster }
447 1.1 oster RF_Free(raidPtr->regionBufferPool.buffers, raidPtr->regionBufferPool.totalBuffers * sizeof(caddr_t));
448 1.1 oster return(ENOMEM);
449 1.1 oster }
450 1.1 oster printf("raidPtr->regionBufferPool.buffers[%d] = %lx\n", i,
451 1.1 oster (long)raidPtr->regionBufferPool.buffers[i]);
452 1.1 oster }
453 1.1 oster rc = rf_ShutdownCreate(listp, rf_ShutdownParityLoggingRegionBufferPool, raidPtr);
454 1.1 oster if (rc) {
455 1.1 oster RF_ERRORMSG3("Unable to create shutdown entry file %s line %d rc=%d\n", __FILE__,
456 1.1 oster __LINE__, rc);
457 1.1 oster rf_ShutdownParityLoggingRegionBufferPool(raidPtr);
458 1.1 oster return(rc);
459 1.1 oster }
460 1.1 oster
461 1.1 oster /* build pool of parity buffers */
462 1.1 oster parityBufferCapacity = maxRegionParityRange;
463 1.1 oster rc = rf_mutex_init(&raidPtr->parityBufferPool.mutex);
464 1.1 oster if (rc) {
465 1.1 oster RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
466 1.1 oster __LINE__, rc);
467 1.1 oster return(rc);
468 1.1 oster }
469 1.1 oster rc = rf_cond_init(&raidPtr->parityBufferPool.cond);
470 1.1 oster if (rc) {
471 1.1 oster RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n", __FILE__,
472 1.1 oster __LINE__, rc);
473 1.1 oster rf_mutex_destroy(&raidPtr->parityBufferPool.mutex);
474 1.1 oster return(ENOMEM);
475 1.1 oster }
476 1.1 oster raidPtr->parityBufferPool.bufferSize = parityBufferCapacity * raidPtr->bytesPerSector;
477 1.1 oster printf("parityBufferPool.bufferSize %d\n",raidPtr->parityBufferPool.bufferSize);
478 1.1 oster raidPtr->parityBufferPool.totalBuffers = 1; /* for now, only one region at a time may be reintegrated */
479 1.1 oster raidPtr->parityBufferPool.availableBuffers = raidPtr->parityBufferPool.totalBuffers;
480 1.1 oster raidPtr->parityBufferPool.availBuffersIndex = 0;
481 1.1 oster raidPtr->parityBufferPool.emptyBuffersIndex = 0;
482 1.1 oster RF_Malloc(raidPtr->parityBufferPool.buffers, raidPtr->parityBufferPool.totalBuffers * sizeof(caddr_t), (caddr_t *));
483 1.1 oster if (raidPtr->parityBufferPool.buffers == NULL) {
484 1.1 oster rf_mutex_destroy(&raidPtr->parityBufferPool.mutex);
485 1.1 oster rf_cond_destroy(&raidPtr->parityBufferPool.cond);
486 1.1 oster return(ENOMEM);
487 1.1 oster }
488 1.1 oster for (i = 0; i < raidPtr->parityBufferPool.totalBuffers; i++) {
489 1.1 oster RF_Malloc(raidPtr->parityBufferPool.buffers[i], raidPtr->parityBufferPool.bufferSize * sizeof(char), (caddr_t));
490 1.1 oster if (raidPtr->parityBufferPool.buffers == NULL) {
491 1.1 oster rf_mutex_destroy(&raidPtr->parityBufferPool.mutex);
492 1.1 oster rf_cond_destroy(&raidPtr->parityBufferPool.cond);
493 1.1 oster for(j=0;j<i;j++) {
494 1.1 oster RF_Free(raidPtr->parityBufferPool.buffers[i], raidPtr->regionBufferPool.bufferSize * sizeof(char));
495 1.1 oster }
496 1.1 oster RF_Free(raidPtr->parityBufferPool.buffers, raidPtr->regionBufferPool.totalBuffers * sizeof(caddr_t));
497 1.1 oster return(ENOMEM);
498 1.1 oster }
499 1.1 oster printf("parityBufferPool.buffers[%d] = %lx\n", i,
500 1.1 oster (long)raidPtr->parityBufferPool.buffers[i]);
501 1.1 oster }
502 1.1 oster rc = rf_ShutdownCreate(listp, rf_ShutdownParityLoggingParityBufferPool, raidPtr);
503 1.1 oster if (rc) {
504 1.1 oster RF_ERRORMSG3("Unable to create shutdown entry file %s line %d rc=%d\n", __FILE__,
505 1.1 oster __LINE__, rc);
506 1.1 oster rf_ShutdownParityLoggingParityBufferPool(raidPtr);
507 1.1 oster return(rc);
508 1.1 oster }
509 1.1 oster
510 1.1 oster /* initialize parityLogDiskQueue */
511 1.1 oster rc = rf_create_managed_mutex(listp, &raidPtr->parityLogDiskQueue.mutex);
512 1.1 oster if (rc) {
513 1.1 oster RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
514 1.1 oster __LINE__, rc);
515 1.1 oster return(rc);
516 1.1 oster }
517 1.1 oster rc = rf_create_managed_cond(listp, &raidPtr->parityLogDiskQueue.cond);
518 1.1 oster if (rc) {
519 1.1 oster RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n", __FILE__,
520 1.1 oster __LINE__, rc);
521 1.1 oster return(rc);
522 1.1 oster }
523 1.1 oster raidPtr->parityLogDiskQueue.flushQueue = NULL;
524 1.1 oster raidPtr->parityLogDiskQueue.reintQueue = NULL;
525 1.1 oster raidPtr->parityLogDiskQueue.bufHead = NULL;
526 1.1 oster raidPtr->parityLogDiskQueue.bufTail = NULL;
527 1.1 oster raidPtr->parityLogDiskQueue.reintHead = NULL;
528 1.1 oster raidPtr->parityLogDiskQueue.reintTail = NULL;
529 1.1 oster raidPtr->parityLogDiskQueue.logBlockHead = NULL;
530 1.1 oster raidPtr->parityLogDiskQueue.logBlockTail = NULL;
531 1.1 oster raidPtr->parityLogDiskQueue.reintBlockHead = NULL;
532 1.1 oster raidPtr->parityLogDiskQueue.reintBlockTail = NULL;
533 1.1 oster raidPtr->parityLogDiskQueue.freeDataList = NULL;
534 1.1 oster raidPtr->parityLogDiskQueue.freeCommonList = NULL;
535 1.1 oster
536 1.1 oster rc = rf_ShutdownCreate(listp, rf_ShutdownParityLoggingDiskQueue, raidPtr);
537 1.1 oster if (rc) {
538 1.1 oster RF_ERRORMSG3("Unable to create shutdown entry file %s line %d rc=%d\n", __FILE__,
539 1.1 oster __LINE__, rc);
540 1.1 oster return(rc);
541 1.1 oster }
542 1.1 oster
543 1.1 oster for (i = 0; i < rf_numParityRegions; i++)
544 1.1 oster {
545 1.1 oster rc = rf_mutex_init(&raidPtr->regionInfo[i].mutex);
546 1.1 oster if (rc) {
547 1.1 oster RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
548 1.1 oster __LINE__, rc);
549 1.1 oster for(j=0;j<i;j++)
550 1.1 oster FreeRegionInfo(raidPtr, j);
551 1.1 oster RF_Free(raidPtr->regionInfo, (rf_numParityRegions * sizeof(RF_RegionInfo_t)));
552 1.1 oster return(ENOMEM);
553 1.1 oster }
554 1.1 oster rc = rf_mutex_init(&raidPtr->regionInfo[i].reintMutex);
555 1.1 oster if (rc) {
556 1.1 oster RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
557 1.1 oster __LINE__, rc);
558 1.1 oster rf_mutex_destroy(&raidPtr->regionInfo[i].mutex);
559 1.1 oster for(j=0;j<i;j++)
560 1.1 oster FreeRegionInfo(raidPtr, j);
561 1.1 oster RF_Free(raidPtr->regionInfo, (rf_numParityRegions * sizeof(RF_RegionInfo_t)));
562 1.1 oster return(ENOMEM);
563 1.1 oster }
564 1.1 oster raidPtr->regionInfo[i].reintInProgress = RF_FALSE;
565 1.1 oster raidPtr->regionInfo[i].regionStartAddr = raidPtr->regionLogCapacity * i;
566 1.1 oster raidPtr->regionInfo[i].parityStartAddr = raidPtr->regionParityRange * i;
567 1.1 oster if (i < rf_numParityRegions - 1)
568 1.1 oster {
569 1.1 oster raidPtr->regionInfo[i].capacity = raidPtr->regionLogCapacity;
570 1.1 oster raidPtr->regionInfo[i].numSectorsParity = raidPtr->regionParityRange;
571 1.1 oster }
572 1.1 oster else
573 1.1 oster {
574 1.1 oster raidPtr->regionInfo[i].capacity = lastRegionCapacity;
575 1.1 oster raidPtr->regionInfo[i].numSectorsParity = raidPtr->sectorsPerDisk - raidPtr->regionParityRange * i;
576 1.1 oster if (raidPtr->regionInfo[i].numSectorsParity > maxRegionParityRange)
577 1.1 oster maxRegionParityRange = raidPtr->regionInfo[i].numSectorsParity;
578 1.1 oster }
579 1.1 oster raidPtr->regionInfo[i].diskCount = 0;
580 1.1 oster RF_ASSERT(raidPtr->regionInfo[i].capacity + raidPtr->regionInfo[i].regionStartAddr <= totalLogCapacity);
581 1.1 oster RF_ASSERT(raidPtr->regionInfo[i].parityStartAddr + raidPtr->regionInfo[i].numSectorsParity <= raidPtr->sectorsPerDisk);
582 1.1 oster RF_Malloc(raidPtr->regionInfo[i].diskMap, (raidPtr->regionInfo[i].capacity * sizeof(RF_DiskMap_t)), (RF_DiskMap_t *));
583 1.1 oster if (raidPtr->regionInfo[i].diskMap == NULL) {
584 1.1 oster rf_mutex_destroy(&raidPtr->regionInfo[i].mutex);
585 1.1 oster rf_mutex_destroy(&raidPtr->regionInfo[i].reintMutex);
586 1.1 oster for(j=0;j<i;j++)
587 1.1 oster FreeRegionInfo(raidPtr, j);
588 1.1 oster RF_Free(raidPtr->regionInfo, (rf_numParityRegions * sizeof(RF_RegionInfo_t)));
589 1.1 oster return(ENOMEM);
590 1.1 oster }
591 1.1 oster raidPtr->regionInfo[i].loggingEnabled = RF_FALSE;
592 1.1 oster raidPtr->regionInfo[i].coreLog = NULL;
593 1.1 oster }
594 1.1 oster rc = rf_ShutdownCreate(listp, rf_ShutdownParityLoggingRegionInfo, raidPtr);
595 1.1 oster if (rc) {
596 1.1 oster RF_ERRORMSG3("Unable to create shutdown entry file %s line %d rc=%d\n", __FILE__,
597 1.1 oster __LINE__, rc);
598 1.1 oster rf_ShutdownParityLoggingRegionInfo(raidPtr);
599 1.1 oster return(rc);
600 1.1 oster }
601 1.1 oster
602 1.1 oster RF_ASSERT(raidPtr->parityLogDiskQueue.threadState == 0);
603 1.1 oster raidPtr->parityLogDiskQueue.threadState = RF_PLOG_CREATED;
604 1.1 oster rc = RF_CREATE_THREAD(raidPtr->pLogDiskThreadHandle, rf_ParityLoggingDiskManager, raidPtr);
605 1.1 oster if (rc) {
606 1.1 oster raidPtr->parityLogDiskQueue.threadState = 0;
607 1.1 oster RF_ERRORMSG3("Unable to create parity logging disk thread file %s line %d rc=%d\n",
608 1.1 oster __FILE__, __LINE__, rc);
609 1.1 oster return(ENOMEM);
610 1.1 oster }
611 1.1 oster /* wait for thread to start */
612 1.1 oster RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
613 1.1 oster while(!(raidPtr->parityLogDiskQueue.threadState&RF_PLOG_RUNNING)) {
614 1.1 oster RF_WAIT_COND(raidPtr->parityLogDiskQueue.cond, raidPtr->parityLogDiskQueue.mutex);
615 1.1 oster }
616 1.1 oster RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
617 1.1 oster
618 1.1 oster rc = rf_ShutdownCreate(listp, rf_ShutdownParityLogging, raidPtr);
619 1.1 oster if (rc) {
620 1.1 oster RF_ERRORMSG1("Got rc=%d adding parity logging shutdown event\n", rc);
621 1.1 oster rf_ShutdownParityLogging(raidPtr);
622 1.1 oster return(rc);
623 1.1 oster }
624 1.1 oster
625 1.1 oster if (rf_parityLogDebug)
626 1.1 oster {
627 1.1 oster printf(" size of disk log in sectors: %d\n",
628 1.1 oster (int)totalLogCapacity);
629 1.1 oster printf(" total number of parity regions is %d\n", (int)rf_numParityRegions);
630 1.1 oster printf(" nominal sectors of log per parity region is %d\n", (int)raidPtr->regionLogCapacity);
631 1.1 oster printf(" nominal region fragmentation is %d sectors\n",(int)fragmentation);
632 1.1 oster printf(" total number of parity logs is %d\n", raidPtr->numParityLogs);
633 1.1 oster printf(" parity log size is %d sectors\n", raidPtr->numSectorsPerLog);
634 1.1 oster printf(" total in-core log space is %d bytes\n", (int) rf_totalInCoreLogCapacity);
635 1.1 oster }
636 1.1 oster
637 1.1 oster rf_EnableParityLogging(raidPtr);
638 1.1 oster
639 1.1 oster return(0);
640 1.1 oster }
641 1.1 oster
642 1.1 oster static void FreeRegionInfo(
643 1.1 oster RF_Raid_t *raidPtr,
644 1.1 oster RF_RegionId_t regionID)
645 1.1 oster {
646 1.1 oster RF_LOCK_MUTEX(raidPtr->regionInfo[regionID].mutex);
647 1.1 oster RF_Free(raidPtr->regionInfo[regionID].diskMap, (raidPtr->regionInfo[regionID].capacity * sizeof(RF_DiskMap_t)));
648 1.1 oster if (!rf_forceParityLogReint && raidPtr->regionInfo[regionID].coreLog) {
649 1.1 oster rf_ReleaseParityLogs(raidPtr, raidPtr->regionInfo[regionID].coreLog);
650 1.1 oster raidPtr->regionInfo[regionID].coreLog = NULL;
651 1.1 oster }
652 1.1 oster else {
653 1.1 oster RF_ASSERT(raidPtr->regionInfo[regionID].coreLog == NULL);
654 1.1 oster RF_ASSERT(raidPtr->regionInfo[regionID].diskCount == 0);
655 1.1 oster }
656 1.1 oster RF_UNLOCK_MUTEX(raidPtr->regionInfo[regionID].mutex);
657 1.1 oster rf_mutex_destroy(&raidPtr->regionInfo[regionID].mutex);
658 1.1 oster rf_mutex_destroy(&raidPtr->regionInfo[regionID].reintMutex);
659 1.1 oster }
660 1.1 oster
661 1.1 oster
662 1.1 oster static void FreeParityLogQueue(
663 1.1 oster RF_Raid_t *raidPtr,
664 1.1 oster RF_ParityLogQueue_t *queue)
665 1.1 oster {
666 1.1 oster RF_ParityLog_t *l1, *l2;
667 1.1 oster
668 1.1 oster RF_LOCK_MUTEX(queue->mutex);
669 1.1 oster l1 = queue->parityLogs;
670 1.1 oster while (l1)
671 1.1 oster {
672 1.1 oster l2 = l1;
673 1.1 oster l1 = l2->next;
674 1.1 oster RF_Free(l2->records, (raidPtr->numSectorsPerLog * sizeof(RF_ParityLogRecord_t)));
675 1.1 oster RF_Free(l2, sizeof(RF_ParityLog_t));
676 1.1 oster }
677 1.1 oster RF_UNLOCK_MUTEX(queue->mutex);
678 1.1 oster rf_mutex_destroy(&queue->mutex);
679 1.1 oster }
680 1.1 oster
681 1.1 oster
682 1.1 oster static void FreeRegionBufferQueue(RF_RegionBufferQueue_t *queue)
683 1.1 oster {
684 1.1 oster int i;
685 1.1 oster
686 1.1 oster RF_LOCK_MUTEX(queue->mutex);
687 1.1 oster if (queue->availableBuffers != queue->totalBuffers)
688 1.1 oster {
689 1.1 oster printf("Attempt to free region queue which is still in use!\n");
690 1.1 oster RF_ASSERT(0);
691 1.1 oster }
692 1.1 oster for (i = 0; i < queue->totalBuffers; i++)
693 1.1 oster RF_Free(queue->buffers[i], queue->bufferSize);
694 1.1 oster RF_Free(queue->buffers, queue->totalBuffers * sizeof(caddr_t));
695 1.1 oster RF_UNLOCK_MUTEX(queue->mutex);
696 1.1 oster rf_mutex_destroy(&queue->mutex);
697 1.1 oster }
698 1.1 oster
699 1.1 oster static void rf_ShutdownParityLoggingRegionInfo(RF_ThreadArg_t arg)
700 1.1 oster {
701 1.1 oster RF_Raid_t *raidPtr;
702 1.1 oster RF_RegionId_t i;
703 1.1 oster
704 1.1 oster raidPtr = (RF_Raid_t *)arg;
705 1.1 oster if (rf_parityLogDebug) {
706 1.1 oster int tid;
707 1.1 oster rf_get_threadid(tid);
708 1.1 oster printf("[%d] ShutdownParityLoggingRegionInfo\n", tid);
709 1.1 oster }
710 1.1 oster /* free region information structs */
711 1.1 oster for (i = 0; i < rf_numParityRegions; i++)
712 1.1 oster FreeRegionInfo(raidPtr, i);
713 1.1 oster RF_Free(raidPtr->regionInfo, (rf_numParityRegions * sizeof(raidPtr->regionInfo)));
714 1.1 oster raidPtr->regionInfo = NULL;
715 1.1 oster }
716 1.1 oster
717 1.1 oster static void rf_ShutdownParityLoggingPool(RF_ThreadArg_t arg)
718 1.1 oster {
719 1.1 oster RF_Raid_t *raidPtr;
720 1.1 oster
721 1.1 oster raidPtr = (RF_Raid_t *)arg;
722 1.1 oster if (rf_parityLogDebug) {
723 1.1 oster int tid;
724 1.1 oster rf_get_threadid(tid);
725 1.1 oster printf("[%d] ShutdownParityLoggingPool\n", tid);
726 1.1 oster }
727 1.1 oster /* free contents of parityLogPool */
728 1.1 oster FreeParityLogQueue(raidPtr, &raidPtr->parityLogPool);
729 1.1 oster RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
730 1.1 oster }
731 1.1 oster
732 1.1 oster static void rf_ShutdownParityLoggingRegionBufferPool(RF_ThreadArg_t arg)
733 1.1 oster {
734 1.1 oster RF_Raid_t *raidPtr;
735 1.1 oster
736 1.1 oster raidPtr = (RF_Raid_t *)arg;
737 1.1 oster if (rf_parityLogDebug) {
738 1.1 oster int tid;
739 1.1 oster rf_get_threadid(tid);
740 1.1 oster printf("[%d] ShutdownParityLoggingRegionBufferPool\n", tid);
741 1.1 oster }
742 1.1 oster FreeRegionBufferQueue(&raidPtr->regionBufferPool);
743 1.1 oster }
744 1.1 oster
745 1.1 oster static void rf_ShutdownParityLoggingParityBufferPool(RF_ThreadArg_t arg)
746 1.1 oster {
747 1.1 oster RF_Raid_t *raidPtr;
748 1.1 oster
749 1.1 oster raidPtr = (RF_Raid_t *)arg;
750 1.1 oster if (rf_parityLogDebug) {
751 1.1 oster int tid;
752 1.1 oster rf_get_threadid(tid);
753 1.1 oster printf("[%d] ShutdownParityLoggingParityBufferPool\n", tid);
754 1.1 oster }
755 1.1 oster FreeRegionBufferQueue(&raidPtr->parityBufferPool);
756 1.1 oster }
757 1.1 oster
758 1.1 oster static void rf_ShutdownParityLoggingDiskQueue(RF_ThreadArg_t arg)
759 1.1 oster {
760 1.1 oster RF_ParityLogData_t *d;
761 1.1 oster RF_CommonLogData_t *c;
762 1.1 oster RF_Raid_t *raidPtr;
763 1.1 oster
764 1.1 oster raidPtr = (RF_Raid_t *)arg;
765 1.1 oster if (rf_parityLogDebug) {
766 1.1 oster int tid;
767 1.1 oster rf_get_threadid(tid);
768 1.1 oster printf("[%d] ShutdownParityLoggingDiskQueue\n", tid);
769 1.1 oster }
770 1.1 oster /* free disk manager stuff */
771 1.1 oster RF_ASSERT(raidPtr->parityLogDiskQueue.bufHead == NULL);
772 1.1 oster RF_ASSERT(raidPtr->parityLogDiskQueue.bufTail == NULL);
773 1.1 oster RF_ASSERT(raidPtr->parityLogDiskQueue.reintHead == NULL);
774 1.1 oster RF_ASSERT(raidPtr->parityLogDiskQueue.reintTail == NULL);
775 1.1 oster while (raidPtr->parityLogDiskQueue.freeDataList)
776 1.1 oster {
777 1.1 oster d = raidPtr->parityLogDiskQueue.freeDataList;
778 1.1 oster raidPtr->parityLogDiskQueue.freeDataList = raidPtr->parityLogDiskQueue.freeDataList->next;
779 1.1 oster RF_Free(d, sizeof(RF_ParityLogData_t));
780 1.1 oster }
781 1.1 oster while (raidPtr->parityLogDiskQueue.freeCommonList)
782 1.1 oster {
783 1.1 oster c = raidPtr->parityLogDiskQueue.freeCommonList;
784 1.1 oster rf_mutex_destroy(&c->mutex);
785 1.1 oster raidPtr->parityLogDiskQueue.freeCommonList = raidPtr->parityLogDiskQueue.freeCommonList->next;
786 1.1 oster RF_Free(c, sizeof(RF_CommonLogData_t));
787 1.1 oster }
788 1.1 oster }
789 1.1 oster
790 1.1 oster static void rf_ShutdownParityLogging(RF_ThreadArg_t arg)
791 1.1 oster {
792 1.1 oster RF_Raid_t *raidPtr;
793 1.1 oster
794 1.1 oster raidPtr = (RF_Raid_t *)arg;
795 1.1 oster if (rf_parityLogDebug) {
796 1.1 oster int tid;
797 1.1 oster rf_get_threadid(tid);
798 1.1 oster printf("[%d] ShutdownParityLogging\n", tid);
799 1.1 oster }
800 1.1 oster #ifndef SIMULATE
801 1.1 oster /* shutdown disk thread */
802 1.1 oster /* This has the desirable side-effect of forcing all regions to be
803 1.1 oster reintegrated. This is necessary since all parity log maps are
804 1.1 oster currently held in volatile memory. */
805 1.1 oster
806 1.1 oster RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
807 1.1 oster raidPtr->parityLogDiskQueue.threadState |= RF_PLOG_TERMINATE;
808 1.1 oster RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
809 1.1 oster RF_SIGNAL_COND(raidPtr->parityLogDiskQueue.cond);
810 1.1 oster /*
811 1.1 oster * pLogDiskThread will now terminate when queues are cleared
812 1.1 oster * now wait for it to be done
813 1.1 oster */
814 1.1 oster RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
815 1.1 oster while(!(raidPtr->parityLogDiskQueue.threadState&RF_PLOG_SHUTDOWN)) {
816 1.1 oster RF_WAIT_COND(raidPtr->parityLogDiskQueue.cond, raidPtr->parityLogDiskQueue.mutex);
817 1.1 oster }
818 1.1 oster RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
819 1.1 oster #else /* !SIMULATE */
820 1.1 oster /* explicitly call shutdown routines which force reintegration */
821 1.1 oster rf_ShutdownLogging(raidPtr);
822 1.1 oster #endif /* !SIMULATE */
823 1.1 oster if (rf_parityLogDebug) {
824 1.1 oster int tid;
825 1.1 oster rf_get_threadid(tid);
826 1.1 oster printf("[%d] ShutdownParityLogging done (thread completed)\n", tid);
827 1.1 oster }
828 1.1 oster }
829 1.1 oster
830 1.1 oster int rf_GetDefaultNumFloatingReconBuffersParityLogging(RF_Raid_t *raidPtr)
831 1.1 oster {
832 1.1 oster return(20);
833 1.1 oster }
834 1.1 oster
835 1.1 oster RF_HeadSepLimit_t rf_GetDefaultHeadSepLimitParityLogging(RF_Raid_t *raidPtr)
836 1.1 oster {
837 1.1 oster return(10);
838 1.1 oster }
839 1.1 oster
840 1.1 oster /* return the region ID for a given RAID address */
841 1.1 oster RF_RegionId_t rf_MapRegionIDParityLogging(
842 1.1 oster RF_Raid_t *raidPtr,
843 1.1 oster RF_SectorNum_t address)
844 1.1 oster {
845 1.1 oster RF_RegionId_t regionID;
846 1.1 oster
847 1.1 oster /* regionID = address / (raidPtr->regionParityRange * raidPtr->Layout.numDataCol); */
848 1.1 oster regionID = address / raidPtr->regionParityRange;
849 1.1 oster if (regionID == rf_numParityRegions)
850 1.1 oster {
851 1.1 oster /* last region may be larger than other regions */
852 1.1 oster regionID--;
853 1.1 oster }
854 1.1 oster RF_ASSERT(address >= raidPtr->regionInfo[regionID].parityStartAddr);
855 1.1 oster RF_ASSERT(address < raidPtr->regionInfo[regionID].parityStartAddr + raidPtr->regionInfo[regionID].numSectorsParity);
856 1.1 oster RF_ASSERT(regionID < rf_numParityRegions);
857 1.1 oster return(regionID);
858 1.1 oster }
859 1.1 oster
860 1.1 oster
861 1.1 oster /* given a logical RAID sector, determine physical disk address of data */
862 1.1 oster void rf_MapSectorParityLogging(
863 1.1 oster RF_Raid_t *raidPtr,
864 1.1 oster RF_RaidAddr_t raidSector,
865 1.1 oster RF_RowCol_t *row,
866 1.1 oster RF_RowCol_t *col,
867 1.1 oster RF_SectorNum_t *diskSector,
868 1.1 oster int remap)
869 1.1 oster {
870 1.1 oster RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
871 1.1 oster *row = 0;
872 1.1 oster /* *col = (SUID % (raidPtr->numCol - raidPtr->Layout.numParityLogCol)); */
873 1.1 oster *col = SUID % raidPtr->Layout.numDataCol;
874 1.1 oster *diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
875 1.1 oster (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
876 1.1 oster }
877 1.1 oster
878 1.1 oster
879 1.1 oster /* given a logical RAID sector, determine physical disk address of parity */
880 1.1 oster void rf_MapParityParityLogging(
881 1.1 oster RF_Raid_t *raidPtr,
882 1.1 oster RF_RaidAddr_t raidSector,
883 1.1 oster RF_RowCol_t *row,
884 1.1 oster RF_RowCol_t *col,
885 1.1 oster RF_SectorNum_t *diskSector,
886 1.1 oster int remap)
887 1.1 oster {
888 1.1 oster RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
889 1.1 oster
890 1.1 oster *row = 0;
891 1.1 oster /* *col = raidPtr->Layout.numDataCol-(SUID/raidPtr->Layout.numDataCol)%(raidPtr->numCol - raidPtr->Layout.numParityLogCol); */
892 1.1 oster *col = raidPtr->Layout.numDataCol;
893 1.1 oster *diskSector =(SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
894 1.1 oster (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
895 1.1 oster }
896 1.1 oster
897 1.1 oster
898 1.1 oster /* given a regionID and sector offset, determine the physical disk address of the parity log */
899 1.1 oster void rf_MapLogParityLogging(
900 1.1 oster RF_Raid_t *raidPtr,
901 1.1 oster RF_RegionId_t regionID,
902 1.1 oster RF_SectorNum_t regionOffset,
903 1.1 oster RF_RowCol_t *row,
904 1.1 oster RF_RowCol_t *col,
905 1.1 oster RF_SectorNum_t *startSector)
906 1.1 oster {
907 1.1 oster *row = 0;
908 1.1 oster *col = raidPtr->numCol - 1;
909 1.1 oster *startSector = raidPtr->regionInfo[regionID].regionStartAddr + regionOffset;
910 1.1 oster }
911 1.1 oster
912 1.1 oster
913 1.1 oster /* given a regionID, determine the physical disk address of the logged parity for that region */
914 1.1 oster void rf_MapRegionParity(
915 1.1 oster RF_Raid_t *raidPtr,
916 1.1 oster RF_RegionId_t regionID,
917 1.1 oster RF_RowCol_t *row,
918 1.1 oster RF_RowCol_t *col,
919 1.1 oster RF_SectorNum_t *startSector,
920 1.1 oster RF_SectorCount_t *numSector)
921 1.1 oster {
922 1.1 oster *row = 0;
923 1.1 oster *col = raidPtr->numCol - 2;
924 1.1 oster *startSector = raidPtr->regionInfo[regionID].parityStartAddr;
925 1.1 oster *numSector = raidPtr->regionInfo[regionID].numSectorsParity;
926 1.1 oster }
927 1.1 oster
928 1.1 oster
929 1.1 oster /* given a logical RAID address, determine the participating disks in the stripe */
930 1.1 oster void rf_IdentifyStripeParityLogging(
931 1.1 oster RF_Raid_t *raidPtr,
932 1.1 oster RF_RaidAddr_t addr,
933 1.1 oster RF_RowCol_t **diskids,
934 1.1 oster RF_RowCol_t *outRow)
935 1.1 oster {
936 1.1 oster RF_StripeNum_t stripeID = rf_RaidAddressToStripeID(&raidPtr->Layout, addr);
937 1.1 oster RF_ParityLoggingConfigInfo_t *info = (RF_ParityLoggingConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
938 1.1 oster *outRow = 0;
939 1.1 oster *diskids = info->stripeIdentifier[ stripeID % raidPtr->numCol ];
940 1.1 oster }
941 1.1 oster
942 1.1 oster
943 1.1 oster void rf_MapSIDToPSIDParityLogging(
944 1.1 oster RF_RaidLayout_t *layoutPtr,
945 1.1 oster RF_StripeNum_t stripeID,
946 1.1 oster RF_StripeNum_t *psID,
947 1.1 oster RF_ReconUnitNum_t *which_ru)
948 1.1 oster {
949 1.1 oster *which_ru = 0;
950 1.1 oster *psID = stripeID;
951 1.1 oster }
952 1.1 oster
953 1.1 oster
954 1.1 oster /* select an algorithm for performing an access. Returns two pointers,
955 1.1 oster * one to a function that will return information about the DAG, and
956 1.1 oster * another to a function that will create the dag.
957 1.1 oster */
958 1.1 oster void rf_ParityLoggingDagSelect(
959 1.1 oster RF_Raid_t *raidPtr,
960 1.1 oster RF_IoType_t type,
961 1.1 oster RF_AccessStripeMap_t *asmp,
962 1.1 oster RF_VoidFuncPtr *createFunc)
963 1.1 oster {
964 1.1 oster RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
965 1.1 oster RF_PhysDiskAddr_t *failedPDA=NULL;
966 1.1 oster RF_RowCol_t frow, fcol;
967 1.1 oster RF_RowStatus_t rstat;
968 1.1 oster int prior_recon;
969 1.1 oster int tid;
970 1.1 oster
971 1.1 oster RF_ASSERT(RF_IO_IS_R_OR_W(type));
972 1.1 oster
973 1.1 oster if (asmp->numDataFailed + asmp->numParityFailed > 1) {
974 1.1 oster RF_ERRORMSG("Multiple disks failed in a single group! Aborting I/O operation.\n");
975 1.1 oster /* *infoFunc = */ *createFunc = NULL;
976 1.1 oster return;
977 1.1 oster } else if (asmp->numDataFailed + asmp->numParityFailed == 1) {
978 1.1 oster
979 1.1 oster /* if under recon & already reconstructed, redirect the access to the spare drive
980 1.1 oster * and eliminate the failure indication
981 1.1 oster */
982 1.1 oster failedPDA = asmp->failedPDAs[0];
983 1.1 oster frow = failedPDA->row; fcol = failedPDA->col;
984 1.1 oster rstat = raidPtr->status[failedPDA->row];
985 1.1 oster prior_recon = (rstat == rf_rs_reconfigured) || (
986 1.1 oster (rstat == rf_rs_reconstructing) ?
987 1.1 oster rf_CheckRUReconstructed(raidPtr->reconControl[frow]->reconMap, failedPDA->startSector) : 0
988 1.1 oster );
989 1.1 oster if (prior_recon) {
990 1.1 oster RF_RowCol_t or = failedPDA->row,oc=failedPDA->col;
991 1.1 oster RF_SectorNum_t oo=failedPDA->startSector;
992 1.1 oster if (layoutPtr->map->flags & RF_DISTRIBUTE_SPARE) { /* redirect to dist spare space */
993 1.1 oster
994 1.1 oster if (failedPDA == asmp->parityInfo) {
995 1.1 oster
996 1.1 oster /* parity has failed */
997 1.1 oster (layoutPtr->map->MapParity)(raidPtr, failedPDA->raidAddress, &failedPDA->row,
998 1.1 oster &failedPDA->col, &failedPDA->startSector, RF_REMAP);
999 1.1 oster
1000 1.1 oster if (asmp->parityInfo->next) { /* redir 2nd component, if any */
1001 1.1 oster RF_PhysDiskAddr_t *p = asmp->parityInfo->next;
1002 1.1 oster RF_SectorNum_t SUoffs = p->startSector % layoutPtr->sectorsPerStripeUnit;
1003 1.1 oster p->row = failedPDA->row;
1004 1.1 oster p->col = failedPDA->col;
1005 1.1 oster p->startSector = rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, failedPDA->startSector) +
1006 1.1 oster SUoffs; /* cheating: startSector is not really a RAID address */
1007 1.1 oster }
1008 1.1 oster
1009 1.1 oster } else if (asmp->parityInfo->next && failedPDA == asmp->parityInfo->next) {
1010 1.1 oster RF_ASSERT(0); /* should not ever happen */
1011 1.1 oster } else {
1012 1.1 oster
1013 1.1 oster /* data has failed */
1014 1.1 oster (layoutPtr->map->MapSector)(raidPtr, failedPDA->raidAddress, &failedPDA->row,
1015 1.1 oster &failedPDA->col, &failedPDA->startSector, RF_REMAP);
1016 1.1 oster
1017 1.1 oster }
1018 1.1 oster
1019 1.1 oster } else { /* redirect to dedicated spare space */
1020 1.1 oster
1021 1.1 oster failedPDA->row = raidPtr->Disks[frow][fcol].spareRow;
1022 1.1 oster failedPDA->col = raidPtr->Disks[frow][fcol].spareCol;
1023 1.1 oster
1024 1.1 oster /* the parity may have two distinct components, both of which may need to be redirected */
1025 1.1 oster if (asmp->parityInfo->next) {
1026 1.1 oster if (failedPDA == asmp->parityInfo) {
1027 1.1 oster failedPDA->next->row = failedPDA->row;
1028 1.1 oster failedPDA->next->col = failedPDA->col;
1029 1.1 oster } else if (failedPDA == asmp->parityInfo->next) { /* paranoid: should never occur */
1030 1.1 oster asmp->parityInfo->row = failedPDA->row;
1031 1.1 oster asmp->parityInfo->col = failedPDA->col;
1032 1.1 oster }
1033 1.1 oster }
1034 1.1 oster }
1035 1.1 oster
1036 1.1 oster RF_ASSERT(failedPDA->col != -1);
1037 1.1 oster
1038 1.1 oster if (rf_dagDebug || rf_mapDebug) {
1039 1.1 oster rf_get_threadid(tid);
1040 1.1 oster printf("[%d] Redirected type '%c' r %d c %d o %ld -> r %d c %d o %ld\n",
1041 1.1 oster tid,type,or,oc,(long)oo,failedPDA->row,failedPDA->col,(long)failedPDA->startSector);
1042 1.1 oster }
1043 1.1 oster
1044 1.1 oster asmp->numDataFailed = asmp->numParityFailed = 0;
1045 1.1 oster }
1046 1.1 oster
1047 1.1 oster }
1048 1.1 oster
1049 1.1 oster
1050 1.1 oster if (type == RF_IO_TYPE_READ) {
1051 1.1 oster
1052 1.1 oster if (asmp->numDataFailed == 0)
1053 1.1 oster *createFunc = (RF_VoidFuncPtr)rf_CreateFaultFreeReadDAG;
1054 1.1 oster else
1055 1.1 oster *createFunc = (RF_VoidFuncPtr)rf_CreateRaidFiveDegradedReadDAG;
1056 1.1 oster
1057 1.1 oster }
1058 1.1 oster else {
1059 1.1 oster
1060 1.1 oster
1061 1.1 oster /* if mirroring, always use large writes. If the access requires two distinct parity updates,
1062 1.1 oster * always do a small write. If the stripe contains a failure but the access does not, do a
1063 1.1 oster * small write.
1064 1.1 oster * The first conditional (numStripeUnitsAccessed <= numDataCol/2) uses a less-than-or-equal
1065 1.1 oster * rather than just a less-than because when G is 3 or 4, numDataCol/2 is 1, and I want
1066 1.1 oster * single-stripe-unit updates to use just one disk.
1067 1.1 oster */
1068 1.1 oster if ( (asmp->numDataFailed + asmp->numParityFailed) == 0) {
1069 1.1 oster if (((asmp->numStripeUnitsAccessed <= (layoutPtr->numDataCol / 2)) && (layoutPtr->numDataCol!=1)) ||
1070 1.1 oster (asmp->parityInfo->next!=NULL) || rf_CheckStripeForFailures(raidPtr, asmp)) {
1071 1.1 oster *createFunc = (RF_VoidFuncPtr)rf_CreateParityLoggingSmallWriteDAG;
1072 1.1 oster }
1073 1.1 oster else
1074 1.1 oster *createFunc = (RF_VoidFuncPtr)rf_CreateParityLoggingLargeWriteDAG;
1075 1.1 oster }
1076 1.1 oster else
1077 1.1 oster if (asmp->numParityFailed == 1)
1078 1.1 oster *createFunc = (RF_VoidFuncPtr)rf_CreateNonRedundantWriteDAG;
1079 1.1 oster else
1080 1.1 oster if (asmp->numStripeUnitsAccessed != 1 && failedPDA->numSector != layoutPtr->sectorsPerStripeUnit)
1081 1.1 oster *createFunc = NULL;
1082 1.1 oster else
1083 1.1 oster *createFunc = (RF_VoidFuncPtr)rf_CreateDegradedWriteDAG;
1084 1.1 oster }
1085 1.1 oster }
1086 1.1 oster
1087 1.1 oster #endif /* RF_INCLUDE_PARITYLOGGING > 0 */
1088