VirtualBox

Ignore:
Timestamp:
Sep 27, 2011 9:07:07 AM (13 years ago)
Author:
vboxsync
Message:

PDM,Devices,Drivers: Add async discard API and make us of it

File:
1 edited

Legend:

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

    r38622 r38878  
    560560    PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
    561561
    562     int rc = drvvdAsyncIOFlushSync(pvUser, pStorage);
    563     if (RT_SUCCESS(rc))
    564         rc = PDMR3AsyncCompletionEpSetSize(pStorageBackend->pEndpoint, cbSize);
    565 
    566     return rc;
     562    return PDMR3AsyncCompletionEpSetSize(pStorageBackend->pEndpoint, cbSize);
    567563}
    568564
     
    16741670}
    16751671
    1676 static DECLCALLBACK(int) drvvdDiscard(PPDMIMEDIA pInterface, PPDMRANGE paRanges, unsigned cRanges)
     1672static DECLCALLBACK(int) drvvdDiscard(PPDMIMEDIA pInterface, PCRTRANGE paRanges, unsigned cRanges)
    16771673{
    16781674    LogFlowFunc(("\n"));
    16791675    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    16801676
    1681     /** @todo: Fix the cast properly without allocating temporary memory (maybe move the type to IPRT). */
    1682     int rc = VDDiscardRanges(pThis->pDisk, (PVDRANGE)paRanges, cRanges);
     1677    int rc = VDDiscardRanges(pThis->pDisk, paRanges, cRanges);
    16831678    LogFlowFunc(("returns %Rrc\n", rc));
    16841679    return rc;
     
    17731768    {
    17741769        rc = PDMR3BlkCacheFlush(pThis->pBlkCache, pvUser);
     1770        if (rc == VINF_AIO_TASK_PENDING)
     1771            rc = VERR_VD_ASYNC_IO_IN_PROGRESS;
     1772        else if (rc == VINF_SUCCESS)
     1773            rc = VINF_VD_ASYNC_IO_FINISHED;
     1774    }
     1775    LogFlowFunc(("returns %Rrc\n", rc));
     1776    return rc;
     1777}
     1778
     1779static DECLCALLBACK(int) drvvdStartDiscard(PPDMIMEDIAASYNC pInterface, PCRTRANGE paRanges,
     1780                                           unsigned cRanges, void *pvUser)
     1781{
     1782    int rc = VINF_SUCCESS;
     1783    PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
     1784
     1785    LogFlowFunc(("paRanges=%#p cRanges=%u pvUser=%#p\n",
     1786                 paRanges, cRanges, pvUser));
     1787
     1788    if (!pThis->pBlkCache)
     1789        rc = VDAsyncDiscardRanges(pThis->pDisk, paRanges, cRanges, drvvdAsyncReqComplete,
     1790                                  pThis, pvUser);
     1791    else
     1792    {
     1793        rc = PDMR3BlkCacheDiscard(pThis->pBlkCache, paRanges, cRanges, pvUser);
    17751794        if (rc == VINF_AIO_TASK_PENDING)
    17761795            rc = VERR_VD_ASYNC_IO_IN_PROGRESS;
     
    18181837            rc = VERR_INVALID_PARAMETER;
    18191838    }
     1839
     1840    if (rc == VINF_VD_ASYNC_IO_FINISHED)
     1841        PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, VINF_SUCCESS);
     1842    else if (RT_FAILURE(rc) && rc != VERR_VD_ASYNC_IO_IN_PROGRESS)
     1843        PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, rc);
     1844
     1845    return VINF_SUCCESS;
     1846}
     1847
     1848/** @copydoc FNPDMBLKCACHEXFERENQUEUEDISCARDDRV */
     1849static int drvvdBlkCacheXferEnqueueDiscard(PPDMDRVINS pDrvIns, PCRTRANGE paRanges,
     1850                                           unsigned cRanges, PPDMBLKCACHEIOXFER hIoXfer)
     1851{
     1852    int rc = VINF_SUCCESS;
     1853    PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
     1854
     1855    rc = VDAsyncDiscardRanges(pThis->pDisk, paRanges, cRanges,
     1856                              drvvdAsyncReqComplete, pThis, hIoXfer);
    18201857
    18211858    if (rc == VINF_VD_ASYNC_IO_FINISHED)
     
    20762113    pThis->IMediaAsync.pfnStartWrite      = drvvdStartWrite;
    20772114    pThis->IMediaAsync.pfnStartFlush      = drvvdStartFlush;
     2115    pThis->IMediaAsync.pfnStartDiscard    = drvvdStartDiscard;
    20782116
    20792117    /* Initialize supported VD interfaces. */
     
    25752613
    25762614        if (!fDiscard)
     2615        {
    25772616            pThis->IMedia.pfnDiscard = NULL;
     2617            pThis->IMediaAsync.pfnStartDiscard = NULL;
     2618        }
    25782619
    25792620        if (RT_SUCCESS(rc))
     
    26662707    if (   fUseBlockCache
    26672708        && !pThis->fShareable
     2709        && !fDiscard
    26682710        && RT_SUCCESS(rc))
    26692711    {
     
    26952737                                             drvvdBlkCacheXferComplete,
    26962738                                             drvvdBlkCacheXferEnqueue,
     2739                                             drvvdBlkCacheXferEnqueueDiscard,
    26972740                                             pszId);
    26982741                if (rc == VERR_NOT_SUPPORTED)
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