void rf_applyPDA(RF_Raid_t *raidPtr, RF_PhysDiskAddr_t *pda, RF_PhysDiskAddr_t *ppda, RF_PhysDiskAddr_t *qpda, void *bp) { RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout); RF_RaidAddr_t s0off = rf_StripeUnitOffset(layoutPtr, ppda->startSector); RF_SectorCount_t s0len = ppda->numSector, len; RF_SectorNum_t suoffset; unsigned coeff; char *pbuf = ppda->bufPtr; char *qbuf = qpda->bufPtr; char *buf; int delta; suoffset = rf_StripeUnitOffset(layoutPtr, pda->startSector); len = pda->numSector; /* See if pda intersects a recovery pda. */ if ((suoffset < s0off + s0len) && (suoffset + len > s0off)) { buf = pda->bufPtr; coeff = rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), pda->raidAddress); coeff = (coeff % raidPtr->Layout.numDataCol); if (suoffset < s0off) { delta = s0off - suoffset; buf += rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), delta); suoffset = s0off; len -= delta; } if (suoffset > s0off) { delta = suoffset - s0off; pbuf += rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), delta); qbuf += rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), delta); } if ((suoffset + len) > (s0len + s0off)) len = s0len + s0off - suoffset; /* Src, dest, len. */ rf_bxor(buf, pbuf, rf_RaidAddressToByte(raidPtr, len), bp); /* Dest, src, len, coeff. */ rf_IncQ((unsigned long *) qbuf, (unsigned long *) buf, rf_RaidAddressToByte(raidPtr, len), coeff); } }
/* returns an array of ints identifying the disks that comprise the stripe containing the indicated address. * the caller must _never_ attempt to modify this array. */ void rf_IdentifyStripeDeclustered(RF_Raid_t *raidPtr, RF_RaidAddr_t addr, RF_RowCol_t **diskids) { RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout); RF_DeclusteredConfigInfo_t *info = (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo; RF_StripeCount_t sus_per_fulltable = info->SUsPerFullTable; RF_StripeCount_t fulltable_depth = info->FullTableDepthInPUs * layoutPtr->SUsPerPU; RF_StripeNum_t base_suid = 0; RF_StripeNum_t SUID = rf_RaidAddressToStripeUnitID(layoutPtr, addr); RF_StripeNum_t stripeID, FullTableID; int tableOffset; rf_decluster_adjust_params(layoutPtr, &SUID, &sus_per_fulltable, &fulltable_depth, &base_suid); FullTableID = SUID / sus_per_fulltable; /* fulltable ID within array * (across rows) */ stripeID = rf_StripeUnitIDToStripeID(layoutPtr, SUID); /* find stripe offset * into array */ tableOffset = (stripeID % info->BlocksPerTable); /* find offset into * block design table */ *diskids = info->LayoutTable[tableOffset]; }
int rf_PQWriteDoubleRecoveryFunc(RF_DagNode_t *node) { /* * The situation: * * We are doing a write that hits only one failed data unit. The other * failed data unit is not being overwritten, so we need to generate * it. * * For the moment, we assume all the nonfailed data being written is in * the shadow of the failed data unit. (i.e., either a single data * unit write or the entire failed stripe unit is being overwritten.) * * Recovery strategy: apply the recovery data to the parity and Q. * Use P & Q to recover the second failed data unit in P. Zero fill * Q, then apply the recovered data to P. Then apply the data being * written to the failed drive. Then walk through the surviving drives, * applying new data when it exists, othewise the recovery data. * Quite a mess. * * * The params: * * read pda0, read pda1, ..., read pda (numDataCol-3), * write pda0, ..., write pda (numStripeUnitAccess - numDataFailed), * failed pda, raidPtr, asmap */ int np = node->numParams; RF_AccessStripeMap_t *asmap = (RF_AccessStripeMap_t *) node->params[np - 1].p; RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[np - 2].p; RF_RaidLayout_t *layoutPtr = (RF_RaidLayout_t *) & (raidPtr->Layout); int i; RF_RaidAddr_t sosAddr; unsigned coeff; RF_StripeCount_t secPerSU = layoutPtr->sectorsPerStripeUnit; RF_PhysDiskAddr_t *ppda, *qpda, *pda, npda; int numDataCol = layoutPtr->numDataCol; RF_Etimer_t timer; RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec; RF_ASSERT(node->numResults == 2); RF_ASSERT(asmap->failedPDAs[1] == NULL); RF_ETIMER_START(timer); ppda = node->results[0]; qpda = node->results[1]; /* apply the recovery data */ for (i = 0; i < numDataCol - 2; i++) rf_applyPDA(raidPtr, node->params[i].p, ppda, qpda, node->dagHdr->bp); /* Determine the other failed data unit. */ pda = asmap->failedPDAs[0]; sosAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, asmap->raidAddress); /* Need to determine the column of the other failed disk. */ coeff = rf_RaidAddressToStripeUnitID(layoutPtr, pda->raidAddress); /* Compute the data unit offset within the column. */ coeff = (coeff % raidPtr->Layout.numDataCol); for (i = 0; i < numDataCol; i++) { npda.raidAddress = sosAddr + (i * secPerSU); (raidPtr->Layout.map->MapSector) (raidPtr, npda.raidAddress, &(npda.row), &(npda.col), &(npda.startSector), 0); /* Skip over dead disks. */ if (RF_DEAD_DISK(raidPtr->Disks[npda.row][npda.col].status)) if (i != coeff) break; } RF_ASSERT(i < numDataCol); /* * Recover the data. The column we want to recover, we write over the * parity. The column we don't care about, we dump in q. */ if (coeff < i) /* Recovering 'a'. */ rf_PQ_recover((unsigned long *) ppda->bufPtr, (unsigned long *) qpda->bufPtr, (unsigned long *) ppda->bufPtr, (unsigned long *) qpda->bufPtr, rf_RaidAddressToByte(raidPtr, pda->numSector), coeff, i); else /* Recovering 'b'. */ rf_PQ_recover((unsigned long *) ppda->bufPtr, (unsigned long *) qpda->bufPtr, (unsigned long *) qpda->bufPtr, (unsigned long *) ppda->bufPtr, rf_RaidAddressToByte(raidPtr, pda->numSector), i, coeff); /* OK. The valid data is in P. Zero fill Q, then inc it into it. */ bzero(qpda->bufPtr, rf_RaidAddressToByte(raidPtr, qpda->numSector)); rf_IncQ((unsigned long *) qpda->bufPtr, (unsigned long *) ppda->bufPtr, rf_RaidAddressToByte(raidPtr, qpda->numSector), i); /* Now apply all the write data to the buffer. */ /* * Single stripe unit write case: The failed data is the only thing * we are writing. */ RF_ASSERT(asmap->numStripeUnitsAccessed == 1); /* Dest, src, len, coeff. */ rf_IncQ((unsigned long *) qpda->bufPtr, (unsigned long *) asmap->failedPDAs[0]->bufPtr, rf_RaidAddressToByte(raidPtr, qpda->numSector), coeff); rf_bxor(asmap->failedPDAs[0]->bufPtr, ppda->bufPtr, rf_RaidAddressToByte(raidPtr, ppda->numSector), node->dagHdr->bp); /* Now apply all the recovery data. */ for (i = 0; i < numDataCol - 2; i++) rf_applyPDA(raidPtr, node->params[i].p, ppda, qpda, node->dagHdr->bp); RF_ETIMER_STOP(timer); RF_ETIMER_EVAL(timer); if (tracerec) tracerec->q_us += RF_ETIMER_VAL_US(timer); rf_GenericWakeupFunc(node, 0); return (0); }
int rf_PQDoubleRecoveryFunc(RF_DagNode_t *node) { int np = node->numParams; RF_AccessStripeMap_t *asmap = (RF_AccessStripeMap_t *) node->params[np - 1].p; RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[np - 2].p; RF_RaidLayout_t *layoutPtr = (RF_RaidLayout_t *) & (raidPtr->Layout); int d, i; unsigned coeff; RF_RaidAddr_t sosAddr, suoffset; RF_SectorCount_t len, secPerSU = layoutPtr->sectorsPerStripeUnit; int two = 0; RF_PhysDiskAddr_t *ppda, *ppda2, *qpda, *qpda2, *pda, npda; char *buf; int numDataCol = layoutPtr->numDataCol; RF_Etimer_t timer; RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec; RF_ETIMER_START(timer); if (asmap->failedPDAs[1] && (asmap->failedPDAs[1]->numSector + asmap->failedPDAs[0]->numSector < secPerSU)) { RF_ASSERT(0); ppda = node->params[np - 6].p; ppda2 = node->params[np - 5].p; qpda = node->params[np - 4].p; qpda2 = node->params[np - 3].p; d = (np - 6); two = 1; } else { ppda = node->params[np - 4].p; qpda = node->params[np - 3].p; d = (np - 4); } for (i = 0; i < d; i++) { pda = node->params[i].p; buf = pda->bufPtr; suoffset = rf_StripeUnitOffset(layoutPtr, pda->startSector); len = pda->numSector; coeff = rf_RaidAddressToStripeUnitID(layoutPtr, pda->raidAddress); /* Compute the data unit offset within the column. */ coeff = (coeff % raidPtr->Layout.numDataCol); /* See if pda intersects a recovery pda. */ rf_applyPDA(raidPtr, pda, ppda, qpda, node->dagHdr->bp); if (two) rf_applyPDA(raidPtr, pda, ppda, qpda, node->dagHdr->bp); } /* * Ok, we got the parity back to the point where we can recover. We * now need to determine the coeff of the columns that need to be * recovered. We can also only need to recover a single stripe unit. */ if (asmap->failedPDAs[1] == NULL) { /* * Only a single stripe unit * to recover. */ pda = asmap->failedPDAs[0]; sosAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, asmap->raidAddress); /* Need to determine the column of the other failed disk. */ coeff = rf_RaidAddressToStripeUnitID(layoutPtr, pda->raidAddress); /* Compute the data unit offset within the column. */ coeff = (coeff % raidPtr->Layout.numDataCol); for (i = 0; i < numDataCol; i++) { npda.raidAddress = sosAddr + (i * secPerSU); (raidPtr->Layout.map->MapSector) (raidPtr, npda.raidAddress, &(npda.row), &(npda.col), &(npda.startSector), 0); /* Skip over dead disks. */ if (RF_DEAD_DISK(raidPtr->Disks[npda.row][npda.col] .status)) if (i != coeff) break; } RF_ASSERT(i < numDataCol); RF_ASSERT(two == 0); /* * Recover the data. Since we need only to recover one * column, we overwrite the parity with the other one. */ if (coeff < i) /* Recovering 'a'. */ rf_PQ_recover((unsigned long *) ppda->bufPtr, (unsigned long *) qpda->bufPtr, (unsigned long *) pda->bufPtr, (unsigned long *) ppda->bufPtr, rf_RaidAddressToByte(raidPtr, pda->numSector), coeff, i); else /* Recovering 'b'. */ rf_PQ_recover((unsigned long *) ppda->bufPtr, (unsigned long *) qpda->bufPtr, (unsigned long *) ppda->bufPtr, (unsigned long *) pda->bufPtr, rf_RaidAddressToByte(raidPtr, pda->numSector), i, coeff); } else RF_PANIC(); RF_ETIMER_STOP(timer); RF_ETIMER_EVAL(timer); if (tracerec) tracerec->q_us += RF_ETIMER_VAL_US(timer); rf_GenericWakeupFunc(node, 0); return (0); }