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