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