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