VirtualBox

Changeset 63997 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
Sep 26, 2016 8:58:39 AM (8 years ago)
Author:
vboxsync
Message:

Storage: Change PDMIMEDIAEX::pfnIoReqDiscard to not get the discard ranges on submission but to query them on demand by using the new PDMIMEDIAEXPORT::pfnIoReqQueryDiscardRanges

Location:
trunk/src/VBox/Devices/Storage
Files:
4 edited

Legend:

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

    r63727 r63997  
    15021502
    15031503/**
     1504 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqQueryDiscardRanges}
     1505 */
     1506static DECLCALLBACK(int) drvdiskintIoReqQueryDiscardRanges(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq,
     1507                                                           void *pvIoReqAlloc, uint32_t idxRangeStart,
     1508                                                           uint32_t cRanges, PRTRANGE paRanges,
     1509                                                           uint32_t *pcRanges)
     1510{
     1511    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaExPort);
     1512    PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)pvIoReqAlloc;
     1513
     1514    return pThis->pDrvMediaExPort->pfnIoReqQueryDiscardRanges(pThis->pDrvMediaExPort, hIoReq, pIoReq + 1, idxRangeStart,
     1515                                                              cRanges, paRanges, pcRanges);
     1516}
     1517
     1518/**
    15041519 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqStateChanged}
    15051520 */
     
    17711786 * @interface_method_impl{PDMIMEDIAEX,pfnIoReqDiscard}
    17721787 */
    1773 static DECLCALLBACK(int) drvdiskintIoReqDiscard(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq, PCRTRANGE paRanges, unsigned cRanges)
     1788static DECLCALLBACK(int) drvdiskintIoReqDiscard(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq, unsigned cRangesMax)
    17741789{
    17751790    PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
    1776     return pThis->pDrvMediaEx->pfnIoReqDiscard(pThis->pDrvMediaEx, hIoReq, paRanges, cRanges);
     1791    return pThis->pDrvMediaEx->pfnIoReqDiscard(pThis->pDrvMediaEx, hIoReq, cRangesMax);
    17771792}
    17781793
     
    20082023
    20092024    /* IMediaExPort. */
    2010     pThis->IMediaExPort.pfnIoReqCompleteNotify = drvdiskintIoReqCompleteNotify;
    2011     pThis->IMediaExPort.pfnIoReqCopyFromBuf    = drvdiskintIoReqCopyFromBuf;
    2012     pThis->IMediaExPort.pfnIoReqCopyToBuf      = drvdiskintIoReqCopyToBuf;
    2013     pThis->IMediaExPort.pfnIoReqStateChanged   = drvdiskintIoReqStateChanged;
     2025    pThis->IMediaExPort.pfnIoReqCompleteNotify     = drvdiskintIoReqCompleteNotify;
     2026    pThis->IMediaExPort.pfnIoReqCopyFromBuf        = drvdiskintIoReqCopyFromBuf;
     2027    pThis->IMediaExPort.pfnIoReqCopyToBuf          = drvdiskintIoReqCopyToBuf;
     2028    pThis->IMediaExPort.pfnIoReqQueryDiscardRanges = drvdiskintIoReqQueryDiscardRanges;
     2029    pThis->IMediaExPort.pfnIoReqStateChanged       = drvdiskintIoReqStateChanged;
    20142030
    20152031    /* Query the media port interface above us. */
  • trunk/src/VBox/Devices/Storage/DrvRamDisk.cpp

    r63724 r63997  
    15241524 * @interface_method_impl{PDMIMEDIAEX,pfnIoReqDiscard}
    15251525 */
    1526 static DECLCALLBACK(int) drvramdiskIoReqDiscard(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq, PCRTRANGE paRanges, unsigned cRanges)
     1526static DECLCALLBACK(int) drvramdiskIoReqDiscard(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq, unsigned cRangesMax)
    15271527{
    15281528    PDRVRAMDISK pThis = RT_FROM_MEMBER(pInterface, DRVRAMDISK, IMediaEx);
     
    15361536        return VERR_PDM_MEDIAEX_IOREQ_INVALID_STATE;
    15371537
    1538     pIoReq->enmType  = PDMMEDIAEXIOREQTYPE_DISCARD;
    1539     pIoReq->tsSubmit = RTTimeMilliTS();
    1540     /* Copy the ranges over because they might not be valid anymore when this method returns. */
    1541     pIoReq->Discard.paRanges = (PRTRANGE)RTMemDup(paRanges, cRanges * sizeof(RTRANGE));
     1538    /* Copy the ranges over now, this can be optimized in the future. */
     1539    pIoReq->Discard.paRanges = (PRTRANGE)RTMemAllocZ(cRangesMax * sizeof(RTRANGE));
    15421540    if (RT_UNLIKELY(!pIoReq->Discard.paRanges))
    15431541        return VERR_NO_MEMORY;
    15441542
    1545     bool fXchg = ASMAtomicCmpXchgU32((volatile uint32_t *)&pIoReq->enmState, VDIOREQSTATE_ACTIVE, VDIOREQSTATE_ALLOCATED);
    1546     if (RT_UNLIKELY(!fXchg))
    1547     {
    1548         /* Must have been canceled inbetween. */
    1549         Assert(pIoReq->enmState == VDIOREQSTATE_CANCELED);
    1550         return VERR_PDM_MEDIAEX_IOREQ_CANCELED;
    1551     }
    1552 
    1553     ASMAtomicIncU32(&pThis->cIoReqsActive);
    1554 
    1555     return RTReqQueueCallEx(pThis->hReqQ, NULL, 0, RTREQFLAGS_NO_WAIT,
    1556                             (PFNRT)drvramdiskIoReqDiscardWorker, 2, pThis, pIoReq);
     1543    int rc = pThis->pDrvMediaExPort->pfnIoReqQueryDiscardRanges(pThis->pDrvMediaExPort, pIoReq, &pIoReq->abAlloc[0],
     1544                                                                0, cRangesMax, pIoReq->Discard.paRanges,
     1545                                                                &pIoReq->Discard.cRanges);
     1546    if (RT_SUCCESS(rc))
     1547    {
     1548        pIoReq->enmType  = PDMMEDIAEXIOREQTYPE_DISCARD;
     1549        pIoReq->tsSubmit = RTTimeMilliTS();
     1550
     1551        bool fXchg = ASMAtomicCmpXchgU32((volatile uint32_t *)&pIoReq->enmState, VDIOREQSTATE_ACTIVE, VDIOREQSTATE_ALLOCATED);
     1552        if (RT_UNLIKELY(!fXchg))
     1553        {
     1554            /* Must have been canceled inbetween. */
     1555            Assert(pIoReq->enmState == VDIOREQSTATE_CANCELED);
     1556            return VERR_PDM_MEDIAEX_IOREQ_CANCELED;
     1557        }
     1558
     1559        ASMAtomicIncU32(&pThis->cIoReqsActive);
     1560
     1561        rc = RTReqQueueCallEx(pThis->hReqQ, NULL, 0, RTREQFLAGS_NO_WAIT,
     1562                              (PFNRT)drvramdiskIoReqDiscardWorker, 2, pThis, pIoReq);
     1563    }
     1564
     1565    return rc;
    15571566}
    15581567
  • trunk/src/VBox/Devices/Storage/DrvSCSI.cpp

    r63992 r63997  
    251251
    252252            pThis->pLed->Asserted.s.fWriting = pThis->pLed->Actual.s.fWriting = 1;
    253             rc = pThis->pDrvMediaEx->pfnIoReqDiscard(pThis->pDrvMediaEx, hIoReq, paRanges, cRanges);
     253            rc = pThis->pDrvMediaEx->pfnIoReqDiscard(pThis->pDrvMediaEx, hIoReq, cRanges);
    254254            if (   RT_FAILURE(rc)
    255255                && pThis->cErrors++ < MAX_LOG_REL_ERRORS)
     
    481481
    482482/**
     483 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqQueryDiscardRanges}
     484 */
     485static DECLCALLBACK(int) drvscsiIoReqQueryDiscardRanges(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq,
     486                                                        void *pvIoReqAlloc, uint32_t idxRangeStart,
     487                                                        uint32_t cRanges, PRTRANGE paRanges,
     488                                                        uint32_t *pcRanges)
     489{
     490    RT_NOREF2(pInterface, hIoReq);
     491
     492    VSCSIIOREQ hVScsiIoReq = DRVSCSI_PDMMEDIAEXIOREQ_2_VSCSIIOREQ(pvIoReqAlloc);
     493    PCRTRANGE paRangesVScsi;
     494    unsigned cRangesVScsi;
     495
     496    int rc = VSCSIIoReqUnmapParamsGet(hVScsiIoReq, &paRangesVScsi, &cRangesVScsi);
     497    if (RT_SUCCESS(rc))
     498    {
     499        uint32_t cRangesCopy = RT_MIN(cRangesVScsi - idxRangeStart, cRanges);
     500        Assert(   idxRangeStart < cRangesVScsi
     501               && (idxRangeStart + cRanges) <= cRangesVScsi);
     502
     503        memcpy(paRanges, &paRangesVScsi[idxRangeStart], cRangesCopy * sizeof(RTRANGE));
     504        *pcRanges = cRangesCopy;
     505    }
     506    return rc;
     507}
     508
     509/**
    483510 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqStateChanged}
    484511 */
     
    778805    pThis->IPortEx.pfnIoReqCopyFromBuf          = drvscsiIoReqCopyFromBuf;
    779806    pThis->IPortEx.pfnIoReqCopyToBuf            = drvscsiIoReqCopyToBuf;
     807    pThis->IPortEx.pfnIoReqQueryDiscardRanges   = drvscsiIoReqQueryDiscardRanges;
    780808    pThis->IPortEx.pfnIoReqStateChanged         = drvscsiIoReqStateChanged;
    781809
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r63991 r63997  
    37183718 * @interface_method_impl{PDMIMEDIAEX,pfnIoReqDiscard}
    37193719 */
    3720 static DECLCALLBACK(int) drvvdIoReqDiscard(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq, PCRTRANGE paRanges, unsigned cRanges)
     3720static DECLCALLBACK(int) drvvdIoReqDiscard(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq, unsigned cRangesMax)
    37213721{
    37223722    PVBOXDISK pThis = RT_FROM_MEMBER(pInterface, VBOXDISK, IMediaEx);
     
    37303730        return VERR_PDM_MEDIAEX_IOREQ_INVALID_STATE;
    37313731
    3732     pIoReq->enmType  = PDMMEDIAEXIOREQTYPE_DISCARD;
    3733     pIoReq->tsSubmit = RTTimeMilliTS();
    3734     /* Copy the ranges over because they might not be valid anymore when this method returns. */
    3735     pIoReq->Discard.paRanges = (PRTRANGE)RTMemDup(paRanges, cRanges * sizeof(RTRANGE));
     3732    /* Copy the ranges over now, this can be optimized in the future. */
     3733    pIoReq->Discard.paRanges = (PRTRANGE)RTMemAllocZ(cRangesMax * sizeof(RTRANGE));
    37363734    if (RT_UNLIKELY(!pIoReq->Discard.paRanges))
    37373735        return VERR_NO_MEMORY;
    37383736
    3739     bool fXchg = ASMAtomicCmpXchgU32((volatile uint32_t *)&pIoReq->enmState, VDIOREQSTATE_ACTIVE, VDIOREQSTATE_ALLOCATED);
    3740     if (RT_UNLIKELY(!fXchg))
    3741     {
    3742         /* Must have been canceled inbetween. */
    3743         Assert(pIoReq->enmState == VDIOREQSTATE_CANCELED);
    3744         return VERR_PDM_MEDIAEX_IOREQ_CANCELED;
    3745     }
    3746 
    3747     ASMAtomicIncU32(&pThis->cIoReqsActive);
    3748     int rc = drvvdMediaExIoReqDiscardWrapper(pThis, pIoReq);
    3749     if (rc == VERR_VD_ASYNC_IO_IN_PROGRESS)
    3750         rc = VINF_PDM_MEDIAEX_IOREQ_IN_PROGRESS;
    3751     else if (rc == VINF_VD_ASYNC_IO_FINISHED)
    3752         rc = VINF_SUCCESS;
    3753 
    3754     if (rc != VINF_PDM_MEDIAEX_IOREQ_IN_PROGRESS)
    3755         rc = drvvdMediaExIoReqCompleteWorker(pThis, pIoReq, rc, false /* fUpNotify */);
     3737    int rc = pThis->pDrvMediaExPort->pfnIoReqQueryDiscardRanges(pThis->pDrvMediaExPort, pIoReq, &pIoReq->abAlloc[0],
     3738                                                                0, cRangesMax, pIoReq->Discard.paRanges,
     3739                                                                &pIoReq->Discard.cRanges);
     3740    if (RT_SUCCESS(rc))
     3741    {
     3742        pIoReq->enmType  = PDMMEDIAEXIOREQTYPE_DISCARD;
     3743        pIoReq->tsSubmit = RTTimeMilliTS();
     3744        bool fXchg = ASMAtomicCmpXchgU32((volatile uint32_t *)&pIoReq->enmState, VDIOREQSTATE_ACTIVE, VDIOREQSTATE_ALLOCATED);
     3745        if (RT_UNLIKELY(!fXchg))
     3746        {
     3747            /* Must have been canceled inbetween. */
     3748            Assert(pIoReq->enmState == VDIOREQSTATE_CANCELED);
     3749            return VERR_PDM_MEDIAEX_IOREQ_CANCELED;
     3750        }
     3751
     3752        ASMAtomicIncU32(&pThis->cIoReqsActive);
     3753        rc = drvvdMediaExIoReqDiscardWrapper(pThis, pIoReq);
     3754        if (rc == VERR_VD_ASYNC_IO_IN_PROGRESS)
     3755            rc = VINF_PDM_MEDIAEX_IOREQ_IN_PROGRESS;
     3756        else if (rc == VINF_VD_ASYNC_IO_FINISHED)
     3757            rc = VINF_SUCCESS;
     3758
     3759        if (rc != VINF_PDM_MEDIAEX_IOREQ_IN_PROGRESS)
     3760            rc = drvvdMediaExIoReqCompleteWorker(pThis, pIoReq, rc, false /* fUpNotify */);
     3761    }
    37563762
    37573763    return rc;
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