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