Home | History | Annotate | Line # | Download | only in raidframe
rf_parityscan.c revision 1.1
      1 /*	$NetBSD: rf_parityscan.c,v 1.1 1998/11/13 04:20:32 oster Exp $	*/
      2 /*
      3  * Copyright (c) 1995 Carnegie-Mellon University.
      4  * All rights reserved.
      5  *
      6  * Author: Mark Holland
      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_parityscan.c -- misc utilities related to parity verification
     32  *
     33  *****************************************************************************/
     34 
     35 /*
     36  * :
     37  * Log: rf_parityscan.c,v
     38  * Revision 1.47  1996/08/20 20:35:01  jimz
     39  * change diagnostic string in rewrite
     40  *
     41  * Revision 1.46  1996/08/20  20:03:19  jimz
     42  * fixed parity rewrite to actually use arch-specific parity stuff
     43  * (this ever worked... how?)
     44  *
     45  * Revision 1.45  1996/08/16  17:41:25  jimz
     46  * allow rewrite parity on any fault-tolerant arch
     47  *
     48  * Revision 1.44  1996/07/28  20:31:39  jimz
     49  * i386netbsd port
     50  * true/false fixup
     51  *
     52  * Revision 1.43  1996/07/27  23:36:08  jimz
     53  * Solaris port of simulator
     54  *
     55  * Revision 1.42  1996/07/22  21:12:01  jimz
     56  * clean up parity scan status printing
     57  *
     58  * Revision 1.41  1996/07/22  19:52:16  jimz
     59  * switched node params to RF_DagParam_t, a union of
     60  * a 64-bit int and a void *, for better portability
     61  * attempted hpux port, but failed partway through for
     62  * lack of a single C compiler capable of compiling all
     63  * source files
     64  *
     65  * Revision 1.40  1996/07/13  00:00:59  jimz
     66  * sanitized generalized reconstruction architecture
     67  * cleaned up head sep, rbuf problems
     68  *
     69  * Revision 1.39  1996/07/09  21:44:26  jimz
     70  * fix bogus return code in VerifyParityBasic when a stripe can't be corrected
     71  *
     72  * Revision 1.38  1996/06/20  17:56:57  jimz
     73  * update VerifyParity to check complete AccessStripeMaps
     74  *
     75  * Revision 1.37  1996/06/19  22:23:01  jimz
     76  * parity verification is now a layout-configurable thing
     77  * not all layouts currently support it (correctly, anyway)
     78  *
     79  * Revision 1.36  1996/06/09  02:36:46  jimz
     80  * lots of little crufty cleanup- fixup whitespace
     81  * issues, comment #ifdefs, improve typing in some
     82  * places (esp size-related)
     83  *
     84  * Revision 1.35  1996/06/07  22:26:27  jimz
     85  * type-ify which_ru (RF_ReconUnitNum_t)
     86  *
     87  * Revision 1.34  1996/06/07  21:33:04  jimz
     88  * begin using consistent types for sector numbers,
     89  * stripe numbers, row+col numbers, recon unit numbers
     90  *
     91  * Revision 1.33  1996/06/05  18:06:02  jimz
     92  * Major code cleanup. The Great Renaming is now done.
     93  * Better modularity. Better typing. Fixed a bunch of
     94  * synchronization bugs. Made a lot of global stuff
     95  * per-desc or per-array. Removed dead code.
     96  *
     97  * Revision 1.32  1996/06/02  17:31:48  jimz
     98  * Moved a lot of global stuff into array structure, where it belongs.
     99  * Fixed up paritylogging, pss modules in this manner. Some general
    100  * code cleanup. Removed lots of dead code, some dead files.
    101  *
    102  * Revision 1.31  1996/05/31  22:26:54  jimz
    103  * fix a lot of mapping problems, memory allocation problems
    104  * found some weird lock issues, fixed 'em
    105  * more code cleanup
    106  *
    107  * Revision 1.30  1996/05/30  23:22:16  jimz
    108  * bugfixes of serialization, timing problems
    109  * more cleanup
    110  *
    111  * Revision 1.29  1996/05/30  12:59:18  jimz
    112  * make etimer happier, more portable
    113  *
    114  * Revision 1.28  1996/05/30  11:29:41  jimz
    115  * Numerous bug fixes. Stripe lock release code disagreed with the taking code
    116  * about when stripes should be locked (I made it consistent: no parity, no lock)
    117  * There was a lot of extra serialization of I/Os which I've removed- a lot of
    118  * it was to calculate values for the cache code, which is no longer with us.
    119  * More types, function, macro cleanup. Added code to properly quiesce the array
    120  * on shutdown. Made a lot of stuff array-specific which was (bogusly) general
    121  * before. Fixed memory allocation, freeing bugs.
    122  *
    123  * Revision 1.27  1996/05/27  18:56:37  jimz
    124  * more code cleanup
    125  * better typing
    126  * compiles in all 3 environments
    127  *
    128  * Revision 1.26  1996/05/24  22:17:04  jimz
    129  * continue code + namespace cleanup
    130  * typed a bunch of flags
    131  *
    132  * Revision 1.25  1996/05/24  04:28:55  jimz
    133  * release cleanup ckpt
    134  *
    135  * Revision 1.24  1996/05/23  21:46:35  jimz
    136  * checkpoint in code cleanup (release prep)
    137  * lots of types, function names have been fixed
    138  *
    139  * Revision 1.23  1996/05/23  00:33:23  jimz
    140  * code cleanup: move all debug decls to rf_options.c, all extern
    141  * debug decls to rf_options.h, all debug vars preceded by rf_
    142  *
    143  * Revision 1.22  1996/05/18  19:51:34  jimz
    144  * major code cleanup- fix syntax, make some types consistent,
    145  * add prototypes, clean out dead code, et cetera
    146  *
    147  * Revision 1.21  1996/05/08  21:01:24  jimz
    148  * fixed up enum type names that were conflicting with other
    149  * enums and function names (ie, "panic")
    150  * future naming trends will be towards RF_ and rf_ for
    151  * everything raidframe-related
    152  *
    153  * Revision 1.20  1995/12/12  18:10:06  jimz
    154  * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
    155  * fix 80-column brain damage in comments
    156  *
    157  * Revision 1.19  1995/11/30  16:16:49  wvcii
    158  * added copyright info
    159  *
    160  * Revision 1.18  1995/11/19  16:32:19  wvcii
    161  * eliminated initialization of dag header fields which no longer exist
    162  * (numDags, numDagsDone, firstHdr)
    163  *
    164  * Revision 1.17  1995/11/07  16:23:36  wvcii
    165  * added comments, asserts, and prototypes
    166  * encoded commit point nodes, barrier, and antecedents types into dags
    167  *
    168  */
    169 
    170 #include "rf_types.h"
    171 #include "rf_raid.h"
    172 #include "rf_dag.h"
    173 #include "rf_dagfuncs.h"
    174 #include "rf_dagutils.h"
    175 #include "rf_mcpair.h"
    176 #include "rf_general.h"
    177 #include "rf_engine.h"
    178 #include "rf_parityscan.h"
    179 #include "rf_map.h"
    180 #include "rf_sys.h"
    181 
    182 /*****************************************************************************************
    183  *
    184  * walk through the entire arry and write new parity.
    185  * This works by creating two DAGs, one to read a stripe of data and one to
    186  * write new parity.  The first is executed, the data is xored together, and
    187  * then the second is executed.  To avoid constantly building and tearing down
    188  * the DAGs, we create them a priori and fill them in with the mapping
    189  * information as we go along.
    190  *
    191  * there should never be more than one thread running this.
    192  *
    193  ****************************************************************************************/
    194 
    195 int rf_RewriteParity(raidPtr)
    196   RF_Raid_t  *raidPtr;
    197 {
    198   RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
    199   RF_AccessStripeMapHeader_t *asm_h;
    200   int old_pctg, new_pctg, rc;
    201   RF_PhysDiskAddr_t pda;
    202   RF_SectorNum_t i;
    203 
    204   pda.startSector = 0;
    205   pda.numSector   = raidPtr->Layout.sectorsPerStripeUnit;
    206   old_pctg = -1;
    207 
    208 /* rf_verifyParityDebug=1; */
    209   for (i=0; i<raidPtr->totalSectors; i+=layoutPtr->dataSectorsPerStripe) {
    210     asm_h = rf_MapAccess(raidPtr, i, layoutPtr->dataSectorsPerStripe, NULL, RF_DONT_REMAP);
    211     rc = rf_VerifyParity(raidPtr, asm_h->stripeMap, 1, 0);
    212     /*     printf("Parity verified: rc=%d\n",rc); */
    213     switch (rc) {
    214       case RF_PARITY_OKAY:
    215       case RF_PARITY_CORRECTED:
    216         break;
    217       case RF_PARITY_BAD:
    218         printf("Parity bad during correction\n");
    219         RF_PANIC();
    220         break;
    221       case RF_PARITY_COULD_NOT_CORRECT:
    222         printf("Could not correct bad parity\n");
    223         RF_PANIC();
    224         break;
    225       case RF_PARITY_COULD_NOT_VERIFY:
    226         printf("Could not verify parity\n");
    227         RF_PANIC();
    228         break;
    229       default:
    230         printf("Bad rc=%d from VerifyParity in RewriteParity\n", rc);
    231         RF_PANIC();
    232     }
    233     rf_FreeAccessStripeMap(asm_h);
    234     new_pctg = i*1000/raidPtr->totalSectors;
    235     if (new_pctg != old_pctg) {
    236 #ifndef KERNEL
    237       fprintf(stderr,"\rParity rewrite: %d.%d%% complete",
    238         new_pctg/10, new_pctg%10);
    239       fflush(stderr);
    240 #endif /* !KERNEL */
    241     }
    242     old_pctg = new_pctg;
    243   }
    244 #ifndef KERNEL
    245   fprintf(stderr,"\rParity rewrite: 100.0%% complete\n");
    246 #endif /* !KERNEL */
    247 #if 1
    248   return(0); /* XXX nothing was here.. GO */
    249 #endif
    250 }
    251 
    252 /*****************************************************************************************
    253  *
    254  * verify that the parity in a particular stripe is correct.
    255  * we validate only the range of parity defined by parityPDA, since
    256  * this is all we have locked.  The way we do this is to create an asm
    257  * that maps the whole stripe and then range-restrict it to the parity
    258  * region defined by the parityPDA.
    259  *
    260  ****************************************************************************************/
    261 int rf_VerifyParity(raidPtr, aasm, correct_it, flags)
    262   RF_Raid_t             *raidPtr;
    263   RF_AccessStripeMap_t  *aasm;
    264   int                    correct_it;
    265   RF_RaidAccessFlags_t   flags;
    266 {
    267   RF_PhysDiskAddr_t *parityPDA;
    268   RF_AccessStripeMap_t *doasm;
    269   RF_LayoutSW_t *lp;
    270   int lrc, rc;
    271 
    272   lp = raidPtr->Layout.map;
    273   if (lp->faultsTolerated == 0) {
    274     /*
    275      * There isn't any parity. Call it "okay."
    276      */
    277     return(RF_PARITY_OKAY);
    278   }
    279   rc = RF_PARITY_OKAY;
    280   if (lp->VerifyParity) {
    281     for(doasm=aasm;doasm;doasm=doasm->next) {
    282       for(parityPDA=doasm->parityInfo;parityPDA;parityPDA=parityPDA->next) {
    283         lrc = lp->VerifyParity(raidPtr, doasm->raidAddress, parityPDA,
    284           correct_it, flags);
    285         if (lrc > rc) {
    286           /* see rf_parityscan.h for why this works */
    287           rc = lrc;
    288         }
    289       }
    290     }
    291   }
    292   else {
    293     rc = RF_PARITY_COULD_NOT_VERIFY;
    294   }
    295   return(rc);
    296 }
    297 
    298 int rf_VerifyParityBasic(raidPtr, raidAddr, parityPDA, correct_it, flags)
    299   RF_Raid_t             *raidPtr;
    300   RF_RaidAddr_t          raidAddr;
    301   RF_PhysDiskAddr_t     *parityPDA;
    302   int                    correct_it;
    303   RF_RaidAccessFlags_t   flags;
    304 {
    305   RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
    306   RF_RaidAddr_t startAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, raidAddr);
    307   RF_SectorCount_t numsector = parityPDA->numSector;
    308   int numbytes  = rf_RaidAddressToByte(raidPtr, numsector);
    309   int bytesPerStripe = numbytes * layoutPtr->numDataCol;
    310   RF_DagHeader_t *rd_dag_h, *wr_dag_h;          /* read, write dag */
    311   RF_DagNode_t *blockNode, *unblockNode, *wrBlock, *wrUnblock;
    312   RF_AccessStripeMapHeader_t *asm_h;
    313   RF_AccessStripeMap_t *asmap;
    314   RF_AllocListElem_t *alloclist;
    315   RF_PhysDiskAddr_t *pda;
    316   char *pbuf, *buf, *end_p, *p;
    317   int i, retcode;
    318   RF_ReconUnitNum_t which_ru;
    319   RF_StripeNum_t psID = rf_RaidAddressToParityStripeID(layoutPtr, raidAddr, &which_ru);
    320   int stripeWidth = layoutPtr->numDataCol + layoutPtr->numParityCol;
    321   RF_AccTraceEntry_t tracerec;
    322   RF_MCPair_t *mcpair;
    323 
    324   retcode = RF_PARITY_OKAY;
    325 
    326   mcpair = rf_AllocMCPair();
    327   rf_MakeAllocList(alloclist);
    328   RF_MallocAndAdd(buf, numbytes * (layoutPtr->numDataCol + layoutPtr->numParityCol), (char *), alloclist);
    329   RF_CallocAndAdd(pbuf, 1, numbytes, (char *), alloclist);     /* use calloc to make sure buffer is zeroed */
    330   end_p = buf + bytesPerStripe;
    331 
    332   rd_dag_h = rf_MakeSimpleDAG(raidPtr, stripeWidth, numbytes, buf, rf_DiskReadFunc, rf_DiskReadUndoFunc,
    333 			   "Rod", alloclist, flags, RF_IO_NORMAL_PRIORITY);
    334   blockNode = rd_dag_h->succedents[0];
    335   unblockNode = blockNode->succedents[0]->succedents[0];
    336 
    337   /* map the stripe and fill in the PDAs in the dag */
    338   asm_h = rf_MapAccess(raidPtr, startAddr, layoutPtr->dataSectorsPerStripe, buf, RF_DONT_REMAP);
    339   asmap = asm_h->stripeMap;
    340 
    341   for (pda=asmap->physInfo,i=0; i<layoutPtr->numDataCol; i++,pda=pda->next) {
    342     RF_ASSERT(pda);
    343     rf_RangeRestrictPDA(raidPtr, parityPDA, pda, 0, 1);
    344     RF_ASSERT(pda->numSector != 0);
    345     if (rf_TryToRedirectPDA(raidPtr, pda, 0)) goto out;   /* no way to verify parity if disk is dead.  return w/ good status */
    346     blockNode->succedents[i]->params[0].p = pda;
    347     blockNode->succedents[i]->params[2].v = psID;
    348     blockNode->succedents[i]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    349   }
    350 
    351   RF_ASSERT(!asmap->parityInfo->next);
    352   rf_RangeRestrictPDA(raidPtr, parityPDA, asmap->parityInfo, 0, 1);
    353   RF_ASSERT(asmap->parityInfo->numSector != 0);
    354   if (rf_TryToRedirectPDA(raidPtr, asmap->parityInfo, 1))
    355     goto out;
    356   blockNode->succedents[layoutPtr->numDataCol]->params[0].p = asmap->parityInfo;
    357 
    358   /* fire off the DAG */
    359   bzero((char *)&tracerec,sizeof(tracerec));
    360   rd_dag_h->tracerec = &tracerec;
    361 
    362   if (rf_verifyParityDebug) {
    363     printf("Parity verify read dag:\n");
    364     rf_PrintDAGList(rd_dag_h);
    365   }
    366 
    367   RF_LOCK_MUTEX(mcpair->mutex);
    368   mcpair->flag = 0;
    369   rf_DispatchDAG(rd_dag_h, (void (*)(void *))rf_MCPairWakeupFunc,
    370 		 (void *) mcpair);
    371   while (!mcpair->flag)
    372 	  RF_WAIT_COND(mcpair->cond, mcpair->mutex);
    373   RF_UNLOCK_MUTEX(mcpair->mutex);
    374   if (rd_dag_h->status != rf_enable) {
    375     RF_ERRORMSG("Unable to verify parity:  can't read the stripe\n");
    376     retcode = RF_PARITY_COULD_NOT_VERIFY;
    377     goto out;
    378   }
    379 
    380   for (p=buf; p<end_p; p+=numbytes) {
    381     rf_bxor(p, pbuf, numbytes, NULL);
    382   }
    383   for (i=0; i<numbytes; i++) {
    384 #if 0
    385 	  if (pbuf[i]!=0 || buf[bytesPerStripe+i]!=0) {
    386 	  printf("Bytes: %d %d %d\n",i,pbuf[i],buf[bytesPerStripe+i]);
    387 	  }
    388 #endif
    389 	  if (pbuf[i] != buf[bytesPerStripe+i]) {
    390 		  if (!correct_it)
    391 			  RF_ERRORMSG3("Parity verify error: byte %d of parity is 0x%x should be 0x%x\n",
    392 			       i,(u_char) buf[bytesPerStripe+i],(u_char) pbuf[i]);
    393 		  retcode = RF_PARITY_BAD;
    394 		  break;
    395 	  }
    396   }
    397 
    398   if (retcode && correct_it) {
    399     wr_dag_h = rf_MakeSimpleDAG(raidPtr, 1, numbytes, pbuf, rf_DiskWriteFunc, rf_DiskWriteUndoFunc,
    400 			     "Wnp", alloclist, flags, RF_IO_NORMAL_PRIORITY);
    401     wrBlock = wr_dag_h->succedents[0]; wrUnblock = wrBlock->succedents[0]->succedents[0];
    402     wrBlock->succedents[0]->params[0].p = asmap->parityInfo;
    403     wrBlock->succedents[0]->params[2].v = psID;
    404     wrBlock->succedents[0]->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru);
    405     bzero((char *)&tracerec,sizeof(tracerec));
    406     wr_dag_h->tracerec = &tracerec;
    407     if (rf_verifyParityDebug) {
    408       printf("Parity verify write dag:\n");
    409       rf_PrintDAGList(wr_dag_h);
    410     }
    411     RF_LOCK_MUTEX(mcpair->mutex);
    412     mcpair->flag = 0;
    413     rf_DispatchDAG(wr_dag_h, (void (*)(void *))rf_MCPairWakeupFunc,
    414 		   (void *) mcpair);
    415     while (!mcpair->flag)
    416       RF_WAIT_COND(mcpair->cond, mcpair->mutex);
    417     RF_UNLOCK_MUTEX(mcpair->mutex);
    418     if (wr_dag_h->status != rf_enable) {
    419       RF_ERRORMSG("Unable to correct parity in VerifyParity:  can't write the stripe\n");
    420       retcode = RF_PARITY_COULD_NOT_CORRECT;
    421     }
    422     rf_FreeDAG(wr_dag_h);
    423     if (retcode == RF_PARITY_BAD)
    424       retcode = RF_PARITY_CORRECTED;
    425   }
    426 
    427 out:
    428   rf_FreeAccessStripeMap(asm_h);
    429   rf_FreeAllocList(alloclist);
    430   rf_FreeDAG(rd_dag_h);
    431   rf_FreeMCPair(mcpair);
    432   return(retcode);
    433 }
    434 
    435 int rf_TryToRedirectPDA(raidPtr, pda, parity)
    436   RF_Raid_t          *raidPtr;
    437   RF_PhysDiskAddr_t  *pda;
    438   int                 parity;
    439 {
    440   if (raidPtr->Disks[pda->row][pda->col].status == rf_ds_reconstructing) {
    441     if (rf_CheckRUReconstructed(raidPtr->reconControl[pda->row]->reconMap, pda->startSector)) {
    442       if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
    443 	RF_RowCol_t or = pda->row, oc = pda->col;
    444 	RF_SectorNum_t os = pda->startSector;
    445 	if (parity) {
    446 	  (raidPtr->Layout.map->MapParity)(raidPtr, pda->raidAddress, &pda->row, &pda->col, &pda->startSector, RF_REMAP);
    447 	  if (rf_verifyParityDebug) printf("VerifyParity: Redir P r %d c %d sect %ld -> r %d c %d sect %ld\n",
    448 					or,oc,(long)os,pda->row,pda->col,(long)pda->startSector);
    449 	} else {
    450 	  (raidPtr->Layout.map->MapSector)(raidPtr, pda->raidAddress, &pda->row, &pda->col, &pda->startSector, RF_REMAP);
    451 	  if (rf_verifyParityDebug) printf("VerifyParity: Redir D r %d c %d sect %ld -> r %d c %d sect %ld\n",
    452 					or,oc,(long)os,pda->row,pda->col,(long)pda->startSector);
    453 	}
    454       } else {
    455 	RF_RowCol_t spRow = raidPtr->Disks[pda->row][pda->col].spareRow;
    456 	RF_RowCol_t spCol = raidPtr->Disks[pda->row][pda->col].spareCol;
    457 	pda->row = spRow;
    458 	pda->col = spCol;
    459       }
    460     }
    461   }
    462   if (RF_DEAD_DISK(raidPtr->Disks[pda->row][pda->col].status)) return(1);
    463   return(0);
    464 }
    465 
    466 /*****************************************************************************************
    467  *
    468  * currently a stub.
    469  *
    470  * takes as input an ASM describing a write operation and containing one failure, and
    471  * verifies that the parity was correctly updated to reflect the write.
    472  *
    473  * if it's a data unit that's failed, we read the other data units in the stripe and
    474  * the parity unit, XOR them together, and verify that we get the data intended for
    475  * the failed disk.  Since it's easy, we also validate that the right data got written
    476  * to the surviving data disks.
    477  *
    478  * If it's the parity that failed, there's really no validation we can do except the
    479  * above verification that the right data got written to all disks.  This is because
    480  * the new data intended for the failed disk is supplied in the ASM, but this is of
    481  * course not the case for the new parity.
    482  *
    483  ****************************************************************************************/
    484 int rf_VerifyDegrModeWrite(raidPtr, asmh)
    485   RF_Raid_t                   *raidPtr;
    486   RF_AccessStripeMapHeader_t  *asmh;
    487 {
    488   return(0);
    489 }
    490 
    491 /* creates a simple DAG with a header, a block-recon node at level 1,
    492  * nNodes nodes at level 2, an unblock-recon node at level 3, and
    493  * a terminator node at level 4.  The stripe address field in
    494  * the block and unblock nodes are not touched, nor are the pda
    495  * fields in the second-level nodes, so they must be filled in later.
    496  *
    497  * commit point is established at unblock node - this means that any
    498  * failure during dag execution causes the dag to fail
    499  */
    500 RF_DagHeader_t *rf_MakeSimpleDAG(raidPtr, nNodes, bytesPerSU, databuf, doFunc, undoFunc, name, alloclist, flags, priority)
    501   RF_Raid_t              *raidPtr;
    502   int                     nNodes;
    503   int                     bytesPerSU;
    504   char                   *databuf;
    505   int                   (*doFunc)(RF_DagNode_t *node);
    506   int                   (*undoFunc)(RF_DagNode_t *node);
    507   char                   *name;        /* node names at the second level */
    508   RF_AllocListElem_t     *alloclist;
    509   RF_RaidAccessFlags_t    flags;
    510   int                     priority;
    511 {
    512   RF_DagHeader_t *dag_h;
    513   RF_DagNode_t *nodes, *termNode, *blockNode, *unblockNode;
    514   int i;
    515 
    516   /* create the nodes, the block & unblock nodes, and the terminator node */
    517   RF_CallocAndAdd(nodes, nNodes+3, sizeof(RF_DagNode_t), (RF_DagNode_t *), alloclist);
    518   blockNode   = &nodes[nNodes];
    519   unblockNode = blockNode+1;
    520   termNode   = unblockNode+1;
    521 
    522   dag_h = rf_AllocDAGHeader();
    523   dag_h->raidPtr = (void *) raidPtr;
    524   dag_h->allocList = NULL;                               /* we won't use this alloc list */
    525   dag_h->status = rf_enable;
    526   dag_h->numSuccedents = 1;
    527   dag_h->creator = "SimpleDAG";
    528 
    529   /* this dag can not commit until the unblock node is reached
    530    * errors prior to the commit point imply the dag has failed
    531    */
    532   dag_h->numCommitNodes = 1;
    533   dag_h->numCommits = 0;
    534 
    535   dag_h->succedents[0] = blockNode;
    536   rf_InitNode(blockNode,   rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, nNodes, 0, 0, 0, dag_h, "Nil", alloclist);
    537   rf_InitNode(unblockNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, 1, nNodes, 0, 0, dag_h, "Nil", alloclist);
    538   unblockNode->succedents[0] = termNode;
    539   for (i=0; i<nNodes; i++) {
    540     blockNode->succedents[i] = unblockNode->antecedents[i] = &nodes[i];
    541     unblockNode->antType[i] = rf_control;
    542     rf_InitNode(&nodes[i], rf_wait, RF_FALSE, doFunc, undoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, name, alloclist);
    543     nodes[i].succedents[0] =  unblockNode;
    544     nodes[i].antecedents[0] = blockNode;
    545     nodes[i].antType[0] = rf_control;
    546     nodes[i].params[1].p = (databuf + (i*bytesPerSU));
    547   }
    548   rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc, NULL, 0, 1, 0, 0, dag_h, "Trm", alloclist);
    549   termNode->antecedents[0] = unblockNode;
    550   termNode->antType[0] = rf_control;
    551   return(dag_h);
    552 }
    553