Home | History | Annotate | Line # | Download | only in raidframe
rf_states.c revision 1.8
      1 /*	$NetBSD: rf_states.c,v 1.8 1999/12/03 03:35:30 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/errno.h>
     30 
     31 #include "rf_archs.h"
     32 #include "rf_threadstuff.h"
     33 #include "rf_raid.h"
     34 #include "rf_dag.h"
     35 #include "rf_desc.h"
     36 #include "rf_aselect.h"
     37 #include "rf_threadid.h"
     38 #include "rf_general.h"
     39 #include "rf_states.h"
     40 #include "rf_dagutils.h"
     41 #include "rf_driver.h"
     42 #include "rf_engine.h"
     43 #include "rf_map.h"
     44 #include "rf_etimer.h"
     45 
     46 #if defined(KERNEL) && (DKUSAGE > 0)
     47 #include <sys/dkusage.h>
     48 #include <io/common/iotypes.h>
     49 #include <io/cam/dec_cam.h>
     50 #include <io/cam/cam.h>
     51 #include <io/cam/pdrv.h>
     52 #endif				/* KERNEL && DKUSAGE > 0 */
     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 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 
     94 void
     95 rf_ContinueRaidAccess(RF_RaidAccessDesc_t * desc)
     96 {
     97 	int     suspended = RF_FALSE;
     98 	int     current_state_index = desc->state;
     99 	RF_AccessState_t current_state = desc->states[current_state_index];
    100 
    101 	do {
    102 
    103 		current_state_index = desc->state;
    104 		current_state = desc->states[current_state_index];
    105 
    106 		switch (current_state) {
    107 
    108 		case rf_QuiesceState:
    109 			suspended = rf_State_Quiesce(desc);
    110 			break;
    111 		case rf_IncrAccessesCountState:
    112 			suspended = rf_State_IncrAccessCount(desc);
    113 			break;
    114 		case rf_MapState:
    115 			suspended = rf_State_Map(desc);
    116 			break;
    117 		case rf_LockState:
    118 			suspended = rf_State_Lock(desc);
    119 			break;
    120 		case rf_CreateDAGState:
    121 			suspended = rf_State_CreateDAG(desc);
    122 			break;
    123 		case rf_ExecuteDAGState:
    124 			suspended = rf_State_ExecuteDAG(desc);
    125 			break;
    126 		case rf_ProcessDAGState:
    127 			suspended = rf_State_ProcessDAG(desc);
    128 			break;
    129 		case rf_CleanupState:
    130 			suspended = rf_State_Cleanup(desc);
    131 			break;
    132 		case rf_DecrAccessesCountState:
    133 			suspended = rf_State_DecrAccessCount(desc);
    134 			break;
    135 		case rf_LastState:
    136 			suspended = rf_State_LastState(desc);
    137 			break;
    138 		}
    139 
    140 		/* after this point, we cannot dereference desc since desc may
    141 		 * have been freed. desc is only freed in LastState, so if we
    142 		 * renter this function or loop back up, desc should be valid. */
    143 
    144 		if (rf_printStatesDebug) {
    145 			int     tid;
    146 			rf_get_threadid(tid);
    147 
    148 			printf("[%d] State: %-24s StateIndex: %3i desc: 0x%ld %s\n",
    149 			    tid, StateName(current_state), current_state_index, (long) desc,
    150 			    suspended ? "callback scheduled" : "looping");
    151 		}
    152 	} while (!suspended && current_state != rf_LastState);
    153 
    154 	return;
    155 }
    156 
    157 
    158 void
    159 rf_ContinueDagAccess(RF_DagList_t * dagList)
    160 {
    161 	RF_AccTraceEntry_t *tracerec = &(dagList->desc->tracerec);
    162 	RF_RaidAccessDesc_t *desc;
    163 	RF_DagHeader_t *dag_h;
    164 	RF_Etimer_t timer;
    165 	int     i;
    166 
    167 	desc = dagList->desc;
    168 
    169 	timer = tracerec->timer;
    170 	RF_ETIMER_STOP(timer);
    171 	RF_ETIMER_EVAL(timer);
    172 	tracerec->specific.user.exec_us = RF_ETIMER_VAL_US(timer);
    173 	RF_ETIMER_START(tracerec->timer);
    174 
    175 	/* skip to dag which just finished */
    176 	dag_h = dagList->dags;
    177 	for (i = 0; i < dagList->numDagsDone; i++) {
    178 		dag_h = dag_h->next;
    179 	}
    180 
    181 	/* check to see if retry is required */
    182 	if (dag_h->status == rf_rollBackward) {
    183 		/* when a dag fails, mark desc status as bad and allow all
    184 		 * other dags in the desc to execute to completion.  then,
    185 		 * free all dags and start over */
    186 		desc->status = 1;	/* bad status */
    187 		{
    188 			printf("[%d] DAG failure: %c addr 0x%lx (%ld) nblk 0x%x (%d) buf 0x%lx\n",
    189 			    desc->tid, desc->type, (long) desc->raidAddress,
    190 			    (long) desc->raidAddress, (int) desc->numBlocks,
    191 			    (int) desc->numBlocks, (unsigned long) (desc->bufPtr));
    192 		}
    193 	}
    194 	dagList->numDagsDone++;
    195 	rf_ContinueRaidAccess(desc);
    196 }
    197 
    198 int
    199 rf_State_LastState(RF_RaidAccessDesc_t * desc)
    200 {
    201 	void    (*callbackFunc) (RF_CBParam_t) = desc->callbackFunc;
    202 	RF_CBParam_t callbackArg;
    203 
    204 	callbackArg.p = desc->callbackArg;
    205 
    206 #if DKUSAGE > 0
    207 	RF_DKU_END_IO(((RF_Raid_t *) desc->raidPtr)->raidid, (struct buf *) desc->bp);
    208 #else
    209 	RF_DKU_END_IO(((RF_Raid_t *) desc->raidPtr)->raidid);
    210 #endif				/* DKUSAGE > 0 */
    211 
    212 	/*
    213 	 * If this is not an async request, wake up the caller
    214 	 */
    215 	if (desc->async_flag == 0)
    216 		wakeup(desc->bp);
    217 
    218 	/*
    219 	 * Wakeup any requests waiting to go.
    220 	 */
    221 
    222 	RF_LOCK_MUTEX(((RF_Raid_t *) desc->raidPtr)->mutex);
    223 	((RF_Raid_t *) desc->raidPtr)->openings++;
    224 	wakeup(&(((RF_Raid_t *) desc->raidPtr)->openings));
    225 	RF_UNLOCK_MUTEX(((RF_Raid_t *) desc->raidPtr)->mutex);
    226 
    227 
    228 	/* printf("Calling biodone on 0x%x\n",desc->bp); */
    229 	biodone(desc->bp);	/* access came through ioctl */
    230 
    231 	if (callbackFunc)
    232 		callbackFunc(callbackArg);
    233 	rf_FreeRaidAccDesc(desc);
    234 
    235 	return RF_FALSE;
    236 }
    237 
    238 int
    239 rf_State_IncrAccessCount(RF_RaidAccessDesc_t * desc)
    240 {
    241 	RF_Raid_t *raidPtr;
    242 
    243 	raidPtr = desc->raidPtr;
    244 	/* Bummer. We have to do this to be 100% safe w.r.t. the increment
    245 	 * below */
    246 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
    247 	raidPtr->accs_in_flight++;	/* used to detect quiescence */
    248 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
    249 
    250 	desc->state++;
    251 	return RF_FALSE;
    252 }
    253 
    254 int
    255 rf_State_DecrAccessCount(RF_RaidAccessDesc_t * desc)
    256 {
    257 	RF_Raid_t *raidPtr;
    258 
    259 	raidPtr = desc->raidPtr;
    260 
    261 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
    262 	raidPtr->accs_in_flight--;
    263 	if (raidPtr->accesses_suspended && raidPtr->accs_in_flight == 0) {
    264 		rf_SignalQuiescenceLock(raidPtr, raidPtr->reconDesc);
    265 	}
    266 	rf_UpdateUserStats(raidPtr, RF_ETIMER_VAL_US(desc->timer), desc->numBlocks);
    267 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
    268 
    269 	desc->state++;
    270 	return RF_FALSE;
    271 }
    272 
    273 int
    274 rf_State_Quiesce(RF_RaidAccessDesc_t * desc)
    275 {
    276 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
    277 	RF_Etimer_t timer;
    278 	int     suspended = RF_FALSE;
    279 	RF_Raid_t *raidPtr;
    280 
    281 	raidPtr = desc->raidPtr;
    282 
    283 	RF_ETIMER_START(timer);
    284 	RF_ETIMER_START(desc->timer);
    285 
    286 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
    287 	if (raidPtr->accesses_suspended) {
    288 		RF_CallbackDesc_t *cb;
    289 		cb = rf_AllocCallbackDesc();
    290 		/* XXX the following cast is quite bogus...
    291 		 * rf_ContinueRaidAccess takes a (RF_RaidAccessDesc_t *) as an
    292 		 * argument..  GO */
    293 		cb->callbackFunc = (void (*) (RF_CBParam_t)) rf_ContinueRaidAccess;
    294 		cb->callbackArg.p = (void *) desc;
    295 		cb->next = raidPtr->quiesce_wait_list;
    296 		raidPtr->quiesce_wait_list = cb;
    297 		suspended = RF_TRUE;
    298 	}
    299 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
    300 
    301 	RF_ETIMER_STOP(timer);
    302 	RF_ETIMER_EVAL(timer);
    303 	tracerec->specific.user.suspend_ovhd_us += RF_ETIMER_VAL_US(timer);
    304 
    305 	if (suspended && rf_quiesceDebug)
    306 		printf("Stalling access due to quiescence lock\n");
    307 
    308 	desc->state++;
    309 	return suspended;
    310 }
    311 
    312 int
    313 rf_State_Map(RF_RaidAccessDesc_t * desc)
    314 {
    315 	RF_Raid_t *raidPtr = desc->raidPtr;
    316 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
    317 	RF_Etimer_t timer;
    318 
    319 	RF_ETIMER_START(timer);
    320 
    321 	if (!(desc->asmap = rf_MapAccess(raidPtr, desc->raidAddress, desc->numBlocks,
    322 		    desc->bufPtr, RF_DONT_REMAP)))
    323 		RF_PANIC();
    324 
    325 	RF_ETIMER_STOP(timer);
    326 	RF_ETIMER_EVAL(timer);
    327 	tracerec->specific.user.map_us = RF_ETIMER_VAL_US(timer);
    328 
    329 	desc->state++;
    330 	return RF_FALSE;
    331 }
    332 
    333 int
    334 rf_State_Lock(RF_RaidAccessDesc_t * desc)
    335 {
    336 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
    337 	RF_Raid_t *raidPtr = desc->raidPtr;
    338 	RF_AccessStripeMapHeader_t *asmh = desc->asmap;
    339 	RF_AccessStripeMap_t *asm_p;
    340 	RF_Etimer_t timer;
    341 	int     suspended = RF_FALSE;
    342 
    343 	RF_ETIMER_START(timer);
    344 	if (!(raidPtr->Layout.map->flags & RF_NO_STRIPE_LOCKS)) {
    345 		RF_StripeNum_t lastStripeID = -1;
    346 
    347 		/* acquire each lock that we don't already hold */
    348 		for (asm_p = asmh->stripeMap; asm_p; asm_p = asm_p->next) {
    349 			RF_ASSERT(RF_IO_IS_R_OR_W(desc->type));
    350 			if (!rf_suppressLocksAndLargeWrites &&
    351 			    asm_p->parityInfo &&
    352 			    !(desc->flags & RF_DAG_SUPPRESS_LOCKS) &&
    353 			    !(asm_p->flags & RF_ASM_FLAGS_LOCK_TRIED)) {
    354 				asm_p->flags |= RF_ASM_FLAGS_LOCK_TRIED;
    355 				RF_ASSERT(asm_p->stripeID > lastStripeID);	/* locks must be
    356 										 * acquired
    357 										 * hierarchically */
    358 				lastStripeID = asm_p->stripeID;
    359 				/* XXX the cast to (void (*)(RF_CBParam_t))
    360 				 * below is bogus!  GO */
    361 				RF_INIT_LOCK_REQ_DESC(asm_p->lockReqDesc, desc->type,
    362 				    (void (*) (struct buf *)) rf_ContinueRaidAccess, desc, asm_p,
    363 				    raidPtr->Layout.dataSectorsPerStripe);
    364 				if (rf_AcquireStripeLock(raidPtr->lockTable, asm_p->stripeID,
    365 					&asm_p->lockReqDesc)) {
    366 					suspended = RF_TRUE;
    367 					break;
    368 				}
    369 			}
    370 			if (desc->type == RF_IO_TYPE_WRITE &&
    371 			    raidPtr->status[asm_p->physInfo->row] == rf_rs_reconstructing) {
    372 				if (!(asm_p->flags & RF_ASM_FLAGS_FORCE_TRIED)) {
    373 					int     val;
    374 
    375 					asm_p->flags |= RF_ASM_FLAGS_FORCE_TRIED;
    376 					/* XXX the cast below is quite
    377 					 * bogus!!! XXX  GO */
    378 					val = rf_ForceOrBlockRecon(raidPtr, asm_p,
    379 					    (void (*) (RF_Raid_t *, void *)) rf_ContinueRaidAccess, desc);
    380 					if (val == 0) {
    381 						asm_p->flags |= RF_ASM_FLAGS_RECON_BLOCKED;
    382 					} else {
    383 						suspended = RF_TRUE;
    384 						break;
    385 					}
    386 				} else {
    387 					if (rf_pssDebug) {
    388 						printf("[%d] skipping force/block because already done, psid %ld\n",
    389 						    desc->tid, (long) asm_p->stripeID);
    390 					}
    391 				}
    392 			} else {
    393 				if (rf_pssDebug) {
    394 					printf("[%d] skipping force/block because not write or not under recon, psid %ld\n",
    395 					    desc->tid, (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_printDAGsDebug)
    445 		for (i = 0; i < desc->numStripes; i++)
    446 			rf_PrintDAGList(desc->dagArray[i].dags);
    447 	RF_ETIMER_STOP(timer);
    448 	RF_ETIMER_EVAL(timer);
    449 	/* update time to create all dags */
    450 	tracerec->specific.user.dag_create_us = RF_ETIMER_VAL_US(timer);
    451 
    452 	desc->status = 0;	/* good status */
    453 
    454 	if (selectStatus) {
    455 		/* failed to create a dag */
    456 		/* this happens when there are too many faults or incomplete
    457 		 * dag libraries */
    458 		printf("[Failed to create a DAG\n]");
    459 		RF_PANIC();
    460 	} else {
    461 		/* bind dags to desc */
    462 		for (i = 0; i < desc->numStripes; i++) {
    463 			dag_h = desc->dagArray[i].dags;
    464 			while (dag_h) {
    465 				dag_h->bp = (struct buf *) desc->bp;
    466 				dag_h->tracerec = tracerec;
    467 				dag_h = dag_h->next;
    468 			}
    469 		}
    470 		desc->flags |= RF_DAG_DISPATCH_RETURNED;
    471 		desc->state++;	/* next state should be rf_State_ExecuteDAG */
    472 	}
    473 	return RF_FALSE;
    474 }
    475 
    476 
    477 
    478 /* the access has an array of dagLists, one dagList per parity stripe.
    479  * fire the first dag in each parity stripe (dagList).
    480  * dags within a stripe (dagList) must be executed sequentially
    481  *  - this preserves atomic parity update
    482  * dags for independents parity groups (stripes) are fired concurrently */
    483 
    484 int
    485 rf_State_ExecuteDAG(RF_RaidAccessDesc_t * desc)
    486 {
    487 	int     i;
    488 	RF_DagHeader_t *dag_h;
    489 	RF_DagList_t *dagArray = desc->dagArray;
    490 
    491 	/* next state is always rf_State_ProcessDAG important to do this
    492 	 * before firing the first dag (it may finish before we leave this
    493 	 * routine) */
    494 	desc->state++;
    495 
    496 	/* sweep dag array, a stripe at a time, firing the first dag in each
    497 	 * stripe */
    498 	for (i = 0; i < desc->numStripes; i++) {
    499 		RF_ASSERT(dagArray[i].numDags > 0);
    500 		RF_ASSERT(dagArray[i].numDagsDone == 0);
    501 		RF_ASSERT(dagArray[i].numDagsFired == 0);
    502 		RF_ETIMER_START(dagArray[i].tracerec.timer);
    503 		/* fire first dag in this stripe */
    504 		dag_h = dagArray[i].dags;
    505 		RF_ASSERT(dag_h);
    506 		dagArray[i].numDagsFired++;
    507 		/* XXX Yet another case where we pass in a conflicting
    508 		 * function pointer :-(  XXX  GO */
    509 		rf_DispatchDAG(dag_h, (void (*) (void *)) rf_ContinueDagAccess, &dagArray[i]);
    510 	}
    511 
    512 	/* the DAG will always call the callback, even if there was no
    513 	 * blocking, so we are always suspended in this state */
    514 	return RF_TRUE;
    515 }
    516 
    517 
    518 
    519 /* rf_State_ProcessDAG is entered when a dag completes.
    520  * first, check to all dags in the access have completed
    521  * if not, fire as many dags as possible */
    522 
    523 int
    524 rf_State_ProcessDAG(RF_RaidAccessDesc_t * desc)
    525 {
    526 	RF_AccessStripeMapHeader_t *asmh = desc->asmap;
    527 	RF_Raid_t *raidPtr = desc->raidPtr;
    528 	RF_DagHeader_t *dag_h;
    529 	int     i, j, done = RF_TRUE;
    530 	RF_DagList_t *dagArray = desc->dagArray;
    531 	RF_Etimer_t timer;
    532 
    533 	/* check to see if this is the last dag */
    534 	for (i = 0; i < desc->numStripes; i++)
    535 		if (dagArray[i].numDags != dagArray[i].numDagsDone)
    536 			done = RF_FALSE;
    537 
    538 	if (done) {
    539 		if (desc->status) {
    540 			/* a dag failed, retry */
    541 			RF_ETIMER_START(timer);
    542 			/* free all dags */
    543 			for (i = 0; i < desc->numStripes; i++) {
    544 				rf_FreeDAG(desc->dagArray[i].dags);
    545 			}
    546 			rf_MarkFailuresInASMList(raidPtr, asmh);
    547 			/* back up to rf_State_CreateDAG */
    548 			desc->state = desc->state - 2;
    549 			return RF_FALSE;
    550 		} else {
    551 			/* move on to rf_State_Cleanup */
    552 			desc->state++;
    553 		}
    554 		return RF_FALSE;
    555 	} else {
    556 		/* more dags to execute */
    557 		/* see if any are ready to be fired.  if so, fire them */
    558 		/* don't fire the initial dag in a list, it's fired in
    559 		 * rf_State_ExecuteDAG */
    560 		for (i = 0; i < desc->numStripes; i++) {
    561 			if ((dagArray[i].numDagsDone < dagArray[i].numDags)
    562 			    && (dagArray[i].numDagsDone == dagArray[i].numDagsFired)
    563 			    && (dagArray[i].numDagsFired > 0)) {
    564 				RF_ETIMER_START(dagArray[i].tracerec.timer);
    565 				/* fire next dag in this stripe */
    566 				/* first, skip to next dag awaiting execution */
    567 				dag_h = dagArray[i].dags;
    568 				for (j = 0; j < dagArray[i].numDagsDone; j++)
    569 					dag_h = dag_h->next;
    570 				dagArray[i].numDagsFired++;
    571 				/* XXX and again we pass a different function
    572 				 * pointer.. GO */
    573 				rf_DispatchDAG(dag_h, (void (*) (void *)) rf_ContinueDagAccess,
    574 				    &dagArray[i]);
    575 			}
    576 		}
    577 		return RF_TRUE;
    578 	}
    579 }
    580 /* only make it this far if all dags complete successfully */
    581 int
    582 rf_State_Cleanup(RF_RaidAccessDesc_t * desc)
    583 {
    584 	RF_AccTraceEntry_t *tracerec = &desc->tracerec;
    585 	RF_AccessStripeMapHeader_t *asmh = desc->asmap;
    586 	RF_Raid_t *raidPtr = desc->raidPtr;
    587 	RF_AccessStripeMap_t *asm_p;
    588 	RF_DagHeader_t *dag_h;
    589 	RF_Etimer_t timer;
    590 	int     tid, i;
    591 
    592 	desc->state++;
    593 
    594 	rf_get_threadid(tid);
    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, asm_p->stripeID,
    635 				    &asm_p->lockReqDesc);
    636 			}
    637 			if (asm_p->flags & RF_ASM_FLAGS_RECON_BLOCKED) {
    638 				rf_UnblockRecon(raidPtr, asm_p);
    639 			}
    640 		}
    641 	}
    642 	RF_ETIMER_STOP(timer);
    643 	RF_ETIMER_EVAL(timer);
    644 	tracerec->specific.user.lock_us += RF_ETIMER_VAL_US(timer);
    645 
    646 	RF_ETIMER_START(timer);
    647 	if (desc->flags & RF_DAG_RETURN_ASM)
    648 		*(desc->paramASM) = asmh;
    649 	else
    650 		rf_FreeAccessStripeMap(asmh);
    651 	RF_ETIMER_STOP(timer);
    652 	RF_ETIMER_EVAL(timer);
    653 	tracerec->specific.user.cleanup_us += RF_ETIMER_VAL_US(timer);
    654 
    655 	RF_ETIMER_STOP(desc->timer);
    656 	RF_ETIMER_EVAL(desc->timer);
    657 
    658 	timer = desc->tracerec.tot_timer;
    659 	RF_ETIMER_STOP(timer);
    660 	RF_ETIMER_EVAL(timer);
    661 	desc->tracerec.total_us = RF_ETIMER_VAL_US(timer);
    662 
    663 	rf_LogTraceRec(raidPtr, tracerec);
    664 
    665 	desc->flags |= RF_DAG_ACCESS_COMPLETE;
    666 
    667 	return RF_FALSE;
    668 }
    669