Home | History | Annotate | Line # | Download | only in raidframe
rf_reconbuffer.c revision 1.4
      1  1.4  soren /*	$NetBSD: rf_reconbuffer.c,v 1.4 2000/03/13 23:52:36 soren Exp $	*/
      2  1.1  oster /*
      3  1.1  oster  * Copyright (c) 1995 Carnegie-Mellon University.
      4  1.1  oster  * All rights reserved.
      5  1.1  oster  *
      6  1.1  oster  * Author: Mark Holland
      7  1.1  oster  *
      8  1.1  oster  * Permission to use, copy, modify and distribute this software and
      9  1.1  oster  * its documentation is hereby granted, provided that both the copyright
     10  1.1  oster  * notice and this permission notice appear in all copies of the
     11  1.1  oster  * software, derivative works or modified versions, and any portions
     12  1.1  oster  * thereof, and that both notices appear in supporting documentation.
     13  1.1  oster  *
     14  1.1  oster  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  1.1  oster  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16  1.1  oster  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  1.1  oster  *
     18  1.1  oster  * Carnegie Mellon requests users of this software to return to
     19  1.1  oster  *
     20  1.1  oster  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  1.1  oster  *  School of Computer Science
     22  1.1  oster  *  Carnegie Mellon University
     23  1.1  oster  *  Pittsburgh PA 15213-3890
     24  1.1  oster  *
     25  1.1  oster  * any improvements or extensions that they make and grant Carnegie the
     26  1.1  oster  * rights to redistribute these changes.
     27  1.1  oster  */
     28  1.1  oster 
     29  1.1  oster /***************************************************
     30  1.1  oster  *
     31  1.1  oster  * rf_reconbuffer.c -- reconstruction buffer manager
     32  1.1  oster  *
     33  1.1  oster  ***************************************************/
     34  1.1  oster 
     35  1.1  oster #include "rf_raid.h"
     36  1.1  oster #include "rf_reconbuffer.h"
     37  1.1  oster #include "rf_acctrace.h"
     38  1.1  oster #include "rf_etimer.h"
     39  1.1  oster #include "rf_general.h"
     40  1.1  oster #include "rf_debugprint.h"
     41  1.1  oster #include "rf_revent.h"
     42  1.1  oster #include "rf_reconutil.h"
     43  1.1  oster #include "rf_nwayxor.h"
     44  1.1  oster 
     45  1.1  oster #define Dprintf1(s,a) if (rf_reconbufferDebug) printf(s,a)
     46  1.1  oster #define Dprintf2(s,a,b) if (rf_reconbufferDebug) printf(s,a,b)
     47  1.1  oster #define Dprintf3(s,a,b,c) if (rf_reconbufferDebug) printf(s,a,b,c)
     48  1.1  oster #define Dprintf4(s,a,b,c,d) if (rf_reconbufferDebug) printf(s,a,b,c,d)
     49  1.1  oster #define Dprintf5(s,a,b,c,d,e) if (rf_reconbufferDebug) printf(s,a,b,c,d,e)
     50  1.1  oster 
     51  1.1  oster /*****************************************************************************************
     52  1.1  oster  *
     53  1.1  oster  * Submit a reconstruction buffer to the manager for XOR.
     54  1.1  oster  * We can only submit a buffer if (1) we can xor into an existing buffer, which means
     55  1.1  oster  * we don't have to acquire a new one, (2) we can acquire a floating
     56  1.1  oster  * recon buffer, or (3) the caller has indicated that we are allowed to keep the
     57  1.1  oster  * submitted buffer.
     58  1.1  oster  *
     59  1.1  oster  * Returns non-zero if and only if we were not able to submit.
     60  1.1  oster  * In this case, we append the current disk ID to the wait list on the indicated
     61  1.1  oster  * RU, so that it will be re-enabled when we acquire a buffer for this RU.
     62  1.1  oster  *
     63  1.1  oster  ****************************************************************************************/
     64  1.1  oster 
     65  1.1  oster /* just to make the code below more readable */
     66  1.1  oster #define BUFWAIT_APPEND(_cb_, _pssPtr_, _row_, _col_) \
     67  1.1  oster   _cb_ = rf_AllocCallbackDesc();                    \
     68  1.1  oster   (_cb_)->row = (_row_); (_cb_)->col = (_col_); (_cb_)->next = (_pssPtr_)->bufWaitList; (_pssPtr_)->bufWaitList = (_cb_);
     69  1.1  oster 
     70  1.1  oster /*
     71  1.1  oster  * nWayXorFuncs[i] is a pointer to a function that will xor "i"
     72  1.1  oster  * bufs into the accumulating sum.
     73  1.1  oster  */
     74  1.1  oster static RF_VoidFuncPtr nWayXorFuncs[] = {
     75  1.3  oster 	NULL,
     76  1.3  oster 	(RF_VoidFuncPtr) rf_nWayXor1,
     77  1.3  oster 	(RF_VoidFuncPtr) rf_nWayXor2,
     78  1.3  oster 	(RF_VoidFuncPtr) rf_nWayXor3,
     79  1.3  oster 	(RF_VoidFuncPtr) rf_nWayXor4,
     80  1.3  oster 	(RF_VoidFuncPtr) rf_nWayXor5,
     81  1.3  oster 	(RF_VoidFuncPtr) rf_nWayXor6,
     82  1.3  oster 	(RF_VoidFuncPtr) rf_nWayXor7,
     83  1.3  oster 	(RF_VoidFuncPtr) rf_nWayXor8,
     84  1.3  oster 	(RF_VoidFuncPtr) rf_nWayXor9
     85  1.1  oster };
     86  1.3  oster 
     87  1.3  oster int
     88  1.3  oster rf_SubmitReconBuffer(rbuf, keep_it, use_committed)
     89  1.3  oster 	RF_ReconBuffer_t *rbuf;	/* the recon buffer to submit */
     90  1.3  oster 	int     keep_it;	/* whether we can keep this buffer or we have
     91  1.3  oster 				 * to return it */
     92  1.3  oster 	int     use_committed;	/* whether to use a committed or an available
     93  1.3  oster 				 * recon buffer */
     94  1.1  oster {
     95  1.3  oster 	RF_LayoutSW_t *lp;
     96  1.3  oster 	int     rc;
     97  1.1  oster 
     98  1.3  oster 	lp = rbuf->raidPtr->Layout.map;
     99  1.3  oster 	rc = lp->SubmitReconBuffer(rbuf, keep_it, use_committed);
    100  1.3  oster 	return (rc);
    101  1.1  oster }
    102  1.1  oster 
    103  1.3  oster int
    104  1.3  oster rf_SubmitReconBufferBasic(rbuf, keep_it, use_committed)
    105  1.3  oster 	RF_ReconBuffer_t *rbuf;	/* the recon buffer to submit */
    106  1.3  oster 	int     keep_it;	/* whether we can keep this buffer or we have
    107  1.3  oster 				 * to return it */
    108  1.3  oster 	int     use_committed;	/* whether to use a committed or an available
    109  1.3  oster 				 * recon buffer */
    110  1.1  oster {
    111  1.3  oster 	RF_Raid_t *raidPtr = rbuf->raidPtr;
    112  1.3  oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
    113  1.3  oster 	RF_ReconCtrl_t *reconCtrlPtr = raidPtr->reconControl[rbuf->row];
    114  1.3  oster 	RF_ReconParityStripeStatus_t *pssPtr;
    115  1.3  oster 	RF_ReconBuffer_t *targetRbuf, *t = NULL;	/* temporary rbuf
    116  1.3  oster 							 * pointers */
    117  1.3  oster 	caddr_t ta;		/* temporary data buffer pointer */
    118  1.3  oster 	RF_CallbackDesc_t *cb, *p;
    119  1.3  oster 	int     retcode = 0, created = 0;
    120  1.3  oster 
    121  1.3  oster 	RF_Etimer_t timer;
    122  1.3  oster 
    123  1.3  oster 	/* makes no sense to have a submission from the failed disk */
    124  1.3  oster 	RF_ASSERT(rbuf);
    125  1.3  oster 	RF_ASSERT(rbuf->col != reconCtrlPtr->fcol);
    126  1.3  oster 
    127  1.3  oster 	Dprintf5("RECON: submission by row %d col %d for psid %ld ru %d (failed offset %ld)\n",
    128  1.3  oster 	    rbuf->row, rbuf->col, (long) rbuf->parityStripeID, rbuf->which_ru, (long) rbuf->failedDiskSectorOffset);
    129  1.3  oster 
    130  1.3  oster 	RF_LOCK_PSS_MUTEX(raidPtr, rbuf->row, rbuf->parityStripeID);
    131  1.3  oster 
    132  1.3  oster 	RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
    133  1.3  oster 
    134  1.3  oster 	pssPtr = rf_LookupRUStatus(raidPtr, reconCtrlPtr->pssTable, rbuf->parityStripeID, rbuf->which_ru, RF_PSS_NONE, &created);
    135  1.3  oster 	RF_ASSERT(pssPtr);	/* if it didn't exist, we wouldn't have gotten
    136  1.3  oster 				 * an rbuf for it */
    137  1.3  oster 
    138  1.3  oster 	/* check to see if enough buffers have accumulated to do an XOR.  If
    139  1.3  oster 	 * so, there's no need to acquire a floating rbuf.  Before we can do
    140  1.3  oster 	 * any XORing, we must have acquired a destination buffer.  If we
    141  1.3  oster 	 * have, then we can go ahead and do the XOR if (1) including this
    142  1.3  oster 	 * buffer, enough bufs have accumulated, or (2) this is the last
    143  1.3  oster 	 * submission for this stripe. Otherwise, we have to go acquire a
    144  1.3  oster 	 * floating rbuf. */
    145  1.3  oster 
    146  1.3  oster 	targetRbuf = (RF_ReconBuffer_t *) pssPtr->rbuf;
    147  1.3  oster 	if ((targetRbuf != NULL) &&
    148  1.3  oster 	    ((pssPtr->xorBufCount == rf_numBufsToAccumulate - 1) || (targetRbuf->count + pssPtr->xorBufCount + 1 == layoutPtr->numDataCol))) {
    149  1.3  oster 		pssPtr->rbufsForXor[pssPtr->xorBufCount++] = rbuf;	/* install this buffer */
    150  1.3  oster 		Dprintf3("RECON: row %d col %d invoking a %d-way XOR\n", rbuf->row, rbuf->col, pssPtr->xorBufCount);
    151  1.3  oster 		RF_ETIMER_START(timer);
    152  1.3  oster 		rf_MultiWayReconXor(raidPtr, pssPtr);
    153  1.3  oster 		RF_ETIMER_STOP(timer);
    154  1.3  oster 		RF_ETIMER_EVAL(timer);
    155  1.3  oster 		raidPtr->accumXorTimeUs += RF_ETIMER_VAL_US(timer);
    156  1.3  oster 		if (!keep_it) {
    157  1.3  oster 			raidPtr->recon_tracerecs[rbuf->col].xor_us = RF_ETIMER_VAL_US(timer);
    158  1.3  oster 			RF_ETIMER_STOP(raidPtr->recon_tracerecs[rbuf->col].recon_timer);
    159  1.3  oster 			RF_ETIMER_EVAL(raidPtr->recon_tracerecs[rbuf->col].recon_timer);
    160  1.3  oster 			raidPtr->recon_tracerecs[rbuf->col].specific.recon.recon_return_to_submit_us +=
    161  1.3  oster 			    RF_ETIMER_VAL_US(raidPtr->recon_tracerecs[rbuf->col].recon_timer);
    162  1.3  oster 			RF_ETIMER_START(raidPtr->recon_tracerecs[rbuf->col].recon_timer);
    163  1.3  oster 
    164  1.3  oster 			rf_LogTraceRec(raidPtr, &raidPtr->recon_tracerecs[rbuf->col]);
    165  1.3  oster 		}
    166  1.3  oster 		rf_CheckForFullRbuf(raidPtr, reconCtrlPtr, pssPtr, layoutPtr->numDataCol);
    167  1.3  oster 
    168  1.3  oster 		/* if use_committed is on, we _must_ consume a buffer off the
    169  1.3  oster 		 * committed list. */
    170  1.3  oster 		if (use_committed) {
    171  1.3  oster 			t = reconCtrlPtr->committedRbufs;
    172  1.3  oster 			RF_ASSERT(t);
    173  1.3  oster 			reconCtrlPtr->committedRbufs = t->next;
    174  1.3  oster 			rf_ReleaseFloatingReconBuffer(raidPtr, rbuf->row, t);
    175  1.3  oster 		}
    176  1.3  oster 		if (keep_it) {
    177  1.3  oster 			RF_UNLOCK_PSS_MUTEX(raidPtr, rbuf->row, rbuf->parityStripeID);
    178  1.3  oster 			RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
    179  1.3  oster 			rf_FreeReconBuffer(rbuf);
    180  1.3  oster 			return (retcode);
    181  1.3  oster 		}
    182  1.3  oster 		goto out;
    183  1.3  oster 	}
    184  1.3  oster 	/* set the value of "t", which we'll use as the rbuf from here on */
    185  1.3  oster 	if (keep_it) {
    186  1.3  oster 		t = rbuf;
    187  1.3  oster 	} else {
    188  1.3  oster 		if (use_committed) {	/* if a buffer has been committed to
    189  1.3  oster 					 * us, use it */
    190  1.3  oster 			t = reconCtrlPtr->committedRbufs;
    191  1.3  oster 			RF_ASSERT(t);
    192  1.3  oster 			reconCtrlPtr->committedRbufs = t->next;
    193  1.3  oster 			t->next = NULL;
    194  1.3  oster 		} else
    195  1.3  oster 			if (reconCtrlPtr->floatingRbufs) {
    196  1.3  oster 				t = reconCtrlPtr->floatingRbufs;
    197  1.3  oster 				reconCtrlPtr->floatingRbufs = t->next;
    198  1.3  oster 				t->next = NULL;
    199  1.3  oster 			}
    200  1.3  oster 	}
    201  1.3  oster 
    202  1.3  oster 	/* If we weren't able to acquire a buffer, append to the end of the
    203  1.3  oster 	 * buf list in the recon ctrl struct. */
    204  1.3  oster 	if (!t) {
    205  1.3  oster 		RF_ASSERT(!keep_it && !use_committed);
    206  1.3  oster 		Dprintf2("RECON: row %d col %d failed to acquire floating rbuf\n", rbuf->row, rbuf->col);
    207  1.3  oster 
    208  1.3  oster 		raidPtr->procsInBufWait++;
    209  1.3  oster 		if ((raidPtr->procsInBufWait == raidPtr->numCol - 1) && (raidPtr->numFullReconBuffers == 0)) {
    210  1.3  oster 			printf("Buffer wait deadlock detected.  Exiting.\n");
    211  1.3  oster 			rf_PrintPSStatusTable(raidPtr, rbuf->row);
    212  1.3  oster 			RF_PANIC();
    213  1.3  oster 		}
    214  1.3  oster 		pssPtr->flags |= RF_PSS_BUFFERWAIT;
    215  1.3  oster 		cb = rf_AllocCallbackDesc();	/* append to buf wait list in
    216  1.3  oster 						 * recon ctrl structure */
    217  1.3  oster 		cb->row = rbuf->row;
    218  1.3  oster 		cb->col = rbuf->col;
    219  1.3  oster 		cb->callbackArg.v = rbuf->parityStripeID;
    220  1.3  oster 		cb->callbackArg2.v = rbuf->which_ru;
    221  1.3  oster 		cb->next = NULL;
    222  1.3  oster 		if (!reconCtrlPtr->bufferWaitList)
    223  1.3  oster 			reconCtrlPtr->bufferWaitList = cb;
    224  1.3  oster 		else {		/* might want to maintain head/tail pointers
    225  1.3  oster 				 * here rather than search for end of list */
    226  1.3  oster 			for (p = reconCtrlPtr->bufferWaitList; p->next; p = p->next);
    227  1.3  oster 			p->next = cb;
    228  1.3  oster 		}
    229  1.3  oster 		retcode = 1;
    230  1.3  oster 		goto out;
    231  1.3  oster 	}
    232  1.3  oster 	Dprintf2("RECON: row %d col %d acquired rbuf\n", rbuf->row, rbuf->col);
    233  1.3  oster 	RF_ETIMER_STOP(raidPtr->recon_tracerecs[rbuf->col].recon_timer);
    234  1.3  oster 	RF_ETIMER_EVAL(raidPtr->recon_tracerecs[rbuf->col].recon_timer);
    235  1.3  oster 	raidPtr->recon_tracerecs[rbuf->col].specific.recon.recon_return_to_submit_us +=
    236  1.3  oster 	    RF_ETIMER_VAL_US(raidPtr->recon_tracerecs[rbuf->col].recon_timer);
    237  1.3  oster 	RF_ETIMER_START(raidPtr->recon_tracerecs[rbuf->col].recon_timer);
    238  1.3  oster 
    239  1.3  oster 	rf_LogTraceRec(raidPtr, &raidPtr->recon_tracerecs[rbuf->col]);
    240  1.3  oster 
    241  1.3  oster 	/* initialize the buffer */
    242  1.3  oster 	if (t != rbuf) {
    243  1.3  oster 		t->row = rbuf->row;
    244  1.3  oster 		t->col = reconCtrlPtr->fcol;
    245  1.3  oster 		t->parityStripeID = rbuf->parityStripeID;
    246  1.3  oster 		t->which_ru = rbuf->which_ru;
    247  1.3  oster 		t->failedDiskSectorOffset = rbuf->failedDiskSectorOffset;
    248  1.3  oster 		t->spRow = rbuf->spRow;
    249  1.3  oster 		t->spCol = rbuf->spCol;
    250  1.3  oster 		t->spOffset = rbuf->spOffset;
    251  1.3  oster 
    252  1.3  oster 		ta = t->buffer;
    253  1.3  oster 		t->buffer = rbuf->buffer;
    254  1.3  oster 		rbuf->buffer = ta;	/* swap buffers */
    255  1.3  oster 	}
    256  1.3  oster 	/* the first installation always gets installed as the destination
    257  1.3  oster 	 * buffer. subsequent installations get stacked up to allow for
    258  1.3  oster 	 * multi-way XOR */
    259  1.3  oster 	if (!pssPtr->rbuf) {
    260  1.3  oster 		pssPtr->rbuf = t;
    261  1.3  oster 		t->count = 1;
    262  1.3  oster 	} else
    263  1.3  oster 		pssPtr->rbufsForXor[pssPtr->xorBufCount++] = t;	/* install this buffer */
    264  1.3  oster 
    265  1.3  oster 	rf_CheckForFullRbuf(raidPtr, reconCtrlPtr, pssPtr, layoutPtr->numDataCol);	/* the buffer is full if
    266  1.3  oster 											 * G=2 */
    267  1.3  oster 
    268  1.3  oster out:
    269  1.3  oster 	RF_UNLOCK_PSS_MUTEX(raidPtr, rbuf->row, rbuf->parityStripeID);
    270  1.3  oster 	RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
    271  1.3  oster 	return (retcode);
    272  1.1  oster }
    273  1.1  oster 
    274  1.3  oster int
    275  1.3  oster rf_MultiWayReconXor(raidPtr, pssPtr)
    276  1.3  oster 	RF_Raid_t *raidPtr;
    277  1.3  oster 	RF_ReconParityStripeStatus_t *pssPtr;	/* the pss descriptor for this
    278  1.3  oster 						 * parity stripe */
    279  1.1  oster {
    280  1.3  oster 	int     i, numBufs = pssPtr->xorBufCount;
    281  1.3  oster 	int     numBytes = rf_RaidAddressToByte(raidPtr, raidPtr->Layout.sectorsPerStripeUnit * raidPtr->Layout.SUsPerRU);
    282  1.3  oster 	RF_ReconBuffer_t **rbufs = (RF_ReconBuffer_t **) pssPtr->rbufsForXor;
    283  1.3  oster 	RF_ReconBuffer_t *targetRbuf = (RF_ReconBuffer_t *) pssPtr->rbuf;
    284  1.3  oster 
    285  1.3  oster 	RF_ASSERT(pssPtr->rbuf != NULL);
    286  1.3  oster 	RF_ASSERT(numBufs > 0 && numBufs < RF_PS_MAX_BUFS);
    287  1.2  oster #ifdef _KERNEL
    288  1.1  oster #ifndef __NetBSD__
    289  1.3  oster 	thread_block();		/* yield the processor before doing a big XOR */
    290  1.1  oster #endif
    291  1.3  oster #endif				/* _KERNEL */
    292  1.3  oster 	/*
    293  1.3  oster          * XXX
    294  1.3  oster          *
    295  1.3  oster          * What if more than 9 bufs?
    296  1.3  oster          */
    297  1.3  oster 	nWayXorFuncs[numBufs] (pssPtr->rbufsForXor, targetRbuf, numBytes / sizeof(long));
    298  1.3  oster 
    299  1.3  oster 	/* release all the reconstruction buffers except the last one, which
    300  1.4  soren 	 * belongs to the disk whose submission caused this XOR to take place */
    301  1.3  oster 	for (i = 0; i < numBufs - 1; i++) {
    302  1.3  oster 		if (rbufs[i]->type == RF_RBUF_TYPE_FLOATING)
    303  1.3  oster 			rf_ReleaseFloatingReconBuffer(raidPtr, rbufs[i]->row, rbufs[i]);
    304  1.3  oster 		else
    305  1.3  oster 			if (rbufs[i]->type == RF_RBUF_TYPE_FORCED)
    306  1.3  oster 				rf_FreeReconBuffer(rbufs[i]);
    307  1.3  oster 			else
    308  1.3  oster 				RF_ASSERT(0);
    309  1.3  oster 	}
    310  1.3  oster 	targetRbuf->count += pssPtr->xorBufCount;
    311  1.3  oster 	pssPtr->xorBufCount = 0;
    312  1.3  oster 	return (0);
    313  1.1  oster }
    314  1.1  oster /* removes one full buffer from one of the full-buffer lists and returns it.
    315  1.1  oster  *
    316  1.1  oster  * ASSUMES THE RB_MUTEX IS UNLOCKED AT ENTRY.
    317  1.1  oster  */
    318  1.3  oster RF_ReconBuffer_t *
    319  1.3  oster rf_GetFullReconBuffer(reconCtrlPtr)
    320  1.3  oster 	RF_ReconCtrl_t *reconCtrlPtr;
    321  1.1  oster {
    322  1.3  oster 	RF_ReconBuffer_t *p;
    323  1.1  oster 
    324  1.3  oster 	RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
    325  1.1  oster 
    326  1.3  oster 	if ((p = reconCtrlPtr->priorityList) != NULL) {
    327  1.3  oster 		reconCtrlPtr->priorityList = p->next;
    328  1.3  oster 		p->next = NULL;
    329  1.3  oster 		goto out;
    330  1.3  oster 	}
    331  1.3  oster 	if ((p = reconCtrlPtr->fullBufferList) != NULL) {
    332  1.3  oster 		reconCtrlPtr->fullBufferList = p->next;
    333  1.3  oster 		p->next = NULL;
    334  1.3  oster 		goto out;
    335  1.3  oster 	}
    336  1.1  oster out:
    337  1.3  oster 	RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
    338  1.3  oster 	return (p);
    339  1.1  oster }
    340  1.1  oster 
    341  1.1  oster 
    342  1.1  oster /* if the reconstruction buffer is full, move it to the full list, which is maintained
    343  1.1  oster  * sorted by failed disk sector offset
    344  1.1  oster  *
    345  1.1  oster  * ASSUMES THE RB_MUTEX IS LOCKED AT ENTRY.
    346  1.1  oster  */
    347  1.3  oster int
    348  1.3  oster rf_CheckForFullRbuf(raidPtr, reconCtrl, pssPtr, numDataCol)
    349  1.3  oster 	RF_Raid_t *raidPtr;
    350  1.3  oster 	RF_ReconCtrl_t *reconCtrl;
    351  1.3  oster 	RF_ReconParityStripeStatus_t *pssPtr;
    352  1.3  oster 	int     numDataCol;
    353  1.1  oster {
    354  1.3  oster 	RF_ReconBuffer_t *p, *pt, *rbuf = (RF_ReconBuffer_t *) pssPtr->rbuf;
    355  1.1  oster 
    356  1.3  oster 	if (rbuf->count == numDataCol) {
    357  1.3  oster 		raidPtr->numFullReconBuffers++;
    358  1.3  oster 		Dprintf2("RECON: rbuf for psid %ld ru %d has filled\n",
    359  1.3  oster 		    (long) rbuf->parityStripeID, rbuf->which_ru);
    360  1.3  oster 		if (!reconCtrl->fullBufferList || (rbuf->failedDiskSectorOffset < reconCtrl->fullBufferList->failedDiskSectorOffset)) {
    361  1.3  oster 			Dprintf2("RECON: rbuf for psid %ld ru %d is head of list\n",
    362  1.3  oster 			    (long) rbuf->parityStripeID, rbuf->which_ru);
    363  1.3  oster 			rbuf->next = reconCtrl->fullBufferList;
    364  1.3  oster 			reconCtrl->fullBufferList = rbuf;
    365  1.3  oster 		} else {
    366  1.3  oster 			for (pt = reconCtrl->fullBufferList, p = pt->next; p && p->failedDiskSectorOffset < rbuf->failedDiskSectorOffset; pt = p, p = p->next);
    367  1.3  oster 			rbuf->next = p;
    368  1.3  oster 			pt->next = rbuf;
    369  1.3  oster 			Dprintf2("RECON: rbuf for psid %ld ru %d is in list\n",
    370  1.3  oster 			    (long) rbuf->parityStripeID, rbuf->which_ru);
    371  1.3  oster 		}
    372  1.1  oster #if 0
    373  1.3  oster 		pssPtr->writeRbuf = pssPtr->rbuf;	/* DEBUG ONLY:  we like
    374  1.3  oster 							 * to be able to find
    375  1.3  oster 							 * this rbuf while it's
    376  1.3  oster 							 * awaiting write */
    377  1.1  oster #else
    378  1.3  oster 		rbuf->pssPtr = pssPtr;
    379  1.1  oster #endif
    380  1.3  oster 		pssPtr->rbuf = NULL;
    381  1.3  oster 		rf_CauseReconEvent(raidPtr, rbuf->row, rbuf->col, NULL, RF_REVENT_BUFREADY);
    382  1.3  oster 	}
    383  1.3  oster 	return (0);
    384  1.1  oster }
    385  1.1  oster 
    386  1.1  oster 
    387  1.1  oster /* release a floating recon buffer for someone else to use.
    388  1.1  oster  * assumes the rb_mutex is LOCKED at entry
    389  1.1  oster  */
    390  1.3  oster void
    391  1.3  oster rf_ReleaseFloatingReconBuffer(raidPtr, row, rbuf)
    392  1.3  oster 	RF_Raid_t *raidPtr;
    393  1.3  oster 	RF_RowCol_t row;
    394  1.3  oster 	RF_ReconBuffer_t *rbuf;
    395  1.1  oster {
    396  1.3  oster 	RF_ReconCtrl_t *rcPtr = raidPtr->reconControl[row];
    397  1.3  oster 	RF_CallbackDesc_t *cb;
    398  1.3  oster 
    399  1.3  oster 	Dprintf2("RECON: releasing rbuf for psid %ld ru %d\n",
    400  1.3  oster 	    (long) rbuf->parityStripeID, rbuf->which_ru);
    401  1.1  oster 
    402  1.3  oster 	/* if anyone is waiting on buffers, wake one of them up.  They will
    403  1.3  oster 	 * subsequently wake up anyone else waiting on their RU */
    404  1.3  oster 	if (rcPtr->bufferWaitList) {
    405  1.3  oster 		rbuf->next = rcPtr->committedRbufs;
    406  1.3  oster 		rcPtr->committedRbufs = rbuf;
    407  1.3  oster 		cb = rcPtr->bufferWaitList;
    408  1.3  oster 		rcPtr->bufferWaitList = cb->next;
    409  1.3  oster 		rf_CauseReconEvent(raidPtr, cb->row, cb->col, (void *) 1, RF_REVENT_BUFCLEAR);	/* arg==1 => we've
    410  1.3  oster 												 * committed a buffer */
    411  1.3  oster 		rf_FreeCallbackDesc(cb);
    412  1.3  oster 		raidPtr->procsInBufWait--;
    413  1.3  oster 	} else {
    414  1.3  oster 		rbuf->next = rcPtr->floatingRbufs;
    415  1.3  oster 		rcPtr->floatingRbufs = rbuf;
    416  1.3  oster 	}
    417  1.1  oster }
    418  1.1  oster /* release any disk that is waiting on a buffer for the indicated RU.
    419  1.1  oster  * assumes the rb_mutex is LOCKED at entry
    420  1.1  oster  */
    421  1.3  oster void
    422  1.3  oster rf_ReleaseBufferWaiters(raidPtr, pssPtr)
    423  1.3  oster 	RF_Raid_t *raidPtr;
    424  1.3  oster 	RF_ReconParityStripeStatus_t *pssPtr;
    425  1.1  oster {
    426  1.3  oster 	RF_CallbackDesc_t *cb1, *cb = pssPtr->bufWaitList;
    427  1.1  oster 
    428  1.3  oster 	Dprintf2("RECON: releasing buf waiters for psid %ld ru %d\n",
    429  1.3  oster 	    (long) pssPtr->parityStripeID, pssPtr->which_ru);
    430  1.3  oster 	pssPtr->flags &= ~RF_PSS_BUFFERWAIT;
    431  1.3  oster 	while (cb) {
    432  1.3  oster 		cb1 = cb->next;
    433  1.3  oster 		cb->next = NULL;
    434  1.3  oster 		rf_CauseReconEvent(raidPtr, cb->row, cb->col, (void *) 0, RF_REVENT_BUFCLEAR);	/* arg==0 => we haven't
    435  1.3  oster 												 * committed a buffer */
    436  1.3  oster 		rf_FreeCallbackDesc(cb);
    437  1.3  oster 		cb = cb1;
    438  1.3  oster 	}
    439  1.3  oster 	pssPtr->bufWaitList = NULL;
    440  1.1  oster }
    441  1.1  oster /* when reconstruction is forced on an RU, there may be some disks waiting to
    442  1.1  oster  * acquire a buffer for that RU.  Since we allocate a new buffer as part of
    443  1.1  oster  * the forced-reconstruction process, we no longer have to wait for any
    444  1.1  oster  * buffers, so we wakeup any waiter that we find in the bufferWaitList
    445  1.1  oster  *
    446  1.1  oster  * assumes the rb_mutex is LOCKED at entry
    447  1.1  oster  */
    448  1.3  oster void
    449  1.3  oster rf_ReleaseBufferWaiter(rcPtr, rbuf)
    450  1.3  oster 	RF_ReconCtrl_t *rcPtr;
    451  1.3  oster 	RF_ReconBuffer_t *rbuf;
    452  1.1  oster {
    453  1.3  oster 	RF_CallbackDesc_t *cb, *cbt;
    454  1.1  oster 
    455  1.3  oster 	for (cbt = NULL, cb = rcPtr->bufferWaitList; cb; cbt = cb, cb = cb->next) {
    456  1.3  oster 		if ((cb->callbackArg.v == rbuf->parityStripeID) && (cb->callbackArg2.v == rbuf->which_ru)) {
    457  1.3  oster 			Dprintf2("RECON: Dropping row %d col %d from buffer wait list\n", cb->row, cb->col);
    458  1.3  oster 			if (cbt)
    459  1.3  oster 				cbt->next = cb->next;
    460  1.3  oster 			else
    461  1.3  oster 				rcPtr->bufferWaitList = cb->next;
    462  1.3  oster 			rf_CauseReconEvent((RF_Raid_t *) rbuf->raidPtr, cb->row, cb->col, (void *) 0, RF_REVENT_BUFREADY);	/* arg==0 => no
    463  1.3  oster 																 * committed buffer */
    464  1.3  oster 			rf_FreeCallbackDesc(cb);
    465  1.3  oster 			return;
    466  1.3  oster 		}
    467  1.3  oster 	}
    468  1.1  oster }
    469