VirtualBox

Changeset 65703 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Feb 9, 2017 4:04:03 PM (8 years ago)
Author:
vboxsync
Message:

DrvDiskIntegrity: Don't embed the tracking structure into the request as it gets too big otherwise making request cache creation fail

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DrvDiskIntegrity.cpp

    r65487 r65703  
    2929#include <iprt/avl.h>
    3030#include <iprt/mem.h>
     31#include <iprt/memcache.h>
    3132#include <iprt/message.h>
    3233#include <iprt/sg.h>
     
    189190    /** Next free slot in the array */
    190191    volatile unsigned       iNextFreeSlot;
     192    /** Request cache. */
     193    RTMEMCACHE              hReqCache;
    191194
    192195    /** Flag whether we check for requests completing twice. */
     
    213216} DRVDISKINTEGRITY, *PDRVDISKINTEGRITY;
    214217
     218
     219#define DISKINTEGRITY_IOREQ_HANDLE_2_DRVDISKAIOREQ(a_pThis, a_hIoReq) ((*(PDRVDISKAIOREQ *)((uintptr_t)(a_hIoReq) + (a_pThis)->cbIoReqOpaque)))
     220#define DISKINTEGRITY_IOREQ_HANDLE_2_UPPER_OPAQUE(a_pThis, a_hIoReq) ((void *)((uintptr_t)(a_hIoReq) + (a_pThis)->cbIoReqOpaque + sizeof(PDRVDISKAIOREQ)))
     221#define DISKINTEGRITY_IOREQ_ALLOC_2_DRVDISKAIOREQ(a_pvIoReqAlloc) (*(PDRVDISKAIOREQ *)(a_pvIoReqAlloc))
     222#define DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(a_pvIoReqAlloc) ((void *)((uintptr_t)(a_pvIoReqAlloc) + sizeof(PDRVDISKAIOREQ)))
    215223
    216224static void drvdiskintIoReqCheckForDoubleCompletion(PDRVDISKINTEGRITY pThis, PDRVDISKAIOREQ pIoReq,
     
    9941002{
    9951003    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaExPort);
    996     PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)pvIoReqAlloc;
     1004    PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_ALLOC_2_DRVDISKAIOREQ(pvIoReqAlloc);
    9971005    int rc = VINF_SUCCESS;
    9981006
     
    10331041        RTSGBUF SgBufCmp;
    10341042        RTSgBufInit(&SgBufCmp, &SegCmp, 1);
    1035         rc = pThis->pDrvMediaExPort->pfnIoReqCopyToBuf(pThis->pDrvMediaExPort, hIoReq, pIoReq + 1,
     1043        rc = pThis->pDrvMediaExPort->pfnIoReqCopyToBuf(pThis->pDrvMediaExPort, hIoReq,
     1044                                                       DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
    10361045                                                       0, &SgBufCmp, pIoReq->cbTransfer);
    10371046        AssertRC(rc);
     
    10871096    else
    10881097    {
    1089         rc = pThis->pDrvMediaExPort->pfnIoReqCompleteNotify(pThis->pDrvMediaExPort, hIoReq, pIoReq + 1, rcReq);
     1098        rc = pThis->pDrvMediaExPort->pfnIoReqCompleteNotify(pThis->pDrvMediaExPort, hIoReq,
     1099                                                            DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
     1100                                                            rcReq);
    10901101        /* Put on the watch list. */
    10911102        if (pThis->fCheckDoubleCompletion)
     
    11041115{
    11051116    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaExPort);
    1106     PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)pvIoReqAlloc;
     1117    PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_ALLOC_2_DRVDISKAIOREQ(pvIoReqAlloc);
    11071118    RTSGBUF SgBuf;
    11081119
    11091120    RTSgBufClone(&SgBuf, pSgBuf);
    11101121
    1111     int rc = pThis->pDrvMediaExPort->pfnIoReqCopyFromBuf(pThis->pDrvMediaExPort, hIoReq, pIoReq + 1, offDst,
    1112                                                          pSgBuf, cbCopy);
     1122    int rc = pThis->pDrvMediaExPort->pfnIoReqCopyFromBuf(pThis->pDrvMediaExPort, hIoReq,
     1123                                                         DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
     1124                                                         offDst, pSgBuf, cbCopy);
    11131125    if (   RT_SUCCESS(rc)
    11141126        && pIoReq->IoSeg.pvSeg)
     
    11431155{
    11441156    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaExPort);
    1145     PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)pvIoReqAlloc;
     1157    PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_ALLOC_2_DRVDISKAIOREQ(pvIoReqAlloc);
    11461158    RTSGBUF SgBuf;
    11471159
    11481160    RTSgBufClone(&SgBuf, pSgBuf);
    11491161
    1150     int rc = pThis->pDrvMediaExPort->pfnIoReqCopyToBuf(pThis->pDrvMediaExPort, hIoReq, pIoReq + 1, offSrc,
    1151                                                        pSgBuf, cbCopy);
     1162    int rc = pThis->pDrvMediaExPort->pfnIoReqCopyToBuf(pThis->pDrvMediaExPort, hIoReq,
     1163                                                       DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
     1164                                                       offSrc, pSgBuf, cbCopy);
    11521165    if (   RT_SUCCESS(rc)
    11531166        && pIoReq->IoSeg.pvSeg)
     
    11851198{
    11861199    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaExPort);
    1187     PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)pvIoReqAlloc;
    1188 
    1189     return pThis->pDrvMediaExPort->pfnIoReqQueryDiscardRanges(pThis->pDrvMediaExPort, hIoReq, pIoReq + 1, idxRangeStart,
    1190                                                               cRanges, paRanges, pcRanges);
     1200    return pThis->pDrvMediaExPort->pfnIoReqQueryDiscardRanges(pThis->pDrvMediaExPort, hIoReq,
     1201                                                              DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
     1202                                                              idxRangeStart, cRanges, paRanges, pcRanges);
    11911203}
    11921204
     
    11981210{
    11991211    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaExPort);
    1200     PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)pvIoReqAlloc;
    1201 
    1202     pThis->pDrvMediaExPort->pfnIoReqStateChanged(pThis->pDrvMediaExPort, hIoReq, pIoReq + 1, enmState);
     1212    pThis->pDrvMediaExPort->pfnIoReqStateChanged(pThis->pDrvMediaExPort, hIoReq,
     1213                                                 DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
     1214                                                enmState);
    12031215}
    12041216
     
    12211233    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
    12221234
    1223     /* Increase the amount by our private tracking structure. */
    1224     cbIoReqAlloc += sizeof(DRVDISKAIOREQ);
     1235    /* Increase the amount by the size of a pointer to our private tracking structure. */
     1236    cbIoReqAlloc += sizeof(PDRVDISKAIOREQ);
    12251237
    12261238    pThis->fCheckDoubleCompletion = false;
     
    12361248{
    12371249    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
    1238     PDRVDISKAIOREQ pIoReq = NULL;
    1239 
    1240     int rc = pThis->pDrvMediaEx->pfnIoReqAlloc(pThis->pDrvMediaEx, phIoReq, (void **)&pIoReq, uIoReqId, fFlags);
    1241     if RT_SUCCESS(rc)
     1250    int rc = VINF_SUCCESS;
     1251    PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)RTMemCacheAlloc(pThis->hReqCache);
     1252    if (RT_LIKELY(pIoReq))
    12421253    {
    12431254        pIoReq->enmTxDir    = DRVDISKAIOTXDIR_INVALID;
     
    12541265        pIoReq->IoSeg.cbSeg = 0;
    12551266
    1256         /*
    1257          * Store the size off the start of our tracking structure because it is
    1258          * required to access it for the read/write callbacks.
    1259          *
    1260          * ASSUMPTION that the offset is constant.
    1261          */
    1262         if (!pThis->cbIoReqOpaque)
    1263             pThis->cbIoReqOpaque = (uintptr_t)pIoReq - (uintptr_t)*phIoReq;
     1267        PDRVDISKAIOREQ *ppIoReq = NULL;
     1268        rc = pThis->pDrvMediaEx->pfnIoReqAlloc(pThis->pDrvMediaEx, phIoReq, (void **)&ppIoReq, uIoReqId, fFlags);
     1269        if RT_SUCCESS(rc)
     1270        {
     1271            /*
     1272             * Store the size off the start of our tracking structure because it is
     1273             * required to access it for the read/write callbacks.
     1274             *
     1275             * ASSUMPTION that the offset is constant.
     1276             */
     1277            if (!pThis->cbIoReqOpaque)
     1278                pThis->cbIoReqOpaque = (uintptr_t)ppIoReq - (uintptr_t)*phIoReq;
     1279            else
     1280                Assert(pThis->cbIoReqOpaque == (uintptr_t)ppIoReq - (uintptr_t)*phIoReq);
     1281
     1282            *ppIoReq = pIoReq;
     1283            *ppvIoReqAlloc = ((uint8_t *)ppIoReq) + sizeof(PDRVDISKAIOREQ);
     1284        }
    12641285        else
    1265             Assert(pThis->cbIoReqOpaque == (uintptr_t)pIoReq - (uintptr_t)*phIoReq);
    1266 
    1267         *ppvIoReqAlloc = pIoReq + 1;
    1268     }
     1286            RTMemCacheFree(pThis->hReqCache, pIoReq);
     1287    }
     1288    else
     1289        rc = VERR_NO_MEMORY;
    12691290
    12701291    return rc;
     
    12771298{
    12781299    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
    1279     PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)((uintptr_t)hIoReq + pThis->cbIoReqOpaque);
     1300    PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_HANDLE_2_DRVDISKAIOREQ(pThis, hIoReq);
    12801301
    12811302    if (pIoReq->IoSeg.pvSeg)
     
    13271348{
    13281349    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
    1329     PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)((uintptr_t)hIoReq + pThis->cbIoReqOpaque);
     1350    PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_HANDLE_2_DRVDISKAIOREQ(pThis, hIoReq);
    13301351
    13311352    pIoReq->enmTxDir    = DRVDISKAIOTXDIR_READ;
     
    13841405{
    13851406    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
    1386     PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)((uintptr_t)hIoReq + pThis->cbIoReqOpaque);
     1407    PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_HANDLE_2_DRVDISKAIOREQ(pThis, hIoReq);
    13871408
    13881409    pIoReq->enmTxDir    = DRVDISKAIOTXDIR_WRITE;
     
    14071428
    14081429            RTSgBufInit(&SgBuf, &pIoReq->IoSeg, 1);
    1409             int rc2 = pThis->pDrvMediaExPort->pfnIoReqCopyToBuf(pThis->pDrvMediaExPort, hIoReq, pIoReq + 1, 0,
    1410                                                                &SgBuf, cbWrite);
     1430            int rc2 = pThis->pDrvMediaExPort->pfnIoReqCopyToBuf(pThis->pDrvMediaExPort, hIoReq,
     1431                                                                DISKINTEGRITY_IOREQ_HANDLE_2_UPPER_OPAQUE(pThis, hIoReq),
     1432                                                                0, &SgBuf, cbWrite);
    14111433            AssertRC(rc2);
    14121434        }
     
    14641486{
    14651487    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
    1466     PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)((uintptr_t)hIoReq + pThis->cbIoReqOpaque);
     1488    PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_HANDLE_2_DRVDISKAIOREQ(pThis, hIoReq);
    14671489
    14681490    pIoReq->enmTxDir    = DRVDISKAIOTXDIR_FLUSH;
     
    16231645    if (pThis->hIoLogger)
    16241646        VDDbgIoLogDestroy(pThis->hIoLogger);
     1647
     1648    if (pThis->hReqCache != NIL_RTMEMCACHE)
     1649    {
     1650        RTMemCacheDestroy(pThis->hReqCache);
     1651        pThis->hReqCache = NIL_RTMEMCACHE;
     1652    }
    16251653}
    16261654
     
    16861714     */
    16871715    pThis->pDrvIns                       = pDrvIns;
     1716    pThis->hReqCache                     = NIL_RTMEMCACHE;
    16881717
    16891718    /* IBase. */
     
    17451774    /* Try to attach extended media port interface above.*/
    17461775    pThis->pDrvMediaExPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAEXPORT);
     1776
     1777    rc = RTMemCacheCreate(&pThis->hReqCache, sizeof(DRVDISKAIOREQ), 0, UINT32_MAX,
     1778                          NULL, NULL, NULL, 0);
     1779    if (RT_FAILURE(rc))
     1780        return PDMDRV_SET_ERROR(pDrvIns, rc,
     1781                                N_("Failed to create request tracking structure cache"));
    17471782
    17481783    /*
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