Home | History | Annotate | Line # | Download | only in raidframe
rf_parityscan.c revision 1.2
      1  1.2  oster /*	$NetBSD: rf_parityscan.c,v 1.2 1999/01/26 02:34:00 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.1  oster  *****************************************************************************/
     34  1.1  oster 
     35  1.1  oster #include "rf_types.h"
     36  1.1  oster #include "rf_raid.h"
     37  1.1  oster #include "rf_dag.h"
     38  1.1  oster #include "rf_dagfuncs.h"
     39  1.1  oster #include "rf_dagutils.h"
     40  1.1  oster #include "rf_mcpair.h"
     41  1.1  oster #include "rf_general.h"
     42  1.1  oster #include "rf_engine.h"
     43  1.1  oster #include "rf_parityscan.h"
     44  1.1  oster #include "rf_map.h"
     45  1.1  oster #include "rf_sys.h"
     46  1.1  oster 
     47  1.1  oster /*****************************************************************************************
     48  1.1  oster  *
     49  1.1  oster  * walk through the entire arry and write new parity.
     50  1.1  oster  * This works by creating two DAGs, one to read a stripe of data and one to
     51  1.1  oster  * write new parity.  The first is executed, the data is xored together, and
     52  1.1  oster  * then the second is executed.  To avoid constantly building and tearing down
     53  1.1  oster  * the DAGs, we create them a priori and fill them in with the mapping
     54  1.1  oster  * information as we go along.
     55  1.1  oster  *
     56  1.1  oster  * there should never be more than one thread running this.
     57  1.1  oster  *
     58  1.1  oster  ****************************************************************************************/
     59  1.1  oster 
     60  1.1  oster int rf_RewriteParity(raidPtr)
     61  1.1  oster   RF_Raid_t  *raidPtr;
     62  1.1  oster {
     63  1.1  oster   RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
     64  1.1  oster   RF_AccessStripeMapHeader_t *asm_h;
     65  1.1  oster   int old_pctg, new_pctg, rc;
     66  1.1  oster   RF_PhysDiskAddr_t pda;
     67  1.1  oster   RF_SectorNum_t i;
     68  1.1  oster 
     69  1.1  oster   pda.startSector = 0;
     70  1.1  oster   pda.numSector   = raidPtr->Layout.sectorsPerStripeUnit;
     71  1.1  oster   old_pctg = -1;
     72  1.1  oster 
     73  1.1  oster /* rf_verifyParityDebug=1; */
     74  1.1  oster   for (i=0; i<raidPtr->totalSectors; i+=layoutPtr->dataSectorsPerStripe) {
     75  1.1  oster     asm_h = rf_MapAccess(raidPtr, i, layoutPtr->dataSectorsPerStripe, NULL, RF_DONT_REMAP);
     76  1.1  oster     rc = rf_VerifyParity(raidPtr, asm_h->stripeMap, 1, 0);
     77  1.1  oster     /*     printf("Parity verified: rc=%d\n",rc); */
     78  1.1  oster     switch (rc) {
     79  1.1  oster       case RF_PARITY_OKAY:
     80  1.1  oster       case RF_PARITY_CORRECTED:
     81  1.1  oster         break;
     82  1.1  oster       case RF_PARITY_BAD:
     83  1.1  oster         printf("Parity bad during correction\n");
     84  1.1  oster         RF_PANIC();
     85  1.1  oster         break;
     86  1.1  oster       case RF_PARITY_COULD_NOT_CORRECT:
     87  1.1  oster         printf("Could not correct bad parity\n");
     88  1.1  oster         RF_PANIC();
     89  1.1  oster         break;
     90  1.1  oster       case RF_PARITY_COULD_NOT_VERIFY:
     91  1.1  oster         printf("Could not verify parity\n");
     92  1.1  oster         RF_PANIC();
     93  1.1  oster         break;
     94  1.1  oster       default:
     95  1.1  oster         printf("Bad rc=%d from VerifyParity in RewriteParity\n", rc);
     96  1.1  oster         RF_PANIC();
     97  1.1  oster     }
     98  1.1  oster     rf_FreeAccessStripeMap(asm_h);
     99  1.1  oster     new_pctg = i*1000/raidPtr->totalSectors;
    100  1.1  oster     if (new_pctg != old_pctg) {
    101  1.1  oster     }
    102  1.1  oster     old_pctg = new_pctg;
    103  1.1  oster   }
    104  1.1  oster #if 1
    105  1.1  oster   return(0); /* XXX nothing was here.. GO */
    106  1.1  oster #endif
    107  1.1  oster }
    108  1.1  oster 
    109  1.1  oster /*****************************************************************************************
    110  1.1  oster  *
    111  1.1  oster  * verify that the parity in a particular stripe is correct.
    112  1.1  oster  * we validate only the range of parity defined by parityPDA, since
    113  1.1  oster  * this is all we have locked.  The way we do this is to create an asm
    114  1.1  oster  * that maps the whole stripe and then range-restrict it to the parity
    115  1.1  oster  * region defined by the parityPDA.
    116  1.1  oster  *
    117  1.1  oster  ****************************************************************************************/
    118  1.1  oster int rf_VerifyParity(raidPtr, aasm, correct_it, flags)
    119  1.1  oster   RF_Raid_t             *raidPtr;
    120  1.1  oster   RF_AccessStripeMap_t  *aasm;
    121  1.1  oster   int                    correct_it;
    122  1.1  oster   RF_RaidAccessFlags_t   flags;
    123  1.1  oster {
    124  1.1  oster   RF_PhysDiskAddr_t *parityPDA;
    125  1.1  oster   RF_AccessStripeMap_t *doasm;
    126  1.1  oster   RF_LayoutSW_t *lp;
    127  1.1  oster   int lrc, rc;
    128  1.1  oster 
    129  1.1  oster   lp = raidPtr->Layout.map;
    130  1.1  oster   if (lp->faultsTolerated == 0) {
    131  1.1  oster     /*
    132  1.1  oster      * There isn't any parity. Call it "okay."
    133  1.1  oster      */
    134  1.1  oster     return(RF_PARITY_OKAY);
    135  1.1  oster   }
    136  1.1  oster   rc = RF_PARITY_OKAY;
    137  1.1  oster   if (lp->VerifyParity) {
    138  1.1  oster     for(doasm=aasm;doasm;doasm=doasm->next) {
    139  1.1  oster       for(parityPDA=doasm->parityInfo;parityPDA;parityPDA=parityPDA->next) {
    140  1.1  oster         lrc = lp->VerifyParity(raidPtr, doasm->raidAddress, parityPDA,
    141  1.1  oster           correct_it, flags);
    142  1.1  oster         if (lrc > rc) {
    143  1.1  oster           /* see rf_parityscan.h for why this works */
    144  1.1  oster           rc = lrc;
    145  1.1  oster         }
    146  1.1  oster       }
    147  1.1  oster     }
    148  1.1  oster   }
    149  1.1  oster   else {
    150  1.1  oster     rc = RF_PARITY_COULD_NOT_VERIFY;
    151  1.1  oster   }
    152  1.1  oster   return(rc);
    153  1.1  oster }
    154  1.1  oster 
    155  1.1  oster int rf_VerifyParityBasic(raidPtr, raidAddr, parityPDA, correct_it, flags)
    156  1.1  oster   RF_Raid_t             *raidPtr;
    157  1.1  oster   RF_RaidAddr_t          raidAddr;
    158  1.1  oster   RF_PhysDiskAddr_t     *parityPDA;
    159  1.1  oster   int                    correct_it;
    160  1.1  oster   RF_RaidAccessFlags_t   flags;
    161  1.1  oster {
    162  1.1  oster   RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
    163  1.1  oster   RF_RaidAddr_t startAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, raidAddr);
    164  1.1  oster   RF_SectorCount_t numsector = parityPDA->numSector;
    165  1.1  oster   int numbytes  = rf_RaidAddressToByte(raidPtr, numsector);
    166  1.1  oster   int bytesPerStripe = numbytes * layoutPtr->numDataCol;
    167  1.1  oster   RF_DagHeader_t *rd_dag_h, *wr_dag_h;          /* read, write dag */
    168  1.1  oster   RF_DagNode_t *blockNode, *unblockNode, *wrBlock, *wrUnblock;
    169  1.1  oster   RF_AccessStripeMapHeader_t *asm_h;
    170  1.1  oster   RF_AccessStripeMap_t *asmap;
    171  1.1  oster   RF_AllocListElem_t *alloclist;
    172  1.1  oster   RF_PhysDiskAddr_t *pda;
    173  1.1  oster   char *pbuf, *buf, *end_p, *p;
    174  1.1  oster   int i, retcode;
    175  1.1  oster   RF_ReconUnitNum_t which_ru;
    176  1.1  oster   RF_StripeNum_t psID = rf_RaidAddressToParityStripeID(layoutPtr, raidAddr, &which_ru);
    177  1.1  oster   int stripeWidth = layoutPtr->numDataCol + layoutPtr->numParityCol;
    178  1.1  oster   RF_AccTraceEntry_t tracerec;
    179  1.1  oster   RF_MCPair_t *mcpair;
    180  1.1  oster 
    181  1.1  oster   retcode = RF_PARITY_OKAY;
    182  1.1  oster 
    183  1.1  oster   mcpair = rf_AllocMCPair();
    184  1.1  oster   rf_MakeAllocList(alloclist);
    185  1.1  oster   RF_MallocAndAdd(buf, numbytes * (layoutPtr->numDataCol + layoutPtr->numParityCol), (char *), alloclist);
    186  1.1  oster   RF_CallocAndAdd(pbuf, 1, numbytes, (char *), alloclist);     /* use calloc to make sure buffer is zeroed */
    187  1.1  oster   end_p = buf + bytesPerStripe;
    188  1.1  oster 
    189  1.1  oster   rd_dag_h = rf_MakeSimpleDAG(raidPtr, stripeWidth, numbytes, buf, rf_DiskReadFunc, rf_DiskReadUndoFunc,
    190  1.1  oster 			   "Rod", alloclist, flags, RF_IO_NORMAL_PRIORITY);
    191  1.1  oster   blockNode = rd_dag_h->succedents[0];
    192  1.1  oster   unblockNode = blockNode->succedents[0]->succedents[0];
    193  1.1  oster 
    194  1.1  oster   /* map the stripe and fill in the PDAs in the dag */
    195  1.1  oster   asm_h = rf_MapAccess(raidPtr, startAddr, layoutPtr->dataSectorsPerStripe, buf, RF_DONT_REMAP);
    196  1.1  oster   asmap = asm_h->stripeMap;
    197  1.1  oster 
    198  1.1  oster   for (pda=asmap->physInfo,i=0; i<layoutPtr->numDataCol; i++,pda=pda->next) {
    199  1.1  oster     RF_ASSERT(pda);
    200  1.1  oster     rf_RangeRestrictPDA(raidPtr, parityPDA, pda, 0, 1);
    201  1.1  oster     RF_ASSERT(pda->numSector != 0);
    202  1.1  oster     if (rf_TryToRedirectPDA(raidPtr, pda, 0)) goto out;   /* no way to verify parity if disk is dead.  return w/ good status */
    203  1.1  oster     blockNode->succedents[i]->params[0].p = pda;
    204  1.1  oster     blockNode->succedents[i]->params[2].v = psID;
    205  1.1  oster     blockNode->succedents[i]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    206  1.1  oster   }
    207  1.1  oster 
    208  1.1  oster   RF_ASSERT(!asmap->parityInfo->next);
    209  1.1  oster   rf_RangeRestrictPDA(raidPtr, parityPDA, asmap->parityInfo, 0, 1);
    210  1.1  oster   RF_ASSERT(asmap->parityInfo->numSector != 0);
    211  1.1  oster   if (rf_TryToRedirectPDA(raidPtr, asmap->parityInfo, 1))
    212  1.1  oster     goto out;
    213  1.1  oster   blockNode->succedents[layoutPtr->numDataCol]->params[0].p = asmap->parityInfo;
    214  1.1  oster 
    215  1.1  oster   /* fire off the DAG */
    216  1.1  oster   bzero((char *)&tracerec,sizeof(tracerec));
    217  1.1  oster   rd_dag_h->tracerec = &tracerec;
    218  1.1  oster 
    219  1.1  oster   if (rf_verifyParityDebug) {
    220  1.1  oster     printf("Parity verify read dag:\n");
    221  1.1  oster     rf_PrintDAGList(rd_dag_h);
    222  1.1  oster   }
    223  1.1  oster 
    224  1.1  oster   RF_LOCK_MUTEX(mcpair->mutex);
    225  1.1  oster   mcpair->flag = 0;
    226  1.1  oster   rf_DispatchDAG(rd_dag_h, (void (*)(void *))rf_MCPairWakeupFunc,
    227  1.1  oster 		 (void *) mcpair);
    228  1.1  oster   while (!mcpair->flag)
    229  1.1  oster 	  RF_WAIT_COND(mcpair->cond, mcpair->mutex);
    230  1.1  oster   RF_UNLOCK_MUTEX(mcpair->mutex);
    231  1.1  oster   if (rd_dag_h->status != rf_enable) {
    232  1.1  oster     RF_ERRORMSG("Unable to verify parity:  can't read the stripe\n");
    233  1.1  oster     retcode = RF_PARITY_COULD_NOT_VERIFY;
    234  1.1  oster     goto out;
    235  1.1  oster   }
    236  1.1  oster 
    237  1.1  oster   for (p=buf; p<end_p; p+=numbytes) {
    238  1.1  oster     rf_bxor(p, pbuf, numbytes, NULL);
    239  1.1  oster   }
    240  1.1  oster   for (i=0; i<numbytes; i++) {
    241  1.1  oster #if 0
    242  1.1  oster 	  if (pbuf[i]!=0 || buf[bytesPerStripe+i]!=0) {
    243  1.1  oster 	  printf("Bytes: %d %d %d\n",i,pbuf[i],buf[bytesPerStripe+i]);
    244  1.1  oster 	  }
    245  1.1  oster #endif
    246  1.1  oster 	  if (pbuf[i] != buf[bytesPerStripe+i]) {
    247  1.1  oster 		  if (!correct_it)
    248  1.1  oster 			  RF_ERRORMSG3("Parity verify error: byte %d of parity is 0x%x should be 0x%x\n",
    249  1.1  oster 			       i,(u_char) buf[bytesPerStripe+i],(u_char) pbuf[i]);
    250  1.1  oster 		  retcode = RF_PARITY_BAD;
    251  1.1  oster 		  break;
    252  1.1  oster 	  }
    253  1.1  oster   }
    254  1.1  oster 
    255  1.1  oster   if (retcode && correct_it) {
    256  1.1  oster     wr_dag_h = rf_MakeSimpleDAG(raidPtr, 1, numbytes, pbuf, rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
    257  1.1  oster 			     "Wnp", alloclist, flags, RF_IO_NORMAL_PRIORITY);
    258  1.1  oster     wrBlock = wr_dag_h->succedents[0]; wrUnblock = wrBlock->succedents[0]->succedents[0];
    259  1.1  oster     wrBlock->succedents[0]->params[0].p = asmap->parityInfo;
    260  1.1  oster     wrBlock->succedents[0]->params[2].v = psID;
    261  1.1  oster     wrBlock->succedents[0]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    262  1.1  oster     bzero((char *)&tracerec,sizeof(tracerec));
    263  1.1  oster     wr_dag_h->tracerec = &tracerec;
    264  1.1  oster     if (rf_verifyParityDebug) {
    265  1.1  oster       printf("Parity verify write dag:\n");
    266  1.1  oster       rf_PrintDAGList(wr_dag_h);
    267  1.1  oster     }
    268  1.1  oster     RF_LOCK_MUTEX(mcpair->mutex);
    269  1.1  oster     mcpair->flag = 0;
    270  1.1  oster     rf_DispatchDAG(wr_dag_h, (void (*)(void *))rf_MCPairWakeupFunc,
    271  1.1  oster 		   (void *) mcpair);
    272  1.1  oster     while (!mcpair->flag)
    273  1.1  oster       RF_WAIT_COND(mcpair->cond, mcpair->mutex);
    274  1.1  oster     RF_UNLOCK_MUTEX(mcpair->mutex);
    275  1.1  oster     if (wr_dag_h->status != rf_enable) {
    276  1.1  oster       RF_ERRORMSG("Unable to correct parity in VerifyParity:  can't write the stripe\n");
    277  1.1  oster       retcode = RF_PARITY_COULD_NOT_CORRECT;
    278  1.1  oster     }
    279  1.1  oster     rf_FreeDAG(wr_dag_h);
    280  1.1  oster     if (retcode == RF_PARITY_BAD)
    281  1.1  oster       retcode = RF_PARITY_CORRECTED;
    282  1.1  oster   }
    283  1.1  oster 
    284  1.1  oster out:
    285  1.1  oster   rf_FreeAccessStripeMap(asm_h);
    286  1.1  oster   rf_FreeAllocList(alloclist);
    287  1.1  oster   rf_FreeDAG(rd_dag_h);
    288  1.1  oster   rf_FreeMCPair(mcpair);
    289  1.1  oster   return(retcode);
    290  1.1  oster }
    291  1.1  oster 
    292  1.1  oster int rf_TryToRedirectPDA(raidPtr, pda, parity)
    293  1.1  oster   RF_Raid_t          *raidPtr;
    294  1.1  oster   RF_PhysDiskAddr_t  *pda;
    295  1.1  oster   int                 parity;
    296  1.1  oster {
    297  1.1  oster   if (raidPtr->Disks[pda->row][pda->col].status == rf_ds_reconstructing) {
    298  1.1  oster     if (rf_CheckRUReconstructed(raidPtr->reconControl[pda->row]->reconMap, pda->startSector)) {
    299  1.1  oster       if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
    300  1.1  oster 	RF_RowCol_t or = pda->row, oc = pda->col;
    301  1.1  oster 	RF_SectorNum_t os = pda->startSector;
    302  1.1  oster 	if (parity) {
    303  1.1  oster 	  (raidPtr->Layout.map->MapParity)(raidPtr, pda->raidAddress, &pda->row, &pda->col, &pda->startSector, RF_REMAP);
    304  1.1  oster 	  if (rf_verifyParityDebug) printf("VerifyParity: Redir P r %d c %d sect %ld -> r %d c %d sect %ld\n",
    305  1.1  oster 					or,oc,(long)os,pda->row,pda->col,(long)pda->startSector);
    306  1.1  oster 	} else {
    307  1.1  oster 	  (raidPtr->Layout.map->MapSector)(raidPtr, pda->raidAddress, &pda->row, &pda->col, &pda->startSector, RF_REMAP);
    308  1.1  oster 	  if (rf_verifyParityDebug) printf("VerifyParity: Redir D r %d c %d sect %ld -> r %d c %d sect %ld\n",
    309  1.1  oster 					or,oc,(long)os,pda->row,pda->col,(long)pda->startSector);
    310  1.1  oster 	}
    311  1.1  oster       } else {
    312  1.1  oster 	RF_RowCol_t spRow = raidPtr->Disks[pda->row][pda->col].spareRow;
    313  1.1  oster 	RF_RowCol_t spCol = raidPtr->Disks[pda->row][pda->col].spareCol;
    314  1.1  oster 	pda->row = spRow;
    315  1.1  oster 	pda->col = spCol;
    316  1.1  oster       }
    317  1.1  oster     }
    318  1.1  oster   }
    319  1.1  oster   if (RF_DEAD_DISK(raidPtr->Disks[pda->row][pda->col].status)) return(1);
    320  1.1  oster   return(0);
    321  1.1  oster }
    322  1.1  oster 
    323  1.1  oster /*****************************************************************************************
    324  1.1  oster  *
    325  1.1  oster  * currently a stub.
    326  1.1  oster  *
    327  1.1  oster  * takes as input an ASM describing a write operation and containing one failure, and
    328  1.1  oster  * verifies that the parity was correctly updated to reflect the write.
    329  1.1  oster  *
    330  1.1  oster  * if it's a data unit that's failed, we read the other data units in the stripe and
    331  1.1  oster  * the parity unit, XOR them together, and verify that we get the data intended for
    332  1.1  oster  * the failed disk.  Since it's easy, we also validate that the right data got written
    333  1.1  oster  * to the surviving data disks.
    334  1.1  oster  *
    335  1.1  oster  * If it's the parity that failed, there's really no validation we can do except the
    336  1.1  oster  * above verification that the right data got written to all disks.  This is because
    337  1.1  oster  * the new data intended for the failed disk is supplied in the ASM, but this is of
    338  1.1  oster  * course not the case for the new parity.
    339  1.1  oster  *
    340  1.1  oster  ****************************************************************************************/
    341  1.1  oster int rf_VerifyDegrModeWrite(raidPtr, asmh)
    342  1.1  oster   RF_Raid_t                   *raidPtr;
    343  1.1  oster   RF_AccessStripeMapHeader_t  *asmh;
    344  1.1  oster {
    345  1.1  oster   return(0);
    346  1.1  oster }
    347  1.1  oster 
    348  1.1  oster /* creates a simple DAG with a header, a block-recon node at level 1,
    349  1.1  oster  * nNodes nodes at level 2, an unblock-recon node at level 3, and
    350  1.1  oster  * a terminator node at level 4.  The stripe address field in
    351  1.1  oster  * the block and unblock nodes are not touched, nor are the pda
    352  1.1  oster  * fields in the second-level nodes, so they must be filled in later.
    353  1.1  oster  *
    354  1.1  oster  * commit point is established at unblock node - this means that any
    355  1.1  oster  * failure during dag execution causes the dag to fail
    356  1.1  oster  */
    357  1.1  oster RF_DagHeader_t *rf_MakeSimpleDAG(raidPtr, nNodes, bytesPerSU, databuf, doFunc, undoFunc, name, alloclist, flags, priority)
    358  1.1  oster   RF_Raid_t              *raidPtr;
    359  1.1  oster   int                     nNodes;
    360  1.1  oster   int                     bytesPerSU;
    361  1.1  oster   char                   *databuf;
    362  1.1  oster   int                   (*doFunc)(RF_DagNode_t *node);
    363  1.1  oster   int                   (*undoFunc)(RF_DagNode_t *node);
    364  1.1  oster   char                   *name;        /* node names at the second level */
    365  1.1  oster   RF_AllocListElem_t     *alloclist;
    366  1.1  oster   RF_RaidAccessFlags_t    flags;
    367  1.1  oster   int                     priority;
    368  1.1  oster {
    369  1.1  oster   RF_DagHeader_t *dag_h;
    370  1.1  oster   RF_DagNode_t *nodes, *termNode, *blockNode, *unblockNode;
    371  1.1  oster   int i;
    372  1.1  oster 
    373  1.1  oster   /* create the nodes, the block & unblock nodes, and the terminator node */
    374  1.1  oster   RF_CallocAndAdd(nodes, nNodes+3, sizeof(RF_DagNode_t), (RF_DagNode_t *), alloclist);
    375  1.1  oster   blockNode   = &nodes[nNodes];
    376  1.1  oster   unblockNode = blockNode+1;
    377  1.1  oster   termNode   = unblockNode+1;
    378  1.1  oster 
    379  1.1  oster   dag_h = rf_AllocDAGHeader();
    380  1.1  oster   dag_h->raidPtr = (void *) raidPtr;
    381  1.1  oster   dag_h->allocList = NULL;                               /* we won't use this alloc list */
    382  1.1  oster   dag_h->status = rf_enable;
    383  1.1  oster   dag_h->numSuccedents = 1;
    384  1.1  oster   dag_h->creator = "SimpleDAG";
    385  1.1  oster 
    386  1.1  oster   /* this dag can not commit until the unblock node is reached
    387  1.1  oster    * errors prior to the commit point imply the dag has failed
    388  1.1  oster    */
    389  1.1  oster   dag_h->numCommitNodes = 1;
    390  1.1  oster   dag_h->numCommits = 0;
    391  1.1  oster 
    392  1.1  oster   dag_h->succedents[0] = blockNode;
    393  1.1  oster   rf_InitNode(blockNode,   rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, nNodes, 0, 0, 0, dag_h, "Nil", alloclist);
    394  1.1  oster   rf_InitNode(unblockNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, 1, nNodes, 0, 0, dag_h, "Nil", alloclist);
    395  1.1  oster   unblockNode->succedents[0] = termNode;
    396  1.1  oster   for (i=0; i<nNodes; i++) {
    397  1.1  oster     blockNode->succedents[i] = unblockNode->antecedents[i] = &nodes[i];
    398  1.1  oster     unblockNode->antType[i] = rf_control;
    399  1.1  oster     rf_InitNode(&nodes[i], rf_wait, RF_FALSE, doFunc, undoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, name, alloclist);
    400  1.1  oster     nodes[i].succedents[0] =  unblockNode;
    401  1.1  oster     nodes[i].antecedents[0] = blockNode;
    402  1.1  oster     nodes[i].antType[0] = rf_control;
    403  1.1  oster     nodes[i].params[1].p = (databuf + (i*bytesPerSU));
    404  1.1  oster   }
    405  1.1  oster   rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc, NULL, 0, 1, 0, 0, dag_h, "Trm", alloclist);
    406  1.1  oster   termNode->antecedents[0] = unblockNode;
    407  1.1  oster   termNode->antType[0] = rf_control;
    408  1.1  oster   return(dag_h);
    409  1.1  oster }
    410