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