int rf_State_Map(RF_RaidAccessDesc_t *desc) { RF_Raid_t *raidPtr = desc->raidPtr; RF_AccTraceEntry_t *tracerec = &desc->tracerec; RF_Etimer_t timer; RF_ETIMER_START(timer); if (!(desc->asmap = rf_MapAccess(raidPtr, desc->raidAddress, desc->numBlocks, desc->bufPtr, RF_DONT_REMAP))) RF_PANIC(); RF_ETIMER_STOP(timer); RF_ETIMER_EVAL(timer); tracerec->specific.user.map_us = RF_ETIMER_VAL_US(timer); desc->state++; return RF_FALSE; }
int rf_SelectAlgorithm(RF_RaidAccessDesc_t *desc, RF_RaidAccessFlags_t flags) { RF_AccessStripeMapHeader_t *asm_h = desc->asmap; RF_IoType_t type = desc->type; RF_Raid_t *raidPtr = desc->raidPtr; void *bp = desc->bp; RF_AccessStripeMap_t *asmap = asm_h->stripeMap; RF_AccessStripeMap_t *asm_p; RF_DagHeader_t *dag_h = NULL, *tempdag_h, *lastdag_h; int i, j, k; RF_VoidFuncPtr *stripeFuncs, normalStripeFuncs[MAXNSTRIPES]; RF_AccessStripeMap_t *asm_up, *asm_bp; RF_AccessStripeMapHeader_t ***asmh_u, *endASMList; RF_AccessStripeMapHeader_t ***asmh_b; RF_VoidFuncPtr **stripeUnitFuncs, uFunc; RF_VoidFuncPtr **blockFuncs, bFunc; int numStripesBailed = 0, cantCreateDAGs = RF_FALSE; int numStripeUnitsBailed = 0; int stripeNum, numUnitDags = 0, stripeUnitNum, numBlockDags = 0; RF_StripeNum_t numStripeUnits; RF_SectorNum_t numBlocks; RF_RaidAddr_t address; int length; RF_PhysDiskAddr_t *physPtr; caddr_t buffer; lastdag_h = NULL; asmh_u = asmh_b = NULL; stripeUnitFuncs = NULL; blockFuncs = NULL; /* * Get an array of dag-function creation pointers. * Try to avoid calling malloc. */ if (asm_h->numStripes <= MAXNSTRIPES) stripeFuncs = normalStripeFuncs; else RF_Calloc(stripeFuncs, asm_h->numStripes, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr *)); /* * Walk through the asm list once collecting information. * Attempt to find a single creation function for each stripe. */ desc->numStripes = 0; for (i = 0, asm_p = asmap; asm_p; asm_p = asm_p->next, i++) { desc->numStripes++; (raidPtr->Layout.map->SelectionFunc) (raidPtr, type, asm_p, &stripeFuncs[i]); /* Check to see if we found a creation func for this stripe. */ if (stripeFuncs[i] == (RF_VoidFuncPtr) NULL) { /* * Could not find creation function for entire stripe. * So, let's see if we can find one for each stripe * unit in the stripe. */ if (numStripesBailed == 0) { /* * One stripe map header for each stripe we * bail on. */ RF_Malloc(asmh_u, sizeof(RF_AccessStripeMapHeader_t **) * asm_h->numStripes, (RF_AccessStripeMapHeader_t ***)); /* * Create an array of ptrs to arrays of * stripeFuncs. */ RF_Calloc(stripeUnitFuncs, asm_h->numStripes, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr **)); } /* * Create an array of creation funcs (called * stripeFuncs) for this stripe. */ numStripeUnits = asm_p->numStripeUnitsAccessed; RF_Calloc(stripeUnitFuncs[numStripesBailed], numStripeUnits, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr *)); RF_Malloc(asmh_u[numStripesBailed], numStripeUnits * sizeof(RF_AccessStripeMapHeader_t *), (RF_AccessStripeMapHeader_t **)); /* Lookup array of stripeUnitFuncs for this stripe. */ for (j = 0, physPtr = asm_p->physInfo; physPtr; physPtr = physPtr->next, j++) { /* * Remap for series of single stripe-unit * accesses. */ address = physPtr->raidAddress; length = physPtr->numSector; buffer = physPtr->bufPtr; asmh_u[numStripesBailed][j] = rf_MapAccess(raidPtr, address, length, buffer, RF_DONT_REMAP); asm_up = asmh_u[numStripesBailed][j]->stripeMap; /* * Get the creation func for this * stripe unit. */ (raidPtr->Layout.map->SelectionFunc) (raidPtr, type, asm_up, &(stripeUnitFuncs[numStripesBailed][j])); /* * Check to see if we found a creation func * for this stripe unit. */ if (stripeUnitFuncs[numStripesBailed][j] == (RF_VoidFuncPtr) NULL) { /* * Could not find creation function * for stripe unit. So, let's see if * we can find one for each block in * the stripe unit. */ if (numStripeUnitsBailed == 0) { /* * one stripe map header for * each stripe unit we bail on. */ RF_Malloc(asmh_b, sizeof(RF_AccessStripeMapHeader_t **) * asm_h->numStripes * raidPtr->Layout.numDataCol, (RF_AccessStripeMapHeader_t ***)); /* * Create an array of ptrs to * arrays of blockFuncs. */ RF_Calloc(blockFuncs, asm_h->numStripes * raidPtr->Layout.numDataCol, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr **)); } /* * Create an array of creation funcs * (called blockFuncs) for this stripe * unit. */ numBlocks = physPtr->numSector; numBlockDags += numBlocks; RF_Calloc( blockFuncs[numStripeUnitsBailed], numBlocks, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr *)); RF_Malloc(asmh_b[numStripeUnitsBailed], numBlocks * sizeof(RF_AccessStripeMapHeader_t *), (RF_AccessStripeMapHeader_t **)); /* * Lookup array of blockFuncs for this * stripe unit. */ for (k = 0; k < numBlocks; k++) { /* * Remap for series of single * stripe-unit accesses. */ address = physPtr->raidAddress + k; length = 1; buffer = physPtr->bufPtr + (k * (1 << raidPtr->logBytesPerSector)); asmh_b[numStripeUnitsBailed][k] = rf_MapAccess(raidPtr, address, length, buffer, RF_DONT_REMAP); asm_bp = asmh_b[numStripeUnitsBailed][k]->stripeMap; /* * Get the creation func for * this stripe unit. */ (raidPtr->Layout.map-> SelectionFunc) (raidPtr, type, asm_bp, &(blockFuncs[numStripeUnitsBailed][k])); /* * Check to see if we found a * creation func for this * stripe unit. */ if (blockFuncs [numStripeUnitsBailed][k] == NULL) cantCreateDAGs = RF_TRUE; } numStripeUnitsBailed++; } else { numUnitDags++; } }