Home | History | Annotate | Line # | Download | only in raidframe
rf_aselect.c revision 1.2
      1  1.2  oster /*	$NetBSD: rf_aselect.c,v 1.2 1999/01/26 02:33:50 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, William V. Courtright II
      7  1.1  oster  *
      8  1.1  oster  * Permission to use, copy, modify and distribute this software and
      9  1.1  oster  * its documentation is hereby granted, provided that both the copyright
     10  1.1  oster  * notice and this permission notice appear in all copies of the
     11  1.1  oster  * software, derivative works or modified versions, and any portions
     12  1.1  oster  * thereof, and that both notices appear in supporting documentation.
     13  1.1  oster  *
     14  1.1  oster  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  1.1  oster  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16  1.1  oster  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  1.1  oster  *
     18  1.1  oster  * Carnegie Mellon requests users of this software to return to
     19  1.1  oster  *
     20  1.1  oster  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  1.1  oster  *  School of Computer Science
     22  1.1  oster  *  Carnegie Mellon University
     23  1.1  oster  *  Pittsburgh PA 15213-3890
     24  1.1  oster  *
     25  1.1  oster  * any improvements or extensions that they make and grant Carnegie the
     26  1.1  oster  * rights to redistribute these changes.
     27  1.1  oster  */
     28  1.1  oster 
     29  1.1  oster /*****************************************************************************
     30  1.1  oster  *
     31  1.1  oster  * aselect.c -- algorithm selection code
     32  1.1  oster  *
     33  1.1  oster  *****************************************************************************/
     34  1.2  oster 
     35  1.1  oster 
     36  1.1  oster #include "rf_archs.h"
     37  1.1  oster #include "rf_types.h"
     38  1.1  oster #include "rf_raid.h"
     39  1.1  oster #include "rf_dag.h"
     40  1.1  oster #include "rf_dagutils.h"
     41  1.1  oster #include "rf_dagfuncs.h"
     42  1.1  oster #include "rf_general.h"
     43  1.1  oster #include "rf_desc.h"
     44  1.1  oster #include "rf_map.h"
     45  1.1  oster 
     46  1.1  oster #if defined(__NetBSD__) && defined(_KERNEL)
     47  1.1  oster /* the function below is not used... so don't define it! */
     48  1.1  oster #else
     49  1.1  oster static void TransferDagMemory(RF_DagHeader_t *, RF_DagHeader_t *);
     50  1.1  oster #endif
     51  1.1  oster 
     52  1.1  oster static int InitHdrNode(RF_DagHeader_t **, RF_Raid_t *, int);
     53  1.1  oster static void UpdateNodeHdrPtr(RF_DagHeader_t *, RF_DagNode_t *);
     54  1.1  oster int rf_SelectAlgorithm(RF_RaidAccessDesc_t *, RF_RaidAccessFlags_t );
     55  1.1  oster 
     56  1.1  oster 
     57  1.1  oster /******************************************************************************
     58  1.1  oster  *
     59  1.1  oster  * Create and Initialiaze a dag header and termination node
     60  1.1  oster  *
     61  1.1  oster  *****************************************************************************/
     62  1.1  oster static int InitHdrNode(hdr, raidPtr, memChunkEnable)
     63  1.1  oster   RF_DagHeader_t  **hdr;
     64  1.1  oster   RF_Raid_t        *raidPtr;
     65  1.1  oster   int               memChunkEnable;
     66  1.1  oster {
     67  1.1  oster   /* create and initialize dag hdr */
     68  1.1  oster   *hdr = rf_AllocDAGHeader();
     69  1.1  oster   rf_MakeAllocList((*hdr)->allocList);
     70  1.1  oster   if ((*hdr)->allocList == NULL) {
     71  1.1  oster     rf_FreeDAGHeader(*hdr);
     72  1.1  oster     return(ENOMEM);
     73  1.1  oster   }
     74  1.1  oster   (*hdr)->status = rf_enable;
     75  1.1  oster   (*hdr)->numSuccedents = 0;
     76  1.1  oster   (*hdr)->raidPtr = raidPtr;
     77  1.1  oster   (*hdr)->next = NULL;
     78  1.1  oster   return(0);
     79  1.1  oster }
     80  1.1  oster 
     81  1.1  oster /******************************************************************************
     82  1.1  oster  *
     83  1.1  oster  * Transfer allocation list and mem chunks from one dag to another
     84  1.1  oster  *
     85  1.1  oster  *****************************************************************************/
     86  1.1  oster #if defined(__NetBSD__) && defined(_KERNEL)
     87  1.1  oster /* the function below is not used... so don't define it! */
     88  1.1  oster #else
     89  1.1  oster static void TransferDagMemory(daga, dagb)
     90  1.1  oster   RF_DagHeader_t  *daga;
     91  1.1  oster   RF_DagHeader_t  *dagb;
     92  1.1  oster {
     93  1.1  oster   RF_AccessStripeMapHeader_t *end;
     94  1.1  oster   RF_AllocListElem_t *p;
     95  1.1  oster   int i, memChunksXfrd = 0, xtraChunksXfrd = 0;
     96  1.1  oster 
     97  1.1  oster   /* transfer allocList from dagb to daga */
     98  1.1  oster   for (p = dagb->allocList; p ; p = p->next)
     99  1.1  oster     {
    100  1.1  oster       for (i = 0; i < p->numPointers; i++)
    101  1.1  oster 	{
    102  1.1  oster 	  rf_AddToAllocList(daga->allocList, p->pointers[i], p->sizes[i]);
    103  1.1  oster 	  p->pointers[i] = NULL;
    104  1.1  oster 	  p->sizes[i] = 0;
    105  1.1  oster 	}
    106  1.1  oster       p->numPointers = 0;
    107  1.1  oster     }
    108  1.1  oster 
    109  1.1  oster   /* transfer chunks from dagb to daga */
    110  1.1  oster   while ((memChunksXfrd + xtraChunksXfrd < dagb->chunkIndex + dagb->xtraChunkIndex) && (daga->chunkIndex < RF_MAXCHUNKS))
    111  1.1  oster     {
    112  1.1  oster       /* stuff chunks into daga's memChunk array */
    113  1.1  oster       if (memChunksXfrd < dagb->chunkIndex)
    114  1.1  oster 	{
    115  1.1  oster 	  daga->memChunk[daga->chunkIndex++] = dagb->memChunk[memChunksXfrd];
    116  1.1  oster 	  dagb->memChunk[memChunksXfrd++] = NULL;
    117  1.1  oster 	}
    118  1.1  oster       else
    119  1.1  oster 	{
    120  1.1  oster 	  daga->memChunk[daga->xtraChunkIndex++] = dagb->xtraMemChunk[xtraChunksXfrd];
    121  1.1  oster 	  dagb->xtraMemChunk[xtraChunksXfrd++] = NULL;
    122  1.1  oster 	}
    123  1.1  oster     }
    124  1.1  oster   /* use escape hatch to hold excess chunks */
    125  1.1  oster   while (memChunksXfrd + xtraChunksXfrd < dagb->chunkIndex + dagb->xtraChunkIndex) {
    126  1.1  oster     if (memChunksXfrd < dagb->chunkIndex)
    127  1.1  oster       {
    128  1.1  oster 	daga->xtraMemChunk[daga->xtraChunkIndex++] = dagb->memChunk[memChunksXfrd];
    129  1.1  oster 	dagb->memChunk[memChunksXfrd++] = NULL;
    130  1.1  oster       }
    131  1.1  oster     else
    132  1.1  oster       {
    133  1.1  oster 	daga->xtraMemChunk[daga->xtraChunkIndex++] = dagb->xtraMemChunk[xtraChunksXfrd];
    134  1.1  oster 	dagb->xtraMemChunk[xtraChunksXfrd++] = NULL;
    135  1.1  oster       }
    136  1.1  oster   }
    137  1.1  oster   RF_ASSERT((memChunksXfrd == dagb->chunkIndex) && (xtraChunksXfrd == dagb->xtraChunkIndex));
    138  1.1  oster   RF_ASSERT(daga->chunkIndex <= RF_MAXCHUNKS);
    139  1.1  oster   RF_ASSERT(daga->xtraChunkIndex <= daga->xtraChunkCnt);
    140  1.1  oster   dagb->chunkIndex = 0;
    141  1.1  oster   dagb->xtraChunkIndex = 0;
    142  1.1  oster 
    143  1.1  oster   /* transfer asmList from dagb to daga */
    144  1.1  oster   if (dagb->asmList)
    145  1.1  oster     {
    146  1.1  oster       if (daga->asmList)
    147  1.1  oster 	{
    148  1.1  oster 	  end = daga->asmList;
    149  1.1  oster 	  while (end->next)
    150  1.1  oster 	    end = end->next;
    151  1.1  oster 	  end->next = dagb->asmList;
    152  1.1  oster 	}
    153  1.1  oster       else
    154  1.1  oster 	daga->asmList = dagb->asmList;
    155  1.1  oster       dagb->asmList = NULL;
    156  1.1  oster     }
    157  1.1  oster }
    158  1.1  oster #endif /* __NetBSD__ */
    159  1.1  oster 
    160  1.1  oster /*****************************************************************************************
    161  1.1  oster  *
    162  1.1  oster  * Ensure that all node->dagHdr fields in a dag are consistent
    163  1.1  oster  *
    164  1.1  oster  * IMPORTANT: This routine recursively searches all succedents of the node.  If a
    165  1.1  oster  * succedent is encountered whose dagHdr ptr does not require adjusting, that node's
    166  1.1  oster  * succedents WILL NOT BE EXAMINED.
    167  1.1  oster  *
    168  1.1  oster  ****************************************************************************************/
    169  1.1  oster static void UpdateNodeHdrPtr(hdr, node)
    170  1.1  oster   RF_DagHeader_t  *hdr;
    171  1.1  oster   RF_DagNode_t    *node;
    172  1.1  oster {
    173  1.1  oster   int i;
    174  1.1  oster   RF_ASSERT(hdr != NULL && node != NULL);
    175  1.1  oster   for (i = 0; i < node->numSuccedents; i++)
    176  1.1  oster     if (node->succedents[i]->dagHdr != hdr)
    177  1.1  oster       UpdateNodeHdrPtr(hdr, node->succedents[i]);
    178  1.1  oster   node->dagHdr = hdr;
    179  1.1  oster }
    180  1.1  oster 
    181  1.1  oster /******************************************************************************
    182  1.1  oster  *
    183  1.1  oster  * Create a DAG to do a read or write operation.
    184  1.1  oster  *
    185  1.1  oster  * create an array of dagLists, one list per parity stripe.
    186  1.1  oster  * return the lists in the array desc->dagArray.
    187  1.1  oster  *
    188  1.1  oster  * Normally, each list contains one dag for the entire stripe.  In some
    189  1.1  oster  * tricky cases, we break this into multiple dags, either one per stripe
    190  1.1  oster  * unit or one per block (sector).  When this occurs, these dags are returned
    191  1.1  oster  * as a linked list (dagList) which is executed sequentially (to preserve
    192  1.1  oster  * atomic parity updates in the stripe).
    193  1.1  oster  *
    194  1.1  oster  * dags which operate on independent parity goups (stripes) are returned in
    195  1.1  oster  * independent dagLists (distinct elements in desc->dagArray) and may be
    196  1.1  oster  * executed concurrently.
    197  1.1  oster  *
    198  1.1  oster  * Finally, if the SelectionFunc fails to create a dag for a block, we punt
    199  1.1  oster  * and return 1.
    200  1.1  oster  *
    201  1.1  oster  * The above process is performed in two phases:
    202  1.1  oster  *   1) create an array(s) of creation functions (eg stripeFuncs)
    203  1.1  oster  *   2) create dags and concatenate/merge to form the final dag.
    204  1.1  oster  *
    205  1.1  oster  * Because dag's are basic blocks (single entry, single exit, unconditional
    206  1.1  oster  * control flow, we can add the following optimizations (future work):
    207  1.1  oster  *   first-pass optimizer to allow max concurrency (need all data dependencies)
    208  1.1  oster  *   second-pass optimizer to eliminate common subexpressions (need true
    209  1.1  oster  *                         data dependencies)
    210  1.1  oster  *   third-pass optimizer to eliminate dead code (need true data dependencies)
    211  1.1  oster  *****************************************************************************/
    212  1.1  oster 
    213  1.1  oster #define MAXNSTRIPES 50
    214  1.1  oster 
    215  1.1  oster int rf_SelectAlgorithm(desc, flags)
    216  1.1  oster   RF_RaidAccessDesc_t   *desc;
    217  1.1  oster   RF_RaidAccessFlags_t   flags;
    218  1.1  oster {
    219  1.1  oster   RF_AccessStripeMapHeader_t *asm_h = desc->asmap;
    220  1.1  oster   RF_IoType_t type     = desc->type;
    221  1.1  oster   RF_Raid_t *raidPtr = desc->raidPtr;
    222  1.1  oster   void *bp      = desc->bp;
    223  1.1  oster 
    224  1.1  oster   RF_AccessStripeMap_t *asmap = asm_h->stripeMap;
    225  1.1  oster   RF_AccessStripeMap_t *asm_p;
    226  1.1  oster   RF_DagHeader_t *dag_h = NULL, *tempdag_h, *lastdag_h;
    227  1.1  oster   int i, j, k;
    228  1.1  oster   RF_VoidFuncPtr *stripeFuncs, normalStripeFuncs[MAXNSTRIPES];
    229  1.1  oster   RF_AccessStripeMap_t *asm_up, *asm_bp;
    230  1.1  oster   RF_AccessStripeMapHeader_t ***asmh_u, *endASMList;
    231  1.1  oster   RF_AccessStripeMapHeader_t ***asmh_b;
    232  1.1  oster   RF_VoidFuncPtr **stripeUnitFuncs, uFunc;
    233  1.1  oster   RF_VoidFuncPtr **blockFuncs, bFunc;
    234  1.1  oster   int numStripesBailed = 0, cantCreateDAGs = RF_FALSE;
    235  1.1  oster   int numStripeUnitsBailed = 0;
    236  1.1  oster   int stripeNum, numUnitDags = 0, stripeUnitNum, numBlockDags = 0;
    237  1.1  oster   RF_StripeNum_t numStripeUnits;
    238  1.1  oster   RF_SectorNum_t numBlocks;
    239  1.1  oster   RF_RaidAddr_t address;
    240  1.1  oster   int length;
    241  1.1  oster   RF_PhysDiskAddr_t *physPtr;
    242  1.1  oster   caddr_t buffer;
    243  1.1  oster 
    244  1.1  oster   lastdag_h = NULL;
    245  1.1  oster   asmh_u = asmh_b = NULL;
    246  1.1  oster   stripeUnitFuncs = NULL;
    247  1.1  oster   blockFuncs = NULL;
    248  1.1  oster 
    249  1.1  oster   /* get an array of dag-function creation pointers, try to avoid calling malloc */
    250  1.1  oster   if (asm_h->numStripes <= MAXNSTRIPES) stripeFuncs = normalStripeFuncs;
    251  1.1  oster   else RF_Calloc(stripeFuncs, asm_h->numStripes, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr *));
    252  1.1  oster 
    253  1.1  oster   /* walk through the asm list once collecting information */
    254  1.1  oster   /* attempt to find a single creation function for each stripe */
    255  1.1  oster   desc->numStripes = 0;
    256  1.1  oster   for (i=0,asm_p = asmap; asm_p; asm_p=asm_p->next,i++) {
    257  1.1  oster     desc->numStripes++;
    258  1.1  oster     (raidPtr->Layout.map->SelectionFunc)(raidPtr, type, asm_p, &stripeFuncs[i]);
    259  1.1  oster     /* check to see if we found a creation func for this stripe */
    260  1.1  oster     if (stripeFuncs[i] == (RF_VoidFuncPtr) NULL)
    261  1.1  oster       {
    262  1.1  oster 	/* could not find creation function for entire stripe
    263  1.1  oster 	   so, let's see if we can find one for each stripe unit in the stripe */
    264  1.1  oster 
    265  1.1  oster 	if (numStripesBailed == 0)
    266  1.1  oster 	  {
    267  1.1  oster 	    /* one stripe map header for each stripe we bail on */
    268  1.1  oster 	    RF_Malloc(asmh_u, sizeof(RF_AccessStripeMapHeader_t **) * asm_h->numStripes, (RF_AccessStripeMapHeader_t ***));
    269  1.1  oster 	    /* create an array of ptrs to arrays of stripeFuncs */
    270  1.1  oster 	    RF_Calloc(stripeUnitFuncs, asm_h->numStripes, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr **));
    271  1.1  oster 	  }
    272  1.1  oster 
    273  1.1  oster 	/* create an array of creation funcs (called stripeFuncs) for this stripe */
    274  1.1  oster 	numStripeUnits = asm_p->numStripeUnitsAccessed;
    275  1.1  oster 	RF_Calloc(stripeUnitFuncs[numStripesBailed], numStripeUnits, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr *));
    276  1.1  oster 	RF_Malloc(asmh_u[numStripesBailed], numStripeUnits * sizeof(RF_AccessStripeMapHeader_t *), (RF_AccessStripeMapHeader_t **));
    277  1.1  oster 
    278  1.1  oster 	/* lookup array of stripeUnitFuncs for this stripe */
    279  1.1  oster 	for (j=0, physPtr = asm_p->physInfo; physPtr; physPtr = physPtr->next, j++)
    280  1.1  oster 	  {
    281  1.1  oster 	    /* remap for series of single stripe-unit accesses */
    282  1.1  oster 	    address = physPtr->raidAddress;
    283  1.1  oster 	    length  = physPtr->numSector;
    284  1.1  oster 	    buffer  = physPtr->bufPtr;
    285  1.1  oster 
    286  1.1  oster 	    asmh_u[numStripesBailed][j] = rf_MapAccess(raidPtr, address, length, buffer, RF_DONT_REMAP);
    287  1.1  oster 	    asm_up = asmh_u[numStripesBailed][j]->stripeMap;
    288  1.1  oster 
    289  1.1  oster 	    /* get the creation func for this stripe unit */
    290  1.1  oster 	    (raidPtr->Layout.map-> SelectionFunc)(raidPtr, type, asm_up, &(stripeUnitFuncs[numStripesBailed][j]));
    291  1.1  oster 
    292  1.1  oster 	    /* check to see if we found a creation func for this stripe unit */
    293  1.1  oster 	    if (stripeUnitFuncs[numStripesBailed][j] == (RF_VoidFuncPtr) NULL)
    294  1.1  oster 	      {
    295  1.1  oster 		/* could not find creation function for stripe unit so,
    296  1.1  oster 		   let's see if we can find one for each block in the stripe unit */
    297  1.1  oster 		if (numStripeUnitsBailed == 0)
    298  1.1  oster 		  {
    299  1.1  oster 		    /* one stripe map header for each stripe unit we bail on */
    300  1.1  oster 		    RF_Malloc(asmh_b, sizeof(RF_AccessStripeMapHeader_t **) * asm_h->numStripes * raidPtr->Layout.numDataCol, (RF_AccessStripeMapHeader_t ***));
    301  1.1  oster 		    /* create an array of ptrs to arrays of blockFuncs */
    302  1.1  oster 		    RF_Calloc(blockFuncs, asm_h->numStripes * raidPtr->Layout.numDataCol, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr **));
    303  1.1  oster 		  }
    304  1.1  oster 
    305  1.1  oster 		/* create an array of creation funcs (called blockFuncs) for this stripe unit */
    306  1.1  oster 		numBlocks = physPtr->numSector;
    307  1.1  oster 		numBlockDags += numBlocks;
    308  1.1  oster 		RF_Calloc(blockFuncs[numStripeUnitsBailed], numBlocks, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr *));
    309  1.1  oster 		RF_Malloc(asmh_b[numStripeUnitsBailed], numBlocks * sizeof(RF_AccessStripeMapHeader_t *), (RF_AccessStripeMapHeader_t **));
    310  1.1  oster 
    311  1.1  oster 		/* lookup array of blockFuncs for this stripe unit */
    312  1.1  oster 		for (k=0; k < numBlocks; k++)
    313  1.1  oster 		  {
    314  1.1  oster 		    /* remap for series of single stripe-unit accesses */
    315  1.1  oster 		    address = physPtr->raidAddress + k;
    316  1.1  oster 		    length  = 1;
    317  1.1  oster 		    buffer  = physPtr->bufPtr + (k * (1<<raidPtr->logBytesPerSector));
    318  1.1  oster 
    319  1.1  oster 		    asmh_b[numStripeUnitsBailed][k] = rf_MapAccess(raidPtr, address, length, buffer, RF_DONT_REMAP);
    320  1.1  oster 		    asm_bp = asmh_b[numStripeUnitsBailed][k]->stripeMap;
    321  1.1  oster 
    322  1.1  oster 		    /* get the creation func for this stripe unit */
    323  1.1  oster 		    (raidPtr->Layout.map-> SelectionFunc)(raidPtr, type, asm_bp, &(blockFuncs[numStripeUnitsBailed][k]));
    324  1.1  oster 
    325  1.1  oster 		    /* check to see if we found a creation func for this stripe unit */
    326  1.1  oster 		    if (blockFuncs[numStripeUnitsBailed][k] == NULL)
    327  1.1  oster 		      cantCreateDAGs = RF_TRUE;
    328  1.1  oster 		  }
    329  1.1  oster 		numStripeUnitsBailed++;
    330  1.1  oster 	      }
    331  1.1  oster 	    else
    332  1.1  oster 	      {
    333  1.1  oster 		numUnitDags++;
    334  1.1  oster 	      }
    335  1.1  oster 	  }
    336  1.1  oster 	RF_ASSERT(j == numStripeUnits);
    337  1.1  oster 	numStripesBailed++;
    338  1.1  oster       }
    339  1.1  oster   }
    340  1.1  oster 
    341  1.1  oster   if (cantCreateDAGs)
    342  1.1  oster     {
    343  1.1  oster       /* free memory and punt */
    344  1.1  oster       if (asm_h->numStripes > MAXNSTRIPES)
    345  1.1  oster 	RF_Free(stripeFuncs, asm_h->numStripes * sizeof(RF_VoidFuncPtr));
    346  1.1  oster       if (numStripesBailed > 0)
    347  1.1  oster 	{
    348  1.1  oster 	  stripeNum = 0;
    349  1.1  oster 	  for (i = 0, asm_p = asmap; asm_p; asm_p = asm_p->next, i++)
    350  1.1  oster 	    if (stripeFuncs[i] == NULL)
    351  1.1  oster 	      {
    352  1.1  oster 		numStripeUnits = asm_p->numStripeUnitsAccessed;
    353  1.1  oster 		for (j = 0; j < numStripeUnits; j++)
    354  1.1  oster 		    rf_FreeAccessStripeMap(asmh_u[stripeNum][j]);
    355  1.1  oster 		RF_Free(asmh_u[stripeNum], numStripeUnits * sizeof(RF_AccessStripeMapHeader_t *));
    356  1.1  oster 		RF_Free(stripeUnitFuncs[stripeNum], numStripeUnits * sizeof(RF_VoidFuncPtr));
    357  1.1  oster 		stripeNum++;
    358  1.1  oster 	      }
    359  1.1  oster 	  RF_ASSERT(stripeNum == numStripesBailed);
    360  1.1  oster 	  RF_Free(stripeUnitFuncs, asm_h->numStripes * sizeof(RF_VoidFuncPtr));
    361  1.1  oster 	  RF_Free(asmh_u, asm_h->numStripes * sizeof(RF_AccessStripeMapHeader_t **));
    362  1.1  oster 	}
    363  1.1  oster       return(1);
    364  1.1  oster     }
    365  1.1  oster   else
    366  1.1  oster     {
    367  1.1  oster       /* begin dag creation */
    368  1.1  oster       stripeNum = 0;
    369  1.1  oster       stripeUnitNum = 0;
    370  1.1  oster 
    371  1.1  oster       /* create an array of dagLists and fill them in */
    372  1.1  oster       RF_CallocAndAdd(desc->dagArray, desc->numStripes, sizeof(RF_DagList_t), (RF_DagList_t *), desc->cleanupList);
    373  1.1  oster 
    374  1.1  oster       for (i=0, asm_p = asmap; asm_p; asm_p=asm_p->next,i++) {
    375  1.1  oster 	/* grab dag header for this stripe */
    376  1.1  oster 	dag_h = NULL;
    377  1.1  oster 	desc->dagArray[i].desc = desc;
    378  1.1  oster 
    379  1.1  oster 	if (stripeFuncs[i] == (RF_VoidFuncPtr) NULL)
    380  1.1  oster 	  {
    381  1.1  oster 	    /* use bailout functions for this stripe */
    382  1.1  oster 	    for (j = 0, physPtr = asm_p->physInfo; physPtr; physPtr=physPtr->next, j++)
    383  1.1  oster 	      {
    384  1.1  oster 		uFunc = stripeUnitFuncs[stripeNum][j];
    385  1.1  oster 		if (uFunc == (RF_VoidFuncPtr) NULL)
    386  1.1  oster 		  {
    387  1.1  oster 		    /* use bailout functions for this stripe unit */
    388  1.1  oster 		    for (k = 0; k < physPtr->numSector; k++)
    389  1.1  oster 		      {
    390  1.1  oster 			/* create a dag for this block */
    391  1.1  oster 			InitHdrNode(&tempdag_h, raidPtr, rf_useMemChunks);
    392  1.1  oster 			desc->dagArray[i].numDags++;
    393  1.1  oster 			if (dag_h == NULL) {
    394  1.1  oster 			  dag_h = tempdag_h;
    395  1.1  oster 			}
    396  1.1  oster 			else {
    397  1.1  oster 			  lastdag_h->next = tempdag_h;
    398  1.1  oster 			}
    399  1.1  oster 			lastdag_h = tempdag_h;
    400  1.1  oster 
    401  1.1  oster 			bFunc = blockFuncs[stripeUnitNum][k];
    402  1.1  oster 			RF_ASSERT(bFunc);
    403  1.1  oster 			asm_bp = asmh_b[stripeUnitNum][k]->stripeMap;
    404  1.1  oster 			(*bFunc)(raidPtr, asm_bp, tempdag_h, bp, flags, tempdag_h->allocList);
    405  1.1  oster 		      }
    406  1.1  oster 		    stripeUnitNum++;
    407  1.1  oster 		  }
    408  1.1  oster 		else
    409  1.1  oster 		  {
    410  1.1  oster 		    /* create a dag for this unit */
    411  1.1  oster 		    InitHdrNode(&tempdag_h, raidPtr, rf_useMemChunks);
    412  1.1  oster 		    desc->dagArray[i].numDags++;
    413  1.1  oster 		    if (dag_h == NULL) {
    414  1.1  oster 		      dag_h = tempdag_h;
    415  1.1  oster 		    }
    416  1.1  oster 		    else {
    417  1.1  oster 		      lastdag_h->next = tempdag_h;
    418  1.1  oster 		    }
    419  1.1  oster 		    lastdag_h = tempdag_h;
    420  1.1  oster 
    421  1.1  oster 		    asm_up = asmh_u[stripeNum][j]->stripeMap;
    422  1.1  oster 		    (*uFunc)(raidPtr, asm_up, tempdag_h, bp, flags, tempdag_h->allocList);
    423  1.1  oster 		  }
    424  1.1  oster 	      }
    425  1.1  oster 	    RF_ASSERT(j == asm_p->numStripeUnitsAccessed);
    426  1.1  oster 	    /* merge linked bailout dag to existing dag collection */
    427  1.1  oster 	    stripeNum++;
    428  1.1  oster 	  }
    429  1.1  oster 	else {
    430  1.1  oster 	  /* Create a dag for this parity stripe */
    431  1.1  oster 	  InitHdrNode(&tempdag_h, raidPtr, rf_useMemChunks);
    432  1.1  oster 	  desc->dagArray[i].numDags++;
    433  1.1  oster 	  if (dag_h == NULL) {
    434  1.1  oster 	    dag_h = tempdag_h;
    435  1.1  oster 	  }
    436  1.1  oster 	  else {
    437  1.1  oster 	    lastdag_h->next = tempdag_h;
    438  1.1  oster 	  }
    439  1.1  oster 	  lastdag_h = tempdag_h;
    440  1.1  oster 
    441  1.1  oster 	  (stripeFuncs[i])(raidPtr, asm_p, tempdag_h, bp, flags, tempdag_h->allocList);
    442  1.1  oster 	}
    443  1.1  oster 	desc->dagArray[i].dags = dag_h;
    444  1.1  oster       }
    445  1.1  oster       RF_ASSERT(i == desc->numStripes);
    446  1.1  oster 
    447  1.1  oster       /* free memory */
    448  1.1  oster       if (asm_h->numStripes > MAXNSTRIPES)
    449  1.1  oster 	RF_Free(stripeFuncs, asm_h->numStripes * sizeof(RF_VoidFuncPtr));
    450  1.1  oster       if ((numStripesBailed > 0) || (numStripeUnitsBailed > 0))
    451  1.1  oster 	{
    452  1.1  oster 	  stripeNum = 0;
    453  1.1  oster 	  stripeUnitNum = 0;
    454  1.1  oster 	  if (dag_h->asmList)
    455  1.1  oster 	    {
    456  1.1  oster 	      endASMList = dag_h->asmList;
    457  1.1  oster 	      while (endASMList->next)
    458  1.1  oster 		endASMList = endASMList->next;
    459  1.1  oster 	    }
    460  1.1  oster 	  else
    461  1.1  oster 	    endASMList = NULL;
    462  1.1  oster 	  /* walk through io, stripe by stripe */
    463  1.1  oster 	  for (i = 0, asm_p = asmap; asm_p; asm_p = asm_p->next, i++)
    464  1.1  oster 	    if (stripeFuncs[i] == NULL)
    465  1.1  oster 	      {
    466  1.1  oster 		numStripeUnits = asm_p->numStripeUnitsAccessed;
    467  1.1  oster 		/* walk through stripe, stripe unit by stripe unit */
    468  1.1  oster 		for (j = 0, physPtr = asm_p->physInfo; physPtr; physPtr = physPtr->next, j++)
    469  1.1  oster 		  {
    470  1.1  oster 		    if (stripeUnitFuncs[stripeNum][j] == NULL)
    471  1.1  oster 		      {
    472  1.1  oster 			numBlocks = physPtr->numSector;
    473  1.1  oster 			/* walk through stripe unit, block by block */
    474  1.1  oster 			for (k = 0; k < numBlocks; k++)
    475  1.1  oster 			  if (dag_h->asmList == NULL)
    476  1.1  oster 			    {
    477  1.1  oster 			      dag_h->asmList = asmh_b[stripeUnitNum][k];
    478  1.1  oster 			      endASMList = dag_h->asmList;
    479  1.1  oster 			    }
    480  1.1  oster 			  else
    481  1.1  oster 			    {
    482  1.1  oster 			      endASMList->next = asmh_b[stripeUnitNum][k];
    483  1.1  oster 			      endASMList = endASMList->next;
    484  1.1  oster 			    }
    485  1.1  oster 			RF_Free(asmh_b[stripeUnitNum], numBlocks * sizeof(RF_AccessStripeMapHeader_t *));
    486  1.1  oster 			RF_Free(blockFuncs[stripeUnitNum], numBlocks * sizeof(RF_VoidFuncPtr));
    487  1.1  oster 			stripeUnitNum++;
    488  1.1  oster 		      }
    489  1.1  oster 		    if (dag_h->asmList == NULL)
    490  1.1  oster 		      {
    491  1.1  oster 			dag_h->asmList = asmh_u[stripeNum][j];
    492  1.1  oster 			endASMList = dag_h->asmList;
    493  1.1  oster 		      }
    494  1.1  oster 		    else
    495  1.1  oster 		      {
    496  1.1  oster 			endASMList->next = asmh_u[stripeNum][j];
    497  1.1  oster 			endASMList = endASMList->next;
    498  1.1  oster 		      }
    499  1.1  oster 		  }
    500  1.1  oster 		RF_Free(asmh_u[stripeNum], numStripeUnits * sizeof(RF_AccessStripeMapHeader_t *));
    501  1.1  oster 		RF_Free(stripeUnitFuncs[stripeNum], numStripeUnits * sizeof(RF_VoidFuncPtr));
    502  1.1  oster 		stripeNum++;
    503  1.1  oster 	      }
    504  1.1  oster 	  RF_ASSERT(stripeNum == numStripesBailed);
    505  1.1  oster 	  RF_Free(stripeUnitFuncs, asm_h->numStripes * sizeof(RF_VoidFuncPtr));
    506  1.1  oster 	  RF_Free(asmh_u, asm_h->numStripes * sizeof(RF_AccessStripeMapHeader_t **));
    507  1.1  oster 	  if (numStripeUnitsBailed > 0)
    508  1.1  oster 	    {
    509  1.1  oster 	      RF_ASSERT(stripeUnitNum == numStripeUnitsBailed);
    510  1.1  oster 	      RF_Free(blockFuncs, raidPtr->Layout.numDataCol * asm_h->numStripes * sizeof(RF_VoidFuncPtr));
    511  1.1  oster 	      RF_Free(asmh_b, raidPtr->Layout.numDataCol * asm_h->numStripes * sizeof(RF_AccessStripeMapHeader_t **));
    512  1.1  oster 	    }
    513  1.1  oster 	}
    514  1.1  oster       return(0);
    515  1.1  oster     }
    516  1.1  oster }
    517