VirtualBox

Changeset 29449 in vbox


Ignore:
Timestamp:
May 13, 2010 3:32:07 PM (15 years ago)
Author:
vboxsync
Message:

fileaio-posix.cpp: Fix flushes which were in the waiting list but not submitted because of an error (EAGAIN)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/fileaio-posix.cpp

    r29129 r29449  
    6868/** Invalid entry in the waiting array. */
    6969#define RTFILEAIOCTX_WAIT_ENTRY_INVALID (~0U)
     70
     71/** No-op replacement for rtFileAioCtxDump for non debug builds */
     72#ifndef LOG_ENABLED
     73# define rtFileAioCtxDump(pCtxInt) do {} while (0)
     74#endif
    7075
    7176/*******************************************************************************
     
    199204                   && pReqHead)
    200205            {
     206                RTFIELAIOREQ_ASSERT_STATE(pReqHead, SUBMITTED);
    201207                pCtxInt->apReqs[pCtxInt->iFirstFree] = pReqHead;
    202208                pReqHead->iWaitingList = pCtxInt->iFirstFree;
     
    215221            if (pReqHead)
    216222            {
     223                RTFIELAIOREQ_ASSERT_STATE(pReqHead, SUBMITTED);
    217224                if (!pCtxInt->pReqsWaitHead)
    218225                {
     
    231238                /* Update tail. */
    232239                while (pReqHead->pNext)
     240                {
     241                    RTFIELAIOREQ_ASSERT_STATE(pReqHead->pNext, SUBMITTED);
    233242                    pReqHead = pReqHead->pNext;
     243                }
    234244
    235245                pCtxInt->pReqsWaitTail = pReqHead;
     
    579589}
    580590
     591#ifdef LOG_ENABLED
     592/**
     593 * Dumps the state of a async I/O context.
     594 */
     595static void rtFileAioCtxDump(PRTFILEAIOCTXINTERNAL pCtxInt)
     596{
     597    LogFlow(("cRequests=%d\n", pCtxInt->cRequests));
     598    LogFlow(("cMaxRequests=%u\n", pCtxInt->cMaxRequests));
     599    LogFlow(("hThreadWait=%#p\n", pCtxInt->hThreadWait));
     600    LogFlow(("fWokenUp=%RTbool\n", pCtxInt->fWokenUp));
     601    LogFlow(("fWaiting=%RTbool\n", pCtxInt->fWaiting));
     602    LogFlow(("fWokenUpInternal=%RTbool\n", pCtxInt->fWokenUpInternal));
     603    for (unsigned i = 0; i < RT_ELEMENTS(pCtxInt->apReqsNewHead); i++)
     604        LogFlow(("apReqsNewHead[%u]=%#p\n", i, pCtxInt->apReqsNewHead[i]));
     605    LogFlow(("pReqToCancel=%#p\n", pCtxInt->pReqToCancel));
     606    LogFlow(("pReqsWaitHead=%#p\n", pCtxInt->pReqsWaitHead));
     607    LogFlow(("pReqsWaitTail=%#p\n", pCtxInt->pReqsWaitTail));
     608    LogFlow(("cReqsWaitMax=%u\n", pCtxInt->cReqsWaitMax));
     609    LogFlow(("iFirstFree=%u\n", pCtxInt->iFirstFree));
     610    for (unsigned i = 0; i < pCtxInt->cReqsWaitMax; i++)
     611        LogFlow(("apReqs[%u]=%#p\n", i, pCtxInt->apReqs[i]));
     612}
     613#endif
     614
    581615RTDECL(int) RTFileAioCtxSubmit(RTFILEAIOCTX hAioCtx, PRTFILEAIOREQ pahReqs, size_t cReqs)
    582616{
     
    588622    AssertReturn(cReqs != 0, VERR_INVALID_POINTER);
    589623    AssertPtrReturn(pahReqs,  VERR_INVALID_PARAMETER);
     624
     625    rtFileAioCtxDump(pCtxInt);
    590626
    591627    /* Check that we don't exceed the limit */
     
    632668            pReqInt->pCtxInt = pCtxInt;
    633669
     670            if (pReqInt->fFlush)
     671                break;
     672
    634673            /* Link them together. */
    635674            pReqInt->pNext = pHead;
     
    639678            pHead = pReqInt;
    640679            RTFILEAIOREQ_SET_STATE(pReqInt, SUBMITTED);
    641 
    642             if (pReqInt->fFlush)
    643                 break;
    644680
    645681            cReqsSubmit++;
     
    732768        {
    733769            pReqInt = pahReqs[0];
    734             RTFILEAIOREQ_VALID_RETURN(pReqInt);
    735770
    736771            if (pReqInt->fFlush)
     
    743778                if (RT_UNLIKELY(rcPosix < 0))
    744779                {
    745                     rc = RTErrConvertFromErrno(errno);
    746                     RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
    747                     pReqInt->Rc = rc;
     780                    if (errno == EAGAIN)
     781                    {
     782                        rc = VERR_FILE_AIO_INSUFFICIENT_RESSOURCES;
     783                        RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
     784                    }
     785                    else
     786                    {
     787                        rc = RTErrConvertFromErrno(errno);
     788                        RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
     789                        pReqInt->Rc = rc;
     790                    }
    748791                    pReqInt->cbTransfered = 0;
    749 
    750                     /* Unlink from the list. */
    751                     PRTFILEAIOREQINTERNAL pNext, pPrev;
    752                     pNext = pReqInt->pNext;
    753                     pPrev = pReqInt->pPrev;
    754                     if (pNext)
    755                         pNext->pPrev = pPrev;
    756                     if (pPrev)
    757                         pPrev->pNext = pNext;
    758                     else
    759                         pHead = pNext;
    760792                    break;
    761793                }
     794
     795                /* Link them together. */
     796                pReqInt->pNext = pHead;
     797                if (pHead)
     798                    pHead->pPrev = pReqInt;
     799                pReqInt->pPrev = NULL;
     800                pHead = pReqInt;
     801                RTFILEAIOREQ_SET_STATE(pReqInt, SUBMITTED);
    762802
    763803                ASMAtomicIncS32(&pCtxInt->cRequests);
     
    804844    }
    805845
     846    rtFileAioCtxDump(pCtxInt);
     847
    806848    return rc;
    807849}
     
    818860    uint64_t         StartNanoTS = 0;
    819861
     862    LogFlowFunc(("hAioCtx=%#p cMinReqs=%zu cMillies=%u pahReqs=%#p cReqs=%zu pcbReqs=%#p\n",
     863                 hAioCtx, cMinReqs, cMillies, pahReqs, cReqs, pcReqs));
     864
    820865    /* Check parameters. */
    821866    AssertPtrReturn(pCtxInt, VERR_INVALID_HANDLE);
     
    824869    AssertReturn(cReqs != 0, VERR_INVALID_PARAMETER);
    825870    AssertReturn(cReqs >= cMinReqs, VERR_OUT_OF_RANGE);
     871
     872    rtFileAioCtxDump(pCtxInt);
    826873
    827874    int32_t cRequestsWaiting = ASMAtomicReadS32(&pCtxInt->cRequests);
     
    866913#endif
    867914
     915        LogFlow(("Waiting for %d requests to complete\n", pCtxInt->iFirstFree));
     916        rtFileAioCtxDump(pCtxInt);
     917
    868918        ASMAtomicXchgBool(&pCtxInt->fWaiting, true);
    869919        int rcPosix = aio_suspend((const struct aiocb * const *)pCtxInt->apReqs,
     
    872922        if (rcPosix < 0)
    873923        {
     924            LogFlow(("aio_suspend failed %d nent=%u\n", errno, pCtxInt->iFirstFree));
    874925            /* Check that this is an external wakeup event. */
    875926            if (errno == EINTR)
     
    9841035    ASMAtomicWriteHandle(&pCtxInt->hThreadWait, NIL_RTTHREAD);
    9851036
     1037    rtFileAioCtxDump(pCtxInt);
     1038
    9861039    return rc;
    9871040}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette