2001-06-19 07:25:16 +04:00
|
|
|
/* $NetBSD: rf_pq.c,v 1.8 2001/06/19 03:25:16 oster Exp $ */
|
1998-11-13 07:20:26 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Daniel Stodolsky
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Code for RAID level 6 (P + Q) disk array architecture.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rf_archs.h"
|
2001-06-19 07:25:16 +04:00
|
|
|
|
|
|
|
#if (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0) || (RF_INCLUDE_EVENODD > 0)
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
#include "rf_types.h"
|
|
|
|
#include "rf_raid.h"
|
|
|
|
#include "rf_dag.h"
|
|
|
|
#include "rf_dagffrd.h"
|
|
|
|
#include "rf_dagffwr.h"
|
|
|
|
#include "rf_dagdegrd.h"
|
|
|
|
#include "rf_dagdegwr.h"
|
|
|
|
#include "rf_dagutils.h"
|
|
|
|
#include "rf_dagfuncs.h"
|
|
|
|
#include "rf_etimer.h"
|
|
|
|
#include "rf_pqdeg.h"
|
|
|
|
#include "rf_general.h"
|
|
|
|
#include "rf_map.h"
|
|
|
|
#include "rf_pq.h"
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_RedFuncs_t rf_pFuncs = {rf_RegularONPFunc, "Regular Old-New P", rf_SimpleONPFunc, "Simple Old-New P"};
|
|
|
|
RF_RedFuncs_t rf_pRecoveryFuncs = {rf_RecoveryPFunc, "Recovery P Func", rf_RecoveryPFunc, "Recovery P Func"};
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_RegularONPFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
return (rf_RegularXorFunc(node));
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
/*
|
1999-02-05 03:06:06 +03:00
|
|
|
same as simpleONQ func, but the coefficient is always 1
|
1998-11-13 07:20:26 +03:00
|
|
|
*/
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_SimpleONPFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
return (rf_SimpleXorFunc(node));
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_RecoveryPFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
return (rf_RecoveryXorFunc(node));
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_RegularPFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
return (rf_RegularXorFunc(node));
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
2001-06-19 07:25:16 +04:00
|
|
|
#endif /* (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0) || (RF_INCLUDE_EVENODD > 0) */
|
1998-11-13 07:20:26 +03:00
|
|
|
#if (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0)
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
static void
|
|
|
|
QDelta(char *dest, char *obuf, char *nbuf, unsigned length,
|
|
|
|
unsigned char coeff);
|
|
|
|
static void
|
|
|
|
rf_InvertQ(unsigned long *qbuf, unsigned long *abuf,
|
|
|
|
unsigned length, unsigned coeff);
|
|
|
|
|
|
|
|
RF_RedFuncs_t rf_qFuncs = {rf_RegularONQFunc, "Regular Old-New Q", rf_SimpleONQFunc, "Simple Old-New Q"};
|
|
|
|
RF_RedFuncs_t rf_qRecoveryFuncs = {rf_RecoveryQFunc, "Recovery Q Func", rf_RecoveryQFunc, "Recovery Q Func"};
|
|
|
|
RF_RedFuncs_t rf_pqRecoveryFuncs = {rf_RecoveryPQFunc, "Recovery PQ Func", rf_RecoveryPQFunc, "Recovery PQ Func"};
|
|
|
|
|
|
|
|
void
|
|
|
|
rf_PQDagSelect(
|
|
|
|
RF_Raid_t * raidPtr,
|
|
|
|
RF_IoType_t type,
|
|
|
|
RF_AccessStripeMap_t * asmap,
|
|
|
|
RF_VoidFuncPtr * createFunc)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
|
|
|
|
unsigned ndfail = asmap->numDataFailed;
|
|
|
|
unsigned npfail = asmap->numParityFailed;
|
|
|
|
unsigned ntfail = npfail + ndfail;
|
|
|
|
|
|
|
|
RF_ASSERT(RF_IO_IS_R_OR_W(type));
|
|
|
|
if (ntfail > 2) {
|
|
|
|
RF_ERRORMSG("more than two disks failed in a single group! Aborting I/O operation.\n");
|
|
|
|
/* *infoFunc = */ *createFunc = NULL;
|
|
|
|
return;
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
/* ok, we can do this I/O */
|
|
|
|
if (type == RF_IO_TYPE_READ) {
|
|
|
|
switch (ndfail) {
|
|
|
|
case 0:
|
|
|
|
/* fault free read */
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_CreateFaultFreeReadDAG; /* same as raid 5 */
|
1999-02-05 03:06:06 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* lost a single data unit */
|
|
|
|
/* two cases: (1) parity is not lost. do a normal raid
|
|
|
|
* 5 reconstruct read. (2) parity is lost. do a
|
|
|
|
* reconstruct read using "q". */
|
|
|
|
if (ntfail == 2) { /* also lost redundancy */
|
|
|
|
if (asmap->failedPDAs[1]->type == RF_PDA_TYPE_PARITY)
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_110_CreateReadDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
else
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_101_CreateReadDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
} else {
|
|
|
|
/* P and Q are ok. But is there a failure in
|
|
|
|
* some unaccessed data unit? */
|
|
|
|
if (rf_NumFailedDataUnitsInStripe(raidPtr, asmap) == 2)
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_200_CreateReadDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
else
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_100_CreateReadDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* lost two data units */
|
|
|
|
/* *infoFunc = PQOneTwo; */
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_200_CreateReadDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
/* a write */
|
|
|
|
switch (ntfail) {
|
|
|
|
case 0: /* fault free */
|
|
|
|
if (rf_suppressLocksAndLargeWrites ||
|
|
|
|
(((asmap->numStripeUnitsAccessed <= (layoutPtr->numDataCol / 2)) && (layoutPtr->numDataCol != 1)) ||
|
|
|
|
(asmap->parityInfo->next != NULL) || (asmap->qInfo->next != NULL) || rf_CheckStripeForFailures(raidPtr, asmap))) {
|
|
|
|
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQCreateSmallWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
} else {
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQCreateLargeWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* single disk fault */
|
|
|
|
if (npfail == 1) {
|
|
|
|
RF_ASSERT((asmap->failedPDAs[0]->type == RF_PDA_TYPE_PARITY) || (asmap->failedPDAs[0]->type == RF_PDA_TYPE_Q));
|
|
|
|
if (asmap->failedPDAs[0]->type == RF_PDA_TYPE_Q) { /* q died, treat like
|
|
|
|
* normal mode raid5
|
|
|
|
* write. */
|
|
|
|
if (((asmap->numStripeUnitsAccessed <= (layoutPtr->numDataCol / 2)) || (asmap->numStripeUnitsAccessed == 1))
|
|
|
|
|| rf_NumFailedDataUnitsInStripe(raidPtr, asmap))
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_001_CreateSmallWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
else
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_001_CreateLargeWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
} else {/* parity died, small write only updating Q */
|
|
|
|
if (((asmap->numStripeUnitsAccessed <= (layoutPtr->numDataCol / 2)) || (asmap->numStripeUnitsAccessed == 1))
|
|
|
|
|| rf_NumFailedDataUnitsInStripe(raidPtr, asmap))
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_010_CreateSmallWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
else
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_010_CreateLargeWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
|
|
|
} else { /* data missing. Do a P reconstruct write if
|
|
|
|
* only a single data unit is lost in the
|
|
|
|
* stripe, otherwise a PQ reconstruct write. */
|
|
|
|
if (rf_NumFailedDataUnitsInStripe(raidPtr, asmap) == 2)
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_200_CreateWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
else
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_100_CreateWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* two disk faults */
|
|
|
|
switch (npfail) {
|
|
|
|
case 2: /* both p and q dead */
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_011_CreateWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
break;
|
|
|
|
case 1: /* either p or q and dead data */
|
|
|
|
RF_ASSERT(asmap->failedPDAs[0]->type == RF_PDA_TYPE_DATA);
|
|
|
|
RF_ASSERT((asmap->failedPDAs[1]->type == RF_PDA_TYPE_PARITY) || (asmap->failedPDAs[1]->type == RF_PDA_TYPE_Q));
|
|
|
|
if (asmap->failedPDAs[1]->type == RF_PDA_TYPE_Q)
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_101_CreateWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
else
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_110_CreateWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
break;
|
|
|
|
case 0: /* double data loss */
|
1999-08-15 06:36:40 +04:00
|
|
|
*createFunc = (RF_VoidFuncPtr) rf_PQ_200_CreateWriteDAG;
|
1999-02-05 03:06:06 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* more than 2 disk faults */
|
|
|
|
*createFunc = NULL;
|
|
|
|
RF_PANIC();
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
return;
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
/*
|
1999-02-05 03:06:06 +03:00
|
|
|
Used as a stop gap info function
|
1998-11-13 07:20:26 +03:00
|
|
|
*/
|
1999-08-15 06:36:40 +04:00
|
|
|
#if 0
|
1999-02-05 03:06:06 +03:00
|
|
|
static void
|
|
|
|
PQOne(raidPtr, nSucc, nAnte, asmap)
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
int *nSucc;
|
|
|
|
int *nAnte;
|
|
|
|
RF_AccessStripeMap_t *asmap;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
*nSucc = *nAnte = 1;
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
static void
|
|
|
|
PQOneTwo(raidPtr, nSucc, nAnte, asmap)
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
int *nSucc;
|
|
|
|
int *nAnte;
|
|
|
|
RF_AccessStripeMap_t *asmap;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
*nSucc = 1;
|
|
|
|
*nAnte = 2;
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-08-15 06:36:40 +04:00
|
|
|
#endif
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
RF_CREATE_DAG_FUNC_DECL(rf_PQCreateLargeWriteDAG)
|
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
rf_CommonCreateLargeWriteDAG(raidPtr, asmap, dag_h, bp, flags, allocList, 2,
|
|
|
|
rf_RegularPQFunc, RF_FALSE);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_RegularONQFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int np = node->numParams;
|
|
|
|
int d;
|
|
|
|
RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[np - 1].p;
|
|
|
|
int i;
|
|
|
|
RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
|
|
|
|
RF_Etimer_t timer;
|
|
|
|
char *qbuf, *qpbuf;
|
|
|
|
char *obuf, *nbuf;
|
|
|
|
RF_PhysDiskAddr_t *old, *new;
|
|
|
|
unsigned long coeff;
|
|
|
|
unsigned secPerSU = raidPtr->Layout.sectorsPerStripeUnit;
|
|
|
|
|
|
|
|
RF_ETIMER_START(timer);
|
|
|
|
|
|
|
|
d = (np - 3) / 4;
|
|
|
|
RF_ASSERT(4 * d + 3 == np);
|
|
|
|
qbuf = (char *) node->params[2 * d + 1].p; /* q buffer */
|
|
|
|
for (i = 0; i < d; i++) {
|
|
|
|
old = (RF_PhysDiskAddr_t *) node->params[2 * i].p;
|
|
|
|
obuf = (char *) node->params[2 * i + 1].p;
|
|
|
|
new = (RF_PhysDiskAddr_t *) node->params[2 * (d + 1 + i)].p;
|
|
|
|
nbuf = (char *) node->params[2 * (d + 1 + i) + 1].p;
|
|
|
|
RF_ASSERT(new->numSector == old->numSector);
|
|
|
|
RF_ASSERT(new->raidAddress == old->raidAddress);
|
|
|
|
/* the stripe unit within the stripe tells us the coefficient
|
|
|
|
* to use for the multiply. */
|
|
|
|
coeff = rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), new->raidAddress);
|
|
|
|
/* compute the data unit offset within the column, then add
|
|
|
|
* one */
|
|
|
|
coeff = (coeff % raidPtr->Layout.numDataCol);
|
|
|
|
qpbuf = qbuf + rf_RaidAddressToByte(raidPtr, old->startSector % secPerSU);
|
|
|
|
QDelta(qpbuf, obuf, nbuf, rf_RaidAddressToByte(raidPtr, old->numSector), coeff);
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_ETIMER_STOP(timer);
|
|
|
|
RF_ETIMER_EVAL(timer);
|
|
|
|
tracerec->q_us += RF_ETIMER_VAL_US(timer);
|
|
|
|
rf_GenericWakeupFunc(node, 0); /* call wake func explicitly since no
|
|
|
|
* I/O in this node */
|
|
|
|
return (0);
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
/*
|
|
|
|
See the SimpleXORFunc for the difference between a simple and regular func.
|
1999-02-05 03:06:06 +03:00
|
|
|
These Q functions should be used for
|
|
|
|
|
|
|
|
new q = Q(data,old data,old q)
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
style updates and not for
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
q = ( new data, new data, .... )
|
|
|
|
|
|
|
|
computations.
|
|
|
|
|
|
|
|
The simple q takes 2(2d+1)+1 params, where d is the number
|
|
|
|
of stripes written. The order of params is
|
|
|
|
old data pda_0, old data buffer_0, old data pda_1, old data buffer_1, ... old data pda_d, old data buffer_d
|
|
|
|
[2d] old q pda_0, old q buffer
|
|
|
|
[2d_2] new data pda_0, new data buffer_0, ... new data pda_d, new data buffer_d
|
|
|
|
raidPtr
|
|
|
|
*/
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_SimpleONQFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int np = node->numParams;
|
|
|
|
int d;
|
|
|
|
RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[np - 1].p;
|
|
|
|
int i;
|
|
|
|
RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
|
|
|
|
RF_Etimer_t timer;
|
|
|
|
char *qbuf;
|
|
|
|
char *obuf, *nbuf;
|
|
|
|
RF_PhysDiskAddr_t *old, *new;
|
|
|
|
unsigned long coeff;
|
|
|
|
|
|
|
|
RF_ETIMER_START(timer);
|
|
|
|
|
|
|
|
d = (np - 3) / 4;
|
|
|
|
RF_ASSERT(4 * d + 3 == np);
|
|
|
|
qbuf = (char *) node->params[2 * d + 1].p; /* q buffer */
|
|
|
|
for (i = 0; i < d; i++) {
|
|
|
|
old = (RF_PhysDiskAddr_t *) node->params[2 * i].p;
|
|
|
|
obuf = (char *) node->params[2 * i + 1].p;
|
|
|
|
new = (RF_PhysDiskAddr_t *) node->params[2 * (d + 1 + i)].p;
|
|
|
|
nbuf = (char *) node->params[2 * (d + 1 + i) + 1].p;
|
|
|
|
RF_ASSERT(new->numSector == old->numSector);
|
|
|
|
RF_ASSERT(new->raidAddress == old->raidAddress);
|
|
|
|
/* the stripe unit within the stripe tells us the coefficient
|
|
|
|
* to use for the multiply. */
|
|
|
|
coeff = rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), new->raidAddress);
|
|
|
|
/* compute the data unit offset within the column, then add
|
|
|
|
* one */
|
|
|
|
coeff = (coeff % raidPtr->Layout.numDataCol);
|
|
|
|
QDelta(qbuf, obuf, nbuf, rf_RaidAddressToByte(raidPtr, old->numSector), coeff);
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_ETIMER_STOP(timer);
|
|
|
|
RF_ETIMER_EVAL(timer);
|
|
|
|
tracerec->q_us += RF_ETIMER_VAL_US(timer);
|
|
|
|
rf_GenericWakeupFunc(node, 0); /* call wake func explicitly since no
|
|
|
|
* I/O in this node */
|
|
|
|
return (0);
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
RF_CREATE_DAG_FUNC_DECL(rf_PQCreateSmallWriteDAG)
|
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
rf_CommonCreateSmallWriteDAG(raidPtr, asmap, dag_h, bp, flags, allocList, &rf_pFuncs, &rf_qFuncs);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
1999-08-15 06:36:40 +04:00
|
|
|
static void RegularQSubr(RF_DagNode_t *node, char *qbuf);
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
static void
|
|
|
|
RegularQSubr(node, qbuf)
|
|
|
|
RF_DagNode_t *node;
|
|
|
|
char *qbuf;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int np = node->numParams;
|
|
|
|
int d;
|
|
|
|
RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[np - 1].p;
|
|
|
|
unsigned secPerSU = raidPtr->Layout.sectorsPerStripeUnit;
|
|
|
|
int i;
|
|
|
|
RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
|
|
|
|
RF_Etimer_t timer;
|
|
|
|
char *obuf, *qpbuf;
|
|
|
|
RF_PhysDiskAddr_t *old;
|
|
|
|
unsigned long coeff;
|
|
|
|
|
|
|
|
RF_ETIMER_START(timer);
|
|
|
|
|
|
|
|
d = (np - 1) / 2;
|
|
|
|
RF_ASSERT(2 * d + 1 == np);
|
|
|
|
for (i = 0; i < d; i++) {
|
|
|
|
old = (RF_PhysDiskAddr_t *) node->params[2 * i].p;
|
|
|
|
obuf = (char *) node->params[2 * i + 1].p;
|
|
|
|
coeff = rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), old->raidAddress);
|
|
|
|
/* compute the data unit offset within the column, then add
|
|
|
|
* one */
|
|
|
|
coeff = (coeff % raidPtr->Layout.numDataCol);
|
|
|
|
/* the input buffers may not all be aligned with the start of
|
|
|
|
* the stripe. so shift by their sector offset within the
|
|
|
|
* stripe unit */
|
|
|
|
qpbuf = qbuf + rf_RaidAddressToByte(raidPtr, old->startSector % secPerSU);
|
|
|
|
rf_IncQ((unsigned long *) qpbuf, (unsigned long *) obuf, rf_RaidAddressToByte(raidPtr, old->numSector), coeff);
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_ETIMER_STOP(timer);
|
|
|
|
RF_ETIMER_EVAL(timer);
|
|
|
|
tracerec->q_us += RF_ETIMER_VAL_US(timer);
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
/*
|
|
|
|
used in degraded writes.
|
|
|
|
*/
|
|
|
|
|
1999-08-15 06:36:40 +04:00
|
|
|
static void DegrQSubr(RF_DagNode_t *node);
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
static void
|
|
|
|
DegrQSubr(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int np = node->numParams;
|
|
|
|
int d;
|
|
|
|
RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[np - 1].p;
|
|
|
|
unsigned secPerSU = raidPtr->Layout.sectorsPerStripeUnit;
|
|
|
|
int i;
|
|
|
|
RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
|
|
|
|
RF_Etimer_t timer;
|
|
|
|
char *qbuf = node->results[1];
|
|
|
|
char *obuf, *qpbuf;
|
|
|
|
RF_PhysDiskAddr_t *old;
|
|
|
|
unsigned long coeff;
|
|
|
|
unsigned fail_start;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
old = (RF_PhysDiskAddr_t *) node->params[np - 2].p;
|
|
|
|
fail_start = old->startSector % secPerSU;
|
|
|
|
|
|
|
|
RF_ETIMER_START(timer);
|
|
|
|
|
|
|
|
d = (np - 2) / 2;
|
|
|
|
RF_ASSERT(2 * d + 2 == np);
|
|
|
|
for (i = 0; i < d; i++) {
|
|
|
|
old = (RF_PhysDiskAddr_t *) node->params[2 * i].p;
|
|
|
|
obuf = (char *) node->params[2 * i + 1].p;
|
|
|
|
coeff = rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), old->raidAddress);
|
|
|
|
/* compute the data unit offset within the column, then add
|
|
|
|
* one */
|
|
|
|
coeff = (coeff % raidPtr->Layout.numDataCol);
|
|
|
|
/* the input buffers may not all be aligned with the start of
|
|
|
|
* the stripe. so shift by their sector offset within the
|
|
|
|
* stripe unit */
|
|
|
|
j = old->startSector % secPerSU;
|
|
|
|
RF_ASSERT(j >= fail_start);
|
|
|
|
qpbuf = qbuf + rf_RaidAddressToByte(raidPtr, j - fail_start);
|
|
|
|
rf_IncQ((unsigned long *) qpbuf, (unsigned long *) obuf, rf_RaidAddressToByte(raidPtr, old->numSector), coeff);
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_ETIMER_STOP(timer);
|
|
|
|
RF_ETIMER_EVAL(timer);
|
|
|
|
tracerec->q_us += RF_ETIMER_VAL_US(timer);
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
/*
|
|
|
|
Called by large write code to compute the new parity and the new q.
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
structure of the params:
|
|
|
|
|
|
|
|
pda_0, buffer_0, pda_1 , buffer_1, ... , pda_d, buffer_d ( d = numDataCol
|
1999-02-05 03:06:06 +03:00
|
|
|
raidPtr
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
for a total of 2d+1 arguments.
|
|
|
|
The result buffers results[0], results[1] are the buffers for the p and q,
|
|
|
|
respectively.
|
|
|
|
|
|
|
|
We compute Q first, then compute P. The P calculation may try to reuse
|
|
|
|
one of the input buffers for its output, so if we computed P first, we would
|
|
|
|
corrupt the input for the q calculation.
|
|
|
|
*/
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_RegularPQFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
RegularQSubr(node, node->results[1]);
|
|
|
|
return (rf_RegularXorFunc(node)); /* does the wakeup */
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_RegularQFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
/* Almost ... adjust Qsubr args */
|
|
|
|
RegularQSubr(node, node->results[0]);
|
|
|
|
rf_GenericWakeupFunc(node, 0); /* call wake func explicitly since no
|
|
|
|
* I/O in this node */
|
|
|
|
return (0);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
Called by singly degraded write code to compute the new parity and the new q.
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
structure of the params:
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
pda_0, buffer_0, pda_1 , buffer_1, ... , pda_d, buffer_d
|
|
|
|
failedPDA raidPtr
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
for a total of 2d+2 arguments.
|
|
|
|
The result buffers results[0], results[1] are the buffers for the parity and q,
|
|
|
|
respectively.
|
|
|
|
|
|
|
|
We compute Q first, then compute parity. The parity calculation may try to reuse
|
|
|
|
one of the input buffers for its output, so if we computed parity first, we would
|
|
|
|
corrupt the input for the q calculation.
|
|
|
|
|
|
|
|
We treat this identically to the regularPQ case, ignoring the failedPDA extra argument.
|
|
|
|
*/
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
void
|
|
|
|
rf_Degraded_100_PQFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int np = node->numParams;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_ASSERT(np >= 2);
|
|
|
|
DegrQSubr(node);
|
|
|
|
rf_RecoveryXorFunc(node);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
The two below are used when reading a stripe with a single lost data unit.
|
|
|
|
The parameters are
|
|
|
|
|
|
|
|
pda_0, buffer_0, .... pda_n, buffer_n, P pda, P buffer, failedPDA, raidPtr
|
|
|
|
|
|
|
|
and results[0] contains the data buffer. Which is originally zero-filled.
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* this Q func is used by the degraded-mode dag functions to recover lost data.
|
|
|
|
* the second-to-last parameter is the PDA for the failed portion of the access.
|
|
|
|
* the code here looks at this PDA and assumes that the xor target buffer is
|
|
|
|
* equal in size to the number of sectors in the failed PDA. It then uses
|
|
|
|
* the other PDAs in the parameter list to determine where within the target
|
|
|
|
* buffer the corresponding data should be xored.
|
|
|
|
*
|
1999-02-05 03:06:06 +03:00
|
|
|
* Recall the basic equation is
|
|
|
|
*
|
1998-11-13 07:20:26 +03:00
|
|
|
* Q = ( data_1 + 2 * data_2 ... + k * data_k ) mod 256
|
|
|
|
*
|
|
|
|
* so to recover data_j we need
|
|
|
|
*
|
|
|
|
* J data_j = (Q - data_1 - 2 data_2 ....- k* data_k) mod 256
|
|
|
|
*
|
|
|
|
* So the coefficient for each buffer is (255 - data_col), and j should be initialized by
|
|
|
|
* copying Q into it. Then we need to do a table lookup to convert to solve
|
|
|
|
* data_j /= J
|
1999-02-05 03:06:06 +03:00
|
|
|
*
|
|
|
|
*
|
1998-11-13 07:20:26 +03:00
|
|
|
*/
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_RecoveryQFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[node->numParams - 1].p;
|
|
|
|
RF_RaidLayout_t *layoutPtr = (RF_RaidLayout_t *) & raidPtr->Layout;
|
|
|
|
RF_PhysDiskAddr_t *failedPDA = (RF_PhysDiskAddr_t *) node->params[node->numParams - 2].p;
|
|
|
|
int i;
|
|
|
|
RF_PhysDiskAddr_t *pda;
|
|
|
|
RF_RaidAddr_t suoffset, failedSUOffset = rf_StripeUnitOffset(layoutPtr, failedPDA->startSector);
|
|
|
|
char *srcbuf, *destbuf;
|
|
|
|
RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
|
|
|
|
RF_Etimer_t timer;
|
|
|
|
unsigned long coeff;
|
|
|
|
|
|
|
|
RF_ETIMER_START(timer);
|
|
|
|
/* start by copying Q into the buffer */
|
|
|
|
bcopy(node->params[node->numParams - 3].p, node->results[0],
|
|
|
|
rf_RaidAddressToByte(raidPtr, failedPDA->numSector));
|
|
|
|
for (i = 0; i < node->numParams - 4; i += 2) {
|
|
|
|
RF_ASSERT(node->params[i + 1].p != node->results[0]);
|
|
|
|
pda = (RF_PhysDiskAddr_t *) node->params[i].p;
|
|
|
|
srcbuf = (char *) node->params[i + 1].p;
|
|
|
|
suoffset = rf_StripeUnitOffset(layoutPtr, pda->startSector);
|
|
|
|
destbuf = ((char *) node->results[0]) + rf_RaidAddressToByte(raidPtr, suoffset - failedSUOffset);
|
|
|
|
coeff = rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), pda->raidAddress);
|
|
|
|
/* compute the data unit offset within the column */
|
|
|
|
coeff = (coeff % raidPtr->Layout.numDataCol);
|
|
|
|
rf_IncQ((unsigned long *) destbuf, (unsigned long *) srcbuf, rf_RaidAddressToByte(raidPtr, pda->numSector), coeff);
|
|
|
|
}
|
|
|
|
/* Do the nasty inversion now */
|
|
|
|
coeff = (rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), failedPDA->startSector) % raidPtr->Layout.numDataCol);
|
|
|
|
rf_InvertQ(node->results[0], node->results[0], rf_RaidAddressToByte(raidPtr, pda->numSector), coeff);
|
|
|
|
RF_ETIMER_STOP(timer);
|
|
|
|
RF_ETIMER_EVAL(timer);
|
|
|
|
tracerec->q_us += RF_ETIMER_VAL_US(timer);
|
|
|
|
rf_GenericWakeupFunc(node, 0);
|
|
|
|
return (0);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_RecoveryPQFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-08-15 07:44:46 +04:00
|
|
|
RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[node->numParams - 1].p;
|
|
|
|
printf("raid%d: Recovery from PQ not implemented.\n",raidPtr->raidid);
|
1999-02-05 03:06:06 +03:00
|
|
|
return (1);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
/*
|
1999-02-05 03:06:06 +03:00
|
|
|
Degraded write Q subroutine.
|
1998-11-13 07:20:26 +03:00
|
|
|
Used when P is dead.
|
1999-02-05 03:06:06 +03:00
|
|
|
Large-write style Q computation.
|
1998-11-13 07:20:26 +03:00
|
|
|
Parameters
|
|
|
|
|
|
|
|
(pda,buf),(pda,buf),.....,(failedPDA,bufPtr),failedPDA,raidPtr.
|
|
|
|
|
|
|
|
We ignore failedPDA.
|
|
|
|
|
|
|
|
This is a "simple style" recovery func.
|
|
|
|
*/
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
void
|
|
|
|
rf_PQ_DegradedWriteQFunc(node)
|
|
|
|
RF_DagNode_t *node;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int np = node->numParams;
|
|
|
|
int d;
|
|
|
|
RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[np - 1].p;
|
|
|
|
unsigned secPerSU = raidPtr->Layout.sectorsPerStripeUnit;
|
|
|
|
int i;
|
|
|
|
RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
|
|
|
|
RF_Etimer_t timer;
|
|
|
|
char *qbuf = node->results[0];
|
|
|
|
char *obuf, *qpbuf;
|
|
|
|
RF_PhysDiskAddr_t *old;
|
|
|
|
unsigned long coeff;
|
|
|
|
int fail_start, j;
|
|
|
|
|
|
|
|
old = (RF_PhysDiskAddr_t *) node->params[np - 2].p;
|
|
|
|
fail_start = old->startSector % secPerSU;
|
|
|
|
|
|
|
|
RF_ETIMER_START(timer);
|
|
|
|
|
|
|
|
d = (np - 2) / 2;
|
|
|
|
RF_ASSERT(2 * d + 2 == np);
|
|
|
|
|
|
|
|
for (i = 0; i < d; i++) {
|
|
|
|
old = (RF_PhysDiskAddr_t *) node->params[2 * i].p;
|
|
|
|
obuf = (char *) node->params[2 * i + 1].p;
|
|
|
|
coeff = rf_RaidAddressToStripeUnitID(&(raidPtr->Layout), old->raidAddress);
|
|
|
|
/* compute the data unit offset within the column, then add
|
|
|
|
* one */
|
|
|
|
coeff = (coeff % raidPtr->Layout.numDataCol);
|
|
|
|
j = old->startSector % secPerSU;
|
|
|
|
RF_ASSERT(j >= fail_start);
|
|
|
|
qpbuf = qbuf + rf_RaidAddressToByte(raidPtr, j - fail_start);
|
|
|
|
rf_IncQ((unsigned long *) qpbuf, (unsigned long *) obuf, rf_RaidAddressToByte(raidPtr, old->numSector), coeff);
|
|
|
|
}
|
|
|
|
|
|
|
|
RF_ETIMER_STOP(timer);
|
|
|
|
RF_ETIMER_EVAL(timer);
|
|
|
|
tracerec->q_us += RF_ETIMER_VAL_US(timer);
|
|
|
|
rf_GenericWakeupFunc(node, 0);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Q computations */
|
|
|
|
|
|
|
|
/*
|
|
|
|
coeff - colummn;
|
|
|
|
|
|
|
|
compute dest ^= qfor[28-coeff][rn[coeff+1] a]
|
|
|
|
|
|
|
|
on 5-bit basis;
|
|
|
|
length in bytes;
|
|
|
|
*/
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
void
|
|
|
|
rf_IncQ(dest, buf, length, coeff)
|
|
|
|
unsigned long *dest;
|
|
|
|
unsigned long *buf;
|
|
|
|
unsigned length;
|
|
|
|
unsigned coeff;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
unsigned long a, d, new;
|
|
|
|
unsigned long a1, a2;
|
|
|
|
unsigned int *q = &(rf_qfor[28 - coeff][0]);
|
|
|
|
unsigned r = rf_rn[coeff + 1];
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
#define EXTRACT(a,i) ((a >> (5L*i)) & 0x1f)
|
|
|
|
#define INSERT(a,i) (a << (5L*i))
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
length /= 8;
|
|
|
|
/* 13 5 bit quants in a 64 bit word */
|
|
|
|
while (length) {
|
|
|
|
a = *buf++;
|
|
|
|
d = *dest;
|
|
|
|
a1 = EXTRACT(a, 0) ^ r;
|
|
|
|
a2 = EXTRACT(a, 1) ^ r;
|
|
|
|
new = INSERT(a2, 1) | a1;
|
|
|
|
a1 = EXTRACT(a, 2) ^ r;
|
|
|
|
a2 = EXTRACT(a, 3) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 2) | INSERT(a2, 3);
|
|
|
|
a1 = EXTRACT(a, 4) ^ r;
|
|
|
|
a2 = EXTRACT(a, 5) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 4) | INSERT(a2, 5);
|
|
|
|
a1 = EXTRACT(a, 5) ^ r;
|
|
|
|
a2 = EXTRACT(a, 6) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 5) | INSERT(a2, 6);
|
1998-11-13 07:20:26 +03:00
|
|
|
#if RF_LONGSHIFT > 2
|
1999-02-05 03:06:06 +03:00
|
|
|
a1 = EXTRACT(a, 7) ^ r;
|
|
|
|
a2 = EXTRACT(a, 8) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 7) | INSERT(a2, 8);
|
|
|
|
a1 = EXTRACT(a, 9) ^ r;
|
|
|
|
a2 = EXTRACT(a, 10) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 9) | INSERT(a2, 10);
|
|
|
|
a1 = EXTRACT(a, 11) ^ r;
|
|
|
|
a2 = EXTRACT(a, 12) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 11) | INSERT(a2, 12);
|
|
|
|
#endif /* RF_LONGSHIFT > 2 */
|
|
|
|
d ^= new;
|
|
|
|
*dest++ = d;
|
|
|
|
length--;
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
/*
|
1999-02-05 03:06:06 +03:00
|
|
|
compute
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
dest ^= rf_qfor[28-coeff][rf_rn[coeff+1] (old^new) ]
|
|
|
|
|
|
|
|
on a five bit basis.
|
|
|
|
optimization: compute old ^ new on 64 bit basis.
|
|
|
|
|
|
|
|
length in bytes.
|
|
|
|
*/
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
static void
|
|
|
|
QDelta(
|
|
|
|
char *dest,
|
|
|
|
char *obuf,
|
|
|
|
char *nbuf,
|
|
|
|
unsigned length,
|
|
|
|
unsigned char coeff)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
unsigned long a, d, new;
|
|
|
|
unsigned long a1, a2;
|
|
|
|
unsigned int *q = &(rf_qfor[28 - coeff][0]);
|
1999-08-15 06:36:40 +04:00
|
|
|
unsigned int r = rf_rn[coeff + 1];
|
|
|
|
|
|
|
|
r = a1 = a2 = new = d = a = 0; /* XXX for now... */
|
|
|
|
q = NULL; /* XXX for now */
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-01-26 05:33:49 +03:00
|
|
|
#ifdef _KERNEL
|
1999-02-05 03:06:06 +03:00
|
|
|
/* PQ in kernel currently not supported because the encoding/decoding
|
|
|
|
* table is not present */
|
|
|
|
bzero(dest, length);
|
|
|
|
#else /* KERNEL */
|
|
|
|
/* this code probably doesn't work and should be rewritten -wvcii */
|
|
|
|
/* 13 5 bit quants in a 64 bit word */
|
|
|
|
length /= 8;
|
|
|
|
while (length) {
|
|
|
|
a = *obuf++; /* XXX need to reorg to avoid cache conflicts */
|
|
|
|
a ^= *nbuf++;
|
|
|
|
d = *dest;
|
|
|
|
a1 = EXTRACT(a, 0) ^ r;
|
|
|
|
a2 = EXTRACT(a, 1) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = INSERT(a2, 1) | a1;
|
|
|
|
a1 = EXTRACT(a, 2) ^ r;
|
|
|
|
a2 = EXTRACT(a, 3) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 2) | INSERT(a2, 3);
|
|
|
|
a1 = EXTRACT(a, 4) ^ r;
|
|
|
|
a2 = EXTRACT(a, 5) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 4) | INSERT(a2, 5);
|
|
|
|
a1 = EXTRACT(a, 5) ^ r;
|
|
|
|
a2 = EXTRACT(a, 6) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 5) | INSERT(a2, 6);
|
1998-11-13 07:20:26 +03:00
|
|
|
#if RF_LONGSHIFT > 2
|
1999-02-05 03:06:06 +03:00
|
|
|
a1 = EXTRACT(a, 7) ^ r;
|
|
|
|
a2 = EXTRACT(a, 8) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 7) | INSERT(a2, 8);
|
|
|
|
a1 = EXTRACT(a, 9) ^ r;
|
|
|
|
a2 = EXTRACT(a, 10) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 9) | INSERT(a2, 10);
|
|
|
|
a1 = EXTRACT(a, 11) ^ r;
|
|
|
|
a2 = EXTRACT(a, 12) ^ r;
|
|
|
|
a1 = q[a1];
|
|
|
|
a2 = q[a2];
|
|
|
|
new = new | INSERT(a1, 11) | INSERT(a2, 12);
|
|
|
|
#endif /* RF_LONGSHIFT > 2 */
|
|
|
|
d ^= new;
|
|
|
|
*dest++ = d;
|
|
|
|
length--;
|
|
|
|
}
|
|
|
|
#endif /* _KERNEL */
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
recover columns a and b from the given p and q into
|
|
|
|
bufs abuf and bbuf. All bufs are word aligned.
|
|
|
|
Length is in bytes.
|
|
|
|
*/
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
*
|
|
|
|
* Everything about this seems wrong.
|
|
|
|
*/
|
1999-02-05 03:06:06 +03:00
|
|
|
void
|
|
|
|
rf_PQ_recover(pbuf, qbuf, abuf, bbuf, length, coeff_a, coeff_b)
|
|
|
|
unsigned long *pbuf;
|
|
|
|
unsigned long *qbuf;
|
|
|
|
unsigned long *abuf;
|
|
|
|
unsigned long *bbuf;
|
|
|
|
unsigned length;
|
|
|
|
unsigned coeff_a;
|
|
|
|
unsigned coeff_b;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
unsigned long p, q, a, a0, a1;
|
|
|
|
int col = (29 * coeff_a) + coeff_b;
|
|
|
|
unsigned char *q0 = &(rf_qinv[col][0]);
|
|
|
|
|
|
|
|
length /= 8;
|
|
|
|
while (length) {
|
|
|
|
p = *pbuf++;
|
|
|
|
q = *qbuf++;
|
|
|
|
a0 = EXTRACT(p, 0);
|
|
|
|
a1 = EXTRACT(q, 0);
|
|
|
|
a = q0[a0 << 5 | a1];
|
1998-11-13 07:20:26 +03:00
|
|
|
#define MF(i) \
|
|
|
|
a0 = EXTRACT(p,i); \
|
|
|
|
a1 = EXTRACT(q,i); \
|
|
|
|
a = a | INSERT(q0[a0<<5 | a1],i)
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
MF(1);
|
|
|
|
MF(2);
|
|
|
|
MF(3);
|
|
|
|
MF(4);
|
|
|
|
MF(5);
|
|
|
|
MF(6);
|
1998-11-13 07:20:26 +03:00
|
|
|
#if 0
|
1999-02-05 03:06:06 +03:00
|
|
|
MF(7);
|
|
|
|
MF(8);
|
|
|
|
MF(9);
|
|
|
|
MF(10);
|
|
|
|
MF(11);
|
|
|
|
MF(12);
|
|
|
|
#endif /* 0 */
|
|
|
|
*abuf++ = a;
|
|
|
|
*bbuf++ = a ^ p;
|
|
|
|
length--;
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
/*
|
1998-11-13 07:20:26 +03:00
|
|
|
Lost parity and a data column. Recover that data column.
|
|
|
|
Assume col coeff is lost. Let q the contents of Q after
|
|
|
|
all surviving data columns have been q-xored out of it.
|
|
|
|
Then we have the equation
|
|
|
|
|
|
|
|
q[28-coeff][a_i ^ r_i+1] = q
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
but q is cyclic with period 31.
|
1998-11-13 07:20:26 +03:00
|
|
|
So q[3+coeff][q[28-coeff][a_i ^ r_{i+1}]] =
|
|
|
|
q[31][a_i ^ r_{i+1}] = a_i ^ r_{i+1} .
|
|
|
|
|
|
|
|
so a_i = r_{coeff+1} ^ q[3+coeff][q]
|
|
|
|
|
|
|
|
The routine is passed q buffer and the buffer
|
|
|
|
the data is to be recoverd into. They can be the same.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
rf_InvertQ(
|
|
|
|
unsigned long *qbuf,
|
|
|
|
unsigned long *abuf,
|
|
|
|
unsigned length,
|
|
|
|
unsigned coeff)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
unsigned long a, new;
|
|
|
|
unsigned long a1, a2;
|
|
|
|
unsigned int *q = &(rf_qfor[3 + coeff][0]);
|
|
|
|
unsigned r = rf_rn[coeff + 1];
|
|
|
|
|
|
|
|
/* 13 5 bit quants in a 64 bit word */
|
|
|
|
length /= 8;
|
|
|
|
while (length) {
|
|
|
|
a = *qbuf++;
|
|
|
|
a1 = EXTRACT(a, 0);
|
|
|
|
a2 = EXTRACT(a, 1);
|
|
|
|
a1 = r ^ q[a1];
|
|
|
|
a2 = r ^ q[a2];
|
|
|
|
new = INSERT(a2, 1) | a1;
|
1998-11-13 07:20:26 +03:00
|
|
|
#define M(i,j) \
|
|
|
|
a1 = EXTRACT(a,i); \
|
|
|
|
a2 = EXTRACT(a,j); \
|
|
|
|
a1 = r ^ q[a1]; \
|
|
|
|
a2 = r ^ q[a2]; \
|
|
|
|
new = new | INSERT(a1,i) | INSERT(a2,j)
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
M(2, 3);
|
|
|
|
M(4, 5);
|
|
|
|
M(5, 6);
|
1998-11-13 07:20:26 +03:00
|
|
|
#if RF_LONGSHIFT > 2
|
1999-02-05 03:06:06 +03:00
|
|
|
M(7, 8);
|
|
|
|
M(9, 10);
|
|
|
|
M(11, 12);
|
|
|
|
#endif /* RF_LONGSHIFT > 2 */
|
|
|
|
*abuf++ = new;
|
|
|
|
length--;
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
#endif /* (RF_INCLUDE_DECL_PQ > 0) ||
|
|
|
|
* (RF_INCLUDE_RAID6 > 0) */
|