Home | History | Annotate | Line # | Download | only in raidframe
rf_states.c revision 1.27
      1 /*	$NetBSD: rf_states.c,v 1.27 2004/02/29 21:38:41 oster 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 (at) 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.27 2004/02/29 21:38:41 oster 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 #endif
    169 	RF_RaidAccessDesc_t *desc;
    170 	RF_DagHeader_t *dag_h;
    171 #if RF_ACC_TRACE > 0
    172 	RF_Etimer_t timer;
    173 #endif
    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) (RF_CBParam_t) = desc->callbackFunc;
    216 	RF_CBParam_t callbackArg;
    217 
    218 	callbackArg.p = desc->callbackArg;
    219 
    220 	/*
    221 	 * If this is not an async request, wake up the caller
    222 	 */
    223 	if (desc->async_flag == 0)
    224 		wakeup(desc->bp);
    225 
    226 	/*
    227 	 * That's all the IO for this one... unbusy the 'disk'.
    228 	 */
    229 
    230 	rf_disk_unbusy(desc);
    231 
    232 	/*
    233 	 * Wakeup any requests waiting to go.
    234 	 */
    235 
    236 	RF_LOCK_MUTEX(((RF_Raid_t *) desc->raidPtr)->mutex);
    237 	((RF_Raid_t *) desc->raidPtr)->openings++;
    238 	RF_UNLOCK_MUTEX(((RF_Raid_t *) desc->raidPtr)->mutex);
    239 
    240 	/* wake up any pending IO */
    241 	raidstart(((RF_Raid_t *) desc->raidPtr));
    242 
    243 	/* printf("Calling biodone on 0x%x\n",desc->bp); */
    244 	biodone(desc->bp);	/* access came through ioctl */
    245 
    246 	if (callbackFunc)
    247 		callbackFunc(callbackArg);
    248 	rf_FreeRaidAccDesc(desc);
    249 
    250 	return RF_FALSE;
    251 }
    252 
    253 int
    254 rf_State_IncrAccessCount(RF_RaidAccessDesc_t *desc)
    255 {
    256 	RF_Raid_t *raidPtr;
    257 
    258 	raidPtr = desc->raidPtr;
    259 	/* Bummer. We have to do this to be 100% safe w.r.t. the increment
    260 	 * below */
    261 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
    262 	raidPtr->accs_in_flight++;	/* used to detect quiescence */
    263 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
    264 
    265 	desc->state++;
    266 	return RF_FALSE;
    267 }
    268 
    269 int
    270 rf_State_DecrAccessCount(RF_RaidAccessDesc_t *desc)
    271 {
    272 	RF_Raid_t *raidPtr;
    273 
    274 	raidPtr = desc->raidPtr;
    275 
    276 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
    277 	raidPtr->accs_in_flight--;
    278 	if (raidPtr->accesses_suspended && raidPtr->accs_in_flight == 0) {
    279 		rf_SignalQuiescenceLock(raidPtr);
    280 	}
    281 	rf_UpdateUserStats(raidPtr, RF_ETIMER_VAL_US(desc->timer), desc->numBlocks);
    282 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
    283 
    284 	desc->state++;
    285 	return RF_FALSE;
    286 }
    287 
    288 int
    289 rf_State_Quiesce(RF_RaidAccessDesc_t *desc)
    290 {
    291 #if RF_ACC_TRACE > 0
    292 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
    293 	RF_Etimer_t timer;
    294 #endif
    295 	int     suspended = RF_FALSE;
    296 	RF_Raid_t *raidPtr;
    297 
    298 	raidPtr = desc->raidPtr;
    299 
    300 #if RF_ACC_TRACE > 0
    301 	RF_ETIMER_START(timer);
    302 	RF_ETIMER_START(desc->timer);
    303 #endif
    304 
    305 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
    306 	if (raidPtr->accesses_suspended) {
    307 		RF_CallbackDesc_t *cb;
    308 		cb = rf_AllocCallbackDesc();
    309 
    310 		cb->callbackFunc = (void (*) (RF_CBParam_t)) rf_ContinueRaidAccess;
    311 		cb->callbackArg.p = (void *) desc;
    312 		cb->next = raidPtr->quiesce_wait_list;
    313 		raidPtr->quiesce_wait_list = cb;
    314 		suspended = RF_TRUE;
    315 	}
    316 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
    317 
    318 #if RF_ACC_TRACE > 0
    319 	RF_ETIMER_STOP(timer);
    320 	RF_ETIMER_EVAL(timer);
    321 	tracerec->specific.user.suspend_ovhd_us += RF_ETIMER_VAL_US(timer);
    322 #endif
    323 
    324 #if RF_DEBUG_QUIESCE
    325 	if (suspended && rf_quiesceDebug)
    326 		printf("Stalling access due to quiescence lock\n");
    327 #endif
    328 	desc->state++;
    329 	return suspended;
    330 }
    331 
    332 int
    333 rf_State_Map(RF_RaidAccessDesc_t *desc)
    334 {
    335 	RF_Raid_t *raidPtr = desc->raidPtr;
    336 #if RF_ACC_TRACE > 0
    337 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
    338 	RF_Etimer_t timer;
    339 
    340 	RF_ETIMER_START(timer);
    341 #endif
    342 
    343 	if (!(desc->asmap = rf_MapAccess(raidPtr, desc->raidAddress, desc->numBlocks,
    344 		    desc->bufPtr, RF_DONT_REMAP)))
    345 		RF_PANIC();
    346 
    347 #if RF_ACC_TRACE > 0
    348 	RF_ETIMER_STOP(timer);
    349 	RF_ETIMER_EVAL(timer);
    350 	tracerec->specific.user.map_us = RF_ETIMER_VAL_US(timer);
    351 #endif
    352 
    353 	desc->state++;
    354 	return RF_FALSE;
    355 }
    356 
    357 int
    358 rf_State_Lock(RF_RaidAccessDesc_t *desc)
    359 {
    360 #if RF_ACC_TRACE > 0
    361 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
    362 #endif
    363 	RF_Raid_t *raidPtr = desc->raidPtr;
    364 	RF_AccessStripeMapHeader_t *asmh = desc->asmap;
    365 	RF_AccessStripeMap_t *asm_p;
    366 #if RF_ACC_TRACE > 0
    367 	RF_Etimer_t timer;
    368 #endif
    369 	int     suspended = RF_FALSE;
    370 
    371 #if RF_ACC_TRACE > 0
    372 	RF_ETIMER_START(timer);
    373 #endif
    374 	if (!(raidPtr->Layout.map->flags & RF_NO_STRIPE_LOCKS)) {
    375 		RF_StripeNum_t lastStripeID = -1;
    376 
    377 		/* acquire each lock that we don't already hold */
    378 		for (asm_p = asmh->stripeMap; asm_p; asm_p = asm_p->next) {
    379 			RF_ASSERT(RF_IO_IS_R_OR_W(desc->type));
    380 			if (!rf_suppressLocksAndLargeWrites &&
    381 			    asm_p->parityInfo &&
    382 			    !(desc->flags & RF_DAG_SUPPRESS_LOCKS) &&
    383 			    !(asm_p->flags & RF_ASM_FLAGS_LOCK_TRIED)) {
    384 				asm_p->flags |= RF_ASM_FLAGS_LOCK_TRIED;
    385 				/* locks must be acquired hierarchically */
    386 				RF_ASSERT(asm_p->stripeID > lastStripeID);
    387 				lastStripeID = asm_p->stripeID;
    388 
    389 				RF_INIT_LOCK_REQ_DESC(asm_p->lockReqDesc, desc->type,
    390 				    (void (*) (struct buf *)) rf_ContinueRaidAccess, desc, asm_p,
    391 				    raidPtr->Layout.dataSectorsPerStripe);
    392 				if (rf_AcquireStripeLock(raidPtr->lockTable, asm_p->stripeID,
    393 					&asm_p->lockReqDesc)) {
    394 					suspended = RF_TRUE;
    395 					break;
    396 				}
    397 			}
    398 			if (desc->type == RF_IO_TYPE_WRITE &&
    399 			    raidPtr->status == rf_rs_reconstructing) {
    400 				if (!(asm_p->flags & RF_ASM_FLAGS_FORCE_TRIED)) {
    401 					int     val;
    402 
    403 					asm_p->flags |= RF_ASM_FLAGS_FORCE_TRIED;
    404 					val = rf_ForceOrBlockRecon(raidPtr, asm_p,
    405 					    (void (*) (RF_Raid_t *, void *)) rf_ContinueRaidAccess, desc);
    406 					if (val == 0) {
    407 						asm_p->flags |= RF_ASM_FLAGS_RECON_BLOCKED;
    408 					} else {
    409 						suspended = RF_TRUE;
    410 						break;
    411 					}
    412 				} else {
    413 					if (rf_pssDebug) {
    414 						printf("raid%d: skipping force/block because already done, psid %ld\n",
    415 						       desc->raidPtr->raidid,
    416 						       (long) asm_p->stripeID);
    417 					}
    418 				}
    419 			} else {
    420 				if (rf_pssDebug) {
    421 					printf("raid%d: skipping force/block because not write or not under recon, psid %ld\n",
    422 					       desc->raidPtr->raidid,
    423 					       (long) asm_p->stripeID);
    424 				}
    425 			}
    426 		}
    427 #if RF_ACC_TRACE > 0
    428 		RF_ETIMER_STOP(timer);
    429 		RF_ETIMER_EVAL(timer);
    430 		tracerec->specific.user.lock_us += RF_ETIMER_VAL_US(timer);
    431 #endif
    432 		if (suspended)
    433 			return (RF_TRUE);
    434 	}
    435 	desc->state++;
    436 	return (RF_FALSE);
    437 }
    438 /*
    439  * the following three states create, execute, and post-process dags
    440  * the error recovery unit is a single dag.
    441  * by default, SelectAlgorithm creates an array of dags, one per parity stripe
    442  * in some tricky cases, multiple dags per stripe are created
    443  *   - dags within a parity stripe are executed sequentially (arbitrary order)
    444  *   - dags for distinct parity stripes are executed concurrently
    445  *
    446  * repeat until all dags complete successfully -or- dag selection fails
    447  *
    448  * while !done
    449  *   create dag(s) (SelectAlgorithm)
    450  *   if dag
    451  *     execute dag (DispatchDAG)
    452  *     if dag successful
    453  *       done (SUCCESS)
    454  *     else
    455  *       !done (RETRY - start over with new dags)
    456  *   else
    457  *     done (FAIL)
    458  */
    459 int
    460 rf_State_CreateDAG(RF_RaidAccessDesc_t *desc)
    461 {
    462 #if RF_ACC_TRACE > 0
    463 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
    464 	RF_Etimer_t timer;
    465 #endif
    466 	RF_DagHeader_t *dag_h;
    467 	RF_DagList_t *dagList;
    468 	struct buf *bp;
    469 	int     i, selectStatus;
    470 
    471 	/* generate a dag for the access, and fire it off.  When the dag
    472 	 * completes, we'll get re-invoked in the next state. */
    473 #if RF_ACC_TRACE > 0
    474 	RF_ETIMER_START(timer);
    475 #endif
    476 	/* SelectAlgorithm returns one or more dags */
    477 	selectStatus = rf_SelectAlgorithm(desc, desc->flags | RF_DAG_SUPPRESS_LOCKS);
    478 #if RF_DEBUG_VALIDATE_DAG
    479 	if (rf_printDAGsDebug) {
    480 		dagList = desc->dagList;
    481 		for (i = 0; i < desc->numStripes; i++) {
    482 			rf_PrintDAGList(dagList.dags);
    483 			dagList = dagList->next;
    484 		}
    485 	}
    486 #endif /* RF_DEBUG_VALIDATE_DAG */
    487 #if RF_ACC_TRACE > 0
    488 	RF_ETIMER_STOP(timer);
    489 	RF_ETIMER_EVAL(timer);
    490 	/* update time to create all dags */
    491 	tracerec->specific.user.dag_create_us = RF_ETIMER_VAL_US(timer);
    492 #endif
    493 
    494 	desc->status = 0;	/* good status */
    495 
    496 	if (selectStatus) {
    497 		/* failed to create a dag */
    498 		/* this happens when there are too many faults or incomplete
    499 		 * dag libraries */
    500 		printf("raid%d: failed to create a dag. "
    501 		       "Too many component failures.\n",
    502 		       desc->raidPtr->raidid);
    503 
    504 		desc->status = 1; /* bad status */
    505 		/* skip straight to rf_State_Cleanup() */
    506 		desc->state = rf_CleanupState;
    507 		bp = (struct buf *)desc->bp;
    508 		bp->b_flags |= B_ERROR;
    509 		bp->b_error = EIO;
    510 	} else {
    511 		/* bind dags to desc */
    512 		dagList = desc->dagList;
    513 		for (i = 0; i < desc->numStripes; i++) {
    514 			dag_h = dagList->dags;
    515 			while (dag_h) {
    516 				dag_h->bp = (struct buf *) desc->bp;
    517 #if RF_ACC_TRACE > 0
    518 				dag_h->tracerec = tracerec;
    519 #endif
    520 				dag_h = dag_h->next;
    521 			}
    522 			dagList = dagList->next;
    523 		}
    524 		desc->flags |= RF_DAG_DISPATCH_RETURNED;
    525 		desc->state++;	/* next state should be rf_State_ExecuteDAG */
    526 	}
    527 	return RF_FALSE;
    528 }
    529 
    530 
    531 
    532 /* the access has an list of dagLists, one dagList per parity stripe.
    533  * fire the first dag in each parity stripe (dagList).
    534  * dags within a stripe (dagList) must be executed sequentially
    535  *  - this preserves atomic parity update
    536  * dags for independents parity groups (stripes) are fired concurrently */
    537 
    538 int
    539 rf_State_ExecuteDAG(RF_RaidAccessDesc_t *desc)
    540 {
    541 	int     i;
    542 	RF_DagHeader_t *dag_h;
    543 	RF_DagList_t *dagList;
    544 
    545 	/* next state is always rf_State_ProcessDAG important to do
    546 	 * this before firing the first dag (it may finish before we
    547 	 * leave this routine) */
    548 	desc->state++;
    549 
    550 	/* sweep dag array, a stripe at a time, firing the first dag
    551 	 * in each stripe */
    552 	dagList = desc->dagList;
    553 	for (i = 0; i < desc->numStripes; i++) {
    554 		RF_ASSERT(dagList->numDags > 0);
    555 		RF_ASSERT(dagList->numDagsDone == 0);
    556 		RF_ASSERT(dagList->numDagsFired == 0);
    557 #if RF_ACC_TRACE > 0
    558 		RF_ETIMER_START(dagList->tracerec.timer);
    559 #endif
    560 		/* fire first dag in this stripe */
    561 		dag_h = dagList->dags;
    562 		RF_ASSERT(dag_h);
    563 		dagList->numDagsFired++;
    564 		rf_DispatchDAG(dag_h, (void (*) (void *)) rf_ContinueDagAccess, dagList);
    565 		dagList = dagList->next;
    566 	}
    567 
    568 	/* the DAG will always call the callback, even if there was no
    569 	 * blocking, so we are always suspended in this state */
    570 	return RF_TRUE;
    571 }
    572 
    573 
    574 
    575 /* rf_State_ProcessDAG is entered when a dag completes.
    576  * first, check to all dags in the access have completed
    577  * if not, fire as many dags as possible */
    578 
    579 int
    580 rf_State_ProcessDAG(RF_RaidAccessDesc_t *desc)
    581 {
    582 	RF_AccessStripeMapHeader_t *asmh = desc->asmap;
    583 	RF_Raid_t *raidPtr = desc->raidPtr;
    584 	RF_DagHeader_t *dag_h;
    585 	int     i, j, done = RF_TRUE;
    586 	RF_DagList_t *dagList, *temp;
    587 	RF_Etimer_t timer;
    588 
    589 	/* check to see if this is the last dag */
    590 	dagList = desc->dagList;
    591 	for (i = 0; i < desc->numStripes; i++) {
    592 		if (dagList->numDags != dagList->numDagsDone)
    593 			done = RF_FALSE;
    594 		dagList = dagList->next;
    595 	}
    596 
    597 	if (done) {
    598 		if (desc->status) {
    599 			/* a dag failed, retry */
    600 			RF_ETIMER_START(timer);
    601 			/* free all dags */
    602 			dagList = desc->dagList;
    603 			for (i = 0; i < desc->numStripes; i++) {
    604 				rf_FreeDAG(dagList->dags);
    605 				temp = dagList;
    606 				dagList = dagList->next;
    607 			}
    608 			rf_MarkFailuresInASMList(raidPtr, asmh);
    609 			/* back up to rf_State_CreateDAG */
    610 			desc->state = desc->state - 2;
    611 			return RF_FALSE;
    612 		} else {
    613 			/* move on to rf_State_Cleanup */
    614 			desc->state++;
    615 		}
    616 		return RF_FALSE;
    617 	} else {
    618 		/* more dags to execute */
    619 		/* see if any are ready to be fired.  if so, fire them */
    620 		/* don't fire the initial dag in a list, it's fired in
    621 		 * rf_State_ExecuteDAG */
    622 		dagList = desc->dagList;
    623 		for (i = 0; i < desc->numStripes; i++) {
    624 			if ((dagList->numDagsDone < dagList->numDags)
    625 			    && (dagList->numDagsDone == dagList->numDagsFired)
    626 			    && (dagList->numDagsFired > 0)) {
    627 #if RF_ACC_TRACE > 0
    628 				RF_ETIMER_START(dagList->tracerec.timer);
    629 #endif
    630 				/* fire next dag in this stripe */
    631 				/* first, skip to next dag awaiting execution */
    632 				dag_h = dagList->dags;
    633 				for (j = 0; j < dagList->numDagsDone; j++)
    634 					dag_h = dag_h->next;
    635 				dagList->numDagsFired++;
    636 				rf_DispatchDAG(dag_h, (void (*) (void *)) rf_ContinueDagAccess,
    637 				    dagList);
    638 			}
    639 			dagList = dagList->next;
    640 		}
    641 		return RF_TRUE;
    642 	}
    643 }
    644 /* only make it this far if all dags complete successfully */
    645 int
    646 rf_State_Cleanup(RF_RaidAccessDesc_t *desc)
    647 {
    648 #if RF_ACC_TRACE > 0
    649 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
    650 #endif
    651 	RF_AccessStripeMapHeader_t *asmh = desc->asmap;
    652 	RF_Raid_t *raidPtr = desc->raidPtr;
    653 	RF_AccessStripeMap_t *asm_p;
    654 	RF_DagList_t *dagList;
    655 #if RF_ACC_TRACE > 0
    656 	RF_Etimer_t timer;
    657 #endif
    658 	int i;
    659 
    660 	desc->state++;
    661 
    662 #if RF_ACC_TRACE > 0
    663 	timer = tracerec->timer;
    664 	RF_ETIMER_STOP(timer);
    665 	RF_ETIMER_EVAL(timer);
    666 	tracerec->specific.user.dag_retry_us = RF_ETIMER_VAL_US(timer);
    667 
    668 	/* the RAID I/O is complete.  Clean up. */
    669 	tracerec->specific.user.dag_retry_us = 0;
    670 
    671 	RF_ETIMER_START(timer);
    672 #endif
    673 	/* free all dags */
    674 	dagList = desc->dagList;
    675 	for (i = 0; i < desc->numStripes; i++) {
    676 		rf_FreeDAG(dagList->dags);
    677 		dagList = dagList->next;
    678 	}
    679 #if RF_ACC_TRACE > 0
    680 	RF_ETIMER_STOP(timer);
    681 	RF_ETIMER_EVAL(timer);
    682 	tracerec->specific.user.cleanup_us = RF_ETIMER_VAL_US(timer);
    683 
    684 	RF_ETIMER_START(timer);
    685 #endif
    686 	if (!(raidPtr->Layout.map->flags & RF_NO_STRIPE_LOCKS)) {
    687 		for (asm_p = asmh->stripeMap; asm_p; asm_p = asm_p->next) {
    688 			if (!rf_suppressLocksAndLargeWrites &&
    689 			    asm_p->parityInfo &&
    690 			    !(desc->flags & RF_DAG_SUPPRESS_LOCKS)) {
    691 				RF_ASSERT_VALID_LOCKREQ(&asm_p->lockReqDesc);
    692 				rf_ReleaseStripeLock(raidPtr->lockTable,
    693 						     asm_p->stripeID,
    694 						     &asm_p->lockReqDesc);
    695 			}
    696 			if (asm_p->flags & RF_ASM_FLAGS_RECON_BLOCKED) {
    697 				rf_UnblockRecon(raidPtr, asm_p);
    698 			}
    699 		}
    700 	}
    701 #if RF_ACC_TRACE > 0
    702 	RF_ETIMER_STOP(timer);
    703 	RF_ETIMER_EVAL(timer);
    704 	tracerec->specific.user.lock_us += RF_ETIMER_VAL_US(timer);
    705 
    706 	RF_ETIMER_START(timer);
    707 #endif
    708 	rf_FreeAccessStripeMap(asmh);
    709 #if RF_ACC_TRACE > 0
    710 	RF_ETIMER_STOP(timer);
    711 	RF_ETIMER_EVAL(timer);
    712 	tracerec->specific.user.cleanup_us += RF_ETIMER_VAL_US(timer);
    713 
    714 	RF_ETIMER_STOP(desc->timer);
    715 	RF_ETIMER_EVAL(desc->timer);
    716 
    717 	timer = desc->tracerec.tot_timer;
    718 	RF_ETIMER_STOP(timer);
    719 	RF_ETIMER_EVAL(timer);
    720 	desc->tracerec.total_us = RF_ETIMER_VAL_US(timer);
    721 
    722 	rf_LogTraceRec(raidPtr, tracerec);
    723 #endif
    724 	desc->flags |= RF_DAG_ACCESS_COMPLETE;
    725 
    726 	return RF_FALSE;
    727 }
    728