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