rf_aselect.c revision 1.1 1 1.1 oster /* $NetBSD: rf_aselect.c,v 1.1 1998/11/13 04:20:26 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.1 oster /*
35 1.1 oster * :
36 1.1 oster * Log: rf_aselect.c,v
37 1.1 oster * Revision 1.35 1996/07/28 20:31:39 jimz
38 1.1 oster * i386netbsd port
39 1.1 oster * true/false fixup
40 1.1 oster *
41 1.1 oster * Revision 1.34 1996/07/27 18:39:39 jimz
42 1.1 oster * cleanup sweep
43 1.1 oster *
44 1.1 oster * Revision 1.33 1996/07/22 19:52:16 jimz
45 1.1 oster * switched node params to RF_DagParam_t, a union of
46 1.1 oster * a 64-bit int and a void *, for better portability
47 1.1 oster * attempted hpux port, but failed partway through for
48 1.1 oster * lack of a single C compiler capable of compiling all
49 1.1 oster * source files
50 1.1 oster *
51 1.1 oster * Revision 1.32 1996/06/12 03:29:40 jimz
52 1.1 oster * Note: things that call InitHdrNode should check
53 1.1 oster * for successful return.
54 1.1 oster *
55 1.1 oster * Revision 1.31 1996/06/07 21:33:04 jimz
56 1.1 oster * begin using consistent types for sector numbers,
57 1.1 oster * stripe numbers, row+col numbers, recon unit numbers
58 1.1 oster *
59 1.1 oster * Revision 1.30 1996/06/05 18:06:02 jimz
60 1.1 oster * Major code cleanup. The Great Renaming is now done.
61 1.1 oster * Better modularity. Better typing. Fixed a bunch of
62 1.1 oster * synchronization bugs. Made a lot of global stuff
63 1.1 oster * per-desc or per-array. Removed dead code.
64 1.1 oster *
65 1.1 oster * Revision 1.29 1996/05/31 22:26:54 jimz
66 1.1 oster * fix a lot of mapping problems, memory allocation problems
67 1.1 oster * found some weird lock issues, fixed 'em
68 1.1 oster * more code cleanup
69 1.1 oster *
70 1.1 oster * Revision 1.28 1996/05/30 11:29:41 jimz
71 1.1 oster * Numerous bug fixes. Stripe lock release code disagreed with the taking code
72 1.1 oster * about when stripes should be locked (I made it consistent: no parity, no lock)
73 1.1 oster * There was a lot of extra serialization of I/Os which I've removed- a lot of
74 1.1 oster * it was to calculate values for the cache code, which is no longer with us.
75 1.1 oster * More types, function, macro cleanup. Added code to properly quiesce the array
76 1.1 oster * on shutdown. Made a lot of stuff array-specific which was (bogusly) general
77 1.1 oster * before. Fixed memory allocation, freeing bugs.
78 1.1 oster *
79 1.1 oster * Revision 1.27 1996/05/27 18:56:37 jimz
80 1.1 oster * more code cleanup
81 1.1 oster * better typing
82 1.1 oster * compiles in all 3 environments
83 1.1 oster *
84 1.1 oster * Revision 1.26 1996/05/24 22:17:04 jimz
85 1.1 oster * continue code + namespace cleanup
86 1.1 oster * typed a bunch of flags
87 1.1 oster *
88 1.1 oster * Revision 1.25 1996/05/24 04:28:55 jimz
89 1.1 oster * release cleanup ckpt
90 1.1 oster *
91 1.1 oster * Revision 1.24 1996/05/23 21:46:35 jimz
92 1.1 oster * checkpoint in code cleanup (release prep)
93 1.1 oster * lots of types, function names have been fixed
94 1.1 oster *
95 1.1 oster * Revision 1.23 1996/05/23 00:33:23 jimz
96 1.1 oster * code cleanup: move all debug decls to rf_options.c, all extern
97 1.1 oster * debug decls to rf_options.h, all debug vars preceded by rf_
98 1.1 oster *
99 1.1 oster * Revision 1.22 1996/05/18 19:51:34 jimz
100 1.1 oster * major code cleanup- fix syntax, make some types consistent,
101 1.1 oster * add prototypes, clean out dead code, et cetera
102 1.1 oster *
103 1.1 oster * Revision 1.21 1996/05/08 21:01:24 jimz
104 1.1 oster * fixed up enum type names that were conflicting with other
105 1.1 oster * enums and function names (ie, "panic")
106 1.1 oster * future naming trends will be towards RF_ and rf_ for
107 1.1 oster * everything raidframe-related
108 1.1 oster *
109 1.1 oster * Revision 1.20 1996/05/03 19:45:35 wvcii
110 1.1 oster * removed includes of old deg creation files
111 1.1 oster * updated SelectAlgorithm comments
112 1.1 oster *
113 1.1 oster * Revision 1.19 1995/12/12 18:10:06 jimz
114 1.1 oster * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
115 1.1 oster * fix 80-column brain damage in comments
116 1.1 oster *
117 1.1 oster * Revision 1.18 1995/11/30 16:27:48 wvcii
118 1.1 oster * added copyright info
119 1.1 oster *
120 1.1 oster * Revision 1.17 1995/11/19 16:25:55 wvcii
121 1.1 oster * SelectAlgorithm now creates an array, returned in desc->dagArray
122 1.1 oster * return value is now int (1 = FAIL)
123 1.1 oster *
124 1.1 oster * Revision 1.16 1995/11/17 15:09:58 wvcii
125 1.1 oster * fixed bug in SelectAlgorithm in which multiple graphs per stripe are required
126 1.1 oster *
127 1.1 oster * Revision 1.15 1995/11/07 17:12:42 wvcii
128 1.1 oster * changed SelectAlgorithm as follows:
129 1.1 oster *
130 1.1 oster * dag creation funcs now create term nodes
131 1.1 oster * dag selection funcs no longer return numHdrSucc, numTermAnt
132 1.1 oster * there is now one dag hdr for each dag in a request, implying
133 1.1 oster * that SelectAlgorithm now returns a linked list of dag hdrs
134 1.1 oster *
135 1.1 oster */
136 1.1 oster
137 1.1 oster #include "rf_archs.h"
138 1.1 oster #include "rf_types.h"
139 1.1 oster #include "rf_raid.h"
140 1.1 oster #include "rf_dag.h"
141 1.1 oster #include "rf_dagutils.h"
142 1.1 oster #include "rf_dagfuncs.h"
143 1.1 oster #include "rf_general.h"
144 1.1 oster #include "rf_desc.h"
145 1.1 oster #include "rf_map.h"
146 1.1 oster
147 1.1 oster #if defined(__NetBSD__) && defined(_KERNEL)
148 1.1 oster /* the function below is not used... so don't define it! */
149 1.1 oster #else
150 1.1 oster static void TransferDagMemory(RF_DagHeader_t *, RF_DagHeader_t *);
151 1.1 oster #endif
152 1.1 oster
153 1.1 oster static int InitHdrNode(RF_DagHeader_t **, RF_Raid_t *, int);
154 1.1 oster static void UpdateNodeHdrPtr(RF_DagHeader_t *, RF_DagNode_t *);
155 1.1 oster int rf_SelectAlgorithm(RF_RaidAccessDesc_t *, RF_RaidAccessFlags_t );
156 1.1 oster
157 1.1 oster
158 1.1 oster /******************************************************************************
159 1.1 oster *
160 1.1 oster * Create and Initialiaze a dag header and termination node
161 1.1 oster *
162 1.1 oster *****************************************************************************/
163 1.1 oster static int InitHdrNode(hdr, raidPtr, memChunkEnable)
164 1.1 oster RF_DagHeader_t **hdr;
165 1.1 oster RF_Raid_t *raidPtr;
166 1.1 oster int memChunkEnable;
167 1.1 oster {
168 1.1 oster /* create and initialize dag hdr */
169 1.1 oster *hdr = rf_AllocDAGHeader();
170 1.1 oster rf_MakeAllocList((*hdr)->allocList);
171 1.1 oster if ((*hdr)->allocList == NULL) {
172 1.1 oster rf_FreeDAGHeader(*hdr);
173 1.1 oster return(ENOMEM);
174 1.1 oster }
175 1.1 oster (*hdr)->status = rf_enable;
176 1.1 oster (*hdr)->numSuccedents = 0;
177 1.1 oster (*hdr)->raidPtr = raidPtr;
178 1.1 oster (*hdr)->next = NULL;
179 1.1 oster return(0);
180 1.1 oster }
181 1.1 oster
182 1.1 oster /******************************************************************************
183 1.1 oster *
184 1.1 oster * Transfer allocation list and mem chunks from one dag to another
185 1.1 oster *
186 1.1 oster *****************************************************************************/
187 1.1 oster #if defined(__NetBSD__) && defined(_KERNEL)
188 1.1 oster /* the function below is not used... so don't define it! */
189 1.1 oster #else
190 1.1 oster static void TransferDagMemory(daga, dagb)
191 1.1 oster RF_DagHeader_t *daga;
192 1.1 oster RF_DagHeader_t *dagb;
193 1.1 oster {
194 1.1 oster RF_AccessStripeMapHeader_t *end;
195 1.1 oster RF_AllocListElem_t *p;
196 1.1 oster int i, memChunksXfrd = 0, xtraChunksXfrd = 0;
197 1.1 oster
198 1.1 oster /* transfer allocList from dagb to daga */
199 1.1 oster for (p = dagb->allocList; p ; p = p->next)
200 1.1 oster {
201 1.1 oster for (i = 0; i < p->numPointers; i++)
202 1.1 oster {
203 1.1 oster rf_AddToAllocList(daga->allocList, p->pointers[i], p->sizes[i]);
204 1.1 oster p->pointers[i] = NULL;
205 1.1 oster p->sizes[i] = 0;
206 1.1 oster }
207 1.1 oster p->numPointers = 0;
208 1.1 oster }
209 1.1 oster
210 1.1 oster /* transfer chunks from dagb to daga */
211 1.1 oster while ((memChunksXfrd + xtraChunksXfrd < dagb->chunkIndex + dagb->xtraChunkIndex) && (daga->chunkIndex < RF_MAXCHUNKS))
212 1.1 oster {
213 1.1 oster /* stuff chunks into daga's memChunk array */
214 1.1 oster if (memChunksXfrd < dagb->chunkIndex)
215 1.1 oster {
216 1.1 oster daga->memChunk[daga->chunkIndex++] = dagb->memChunk[memChunksXfrd];
217 1.1 oster dagb->memChunk[memChunksXfrd++] = NULL;
218 1.1 oster }
219 1.1 oster else
220 1.1 oster {
221 1.1 oster daga->memChunk[daga->xtraChunkIndex++] = dagb->xtraMemChunk[xtraChunksXfrd];
222 1.1 oster dagb->xtraMemChunk[xtraChunksXfrd++] = NULL;
223 1.1 oster }
224 1.1 oster }
225 1.1 oster /* use escape hatch to hold excess chunks */
226 1.1 oster while (memChunksXfrd + xtraChunksXfrd < dagb->chunkIndex + dagb->xtraChunkIndex) {
227 1.1 oster if (memChunksXfrd < dagb->chunkIndex)
228 1.1 oster {
229 1.1 oster daga->xtraMemChunk[daga->xtraChunkIndex++] = dagb->memChunk[memChunksXfrd];
230 1.1 oster dagb->memChunk[memChunksXfrd++] = NULL;
231 1.1 oster }
232 1.1 oster else
233 1.1 oster {
234 1.1 oster daga->xtraMemChunk[daga->xtraChunkIndex++] = dagb->xtraMemChunk[xtraChunksXfrd];
235 1.1 oster dagb->xtraMemChunk[xtraChunksXfrd++] = NULL;
236 1.1 oster }
237 1.1 oster }
238 1.1 oster RF_ASSERT((memChunksXfrd == dagb->chunkIndex) && (xtraChunksXfrd == dagb->xtraChunkIndex));
239 1.1 oster RF_ASSERT(daga->chunkIndex <= RF_MAXCHUNKS);
240 1.1 oster RF_ASSERT(daga->xtraChunkIndex <= daga->xtraChunkCnt);
241 1.1 oster dagb->chunkIndex = 0;
242 1.1 oster dagb->xtraChunkIndex = 0;
243 1.1 oster
244 1.1 oster /* transfer asmList from dagb to daga */
245 1.1 oster if (dagb->asmList)
246 1.1 oster {
247 1.1 oster if (daga->asmList)
248 1.1 oster {
249 1.1 oster end = daga->asmList;
250 1.1 oster while (end->next)
251 1.1 oster end = end->next;
252 1.1 oster end->next = dagb->asmList;
253 1.1 oster }
254 1.1 oster else
255 1.1 oster daga->asmList = dagb->asmList;
256 1.1 oster dagb->asmList = NULL;
257 1.1 oster }
258 1.1 oster }
259 1.1 oster #endif /* __NetBSD__ */
260 1.1 oster
261 1.1 oster /*****************************************************************************************
262 1.1 oster *
263 1.1 oster * Ensure that all node->dagHdr fields in a dag are consistent
264 1.1 oster *
265 1.1 oster * IMPORTANT: This routine recursively searches all succedents of the node. If a
266 1.1 oster * succedent is encountered whose dagHdr ptr does not require adjusting, that node's
267 1.1 oster * succedents WILL NOT BE EXAMINED.
268 1.1 oster *
269 1.1 oster ****************************************************************************************/
270 1.1 oster static void UpdateNodeHdrPtr(hdr, node)
271 1.1 oster RF_DagHeader_t *hdr;
272 1.1 oster RF_DagNode_t *node;
273 1.1 oster {
274 1.1 oster int i;
275 1.1 oster RF_ASSERT(hdr != NULL && node != NULL);
276 1.1 oster for (i = 0; i < node->numSuccedents; i++)
277 1.1 oster if (node->succedents[i]->dagHdr != hdr)
278 1.1 oster UpdateNodeHdrPtr(hdr, node->succedents[i]);
279 1.1 oster node->dagHdr = hdr;
280 1.1 oster }
281 1.1 oster
282 1.1 oster /******************************************************************************
283 1.1 oster *
284 1.1 oster * Create a DAG to do a read or write operation.
285 1.1 oster *
286 1.1 oster * create an array of dagLists, one list per parity stripe.
287 1.1 oster * return the lists in the array desc->dagArray.
288 1.1 oster *
289 1.1 oster * Normally, each list contains one dag for the entire stripe. In some
290 1.1 oster * tricky cases, we break this into multiple dags, either one per stripe
291 1.1 oster * unit or one per block (sector). When this occurs, these dags are returned
292 1.1 oster * as a linked list (dagList) which is executed sequentially (to preserve
293 1.1 oster * atomic parity updates in the stripe).
294 1.1 oster *
295 1.1 oster * dags which operate on independent parity goups (stripes) are returned in
296 1.1 oster * independent dagLists (distinct elements in desc->dagArray) and may be
297 1.1 oster * executed concurrently.
298 1.1 oster *
299 1.1 oster * Finally, if the SelectionFunc fails to create a dag for a block, we punt
300 1.1 oster * and return 1.
301 1.1 oster *
302 1.1 oster * The above process is performed in two phases:
303 1.1 oster * 1) create an array(s) of creation functions (eg stripeFuncs)
304 1.1 oster * 2) create dags and concatenate/merge to form the final dag.
305 1.1 oster *
306 1.1 oster * Because dag's are basic blocks (single entry, single exit, unconditional
307 1.1 oster * control flow, we can add the following optimizations (future work):
308 1.1 oster * first-pass optimizer to allow max concurrency (need all data dependencies)
309 1.1 oster * second-pass optimizer to eliminate common subexpressions (need true
310 1.1 oster * data dependencies)
311 1.1 oster * third-pass optimizer to eliminate dead code (need true data dependencies)
312 1.1 oster *****************************************************************************/
313 1.1 oster
314 1.1 oster #define MAXNSTRIPES 50
315 1.1 oster
316 1.1 oster int rf_SelectAlgorithm(desc, flags)
317 1.1 oster RF_RaidAccessDesc_t *desc;
318 1.1 oster RF_RaidAccessFlags_t flags;
319 1.1 oster {
320 1.1 oster RF_AccessStripeMapHeader_t *asm_h = desc->asmap;
321 1.1 oster RF_IoType_t type = desc->type;
322 1.1 oster RF_Raid_t *raidPtr = desc->raidPtr;
323 1.1 oster void *bp = desc->bp;
324 1.1 oster
325 1.1 oster RF_AccessStripeMap_t *asmap = asm_h->stripeMap;
326 1.1 oster RF_AccessStripeMap_t *asm_p;
327 1.1 oster RF_DagHeader_t *dag_h = NULL, *tempdag_h, *lastdag_h;
328 1.1 oster int i, j, k;
329 1.1 oster RF_VoidFuncPtr *stripeFuncs, normalStripeFuncs[MAXNSTRIPES];
330 1.1 oster RF_AccessStripeMap_t *asm_up, *asm_bp;
331 1.1 oster RF_AccessStripeMapHeader_t ***asmh_u, *endASMList;
332 1.1 oster RF_AccessStripeMapHeader_t ***asmh_b;
333 1.1 oster RF_VoidFuncPtr **stripeUnitFuncs, uFunc;
334 1.1 oster RF_VoidFuncPtr **blockFuncs, bFunc;
335 1.1 oster int numStripesBailed = 0, cantCreateDAGs = RF_FALSE;
336 1.1 oster int numStripeUnitsBailed = 0;
337 1.1 oster int stripeNum, numUnitDags = 0, stripeUnitNum, numBlockDags = 0;
338 1.1 oster RF_StripeNum_t numStripeUnits;
339 1.1 oster RF_SectorNum_t numBlocks;
340 1.1 oster RF_RaidAddr_t address;
341 1.1 oster int length;
342 1.1 oster RF_PhysDiskAddr_t *physPtr;
343 1.1 oster caddr_t buffer;
344 1.1 oster
345 1.1 oster lastdag_h = NULL;
346 1.1 oster asmh_u = asmh_b = NULL;
347 1.1 oster stripeUnitFuncs = NULL;
348 1.1 oster blockFuncs = NULL;
349 1.1 oster
350 1.1 oster /* get an array of dag-function creation pointers, try to avoid calling malloc */
351 1.1 oster if (asm_h->numStripes <= MAXNSTRIPES) stripeFuncs = normalStripeFuncs;
352 1.1 oster else RF_Calloc(stripeFuncs, asm_h->numStripes, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr *));
353 1.1 oster
354 1.1 oster /* walk through the asm list once collecting information */
355 1.1 oster /* attempt to find a single creation function for each stripe */
356 1.1 oster desc->numStripes = 0;
357 1.1 oster for (i=0,asm_p = asmap; asm_p; asm_p=asm_p->next,i++) {
358 1.1 oster desc->numStripes++;
359 1.1 oster (raidPtr->Layout.map->SelectionFunc)(raidPtr, type, asm_p, &stripeFuncs[i]);
360 1.1 oster /* check to see if we found a creation func for this stripe */
361 1.1 oster if (stripeFuncs[i] == (RF_VoidFuncPtr) NULL)
362 1.1 oster {
363 1.1 oster /* could not find creation function for entire stripe
364 1.1 oster so, let's see if we can find one for each stripe unit in the stripe */
365 1.1 oster
366 1.1 oster if (numStripesBailed == 0)
367 1.1 oster {
368 1.1 oster /* one stripe map header for each stripe we bail on */
369 1.1 oster RF_Malloc(asmh_u, sizeof(RF_AccessStripeMapHeader_t **) * asm_h->numStripes, (RF_AccessStripeMapHeader_t ***));
370 1.1 oster /* create an array of ptrs to arrays of stripeFuncs */
371 1.1 oster RF_Calloc(stripeUnitFuncs, asm_h->numStripes, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr **));
372 1.1 oster }
373 1.1 oster
374 1.1 oster /* create an array of creation funcs (called stripeFuncs) for this stripe */
375 1.1 oster numStripeUnits = asm_p->numStripeUnitsAccessed;
376 1.1 oster RF_Calloc(stripeUnitFuncs[numStripesBailed], numStripeUnits, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr *));
377 1.1 oster RF_Malloc(asmh_u[numStripesBailed], numStripeUnits * sizeof(RF_AccessStripeMapHeader_t *), (RF_AccessStripeMapHeader_t **));
378 1.1 oster
379 1.1 oster /* lookup array of stripeUnitFuncs for this stripe */
380 1.1 oster for (j=0, physPtr = asm_p->physInfo; physPtr; physPtr = physPtr->next, j++)
381 1.1 oster {
382 1.1 oster /* remap for series of single stripe-unit accesses */
383 1.1 oster address = physPtr->raidAddress;
384 1.1 oster length = physPtr->numSector;
385 1.1 oster buffer = physPtr->bufPtr;
386 1.1 oster
387 1.1 oster asmh_u[numStripesBailed][j] = rf_MapAccess(raidPtr, address, length, buffer, RF_DONT_REMAP);
388 1.1 oster asm_up = asmh_u[numStripesBailed][j]->stripeMap;
389 1.1 oster
390 1.1 oster /* get the creation func for this stripe unit */
391 1.1 oster (raidPtr->Layout.map-> SelectionFunc)(raidPtr, type, asm_up, &(stripeUnitFuncs[numStripesBailed][j]));
392 1.1 oster
393 1.1 oster /* check to see if we found a creation func for this stripe unit */
394 1.1 oster if (stripeUnitFuncs[numStripesBailed][j] == (RF_VoidFuncPtr) NULL)
395 1.1 oster {
396 1.1 oster /* could not find creation function for stripe unit so,
397 1.1 oster let's see if we can find one for each block in the stripe unit */
398 1.1 oster if (numStripeUnitsBailed == 0)
399 1.1 oster {
400 1.1 oster /* one stripe map header for each stripe unit we bail on */
401 1.1 oster RF_Malloc(asmh_b, sizeof(RF_AccessStripeMapHeader_t **) * asm_h->numStripes * raidPtr->Layout.numDataCol, (RF_AccessStripeMapHeader_t ***));
402 1.1 oster /* create an array of ptrs to arrays of blockFuncs */
403 1.1 oster RF_Calloc(blockFuncs, asm_h->numStripes * raidPtr->Layout.numDataCol, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr **));
404 1.1 oster }
405 1.1 oster
406 1.1 oster /* create an array of creation funcs (called blockFuncs) for this stripe unit */
407 1.1 oster numBlocks = physPtr->numSector;
408 1.1 oster numBlockDags += numBlocks;
409 1.1 oster RF_Calloc(blockFuncs[numStripeUnitsBailed], numBlocks, sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr *));
410 1.1 oster RF_Malloc(asmh_b[numStripeUnitsBailed], numBlocks * sizeof(RF_AccessStripeMapHeader_t *), (RF_AccessStripeMapHeader_t **));
411 1.1 oster
412 1.1 oster /* lookup array of blockFuncs for this stripe unit */
413 1.1 oster for (k=0; k < numBlocks; k++)
414 1.1 oster {
415 1.1 oster /* remap for series of single stripe-unit accesses */
416 1.1 oster address = physPtr->raidAddress + k;
417 1.1 oster length = 1;
418 1.1 oster buffer = physPtr->bufPtr + (k * (1<<raidPtr->logBytesPerSector));
419 1.1 oster
420 1.1 oster asmh_b[numStripeUnitsBailed][k] = rf_MapAccess(raidPtr, address, length, buffer, RF_DONT_REMAP);
421 1.1 oster asm_bp = asmh_b[numStripeUnitsBailed][k]->stripeMap;
422 1.1 oster
423 1.1 oster /* get the creation func for this stripe unit */
424 1.1 oster (raidPtr->Layout.map-> SelectionFunc)(raidPtr, type, asm_bp, &(blockFuncs[numStripeUnitsBailed][k]));
425 1.1 oster
426 1.1 oster /* check to see if we found a creation func for this stripe unit */
427 1.1 oster if (blockFuncs[numStripeUnitsBailed][k] == NULL)
428 1.1 oster cantCreateDAGs = RF_TRUE;
429 1.1 oster }
430 1.1 oster numStripeUnitsBailed++;
431 1.1 oster }
432 1.1 oster else
433 1.1 oster {
434 1.1 oster numUnitDags++;
435 1.1 oster }
436 1.1 oster }
437 1.1 oster RF_ASSERT(j == numStripeUnits);
438 1.1 oster numStripesBailed++;
439 1.1 oster }
440 1.1 oster }
441 1.1 oster
442 1.1 oster if (cantCreateDAGs)
443 1.1 oster {
444 1.1 oster /* free memory and punt */
445 1.1 oster if (asm_h->numStripes > MAXNSTRIPES)
446 1.1 oster RF_Free(stripeFuncs, asm_h->numStripes * sizeof(RF_VoidFuncPtr));
447 1.1 oster if (numStripesBailed > 0)
448 1.1 oster {
449 1.1 oster stripeNum = 0;
450 1.1 oster for (i = 0, asm_p = asmap; asm_p; asm_p = asm_p->next, i++)
451 1.1 oster if (stripeFuncs[i] == NULL)
452 1.1 oster {
453 1.1 oster numStripeUnits = asm_p->numStripeUnitsAccessed;
454 1.1 oster for (j = 0; j < numStripeUnits; j++)
455 1.1 oster rf_FreeAccessStripeMap(asmh_u[stripeNum][j]);
456 1.1 oster RF_Free(asmh_u[stripeNum], numStripeUnits * sizeof(RF_AccessStripeMapHeader_t *));
457 1.1 oster RF_Free(stripeUnitFuncs[stripeNum], numStripeUnits * sizeof(RF_VoidFuncPtr));
458 1.1 oster stripeNum++;
459 1.1 oster }
460 1.1 oster RF_ASSERT(stripeNum == numStripesBailed);
461 1.1 oster RF_Free(stripeUnitFuncs, asm_h->numStripes * sizeof(RF_VoidFuncPtr));
462 1.1 oster RF_Free(asmh_u, asm_h->numStripes * sizeof(RF_AccessStripeMapHeader_t **));
463 1.1 oster }
464 1.1 oster return(1);
465 1.1 oster }
466 1.1 oster else
467 1.1 oster {
468 1.1 oster /* begin dag creation */
469 1.1 oster stripeNum = 0;
470 1.1 oster stripeUnitNum = 0;
471 1.1 oster
472 1.1 oster /* create an array of dagLists and fill them in */
473 1.1 oster RF_CallocAndAdd(desc->dagArray, desc->numStripes, sizeof(RF_DagList_t), (RF_DagList_t *), desc->cleanupList);
474 1.1 oster
475 1.1 oster for (i=0, asm_p = asmap; asm_p; asm_p=asm_p->next,i++) {
476 1.1 oster /* grab dag header for this stripe */
477 1.1 oster dag_h = NULL;
478 1.1 oster desc->dagArray[i].desc = desc;
479 1.1 oster
480 1.1 oster if (stripeFuncs[i] == (RF_VoidFuncPtr) NULL)
481 1.1 oster {
482 1.1 oster /* use bailout functions for this stripe */
483 1.1 oster for (j = 0, physPtr = asm_p->physInfo; physPtr; physPtr=physPtr->next, j++)
484 1.1 oster {
485 1.1 oster uFunc = stripeUnitFuncs[stripeNum][j];
486 1.1 oster if (uFunc == (RF_VoidFuncPtr) NULL)
487 1.1 oster {
488 1.1 oster /* use bailout functions for this stripe unit */
489 1.1 oster for (k = 0; k < physPtr->numSector; k++)
490 1.1 oster {
491 1.1 oster /* create a dag for this block */
492 1.1 oster InitHdrNode(&tempdag_h, raidPtr, rf_useMemChunks);
493 1.1 oster desc->dagArray[i].numDags++;
494 1.1 oster if (dag_h == NULL) {
495 1.1 oster dag_h = tempdag_h;
496 1.1 oster }
497 1.1 oster else {
498 1.1 oster lastdag_h->next = tempdag_h;
499 1.1 oster }
500 1.1 oster lastdag_h = tempdag_h;
501 1.1 oster
502 1.1 oster bFunc = blockFuncs[stripeUnitNum][k];
503 1.1 oster RF_ASSERT(bFunc);
504 1.1 oster asm_bp = asmh_b[stripeUnitNum][k]->stripeMap;
505 1.1 oster (*bFunc)(raidPtr, asm_bp, tempdag_h, bp, flags, tempdag_h->allocList);
506 1.1 oster }
507 1.1 oster stripeUnitNum++;
508 1.1 oster }
509 1.1 oster else
510 1.1 oster {
511 1.1 oster /* create a dag for this unit */
512 1.1 oster InitHdrNode(&tempdag_h, raidPtr, rf_useMemChunks);
513 1.1 oster desc->dagArray[i].numDags++;
514 1.1 oster if (dag_h == NULL) {
515 1.1 oster dag_h = tempdag_h;
516 1.1 oster }
517 1.1 oster else {
518 1.1 oster lastdag_h->next = tempdag_h;
519 1.1 oster }
520 1.1 oster lastdag_h = tempdag_h;
521 1.1 oster
522 1.1 oster asm_up = asmh_u[stripeNum][j]->stripeMap;
523 1.1 oster (*uFunc)(raidPtr, asm_up, tempdag_h, bp, flags, tempdag_h->allocList);
524 1.1 oster }
525 1.1 oster }
526 1.1 oster RF_ASSERT(j == asm_p->numStripeUnitsAccessed);
527 1.1 oster /* merge linked bailout dag to existing dag collection */
528 1.1 oster stripeNum++;
529 1.1 oster }
530 1.1 oster else {
531 1.1 oster /* Create a dag for this parity stripe */
532 1.1 oster InitHdrNode(&tempdag_h, raidPtr, rf_useMemChunks);
533 1.1 oster desc->dagArray[i].numDags++;
534 1.1 oster if (dag_h == NULL) {
535 1.1 oster dag_h = tempdag_h;
536 1.1 oster }
537 1.1 oster else {
538 1.1 oster lastdag_h->next = tempdag_h;
539 1.1 oster }
540 1.1 oster lastdag_h = tempdag_h;
541 1.1 oster
542 1.1 oster (stripeFuncs[i])(raidPtr, asm_p, tempdag_h, bp, flags, tempdag_h->allocList);
543 1.1 oster }
544 1.1 oster desc->dagArray[i].dags = dag_h;
545 1.1 oster }
546 1.1 oster RF_ASSERT(i == desc->numStripes);
547 1.1 oster
548 1.1 oster /* free memory */
549 1.1 oster if (asm_h->numStripes > MAXNSTRIPES)
550 1.1 oster RF_Free(stripeFuncs, asm_h->numStripes * sizeof(RF_VoidFuncPtr));
551 1.1 oster if ((numStripesBailed > 0) || (numStripeUnitsBailed > 0))
552 1.1 oster {
553 1.1 oster stripeNum = 0;
554 1.1 oster stripeUnitNum = 0;
555 1.1 oster if (dag_h->asmList)
556 1.1 oster {
557 1.1 oster endASMList = dag_h->asmList;
558 1.1 oster while (endASMList->next)
559 1.1 oster endASMList = endASMList->next;
560 1.1 oster }
561 1.1 oster else
562 1.1 oster endASMList = NULL;
563 1.1 oster /* walk through io, stripe by stripe */
564 1.1 oster for (i = 0, asm_p = asmap; asm_p; asm_p = asm_p->next, i++)
565 1.1 oster if (stripeFuncs[i] == NULL)
566 1.1 oster {
567 1.1 oster numStripeUnits = asm_p->numStripeUnitsAccessed;
568 1.1 oster /* walk through stripe, stripe unit by stripe unit */
569 1.1 oster for (j = 0, physPtr = asm_p->physInfo; physPtr; physPtr = physPtr->next, j++)
570 1.1 oster {
571 1.1 oster if (stripeUnitFuncs[stripeNum][j] == NULL)
572 1.1 oster {
573 1.1 oster numBlocks = physPtr->numSector;
574 1.1 oster /* walk through stripe unit, block by block */
575 1.1 oster for (k = 0; k < numBlocks; k++)
576 1.1 oster if (dag_h->asmList == NULL)
577 1.1 oster {
578 1.1 oster dag_h->asmList = asmh_b[stripeUnitNum][k];
579 1.1 oster endASMList = dag_h->asmList;
580 1.1 oster }
581 1.1 oster else
582 1.1 oster {
583 1.1 oster endASMList->next = asmh_b[stripeUnitNum][k];
584 1.1 oster endASMList = endASMList->next;
585 1.1 oster }
586 1.1 oster RF_Free(asmh_b[stripeUnitNum], numBlocks * sizeof(RF_AccessStripeMapHeader_t *));
587 1.1 oster RF_Free(blockFuncs[stripeUnitNum], numBlocks * sizeof(RF_VoidFuncPtr));
588 1.1 oster stripeUnitNum++;
589 1.1 oster }
590 1.1 oster if (dag_h->asmList == NULL)
591 1.1 oster {
592 1.1 oster dag_h->asmList = asmh_u[stripeNum][j];
593 1.1 oster endASMList = dag_h->asmList;
594 1.1 oster }
595 1.1 oster else
596 1.1 oster {
597 1.1 oster endASMList->next = asmh_u[stripeNum][j];
598 1.1 oster endASMList = endASMList->next;
599 1.1 oster }
600 1.1 oster }
601 1.1 oster RF_Free(asmh_u[stripeNum], numStripeUnits * sizeof(RF_AccessStripeMapHeader_t *));
602 1.1 oster RF_Free(stripeUnitFuncs[stripeNum], numStripeUnits * sizeof(RF_VoidFuncPtr));
603 1.1 oster stripeNum++;
604 1.1 oster }
605 1.1 oster RF_ASSERT(stripeNum == numStripesBailed);
606 1.1 oster RF_Free(stripeUnitFuncs, asm_h->numStripes * sizeof(RF_VoidFuncPtr));
607 1.1 oster RF_Free(asmh_u, asm_h->numStripes * sizeof(RF_AccessStripeMapHeader_t **));
608 1.1 oster if (numStripeUnitsBailed > 0)
609 1.1 oster {
610 1.1 oster RF_ASSERT(stripeUnitNum == numStripeUnitsBailed);
611 1.1 oster RF_Free(blockFuncs, raidPtr->Layout.numDataCol * asm_h->numStripes * sizeof(RF_VoidFuncPtr));
612 1.1 oster RF_Free(asmh_b, raidPtr->Layout.numDataCol * asm_h->numStripes * sizeof(RF_AccessStripeMapHeader_t **));
613 1.1 oster }
614 1.1 oster }
615 1.1 oster return(0);
616 1.1 oster }
617 1.1 oster }
618