📄 rf_reconbuffer.c
字号:
if (use_committed) { /* if a buffer has been committed to us, use it */ t = reconCtrlPtr->committedRbufs; RF_ASSERT(t); reconCtrlPtr->committedRbufs = t->next; t->next = NULL; } else if (reconCtrlPtr->floatingRbufs) { t = reconCtrlPtr->floatingRbufs; reconCtrlPtr->floatingRbufs = t->next; t->next = NULL; } } /* If we weren't able to acquire a buffer, * append to the end of the buf list in the recon ctrl struct. */ if (!t) { RF_ASSERT(!keep_it && !use_committed); Dprintf2("RECON: row %d col %d failed to acquire floating rbuf\n",rbuf->row, rbuf->col); raidPtr->procsInBufWait++; if ( (raidPtr->procsInBufWait == raidPtr->numCol -1) && (raidPtr->numFullReconBuffers == 0)) { printf("Buffer wait deadlock detected. Exiting.\n"); rf_PrintPSStatusTable(raidPtr, rbuf->row); RF_PANIC(); } pssPtr->flags |= RF_PSS_BUFFERWAIT; cb = rf_AllocCallbackDesc(); /* append to buf wait list in recon ctrl structure */ cb->row = rbuf->row; cb->col = rbuf->col; cb->callbackArg.v = rbuf->parityStripeID; cb->callbackArg2.v = rbuf->which_ru; cb->next = NULL; if (!reconCtrlPtr->bufferWaitList) reconCtrlPtr->bufferWaitList = cb; else { /* might want to maintain head/tail pointers here rather than search for end of list */ for (p = reconCtrlPtr->bufferWaitList; p->next; p=p->next); p->next = cb; } retcode = 1; goto out; } Dprintf2("RECON: row %d col %d acquired rbuf\n",rbuf->row, rbuf->col); RF_ETIMER_STOP(raidPtr->recon_tracerecs[rbuf->col].recon_timer); RF_ETIMER_EVAL(raidPtr->recon_tracerecs[rbuf->col].recon_timer); raidPtr->recon_tracerecs[rbuf->col].specific.recon.recon_return_to_submit_us += RF_ETIMER_VAL_US(raidPtr->recon_tracerecs[rbuf->col].recon_timer); RF_ETIMER_START(raidPtr->recon_tracerecs[rbuf->col].recon_timer); rf_LogTraceRec(raidPtr, &raidPtr->recon_tracerecs[rbuf->col]); /* initialize the buffer */ if (t!=rbuf) { t->row = rbuf->row; t->col = reconCtrlPtr->fcol; t->parityStripeID = rbuf->parityStripeID; t->which_ru = rbuf->which_ru; t->failedDiskSectorOffset = rbuf->failedDiskSectorOffset; t->spRow=rbuf->spRow; t->spCol=rbuf->spCol; t->spOffset=rbuf->spOffset; ta = t->buffer; t->buffer = rbuf->buffer; rbuf->buffer = ta; /* swap buffers */ } /* the first installation always gets installed as the destination buffer. * subsequent installations get stacked up to allow for multi-way XOR */ if (!pssPtr->rbuf) {pssPtr->rbuf = t; t->count = 1;} else pssPtr->rbufsForXor[ pssPtr->xorBufCount++ ] = t; /* install this buffer */ rf_CheckForFullRbuf(raidPtr, reconCtrlPtr, pssPtr, layoutPtr->numDataCol); /* the buffer is full if G=2 */out: RF_UNLOCK_PSS_MUTEX( raidPtr,rbuf->row,rbuf->parityStripeID); RF_UNLOCK_MUTEX( reconCtrlPtr->rb_mutex ); return(retcode);}int rf_MultiWayReconXor(raidPtr, pssPtr) RF_Raid_t *raidPtr; RF_ReconParityStripeStatus_t *pssPtr; /* the pss descriptor for this parity stripe */{ int i, numBufs = pssPtr->xorBufCount; int numBytes = rf_RaidAddressToByte(raidPtr, raidPtr->Layout.sectorsPerStripeUnit * raidPtr->Layout.SUsPerRU); RF_ReconBuffer_t **rbufs = (RF_ReconBuffer_t **) pssPtr->rbufsForXor; RF_ReconBuffer_t *targetRbuf = (RF_ReconBuffer_t *) pssPtr->rbuf; RF_ASSERT(pssPtr->rbuf != NULL); RF_ASSERT(numBufs > 0 && numBufs < RF_PS_MAX_BUFS);#ifdef KERNEL thread_block(); /* yield the processor before doing a big XOR */#endif /* KERNEL */ /* * XXX * * What if more than 9 bufs? */ nWayXorFuncs[numBufs](pssPtr->rbufsForXor, targetRbuf, numBytes/sizeof(long)); /* release all the reconstruction buffers except the last one, which belongs to the * the disk who's submission caused this XOR to take place */ for (i=0; i < numBufs-1; i++) { if (rbufs[i]->type == RF_RBUF_TYPE_FLOATING) rf_ReleaseFloatingReconBuffer(raidPtr, rbufs[i]->row, rbufs[i]); else if (rbufs[i]->type == RF_RBUF_TYPE_FORCED) rf_FreeReconBuffer(rbufs[i]); else RF_ASSERT(0); } targetRbuf->count += pssPtr->xorBufCount; pssPtr->xorBufCount = 0; return(0);}/* removes one full buffer from one of the full-buffer lists and returns it. * * ASSUMES THE RB_MUTEX IS UNLOCKED AT ENTRY. */RF_ReconBuffer_t *rf_GetFullReconBuffer(reconCtrlPtr) RF_ReconCtrl_t *reconCtrlPtr;{ RF_ReconBuffer_t *p; RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex); if ( (p=reconCtrlPtr->priorityList) != NULL) { reconCtrlPtr->priorityList = p->next; p->next = NULL; goto out; } if ( (p=reconCtrlPtr->fullBufferList) != NULL) { reconCtrlPtr->fullBufferList = p->next; p->next = NULL; goto out; }out: RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex); return(p);}/* if the reconstruction buffer is full, move it to the full list, which is maintained * sorted by failed disk sector offset * * ASSUMES THE RB_MUTEX IS LOCKED AT ENTRY. */int rf_CheckForFullRbuf(raidPtr, reconCtrl, pssPtr, numDataCol) RF_Raid_t *raidPtr; RF_ReconCtrl_t *reconCtrl; RF_ReconParityStripeStatus_t *pssPtr; int numDataCol;{ RF_ReconBuffer_t *p, *pt, *rbuf = (RF_ReconBuffer_t *) pssPtr->rbuf; if (rbuf->count == numDataCol) { raidPtr->numFullReconBuffers++; Dprintf2("RECON: rbuf for psid %ld ru %d has filled\n",rbuf->parityStripeID, rbuf->which_ru); if (!reconCtrl->fullBufferList || (rbuf->failedDiskSectorOffset < reconCtrl->fullBufferList->failedDiskSectorOffset)) { Dprintf2("RECON: rbuf for psid %ld ru %d is head of list\n", rbuf->parityStripeID, rbuf->which_ru); rbuf->next = reconCtrl->fullBufferList; reconCtrl->fullBufferList = rbuf; } else { for (pt = reconCtrl->fullBufferList, p = pt->next; p && p->failedDiskSectorOffset < rbuf->failedDiskSectorOffset; pt=p, p=p->next); rbuf->next = p; pt->next = rbuf; Dprintf2("RECON: rbuf for psid %ld ru %d is in list\n", rbuf->parityStripeID, rbuf->which_ru); }#if 0 pssPtr->writeRbuf = pssPtr->rbuf; /* DEBUG ONLY: we like to be able to find this rbuf while it's awaiting write */#else rbuf->pssPtr = pssPtr;#endif pssPtr->rbuf = NULL; rf_CauseReconEvent(raidPtr, rbuf->row, rbuf->col, NULL, RF_REVENT_BUFREADY); } return(0);}/* release a floating recon buffer for someone else to use. * assumes the rb_mutex is LOCKED at entry */void rf_ReleaseFloatingReconBuffer(raidPtr, row, rbuf) RF_Raid_t *raidPtr; RF_RowCol_t row; RF_ReconBuffer_t *rbuf;{ RF_ReconCtrl_t *rcPtr = raidPtr->reconControl[row]; RF_CallbackDesc_t *cb; Dprintf2("RECON: releasing rbuf for psid %ld ru %d\n",rbuf->parityStripeID, rbuf->which_ru); /* if anyone is waiting on buffers, wake one of them up. They will subsequently wake up anyone * else waiting on their RU */ if (rcPtr->bufferWaitList) { rbuf->next = rcPtr->committedRbufs; rcPtr->committedRbufs = rbuf; cb = rcPtr->bufferWaitList; rcPtr->bufferWaitList = cb->next; rf_CauseReconEvent(raidPtr, cb->row, cb->col, (void *) 1, RF_REVENT_BUFCLEAR); /* arg==1 => we've committed a buffer */ rf_FreeCallbackDesc(cb); raidPtr->procsInBufWait--; } else { rbuf->next = rcPtr->floatingRbufs; rcPtr->floatingRbufs = rbuf; }}/* release any disk that is waiting on a buffer for the indicated RU. * assumes the rb_mutex is LOCKED at entry */void rf_ReleaseBufferWaiters(raidPtr, pssPtr) RF_Raid_t *raidPtr; RF_ReconParityStripeStatus_t *pssPtr;{ RF_CallbackDesc_t *cb1, *cb = pssPtr->bufWaitList; Dprintf2("RECON: releasing buf waiters for psid %ld ru %d\n",pssPtr->parityStripeID, pssPtr->which_ru); pssPtr->flags &= ~RF_PSS_BUFFERWAIT; while (cb) { cb1 = cb->next; cb->next = NULL; rf_CauseReconEvent(raidPtr, cb->row, cb->col, (void *) 0, RF_REVENT_BUFCLEAR); /* arg==0 => we haven't committed a buffer */ rf_FreeCallbackDesc(cb); cb = cb1; } pssPtr->bufWaitList = NULL;}/* when reconstruction is forced on an RU, there may be some disks waiting to * acquire a buffer for that RU. Since we allocate a new buffer as part of * the forced-reconstruction process, we no longer have to wait for any * buffers, so we wakeup any waiter that we find in the bufferWaitList * * assumes the rb_mutex is LOCKED at entry */void rf_ReleaseBufferWaiter(rcPtr, rbuf) RF_ReconCtrl_t *rcPtr; RF_ReconBuffer_t *rbuf;{ RF_CallbackDesc_t *cb, *cbt; for (cbt = NULL, cb = rcPtr->bufferWaitList; cb; cbt = cb, cb=cb->next) { if ( (cb->callbackArg.v == rbuf->parityStripeID) && ( cb->callbackArg2.v == rbuf->which_ru)) { Dprintf2("RECON: Dropping row %d col %d from buffer wait list\n", cb->row, cb->col); if (cbt) cbt->next = cb->next; else rcPtr->bufferWaitList = cb->next; rf_CauseReconEvent((RF_Raid_t *) rbuf->raidPtr, cb->row, cb->col, (void *) 0, RF_REVENT_BUFREADY); /* arg==0 => no committed buffer */ rf_FreeCallbackDesc(cb); return; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -