xref: /netbsd-src/sys/dev/raidframe/rf_states.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: rf_states.c,v 1.41 2007/07/29 12:50:22 ad Exp $	*/
2 /*
3  * Copyright (c) 1995 Carnegie-Mellon University.
4  * All rights reserved.
5  *
6  * Author: Mark Holland, William V. Courtright II, Robby Findler
7  *
8  * Permission to use, copy, modify and distribute this software and
9  * its documentation is hereby granted, provided that both the copyright
10  * notice and this permission notice appear in all copies of the
11  * software, derivative works or modified versions, and any portions
12  * thereof, and that both notices appear in supporting documentation.
13  *
14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17  *
18  * Carnegie Mellon requests users of this software to return to
19  *
20  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
21  *  School of Computer Science
22  *  Carnegie Mellon University
23  *  Pittsburgh PA 15213-3890
24  *
25  * any improvements or extensions that they make and grant Carnegie the
26  * rights to redistribute these changes.
27  */
28 
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: rf_states.c,v 1.41 2007/07/29 12:50:22 ad Exp $");
31 
32 #include <sys/errno.h>
33 
34 #include "rf_archs.h"
35 #include "rf_threadstuff.h"
36 #include "rf_raid.h"
37 #include "rf_dag.h"
38 #include "rf_desc.h"
39 #include "rf_aselect.h"
40 #include "rf_general.h"
41 #include "rf_states.h"
42 #include "rf_dagutils.h"
43 #include "rf_driver.h"
44 #include "rf_engine.h"
45 #include "rf_map.h"
46 #include "rf_etimer.h"
47 #include "rf_kintf.h"
48 
49 #ifndef RF_DEBUG_STATES
50 #define RF_DEBUG_STATES 0
51 #endif
52 
53 /* prototypes for some of the available states.
54 
55    States must:
56 
57      - not block.
58 
59      - either schedule rf_ContinueRaidAccess as a callback and return
60        RF_TRUE, or complete all of their work and return RF_FALSE.
61 
62      - increment desc->state when they have finished their work.
63 */
64 
65 #if RF_DEBUG_STATES
66 static char *
67 StateName(RF_AccessState_t state)
68 {
69 	switch (state) {
70 		case rf_QuiesceState:return "QuiesceState";
71 	case rf_MapState:
72 		return "MapState";
73 	case rf_LockState:
74 		return "LockState";
75 	case rf_CreateDAGState:
76 		return "CreateDAGState";
77 	case rf_ExecuteDAGState:
78 		return "ExecuteDAGState";
79 	case rf_ProcessDAGState:
80 		return "ProcessDAGState";
81 	case rf_CleanupState:
82 		return "CleanupState";
83 	case rf_LastState:
84 		return "LastState";
85 	case rf_IncrAccessesCountState:
86 		return "IncrAccessesCountState";
87 	case rf_DecrAccessesCountState:
88 		return "DecrAccessesCountState";
89 	default:
90 		return "!!! UnnamedState !!!";
91 	}
92 }
93 #endif
94 
95 void
96 rf_ContinueRaidAccess(RF_RaidAccessDesc_t *desc)
97 {
98 	int     suspended = RF_FALSE;
99 	int     current_state_index = desc->state;
100 	RF_AccessState_t current_state = desc->states[current_state_index];
101 #if RF_DEBUG_STATES
102 	int     unit = desc->raidPtr->raidid;
103 #endif
104 
105 	do {
106 
107 		current_state_index = desc->state;
108 		current_state = desc->states[current_state_index];
109 
110 		switch (current_state) {
111 
112 		case rf_QuiesceState:
113 			suspended = rf_State_Quiesce(desc);
114 			break;
115 		case rf_IncrAccessesCountState:
116 			suspended = rf_State_IncrAccessCount(desc);
117 			break;
118 		case rf_MapState:
119 			suspended = rf_State_Map(desc);
120 			break;
121 		case rf_LockState:
122 			suspended = rf_State_Lock(desc);
123 			break;
124 		case rf_CreateDAGState:
125 			suspended = rf_State_CreateDAG(desc);
126 			break;
127 		case rf_ExecuteDAGState:
128 			suspended = rf_State_ExecuteDAG(desc);
129 			break;
130 		case rf_ProcessDAGState:
131 			suspended = rf_State_ProcessDAG(desc);
132 			break;
133 		case rf_CleanupState:
134 			suspended = rf_State_Cleanup(desc);
135 			break;
136 		case rf_DecrAccessesCountState:
137 			suspended = rf_State_DecrAccessCount(desc);
138 			break;
139 		case rf_LastState:
140 			suspended = rf_State_LastState(desc);
141 			break;
142 		}
143 
144 		/* after this point, we cannot dereference desc since
145 		 * desc may have been freed. desc is only freed in
146 		 * LastState, so if we renter this function or loop
147 		 * back up, desc should be valid. */
148 
149 #if RF_DEBUG_STATES
150 		if (rf_printStatesDebug) {
151 			printf("raid%d: State: %-24s StateIndex: %3i desc: 0x%ld %s\n",
152 			       unit, StateName(current_state),
153 			       current_state_index, (long) desc,
154 			       suspended ? "callback scheduled" : "looping");
155 		}
156 #endif
157 	} while (!suspended && current_state != rf_LastState);
158 
159 	return;
160 }
161 
162 
163 void
164 rf_ContinueDagAccess(RF_DagList_t *dagList)
165 {
166 #if RF_ACC_TRACE > 0
167 	RF_AccTraceEntry_t *tracerec = &(dagList->desc->tracerec);
168 	RF_Etimer_t timer;
169 #endif
170 	RF_RaidAccessDesc_t *desc;
171 	RF_DagHeader_t *dag_h;
172 	int     i;
173 
174 	desc = dagList->desc;
175 
176 #if RF_ACC_TRACE > 0
177 	timer = tracerec->timer;
178 	RF_ETIMER_STOP(timer);
179 	RF_ETIMER_EVAL(timer);
180 	tracerec->specific.user.exec_us = RF_ETIMER_VAL_US(timer);
181 	RF_ETIMER_START(tracerec->timer);
182 #endif
183 
184 	/* skip to dag which just finished */
185 	dag_h = dagList->dags;
186 	for (i = 0; i < dagList->numDagsDone; i++) {
187 		dag_h = dag_h->next;
188 	}
189 
190 	/* check to see if retry is required */
191 	if (dag_h->status == rf_rollBackward) {
192 		/* when a dag fails, mark desc status as bad and allow
193 		 * all other dags in the desc to execute to
194 		 * completion.  then, free all dags and start over */
195 		desc->status = 1;	/* bad status */
196 #if 0
197 		printf("raid%d: DAG failure: %c addr 0x%lx "
198 		       "(%ld) nblk 0x%x (%d) buf 0x%lx state %d\n",
199 		       desc->raidPtr->raidid, desc->type,
200 		       (long) desc->raidAddress,
201 		       (long) desc->raidAddress, (int) desc->numBlocks,
202 		       (int) desc->numBlocks,
203 		       (unsigned long) (desc->bufPtr), desc->state);
204 #endif
205 	}
206 	dagList->numDagsDone++;
207 	rf_ContinueRaidAccess(desc);
208 }
209 
210 int
211 rf_State_LastState(RF_RaidAccessDesc_t *desc)
212 {
213 	void    (*callbackFunc) (RF_CBParam_t) = desc->callbackFunc;
214 	RF_CBParam_t callbackArg;
215 
216 	callbackArg.p = desc->callbackArg;
217 
218 	/*
219 	 * If this is not an async request, wake up the caller
220 	 */
221 	if (desc->async_flag == 0)
222 		wakeup(desc->bp);
223 
224 	/*
225 	 * That's all the IO for this one... unbusy the 'disk'.
226 	 */
227 
228 	rf_disk_unbusy(desc);
229 
230 	/*
231 	 * Wakeup any requests waiting to go.
232 	 */
233 
234 	RF_LOCK_MUTEX(((RF_Raid_t *) desc->raidPtr)->mutex);
235 	((RF_Raid_t *) desc->raidPtr)->openings++;
236 	RF_UNLOCK_MUTEX(((RF_Raid_t *) desc->raidPtr)->mutex);
237 
238 	wakeup(&(desc->raidPtr->iodone));
239 
240 	/* printf("Calling biodone on 0x%x\n",desc->bp); */
241 	biodone(desc->bp);	/* access came through ioctl */
242 
243 	if (callbackFunc)
244 		callbackFunc(callbackArg);
245 	rf_FreeRaidAccDesc(desc);
246 
247 	return RF_FALSE;
248 }
249 
250 int
251 rf_State_IncrAccessCount(RF_RaidAccessDesc_t *desc)
252 {
253 	RF_Raid_t *raidPtr;
254 
255 	raidPtr = desc->raidPtr;
256 	/* Bummer. We have to do this to be 100% safe w.r.t. the increment
257 	 * below */
258 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
259 	raidPtr->accs_in_flight++;	/* used to detect quiescence */
260 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
261 
262 	desc->state++;
263 	return RF_FALSE;
264 }
265 
266 int
267 rf_State_DecrAccessCount(RF_RaidAccessDesc_t *desc)
268 {
269 	RF_Raid_t *raidPtr;
270 
271 	raidPtr = desc->raidPtr;
272 
273 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
274 	raidPtr->accs_in_flight--;
275 	if (raidPtr->accesses_suspended && raidPtr->accs_in_flight == 0) {
276 		rf_SignalQuiescenceLock(raidPtr);
277 	}
278 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
279 
280 	desc->state++;
281 	return RF_FALSE;
282 }
283 
284 int
285 rf_State_Quiesce(RF_RaidAccessDesc_t *desc)
286 {
287 #if RF_ACC_TRACE > 0
288 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
289 	RF_Etimer_t timer;
290 #endif
291 	RF_CallbackDesc_t *cb;
292 	RF_Raid_t *raidPtr;
293 	int     suspended = RF_FALSE;
294 	int need_cb, used_cb;
295 
296 	raidPtr = desc->raidPtr;
297 
298 #if RF_ACC_TRACE > 0
299 	RF_ETIMER_START(timer);
300 	RF_ETIMER_START(desc->timer);
301 #endif
302 
303 	need_cb = 0;
304 	used_cb = 0;
305 	cb = NULL;
306 
307 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
308 	/* Do an initial check to see if we might need a callback structure */
309 	if (raidPtr->accesses_suspended) {
310 		need_cb = 1;
311 	}
312 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
313 
314 	if (need_cb) {
315 		/* create a callback if we might need it...
316 		   and we likely do. */
317 		cb = rf_AllocCallbackDesc();
318 	}
319 
320 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
321 	if (raidPtr->accesses_suspended) {
322 		cb->callbackFunc = (void (*) (RF_CBParam_t)) rf_ContinueRaidAccess;
323 		cb->callbackArg.p = (void *) desc;
324 		cb->next = raidPtr->quiesce_wait_list;
325 		raidPtr->quiesce_wait_list = cb;
326 		suspended = RF_TRUE;
327 		used_cb = 1;
328 	}
329 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
330 
331 	if ((need_cb == 1) && (used_cb == 0)) {
332 		rf_FreeCallbackDesc(cb);
333 	}
334 
335 #if RF_ACC_TRACE > 0
336 	RF_ETIMER_STOP(timer);
337 	RF_ETIMER_EVAL(timer);
338 	tracerec->specific.user.suspend_ovhd_us += RF_ETIMER_VAL_US(timer);
339 #endif
340 
341 #if RF_DEBUG_QUIESCE
342 	if (suspended && rf_quiesceDebug)
343 		printf("Stalling access due to quiescence lock\n");
344 #endif
345 	desc->state++;
346 	return suspended;
347 }
348 
349 int
350 rf_State_Map(RF_RaidAccessDesc_t *desc)
351 {
352 	RF_Raid_t *raidPtr = desc->raidPtr;
353 #if RF_ACC_TRACE > 0
354 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
355 	RF_Etimer_t timer;
356 
357 	RF_ETIMER_START(timer);
358 #endif
359 
360 	if (!(desc->asmap = rf_MapAccess(raidPtr, desc->raidAddress, desc->numBlocks,
361 		    desc->bufPtr, RF_DONT_REMAP)))
362 		RF_PANIC();
363 
364 #if RF_ACC_TRACE > 0
365 	RF_ETIMER_STOP(timer);
366 	RF_ETIMER_EVAL(timer);
367 	tracerec->specific.user.map_us = RF_ETIMER_VAL_US(timer);
368 #endif
369 
370 	desc->state++;
371 	return RF_FALSE;
372 }
373 
374 int
375 rf_State_Lock(RF_RaidAccessDesc_t *desc)
376 {
377 #if RF_ACC_TRACE > 0
378 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
379 	RF_Etimer_t timer;
380 #endif
381 	RF_Raid_t *raidPtr = desc->raidPtr;
382 	RF_AccessStripeMapHeader_t *asmh = desc->asmap;
383 	RF_AccessStripeMap_t *asm_p;
384 	RF_StripeNum_t lastStripeID = -1;
385 	int     suspended = RF_FALSE;
386 
387 #if RF_ACC_TRACE > 0
388 	RF_ETIMER_START(timer);
389 #endif
390 
391 	/* acquire each lock that we don't already hold */
392 	for (asm_p = asmh->stripeMap; asm_p; asm_p = asm_p->next) {
393 		RF_ASSERT(RF_IO_IS_R_OR_W(desc->type));
394 		if (!rf_suppressLocksAndLargeWrites &&
395 		    asm_p->parityInfo &&
396 		    !(desc->flags & RF_DAG_SUPPRESS_LOCKS) &&
397 		    !(asm_p->flags & RF_ASM_FLAGS_LOCK_TRIED)) {
398 			asm_p->flags |= RF_ASM_FLAGS_LOCK_TRIED;
399 				/* locks must be acquired hierarchically */
400 			RF_ASSERT(asm_p->stripeID > lastStripeID);
401 			lastStripeID = asm_p->stripeID;
402 
403 			RF_INIT_LOCK_REQ_DESC(asm_p->lockReqDesc, desc->type,
404 					      (void (*) (struct buf *)) rf_ContinueRaidAccess, desc, asm_p,
405 					      raidPtr->Layout.dataSectorsPerStripe);
406 			if (rf_AcquireStripeLock(raidPtr->lockTable, asm_p->stripeID,
407 						 &asm_p->lockReqDesc)) {
408 				suspended = RF_TRUE;
409 				break;
410 			}
411 		}
412 		if (desc->type == RF_IO_TYPE_WRITE &&
413 		    raidPtr->status == rf_rs_reconstructing) {
414 			if (!(asm_p->flags & RF_ASM_FLAGS_FORCE_TRIED)) {
415 				int     val;
416 
417 				asm_p->flags |= RF_ASM_FLAGS_FORCE_TRIED;
418 				val = rf_ForceOrBlockRecon(raidPtr, asm_p,
419 							   (void (*) (RF_Raid_t *, void *)) rf_ContinueRaidAccess, desc);
420 				if (val == 0) {
421 					asm_p->flags |= RF_ASM_FLAGS_RECON_BLOCKED;
422 				} else {
423 					suspended = RF_TRUE;
424 					break;
425 				}
426 			} else {
427 #if RF_DEBUG_PSS > 0
428 				if (rf_pssDebug) {
429 					printf("raid%d: skipping force/block because already done, psid %ld\n",
430 					       desc->raidPtr->raidid,
431 					       (long) asm_p->stripeID);
432 				}
433 #endif
434 			}
435 		} else {
436 #if RF_DEBUG_PSS > 0
437 			if (rf_pssDebug) {
438 				printf("raid%d: skipping force/block because not write or not under recon, psid %ld\n",
439 				       desc->raidPtr->raidid,
440 				       (long) asm_p->stripeID);
441 			}
442 #endif
443 		}
444 	}
445 #if RF_ACC_TRACE > 0
446 	RF_ETIMER_STOP(timer);
447 	RF_ETIMER_EVAL(timer);
448 	tracerec->specific.user.lock_us += RF_ETIMER_VAL_US(timer);
449 #endif
450 	if (suspended)
451 		return (RF_TRUE);
452 
453 	desc->state++;
454 	return (RF_FALSE);
455 }
456 /*
457  * the following three states create, execute, and post-process dags
458  * the error recovery unit is a single dag.
459  * by default, SelectAlgorithm creates an array of dags, one per parity stripe
460  * in some tricky cases, multiple dags per stripe are created
461  *   - dags within a parity stripe are executed sequentially (arbitrary order)
462  *   - dags for distinct parity stripes are executed concurrently
463  *
464  * repeat until all dags complete successfully -or- dag selection fails
465  *
466  * while !done
467  *   create dag(s) (SelectAlgorithm)
468  *   if dag
469  *     execute dag (DispatchDAG)
470  *     if dag successful
471  *       done (SUCCESS)
472  *     else
473  *       !done (RETRY - start over with new dags)
474  *   else
475  *     done (FAIL)
476  */
477 int
478 rf_State_CreateDAG(RF_RaidAccessDesc_t *desc)
479 {
480 #if RF_ACC_TRACE > 0
481 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
482 	RF_Etimer_t timer;
483 #endif
484 	RF_DagHeader_t *dag_h;
485 	RF_DagList_t *dagList;
486 	struct buf *bp;
487 	int     i, selectStatus;
488 
489 	/* generate a dag for the access, and fire it off.  When the dag
490 	 * completes, we'll get re-invoked in the next state. */
491 #if RF_ACC_TRACE > 0
492 	RF_ETIMER_START(timer);
493 #endif
494 	/* SelectAlgorithm returns one or more dags */
495 	selectStatus = rf_SelectAlgorithm(desc, desc->flags | RF_DAG_SUPPRESS_LOCKS);
496 #if RF_DEBUG_VALIDATE_DAG
497 	if (rf_printDAGsDebug) {
498 		dagList = desc->dagList;
499 		for (i = 0; i < desc->numStripes; i++) {
500 			rf_PrintDAGList(dagList.dags);
501 			dagList = dagList->next;
502 		}
503 	}
504 #endif /* RF_DEBUG_VALIDATE_DAG */
505 #if RF_ACC_TRACE > 0
506 	RF_ETIMER_STOP(timer);
507 	RF_ETIMER_EVAL(timer);
508 	/* update time to create all dags */
509 	tracerec->specific.user.dag_create_us = RF_ETIMER_VAL_US(timer);
510 #endif
511 
512 	desc->status = 0;	/* good status */
513 
514 	if (selectStatus || (desc->numRetries > RF_RETRY_THRESHOLD)) {
515 		/* failed to create a dag */
516 		/* this happens when there are too many faults or incomplete
517 		 * dag libraries */
518 		if (selectStatus) {
519 			printf("raid%d: failed to create a dag. "
520 			       "Too many component failures.\n",
521 			       desc->raidPtr->raidid);
522 		} else {
523 			printf("raid%d: IO failed after %d retries.\n",
524 			       desc->raidPtr->raidid, RF_RETRY_THRESHOLD);
525 		}
526 
527 		desc->status = 1; /* bad status */
528 		/* skip straight to rf_State_Cleanup() */
529 		desc->state = rf_CleanupState;
530 		bp = (struct buf *)desc->bp;
531 		bp->b_error = EIO;
532 	} else {
533 		/* bind dags to desc */
534 		dagList = desc->dagList;
535 		for (i = 0; i < desc->numStripes; i++) {
536 			dag_h = dagList->dags;
537 			while (dag_h) {
538 				dag_h->bp = (struct buf *) desc->bp;
539 #if RF_ACC_TRACE > 0
540 				dag_h->tracerec = tracerec;
541 #endif
542 				dag_h = dag_h->next;
543 			}
544 			dagList = dagList->next;
545 		}
546 		desc->flags |= RF_DAG_DISPATCH_RETURNED;
547 		desc->state++;	/* next state should be rf_State_ExecuteDAG */
548 	}
549 	return RF_FALSE;
550 }
551 
552 
553 
554 /* the access has an list of dagLists, one dagList per parity stripe.
555  * fire the first dag in each parity stripe (dagList).
556  * dags within a stripe (dagList) must be executed sequentially
557  *  - this preserves atomic parity update
558  * dags for independents parity groups (stripes) are fired concurrently */
559 
560 int
561 rf_State_ExecuteDAG(RF_RaidAccessDesc_t *desc)
562 {
563 	int     i;
564 	RF_DagHeader_t *dag_h;
565 	RF_DagList_t *dagList;
566 
567 	/* next state is always rf_State_ProcessDAG important to do
568 	 * this before firing the first dag (it may finish before we
569 	 * leave this routine) */
570 	desc->state++;
571 
572 	/* sweep dag array, a stripe at a time, firing the first dag
573 	 * in each stripe */
574 	dagList = desc->dagList;
575 	for (i = 0; i < desc->numStripes; i++) {
576 		RF_ASSERT(dagList->numDags > 0);
577 		RF_ASSERT(dagList->numDagsDone == 0);
578 		RF_ASSERT(dagList->numDagsFired == 0);
579 #if RF_ACC_TRACE > 0
580 		RF_ETIMER_START(dagList->tracerec.timer);
581 #endif
582 		/* fire first dag in this stripe */
583 		dag_h = dagList->dags;
584 		RF_ASSERT(dag_h);
585 		dagList->numDagsFired++;
586 		rf_DispatchDAG(dag_h, (void (*) (void *)) rf_ContinueDagAccess, dagList);
587 		dagList = dagList->next;
588 	}
589 
590 	/* the DAG will always call the callback, even if there was no
591 	 * blocking, so we are always suspended in this state */
592 	return RF_TRUE;
593 }
594 
595 
596 
597 /* rf_State_ProcessDAG is entered when a dag completes.
598  * first, check to all dags in the access have completed
599  * if not, fire as many dags as possible */
600 
601 int
602 rf_State_ProcessDAG(RF_RaidAccessDesc_t *desc)
603 {
604 	RF_AccessStripeMapHeader_t *asmh = desc->asmap;
605 	RF_Raid_t *raidPtr = desc->raidPtr;
606 	RF_DagHeader_t *dag_h;
607 	int     i, j, done = RF_TRUE;
608 	RF_DagList_t *dagList, *temp;
609 
610 	/* check to see if this is the last dag */
611 	dagList = desc->dagList;
612 	for (i = 0; i < desc->numStripes; i++) {
613 		if (dagList->numDags != dagList->numDagsDone)
614 			done = RF_FALSE;
615 		dagList = dagList->next;
616 	}
617 
618 	if (done) {
619 		if (desc->status) {
620 			/* a dag failed, retry */
621 			/* free all dags */
622 			dagList = desc->dagList;
623 			for (i = 0; i < desc->numStripes; i++) {
624 				rf_FreeDAG(dagList->dags);
625 				temp = dagList;
626 				dagList = dagList->next;
627 				rf_FreeDAGList(temp);
628 			}
629 			desc->dagList = NULL;
630 
631 			rf_MarkFailuresInASMList(raidPtr, asmh);
632 
633 			/* note the retry so that we'll bail in
634 			   rf_State_CreateDAG() once we've retired
635 			   the IO RF_RETRY_THRESHOLD times */
636 
637 			desc->numRetries++;
638 
639 			/* back up to rf_State_CreateDAG */
640 			desc->state = desc->state - 2;
641 			return RF_FALSE;
642 		} else {
643 			/* move on to rf_State_Cleanup */
644 			desc->state++;
645 		}
646 		return RF_FALSE;
647 	} else {
648 		/* more dags to execute */
649 		/* see if any are ready to be fired.  if so, fire them */
650 		/* don't fire the initial dag in a list, it's fired in
651 		 * rf_State_ExecuteDAG */
652 		dagList = desc->dagList;
653 		for (i = 0; i < desc->numStripes; i++) {
654 			if ((dagList->numDagsDone < dagList->numDags)
655 			    && (dagList->numDagsDone == dagList->numDagsFired)
656 			    && (dagList->numDagsFired > 0)) {
657 #if RF_ACC_TRACE > 0
658 				RF_ETIMER_START(dagList->tracerec.timer);
659 #endif
660 				/* fire next dag in this stripe */
661 				/* first, skip to next dag awaiting execution */
662 				dag_h = dagList->dags;
663 				for (j = 0; j < dagList->numDagsDone; j++)
664 					dag_h = dag_h->next;
665 				dagList->numDagsFired++;
666 				rf_DispatchDAG(dag_h, (void (*) (void *)) rf_ContinueDagAccess,
667 				    dagList);
668 			}
669 			dagList = dagList->next;
670 		}
671 		return RF_TRUE;
672 	}
673 }
674 /* only make it this far if all dags complete successfully */
675 int
676 rf_State_Cleanup(RF_RaidAccessDesc_t *desc)
677 {
678 #if RF_ACC_TRACE > 0
679 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
680 	RF_Etimer_t timer;
681 #endif
682 	RF_AccessStripeMapHeader_t *asmh = desc->asmap;
683 	RF_Raid_t *raidPtr = desc->raidPtr;
684 	RF_AccessStripeMap_t *asm_p;
685 	RF_DagList_t *dagList;
686 	int i;
687 
688 	desc->state++;
689 
690 #if RF_ACC_TRACE > 0
691 	timer = tracerec->timer;
692 	RF_ETIMER_STOP(timer);
693 	RF_ETIMER_EVAL(timer);
694 	tracerec->specific.user.dag_retry_us = RF_ETIMER_VAL_US(timer);
695 
696 	/* the RAID I/O is complete.  Clean up. */
697 	tracerec->specific.user.dag_retry_us = 0;
698 
699 	RF_ETIMER_START(timer);
700 #endif
701 	/* free all dags */
702 	dagList = desc->dagList;
703 	for (i = 0; i < desc->numStripes; i++) {
704 		rf_FreeDAG(dagList->dags);
705 		dagList = dagList->next;
706 	}
707 #if RF_ACC_TRACE > 0
708 	RF_ETIMER_STOP(timer);
709 	RF_ETIMER_EVAL(timer);
710 	tracerec->specific.user.cleanup_us = RF_ETIMER_VAL_US(timer);
711 
712 	RF_ETIMER_START(timer);
713 #endif
714 	for (asm_p = asmh->stripeMap; asm_p; asm_p = asm_p->next) {
715 		if (!rf_suppressLocksAndLargeWrites &&
716 		    asm_p->parityInfo &&
717 		    !(desc->flags & RF_DAG_SUPPRESS_LOCKS)) {
718 			RF_ASSERT_VALID_LOCKREQ(&asm_p->lockReqDesc);
719 			rf_ReleaseStripeLock(raidPtr->lockTable,
720 					     asm_p->stripeID,
721 					     &asm_p->lockReqDesc);
722 		}
723 		if (asm_p->flags & RF_ASM_FLAGS_RECON_BLOCKED) {
724 			rf_UnblockRecon(raidPtr, asm_p);
725 		}
726 	}
727 #if RF_ACC_TRACE > 0
728 	RF_ETIMER_STOP(timer);
729 	RF_ETIMER_EVAL(timer);
730 	tracerec->specific.user.lock_us += RF_ETIMER_VAL_US(timer);
731 
732 	RF_ETIMER_START(timer);
733 #endif
734 	rf_FreeAccessStripeMap(asmh);
735 #if RF_ACC_TRACE > 0
736 	RF_ETIMER_STOP(timer);
737 	RF_ETIMER_EVAL(timer);
738 	tracerec->specific.user.cleanup_us += RF_ETIMER_VAL_US(timer);
739 
740 	RF_ETIMER_STOP(desc->timer);
741 	RF_ETIMER_EVAL(desc->timer);
742 
743 	timer = desc->tracerec.tot_timer;
744 	RF_ETIMER_STOP(timer);
745 	RF_ETIMER_EVAL(timer);
746 	desc->tracerec.total_us = RF_ETIMER_VAL_US(timer);
747 
748 	rf_LogTraceRec(raidPtr, tracerec);
749 #endif
750 	desc->flags |= RF_DAG_ACCESS_COMPLETE;
751 
752 	return RF_FALSE;
753 }
754