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