This source file includes following definitions.
- StateName
- rf_ContinueRaidAccess
- rf_ContinueDagAccess
- rf_State_LastState
- rf_State_IncrAccessCount
- rf_State_DecrAccessCount
- rf_State_Quiesce
- rf_State_Map
- rf_State_Lock
- rf_State_CreateDAG
- rf_State_ExecuteDAG
- rf_State_ProcessDAG
- rf_State_Cleanup
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 #include <sys/errno.h>
32
33 #include "rf_archs.h"
34 #include "rf_threadstuff.h"
35 #include "rf_raid.h"
36 #include "rf_dag.h"
37 #include "rf_desc.h"
38 #include "rf_aselect.h"
39 #include "rf_general.h"
40 #include "rf_states.h"
41 #include "rf_dagutils.h"
42 #include "rf_driver.h"
43 #include "rf_engine.h"
44 #include "rf_map.h"
45 #include "rf_etimer.h"
46 #include "rf_kintf.h"
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 char *StateName(RF_AccessState_t);
62
63 char *
64 StateName(RF_AccessState_t state)
65 {
66 switch (state) {
67 case rf_QuiesceState:return "QuiesceState";
68 case rf_MapState:
69 return "MapState";
70 case rf_LockState:
71 return "LockState";
72 case rf_CreateDAGState:
73 return "CreateDAGState";
74 case rf_ExecuteDAGState:
75 return "ExecuteDAGState";
76 case rf_ProcessDAGState:
77 return "ProcessDAGState";
78 case rf_CleanupState:
79 return "CleanupState";
80 case rf_LastState:
81 return "LastState";
82 case rf_IncrAccessesCountState:
83 return "IncrAccessesCountState";
84 case rf_DecrAccessesCountState:
85 return "DecrAccessesCountState";
86 default:
87 return "!!! UnnamedState !!!";
88 }
89 }
90
91 void
92 rf_ContinueRaidAccess(RF_RaidAccessDesc_t *desc)
93 {
94 int suspended = RF_FALSE;
95 int current_state_index = desc->state;
96 RF_AccessState_t current_state = desc->states[current_state_index];
97 int unit = desc->raidPtr->raidid;
98
99 do {
100 current_state_index = desc->state;
101 current_state = desc->states[current_state_index];
102
103 switch (current_state) {
104
105 case rf_QuiesceState:
106 suspended = rf_State_Quiesce(desc);
107 break;
108 case rf_IncrAccessesCountState:
109 suspended = rf_State_IncrAccessCount(desc);
110 break;
111 case rf_MapState:
112 suspended = rf_State_Map(desc);
113 break;
114 case rf_LockState:
115 suspended = rf_State_Lock(desc);
116 break;
117 case rf_CreateDAGState:
118 suspended = rf_State_CreateDAG(desc);
119 break;
120 case rf_ExecuteDAGState:
121 suspended = rf_State_ExecuteDAG(desc);
122 break;
123 case rf_ProcessDAGState:
124 suspended = rf_State_ProcessDAG(desc);
125 break;
126 case rf_CleanupState:
127 suspended = rf_State_Cleanup(desc);
128 break;
129 case rf_DecrAccessesCountState:
130 suspended = rf_State_DecrAccessCount(desc);
131 break;
132 case rf_LastState:
133 suspended = rf_State_LastState(desc);
134 break;
135 }
136
137
138
139
140
141
142
143 if (rf_printStatesDebug) {
144 printf("raid%d: State: %-24s StateIndex: %3i desc:"
145 " 0x%ld %s.\n", unit, StateName(current_state),
146 current_state_index, (long) desc, suspended ?
147 "callback scheduled" : "looping");
148 }
149 } while (!suspended && current_state != rf_LastState);
150
151 return;
152 }
153
154
155 void
156 rf_ContinueDagAccess(RF_DagList_t *dagList)
157 {
158 RF_AccTraceEntry_t *tracerec = &(dagList->desc->tracerec);
159 RF_RaidAccessDesc_t *desc;
160 RF_DagHeader_t *dag_h;
161 RF_Etimer_t timer;
162 int i;
163
164 desc = dagList->desc;
165
166 timer = tracerec->timer;
167 RF_ETIMER_STOP(timer);
168 RF_ETIMER_EVAL(timer);
169 tracerec->specific.user.exec_us = RF_ETIMER_VAL_US(timer);
170 RF_ETIMER_START(tracerec->timer);
171
172
173 dag_h = dagList->dags;
174 for (i = 0; i < dagList->numDagsDone; i++) {
175 dag_h = dag_h->next;
176 }
177
178
179 if (dag_h->status == rf_rollBackward) {
180
181
182
183
184
185 desc->status = 1;
186 {
187 printf("raid%d: DAG failure: %c addr 0x%lx (%ld)"
188 " nblk 0x%x (%d) buf 0x%lx.\n",
189 desc->raidPtr->raidid, desc->type,
190 (long) desc->raidAddress,
191 (long) desc->raidAddress,
192 (int) desc->numBlocks, (int) desc->numBlocks,
193 (unsigned long) (desc->bufPtr));
194 }
195 }
196 dagList->numDagsDone++;
197 rf_ContinueRaidAccess(desc);
198 }
199
200 int
201 rf_State_LastState(RF_RaidAccessDesc_t *desc)
202 {
203 void (*callbackFunc) (RF_CBParam_t) = desc->callbackFunc;
204 RF_CBParam_t callbackArg;
205
206 callbackArg.p = desc->callbackArg;
207
208
209
210
211 if (desc->async_flag == 0)
212 wakeup(desc->bp);
213
214
215
216
217
218 rf_disk_unbusy(desc);
219
220
221
222
223
224 RF_LOCK_MUTEX(((RF_Raid_t *) desc->raidPtr)->mutex);
225 ((RF_Raid_t *) desc->raidPtr)->openings++;
226 RF_UNLOCK_MUTEX(((RF_Raid_t *) desc->raidPtr)->mutex);
227
228
229 raidstart(((RF_Raid_t *) desc->raidPtr));
230
231
232 splassert(IPL_BIO);
233 biodone(desc->bp);
234
235 if (callbackFunc)
236 callbackFunc(callbackArg);
237 rf_FreeRaidAccDesc(desc);
238
239 return RF_FALSE;
240 }
241
242 int
243 rf_State_IncrAccessCount(RF_RaidAccessDesc_t *desc)
244 {
245 RF_Raid_t *raidPtr;
246
247 raidPtr = desc->raidPtr;
248
249
250
251
252 RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
253 raidPtr->accs_in_flight++;
254 RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
255
256 desc->state++;
257 return RF_FALSE;
258 }
259
260 int
261 rf_State_DecrAccessCount(RF_RaidAccessDesc_t *desc)
262 {
263 RF_Raid_t *raidPtr;
264
265 raidPtr = desc->raidPtr;
266
267 RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
268 raidPtr->accs_in_flight--;
269 if (raidPtr->accesses_suspended && raidPtr->accs_in_flight == 0) {
270 rf_SignalQuiescenceLock(raidPtr, raidPtr->reconDesc);
271 }
272 rf_UpdateUserStats(raidPtr, RF_ETIMER_VAL_US(desc->timer),
273 desc->numBlocks);
274 RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
275
276 desc->state++;
277 return RF_FALSE;
278 }
279
280 int
281 rf_State_Quiesce(RF_RaidAccessDesc_t *desc)
282 {
283 RF_AccTraceEntry_t *tracerec = &desc->tracerec;
284 RF_Etimer_t timer;
285 int suspended = RF_FALSE;
286 RF_Raid_t *raidPtr;
287
288 raidPtr = desc->raidPtr;
289
290 RF_ETIMER_START(timer);
291 RF_ETIMER_START(desc->timer);
292
293 RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
294 if (raidPtr->accesses_suspended) {
295 RF_CallbackDesc_t *cb;
296 cb = rf_AllocCallbackDesc();
297
298
299
300
301
302 cb->callbackFunc = (void (*) (RF_CBParam_t))
303 rf_ContinueRaidAccess;
304 cb->callbackArg.p = (void *) desc;
305 cb->next = raidPtr->quiesce_wait_list;
306 raidPtr->quiesce_wait_list = cb;
307 suspended = RF_TRUE;
308 }
309 RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
310
311 RF_ETIMER_STOP(timer);
312 RF_ETIMER_EVAL(timer);
313 tracerec->specific.user.suspend_ovhd_us += RF_ETIMER_VAL_US(timer);
314
315 if (suspended && rf_quiesceDebug)
316 printf("Stalling access due to quiescence lock.\n");
317
318 desc->state++;
319 return suspended;
320 }
321
322 int
323 rf_State_Map(RF_RaidAccessDesc_t *desc)
324 {
325 RF_Raid_t *raidPtr = desc->raidPtr;
326 RF_AccTraceEntry_t *tracerec = &desc->tracerec;
327 RF_Etimer_t timer;
328
329 RF_ETIMER_START(timer);
330
331 if (!(desc->asmap = rf_MapAccess(raidPtr, desc->raidAddress,
332 desc->numBlocks, desc->bufPtr, RF_DONT_REMAP)))
333 RF_PANIC();
334
335 RF_ETIMER_STOP(timer);
336 RF_ETIMER_EVAL(timer);
337 tracerec->specific.user.map_us = RF_ETIMER_VAL_US(timer);
338
339 desc->state++;
340 return RF_FALSE;
341 }
342
343 int
344 rf_State_Lock(RF_RaidAccessDesc_t *desc)
345 {
346 RF_AccTraceEntry_t *tracerec = &desc->tracerec;
347 RF_Raid_t *raidPtr = desc->raidPtr;
348 RF_AccessStripeMapHeader_t *asmh = desc->asmap;
349 RF_AccessStripeMap_t *asm_p;
350 RF_Etimer_t timer;
351 int suspended = RF_FALSE;
352
353 RF_ETIMER_START(timer);
354 if (!(raidPtr->Layout.map->flags & RF_NO_STRIPE_LOCKS)) {
355 RF_StripeNum_t lastStripeID = -1;
356
357
358 for (asm_p = asmh->stripeMap; asm_p; asm_p = asm_p->next) {
359 RF_ASSERT(RF_IO_IS_R_OR_W(desc->type));
360 if (!rf_suppressLocksAndLargeWrites &&
361 asm_p->parityInfo &&
362 !(desc->flags & RF_DAG_SUPPRESS_LOCKS) &&
363 !(asm_p->flags & RF_ASM_FLAGS_LOCK_TRIED)) {
364 asm_p->flags |= RF_ASM_FLAGS_LOCK_TRIED;
365
366 RF_ASSERT(asm_p->stripeID > lastStripeID);
367 lastStripeID = asm_p->stripeID;
368
369
370
371
372 RF_INIT_LOCK_REQ_DESC(asm_p->lockReqDesc,
373 desc->type, (void (*) (struct buf *))
374 rf_ContinueRaidAccess, desc, asm_p,
375 raidPtr->Layout.dataSectorsPerStripe);
376 if (rf_AcquireStripeLock(raidPtr->lockTable,
377 asm_p->stripeID, &asm_p->lockReqDesc)) {
378 suspended = RF_TRUE;
379 break;
380 }
381 }
382 if (desc->type == RF_IO_TYPE_WRITE &&
383 raidPtr->status[asm_p->physInfo->row] ==
384 rf_rs_reconstructing) {
385 if (!(asm_p->flags & RF_ASM_FLAGS_FORCE_TRIED))
386 {
387 int val;
388
389 asm_p->flags |=
390 RF_ASM_FLAGS_FORCE_TRIED;
391
392
393
394
395 val = rf_ForceOrBlockRecon(raidPtr,
396 asm_p,
397 (void (*) (RF_Raid_t *, void *))
398 rf_ContinueRaidAccess, desc);
399 if (val == 0) {
400 asm_p->flags |=
401 RF_ASM_FLAGS_RECON_BLOCKED;
402 } else {
403 suspended = RF_TRUE;
404 break;
405 }
406 } else {
407 if (rf_pssDebug) {
408 printf("raid%d: skipping"
409 " force/block because"
410 " already done, psid"
411 " %ld.\n",
412 desc->raidPtr->raidid,
413 (long) asm_p->stripeID);
414 }
415 }
416 } else {
417 if (rf_pssDebug) {
418 printf("raid%d: skipping force/block"
419 " because not write or not"
420 " under recon, psid %ld.\n",
421 desc->raidPtr->raidid,
422 (long) asm_p->stripeID);
423 }
424 }
425 }
426
427 RF_ETIMER_STOP(timer);
428 RF_ETIMER_EVAL(timer);
429 tracerec->specific.user.lock_us += RF_ETIMER_VAL_US(timer);
430
431 if (suspended)
432 return (RF_TRUE);
433 }
434 desc->state++;
435 return (RF_FALSE);
436 }
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459 int
460 rf_State_CreateDAG(RF_RaidAccessDesc_t *desc)
461 {
462 RF_AccTraceEntry_t *tracerec = &desc->tracerec;
463 RF_Etimer_t timer;
464 RF_DagHeader_t *dag_h;
465 int i, selectStatus;
466
467
468
469
470
471 RF_ETIMER_START(timer);
472
473 selectStatus = rf_SelectAlgorithm(desc,
474 desc->flags | RF_DAG_SUPPRESS_LOCKS);
475 if (rf_printDAGsDebug)
476 for (i = 0; i < desc->numStripes; i++)
477 rf_PrintDAGList(desc->dagArray[i].dags);
478 RF_ETIMER_STOP(timer);
479 RF_ETIMER_EVAL(timer);
480
481 tracerec->specific.user.dag_create_us = RF_ETIMER_VAL_US(timer);
482
483 desc->status = 0;
484
485 if (selectStatus) {
486
487
488
489
490
491 printf("[Failed to create a DAG]\n");
492 RF_PANIC();
493 } else {
494
495 for (i = 0; i < desc->numStripes; i++) {
496 dag_h = desc->dagArray[i].dags;
497 while (dag_h) {
498 dag_h->bp = (struct buf *) desc->bp;
499 dag_h->tracerec = tracerec;
500 dag_h = dag_h->next;
501 }
502 }
503 desc->flags |= RF_DAG_DISPATCH_RETURNED;
504 desc->state++;
505 }
506 return RF_FALSE;
507 }
508
509
510
511
512
513
514
515
516
517 int
518 rf_State_ExecuteDAG(RF_RaidAccessDesc_t *desc)
519 {
520 int i;
521 RF_DagHeader_t *dag_h;
522 RF_DagList_t *dagArray = desc->dagArray;
523
524
525
526
527
528
529 desc->state++;
530
531
532
533
534
535 for (i = 0; i < desc->numStripes; i++) {
536 RF_ASSERT(dagArray[i].numDags > 0);
537 RF_ASSERT(dagArray[i].numDagsDone == 0);
538 RF_ASSERT(dagArray[i].numDagsFired == 0);
539 RF_ETIMER_START(dagArray[i].tracerec.timer);
540
541 dag_h = dagArray[i].dags;
542 RF_ASSERT(dag_h);
543 dagArray[i].numDagsFired++;
544
545
546
547
548 rf_DispatchDAG(dag_h, (void (*) (void *)) rf_ContinueDagAccess,
549 &dagArray[i]);
550 }
551
552
553
554
555
556 return RF_TRUE;
557 }
558
559
560
561
562
563
564
565 int
566 rf_State_ProcessDAG(RF_RaidAccessDesc_t *desc)
567 {
568 RF_AccessStripeMapHeader_t *asmh = desc->asmap;
569 RF_Raid_t *raidPtr = desc->raidPtr;
570 RF_DagHeader_t *dag_h;
571 int i, j, done = RF_TRUE;
572 RF_DagList_t *dagArray = desc->dagArray;
573 RF_Etimer_t timer;
574
575
576 for (i = 0; i < desc->numStripes; i++)
577 if (dagArray[i].numDags != dagArray[i].numDagsDone)
578 done = RF_FALSE;
579
580 if (done) {
581 if (desc->status) {
582
583 RF_ETIMER_START(timer);
584
585 for (i = 0; i < desc->numStripes; i++) {
586 rf_FreeDAG(desc->dagArray[i].dags);
587 }
588 rf_MarkFailuresInASMList(raidPtr, asmh);
589
590 desc->state = desc->state - 2;
591 return RF_FALSE;
592 } else {
593
594 desc->state++;
595 }
596 return RF_FALSE;
597 } else {
598
599
600
601
602
603
604 for (i = 0; i < desc->numStripes; i++) {
605 if ((dagArray[i].numDagsDone < dagArray[i].numDags) &&
606 (dagArray[i].numDagsDone ==
607 dagArray[i].numDagsFired) &&
608 (dagArray[i].numDagsFired > 0)) {
609 RF_ETIMER_START(dagArray[i].tracerec.timer);
610
611
612
613
614 dag_h = dagArray[i].dags;
615 for (j = 0; j < dagArray[i].numDagsDone; j++)
616 dag_h = dag_h->next;
617 dagArray[i].numDagsFired++;
618
619
620
621
622 rf_DispatchDAG(dag_h, (void (*) (void *))
623 rf_ContinueDagAccess, &dagArray[i]);
624 }
625 }
626 return RF_TRUE;
627 }
628 }
629
630
631 int
632 rf_State_Cleanup(RF_RaidAccessDesc_t *desc)
633 {
634 RF_AccTraceEntry_t *tracerec = &desc->tracerec;
635 RF_AccessStripeMapHeader_t *asmh = desc->asmap;
636 RF_Raid_t *raidPtr = desc->raidPtr;
637 RF_AccessStripeMap_t *asm_p;
638 RF_DagHeader_t *dag_h;
639 RF_Etimer_t timer;
640 int i;
641
642 desc->state++;
643
644 timer = tracerec->timer;
645 RF_ETIMER_STOP(timer);
646 RF_ETIMER_EVAL(timer);
647 tracerec->specific.user.dag_retry_us = RF_ETIMER_VAL_US(timer);
648
649
650 tracerec->specific.user.dag_retry_us = 0;
651
652 RF_ETIMER_START(timer);
653 if (desc->flags & RF_DAG_RETURN_DAG) {
654
655 *(desc->paramDAG) = desc->dagArray[0].dags;
656 dag_h = *(desc->paramDAG);
657 for (i = 1; i < desc->numStripes; i++) {
658
659 RF_ASSERT(dag_h);
660 while (dag_h->next)
661 dag_h = dag_h->next;
662 dag_h->next = desc->dagArray[i].dags;
663 }
664 } else {
665
666 for (i = 0; i < desc->numStripes; i++) {
667 rf_FreeDAG(desc->dagArray[i].dags);
668 }
669 }
670
671 RF_ETIMER_STOP(timer);
672 RF_ETIMER_EVAL(timer);
673 tracerec->specific.user.cleanup_us = RF_ETIMER_VAL_US(timer);
674
675 RF_ETIMER_START(timer);
676 if (!(raidPtr->Layout.map->flags & RF_NO_STRIPE_LOCKS)) {
677 for (asm_p = asmh->stripeMap; asm_p; asm_p = asm_p->next) {
678 if (!rf_suppressLocksAndLargeWrites &&
679 asm_p->parityInfo &&
680 !(desc->flags & RF_DAG_SUPPRESS_LOCKS)) {
681 RF_ASSERT_VALID_LOCKREQ(&asm_p->lockReqDesc);
682 rf_ReleaseStripeLock(raidPtr->lockTable,
683 asm_p->stripeID, &asm_p->lockReqDesc);
684 }
685 if (asm_p->flags & RF_ASM_FLAGS_RECON_BLOCKED) {
686 rf_UnblockRecon(raidPtr, asm_p);
687 }
688 }
689 }
690 RF_ETIMER_STOP(timer);
691 RF_ETIMER_EVAL(timer);
692 tracerec->specific.user.lock_us += RF_ETIMER_VAL_US(timer);
693
694 RF_ETIMER_START(timer);
695 if (desc->flags & RF_DAG_RETURN_ASM)
696 *(desc->paramASM) = asmh;
697 else
698 rf_FreeAccessStripeMap(asmh);
699 RF_ETIMER_STOP(timer);
700 RF_ETIMER_EVAL(timer);
701 tracerec->specific.user.cleanup_us += RF_ETIMER_VAL_US(timer);
702
703 RF_ETIMER_STOP(desc->timer);
704 RF_ETIMER_EVAL(desc->timer);
705
706 timer = desc->tracerec.tot_timer;
707 RF_ETIMER_STOP(timer);
708 RF_ETIMER_EVAL(timer);
709 desc->tracerec.total_us = RF_ETIMER_VAL_US(timer);
710
711 rf_LogTraceRec(raidPtr, tracerec);
712
713 desc->flags |= RF_DAG_ACCESS_COMPLETE;
714
715 return RF_FALSE;
716 }