At (closer to) 80-columns, this may actually be readable code.

This commit is contained in:
oster 2000-01-09 04:35:13 +00:00
parent 636b65bec8
commit 2c4bbb1b26
1 changed files with 240 additions and 115 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rf_paritylogging.c,v 1.7 2000/01/09 03:28:11 oster Exp $ */
/* $NetBSD: rf_paritylogging.c,v 1.8 2000/01/09 04:35:13 oster Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
* All rights reserved.
@ -93,7 +93,9 @@ rf_ConfigureParityLogging(
raidPtr->numSectorsPerLog = RF_DEFAULT_NUM_SECTORS_PER_LOG;
/* create a parity logging configuration structure */
RF_MallocAndAdd(info, sizeof(RF_ParityLoggingConfigInfo_t), (RF_ParityLoggingConfigInfo_t *), raidPtr->cleanupList);
RF_MallocAndAdd(info, sizeof(RF_ParityLoggingConfigInfo_t),
(RF_ParityLoggingConfigInfo_t *),
raidPtr->cleanupList);
if (info == NULL)
return (ENOMEM);
layoutPtr->layoutSpecificInfo = (void *) info;
@ -102,14 +104,17 @@ rf_ConfigureParityLogging(
/* the stripe identifier must identify the disks in each stripe, IN
* THE ORDER THAT THEY APPEAR IN THE STRIPE. */
info->stripeIdentifier = rf_make_2d_array((raidPtr->numCol), (raidPtr->numCol), raidPtr->cleanupList);
info->stripeIdentifier = rf_make_2d_array((raidPtr->numCol),
(raidPtr->numCol),
raidPtr->cleanupList);
if (info->stripeIdentifier == NULL)
return (ENOMEM);
startdisk = 0;
for (i = 0; i < (raidPtr->numCol); i++) {
for (j = 0; j < (raidPtr->numCol); j++) {
info->stripeIdentifier[i][j] = (startdisk + j) % (raidPtr->numCol - 1);
info->stripeIdentifier[i][j] = (startdisk + j) %
(raidPtr->numCol - 1);
}
if ((--startdisk) < 0)
startdisk = raidPtr->numCol - 1 - 1;
@ -117,15 +122,20 @@ rf_ConfigureParityLogging(
/* fill in the remaining layout parameters */
layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit <<
raidPtr->logBytesPerSector;
layoutPtr->numParityCol = 1;
layoutPtr->numParityLogCol = 1;
layoutPtr->numDataCol = raidPtr->numCol - layoutPtr->numParityCol - layoutPtr->numParityLogCol;
layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
layoutPtr->numDataCol = raidPtr->numCol - layoutPtr->numParityCol -
layoutPtr->numParityLogCol;
layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol *
layoutPtr->sectorsPerStripeUnit;
layoutPtr->dataStripeUnitsPerDisk = layoutPtr->stripeUnitsPerDisk;
raidPtr->sectorsPerDisk = layoutPtr->stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit;
raidPtr->sectorsPerDisk = layoutPtr->stripeUnitsPerDisk *
layoutPtr->sectorsPerStripeUnit;
raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk *
layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
/* configure parity log parameters
*
@ -160,37 +170,51 @@ rf_ConfigureParityLogging(
fragmentation = raidPtr->regionLogCapacity % raidPtr->numSectorsPerLog;
if (fragmentation > 0)
for (i = 1; i < (raidPtr->numSectorsPerLog / 2); i++) {
if (((totalLogCapacity / (rf_numParityRegions + i)) % raidPtr->numSectorsPerLog) < fragmentation) {
if (((totalLogCapacity / (rf_numParityRegions + i)) %
raidPtr->numSectorsPerLog) < fragmentation) {
rf_numParityRegions++;
raidPtr->regionLogCapacity = totalLogCapacity / rf_numParityRegions;
fragmentation = raidPtr->regionLogCapacity % raidPtr->numSectorsPerLog;
raidPtr->regionLogCapacity = totalLogCapacity /
rf_numParityRegions;
fragmentation = raidPtr->regionLogCapacity %
raidPtr->numSectorsPerLog;
}
if (((totalLogCapacity / (rf_numParityRegions - i)) % raidPtr->numSectorsPerLog) < fragmentation) {
if (((totalLogCapacity / (rf_numParityRegions - i)) %
raidPtr->numSectorsPerLog) < fragmentation) {
rf_numParityRegions--;
raidPtr->regionLogCapacity = totalLogCapacity / rf_numParityRegions;
fragmentation = raidPtr->regionLogCapacity % raidPtr->numSectorsPerLog;
raidPtr->regionLogCapacity = totalLogCapacity /
rf_numParityRegions;
fragmentation = raidPtr->regionLogCapacity %
raidPtr->numSectorsPerLog;
}
}
/* ensure integral number of regions per log */
raidPtr->regionLogCapacity = (raidPtr->regionLogCapacity / raidPtr->numSectorsPerLog) * raidPtr->numSectorsPerLog;
raidPtr->regionLogCapacity = (raidPtr->regionLogCapacity /
raidPtr->numSectorsPerLog) *
raidPtr->numSectorsPerLog;
raidPtr->numParityLogs = rf_totalInCoreLogCapacity / (raidPtr->bytesPerSector * raidPtr->numSectorsPerLog);
raidPtr->numParityLogs = rf_totalInCoreLogCapacity /
(raidPtr->bytesPerSector * raidPtr->numSectorsPerLog);
/* to avoid deadlock, must ensure that enough logs exist for each
* region to have one simultaneously */
if (raidPtr->numParityLogs < rf_numParityRegions)
raidPtr->numParityLogs = rf_numParityRegions;
/* create region information structs */
RF_Malloc(raidPtr->regionInfo, (rf_numParityRegions * sizeof(RF_RegionInfo_t)), (RF_RegionInfo_t *));
RF_Malloc(raidPtr->regionInfo,
(rf_numParityRegions * sizeof(RF_RegionInfo_t)),
(RF_RegionInfo_t *));
if (raidPtr->regionInfo == NULL)
return (ENOMEM);
/* last region may not be full capacity */
lastRegionCapacity = raidPtr->regionLogCapacity;
while ((rf_numParityRegions - 1) * raidPtr->regionLogCapacity + lastRegionCapacity > totalLogCapacity)
lastRegionCapacity = lastRegionCapacity - raidPtr->numSectorsPerLog;
while ((rf_numParityRegions - 1) * raidPtr->regionLogCapacity +
lastRegionCapacity > totalLogCapacity)
lastRegionCapacity = lastRegionCapacity -
raidPtr->numSectorsPerLog;
raidPtr->regionParityRange = raidPtr->sectorsPerDisk / rf_numParityRegions;
raidPtr->regionParityRange = raidPtr->sectorsPerDisk /
rf_numParityRegions;
maxRegionParityRange = raidPtr->regionParityRange;
/* i can't remember why this line is in the code -wvcii 6/30/95 */
@ -198,30 +222,43 @@ rf_ConfigureParityLogging(
regionParityRange++; */
/* build pool of unused parity logs */
RF_Malloc(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector, (caddr_t));
RF_Malloc(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs *
raidPtr->numSectorsPerLog * raidPtr->bytesPerSector,
(caddr_t));
if (raidPtr->parityLogBufferHeap == NULL)
return (ENOMEM);
lHeapPtr = raidPtr->parityLogBufferHeap;
rc = rf_mutex_init(&raidPtr->parityLogPool.mutex);
if (rc) {
RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
__LINE__, rc);
RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n",
__FILE__, __LINE__, rc);
RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs *
raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
return (ENOMEM);
}
for (i = 0; i < raidPtr->numParityLogs; i++) {
if (i == 0) {
RF_Calloc(raidPtr->parityLogPool.parityLogs, 1, sizeof(RF_ParityLog_t), (RF_ParityLog_t *));
RF_Calloc(raidPtr->parityLogPool.parityLogs, 1,
sizeof(RF_ParityLog_t), (RF_ParityLog_t *));
if (raidPtr->parityLogPool.parityLogs == NULL) {
RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
RF_Free(raidPtr->parityLogBufferHeap,
raidPtr->numParityLogs *
raidPtr->numSectorsPerLog *
raidPtr->bytesPerSector);
return (ENOMEM);
}
l = raidPtr->parityLogPool.parityLogs;
} else {
RF_Calloc(l->next, 1, sizeof(RF_ParityLog_t), (RF_ParityLog_t *));
RF_Calloc(l->next, 1, sizeof(RF_ParityLog_t),
(RF_ParityLog_t *));
if (l->next == NULL) {
RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
for (l = raidPtr->parityLogPool.parityLogs; l; l = next) {
RF_Free(raidPtr->parityLogBufferHeap,
raidPtr->numParityLogs *
raidPtr->numSectorsPerLog *
raidPtr->bytesPerSector);
for (l = raidPtr->parityLogPool.parityLogs;
l;
l = next) {
next = l->next;
if (l->records)
RF_Free(l->records, (raidPtr->numSectorsPerLog * sizeof(RF_ParityLogRecord_t)));
@ -232,14 +269,24 @@ rf_ConfigureParityLogging(
l = l->next;
}
l->bufPtr = lHeapPtr;
lHeapPtr += raidPtr->numSectorsPerLog * raidPtr->bytesPerSector;
RF_Malloc(l->records, (raidPtr->numSectorsPerLog * sizeof(RF_ParityLogRecord_t)), (RF_ParityLogRecord_t *));
lHeapPtr += raidPtr->numSectorsPerLog *
raidPtr->bytesPerSector;
RF_Malloc(l->records, (raidPtr->numSectorsPerLog *
sizeof(RF_ParityLogRecord_t)),
(RF_ParityLogRecord_t *));
if (l->records == NULL) {
RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
for (l = raidPtr->parityLogPool.parityLogs; l; l = next) {
RF_Free(raidPtr->parityLogBufferHeap,
raidPtr->numParityLogs *
raidPtr->numSectorsPerLog *
raidPtr->bytesPerSector);
for (l = raidPtr->parityLogPool.parityLogs;
l;
l = next) {
next = l->next;
if (l->records)
RF_Free(l->records, (raidPtr->numSectorsPerLog * sizeof(RF_ParityLogRecord_t)));
RF_Free(l->records,
(raidPtr->numSectorsPerLog *
sizeof(RF_ParityLogRecord_t)));
RF_Free(l, sizeof(RF_ParityLog_t));
}
return (ENOMEM);
@ -255,46 +302,60 @@ rf_ConfigureParityLogging(
/* build pool of region buffers */
rc = rf_mutex_init(&raidPtr->regionBufferPool.mutex);
if (rc) {
RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
__LINE__, rc);
RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n",
__FILE__, __LINE__, rc);
return (ENOMEM);
}
rc = rf_cond_init(&raidPtr->regionBufferPool.cond);
if (rc) {
RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n", __FILE__,
__LINE__, rc);
RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n",
__FILE__, __LINE__, rc);
rf_mutex_destroy(&raidPtr->regionBufferPool.mutex);
return (ENOMEM);
}
raidPtr->regionBufferPool.bufferSize = raidPtr->regionLogCapacity * raidPtr->bytesPerSector;
printf("regionBufferPool.bufferSize %d\n", raidPtr->regionBufferPool.bufferSize);
raidPtr->regionBufferPool.totalBuffers = 1; /* for now, only one
* region at a time may
* be reintegrated */
raidPtr->regionBufferPool.availableBuffers = raidPtr->regionBufferPool.totalBuffers;
raidPtr->regionBufferPool.bufferSize = raidPtr->regionLogCapacity *
raidPtr->bytesPerSector;
printf("regionBufferPool.bufferSize %d\n",
raidPtr->regionBufferPool.bufferSize);
/* for now, only one region at a time may be reintegrated */
raidPtr->regionBufferPool.totalBuffers = 1;
raidPtr->regionBufferPool.availableBuffers =
raidPtr->regionBufferPool.totalBuffers;
raidPtr->regionBufferPool.availBuffersIndex = 0;
raidPtr->regionBufferPool.emptyBuffersIndex = 0;
RF_Malloc(raidPtr->regionBufferPool.buffers, raidPtr->regionBufferPool.totalBuffers * sizeof(caddr_t), (caddr_t *));
RF_Malloc(raidPtr->regionBufferPool.buffers,
raidPtr->regionBufferPool.totalBuffers * sizeof(caddr_t),
(caddr_t *));
if (raidPtr->regionBufferPool.buffers == NULL) {
rf_mutex_destroy(&raidPtr->regionBufferPool.mutex);
rf_cond_destroy(&raidPtr->regionBufferPool.cond);
return (ENOMEM);
}
for (i = 0; i < raidPtr->regionBufferPool.totalBuffers; i++) {
RF_Malloc(raidPtr->regionBufferPool.buffers[i], raidPtr->regionBufferPool.bufferSize * sizeof(char), (caddr_t));
RF_Malloc(raidPtr->regionBufferPool.buffers[i],
raidPtr->regionBufferPool.bufferSize * sizeof(char),
(caddr_t));
if (raidPtr->regionBufferPool.buffers[i] == NULL) {
rf_mutex_destroy(&raidPtr->regionBufferPool.mutex);
rf_cond_destroy(&raidPtr->regionBufferPool.cond);
for (j = 0; j < i; j++) {
RF_Free(raidPtr->regionBufferPool.buffers[i], raidPtr->regionBufferPool.bufferSize * sizeof(char));
RF_Free(raidPtr->regionBufferPool.buffers[i],
raidPtr->regionBufferPool.bufferSize *
sizeof(char));
}
RF_Free(raidPtr->regionBufferPool.buffers, raidPtr->regionBufferPool.totalBuffers * sizeof(caddr_t));
RF_Free(raidPtr->regionBufferPool.buffers,
raidPtr->regionBufferPool.totalBuffers *
sizeof(caddr_t));
return (ENOMEM);
}
printf("raidPtr->regionBufferPool.buffers[%d] = %lx\n", i,
(long) raidPtr->regionBufferPool.buffers[i]);
}
rc = rf_ShutdownCreate(listp, rf_ShutdownParityLoggingRegionBufferPool, raidPtr);
rc = rf_ShutdownCreate(listp,
rf_ShutdownParityLoggingRegionBufferPool,
raidPtr);
if (rc) {
RF_ERRORMSG3("Unable to create shutdown entry file %s line %d rc=%d\n", __FILE__,
__LINE__, rc);
@ -305,46 +366,60 @@ rf_ConfigureParityLogging(
parityBufferCapacity = maxRegionParityRange;
rc = rf_mutex_init(&raidPtr->parityBufferPool.mutex);
if (rc) {
RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
__LINE__, rc);
RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n",
__FILE__, __LINE__, rc);
return (rc);
}
rc = rf_cond_init(&raidPtr->parityBufferPool.cond);
if (rc) {
RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n", __FILE__,
__LINE__, rc);
RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n",
__FILE__, __LINE__, rc);
rf_mutex_destroy(&raidPtr->parityBufferPool.mutex);
return (ENOMEM);
}
raidPtr->parityBufferPool.bufferSize = parityBufferCapacity * raidPtr->bytesPerSector;
printf("parityBufferPool.bufferSize %d\n", raidPtr->parityBufferPool.bufferSize);
raidPtr->parityBufferPool.totalBuffers = 1; /* for now, only one
* region at a time may
* be reintegrated */
raidPtr->parityBufferPool.availableBuffers = raidPtr->parityBufferPool.totalBuffers;
raidPtr->parityBufferPool.bufferSize = parityBufferCapacity *
raidPtr->bytesPerSector;
printf("parityBufferPool.bufferSize %d\n",
raidPtr->parityBufferPool.bufferSize);
/* for now, only one region at a time may be reintegrated */
raidPtr->parityBufferPool.totalBuffers = 1;
raidPtr->parityBufferPool.availableBuffers =
raidPtr->parityBufferPool.totalBuffers;
raidPtr->parityBufferPool.availBuffersIndex = 0;
raidPtr->parityBufferPool.emptyBuffersIndex = 0;
RF_Malloc(raidPtr->parityBufferPool.buffers, raidPtr->parityBufferPool.totalBuffers * sizeof(caddr_t), (caddr_t *));
RF_Malloc(raidPtr->parityBufferPool.buffers,
raidPtr->parityBufferPool.totalBuffers * sizeof(caddr_t),
(caddr_t *));
if (raidPtr->parityBufferPool.buffers == NULL) {
rf_mutex_destroy(&raidPtr->parityBufferPool.mutex);
rf_cond_destroy(&raidPtr->parityBufferPool.cond);
return (ENOMEM);
}
for (i = 0; i < raidPtr->parityBufferPool.totalBuffers; i++) {
RF_Malloc(raidPtr->parityBufferPool.buffers[i], raidPtr->parityBufferPool.bufferSize * sizeof(char), (caddr_t));
RF_Malloc(raidPtr->parityBufferPool.buffers[i],
raidPtr->parityBufferPool.bufferSize * sizeof(char),
(caddr_t));
if (raidPtr->parityBufferPool.buffers == NULL) {
rf_mutex_destroy(&raidPtr->parityBufferPool.mutex);
rf_cond_destroy(&raidPtr->parityBufferPool.cond);
for (j = 0; j < i; j++) {
RF_Free(raidPtr->parityBufferPool.buffers[i], raidPtr->regionBufferPool.bufferSize * sizeof(char));
RF_Free(raidPtr->parityBufferPool.buffers[i],
raidPtr->regionBufferPool.bufferSize *
sizeof(char));
}
RF_Free(raidPtr->parityBufferPool.buffers, raidPtr->regionBufferPool.totalBuffers * sizeof(caddr_t));
RF_Free(raidPtr->parityBufferPool.buffers,
raidPtr->regionBufferPool.totalBuffers *
sizeof(caddr_t));
return (ENOMEM);
}
printf("parityBufferPool.buffers[%d] = %lx\n", i,
(long) raidPtr->parityBufferPool.buffers[i]);
}
rc = rf_ShutdownCreate(listp, rf_ShutdownParityLoggingParityBufferPool, raidPtr);
rc = rf_ShutdownCreate(listp,
rf_ShutdownParityLoggingParityBufferPool,
raidPtr);
if (rc) {
RF_ERRORMSG3("Unable to create shutdown entry file %s line %d rc=%d\n", __FILE__,
__LINE__, rc);
@ -352,16 +427,17 @@ rf_ConfigureParityLogging(
return (rc);
}
/* initialize parityLogDiskQueue */
rc = rf_create_managed_mutex(listp, &raidPtr->parityLogDiskQueue.mutex);
rc = rf_create_managed_mutex(listp,
&raidPtr->parityLogDiskQueue.mutex);
if (rc) {
RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
__LINE__, rc);
RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n",
__FILE__, __LINE__, rc);
return (rc);
}
rc = rf_create_managed_cond(listp, &raidPtr->parityLogDiskQueue.cond);
if (rc) {
RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n", __FILE__,
__LINE__, rc);
RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n",
__FILE__, __LINE__, rc);
return (rc);
}
raidPtr->parityLogDiskQueue.flushQueue = NULL;
@ -377,7 +453,9 @@ rf_ConfigureParityLogging(
raidPtr->parityLogDiskQueue.freeDataList = NULL;
raidPtr->parityLogDiskQueue.freeCommonList = NULL;
rc = rf_ShutdownCreate(listp, rf_ShutdownParityLoggingDiskQueue, raidPtr);
rc = rf_ShutdownCreate(listp,
rf_ShutdownParityLoggingDiskQueue,
raidPtr);
if (rc) {
RF_ERRORMSG3("Unable to create shutdown entry file %s line %d rc=%d\n", __FILE__,
__LINE__, rc);
@ -390,7 +468,9 @@ rf_ConfigureParityLogging(
__LINE__, rc);
for (j = 0; j < i; j++)
FreeRegionInfo(raidPtr, j);
RF_Free(raidPtr->regionInfo, (rf_numParityRegions * sizeof(RF_RegionInfo_t)));
RF_Free(raidPtr->regionInfo,
(rf_numParityRegions *
sizeof(RF_RegionInfo_t)));
return (ENOMEM);
}
rc = rf_mutex_init(&raidPtr->regionInfo[i].reintMutex);
@ -400,37 +480,59 @@ rf_ConfigureParityLogging(
rf_mutex_destroy(&raidPtr->regionInfo[i].mutex);
for (j = 0; j < i; j++)
FreeRegionInfo(raidPtr, j);
RF_Free(raidPtr->regionInfo, (rf_numParityRegions * sizeof(RF_RegionInfo_t)));
RF_Free(raidPtr->regionInfo,
(rf_numParityRegions *
sizeof(RF_RegionInfo_t)));
return (ENOMEM);
}
raidPtr->regionInfo[i].reintInProgress = RF_FALSE;
raidPtr->regionInfo[i].regionStartAddr = raidPtr->regionLogCapacity * i;
raidPtr->regionInfo[i].parityStartAddr = raidPtr->regionParityRange * i;
raidPtr->regionInfo[i].regionStartAddr =
raidPtr->regionLogCapacity * i;
raidPtr->regionInfo[i].parityStartAddr =
raidPtr->regionParityRange * i;
if (i < rf_numParityRegions - 1) {
raidPtr->regionInfo[i].capacity = raidPtr->regionLogCapacity;
raidPtr->regionInfo[i].numSectorsParity = raidPtr->regionParityRange;
raidPtr->regionInfo[i].capacity =
raidPtr->regionLogCapacity;
raidPtr->regionInfo[i].numSectorsParity =
raidPtr->regionParityRange;
} else {
raidPtr->regionInfo[i].capacity = lastRegionCapacity;
raidPtr->regionInfo[i].numSectorsParity = raidPtr->sectorsPerDisk - raidPtr->regionParityRange * i;
if (raidPtr->regionInfo[i].numSectorsParity > maxRegionParityRange)
maxRegionParityRange = raidPtr->regionInfo[i].numSectorsParity;
raidPtr->regionInfo[i].capacity =
lastRegionCapacity;
raidPtr->regionInfo[i].numSectorsParity =
raidPtr->sectorsPerDisk -
raidPtr->regionParityRange * i;
if (raidPtr->regionInfo[i].numSectorsParity >
maxRegionParityRange)
maxRegionParityRange =
raidPtr->regionInfo[i].numSectorsParity;
}
raidPtr->regionInfo[i].diskCount = 0;
RF_ASSERT(raidPtr->regionInfo[i].capacity + raidPtr->regionInfo[i].regionStartAddr <= totalLogCapacity);
RF_ASSERT(raidPtr->regionInfo[i].parityStartAddr + raidPtr->regionInfo[i].numSectorsParity <= raidPtr->sectorsPerDisk);
RF_Malloc(raidPtr->regionInfo[i].diskMap, (raidPtr->regionInfo[i].capacity * sizeof(RF_DiskMap_t)), (RF_DiskMap_t *));
RF_ASSERT(raidPtr->regionInfo[i].capacity +
raidPtr->regionInfo[i].regionStartAddr <=
totalLogCapacity);
RF_ASSERT(raidPtr->regionInfo[i].parityStartAddr +
raidPtr->regionInfo[i].numSectorsParity <=
raidPtr->sectorsPerDisk);
RF_Malloc(raidPtr->regionInfo[i].diskMap,
(raidPtr->regionInfo[i].capacity *
sizeof(RF_DiskMap_t)),
(RF_DiskMap_t *));
if (raidPtr->regionInfo[i].diskMap == NULL) {
rf_mutex_destroy(&raidPtr->regionInfo[i].mutex);
rf_mutex_destroy(&raidPtr->regionInfo[i].reintMutex);
for (j = 0; j < i; j++)
FreeRegionInfo(raidPtr, j);
RF_Free(raidPtr->regionInfo, (rf_numParityRegions * sizeof(RF_RegionInfo_t)));
RF_Free(raidPtr->regionInfo,
(rf_numParityRegions *
sizeof(RF_RegionInfo_t)));
return (ENOMEM);
}
raidPtr->regionInfo[i].loggingEnabled = RF_FALSE;
raidPtr->regionInfo[i].coreLog = NULL;
}
rc = rf_ShutdownCreate(listp, rf_ShutdownParityLoggingRegionInfo, raidPtr);
rc = rf_ShutdownCreate(listp,
rf_ShutdownParityLoggingRegionInfo,
raidPtr);
if (rc) {
RF_ERRORMSG3("Unable to create shutdown entry file %s line %d rc=%d\n", __FILE__,
__LINE__, rc);
@ -439,7 +541,8 @@ rf_ConfigureParityLogging(
}
RF_ASSERT(raidPtr->parityLogDiskQueue.threadState == 0);
raidPtr->parityLogDiskQueue.threadState = RF_PLOG_CREATED;
rc = RF_CREATE_THREAD(raidPtr->pLogDiskThreadHandle, rf_ParityLoggingDiskManager, raidPtr,"rf_log");
rc = RF_CREATE_THREAD(raidPtr->pLogDiskThreadHandle,
rf_ParityLoggingDiskManager, raidPtr,"rf_log");
if (rc) {
raidPtr->parityLogDiskQueue.threadState = 0;
RF_ERRORMSG3("Unable to create parity logging disk thread file %s line %d rc=%d\n",
@ -449,7 +552,8 @@ rf_ConfigureParityLogging(
/* wait for thread to start */
RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
while (!(raidPtr->parityLogDiskQueue.threadState & RF_PLOG_RUNNING)) {
RF_WAIT_COND(raidPtr->parityLogDiskQueue.cond, raidPtr->parityLogDiskQueue.mutex);
RF_WAIT_COND(raidPtr->parityLogDiskQueue.cond,
raidPtr->parityLogDiskQueue.mutex);
}
RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
@ -480,9 +584,12 @@ FreeRegionInfo(
RF_RegionId_t regionID)
{
RF_LOCK_MUTEX(raidPtr->regionInfo[regionID].mutex);
RF_Free(raidPtr->regionInfo[regionID].diskMap, (raidPtr->regionInfo[regionID].capacity * sizeof(RF_DiskMap_t)));
RF_Free(raidPtr->regionInfo[regionID].diskMap,
(raidPtr->regionInfo[regionID].capacity *
sizeof(RF_DiskMap_t)));
if (!rf_forceParityLogReint && raidPtr->regionInfo[regionID].coreLog) {
rf_ReleaseParityLogs(raidPtr, raidPtr->regionInfo[regionID].coreLog);
rf_ReleaseParityLogs(raidPtr,
raidPtr->regionInfo[regionID].coreLog);
raidPtr->regionInfo[regionID].coreLog = NULL;
} else {
RF_ASSERT(raidPtr->regionInfo[regionID].coreLog == NULL);
@ -506,7 +613,8 @@ FreeParityLogQueue(
while (l1) {
l2 = l1;
l1 = l2->next;
RF_Free(l2->records, (raidPtr->numSectorsPerLog * sizeof(RF_ParityLogRecord_t)));
RF_Free(l2->records, (raidPtr->numSectorsPerLog *
sizeof(RF_ParityLogRecord_t)));
RF_Free(l2, sizeof(RF_ParityLog_t));
}
RF_UNLOCK_MUTEX(queue->mutex);
@ -545,7 +653,8 @@ rf_ShutdownParityLoggingRegionInfo(RF_ThreadArg_t arg)
/* free region information structs */
for (i = 0; i < rf_numParityRegions; i++)
FreeRegionInfo(raidPtr, i);
RF_Free(raidPtr->regionInfo, (rf_numParityRegions * sizeof(raidPtr->regionInfo)));
RF_Free(raidPtr->regionInfo, (rf_numParityRegions *
sizeof(raidPtr->regionInfo)));
raidPtr->regionInfo = NULL;
}
@ -560,7 +669,8 @@ rf_ShutdownParityLoggingPool(RF_ThreadArg_t arg)
}
/* free contents of parityLogPool */
FreeParityLogQueue(raidPtr, &raidPtr->parityLogPool);
RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs *
raidPtr->numSectorsPerLog * raidPtr->bytesPerSector);
}
static void
@ -608,13 +718,15 @@ rf_ShutdownParityLoggingDiskQueue(RF_ThreadArg_t arg)
RF_ASSERT(raidPtr->parityLogDiskQueue.reintTail == NULL);
while (raidPtr->parityLogDiskQueue.freeDataList) {
d = raidPtr->parityLogDiskQueue.freeDataList;
raidPtr->parityLogDiskQueue.freeDataList = raidPtr->parityLogDiskQueue.freeDataList->next;
raidPtr->parityLogDiskQueue.freeDataList =
raidPtr->parityLogDiskQueue.freeDataList->next;
RF_Free(d, sizeof(RF_ParityLogData_t));
}
while (raidPtr->parityLogDiskQueue.freeCommonList) {
c = raidPtr->parityLogDiskQueue.freeCommonList;
rf_mutex_destroy(&c->mutex);
raidPtr->parityLogDiskQueue.freeCommonList = raidPtr->parityLogDiskQueue.freeCommonList->next;
raidPtr->parityLogDiskQueue.freeCommonList =
raidPtr->parityLogDiskQueue.freeCommonList->next;
RF_Free(c, sizeof(RF_CommonLogData_t));
}
}
@ -643,7 +755,8 @@ rf_ShutdownParityLogging(RF_ThreadArg_t arg)
*/
RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
while (!(raidPtr->parityLogDiskQueue.threadState & RF_PLOG_SHUTDOWN)) {
RF_WAIT_COND(raidPtr->parityLogDiskQueue.cond, raidPtr->parityLogDiskQueue.mutex);
RF_WAIT_COND(raidPtr->parityLogDiskQueue.cond,
raidPtr->parityLogDiskQueue.mutex);
}
RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);
if (rf_parityLogDebug) {
@ -677,7 +790,8 @@ rf_MapRegionIDParityLogging(
regionID--;
}
RF_ASSERT(address >= raidPtr->regionInfo[regionID].parityStartAddr);
RF_ASSERT(address < raidPtr->regionInfo[regionID].parityStartAddr + raidPtr->regionInfo[regionID].numSectorsParity);
RF_ASSERT(address < raidPtr->regionInfo[regionID].parityStartAddr +
raidPtr->regionInfo[regionID].numSectorsParity);
RF_ASSERT(regionID < rf_numParityRegions);
return (regionID);
}
@ -693,12 +807,14 @@ rf_MapSectorParityLogging(
RF_SectorNum_t * diskSector,
int remap)
{
RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
RF_StripeNum_t SUID = raidSector /
raidPtr->Layout.sectorsPerStripeUnit;
*row = 0;
/* *col = (SUID % (raidPtr->numCol -
* raidPtr->Layout.numParityLogCol)); */
*col = SUID % raidPtr->Layout.numDataCol;
*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
*diskSector = (SUID / (raidPtr->Layout.numDataCol)) *
raidPtr->Layout.sectorsPerStripeUnit +
(raidSector % raidPtr->Layout.sectorsPerStripeUnit);
}
@ -713,14 +829,16 @@ rf_MapParityParityLogging(
RF_SectorNum_t * diskSector,
int remap)
{
RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
RF_StripeNum_t SUID = raidSector /
raidPtr->Layout.sectorsPerStripeUnit;
*row = 0;
/* *col =
* raidPtr->Layout.numDataCol-(SUID/raidPtr->Layout.numDataCol)%(raidPt
* r->numCol - raidPtr->Layout.numParityLogCol); */
*col = raidPtr->Layout.numDataCol;
*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
*diskSector = (SUID / (raidPtr->Layout.numDataCol)) *
raidPtr->Layout.sectorsPerStripeUnit +
(raidSector % raidPtr->Layout.sectorsPerStripeUnit);
}
@ -741,7 +859,8 @@ rf_MapLogParityLogging(
}
/* given a regionID, determine the physical disk address of the logged parity for that region */
/* given a regionID, determine the physical disk address of the logged
parity for that region */
void
rf_MapRegionParity(
RF_Raid_t * raidPtr,
@ -758,7 +877,8 @@ rf_MapRegionParity(
}
/* given a logical RAID address, determine the participating disks in the stripe */
/* given a logical RAID address, determine the participating disks in
the stripe */
void
rf_IdentifyStripeParityLogging(
RF_Raid_t * raidPtr,
@ -766,8 +886,10 @@ rf_IdentifyStripeParityLogging(
RF_RowCol_t ** diskids,
RF_RowCol_t * outRow)
{
RF_StripeNum_t stripeID = rf_RaidAddressToStripeID(&raidPtr->Layout, addr);
RF_ParityLoggingConfigInfo_t *info = (RF_ParityLoggingConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
RF_StripeNum_t stripeID = rf_RaidAddressToStripeID(&raidPtr->Layout,
addr);
RF_ParityLoggingConfigInfo_t *info = (RF_ParityLoggingConfigInfo_t *)
raidPtr->Layout.layoutSpecificInfo;
*outRow = 0;
*diskids = info->stripeIdentifier[stripeID % raidPtr->numCol];
}
@ -825,8 +947,9 @@ rf_ParityLoggingDagSelect(
if (prior_recon) {
RF_RowCol_t or = failedPDA->row, oc = failedPDA->col;
RF_SectorNum_t oo = failedPDA->startSector;
if (layoutPtr->map->flags & RF_DISTRIBUTE_SPARE) { /* redirect to dist
* spare space */
if (layoutPtr->map->flags &
RF_DISTRIBUTE_SPARE) {
/* redirect to dist spare space */
if (failedPDA == asmp->parityInfo) {
@ -857,8 +980,8 @@ rf_ParityLoggingDagSelect(
}
} else { /* redirect to dedicated spare
* space */
} else {
/* redirect to dedicated spare space */
failedPDA->row = raidPtr->Disks[frow][fcol].spareRow;
failedPDA->col = raidPtr->Disks[frow][fcol].spareCol;
@ -871,8 +994,7 @@ rf_ParityLoggingDagSelect(
failedPDA->next->row = failedPDA->row;
failedPDA->next->col = failedPDA->col;
} else
if (failedPDA == asmp->parityInfo->next) { /* paranoid: should
* never occur */
if (failedPDA == asmp->parityInfo->next) { /* paranoid: should never occur */
asmp->parityInfo->row = failedPDA->row;
asmp->parityInfo->col = failedPDA->col;
}
@ -907,8 +1029,11 @@ rf_ParityLoggingDagSelect(
* when G is 3 or 4, numDataCol/2 is 1, and I want
* single-stripe-unit updates to use just one disk. */
if ((asmp->numDataFailed + asmp->numParityFailed) == 0) {
if (((asmp->numStripeUnitsAccessed <= (layoutPtr->numDataCol / 2)) && (layoutPtr->numDataCol != 1)) ||
(asmp->parityInfo->next != NULL) || rf_CheckStripeForFailures(raidPtr, asmp)) {
if (((asmp->numStripeUnitsAccessed <=
(layoutPtr->numDataCol / 2)) &&
(layoutPtr->numDataCol != 1)) ||
(asmp->parityInfo->next != NULL) ||
rf_CheckStripeForFailures(raidPtr, asmp)) {
*createFunc = (RF_VoidFuncPtr) rf_CreateParityLoggingSmallWriteDAG;
} else
*createFunc = (RF_VoidFuncPtr) rf_CreateParityLoggingLargeWriteDAG;