This source file includes following definitions.
- rf_InitHdrNode
- rf_TransferDagMemory
- rf_UpdateNodeHdrPtr
- rf_SelectAlgorithm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 #include "rf_archs.h"
39 #include "rf_types.h"
40 #include "rf_raid.h"
41 #include "rf_dag.h"
42 #include "rf_dagutils.h"
43 #include "rf_dagfuncs.h"
44 #include "rf_general.h"
45 #include "rf_desc.h"
46 #include "rf_map.h"
47
48 #if (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(_KERNEL)
49
50 #else
51 void rf_TransferDagMemory(RF_DagHeader_t *, RF_DagHeader_t *);
52 #endif
53
54 int rf_InitHdrNode(RF_DagHeader_t **, RF_Raid_t *, int);
55 void rf_UpdateNodeHdrPtr(RF_DagHeader_t *, RF_DagNode_t *);
56 int rf_SelectAlgorithm(RF_RaidAccessDesc_t *, RF_RaidAccessFlags_t);
57
58
59
60
61
62
63
64 int
65 rf_InitHdrNode(RF_DagHeader_t **hdr, RF_Raid_t *raidPtr, int memChunkEnable)
66 {
67
68 *hdr = rf_AllocDAGHeader();
69 rf_MakeAllocList((*hdr)->allocList);
70 if ((*hdr)->allocList == NULL) {
71 rf_FreeDAGHeader(*hdr);
72 return (ENOMEM);
73 }
74 (*hdr)->status = rf_enable;
75 (*hdr)->numSuccedents = 0;
76 (*hdr)->raidPtr = raidPtr;
77 (*hdr)->next = NULL;
78 return (0);
79 }
80
81
82
83
84
85
86
87 #if (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(_KERNEL)
88
89 #else
90 void
91 rf_TransferDagMemory(RF_DagHeader_t *daga, RF_DagHeader_t *dagb)
92 {
93 RF_AccessStripeMapHeader_t *end;
94 RF_AllocListElem_t *p;
95 int i, memChunksXfrd = 0, xtraChunksXfrd = 0;
96
97
98 for (p = dagb->allocList; p; p = p->next) {
99 for (i = 0; i < p->numPointers; i++) {
100 rf_AddToAllocList(daga->allocList, p->pointers[i],
101 p->sizes[i]);
102 p->pointers[i] = NULL;
103 p->sizes[i] = 0;
104 }
105 p->numPointers = 0;
106 }
107
108
109 while ((memChunksXfrd + xtraChunksXfrd <
110 dagb->chunkIndex + dagb->xtraChunkIndex) &&
111 (daga->chunkIndex < RF_MAXCHUNKS)) {
112
113 if (memChunksXfrd < dagb->chunkIndex) {
114 daga->memChunk[daga->chunkIndex++] =
115 dagb->memChunk[memChunksXfrd];
116 dagb->memChunk[memChunksXfrd++] = NULL;
117 } else {
118 daga->memChunk[daga->xtraChunkIndex++] =
119 dagb->xtraMemChunk[xtraChunksXfrd];
120 dagb->xtraMemChunk[xtraChunksXfrd++] = NULL;
121 }
122 }
123
124 while (memChunksXfrd + xtraChunksXfrd <
125 dagb->chunkIndex + dagb->xtraChunkIndex) {
126 if (memChunksXfrd < dagb->chunkIndex) {
127 daga->xtraMemChunk[daga->xtraChunkIndex++] =
128 dagb->memChunk[memChunksXfrd];
129 dagb->memChunk[memChunksXfrd++] = NULL;
130 } else {
131 daga->xtraMemChunk[daga->xtraChunkIndex++] =
132 dagb->xtraMemChunk[xtraChunksXfrd];
133 dagb->xtraMemChunk[xtraChunksXfrd++] = NULL;
134 }
135 }
136 RF_ASSERT((memChunksXfrd == dagb->chunkIndex) &&
137 (xtraChunksXfrd == dagb->xtraChunkIndex));
138 RF_ASSERT(daga->chunkIndex <= RF_MAXCHUNKS);
139 RF_ASSERT(daga->xtraChunkIndex <= daga->xtraChunkCnt);
140 dagb->chunkIndex = 0;
141 dagb->xtraChunkIndex = 0;
142
143
144 if (dagb->asmList) {
145 if (daga->asmList) {
146 end = daga->asmList;
147 while (end->next)
148 end = end->next;
149 end->next = dagb->asmList;
150 } else
151 daga->asmList = dagb->asmList;
152 dagb->asmList = NULL;
153 }
154 }
155 #endif
156
157
158
159
160
161
162
163
164
165
166
167 void
168 rf_UpdateNodeHdrPtr(RF_DagHeader_t *hdr, RF_DagNode_t *node)
169 {
170 int i;
171 RF_ASSERT(hdr != NULL && node != NULL);
172 for (i = 0; i < node->numSuccedents; i++)
173 if (node->succedents[i]->dagHdr != hdr)
174 rf_UpdateNodeHdrPtr(hdr, node->succedents[i]);
175 node->dagHdr = hdr;
176 }
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211 #define MAXNSTRIPES 50
212
213 int
214 rf_SelectAlgorithm(RF_RaidAccessDesc_t *desc, RF_RaidAccessFlags_t flags)
215 {
216 RF_AccessStripeMapHeader_t *asm_h = desc->asmap;
217 RF_IoType_t type = desc->type;
218 RF_Raid_t *raidPtr = desc->raidPtr;
219 void *bp = desc->bp;
220
221 RF_AccessStripeMap_t *asmap = asm_h->stripeMap;
222 RF_AccessStripeMap_t *asm_p;
223 RF_DagHeader_t *dag_h = NULL, *tempdag_h, *lastdag_h;
224 int i, j, k;
225 RF_VoidFuncPtr *stripeFuncs, normalStripeFuncs[MAXNSTRIPES];
226 RF_AccessStripeMap_t *asm_up, *asm_bp;
227 RF_AccessStripeMapHeader_t ***asmh_u, *endASMList;
228 RF_AccessStripeMapHeader_t ***asmh_b;
229 RF_VoidFuncPtr **stripeUnitFuncs, uFunc;
230 RF_VoidFuncPtr **blockFuncs, bFunc;
231 int numStripesBailed = 0, cantCreateDAGs = RF_FALSE;
232 int numStripeUnitsBailed = 0;
233 int stripeNum, numUnitDags = 0, stripeUnitNum, numBlockDags = 0;
234 RF_StripeNum_t numStripeUnits;
235 RF_SectorNum_t numBlocks;
236 RF_RaidAddr_t address;
237 int length;
238 RF_PhysDiskAddr_t *physPtr;
239 caddr_t buffer;
240
241 lastdag_h = NULL;
242 asmh_u = asmh_b = NULL;
243 stripeUnitFuncs = NULL;
244 blockFuncs = NULL;
245
246
247
248
249
250 if (asm_h->numStripes <= MAXNSTRIPES)
251 stripeFuncs = normalStripeFuncs;
252 else
253 RF_Calloc(stripeFuncs, asm_h->numStripes,
254 sizeof(RF_VoidFuncPtr), (RF_VoidFuncPtr *));
255
256
257
258
259
260 desc->numStripes = 0;
261 for (i = 0, asm_p = asmap; asm_p; asm_p = asm_p->next, i++) {
262 desc->numStripes++;
263 (raidPtr->Layout.map->SelectionFunc) (raidPtr, type, asm_p,
264 &stripeFuncs[i]);
265
266 if (stripeFuncs[i] == (RF_VoidFuncPtr) NULL) {
267
268
269
270
271
272
273 if (numStripesBailed == 0) {
274
275
276
277
278 RF_Malloc(asmh_u,
279 sizeof(RF_AccessStripeMapHeader_t **) *
280 asm_h->numStripes,
281 (RF_AccessStripeMapHeader_t ***));
282
283
284
285
286 RF_Calloc(stripeUnitFuncs, asm_h->numStripes,
287 sizeof(RF_VoidFuncPtr),
288 (RF_VoidFuncPtr **));
289 }
290
291
292
293
294 numStripeUnits = asm_p->numStripeUnitsAccessed;
295 RF_Calloc(stripeUnitFuncs[numStripesBailed],
296 numStripeUnits, sizeof(RF_VoidFuncPtr),
297 (RF_VoidFuncPtr *));
298 RF_Malloc(asmh_u[numStripesBailed], numStripeUnits *
299 sizeof(RF_AccessStripeMapHeader_t *),
300 (RF_AccessStripeMapHeader_t **));
301
302
303 for (j = 0, physPtr = asm_p->physInfo; physPtr;
304 physPtr = physPtr->next, j++) {
305
306
307
308
309 address = physPtr->raidAddress;
310 length = physPtr->numSector;
311 buffer = physPtr->bufPtr;
312
313 asmh_u[numStripesBailed][j] =
314 rf_MapAccess(raidPtr, address, length,
315 buffer, RF_DONT_REMAP);
316 asm_up = asmh_u[numStripesBailed][j]->stripeMap;
317
318
319
320
321
322 (raidPtr->Layout.map->SelectionFunc) (raidPtr,
323 type, asm_up,
324 &(stripeUnitFuncs[numStripesBailed][j]));
325
326
327
328
329
330 if (stripeUnitFuncs[numStripesBailed][j] ==
331 (RF_VoidFuncPtr) NULL) {
332
333
334
335
336
337
338 if (numStripeUnitsBailed == 0) {
339
340
341
342
343 RF_Malloc(asmh_b,
344 sizeof(RF_AccessStripeMapHeader_t **) *
345 asm_h->numStripes *
346 raidPtr->Layout.numDataCol,
347 (RF_AccessStripeMapHeader_t ***));
348
349
350
351
352 RF_Calloc(blockFuncs,
353 asm_h->numStripes *
354 raidPtr->Layout.numDataCol,
355 sizeof(RF_VoidFuncPtr),
356 (RF_VoidFuncPtr **));
357 }
358
359
360
361
362
363 numBlocks = physPtr->numSector;
364 numBlockDags += numBlocks;
365 RF_Calloc(
366 blockFuncs[numStripeUnitsBailed],
367 numBlocks, sizeof(RF_VoidFuncPtr),
368 (RF_VoidFuncPtr *));
369 RF_Malloc(asmh_b[numStripeUnitsBailed],
370 numBlocks *
371 sizeof(RF_AccessStripeMapHeader_t *),
372 (RF_AccessStripeMapHeader_t **));
373
374
375
376
377
378 for (k = 0; k < numBlocks; k++) {
379
380
381
382
383 address = physPtr->raidAddress
384 + k;
385 length = 1;
386 buffer = physPtr->bufPtr +
387 (k * (1 <<
388 raidPtr->logBytesPerSector));
389
390 asmh_b[numStripeUnitsBailed][k]
391 = rf_MapAccess(raidPtr,
392 address, length, buffer,
393 RF_DONT_REMAP);
394 asm_bp =
395 asmh_b[numStripeUnitsBailed][k]->stripeMap;
396
397
398
399
400
401 (raidPtr->Layout.map->
402 SelectionFunc) (raidPtr,
403 type, asm_bp,
404 &(blockFuncs[numStripeUnitsBailed][k]));
405
406
407
408
409
410
411 if (blockFuncs
412 [numStripeUnitsBailed][k]
413 == NULL)
414 cantCreateDAGs =
415 RF_TRUE;
416 }
417 numStripeUnitsBailed++;
418 } else {
419 numUnitDags++;
420 }
421 }
422 RF_ASSERT(j == numStripeUnits);
423 numStripesBailed++;
424 }
425 }
426
427 if (cantCreateDAGs) {
428
429 if (asm_h->numStripes > MAXNSTRIPES)
430 RF_Free(stripeFuncs, asm_h->numStripes *
431 sizeof(RF_VoidFuncPtr));
432 if (numStripesBailed > 0) {
433 stripeNum = 0;
434 for (i = 0, asm_p = asmap; asm_p;
435 asm_p = asm_p->next, i++)
436 if (stripeFuncs[i] == NULL) {
437 numStripeUnits =
438 asm_p->numStripeUnitsAccessed;
439 for (j = 0; j < numStripeUnits; j++)
440 rf_FreeAccessStripeMap(
441 asmh_u[stripeNum][j]);
442 RF_Free(asmh_u[stripeNum],
443 numStripeUnits *
444 sizeof(RF_AccessStripeMapHeader_t *));
445 RF_Free(stripeUnitFuncs[stripeNum],
446 numStripeUnits *
447 sizeof(RF_VoidFuncPtr));
448 stripeNum++;
449 }
450 RF_ASSERT(stripeNum == numStripesBailed);
451 RF_Free(stripeUnitFuncs, asm_h->numStripes *
452 sizeof(RF_VoidFuncPtr));
453 RF_Free(asmh_u, asm_h->numStripes *
454 sizeof(RF_AccessStripeMapHeader_t **));
455 }
456 return (1);
457 } else {
458
459 stripeNum = 0;
460 stripeUnitNum = 0;
461
462
463 RF_CallocAndAdd(desc->dagArray, desc->numStripes,
464 sizeof(RF_DagList_t), (RF_DagList_t *), desc->cleanupList);
465
466 for (i = 0, asm_p = asmap; asm_p; asm_p = asm_p->next, i++) {
467
468 dag_h = NULL;
469 desc->dagArray[i].desc = desc;
470
471 if (stripeFuncs[i] == (RF_VoidFuncPtr) NULL) {
472
473 for (j = 0, physPtr = asm_p->physInfo; physPtr;
474 physPtr = physPtr->next, j++) {
475 uFunc = stripeUnitFuncs[stripeNum][j];
476 if (uFunc == (RF_VoidFuncPtr) NULL) {
477
478
479
480
481 for (k = 0; k <
482 physPtr->numSector; k++) {
483
484
485
486
487 rf_InitHdrNode(
488 &tempdag_h,
489 raidPtr,
490 rf_useMemChunks);
491 desc->dagArray[i].
492 numDags++;
493 if (dag_h == NULL) {
494 dag_h =
495 tempdag_h;
496 } else {
497 lastdag_h->next
498 = tempdag_h;
499 }
500 lastdag_h = tempdag_h;
501
502 bFunc = blockFuncs
503 [stripeUnitNum][k];
504 RF_ASSERT(bFunc);
505 asm_bp = asmh_b
506 [stripeUnitNum][k]
507 ->stripeMap;
508 (*bFunc) (raidPtr,
509 asm_bp, tempdag_h,
510 bp, flags,
511 tempdag_h
512 ->allocList);
513 }
514 stripeUnitNum++;
515 } else {
516
517
518
519 rf_InitHdrNode(&tempdag_h,
520 raidPtr, rf_useMemChunks);
521 desc->dagArray[i].numDags++;
522 if (dag_h == NULL) {
523 dag_h = tempdag_h;
524 } else {
525 lastdag_h->next =
526 tempdag_h;
527 }
528 lastdag_h = tempdag_h;
529
530 asm_up = asmh_u[stripeNum][j]
531 ->stripeMap;
532 (*uFunc) (raidPtr, asm_up,
533 tempdag_h, bp, flags,
534 tempdag_h->allocList);
535 }
536 }
537 RF_ASSERT(j == asm_p->numStripeUnitsAccessed);
538
539
540
541
542 stripeNum++;
543 } else {
544
545 rf_InitHdrNode(&tempdag_h, raidPtr,
546 rf_useMemChunks);
547 desc->dagArray[i].numDags++;
548 if (dag_h == NULL) {
549 dag_h = tempdag_h;
550 } else {
551 lastdag_h->next = tempdag_h;
552 }
553 lastdag_h = tempdag_h;
554
555 (stripeFuncs[i]) (raidPtr, asm_p, tempdag_h,
556 bp, flags, tempdag_h->allocList);
557 }
558 desc->dagArray[i].dags = dag_h;
559 }
560 RF_ASSERT(i == desc->numStripes);
561
562
563 if (asm_h->numStripes > MAXNSTRIPES)
564 RF_Free(stripeFuncs, asm_h->numStripes *
565 sizeof(RF_VoidFuncPtr));
566 if ((numStripesBailed > 0) || (numStripeUnitsBailed > 0)) {
567 stripeNum = 0;
568 stripeUnitNum = 0;
569 if (dag_h->asmList) {
570 endASMList = dag_h->asmList;
571 while (endASMList->next)
572 endASMList = endASMList->next;
573 } else
574 endASMList = NULL;
575
576 for (i = 0, asm_p = asmap; asm_p;
577 asm_p = asm_p->next, i++)
578 if (stripeFuncs[i] == NULL) {
579 numStripeUnits =
580 asm_p->numStripeUnitsAccessed;
581
582
583
584
585 for (j = 0, physPtr = asm_p->physInfo;
586 physPtr;
587 physPtr = physPtr->next, j++) {
588 if (stripeUnitFuncs[stripeNum]
589 [j] == NULL) {
590 numBlocks =
591 physPtr->numSector;
592
593
594
595
596
597 for (k = 0; k <
598 numBlocks; k++)
599 if (dag_h
600 ->asmList
601 == NULL) {
602 dag_h->asmList =
603 asmh_b[stripeUnitNum][k];
604 endASMList = dag_h->asmList;
605 } else {
606 endASMList->next =
607 asmh_b[stripeUnitNum][k];
608 endASMList = endASMList->next;
609 }
610 RF_Free(asmh_b
611 [stripeUnitNum], numBlocks *
612 sizeof(RF_AccessStripeMapHeader_t *));
613 RF_Free(blockFuncs
614 [stripeUnitNum], numBlocks *
615 sizeof(RF_VoidFuncPtr));
616 stripeUnitNum++;
617 }
618 if (dag_h->asmList == NULL) {
619 dag_h->asmList = asmh_u
620 [stripeNum][j];
621 endASMList = dag_h
622 ->asmList;
623 } else {
624 endASMList->next =
625 asmh_u[stripeNum]
626 [j];
627 endASMList = endASMList
628 ->next;
629 }
630 }
631 RF_Free(asmh_u[stripeNum],
632 numStripeUnits *
633 sizeof(
634 RF_AccessStripeMapHeader_t *));
635 RF_Free(stripeUnitFuncs[stripeNum],
636 numStripeUnits *
637 sizeof(RF_VoidFuncPtr));
638 stripeNum++;
639 }
640 RF_ASSERT(stripeNum == numStripesBailed);
641 RF_Free(stripeUnitFuncs, asm_h->numStripes *
642 sizeof(RF_VoidFuncPtr));
643 RF_Free(asmh_u, asm_h->numStripes *
644 sizeof(RF_AccessStripeMapHeader_t **));
645 if (numStripeUnitsBailed > 0) {
646 RF_ASSERT(stripeUnitNum ==
647 numStripeUnitsBailed);
648 RF_Free(blockFuncs, raidPtr->Layout.numDataCol
649 * asm_h->numStripes *
650 sizeof(RF_VoidFuncPtr));
651 RF_Free(asmh_b, raidPtr->Layout.numDataCol *
652 asm_h->numStripes *
653 sizeof(RF_AccessStripeMapHeader_t **));
654 }
655 }
656 return (0);
657 }
658 }