Home | History | Annotate | Line # | Download | only in raidframe
rf_raid1.c revision 1.13
      1  1.13    oster /*	$NetBSD: rf_raid1.c,v 1.13 2002/09/23 03:38:51 oster Exp $	*/
      2   1.1    oster /*
      3   1.1    oster  * Copyright (c) 1995 Carnegie-Mellon University.
      4   1.1    oster  * All rights reserved.
      5   1.1    oster  *
      6   1.1    oster  * Author: William V. Courtright II
      7   1.1    oster  *
      8   1.1    oster  * Permission to use, copy, modify and distribute this software and
      9   1.1    oster  * its documentation is hereby granted, provided that both the copyright
     10   1.1    oster  * notice and this permission notice appear in all copies of the
     11   1.1    oster  * software, derivative works or modified versions, and any portions
     12   1.1    oster  * thereof, and that both notices appear in supporting documentation.
     13   1.1    oster  *
     14   1.1    oster  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15   1.1    oster  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16   1.1    oster  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17   1.1    oster  *
     18   1.1    oster  * Carnegie Mellon requests users of this software to return to
     19   1.1    oster  *
     20   1.1    oster  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21   1.1    oster  *  School of Computer Science
     22   1.1    oster  *  Carnegie Mellon University
     23   1.1    oster  *  Pittsburgh PA 15213-3890
     24   1.1    oster  *
     25   1.1    oster  * any improvements or extensions that they make and grant Carnegie the
     26   1.1    oster  * rights to redistribute these changes.
     27   1.1    oster  */
     28   1.1    oster 
     29   1.1    oster /*****************************************************************************
     30   1.1    oster  *
     31   1.1    oster  * rf_raid1.c -- implements RAID Level 1
     32   1.1    oster  *
     33   1.1    oster  *****************************************************************************/
     34   1.8    lukem 
     35   1.8    lukem #include <sys/cdefs.h>
     36  1.13    oster __KERNEL_RCSID(0, "$NetBSD: rf_raid1.c,v 1.13 2002/09/23 03:38:51 oster Exp $");
     37   1.1    oster 
     38   1.1    oster #include "rf_raid.h"
     39   1.1    oster #include "rf_raid1.h"
     40   1.1    oster #include "rf_dag.h"
     41   1.1    oster #include "rf_dagffrd.h"
     42   1.1    oster #include "rf_dagffwr.h"
     43   1.1    oster #include "rf_dagdegrd.h"
     44   1.1    oster #include "rf_dagutils.h"
     45   1.1    oster #include "rf_dagfuncs.h"
     46   1.1    oster #include "rf_diskqueue.h"
     47   1.1    oster #include "rf_general.h"
     48   1.1    oster #include "rf_utils.h"
     49   1.1    oster #include "rf_parityscan.h"
     50   1.1    oster #include "rf_mcpair.h"
     51   1.1    oster #include "rf_layout.h"
     52   1.1    oster #include "rf_map.h"
     53   1.1    oster #include "rf_engine.h"
     54   1.1    oster #include "rf_reconbuffer.h"
     55   1.1    oster 
     56   1.1    oster typedef struct RF_Raid1ConfigInfo_s {
     57   1.3    oster 	RF_RowCol_t **stripeIdentifier;
     58   1.3    oster }       RF_Raid1ConfigInfo_t;
     59   1.1    oster /* start of day code specific to RAID level 1 */
     60   1.3    oster int
     61   1.3    oster rf_ConfigureRAID1(
     62   1.3    oster     RF_ShutdownList_t ** listp,
     63   1.3    oster     RF_Raid_t * raidPtr,
     64   1.3    oster     RF_Config_t * cfgPtr)
     65   1.1    oster {
     66   1.3    oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
     67   1.3    oster 	RF_Raid1ConfigInfo_t *info;
     68   1.3    oster 	RF_RowCol_t i;
     69   1.3    oster 
     70   1.3    oster 	/* create a RAID level 1 configuration structure */
     71   1.3    oster 	RF_MallocAndAdd(info, sizeof(RF_Raid1ConfigInfo_t), (RF_Raid1ConfigInfo_t *), raidPtr->cleanupList);
     72   1.3    oster 	if (info == NULL)
     73   1.3    oster 		return (ENOMEM);
     74   1.3    oster 	layoutPtr->layoutSpecificInfo = (void *) info;
     75   1.3    oster 
     76   1.3    oster 	/* ... and fill it in. */
     77   1.3    oster 	info->stripeIdentifier = rf_make_2d_array(raidPtr->numCol / 2, 2, raidPtr->cleanupList);
     78   1.3    oster 	if (info->stripeIdentifier == NULL)
     79   1.3    oster 		return (ENOMEM);
     80   1.3    oster 	for (i = 0; i < (raidPtr->numCol / 2); i++) {
     81   1.3    oster 		info->stripeIdentifier[i][0] = (2 * i);
     82   1.3    oster 		info->stripeIdentifier[i][1] = (2 * i) + 1;
     83   1.3    oster 	}
     84   1.3    oster 
     85   1.3    oster 	RF_ASSERT(raidPtr->numRow == 1);
     86   1.3    oster 
     87   1.3    oster 	/* this implementation of RAID level 1 uses one row of numCol disks
     88   1.3    oster 	 * and allows multiple (numCol / 2) stripes per row.  A stripe
     89   1.3    oster 	 * consists of a single data unit and a single parity (mirror) unit.
     90   1.3    oster 	 * stripe id = raidAddr / stripeUnitSize */
     91   1.3    oster 	raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * (raidPtr->numCol / 2) * layoutPtr->sectorsPerStripeUnit;
     92   1.3    oster 	layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk * (raidPtr->numCol / 2);
     93   1.3    oster 	layoutPtr->dataSectorsPerStripe = layoutPtr->sectorsPerStripeUnit;
     94   1.3    oster 	layoutPtr->numDataCol = 1;
     95   1.3    oster 	layoutPtr->numParityCol = 1;
     96   1.3    oster 	return (0);
     97   1.1    oster }
     98   1.1    oster 
     99   1.1    oster 
    100   1.1    oster /* returns the physical disk location of the primary copy in the mirror pair */
    101   1.3    oster void
    102   1.3    oster rf_MapSectorRAID1(
    103   1.3    oster     RF_Raid_t * raidPtr,
    104   1.3    oster     RF_RaidAddr_t raidSector,
    105   1.3    oster     RF_RowCol_t * row,
    106   1.3    oster     RF_RowCol_t * col,
    107   1.3    oster     RF_SectorNum_t * diskSector,
    108   1.3    oster     int remap)
    109   1.1    oster {
    110   1.3    oster 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    111   1.3    oster 	RF_RowCol_t mirrorPair = SUID % (raidPtr->numCol / 2);
    112   1.1    oster 
    113   1.3    oster 	*row = 0;
    114   1.3    oster 	*col = 2 * mirrorPair;
    115   1.3    oster 	*diskSector = ((SUID / (raidPtr->numCol / 2)) * raidPtr->Layout.sectorsPerStripeUnit) + (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    116   1.1    oster }
    117   1.1    oster 
    118   1.1    oster 
    119   1.1    oster /* Map Parity
    120   1.1    oster  *
    121   1.1    oster  * returns the physical disk location of the secondary copy in the mirror
    122   1.1    oster  * pair
    123   1.1    oster  */
    124   1.3    oster void
    125   1.3    oster rf_MapParityRAID1(
    126   1.3    oster     RF_Raid_t * raidPtr,
    127   1.3    oster     RF_RaidAddr_t raidSector,
    128   1.3    oster     RF_RowCol_t * row,
    129   1.3    oster     RF_RowCol_t * col,
    130   1.3    oster     RF_SectorNum_t * diskSector,
    131   1.3    oster     int remap)
    132   1.1    oster {
    133   1.3    oster 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    134   1.3    oster 	RF_RowCol_t mirrorPair = SUID % (raidPtr->numCol / 2);
    135   1.1    oster 
    136   1.3    oster 	*row = 0;
    137   1.3    oster 	*col = (2 * mirrorPair) + 1;
    138   1.1    oster 
    139   1.3    oster 	*diskSector = ((SUID / (raidPtr->numCol / 2)) * raidPtr->Layout.sectorsPerStripeUnit) + (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    140   1.1    oster }
    141   1.1    oster 
    142   1.1    oster 
    143   1.1    oster /* IdentifyStripeRAID1
    144   1.1    oster  *
    145   1.1    oster  * returns a list of disks for a given redundancy group
    146   1.1    oster  */
    147   1.3    oster void
    148   1.3    oster rf_IdentifyStripeRAID1(
    149   1.3    oster     RF_Raid_t * raidPtr,
    150   1.3    oster     RF_RaidAddr_t addr,
    151   1.3    oster     RF_RowCol_t ** diskids,
    152   1.3    oster     RF_RowCol_t * outRow)
    153   1.1    oster {
    154   1.3    oster 	RF_StripeNum_t stripeID = rf_RaidAddressToStripeID(&raidPtr->Layout, addr);
    155   1.3    oster 	RF_Raid1ConfigInfo_t *info = raidPtr->Layout.layoutSpecificInfo;
    156   1.3    oster 	RF_ASSERT(stripeID >= 0);
    157   1.3    oster 	RF_ASSERT(addr >= 0);
    158   1.3    oster 	*outRow = 0;
    159   1.3    oster 	*diskids = info->stripeIdentifier[stripeID % (raidPtr->numCol / 2)];
    160   1.3    oster 	RF_ASSERT(*diskids);
    161   1.1    oster }
    162   1.1    oster 
    163   1.1    oster 
    164   1.1    oster /* MapSIDToPSIDRAID1
    165   1.1    oster  *
    166   1.1    oster  * maps a logical stripe to a stripe in the redundant array
    167   1.1    oster  */
    168   1.3    oster void
    169   1.3    oster rf_MapSIDToPSIDRAID1(
    170   1.3    oster     RF_RaidLayout_t * layoutPtr,
    171   1.3    oster     RF_StripeNum_t stripeID,
    172   1.3    oster     RF_StripeNum_t * psID,
    173   1.3    oster     RF_ReconUnitNum_t * which_ru)
    174   1.1    oster {
    175   1.3    oster 	*which_ru = 0;
    176   1.3    oster 	*psID = stripeID;
    177   1.1    oster }
    178   1.1    oster 
    179   1.1    oster 
    180   1.1    oster 
    181   1.1    oster /******************************************************************************
    182   1.1    oster  * select a graph to perform a single-stripe access
    183   1.1    oster  *
    184   1.1    oster  * Parameters:  raidPtr    - description of the physical array
    185   1.1    oster  *              type       - type of operation (read or write) requested
    186   1.1    oster  *              asmap      - logical & physical addresses for this access
    187   1.1    oster  *              createFunc - name of function to use to create the graph
    188   1.1    oster  *****************************************************************************/
    189   1.1    oster 
    190   1.3    oster void
    191   1.3    oster rf_RAID1DagSelect(
    192   1.3    oster     RF_Raid_t * raidPtr,
    193   1.3    oster     RF_IoType_t type,
    194   1.3    oster     RF_AccessStripeMap_t * asmap,
    195   1.3    oster     RF_VoidFuncPtr * createFunc)
    196   1.1    oster {
    197   1.3    oster 	RF_RowCol_t frow, fcol, or, oc;
    198   1.3    oster 	RF_PhysDiskAddr_t *failedPDA;
    199   1.5    oster 	int     prior_recon;
    200   1.3    oster 	RF_RowStatus_t rstat;
    201   1.3    oster 	RF_SectorNum_t oo;
    202   1.3    oster 
    203   1.3    oster 
    204   1.3    oster 	RF_ASSERT(RF_IO_IS_R_OR_W(type));
    205   1.3    oster 
    206   1.3    oster 	if (asmap->numDataFailed + asmap->numParityFailed > 1) {
    207   1.3    oster 		RF_ERRORMSG("Multiple disks failed in a single group!  Aborting I/O operation.\n");
    208   1.3    oster 		*createFunc = NULL;
    209   1.3    oster 		return;
    210   1.3    oster 	}
    211   1.3    oster 	if (asmap->numDataFailed + asmap->numParityFailed) {
    212   1.3    oster 		/*
    213   1.3    oster 	         * We've got a fault. Re-map to spare space, iff applicable.
    214   1.3    oster 	         * Shouldn't the arch-independent code do this for us?
    215   1.3    oster 	         * Anyway, it turns out if we don't do this here, then when
    216   1.3    oster 	         * we're reconstructing, writes go only to the surviving
    217   1.3    oster 	         * original disk, and aren't reflected on the reconstructed
    218   1.3    oster 	         * spare. Oops. --jimz
    219   1.3    oster 	         */
    220   1.3    oster 		failedPDA = asmap->failedPDAs[0];
    221   1.3    oster 		frow = failedPDA->row;
    222   1.3    oster 		fcol = failedPDA->col;
    223   1.3    oster 		rstat = raidPtr->status[frow];
    224   1.3    oster 		prior_recon = (rstat == rf_rs_reconfigured) || (
    225   1.3    oster 		    (rstat == rf_rs_reconstructing) ?
    226   1.3    oster 		    rf_CheckRUReconstructed(raidPtr->reconControl[frow]->reconMap, failedPDA->startSector) : 0
    227   1.3    oster 		    );
    228   1.3    oster 		if (prior_recon) {
    229   1.3    oster 			or = frow;
    230   1.3    oster 			oc = fcol;
    231   1.3    oster 			oo = failedPDA->startSector;
    232   1.3    oster 			/*
    233   1.3    oster 		         * If we did distributed sparing, we'd monkey with that here.
    234   1.3    oster 		         * But we don't, so we'll
    235   1.3    oster 		         */
    236   1.3    oster 			failedPDA->row = raidPtr->Disks[frow][fcol].spareRow;
    237   1.3    oster 			failedPDA->col = raidPtr->Disks[frow][fcol].spareCol;
    238   1.3    oster 			/*
    239   1.3    oster 		         * Redirect other components, iff necessary. This looks
    240   1.3    oster 		         * pretty suspicious to me, but it's what the raid5
    241   1.3    oster 		         * DAG select does.
    242   1.3    oster 		         */
    243   1.3    oster 			if (asmap->parityInfo->next) {
    244   1.3    oster 				if (failedPDA == asmap->parityInfo) {
    245   1.3    oster 					failedPDA->next->row = failedPDA->row;
    246   1.3    oster 					failedPDA->next->col = failedPDA->col;
    247   1.3    oster 				} else {
    248   1.3    oster 					if (failedPDA == asmap->parityInfo->next) {
    249   1.3    oster 						asmap->parityInfo->row = failedPDA->row;
    250   1.3    oster 						asmap->parityInfo->col = failedPDA->col;
    251   1.3    oster 					}
    252   1.3    oster 				}
    253   1.3    oster 			}
    254   1.3    oster 			if (rf_dagDebug || rf_mapDebug) {
    255   1.5    oster 				printf("raid%d: Redirected type '%c' r %d c %d o %ld -> r %d c %d o %ld\n",
    256   1.5    oster 				       raidPtr->raidid, type, or, oc,
    257   1.5    oster 				       (long) oo, failedPDA->row,
    258   1.5    oster 				       failedPDA->col,
    259   1.5    oster 				       (long) failedPDA->startSector);
    260   1.3    oster 			}
    261   1.3    oster 			asmap->numDataFailed = asmap->numParityFailed = 0;
    262   1.3    oster 		}
    263   1.3    oster 	}
    264   1.3    oster 	if (type == RF_IO_TYPE_READ) {
    265   1.3    oster 		if (asmap->numDataFailed == 0)
    266   1.3    oster 			*createFunc = (RF_VoidFuncPtr) rf_CreateMirrorIdleReadDAG;
    267   1.3    oster 		else
    268   1.3    oster 			*createFunc = (RF_VoidFuncPtr) rf_CreateRaidOneDegradedReadDAG;
    269   1.3    oster 	} else {
    270   1.3    oster 		*createFunc = (RF_VoidFuncPtr) rf_CreateRaidOneWriteDAG;
    271   1.3    oster 	}
    272   1.1    oster }
    273   1.1    oster 
    274   1.3    oster int
    275   1.3    oster rf_VerifyParityRAID1(
    276   1.3    oster     RF_Raid_t * raidPtr,
    277   1.3    oster     RF_RaidAddr_t raidAddr,
    278   1.3    oster     RF_PhysDiskAddr_t * parityPDA,
    279   1.3    oster     int correct_it,
    280   1.3    oster     RF_RaidAccessFlags_t flags)
    281   1.1    oster {
    282   1.5    oster 	int     nbytes, bcount, stripeWidth, ret, i, j, nbad, *bbufs;
    283  1.13    oster 	RF_DagNode_t *blockNode, *wrBlock;
    284   1.3    oster 	RF_DagHeader_t *rd_dag_h, *wr_dag_h;
    285   1.3    oster 	RF_AccessStripeMapHeader_t *asm_h;
    286   1.3    oster 	RF_AllocListElem_t *allocList;
    287   1.3    oster 	RF_AccTraceEntry_t tracerec;
    288   1.3    oster 	RF_ReconUnitNum_t which_ru;
    289   1.3    oster 	RF_RaidLayout_t *layoutPtr;
    290   1.3    oster 	RF_AccessStripeMap_t *aasm;
    291   1.3    oster 	RF_SectorCount_t nsector;
    292   1.3    oster 	RF_RaidAddr_t startAddr;
    293   1.3    oster 	char   *buf, *buf1, *buf2;
    294   1.3    oster 	RF_PhysDiskAddr_t *pda;
    295   1.3    oster 	RF_StripeNum_t psID;
    296   1.3    oster 	RF_MCPair_t *mcpair;
    297   1.3    oster 
    298   1.3    oster 	layoutPtr = &raidPtr->Layout;
    299   1.3    oster 	startAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, raidAddr);
    300   1.3    oster 	nsector = parityPDA->numSector;
    301   1.3    oster 	nbytes = rf_RaidAddressToByte(raidPtr, nsector);
    302   1.3    oster 	psID = rf_RaidAddressToParityStripeID(layoutPtr, raidAddr, &which_ru);
    303   1.3    oster 
    304   1.3    oster 	asm_h = NULL;
    305   1.3    oster 	rd_dag_h = wr_dag_h = NULL;
    306   1.3    oster 	mcpair = NULL;
    307   1.3    oster 
    308   1.3    oster 	ret = RF_PARITY_COULD_NOT_VERIFY;
    309   1.3    oster 
    310   1.3    oster 	rf_MakeAllocList(allocList);
    311   1.3    oster 	if (allocList == NULL)
    312   1.3    oster 		return (RF_PARITY_COULD_NOT_VERIFY);
    313   1.3    oster 	mcpair = rf_AllocMCPair();
    314   1.3    oster 	if (mcpair == NULL)
    315   1.3    oster 		goto done;
    316   1.3    oster 	RF_ASSERT(layoutPtr->numDataCol == layoutPtr->numParityCol);
    317   1.3    oster 	stripeWidth = layoutPtr->numDataCol + layoutPtr->numParityCol;
    318   1.3    oster 	bcount = nbytes * (layoutPtr->numDataCol + layoutPtr->numParityCol);
    319   1.3    oster 	RF_MallocAndAdd(buf, bcount, (char *), allocList);
    320   1.3    oster 	if (buf == NULL)
    321   1.3    oster 		goto done;
    322  1.10    oster #if RF_DEBUG_VERIFYPARITY
    323   1.3    oster 	if (rf_verifyParityDebug) {
    324   1.5    oster 		printf("raid%d: RAID1 parity verify: buf=%lx bcount=%d (%lx - %lx)\n",
    325   1.5    oster 		       raidPtr->raidid, (long) buf, bcount, (long) buf,
    326   1.5    oster 		       (long) buf + bcount);
    327   1.3    oster 	}
    328  1.10    oster #endif
    329   1.3    oster 	/*
    330   1.3    oster          * Generate a DAG which will read the entire stripe- then we can
    331   1.3    oster          * just compare data chunks versus "parity" chunks.
    332   1.3    oster          */
    333   1.3    oster 
    334   1.3    oster 	rd_dag_h = rf_MakeSimpleDAG(raidPtr, stripeWidth, nbytes, buf,
    335   1.3    oster 	    rf_DiskReadFunc, rf_DiskReadUndoFunc, "Rod", allocList, flags,
    336   1.3    oster 	    RF_IO_NORMAL_PRIORITY);
    337   1.3    oster 	if (rd_dag_h == NULL)
    338   1.3    oster 		goto done;
    339   1.3    oster 	blockNode = rd_dag_h->succedents[0];
    340   1.3    oster 
    341   1.3    oster 	/*
    342   1.3    oster          * Map the access to physical disk addresses (PDAs)- this will
    343   1.3    oster          * get us both a list of data addresses, and "parity" addresses
    344   1.3    oster          * (which are really mirror copies).
    345   1.3    oster          */
    346   1.3    oster 	asm_h = rf_MapAccess(raidPtr, startAddr, layoutPtr->dataSectorsPerStripe,
    347   1.3    oster 	    buf, RF_DONT_REMAP);
    348   1.3    oster 	aasm = asm_h->stripeMap;
    349   1.3    oster 
    350   1.3    oster 	buf1 = buf;
    351   1.3    oster 	/*
    352   1.3    oster          * Loop through the data blocks, setting up read nodes for each.
    353   1.3    oster          */
    354   1.3    oster 	for (pda = aasm->physInfo, i = 0; i < layoutPtr->numDataCol; i++, pda = pda->next) {
    355   1.3    oster 		RF_ASSERT(pda);
    356   1.3    oster 
    357   1.3    oster 		rf_RangeRestrictPDA(raidPtr, parityPDA, pda, 0, 1);
    358   1.3    oster 
    359   1.3    oster 		RF_ASSERT(pda->numSector != 0);
    360   1.3    oster 		if (rf_TryToRedirectPDA(raidPtr, pda, 0)) {
    361   1.3    oster 			/* cannot verify parity with dead disk */
    362   1.3    oster 			goto done;
    363   1.3    oster 		}
    364   1.3    oster 		pda->bufPtr = buf1;
    365   1.3    oster 		blockNode->succedents[i]->params[0].p = pda;
    366   1.3    oster 		blockNode->succedents[i]->params[1].p = buf1;
    367   1.3    oster 		blockNode->succedents[i]->params[2].v = psID;
    368   1.3    oster 		blockNode->succedents[i]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    369   1.3    oster 		buf1 += nbytes;
    370   1.3    oster 	}
    371   1.3    oster 	RF_ASSERT(pda == NULL);
    372   1.3    oster 	/*
    373   1.3    oster          * keep i, buf1 running
    374   1.3    oster          *
    375   1.3    oster          * Loop through parity blocks, setting up read nodes for each.
    376   1.3    oster          */
    377   1.3    oster 	for (pda = aasm->parityInfo; i < layoutPtr->numDataCol + layoutPtr->numParityCol; i++, pda = pda->next) {
    378   1.3    oster 		RF_ASSERT(pda);
    379   1.3    oster 		rf_RangeRestrictPDA(raidPtr, parityPDA, pda, 0, 1);
    380   1.3    oster 		RF_ASSERT(pda->numSector != 0);
    381   1.3    oster 		if (rf_TryToRedirectPDA(raidPtr, pda, 0)) {
    382   1.3    oster 			/* cannot verify parity with dead disk */
    383   1.3    oster 			goto done;
    384   1.3    oster 		}
    385   1.3    oster 		pda->bufPtr = buf1;
    386   1.3    oster 		blockNode->succedents[i]->params[0].p = pda;
    387   1.3    oster 		blockNode->succedents[i]->params[1].p = buf1;
    388   1.3    oster 		blockNode->succedents[i]->params[2].v = psID;
    389   1.3    oster 		blockNode->succedents[i]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    390   1.3    oster 		buf1 += nbytes;
    391   1.3    oster 	}
    392   1.3    oster 	RF_ASSERT(pda == NULL);
    393   1.3    oster 
    394   1.6  thorpej 	memset((char *) &tracerec, 0, sizeof(tracerec));
    395   1.3    oster 	rd_dag_h->tracerec = &tracerec;
    396   1.3    oster 
    397   1.9    oster #if 0
    398   1.3    oster 	if (rf_verifyParityDebug > 1) {
    399   1.5    oster 		printf("raid%d: RAID1 parity verify read dag:\n",
    400   1.5    oster 		       raidPtr->raidid);
    401   1.3    oster 		rf_PrintDAGList(rd_dag_h);
    402   1.3    oster 	}
    403   1.9    oster #endif
    404   1.3    oster 	RF_LOCK_MUTEX(mcpair->mutex);
    405   1.3    oster 	mcpair->flag = 0;
    406   1.3    oster 	rf_DispatchDAG(rd_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
    407   1.3    oster 	    (void *) mcpair);
    408   1.3    oster 	while (mcpair->flag == 0) {
    409   1.3    oster 		RF_WAIT_MCPAIR(mcpair);
    410   1.3    oster 	}
    411   1.3    oster 	RF_UNLOCK_MUTEX(mcpair->mutex);
    412   1.3    oster 
    413   1.3    oster 	if (rd_dag_h->status != rf_enable) {
    414   1.3    oster 		RF_ERRORMSG("Unable to verify raid1 parity: can't read stripe\n");
    415   1.3    oster 		ret = RF_PARITY_COULD_NOT_VERIFY;
    416   1.3    oster 		goto done;
    417   1.3    oster 	}
    418   1.3    oster 	/*
    419   1.3    oster          * buf1 is the beginning of the data blocks chunk
    420   1.3    oster          * buf2 is the beginning of the parity blocks chunk
    421   1.3    oster          */
    422   1.3    oster 	buf1 = buf;
    423   1.3    oster 	buf2 = buf + (nbytes * layoutPtr->numDataCol);
    424   1.3    oster 	ret = RF_PARITY_OKAY;
    425   1.3    oster 	/*
    426   1.3    oster          * bbufs is "bad bufs"- an array whose entries are the data
    427   1.3    oster          * column numbers where we had miscompares. (That is, column 0
    428   1.3    oster          * and column 1 of the array are mirror copies, and are considered
    429   1.3    oster          * "data column 0" for this purpose).
    430   1.3    oster          */
    431   1.3    oster 	RF_MallocAndAdd(bbufs, layoutPtr->numParityCol * sizeof(int), (int *),
    432   1.3    oster 	    allocList);
    433   1.3    oster 	nbad = 0;
    434   1.3    oster 	/*
    435   1.3    oster          * Check data vs "parity" (mirror copy).
    436   1.3    oster          */
    437   1.3    oster 	for (i = 0; i < layoutPtr->numDataCol; i++) {
    438  1.10    oster #if RF_DEBUG_VERIFYPARITY
    439   1.3    oster 		if (rf_verifyParityDebug) {
    440   1.5    oster 			printf("raid%d: RAID1 parity verify %d bytes: i=%d buf1=%lx buf2=%lx buf=%lx\n",
    441   1.5    oster 			       raidPtr->raidid, nbytes, i, (long) buf1,
    442   1.5    oster 			       (long) buf2, (long) buf);
    443   1.3    oster 		}
    444  1.10    oster #endif
    445   1.7  thorpej 		ret = memcmp(buf1, buf2, nbytes);
    446   1.3    oster 		if (ret) {
    447  1.10    oster #if RF_DEBUG_VERIFYPARITY
    448   1.3    oster 			if (rf_verifyParityDebug > 1) {
    449   1.3    oster 				for (j = 0; j < nbytes; j++) {
    450   1.3    oster 					if (buf1[j] != buf2[j])
    451   1.3    oster 						break;
    452   1.3    oster 				}
    453   1.3    oster 				printf("psid=%ld j=%d\n", (long) psID, j);
    454   1.3    oster 				printf("buf1 %02x %02x %02x %02x %02x\n", buf1[0] & 0xff,
    455   1.3    oster 				    buf1[1] & 0xff, buf1[2] & 0xff, buf1[3] & 0xff, buf1[4] & 0xff);
    456   1.3    oster 				printf("buf2 %02x %02x %02x %02x %02x\n", buf2[0] & 0xff,
    457   1.3    oster 				    buf2[1] & 0xff, buf2[2] & 0xff, buf2[3] & 0xff, buf2[4] & 0xff);
    458   1.3    oster 			}
    459   1.3    oster 			if (rf_verifyParityDebug) {
    460   1.5    oster 				printf("raid%d: RAID1: found bad parity, i=%d\n", raidPtr->raidid, i);
    461   1.3    oster 			}
    462  1.10    oster #endif
    463   1.3    oster 			/*
    464   1.3    oster 		         * Parity is bad. Keep track of which columns were bad.
    465   1.3    oster 		         */
    466   1.3    oster 			if (bbufs)
    467   1.3    oster 				bbufs[nbad] = i;
    468   1.3    oster 			nbad++;
    469   1.3    oster 			ret = RF_PARITY_BAD;
    470   1.3    oster 		}
    471   1.3    oster 		buf1 += nbytes;
    472   1.3    oster 		buf2 += nbytes;
    473   1.3    oster 	}
    474   1.3    oster 
    475   1.3    oster 	if ((ret != RF_PARITY_OKAY) && correct_it) {
    476   1.3    oster 		ret = RF_PARITY_COULD_NOT_CORRECT;
    477  1.10    oster #if RF_DEBUG_VERIFYPARITY
    478   1.3    oster 		if (rf_verifyParityDebug) {
    479   1.5    oster 			printf("raid%d: RAID1 parity verify: parity not correct\n", raidPtr->raidid);
    480   1.3    oster 		}
    481  1.10    oster #endif
    482   1.3    oster 		if (bbufs == NULL)
    483   1.3    oster 			goto done;
    484   1.3    oster 		/*
    485   1.3    oster 	         * Make a DAG with one write node for each bad unit. We'll simply
    486   1.3    oster 	         * write the contents of the data unit onto the parity unit for
    487   1.3    oster 	         * correction. (It's possible that the mirror copy was the correct
    488   1.3    oster 	         * copy, and that we're spooging good data by writing bad over it,
    489   1.3    oster 	         * but there's no way we can know that.
    490   1.3    oster 	         */
    491   1.3    oster 		wr_dag_h = rf_MakeSimpleDAG(raidPtr, nbad, nbytes, buf,
    492   1.3    oster 		    rf_DiskWriteFunc, rf_DiskWriteUndoFunc, "Wnp", allocList, flags,
    493   1.3    oster 		    RF_IO_NORMAL_PRIORITY);
    494   1.3    oster 		if (wr_dag_h == NULL)
    495   1.3    oster 			goto done;
    496   1.3    oster 		wrBlock = wr_dag_h->succedents[0];
    497   1.3    oster 		/*
    498   1.3    oster 	         * Fill in a write node for each bad compare.
    499   1.3    oster 	         */
    500   1.3    oster 		for (i = 0; i < nbad; i++) {
    501   1.3    oster 			j = i + layoutPtr->numDataCol;
    502   1.3    oster 			pda = blockNode->succedents[j]->params[0].p;
    503   1.3    oster 			pda->bufPtr = blockNode->succedents[i]->params[1].p;
    504   1.3    oster 			wrBlock->succedents[i]->params[0].p = pda;
    505   1.3    oster 			wrBlock->succedents[i]->params[1].p = pda->bufPtr;
    506   1.3    oster 			wrBlock->succedents[i]->params[2].v = psID;
    507   1.3    oster 			wrBlock->succedents[0]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    508   1.3    oster 		}
    509   1.6  thorpej 		memset((char *) &tracerec, 0, sizeof(tracerec));
    510   1.3    oster 		wr_dag_h->tracerec = &tracerec;
    511   1.9    oster #if 0
    512   1.3    oster 		if (rf_verifyParityDebug > 1) {
    513   1.3    oster 			printf("Parity verify write dag:\n");
    514   1.3    oster 			rf_PrintDAGList(wr_dag_h);
    515   1.3    oster 		}
    516   1.9    oster #endif
    517   1.3    oster 		RF_LOCK_MUTEX(mcpair->mutex);
    518   1.3    oster 		mcpair->flag = 0;
    519   1.3    oster 		/* fire off the write DAG */
    520   1.3    oster 		rf_DispatchDAG(wr_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
    521   1.3    oster 		    (void *) mcpair);
    522   1.3    oster 		while (!mcpair->flag) {
    523   1.3    oster 			RF_WAIT_COND(mcpair->cond, mcpair->mutex);
    524   1.3    oster 		}
    525   1.3    oster 		RF_UNLOCK_MUTEX(mcpair->mutex);
    526   1.3    oster 		if (wr_dag_h->status != rf_enable) {
    527   1.3    oster 			RF_ERRORMSG("Unable to correct RAID1 parity in VerifyParity\n");
    528   1.3    oster 			goto done;
    529   1.3    oster 		}
    530   1.3    oster 		ret = RF_PARITY_CORRECTED;
    531   1.3    oster 	}
    532   1.1    oster done:
    533   1.3    oster 	/*
    534   1.3    oster          * All done. We might've gotten here without doing part of the function,
    535   1.3    oster          * so cleanup what we have to and return our running status.
    536   1.3    oster          */
    537   1.3    oster 	if (asm_h)
    538   1.3    oster 		rf_FreeAccessStripeMap(asm_h);
    539   1.3    oster 	if (rd_dag_h)
    540   1.3    oster 		rf_FreeDAG(rd_dag_h);
    541   1.3    oster 	if (wr_dag_h)
    542   1.3    oster 		rf_FreeDAG(wr_dag_h);
    543   1.3    oster 	if (mcpair)
    544   1.3    oster 		rf_FreeMCPair(mcpair);
    545   1.3    oster 	rf_FreeAllocList(allocList);
    546  1.10    oster #if RF_DEBUG_VERIFYPARITY
    547   1.3    oster 	if (rf_verifyParityDebug) {
    548   1.5    oster 		printf("raid%d: RAID1 parity verify, returning %d\n",
    549   1.5    oster 		       raidPtr->raidid, ret);
    550   1.3    oster 	}
    551  1.10    oster #endif
    552   1.3    oster 	return (ret);
    553   1.1    oster }
    554   1.1    oster 
    555   1.3    oster int
    556   1.3    oster rf_SubmitReconBufferRAID1(rbuf, keep_it, use_committed)
    557   1.3    oster 	RF_ReconBuffer_t *rbuf;	/* the recon buffer to submit */
    558   1.3    oster 	int     keep_it;	/* whether we can keep this buffer or we have
    559   1.3    oster 				 * to return it */
    560   1.3    oster 	int     use_committed;	/* whether to use a committed or an available
    561   1.3    oster 				 * recon buffer */
    562   1.1    oster {
    563   1.3    oster 	RF_ReconParityStripeStatus_t *pssPtr;
    564   1.3    oster 	RF_ReconCtrl_t *reconCtrlPtr;
    565   1.5    oster 	int     retcode, created;
    566   1.3    oster 	RF_CallbackDesc_t *cb, *p;
    567   1.3    oster 	RF_ReconBuffer_t *t;
    568   1.3    oster 	RF_Raid_t *raidPtr;
    569   1.3    oster 	caddr_t ta;
    570   1.3    oster 
    571   1.3    oster 	retcode = 0;
    572   1.3    oster 	created = 0;
    573   1.3    oster 
    574   1.3    oster 	raidPtr = rbuf->raidPtr;
    575   1.3    oster 	reconCtrlPtr = raidPtr->reconControl[rbuf->row];
    576   1.3    oster 
    577   1.3    oster 	RF_ASSERT(rbuf);
    578   1.3    oster 	RF_ASSERT(rbuf->col != reconCtrlPtr->fcol);
    579   1.3    oster 
    580  1.11    oster #if RF_DEBUG_RECON
    581   1.3    oster 	if (rf_reconbufferDebug) {
    582   1.5    oster 		printf("raid%d: RAID1 reconbuffer submission r%d c%d psid %ld ru%d (failed offset %ld)\n",
    583   1.5    oster 		       raidPtr->raidid, rbuf->row, rbuf->col,
    584   1.5    oster 		       (long) rbuf->parityStripeID, rbuf->which_ru,
    585   1.5    oster 		       (long) rbuf->failedDiskSectorOffset);
    586   1.3    oster 	}
    587  1.10    oster #endif
    588   1.3    oster 	if (rf_reconDebug) {
    589   1.3    oster 		printf("RAID1 reconbuffer submit psid %ld buf %lx\n",
    590   1.3    oster 		    (long) rbuf->parityStripeID, (long) rbuf->buffer);
    591   1.3    oster 		printf("RAID1 psid %ld   %02x %02x %02x %02x %02x\n",
    592   1.3    oster 		    (long) rbuf->parityStripeID,
    593   1.3    oster 		    rbuf->buffer[0], rbuf->buffer[1], rbuf->buffer[2], rbuf->buffer[3],
    594   1.3    oster 		    rbuf->buffer[4]);
    595   1.3    oster 	}
    596   1.3    oster 	RF_LOCK_PSS_MUTEX(raidPtr, rbuf->row, rbuf->parityStripeID);
    597   1.3    oster 
    598   1.3    oster 	RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
    599   1.3    oster 
    600   1.3    oster 	pssPtr = rf_LookupRUStatus(raidPtr, reconCtrlPtr->pssTable,
    601   1.3    oster 	    rbuf->parityStripeID, rbuf->which_ru, RF_PSS_NONE, &created);
    602   1.3    oster 	RF_ASSERT(pssPtr);	/* if it didn't exist, we wouldn't have gotten
    603   1.3    oster 				 * an rbuf for it */
    604   1.3    oster 
    605   1.3    oster 	/*
    606   1.3    oster          * Since this is simple mirroring, the first submission for a stripe is also
    607   1.3    oster          * treated as the last.
    608   1.3    oster          */
    609   1.3    oster 
    610   1.3    oster 	t = NULL;
    611   1.3    oster 	if (keep_it) {
    612  1.11    oster #if RF_DEBUG_RECON
    613   1.3    oster 		if (rf_reconbufferDebug) {
    614   1.5    oster 			printf("raid%d: RAID1 rbuf submission: keeping rbuf\n",
    615   1.5    oster 			       raidPtr->raidid);
    616   1.3    oster 		}
    617  1.10    oster #endif
    618   1.3    oster 		t = rbuf;
    619   1.3    oster 	} else {
    620   1.3    oster 		if (use_committed) {
    621  1.11    oster #if RF_DEBUG_RECON
    622   1.3    oster 			if (rf_reconbufferDebug) {
    623   1.5    oster 				printf("raid%d: RAID1 rbuf submission: using committed rbuf\n", raidPtr->raidid);
    624   1.3    oster 			}
    625  1.10    oster #endif
    626   1.3    oster 			t = reconCtrlPtr->committedRbufs;
    627   1.3    oster 			RF_ASSERT(t);
    628   1.3    oster 			reconCtrlPtr->committedRbufs = t->next;
    629   1.3    oster 			t->next = NULL;
    630   1.3    oster 		} else
    631   1.3    oster 			if (reconCtrlPtr->floatingRbufs) {
    632  1.11    oster #if RF_DEBUG_RECON
    633   1.3    oster 				if (rf_reconbufferDebug) {
    634   1.5    oster 					printf("raid%d: RAID1 rbuf submission: using floating rbuf\n", raidPtr->raidid);
    635   1.3    oster 				}
    636  1.10    oster #endif
    637   1.3    oster 				t = reconCtrlPtr->floatingRbufs;
    638   1.3    oster 				reconCtrlPtr->floatingRbufs = t->next;
    639   1.3    oster 				t->next = NULL;
    640   1.3    oster 			}
    641   1.3    oster 	}
    642   1.3    oster 	if (t == NULL) {
    643  1.11    oster #if RF_DEBUG_RECON
    644   1.3    oster 		if (rf_reconbufferDebug) {
    645   1.5    oster 			printf("raid%d: RAID1 rbuf submission: waiting for rbuf\n", raidPtr->raidid);
    646   1.3    oster 		}
    647  1.10    oster #endif
    648   1.3    oster 		RF_ASSERT((keep_it == 0) && (use_committed == 0));
    649   1.3    oster 		raidPtr->procsInBufWait++;
    650   1.3    oster 		if ((raidPtr->procsInBufWait == (raidPtr->numCol - 1))
    651   1.3    oster 		    && (raidPtr->numFullReconBuffers == 0)) {
    652   1.3    oster 			/* ruh-ro */
    653   1.3    oster 			RF_ERRORMSG("Buffer wait deadlock\n");
    654   1.3    oster 			rf_PrintPSStatusTable(raidPtr, rbuf->row);
    655   1.3    oster 			RF_PANIC();
    656   1.3    oster 		}
    657   1.3    oster 		pssPtr->flags |= RF_PSS_BUFFERWAIT;
    658   1.3    oster 		cb = rf_AllocCallbackDesc();
    659   1.3    oster 		cb->row = rbuf->row;
    660   1.3    oster 		cb->col = rbuf->col;
    661   1.3    oster 		cb->callbackArg.v = rbuf->parityStripeID;
    662   1.3    oster 		cb->callbackArg2.v = rbuf->which_ru;
    663   1.3    oster 		cb->next = NULL;
    664   1.3    oster 		if (reconCtrlPtr->bufferWaitList == NULL) {
    665   1.3    oster 			/* we are the wait list- lucky us */
    666   1.3    oster 			reconCtrlPtr->bufferWaitList = cb;
    667   1.3    oster 		} else {
    668   1.3    oster 			/* append to wait list */
    669   1.3    oster 			for (p = reconCtrlPtr->bufferWaitList; p->next; p = p->next);
    670   1.3    oster 			p->next = cb;
    671   1.3    oster 		}
    672   1.3    oster 		retcode = 1;
    673   1.3    oster 		goto out;
    674   1.3    oster 	}
    675   1.3    oster 	if (t != rbuf) {
    676   1.3    oster 		t->row = rbuf->row;
    677   1.3    oster 		t->col = reconCtrlPtr->fcol;
    678   1.3    oster 		t->parityStripeID = rbuf->parityStripeID;
    679   1.3    oster 		t->which_ru = rbuf->which_ru;
    680   1.3    oster 		t->failedDiskSectorOffset = rbuf->failedDiskSectorOffset;
    681   1.3    oster 		t->spRow = rbuf->spRow;
    682   1.3    oster 		t->spCol = rbuf->spCol;
    683   1.3    oster 		t->spOffset = rbuf->spOffset;
    684   1.3    oster 		/* Swap buffers. DANCE! */
    685   1.3    oster 		ta = t->buffer;
    686   1.3    oster 		t->buffer = rbuf->buffer;
    687   1.3    oster 		rbuf->buffer = ta;
    688   1.3    oster 	}
    689   1.3    oster 	/*
    690   1.3    oster          * Use the rbuf we've been given as the target.
    691   1.3    oster          */
    692   1.3    oster 	RF_ASSERT(pssPtr->rbuf == NULL);
    693   1.3    oster 	pssPtr->rbuf = t;
    694   1.3    oster 
    695   1.3    oster 	t->count = 1;
    696   1.3    oster 	/*
    697   1.3    oster          * Below, we use 1 for numDataCol (which is equal to the count in the
    698   1.3    oster          * previous line), so we'll always be done.
    699   1.3    oster          */
    700   1.3    oster 	rf_CheckForFullRbuf(raidPtr, reconCtrlPtr, pssPtr, 1);
    701   1.1    oster 
    702   1.1    oster out:
    703   1.3    oster 	RF_UNLOCK_PSS_MUTEX(raidPtr, rbuf->row, rbuf->parityStripeID);
    704   1.3    oster 	RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
    705  1.11    oster #if RF_DEBUG_RECON
    706   1.3    oster 	if (rf_reconbufferDebug) {
    707   1.5    oster 		printf("raid%d: RAID1 rbuf submission: returning %d\n",
    708   1.5    oster 		       raidPtr->raidid, retcode);
    709   1.3    oster 	}
    710  1.10    oster #endif
    711   1.3    oster 	return (retcode);
    712   1.1    oster }
    713