VirtualBox

Changeset 6312 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 9, 2008 10:25:55 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27189
Message:

remove functions from PDMIMEDIAASYNC and PCMIBLOCKASYNC. PDMIMEDIA and PDMIBLOCK are mandatory now and the async versions are optional extensions which can be implemented. Removed duplicated code

File:
1 edited

Legend:

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

    r6291 r6312  
    9595    PDMIMOUNT               IMount;
    9696
     97    /** Pointer to the async media driver below us.
     98     * This is NULL if the media is not mounted. */
     99    PPDMIMEDIAASYNC         pDrvMediaAsync;
     100    /** Our media async port. */
     101    PDMIMEDIAASYNCPORT      IMediaAsyncPort;
     102    /** Pointer to the async block port interface above us. */
     103    PPDMIBLOCKASYNCPORT     pDrvBlockAsyncPort;
     104    /** Our async block interface. */
     105    PDMIBLOCKASYNC          IBlockAsync;
     106
    97107    /** Uuid of the drive. */
    98108    RTUUID                  Uuid;
     
    109119/** Makes a PDRVBLOCK out of a PPDMIBLOCK. */
    110120#define PDMIBLOCK_2_DRVBLOCK(pInterface)        ( (PDRVBLOCK)((uintptr_t)pInterface - RT_OFFSETOF(DRVBLOCK, IBlock)) )
    111 
    112121
    113122/** @copydoc PDMIBLOCK::pfnRead */
     
    241250}
    242251
     252/* -=-=-=-=- IBlockAsync -=-=-=-=- */
     253
     254/** Makes a PDRVBLOCK out of a PPDMIBLOCKASYNC. */
     255#define PDMIBLOCKASYNC_2_DRVBLOCK(pInterface)        ( (PDRVBLOCK)((uintptr_t)pInterface - RT_OFFSETOF(DRVBLOCK, IBlockAsync)) )
     256
     257/** @copydoc PDMIBLOCKASYNC::pfnRead */
     258static DECLCALLBACK(int) drvblockAsyncReadStart(PPDMIBLOCKASYNC pInterface, uint64_t off, void *pvBuf, size_t cbRead, void *pvUser)
     259{
     260    PDRVBLOCK pData = PDMIBLOCKASYNC_2_DRVBLOCK(pInterface);
     261
     262    /*
     263     * Check the state.
     264     */
     265    if (!pData->pDrvMediaAsync)
     266    {
     267        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     268        return VERR_PDM_MEDIA_NOT_MOUNTED;
     269    }
     270
     271    int rc = pData->pDrvMediaAsync->pfnStartRead(pData->pDrvMediaAsync, off, pvBuf, cbRead, pvUser);
     272    return rc;
     273}
     274
     275
     276/** @copydoc PDMIBLOCKASYNC::pfnWrite */
     277static DECLCALLBACK(int) drvblockAsyncWriteStart(PPDMIBLOCKASYNC pInterface, uint64_t off, const void *pvBuf, size_t cbWrite, void *pvUser)
     278{
     279    PDRVBLOCK pData = PDMIBLOCKASYNC_2_DRVBLOCK(pInterface);
     280
     281    /*
     282     * Check the state.
     283     */
     284    if (!pData->pDrvMediaAsync)
     285    {
     286        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     287        return VERR_PDM_MEDIA_NOT_MOUNTED;
     288    }
     289
     290    int rc = pData->pDrvMediaAsync->pfnStartWrite(pData->pDrvMediaAsync, off, pvBuf, cbWrite, pvUser);
     291
     292    return rc;
     293}
     294
     295/* -=-=-=-=- IMediaAsyncPort -=-=-=-=- */
     296
     297/** Makes a PDRVBLOCKASYNC out of a PPDMIMEDIAASYNCPORT. */
     298#define PDMIMEDIAASYNCPORT_2_DRVBLOCK(pInterface)    ( (PDRVBLOCK((uintptr_t)pInterface - RT_OFFSETOF(DRVBLOCK, IMediaAsyncPort))) )
     299
     300
     301static DECLCALLBACK(int) drvblockAsyncReadCompleteNotify(PPDMIMEDIAASYNCPORT pInterface, uint64_t uOffset, void *pvBuf, size_t cbRead, void *pvUser)
     302{
     303    PDRVBLOCK pData = PDMIMEDIAASYNCPORT_2_DRVBLOCK(pInterface);
     304
     305    return pData->pDrvBlockAsyncPort->pfnReadCompleteNotify(pData->pDrvBlockAsyncPort, uOffset, pvBuf, cbRead, pvUser);
     306}
     307
     308static DECLCALLBACK(int) drvblockAsyncWriteCompleteNotify(PPDMIMEDIAASYNCPORT pInterface, uint64_t uOffset, void *pvBuf, size_t cbWritten, void *pvUser)
     309{
     310    PDRVBLOCK pData = PDMIMEDIAASYNCPORT_2_DRVBLOCK(pInterface);
     311
     312#ifdef VBOX_PERIODIC_FLUSH
     313    if (pData->cbFlushInterval)
     314    {
     315        pData->cbDataWritten += cbWritten;
     316        if (pData->cbDataWritten > pData->cbFlushInterval)
     317        {
     318            pData->cbDataWritten = 0;
     319            pData->pDrvMedia->pfnFlush(pData->pDrvMedia);
     320        }
     321    }
     322#endif /* VBOX_PERIODIC_FLUSH */
     323
     324    return pData->pDrvBlockAsyncPort->pfnWriteCompleteNotify(pData->pDrvBlockAsyncPort, uOffset, pvBuf, cbWritten, pvUser);
     325}
    243326
    244327/* -=-=-=-=- IBlockBios -=-=-=-=- */
     
    275358     */
    276359    int rc = pData->pDrvMedia->pfnBiosGetPCHSGeometry(pData->pDrvMedia, &pData->PCHSGeometry);
     360
    277361    if (VBOX_SUCCESS(rc))
    278362    {
     
    308392     */
    309393    int rc = pData->pDrvMedia->pfnBiosSetPCHSGeometry(pData->pDrvMedia, pPCHSGeometry);
     394
    310395    if (    VBOX_SUCCESS(rc)
    311396        ||  rc == VERR_NOT_IMPLEMENTED)
     
    345430     */
    346431    int rc = pData->pDrvMedia->pfnBiosGetLCHSGeometry(pData->pDrvMedia, &pData->LCHSGeometry);
     432
    347433    if (VBOX_SUCCESS(rc))
    348434    {
     
    378464     */
    379465    int rc = pData->pDrvMedia->pfnBiosSetLCHSGeometry(pData->pDrvMedia, pLCHSGeometry);
     466
    380467    if (    VBOX_SUCCESS(rc)
    381468        ||  rc == VERR_NOT_IMPLEMENTED)
     
    584671        case PDMINTERFACE_MOUNT:
    585672            return pData->fMountable ? &pData->IMount : NULL;
     673        case PDMINTERFACE_BLOCK_ASYNC:
     674            return pData->pDrvMediaAsync ? &pData->IBlockAsync : NULL;
     675        case PDMINTERFACE_MEDIA_ASYNC_PORT:
     676            return &pData->IMediaAsyncPort;
    586677        default:
    587678            return NULL;
     
    597688    PDRVBLOCK pData = PDMINS2DATA(pDrvIns, PDRVBLOCK);
    598689    pData->pDrvMedia = NULL;
     690    pData->pDrvMediaAsync = NULL;
    599691}
    600692
     
    658750    pData->IMount.pfnIsLocked               = drvblockIsLocked;
    659751
     752    /* IBlockAsync. */
     753    pData->IBlockAsync.pfnStartRead         = drvblockAsyncReadStart;
     754    pData->IBlockAsync.pfnStartWrite        = drvblockAsyncWriteStart;
     755
     756    /* IMediaAsyncPort. */
     757    pData->IMediaAsyncPort.pfnReadCompleteNotify  = drvblockAsyncReadCompleteNotify;
     758    pData->IMediaAsyncPort.pfnWriteCompleteNotify = drvblockAsyncWriteCompleteNotify;
     759
    660760    /*
    661761     * Get the IBlockPort & IMountNotify interfaces of the above driver/device.
     
    667767        return VERR_PDM_MISSING_INTERFACE_ABOVE;
    668768    }
     769
     770    /* Try to get the optional async block port interface above. */
     771    pData->pDrvBlockAsyncPort = (PPDMIBLOCKASYNCPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_BLOCK_ASYNC_PORT);
     772
    669773    pData->pDrvMountNotify = (PPDMIMOUNTNOTIFY)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_MOUNT_NOTIFY);
    670774
     
    826930    if (!pData->pDrvMedia)
    827931    {
    828         AssertMsgFailed(("Configuration error: No media interface below!\n"));
    829         return VERR_PDM_MISSING_INTERFACE_BELOW;
    830     }
     932            AssertMsgFailed(("Configuration error: No media or async media interface below!\n"));
     933            return VERR_PDM_MISSING_INTERFACE_BELOW;
     934    }
     935
     936    /* Try to get the optional async interface. */
     937    pData->pDrvMediaAsync = (PPDMIMEDIAASYNC)pBase->pfnQueryInterface(pBase, PDMINTERFACE_MEDIA_ASYNC);
     938
    831939    if (RTUuidIsNull(&pData->Uuid))
    832940    {
Note: See TracChangeset for help on using the changeset viewer.

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