rf_paritylogDiskMgr.c revision 1.7 1 /* $NetBSD: rf_paritylogDiskMgr.c,v 1.7 2000/01/08 01:18:36 oster Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
5 *
6 * Author: William V. Courtright II
7 *
8 * Permission to use, copy, modify and distribute this software and
9 * its documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
27 */
28 /* Code for flushing and reintegration operations related to parity logging.
29 *
30 */
31
32 #include "rf_archs.h"
33
34 #if RF_INCLUDE_PARITYLOGGING > 0
35
36 #include "rf_types.h"
37 #include "rf_threadstuff.h"
38 #include "rf_mcpair.h"
39 #include "rf_raid.h"
40 #include "rf_dag.h"
41 #include "rf_dagfuncs.h"
42 #include "rf_desc.h"
43 #include "rf_layout.h"
44 #include "rf_diskqueue.h"
45 #include "rf_paritylog.h"
46 #include "rf_general.h"
47 #include "rf_etimer.h"
48 #include "rf_paritylogging.h"
49 #include "rf_engine.h"
50 #include "rf_dagutils.h"
51 #include "rf_map.h"
52 #include "rf_parityscan.h"
53
54 #include "rf_paritylogDiskMgr.h"
55
56 static caddr_t AcquireReintBuffer(RF_RegionBufferQueue_t *);
57
58 static caddr_t
59 AcquireReintBuffer(pool)
60 RF_RegionBufferQueue_t *pool;
61 {
62 caddr_t bufPtr = NULL;
63
64 /* Return a region buffer from the free list (pool). If the free list
65 * is empty, WAIT. BLOCKING */
66
67 RF_LOCK_MUTEX(pool->mutex);
68 if (pool->availableBuffers > 0) {
69 bufPtr = pool->buffers[pool->availBuffersIndex];
70 pool->availableBuffers--;
71 pool->availBuffersIndex++;
72 if (pool->availBuffersIndex == pool->totalBuffers)
73 pool->availBuffersIndex = 0;
74 RF_UNLOCK_MUTEX(pool->mutex);
75 } else {
76 RF_PANIC(); /* should never happen in currect config,
77 * single reint */
78 RF_WAIT_COND(pool->cond, pool->mutex);
79 }
80 return (bufPtr);
81 }
82
83 static void
84 ReleaseReintBuffer(
85 RF_RegionBufferQueue_t * pool,
86 caddr_t bufPtr)
87 {
88 /* Insert a region buffer (bufPtr) into the free list (pool).
89 * NON-BLOCKING */
90
91 RF_LOCK_MUTEX(pool->mutex);
92 pool->availableBuffers++;
93 pool->buffers[pool->emptyBuffersIndex] = bufPtr;
94 pool->emptyBuffersIndex++;
95 if (pool->emptyBuffersIndex == pool->totalBuffers)
96 pool->emptyBuffersIndex = 0;
97 RF_ASSERT(pool->availableBuffers <= pool->totalBuffers);
98 RF_UNLOCK_MUTEX(pool->mutex);
99 RF_SIGNAL_COND(pool->cond);
100 }
101
102
103
104 static void
105 ReadRegionLog(
106 RF_RegionId_t regionID,
107 RF_MCPair_t * rrd_mcpair,
108 caddr_t regionBuffer,
109 RF_Raid_t * raidPtr,
110 RF_DagHeader_t ** rrd_dag_h,
111 RF_AllocListElem_t ** rrd_alloclist,
112 RF_PhysDiskAddr_t ** rrd_pda)
113 {
114 /* Initiate the read a region log from disk. Once initiated, return
115 * to the calling routine.
116 *
117 * NON-BLOCKING */
118
119 RF_AccTraceEntry_t tracerec;
120 RF_DagNode_t *rrd_rdNode;
121
122 /* create DAG to read region log from disk */
123 rf_MakeAllocList(*rrd_alloclist);
124 *rrd_dag_h = rf_MakeSimpleDAG(raidPtr, 1, 0, regionBuffer, rf_DiskReadFunc, rf_DiskReadUndoFunc,
125 "Rrl", *rrd_alloclist, RF_DAG_FLAGS_NONE, RF_IO_NORMAL_PRIORITY);
126
127 /* create and initialize PDA for the core log */
128 /* RF_Malloc(*rrd_pda, sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t
129 * *)); */
130 *rrd_pda = rf_AllocPDAList(1);
131 rf_MapLogParityLogging(raidPtr, regionID, 0, &((*rrd_pda)->row), &((*rrd_pda)->col), &((*rrd_pda)->startSector));
132 (*rrd_pda)->numSector = raidPtr->regionInfo[regionID].capacity;
133
134 if ((*rrd_pda)->next) {
135 (*rrd_pda)->next = NULL;
136 printf("set rrd_pda->next to NULL\n");
137 }
138 /* initialize DAG parameters */
139 bzero((char *) &tracerec, sizeof(tracerec));
140 (*rrd_dag_h)->tracerec = &tracerec;
141 rrd_rdNode = (*rrd_dag_h)->succedents[0]->succedents[0];
142 rrd_rdNode->params[0].p = *rrd_pda;
143 /* rrd_rdNode->params[1] = regionBuffer; */
144 rrd_rdNode->params[2].v = 0;
145 rrd_rdNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, 0);
146
147 /* launch region log read dag */
148 rf_DispatchDAG(*rrd_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
149 (void *) rrd_mcpair);
150 }
151
152
153
154 static void
155 WriteCoreLog(
156 RF_ParityLog_t * log,
157 RF_MCPair_t * fwr_mcpair,
158 RF_Raid_t * raidPtr,
159 RF_DagHeader_t ** fwr_dag_h,
160 RF_AllocListElem_t ** fwr_alloclist,
161 RF_PhysDiskAddr_t ** fwr_pda)
162 {
163 RF_RegionId_t regionID = log->regionID;
164 RF_AccTraceEntry_t tracerec;
165 RF_SectorNum_t regionOffset;
166 RF_DagNode_t *fwr_wrNode;
167
168 /* Initiate the write of a core log to a region log disk. Once
169 * initiated, return to the calling routine.
170 *
171 * NON-BLOCKING */
172
173 /* create DAG to write a core log to a region log disk */
174 rf_MakeAllocList(*fwr_alloclist);
175 *fwr_dag_h = rf_MakeSimpleDAG(raidPtr, 1, 0, log->bufPtr, rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
176 "Wcl", *fwr_alloclist, RF_DAG_FLAGS_NONE, RF_IO_NORMAL_PRIORITY);
177
178 /* create and initialize PDA for the region log */
179 /* RF_Malloc(*fwr_pda, sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t
180 * *)); */
181 *fwr_pda = rf_AllocPDAList(1);
182 regionOffset = log->diskOffset;
183 rf_MapLogParityLogging(raidPtr, regionID, regionOffset, &((*fwr_pda)->row), &((*fwr_pda)->col), &((*fwr_pda)->startSector));
184 (*fwr_pda)->numSector = raidPtr->numSectorsPerLog;
185
186 /* initialize DAG parameters */
187 bzero((char *) &tracerec, sizeof(tracerec));
188 (*fwr_dag_h)->tracerec = &tracerec;
189 fwr_wrNode = (*fwr_dag_h)->succedents[0]->succedents[0];
190 fwr_wrNode->params[0].p = *fwr_pda;
191 /* fwr_wrNode->params[1] = log->bufPtr; */
192 fwr_wrNode->params[2].v = 0;
193 fwr_wrNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, 0);
194
195 /* launch the dag to write the core log to disk */
196 rf_DispatchDAG(*fwr_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
197 (void *) fwr_mcpair);
198 }
199
200
201 static void
202 ReadRegionParity(
203 RF_RegionId_t regionID,
204 RF_MCPair_t * prd_mcpair,
205 caddr_t parityBuffer,
206 RF_Raid_t * raidPtr,
207 RF_DagHeader_t ** prd_dag_h,
208 RF_AllocListElem_t ** prd_alloclist,
209 RF_PhysDiskAddr_t ** prd_pda)
210 {
211 /* Initiate the read region parity from disk. Once initiated, return
212 * to the calling routine.
213 *
214 * NON-BLOCKING */
215
216 RF_AccTraceEntry_t tracerec;
217 RF_DagNode_t *prd_rdNode;
218
219 /* create DAG to read region parity from disk */
220 rf_MakeAllocList(*prd_alloclist);
221 *prd_dag_h = rf_MakeSimpleDAG(raidPtr, 1, 0, NULL, rf_DiskReadFunc, rf_DiskReadUndoFunc,
222 "Rrp", *prd_alloclist, RF_DAG_FLAGS_NONE, RF_IO_NORMAL_PRIORITY);
223
224 /* create and initialize PDA for region parity */
225 /* RF_Malloc(*prd_pda, sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t
226 * *)); */
227 *prd_pda = rf_AllocPDAList(1);
228 rf_MapRegionParity(raidPtr, regionID, &((*prd_pda)->row), &((*prd_pda)->col), &((*prd_pda)->startSector), &((*prd_pda)->numSector));
229 if (rf_parityLogDebug)
230 printf("[reading %d sectors of parity from region %d]\n",
231 (int) (*prd_pda)->numSector, regionID);
232 if ((*prd_pda)->next) {
233 (*prd_pda)->next = NULL;
234 printf("set prd_pda->next to NULL\n");
235 }
236 /* initialize DAG parameters */
237 bzero((char *) &tracerec, sizeof(tracerec));
238 (*prd_dag_h)->tracerec = &tracerec;
239 prd_rdNode = (*prd_dag_h)->succedents[0]->succedents[0];
240 prd_rdNode->params[0].p = *prd_pda;
241 prd_rdNode->params[1].p = parityBuffer;
242 prd_rdNode->params[2].v = 0;
243 prd_rdNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, 0);
244 if (rf_validateDAGDebug)
245 rf_ValidateDAG(*prd_dag_h);
246 /* launch region parity read dag */
247 rf_DispatchDAG(*prd_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
248 (void *) prd_mcpair);
249 }
250
251 static void
252 WriteRegionParity(
253 RF_RegionId_t regionID,
254 RF_MCPair_t * pwr_mcpair,
255 caddr_t parityBuffer,
256 RF_Raid_t * raidPtr,
257 RF_DagHeader_t ** pwr_dag_h,
258 RF_AllocListElem_t ** pwr_alloclist,
259 RF_PhysDiskAddr_t ** pwr_pda)
260 {
261 /* Initiate the write of region parity to disk. Once initiated, return
262 * to the calling routine.
263 *
264 * NON-BLOCKING */
265
266 RF_AccTraceEntry_t tracerec;
267 RF_DagNode_t *pwr_wrNode;
268
269 /* create DAG to write region log from disk */
270 rf_MakeAllocList(*pwr_alloclist);
271 *pwr_dag_h = rf_MakeSimpleDAG(raidPtr, 1, 0, parityBuffer, rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
272 "Wrp", *pwr_alloclist, RF_DAG_FLAGS_NONE, RF_IO_NORMAL_PRIORITY);
273
274 /* create and initialize PDA for region parity */
275 /* RF_Malloc(*pwr_pda, sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t
276 * *)); */
277 *pwr_pda = rf_AllocPDAList(1);
278 rf_MapRegionParity(raidPtr, regionID, &((*pwr_pda)->row), &((*pwr_pda)->col), &((*pwr_pda)->startSector), &((*pwr_pda)->numSector));
279
280 /* initialize DAG parameters */
281 bzero((char *) &tracerec, sizeof(tracerec));
282 (*pwr_dag_h)->tracerec = &tracerec;
283 pwr_wrNode = (*pwr_dag_h)->succedents[0]->succedents[0];
284 pwr_wrNode->params[0].p = *pwr_pda;
285 /* pwr_wrNode->params[1] = parityBuffer; */
286 pwr_wrNode->params[2].v = 0;
287 pwr_wrNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, 0);
288
289 /* launch the dag to write region parity to disk */
290 rf_DispatchDAG(*pwr_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
291 (void *) pwr_mcpair);
292 }
293
294 static void
295 FlushLogsToDisk(
296 RF_Raid_t * raidPtr,
297 RF_ParityLog_t * logList)
298 {
299 /* Flush a linked list of core logs to the log disk. Logs contain the
300 * disk location where they should be written. Logs were written in
301 * FIFO order and that order must be preserved.
302 *
303 * Recommended optimizations: 1) allow multiple flushes to occur
304 * simultaneously 2) coalesce contiguous flush operations
305 *
306 * BLOCKING */
307
308 RF_ParityLog_t *log;
309 RF_RegionId_t regionID;
310 RF_MCPair_t *fwr_mcpair;
311 RF_DagHeader_t *fwr_dag_h;
312 RF_AllocListElem_t *fwr_alloclist;
313 RF_PhysDiskAddr_t *fwr_pda;
314
315 fwr_mcpair = rf_AllocMCPair();
316 RF_LOCK_MUTEX(fwr_mcpair->mutex);
317
318 RF_ASSERT(logList);
319 log = logList;
320 while (log) {
321 regionID = log->regionID;
322
323 /* create and launch a DAG to write the core log */
324 if (rf_parityLogDebug)
325 printf("[initiating write of core log for region %d]\n", regionID);
326 fwr_mcpair->flag = RF_FALSE;
327 WriteCoreLog(log, fwr_mcpair, raidPtr, &fwr_dag_h, &fwr_alloclist, &fwr_pda);
328
329 /* wait for the DAG to complete */
330 while (!fwr_mcpair->flag)
331 RF_WAIT_COND(fwr_mcpair->cond, fwr_mcpair->mutex);
332 if (fwr_dag_h->status != rf_enable) {
333 RF_ERRORMSG1("Unable to write core log to disk (region %d)\n", regionID);
334 RF_ASSERT(0);
335 }
336 /* RF_Free(fwr_pda, sizeof(RF_PhysDiskAddr_t)); */
337 rf_FreePhysDiskAddr(fwr_pda);
338 rf_FreeDAG(fwr_dag_h);
339 rf_FreeAllocList(fwr_alloclist);
340
341 log = log->next;
342 }
343 RF_UNLOCK_MUTEX(fwr_mcpair->mutex);
344 rf_FreeMCPair(fwr_mcpair);
345 rf_ReleaseParityLogs(raidPtr, logList);
346 }
347
348 static void
349 ReintegrateRegion(
350 RF_Raid_t * raidPtr,
351 RF_RegionId_t regionID,
352 RF_ParityLog_t * coreLog)
353 {
354 RF_MCPair_t *rrd_mcpair = NULL, *prd_mcpair, *pwr_mcpair;
355 RF_DagHeader_t *rrd_dag_h, *prd_dag_h, *pwr_dag_h;
356 RF_AllocListElem_t *rrd_alloclist, *prd_alloclist, *pwr_alloclist;
357 RF_PhysDiskAddr_t *rrd_pda, *prd_pda, *pwr_pda;
358 caddr_t parityBuffer, regionBuffer = NULL;
359
360 /* Reintegrate a region (regionID). 1. acquire region and parity
361 * buffers 2. read log from disk 3. read parity from disk 4. apply log
362 * to parity 5. apply core log to parity 6. write new parity to disk
363 *
364 * BLOCKING */
365
366 if (rf_parityLogDebug)
367 printf("[reintegrating region %d]\n", regionID);
368
369 /* initiate read of region parity */
370 if (rf_parityLogDebug)
371 printf("[initiating read of parity for region %d]\n", regionID);
372 parityBuffer = AcquireReintBuffer(&raidPtr->parityBufferPool);
373 prd_mcpair = rf_AllocMCPair();
374 RF_LOCK_MUTEX(prd_mcpair->mutex);
375 prd_mcpair->flag = RF_FALSE;
376 ReadRegionParity(regionID, prd_mcpair, parityBuffer, raidPtr, &prd_dag_h, &prd_alloclist, &prd_pda);
377
378 /* if region log nonempty, initiate read */
379 if (raidPtr->regionInfo[regionID].diskCount > 0) {
380 if (rf_parityLogDebug)
381 printf("[initiating read of disk log for region %d]\n", regionID);
382 regionBuffer = AcquireReintBuffer(&raidPtr->regionBufferPool);
383 rrd_mcpair = rf_AllocMCPair();
384 RF_LOCK_MUTEX(rrd_mcpair->mutex);
385 rrd_mcpair->flag = RF_FALSE;
386 ReadRegionLog(regionID, rrd_mcpair, regionBuffer, raidPtr, &rrd_dag_h, &rrd_alloclist, &rrd_pda);
387 }
388 /* wait on read of region parity to complete */
389 while (!prd_mcpair->flag) {
390 RF_WAIT_COND(prd_mcpair->cond, prd_mcpair->mutex);
391 }
392 RF_UNLOCK_MUTEX(prd_mcpair->mutex);
393 if (prd_dag_h->status != rf_enable) {
394 RF_ERRORMSG("Unable to read parity from disk\n");
395 /* add code to fail the parity disk */
396 RF_ASSERT(0);
397 }
398 /* apply core log to parity */
399 /* if (coreLog) ApplyLogsToParity(coreLog, parityBuffer); */
400
401 if (raidPtr->regionInfo[regionID].diskCount > 0) {
402 /* wait on read of region log to complete */
403 while (!rrd_mcpair->flag)
404 RF_WAIT_COND(rrd_mcpair->cond, rrd_mcpair->mutex);
405 RF_UNLOCK_MUTEX(rrd_mcpair->mutex);
406 if (rrd_dag_h->status != rf_enable) {
407 RF_ERRORMSG("Unable to read region log from disk\n");
408 /* add code to fail the log disk */
409 RF_ASSERT(0);
410 }
411 /* apply region log to parity */
412 /* ApplyRegionToParity(regionID, regionBuffer, parityBuffer); */
413 /* release resources associated with region log */
414 /* RF_Free(rrd_pda, sizeof(RF_PhysDiskAddr_t)); */
415 rf_FreePhysDiskAddr(rrd_pda);
416 rf_FreeDAG(rrd_dag_h);
417 rf_FreeAllocList(rrd_alloclist);
418 rf_FreeMCPair(rrd_mcpair);
419 ReleaseReintBuffer(&raidPtr->regionBufferPool, regionBuffer);
420 }
421 /* write reintegrated parity to disk */
422 if (rf_parityLogDebug)
423 printf("[initiating write of parity for region %d]\n", regionID);
424 pwr_mcpair = rf_AllocMCPair();
425 RF_LOCK_MUTEX(pwr_mcpair->mutex);
426 pwr_mcpair->flag = RF_FALSE;
427 WriteRegionParity(regionID, pwr_mcpair, parityBuffer, raidPtr, &pwr_dag_h, &pwr_alloclist, &pwr_pda);
428 while (!pwr_mcpair->flag)
429 RF_WAIT_COND(pwr_mcpair->cond, pwr_mcpair->mutex);
430 RF_UNLOCK_MUTEX(pwr_mcpair->mutex);
431 if (pwr_dag_h->status != rf_enable) {
432 RF_ERRORMSG("Unable to write parity to disk\n");
433 /* add code to fail the parity disk */
434 RF_ASSERT(0);
435 }
436 /* release resources associated with read of old parity */
437 /* RF_Free(prd_pda, sizeof(RF_PhysDiskAddr_t)); */
438 rf_FreePhysDiskAddr(prd_pda);
439 rf_FreeDAG(prd_dag_h);
440 rf_FreeAllocList(prd_alloclist);
441 rf_FreeMCPair(prd_mcpair);
442
443 /* release resources associated with write of new parity */
444 ReleaseReintBuffer(&raidPtr->parityBufferPool, parityBuffer);
445 /* RF_Free(pwr_pda, sizeof(RF_PhysDiskAddr_t)); */
446 rf_FreePhysDiskAddr(pwr_pda);
447 rf_FreeDAG(pwr_dag_h);
448 rf_FreeAllocList(pwr_alloclist);
449 rf_FreeMCPair(pwr_mcpair);
450
451 if (rf_parityLogDebug)
452 printf("[finished reintegrating region %d]\n", regionID);
453 }
454
455
456
457 static void
458 ReintegrateLogs(
459 RF_Raid_t * raidPtr,
460 RF_ParityLog_t * logList)
461 {
462 RF_ParityLog_t *log, *freeLogList = NULL;
463 RF_ParityLogData_t *logData, *logDataList;
464 RF_RegionId_t regionID;
465
466 RF_ASSERT(logList);
467 while (logList) {
468 log = logList;
469 logList = logList->next;
470 log->next = NULL;
471 regionID = log->regionID;
472 ReintegrateRegion(raidPtr, regionID, log);
473 log->numRecords = 0;
474
475 /* remove all items which are blocked on reintegration of this
476 * region */
477 RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
478 logData = rf_SearchAndDequeueParityLogData(raidPtr, regionID, &raidPtr->parityLogDiskQueue.reintBlockHead, &raidPtr->parityLogDiskQueue.reintBlockTail, RF_TRUE);
479 logDataList = logData;
480 while (logData) {
481 logData->next = rf_SearchAndDequeueParityLogData(raidPtr, regionID, &raidPtr->parityLogDiskQueue.reintBlockHead, &raidPtr->parityLogDiskQueue.reintBlockTail, RF_TRUE);
482 logData = logData->next;
483 }
484 RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
485
486 /* process blocked log data and clear reintInProgress flag for
487 * this region */
488 if (logDataList)
489 rf_ParityLogAppend(logDataList, RF_TRUE, &log, RF_TRUE);
490 else {
491 /* Enable flushing for this region. Holding both
492 * locks provides a synchronization barrier with
493 * DumpParityLogToDisk */
494 RF_LOCK_MUTEX(raidPtr->regionInfo[regionID].mutex);
495 RF_LOCK_MUTEX(raidPtr->regionInfo[regionID].reintMutex);
496 RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
497 raidPtr->regionInfo[regionID].diskCount = 0;
498 raidPtr->regionInfo[regionID].reintInProgress = RF_FALSE;
499 RF_UNLOCK_MUTEX(raidPtr->regionInfo[regionID].mutex);
500 RF_UNLOCK_MUTEX(raidPtr->regionInfo[regionID].reintMutex); /* flushing is now
501 * enabled */
502 RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
503 }
504 /* if log wasn't used, attach it to the list of logs to be
505 * returned */
506 if (log) {
507 log->next = freeLogList;
508 freeLogList = log;
509 }
510 }
511 if (freeLogList)
512 rf_ReleaseParityLogs(raidPtr, freeLogList);
513 }
514
515 int
516 rf_ShutdownLogging(RF_Raid_t * raidPtr)
517 {
518 /* shutdown parity logging 1) disable parity logging in all regions 2)
519 * reintegrate all regions */
520
521 RF_SectorCount_t diskCount;
522 RF_RegionId_t regionID;
523 RF_ParityLog_t *log;
524
525 if (rf_parityLogDebug)
526 printf("[shutting down parity logging]\n");
527 /* Since parity log maps are volatile, we must reintegrate all
528 * regions. */
529 if (rf_forceParityLogReint) {
530 for (regionID = 0; regionID < rf_numParityRegions; regionID++) {
531 RF_LOCK_MUTEX(raidPtr->regionInfo[regionID].mutex);
532 raidPtr->regionInfo[regionID].loggingEnabled = RF_FALSE;
533 log = raidPtr->regionInfo[regionID].coreLog;
534 raidPtr->regionInfo[regionID].coreLog = NULL;
535 diskCount = raidPtr->regionInfo[regionID].diskCount;
536 RF_UNLOCK_MUTEX(raidPtr->regionInfo[regionID].mutex);
537 if (diskCount > 0 || log != NULL)
538 ReintegrateRegion(raidPtr, regionID, log);
539 if (log != NULL)
540 rf_ReleaseParityLogs(raidPtr, log);
541 }
542 }
543 if (rf_parityLogDebug) {
544 printf("[parity logging disabled]\n");
545 printf("[should be done!]\n");
546 }
547 return (0);
548 }
549
550 int
551 rf_ParityLoggingDiskManager(RF_Raid_t * raidPtr)
552 {
553 RF_ParityLog_t *reintQueue, *flushQueue;
554 int workNeeded, done = RF_FALSE;
555
556 /* Main program for parity logging disk thread. This routine waits
557 * for work to appear in either the flush or reintegration queues and
558 * is responsible for flushing core logs to the log disk as well as
559 * reintegrating parity regions.
560 *
561 * BLOCKING */
562
563 RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
564
565 /*
566 * Inform our creator that we're running. Don't bother doing the
567 * mutex lock/unlock dance- we locked above, and we'll unlock
568 * below with nothing to do, yet.
569 */
570 raidPtr->parityLogDiskQueue.threadState |= RF_PLOG_RUNNING;
571 RF_SIGNAL_COND(raidPtr->parityLogDiskQueue.cond);
572
573 /* empty the work queues */
574 flushQueue = raidPtr->parityLogDiskQueue.flushQueue;
575 raidPtr->parityLogDiskQueue.flushQueue = NULL;
576 reintQueue = raidPtr->parityLogDiskQueue.reintQueue;
577 raidPtr->parityLogDiskQueue.reintQueue = NULL;
578 workNeeded = (flushQueue || reintQueue);
579
580 while (!done) {
581 while (workNeeded) {
582 /* First, flush all logs in the flush queue, freeing
583 * buffers Second, reintegrate all regions which are
584 * reported as full. Third, append queued log data
585 * until blocked.
586 *
587 * Note: Incoming appends (ParityLogAppend) can block on
588 * either 1. empty buffer pool 2. region under
589 * reintegration To preserve a global FIFO ordering of
590 * appends, buffers are not released to the world
591 * until those appends blocked on buffers are removed
592 * from the append queue. Similarly, regions which
593 * are reintegrated are not opened for general use
594 * until the append queue has been emptied. */
595
596 RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
597
598 /* empty flushQueue, using free'd log buffers to
599 * process bufTail */
600 if (flushQueue)
601 FlushLogsToDisk(raidPtr, flushQueue);
602
603 /* empty reintQueue, flushing from reintTail as we go */
604 if (reintQueue)
605 ReintegrateLogs(raidPtr, reintQueue);
606
607 RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
608 flushQueue = raidPtr->parityLogDiskQueue.flushQueue;
609 raidPtr->parityLogDiskQueue.flushQueue = NULL;
610 reintQueue = raidPtr->parityLogDiskQueue.reintQueue;
611 raidPtr->parityLogDiskQueue.reintQueue = NULL;
612 workNeeded = (flushQueue || reintQueue);
613 }
614 /* no work is needed at this point */
615 if (raidPtr->parityLogDiskQueue.threadState & RF_PLOG_TERMINATE) {
616 /* shutdown parity logging 1. disable parity logging
617 * in all regions 2. reintegrate all regions */
618 done = RF_TRUE; /* thread disabled, no work needed */
619 RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
620 rf_ShutdownLogging(raidPtr);
621 }
622 if (!done) {
623 /* thread enabled, no work needed, so sleep */
624 if (rf_parityLogDebug)
625 printf("[parity logging disk manager sleeping]\n");
626 RF_WAIT_COND(raidPtr->parityLogDiskQueue.cond, raidPtr->parityLogDiskQueue.mutex);
627 if (rf_parityLogDebug)
628 printf("[parity logging disk manager just woke up]\n");
629 flushQueue = raidPtr->parityLogDiskQueue.flushQueue;
630 raidPtr->parityLogDiskQueue.flushQueue = NULL;
631 reintQueue = raidPtr->parityLogDiskQueue.reintQueue;
632 raidPtr->parityLogDiskQueue.reintQueue = NULL;
633 workNeeded = (flushQueue || reintQueue);
634 }
635 }
636 /*
637 * Announce that we're done.
638 */
639 RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
640 raidPtr->parityLogDiskQueue.threadState |= RF_PLOG_SHUTDOWN;
641 RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
642 RF_SIGNAL_COND(raidPtr->parityLogDiskQueue.cond);
643
644 /*
645 * In the NetBSD kernel, the thread must exit; returning would
646 * cause the proc trampoline to attempt to return to userspace.
647 */
648 kthread_exit(0); /* does not return */
649 }
650 #endif /* RF_INCLUDE_PARITYLOGGING > 0 */
651