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