Home | History | Annotate | Line # | Download | only in raidframe
rf_parityscan.c revision 1.37
      1  1.37     oster /*	$NetBSD: rf_parityscan.c,v 1.37 2021/07/23 00:54:45 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: Mark Holland
      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_parityscan.c -- misc utilities related to parity verification
     32   1.1     oster  *
     33  1.22     oster  ****************************************************************************/
     34  1.12     lukem 
     35  1.12     lukem #include <sys/cdefs.h>
     36  1.37     oster __KERNEL_RCSID(0, "$NetBSD: rf_parityscan.c,v 1.37 2021/07/23 00:54:45 oster Exp $");
     37   1.1     oster 
     38  1.11     oster #include <dev/raidframe/raidframevar.h>
     39  1.11     oster 
     40   1.1     oster #include "rf_raid.h"
     41   1.1     oster #include "rf_dag.h"
     42   1.1     oster #include "rf_dagfuncs.h"
     43   1.1     oster #include "rf_dagutils.h"
     44   1.1     oster #include "rf_mcpair.h"
     45   1.1     oster #include "rf_general.h"
     46   1.1     oster #include "rf_engine.h"
     47   1.1     oster #include "rf_parityscan.h"
     48   1.1     oster #include "rf_map.h"
     49  1.33       jld #include "rf_paritymap.h"
     50   1.1     oster 
     51  1.22     oster /*****************************************************************************
     52   1.1     oster  *
     53  1.22     oster  * walk through the entire arry and write new parity.  This works by
     54  1.22     oster  * creating two DAGs, one to read a stripe of data and one to write
     55  1.22     oster  * new parity.  The first is executed, the data is xored together, and
     56  1.22     oster  * then the second is executed.  To avoid constantly building and
     57  1.22     oster  * tearing down the DAGs, we create them a priori and fill them in
     58  1.22     oster  * with the mapping information as we go along.
     59   1.1     oster  *
     60   1.1     oster  * there should never be more than one thread running this.
     61   1.1     oster  *
     62  1.22     oster  ****************************************************************************/
     63   1.1     oster 
     64  1.28     perry int
     65  1.22     oster rf_RewriteParity(RF_Raid_t *raidPtr)
     66   1.1     oster {
     67  1.33       jld 	if (raidPtr->parity_map != NULL)
     68  1.33       jld 		return rf_paritymap_rewrite(raidPtr->parity_map);
     69  1.33       jld 	else
     70  1.33       jld 		return rf_RewriteParityRange(raidPtr, 0, raidPtr->totalSectors);
     71  1.33       jld }
     72  1.33       jld 
     73  1.33       jld int
     74  1.33       jld rf_RewriteParityRange(RF_Raid_t *raidPtr, RF_SectorNum_t sec_begin,
     75  1.33       jld     RF_SectorNum_t sec_len)
     76  1.33       jld {
     77  1.33       jld 	/*
     78  1.33       jld 	 * Note: It is the caller's responsibility to ensure that
     79  1.33       jld 	 * sec_begin and sec_len are stripe-aligned.
     80  1.33       jld 	 */
     81   1.3     oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
     82   1.3     oster 	RF_AccessStripeMapHeader_t *asm_h;
     83   1.6     oster 	int ret_val;
     84   1.4     oster 	int rc;
     85   1.3     oster 	RF_SectorNum_t i;
     86   1.5     oster 
     87   1.5     oster 	if (raidPtr->Layout.map->faultsTolerated == 0) {
     88   1.5     oster 		/* There isn't any parity. Call it "okay." */
     89   1.5     oster 		return (RF_PARITY_OKAY);
     90   1.5     oster 	}
     91  1.19     oster 	if (raidPtr->status != rf_rs_optimal) {
     92   1.5     oster 		/*
     93  1.28     perry 		 * We're in degraded mode.  Don't try to verify parity now!
     94  1.28     perry 		 * XXX: this should be a "we don't want to", not a
     95  1.28     perry 		 * "we can't" error.
     96   1.5     oster 		 */
     97   1.5     oster 		return (RF_PARITY_COULD_NOT_VERIFY);
     98   1.5     oster 	}
     99   1.3     oster 
    100   1.6     oster 	ret_val = 0;
    101   1.6     oster 
    102   1.6     oster 	rc = RF_PARITY_OKAY;
    103   1.1     oster 
    104  1.33       jld 	for (i = sec_begin; i < sec_begin + sec_len &&
    105  1.28     perry 		     rc <= RF_PARITY_CORRECTED;
    106   1.4     oster 	     i += layoutPtr->dataSectorsPerStripe) {
    107   1.9     oster 		if (raidPtr->waitShutdown) {
    108   1.9     oster 			/* Someone is pulling the plug on this set...
    109   1.9     oster 			   abort the re-write */
    110   1.9     oster 			return (1);
    111   1.9     oster 		}
    112  1.28     perry 		asm_h = rf_MapAccess(raidPtr, i,
    113  1.28     perry 				     layoutPtr->dataSectorsPerStripe,
    114   1.4     oster 				     NULL, RF_DONT_REMAP);
    115  1.28     perry 		raidPtr->parity_rewrite_stripes_done =
    116   1.8     oster 			i / layoutPtr->dataSectorsPerStripe ;
    117   1.3     oster 		rc = rf_VerifyParity(raidPtr, asm_h->stripeMap, 1, 0);
    118   1.4     oster 
    119   1.3     oster 		switch (rc) {
    120   1.3     oster 		case RF_PARITY_OKAY:
    121   1.3     oster 		case RF_PARITY_CORRECTED:
    122   1.3     oster 			break;
    123   1.3     oster 		case RF_PARITY_BAD:
    124   1.3     oster 			printf("Parity bad during correction\n");
    125   1.6     oster 			ret_val = 1;
    126   1.3     oster 			break;
    127   1.3     oster 		case RF_PARITY_COULD_NOT_CORRECT:
    128   1.3     oster 			printf("Could not correct bad parity\n");
    129   1.6     oster 			ret_val = 1;
    130   1.3     oster 			break;
    131   1.3     oster 		case RF_PARITY_COULD_NOT_VERIFY:
    132   1.3     oster 			printf("Could not verify parity\n");
    133   1.6     oster 			ret_val = 1;
    134   1.3     oster 			break;
    135   1.3     oster 		default:
    136   1.3     oster 			printf("Bad rc=%d from VerifyParity in RewriteParity\n", rc);
    137   1.6     oster 			ret_val = 1;
    138   1.3     oster 		}
    139  1.37     oster 		rf_FreeAccessStripeMap(raidPtr, asm_h);
    140   1.3     oster 	}
    141   1.6     oster 	return (ret_val);
    142   1.1     oster }
    143  1.22     oster /*****************************************************************************
    144   1.1     oster  *
    145  1.22     oster  * verify that the parity in a particular stripe is correct.  we
    146  1.22     oster  * validate only the range of parity defined by parityPDA, since this
    147  1.22     oster  * is all we have locked.  The way we do this is to create an asm that
    148  1.22     oster  * maps the whole stripe and then range-restrict it to the parity
    149   1.1     oster  * region defined by the parityPDA.
    150   1.1     oster  *
    151  1.22     oster  ****************************************************************************/
    152  1.28     perry int
    153  1.22     oster rf_VerifyParity(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *aasm,
    154  1.22     oster 		int correct_it, RF_RaidAccessFlags_t flags)
    155   1.1     oster {
    156   1.3     oster 	RF_PhysDiskAddr_t *parityPDA;
    157   1.3     oster 	RF_AccessStripeMap_t *doasm;
    158  1.18  jdolecek 	const RF_LayoutSW_t *lp;
    159   1.3     oster 	int     lrc, rc;
    160   1.3     oster 
    161   1.3     oster 	lp = raidPtr->Layout.map;
    162   1.3     oster 	if (lp->faultsTolerated == 0) {
    163   1.3     oster 		/*
    164   1.3     oster 	         * There isn't any parity. Call it "okay."
    165   1.3     oster 	         */
    166   1.3     oster 		return (RF_PARITY_OKAY);
    167   1.3     oster 	}
    168   1.3     oster 	rc = RF_PARITY_OKAY;
    169   1.3     oster 	if (lp->VerifyParity) {
    170   1.3     oster 		for (doasm = aasm; doasm; doasm = doasm->next) {
    171  1.28     perry 			for (parityPDA = doasm->parityInfo; parityPDA;
    172   1.4     oster 			     parityPDA = parityPDA->next) {
    173  1.28     perry 				lrc = lp->VerifyParity(raidPtr,
    174  1.28     perry 						       doasm->raidAddress,
    175   1.4     oster 						       parityPDA,
    176   1.4     oster 						       correct_it, flags);
    177   1.3     oster 				if (lrc > rc) {
    178   1.3     oster 					/* see rf_parityscan.h for why this
    179   1.3     oster 					 * works */
    180   1.3     oster 					rc = lrc;
    181   1.3     oster 				}
    182   1.3     oster 			}
    183   1.3     oster 		}
    184   1.3     oster 	} else {
    185   1.3     oster 		rc = RF_PARITY_COULD_NOT_VERIFY;
    186   1.3     oster 	}
    187   1.3     oster 	return (rc);
    188   1.1     oster }
    189   1.1     oster 
    190  1.28     perry int
    191  1.22     oster rf_VerifyParityBasic(RF_Raid_t *raidPtr, RF_RaidAddr_t raidAddr,
    192  1.22     oster 		     RF_PhysDiskAddr_t *parityPDA, int correct_it,
    193  1.22     oster 		     RF_RaidAccessFlags_t flags)
    194   1.1     oster {
    195   1.3     oster 	RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
    196   1.4     oster 	RF_RaidAddr_t startAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr,
    197   1.4     oster 								     raidAddr);
    198   1.3     oster 	RF_SectorCount_t numsector = parityPDA->numSector;
    199   1.3     oster 	int     numbytes = rf_RaidAddressToByte(raidPtr, numsector);
    200   1.3     oster 	int     bytesPerStripe = numbytes * layoutPtr->numDataCol;
    201   1.3     oster 	RF_DagHeader_t *rd_dag_h, *wr_dag_h;	/* read, write dag */
    202  1.16     oster 	RF_DagNode_t *blockNode, *wrBlock;
    203   1.3     oster 	RF_AccessStripeMapHeader_t *asm_h;
    204   1.3     oster 	RF_AccessStripeMap_t *asmap;
    205   1.3     oster 	RF_AllocListElem_t *alloclist;
    206   1.3     oster 	RF_PhysDiskAddr_t *pda;
    207  1.29  christos 	char   *pbuf, *bf, *end_p, *p;
    208   1.3     oster 	int     i, retcode;
    209   1.3     oster 	RF_ReconUnitNum_t which_ru;
    210  1.28     perry 	RF_StripeNum_t psID = rf_RaidAddressToParityStripeID(layoutPtr,
    211  1.28     perry 							     raidAddr,
    212   1.4     oster 							     &which_ru);
    213   1.3     oster 	int     stripeWidth = layoutPtr->numDataCol + layoutPtr->numParityCol;
    214  1.24     oster #if RF_ACC_TRACE > 0
    215   1.3     oster 	RF_AccTraceEntry_t tracerec;
    216  1.24     oster #endif
    217   1.3     oster 	RF_MCPair_t *mcpair;
    218   1.3     oster 
    219   1.3     oster 	retcode = RF_PARITY_OKAY;
    220   1.3     oster 
    221  1.37     oster 	mcpair = rf_AllocMCPair(raidPtr);
    222   1.3     oster 	rf_MakeAllocList(alloclist);
    223  1.35  christos 	bf = RF_MallocAndAdd(numbytes
    224  1.35  christos 	    * (layoutPtr->numDataCol + layoutPtr->numParityCol), alloclist);
    225  1.35  christos 	pbuf = RF_MallocAndAdd(numbytes, alloclist);
    226  1.29  christos 	end_p = bf + bytesPerStripe;
    227   1.3     oster 
    228  1.29  christos 	rd_dag_h = rf_MakeSimpleDAG(raidPtr, stripeWidth, numbytes, bf, rf_DiskReadFunc, rf_DiskReadUndoFunc,
    229   1.3     oster 	    "Rod", alloclist, flags, RF_IO_NORMAL_PRIORITY);
    230   1.3     oster 	blockNode = rd_dag_h->succedents[0];
    231   1.3     oster 
    232   1.3     oster 	/* map the stripe and fill in the PDAs in the dag */
    233  1.29  christos 	asm_h = rf_MapAccess(raidPtr, startAddr, layoutPtr->dataSectorsPerStripe, bf, RF_DONT_REMAP);
    234   1.3     oster 	asmap = asm_h->stripeMap;
    235   1.3     oster 
    236   1.3     oster 	for (pda = asmap->physInfo, i = 0; i < layoutPtr->numDataCol; i++, pda = pda->next) {
    237   1.3     oster 		RF_ASSERT(pda);
    238   1.3     oster 		rf_RangeRestrictPDA(raidPtr, parityPDA, pda, 0, 1);
    239   1.3     oster 		RF_ASSERT(pda->numSector != 0);
    240   1.3     oster 		if (rf_TryToRedirectPDA(raidPtr, pda, 0))
    241   1.3     oster 			goto out;	/* no way to verify parity if disk is
    242   1.3     oster 					 * dead.  return w/ good status */
    243   1.3     oster 		blockNode->succedents[i]->params[0].p = pda;
    244   1.3     oster 		blockNode->succedents[i]->params[2].v = psID;
    245  1.23     oster 		blockNode->succedents[i]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
    246   1.3     oster 	}
    247   1.3     oster 
    248   1.3     oster 	RF_ASSERT(!asmap->parityInfo->next);
    249   1.3     oster 	rf_RangeRestrictPDA(raidPtr, parityPDA, asmap->parityInfo, 0, 1);
    250   1.3     oster 	RF_ASSERT(asmap->parityInfo->numSector != 0);
    251   1.3     oster 	if (rf_TryToRedirectPDA(raidPtr, asmap->parityInfo, 1))
    252   1.3     oster 		goto out;
    253   1.3     oster 	blockNode->succedents[layoutPtr->numDataCol]->params[0].p = asmap->parityInfo;
    254   1.3     oster 
    255   1.3     oster 	/* fire off the DAG */
    256  1.24     oster #if RF_ACC_TRACE > 0
    257  1.35  christos 	memset(&tracerec, 0, sizeof(tracerec));
    258   1.3     oster 	rd_dag_h->tracerec = &tracerec;
    259  1.24     oster #endif
    260  1.13     oster #if 0
    261   1.3     oster 	if (rf_verifyParityDebug) {
    262   1.3     oster 		printf("Parity verify read dag:\n");
    263   1.3     oster 		rf_PrintDAGList(rd_dag_h);
    264   1.3     oster 	}
    265  1.13     oster #endif
    266  1.34       mrg 	RF_LOCK_MCPAIR(mcpair);
    267   1.3     oster 	mcpair->flag = 0;
    268  1.34       mrg 	RF_UNLOCK_MCPAIR(mcpair);
    269  1.25     oster 
    270   1.3     oster 	rf_DispatchDAG(rd_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
    271   1.3     oster 	    (void *) mcpair);
    272  1.25     oster 
    273  1.34       mrg 	RF_LOCK_MCPAIR(mcpair);
    274   1.3     oster 	while (!mcpair->flag)
    275  1.34       mrg 		RF_WAIT_MCPAIR(mcpair);
    276  1.34       mrg 	RF_UNLOCK_MCPAIR(mcpair);
    277   1.3     oster 	if (rd_dag_h->status != rf_enable) {
    278   1.3     oster 		RF_ERRORMSG("Unable to verify parity:  can't read the stripe\n");
    279   1.3     oster 		retcode = RF_PARITY_COULD_NOT_VERIFY;
    280   1.3     oster 		goto out;
    281   1.3     oster 	}
    282  1.29  christos 	for (p = bf; p < end_p; p += numbytes) {
    283  1.21     oster 		rf_bxor(p, pbuf, numbytes);
    284   1.3     oster 	}
    285   1.3     oster 	for (i = 0; i < numbytes; i++) {
    286  1.29  christos 		if (pbuf[i] != bf[bytesPerStripe + i]) {
    287   1.3     oster 			if (!correct_it)
    288   1.3     oster 				RF_ERRORMSG3("Parity verify error: byte %d of parity is 0x%x should be 0x%x\n",
    289  1.29  christos 				    i, (u_char) bf[bytesPerStripe + i], (u_char) pbuf[i]);
    290   1.3     oster 			retcode = RF_PARITY_BAD;
    291   1.3     oster 			break;
    292   1.3     oster 		}
    293   1.3     oster 	}
    294   1.1     oster 
    295   1.3     oster 	if (retcode && correct_it) {
    296   1.3     oster 		wr_dag_h = rf_MakeSimpleDAG(raidPtr, 1, numbytes, pbuf, rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
    297   1.3     oster 		    "Wnp", alloclist, flags, RF_IO_NORMAL_PRIORITY);
    298   1.3     oster 		wrBlock = wr_dag_h->succedents[0];
    299   1.3     oster 		wrBlock->succedents[0]->params[0].p = asmap->parityInfo;
    300   1.3     oster 		wrBlock->succedents[0]->params[2].v = psID;
    301  1.23     oster 		wrBlock->succedents[0]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, which_ru);
    302  1.24     oster #if RF_ACC_TRACE > 0
    303  1.35  christos 		memset(&tracerec, 0, sizeof(tracerec));
    304   1.3     oster 		wr_dag_h->tracerec = &tracerec;
    305  1.24     oster #endif
    306  1.13     oster #if 0
    307   1.3     oster 		if (rf_verifyParityDebug) {
    308   1.3     oster 			printf("Parity verify write dag:\n");
    309   1.3     oster 			rf_PrintDAGList(wr_dag_h);
    310   1.3     oster 		}
    311  1.13     oster #endif
    312  1.34       mrg 		RF_LOCK_MCPAIR(mcpair);
    313   1.3     oster 		mcpair->flag = 0;
    314  1.34       mrg 		RF_UNLOCK_MCPAIR(mcpair);
    315  1.25     oster 
    316   1.3     oster 		rf_DispatchDAG(wr_dag_h, (void (*) (void *)) rf_MCPairWakeupFunc,
    317   1.3     oster 		    (void *) mcpair);
    318  1.25     oster 
    319  1.34       mrg 		RF_LOCK_MCPAIR(mcpair);
    320   1.3     oster 		while (!mcpair->flag)
    321  1.34       mrg 			RF_WAIT_MCPAIR(mcpair);
    322  1.34       mrg 		RF_UNLOCK_MCPAIR(mcpair);
    323   1.3     oster 		if (wr_dag_h->status != rf_enable) {
    324   1.3     oster 			RF_ERRORMSG("Unable to correct parity in VerifyParity:  can't write the stripe\n");
    325   1.3     oster 			retcode = RF_PARITY_COULD_NOT_CORRECT;
    326   1.3     oster 		}
    327   1.3     oster 		rf_FreeDAG(wr_dag_h);
    328   1.3     oster 		if (retcode == RF_PARITY_BAD)
    329   1.3     oster 			retcode = RF_PARITY_CORRECTED;
    330   1.3     oster 	}
    331   1.1     oster out:
    332  1.37     oster 	rf_FreeAccessStripeMap(raidPtr, asm_h);
    333   1.3     oster 	rf_FreeAllocList(alloclist);
    334   1.3     oster 	rf_FreeDAG(rd_dag_h);
    335  1.37     oster 	rf_FreeMCPair(raidPtr, mcpair);
    336   1.3     oster 	return (retcode);
    337   1.1     oster }
    338   1.1     oster 
    339  1.28     perry int
    340  1.31  christos rf_TryToRedirectPDA(RF_Raid_t *raidPtr, RF_PhysDiskAddr_t *pda,
    341  1.32  christos     int parity)
    342   1.1     oster {
    343  1.19     oster 	if (raidPtr->Disks[pda->col].status == rf_ds_reconstructing) {
    344  1.19     oster 		if (rf_CheckRUReconstructed(raidPtr->reconControl->reconMap, pda->startSector)) {
    345  1.26     oster #if RF_INCLUDE_PARITY_DECLUSTERING_DS > 0
    346   1.3     oster 			if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
    347  1.14     oster #if RF_DEBUG_VERIFYPARITY
    348  1.19     oster 				RF_RowCol_t oc = pda->col;
    349   1.3     oster 				RF_SectorNum_t os = pda->startSector;
    350  1.14     oster #endif
    351   1.3     oster 				if (parity) {
    352  1.19     oster 					(raidPtr->Layout.map->MapParity) (raidPtr, pda->raidAddress, &pda->col, &pda->startSector, RF_REMAP);
    353  1.14     oster #if RF_DEBUG_VERIFYPARITY
    354   1.3     oster 					if (rf_verifyParityDebug)
    355  1.19     oster 						printf("VerifyParity: Redir P c %d sect %ld -> c %d sect %ld\n",
    356  1.19     oster 						    oc, (long) os, pda->col, (long) pda->startSector);
    357  1.14     oster #endif
    358   1.3     oster 				} else {
    359  1.19     oster 					(raidPtr->Layout.map->MapSector) (raidPtr, pda->raidAddress, &pda->col, &pda->startSector, RF_REMAP);
    360  1.14     oster #if RF_DEBUG_VERIFYPARITY
    361   1.3     oster 					if (rf_verifyParityDebug)
    362  1.19     oster 						printf("VerifyParity: Redir D c %d sect %ld -> c %d sect %ld\n",
    363  1.19     oster 						   oc, (long) os, pda->col, (long) pda->startSector);
    364  1.14     oster #endif
    365   1.3     oster 				}
    366   1.3     oster 			} else {
    367  1.26     oster #endif
    368  1.19     oster 				RF_RowCol_t spCol = raidPtr->Disks[pda->col].spareCol;
    369   1.3     oster 				pda->col = spCol;
    370  1.26     oster #if RF_INCLUDE_PARITY_DECLUSTERING_DS > 0
    371   1.3     oster 			}
    372  1.26     oster #endif
    373   1.3     oster 		}
    374   1.3     oster 	}
    375  1.19     oster 	if (RF_DEAD_DISK(raidPtr->Disks[pda->col].status))
    376   1.3     oster 		return (1);
    377   1.3     oster 	return (0);
    378   1.1     oster }
    379  1.22     oster /*****************************************************************************
    380   1.1     oster  *
    381   1.1     oster  * currently a stub.
    382   1.1     oster  *
    383  1.22     oster  * takes as input an ASM describing a write operation and containing
    384  1.22     oster  * one failure, and verifies that the parity was correctly updated to
    385  1.22     oster  * reflect the write.
    386  1.22     oster  *
    387  1.22     oster  * if it's a data unit that's failed, we read the other data units in
    388  1.22     oster  * the stripe and the parity unit, XOR them together, and verify that
    389  1.22     oster  * we get the data intended for the failed disk.  Since it's easy, we
    390  1.22     oster  * also validate that the right data got written to the surviving data
    391  1.22     oster  * disks.
    392  1.22     oster  *
    393  1.22     oster  * If it's the parity that failed, there's really no validation we can
    394  1.22     oster  * do except the above verification that the right data got written to
    395  1.22     oster  * all disks.  This is because the new data intended for the failed
    396  1.22     oster  * disk is supplied in the ASM, but this is of course not the case for
    397  1.22     oster  * the new parity.
    398   1.1     oster  *
    399  1.22     oster  ****************************************************************************/
    400  1.15     oster #if 0
    401  1.28     perry int
    402  1.22     oster rf_VerifyDegrModeWrite(RF_Raid_t *raidPtr, RF_AccessStripeMapHeader_t *asmh)
    403   1.1     oster {
    404   1.3     oster 	return (0);
    405   1.1     oster }
    406  1.15     oster #endif
    407   1.1     oster /* creates a simple DAG with a header, a block-recon node at level 1,
    408  1.22     oster  * nNodes nodes at level 2, an unblock-recon node at level 3, and a
    409  1.22     oster  * terminator node at level 4.  The stripe address field in the block
    410  1.22     oster  * and unblock nodes are not touched, nor are the pda fields in the
    411  1.22     oster  * second-level nodes, so they must be filled in later.
    412   1.1     oster  *
    413   1.1     oster  * commit point is established at unblock node - this means that any
    414  1.28     perry  * failure during dag execution causes the dag to fail
    415  1.22     oster  *
    416  1.22     oster  * name - node names at the second level
    417   1.1     oster  */
    418   1.3     oster RF_DagHeader_t *
    419  1.22     oster rf_MakeSimpleDAG(RF_Raid_t *raidPtr, int nNodes, int bytesPerSU, char *databuf,
    420  1.36  christos 		 void (*doFunc) (RF_DagNode_t * node),
    421  1.36  christos 		 void (*undoFunc) (RF_DagNode_t * node),
    422  1.29  christos 		 const char *name, RF_AllocListElem_t *alloclist,
    423  1.32  christos 		 RF_RaidAccessFlags_t flags, int priority)
    424   1.1     oster {
    425   1.3     oster 	RF_DagHeader_t *dag_h;
    426  1.27     oster 	RF_DagNode_t *nodes, *termNode, *blockNode, *unblockNode, *tmpNode;
    427   1.3     oster 	int     i;
    428   1.3     oster 
    429  1.27     oster 	/* grab a DAG header... */
    430   1.3     oster 
    431  1.37     oster 	dag_h = rf_AllocDAGHeader(raidPtr);
    432   1.3     oster 	dag_h->raidPtr = (void *) raidPtr;
    433   1.3     oster 	dag_h->allocList = NULL;/* we won't use this alloc list */
    434   1.3     oster 	dag_h->status = rf_enable;
    435   1.3     oster 	dag_h->numSuccedents = 1;
    436   1.3     oster 	dag_h->creator = "SimpleDAG";
    437   1.3     oster 
    438   1.3     oster 	/* this dag can not commit until the unblock node is reached errors
    439   1.3     oster 	 * prior to the commit point imply the dag has failed */
    440   1.3     oster 	dag_h->numCommitNodes = 1;
    441   1.3     oster 	dag_h->numCommits = 0;
    442   1.3     oster 
    443  1.27     oster 	/* create the nodes, the block & unblock nodes, and the terminator
    444  1.27     oster 	 * node */
    445  1.27     oster 
    446  1.27     oster 	for (i = 0; i < nNodes; i++) {
    447  1.37     oster 		tmpNode = rf_AllocDAGNode(raidPtr);
    448  1.27     oster 		tmpNode->list_next = dag_h->nodes;
    449  1.27     oster 		dag_h->nodes = tmpNode;
    450  1.27     oster 	}
    451  1.27     oster 	nodes = dag_h->nodes;
    452  1.27     oster 
    453  1.37     oster 	blockNode = rf_AllocDAGNode(raidPtr);
    454  1.27     oster 	blockNode->list_next = dag_h->nodes;
    455  1.27     oster 	dag_h->nodes = blockNode;
    456  1.27     oster 
    457  1.37     oster 	unblockNode = rf_AllocDAGNode(raidPtr);
    458  1.27     oster 	unblockNode->list_next = dag_h->nodes;
    459  1.27     oster 	dag_h->nodes = unblockNode;
    460  1.27     oster 
    461  1.37     oster 	termNode = rf_AllocDAGNode(raidPtr);
    462  1.27     oster 	termNode->list_next = dag_h->nodes;
    463  1.27     oster 	dag_h->nodes = termNode;
    464  1.27     oster 
    465   1.3     oster 	dag_h->succedents[0] = blockNode;
    466   1.3     oster 	rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, nNodes, 0, 0, 0, dag_h, "Nil", alloclist);
    467   1.3     oster 	rf_InitNode(unblockNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, 1, nNodes, 0, 0, dag_h, "Nil", alloclist);
    468   1.3     oster 	unblockNode->succedents[0] = termNode;
    469  1.27     oster 	tmpNode = nodes;
    470   1.3     oster 	for (i = 0; i < nNodes; i++) {
    471  1.27     oster 		blockNode->succedents[i] = unblockNode->antecedents[i] = tmpNode;
    472   1.3     oster 		unblockNode->antType[i] = rf_control;
    473  1.27     oster 		rf_InitNode(tmpNode, rf_wait, RF_FALSE, doFunc, undoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, name, alloclist);
    474  1.27     oster 		tmpNode->succedents[0] = unblockNode;
    475  1.27     oster 		tmpNode->antecedents[0] = blockNode;
    476  1.27     oster 		tmpNode->antType[0] = rf_control;
    477  1.27     oster 		tmpNode->params[1].p = (databuf + (i * bytesPerSU));
    478  1.27     oster 		tmpNode = tmpNode->list_next;
    479   1.3     oster 	}
    480   1.3     oster 	rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc, NULL, 0, 1, 0, 0, dag_h, "Trm", alloclist);
    481   1.3     oster 	termNode->antecedents[0] = unblockNode;
    482   1.3     oster 	termNode->antType[0] = rf_control;
    483   1.3     oster 	return (dag_h);
    484   1.1     oster }
    485