DrvVD.cpp revision aa834e89e076db44fa8fe82d177748f0a45d14c2
77b1a2d8b5dbe2c0b5200794914239fee3c8ee5dvboxsync * DrvVD - Generic VBox disk media driver.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2010 Oracle Corporation
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * available from http://www.virtualbox.org. This file is free software;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/*******************************************************************************
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync* Header files *
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync*******************************************************************************/
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync/* All lwip header files are not C++ safe. So hack around this. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#endif /* VBOX_WITH_INIP */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/* Small hack to get at lwIP initialized status */
efff36b306e370346025647a158689021df2e1d1vboxsyncextern bool DevINIPConfigured(void);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync#endif /* VBOX_WITH_INIP */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/*******************************************************************************
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync* Defined types, constants and macros *
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync*******************************************************************************/
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** Converts a pointer to VBOXDISK::IMedia to a PVBOXDISK. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync ( (PVBOXDISK)((uintptr_t)pInterface - RT_OFFSETOF(VBOXDISK, IMedia)) )
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** Converts a pointer to PDMDRVINS::IBase to a PPDMDRVINS. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync ( (PPDMDRVINS)((uintptr_t)pInterface - RT_OFFSETOF(PDMDRVINS, IBase)) )
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** Converts a pointer to PDMDRVINS::IBase to a PVBOXDISK. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync ( PDMINS_2_DATA(PDMIBASE_2_DRVINS(pInterface), PVBOXDISK) )
9496f2d398b49813176939d7a339ae513d5175efvboxsync/** Converts a pointer to VBOXDISK::IMediaAsync to a PVBOXDISK. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync ( (PVBOXDISK)((uintptr_t)pInterface - RT_OFFSETOF(VBOXDISK, IMediaAsync)) )
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * VBox disk container, image information, private part.
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsynctypedef struct VBOXIMAGE
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Pointer to next image. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Pointer to list of VD interfaces. Per-image. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Common structure for the configuration information interface. */
c0a370e600bb60153a269fb32b5f709347c35768vboxsync /** Common structure for the supported TCP network stack interface. */
c0a370e600bb60153a269fb32b5f709347c35768vboxsync /** Common structure for the supported I/O interface. */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync * Storage backend data.
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /** PDM async completion end point. */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /** The template. */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /** Event semaphore for synchronous operations. */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /** Flag whether a synchronous operation is currently pending. */
7766bf675357fd940d8c49e69a5d72dc6eaa6be4vboxsync volatile bool fSyncIoPending;
7766bf675357fd940d8c49e69a5d72dc6eaa6be4vboxsync /** Return code of the last completed request. */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /** Callback routine */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * VBox disk container media main structure, private part.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMIMEDIA
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMIMEDIAASYNC
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements VDINTERFACEERROR
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements VDINTERFACETCPNET
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements VDINTERFACEASYNCIO
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * @implements VDINTERFACECONFIG
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsynctypedef struct VBOXDISK
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** The VBox disk container. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** The media interface. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Media port. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Pointer to the driver instance. */
21029597fc4b76d0db0c9542daee201447281781vboxsync /** Flag whether suspend has changed image open mode to read only. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Flag whether to use the runtime (true) or startup error facility. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Pointer to list of VD interfaces. Per-disk. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Common structure for the supported error interface. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Callback table for error interface. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Common structure for the supported thread synchronization interface. */
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync /** Callback table for thread synchronization interface. */
c0a370e600bb60153a269fb32b5f709347c35768vboxsync /** Callback table for the configuration information interface. */
c0a370e600bb60153a269fb32b5f709347c35768vboxsync /** Callback table for TCP network stack interface. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Callback table for I/O interface. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Flag whether opened disk supports async I/O operations. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** The async media interface. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** The async media port interface above. */
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync /** Pointer to the list of data we need to keep per image. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Flag whether the media should allow concurrent open for writing. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Flag whether a merge operation has been set up. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Synchronization to prevent destruction before merge finishes. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Synchronization between merge and other image accesses. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Source image index for merging. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /** Target image index for merging. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /** Flag whether boot acceleration is enabled. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /** Flag whether boot acceleration is currently active. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /** Size of the disk, used for read truncation. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /** Size of the configured buffer. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /** Start offset for which the buffer holds data. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /** Number of valid bytes in the buffer. */
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync /** The disk buffer. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /** Bandwidth group the disk is assigned to. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /** Flag whether async I/O using the host cache is enabled. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /** I/O interface for a cache image. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Interface list for the cache image. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** The block cache handle if configured. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync/*******************************************************************************
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync* Internal Functions *
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync*******************************************************************************/
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * Internal: allocate new image descriptor and put it in the list
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync PVBOXIMAGE pImage = (PVBOXIMAGE)RTMemAllocZ(sizeof(VBOXIMAGE));
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Internal: free the list of images descriptors.
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Make the image temporarily read-only.
16a9adc14900ca18e6909679a579f6833425e030vboxsync * @returns VBox status code.
16a9adc14900ca18e6909679a579f6833425e030vboxsync * @param pThis The driver instance data.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDGetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, &uOpenFlags);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDSetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, uOpenFlags);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * Undo the temporary read-only status of the image.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @returns VBox status code.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @param pThis The driver instance data.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDGetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, &uOpenFlags);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDSetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, uOpenFlags);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/*******************************************************************************
a9d49c8f2b28a72e6a4db86eee91e4569290157bvboxsync* Error reporting callback *
a9d49c8f2b28a72e6a4db86eee91e4569290157bvboxsync*******************************************************************************/
a9d49c8f2b28a72e6a4db86eee91e4569290157bvboxsyncstatic void drvvdErrorCallback(void *pvUser, int rc, RT_SRC_POS_DECL,
9496f2d398b49813176939d7a339ae513d5175efvboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
9496f2d398b49813176939d7a339ae513d5175efvboxsync /* We must not pass VMSETRTERR_FLAGS_FATAL as it could lead to a
59d7f5939d42ad9d344fbad8401e00a900db92c5vboxsync * deadlock: We are probably executed in a thread context != EMT
59d7f5939d42ad9d344fbad8401e00a900db92c5vboxsync * and the EM thread would wait until every thread is suspended
22ec733a5e041fcdfe02fce2eafc9faf8b0077ddvboxsync * but we would wait for the EM thread ... */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDMDrvHlpVMSetRuntimeErrorV(pDrvIns, /* fFlags=*/ 0, "DrvVD", pszFormat, va);
9496f2d398b49813176939d7a339ae513d5175efvboxsync PDMDrvHlpVMSetErrorV(pDrvIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/*******************************************************************************
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync* VD Async I/O interface implementation *
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync*******************************************************************************/
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(void) drvvdAsyncTaskCompleted(PPDMDRVINS pDrvIns, void *pvTemplateUser, void *pvUser, int rcReq)
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pvTemplateUser;
5d0d754550d06b7d59a935e59caaf814462d53ccvboxsync LogFlowFunc(("pDrvIns=%#p pvTemplateUser=%#p pvUser=%#p rcReq=%d\n",
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOOpen(void *pvUser, const char *pszLocation,
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)RTMemAllocZ(sizeof(DRVVDSTORAGEBACKEND));
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync rc = PDMDrvHlpAsyncCompletionTemplateCreate(pThis->pDrvIns, &pStorageBackend->pTemplate,
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync drvvdAsyncTaskCompleted, pStorageBackend, "AsyncTaskCompleted");
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync uint32_t fFlags = (fOpen & RTFILE_O_ACCESS_MASK) == RTFILE_O_READ
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync Assert((fOpen & RTFILE_O_DENY_MASK) == RTFILE_O_DENY_NONE);
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync rc = PDMR3AsyncCompletionEpCreateForFile(&pStorageBackend->pEndpoint,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync rc = PDMR3AsyncCompletionEpSetBwMgr(pStorageBackend->pEndpoint, pThis->pszBwGroup);
9496f2d398b49813176939d7a339ae513d5175efvboxsync PDMR3AsyncCompletionEpClose(pStorageBackend->pEndpoint);
16a9adc14900ca18e6909679a579f6833425e030vboxsync PDMR3AsyncCompletionTemplateDestroy(pStorageBackend->pTemplate);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOClose(void *pvUser, void *pStorage)
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDMR3AsyncCompletionEpClose(pStorageBackend->pEndpoint);
9496f2d398b49813176939d7a339ae513d5175efvboxsync PDMR3AsyncCompletionTemplateDestroy(pStorageBackend->pTemplate);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOReadSync(void *pvUser, void *pStorage, uint64_t uOffset,
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync int rc = PDMR3AsyncCompletionEpRead(pStorageBackend->pEndpoint, uOffset, &DataSeg, 1, cbRead, NULL, &pTask);
9496f2d398b49813176939d7a339ae513d5175efvboxsync rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOWriteSync(void *pvUser, void *pStorage, uint64_t uOffset,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync const void *pvBuf, size_t cbWrite, size_t *pcbWritten)
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync int rc = PDMR3AsyncCompletionEpWrite(pStorageBackend->pEndpoint, uOffset, &DataSeg, 1, cbWrite, NULL, &pTask);
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
9496f2d398b49813176939d7a339ae513d5175efvboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOFlushSync(void *pvUser, void *pStorage)
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync LogFlowFunc(("pvUser=%#p pStorage=%#p\n", pvUser, pStorage));
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
7766bf675357fd940d8c49e69a5d72dc6eaa6be4vboxsync int rc = PDMR3AsyncCompletionEpFlush(pStorageBackend->pEndpoint, NULL, &pTask);
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOReadAsync(void *pvUser, void *pStorage, uint64_t uOffset,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync int rc = PDMR3AsyncCompletionEpRead(pStorageBackend->pEndpoint, uOffset, paSegments, cSegments, cbRead,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOWriteAsync(void *pvUser, void *pStorage, uint64_t uOffset,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync int rc = PDMR3AsyncCompletionEpWrite(pStorageBackend->pEndpoint, uOffset, paSegments, cSegments, cbWrite,
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOFlushAsync(void *pvUser, void *pStorage,
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync int rc = PDMR3AsyncCompletionEpFlush(pStorageBackend->pEndpoint, pvCompletion,
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOGetSize(void *pvUser, void *pStorage, uint64_t *pcbSize)
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync return PDMR3AsyncCompletionEpGetSize(pStorageBackend->pEndpoint, pcbSize);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOSetSize(void *pvUser, void *pStorage, uint64_t cbSize)
16a9adc14900ca18e6909679a579f6833425e030vboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = PDMR3AsyncCompletionEpSetSize(pStorageBackend->pEndpoint, cbSize);
16a9adc14900ca18e6909679a579f6833425e030vboxsync#endif /* VBOX_WITH_PDM_ASYNC_COMPLETION */
16a9adc14900ca18e6909679a579f6833425e030vboxsync/*******************************************************************************
16a9adc14900ca18e6909679a579f6833425e030vboxsync* VD Thread Synchronization interface implementation *
16a9adc14900ca18e6909679a579f6833425e030vboxsync*******************************************************************************/
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdThreadStartRead(void *pvUser)
16a9adc14900ca18e6909679a579f6833425e030vboxsync return RTSemRWRequestRead(pThis->MergeLock, RT_INDEFINITE_WAIT);
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdThreadFinishRead(void *pvUser)
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdThreadStartWrite(void *pvUser)
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync return RTSemRWRequestWrite(pThis->MergeLock, RT_INDEFINITE_WAIT);
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsyncstatic DECLCALLBACK(int) drvvdThreadFinishWrite(void *pvUser)
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync/*******************************************************************************
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync* VD Configuration interface implementation *
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync*******************************************************************************/
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsyncstatic bool drvvdCfgAreKeysValid(void *pvUser, const char *pszzValid)
efff36b306e370346025647a158689021df2e1d1vboxsync return CFGMR3AreValuesValid((PCFGMNODE)pvUser, pszzValid);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic int drvvdCfgQuerySize(void *pvUser, const char *pszName, size_t *pcb)
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync return CFGMR3QuerySize((PCFGMNODE)pvUser, pszName, pcb);
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsyncstatic int drvvdCfgQuery(void *pvUser, const char *pszName, char *pszString, size_t cchString)
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync return CFGMR3QueryString((PCFGMNODE)pvUser, pszName, pszString, cchString);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/*******************************************************************************
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync* VD TCP network stack interface implementation - INIP case *
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync*******************************************************************************/
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsynctypedef struct INIPSOCKET
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPFlush(VDSOCKET Sock);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSocketCreate */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPSocketCreate(uint32_t fFlags, PVDSOCKET pSock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync * The extended select method is not supported because it is impossible to wakeup
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync * the thread.
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync if (fFlags & VD_INTERFACETCPNET_CONNECT_EXTENDED_SELECT)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync pSocketInt = (PINIPSOCKET)RTMemAllocZ(sizeof(INIPSOCKET));
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSocketCreate */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPSocketDestroy(VDSOCKET Sock)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnClientConnect */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* Check whether lwIP is set up in this VM instance. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* Resolve hostname. As there is no standard resolver for lwIP yet,
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * just accept numeric IP addresses for now. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync LogRelFunc(("cannot resolve IP %s\n", pszAddress));
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /* Create socket and connect. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync if (!lwip_connect(iSock, (struct sockaddr *)&InAddr, sizeof(InAddr)))
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = VERR_NET_CONNECTION_REFUSED; /* @todo real solution needed */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = VERR_NET_CONNECTION_REFUSED; /* @todo real solution needed */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnClientClose */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPClientClose(VDSOCKET Sock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return VINF_SUCCESS; /** @todo real solution needed */
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync/** @copydoc VDINTERFACETCPNET::pfnIsClientConnected */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(bool) drvvdINIPIsClientConnected(VDSOCKET Sock)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOne */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = lwip_select(pSocketInt->hSock + 1, &fdsetR, NULL, &fdsetE, NULL);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = lwip_select(pSocketInt->hSock + 1, &fdsetR, NULL, &fdsetE, &timeout);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution needed */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnRead */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* Do params checking */
59a2c1c0a4a0762b46bc5ff056f5705ec9c0a660vboxsync * Read loop.
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * If pcbRead is NULL we have to fill the entire buffer!
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /** @todo this clipping here is just in case (the send function
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * needed it, so I added it here, too). Didn't investigate if this
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * really has issues. Better be safe than sorry. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync ssize_t cbBytesRead = lwip_recv(pSocketInt->hSock, (char *)pvBuffer + cbRead,
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (cbBytesRead == 0 && errno) /** @todo r=bird: lwip_recv will not touch errno on Windows. This may apply to other hosts as well */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* return partial data */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* read more? */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnWrite */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /** @todo lwip send only supports up to 65535 bytes in a single
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * send (stupid limitation buried in the code), so make sure we
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * don't get any wraparounds. This should be moved to DevINIP
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync * stack interface once that's implemented. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync ssize_t cbWritten = lwip_send(pSocketInt->hSock, (void *)pvBuffer,
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution needed */
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync AssertMsg(cbBuffer >= (size_t)cbWritten, ("Wrote more than we requested!!! cbWritten=%d cbBuffer=%d\n",
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync/** @copydoc VDINTERFACETCPNET::pfnSgWrite */
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsyncstatic DECLCALLBACK(int) drvvdINIPSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf)
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync /* This is an extremely crude emulation, however it's good enough
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * for our iSCSI code. INIP has no sendmsg(). */
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync/** @copydoc VDINTERFACETCPNET::pfnFlush */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPFlush(VDSOCKET Sock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync lwip_setsockopt(pSocketInt->hSock, IPPROTO_TCP, TCP_NODELAY,
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync lwip_setsockopt(pSocketInt->hSock, IPPROTO_TCP, TCP_NODELAY,
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSetSendCoalescing */
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsyncstatic DECLCALLBACK(int) drvvdINIPSetSendCoalescing(VDSOCKET Sock, bool fEnable)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync lwip_setsockopt(pSocketInt->hSock, IPPROTO_TCP, TCP_NODELAY,
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetLocalAddress */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsyncstatic DECLCALLBACK(int) drvvdINIPGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync if (!lwip_getsockname(pSocketInt->hSock, &u.Addr, &cbAddr))
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync * Convert the address.
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetPeerAddress */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsyncstatic DECLCALLBACK(int) drvvdINIPGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync if (!lwip_getpeername(pSocketInt->hSock, &u.Addr, &cbAddr))
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync * Convert the address.
efff36b306e370346025647a158689021df2e1d1vboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOneEx */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPSelectOneEx(VDSOCKET Sock, uint32_t fEvents, uint32_t *pfEvents, RTMSINTERVAL cMillies)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnPoke */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPPoke(VDSOCKET Sock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync#endif /* VBOX_WITH_INIP */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/*******************************************************************************
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync* VD TCP network stack interface implementation - Host TCP case *
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync*******************************************************************************/
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync * Socket data.
51a01524909c95ee04b636218b6a89b29fb81825vboxsynctypedef struct VDSOCKETINT
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /** IPRT socket handle. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /** Pollset with the wakeup pipe and socket. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /** Pipe endpoint - read (in the pollset). */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /** Pipe endpoint - write. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /** Flag whether the thread was woken up. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync volatile bool fWokenUp;
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /** Flag whether the thread is waiting in the select call. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync volatile bool fWaiting;
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /** Old event mask. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** Pollset id of the socket. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** Pollset id of the pipe. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSocketCreate */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync pSockInt = (PVDSOCKETINT)RTMemAllocZ(sizeof(VDSOCKETINT));
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync if (fFlags & VD_INTERFACETCPNET_CONNECT_EXTENDED_SELECT)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /* Init pipe and pollset. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTPipeCreate(&pSockInt->hPipeR, &pSockInt->hPipeW, 0);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTPollSetAddPipe(pSockInt->hPollSet, pSockInt->hPipeR,
b0b15690f00527424b2d5fb88456d747252322f7vboxsync RTPollSetRemove(pSockInt->hPollSet, VDSOCKET_POLL_ID_PIPE);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSocketDestroy */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpSocketDestroy(VDSOCKET Sock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /* Destroy the pipe and pollset if necessary. */
a2f96875f61628e5a5fd33785f8c0bbb310f981fvboxsync rc = RTPollSetRemove(pSockInt->hPollSet, VDSOCKET_POLL_ID_SOCKET);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync Assert(RT_SUCCESS(rc) || rc == VERR_POLL_HANDLE_ID_NOT_FOUND);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTPollSetRemove(pSockInt->hPollSet, VDSOCKET_POLL_ID_PIPE);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTTcpClientCloseEx(pSockInt->hSocket, false /*fGracefulShutdown*/);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnClientConnect */
51a01524909c95ee04b636218b6a89b29fb81825vboxsyncstatic DECLCALLBACK(int) drvvdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort)
b0b15690f00527424b2d5fb88456d747252322f7vboxsync rc = RTTcpClientConnect(pszAddress, uPort, &pSockInt->hSocket);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /* Add to the pollset if required. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync pSockInt->fEventsOld = RTPOLL_EVT_READ | RTPOLL_EVT_WRITE | RTPOLL_EVT_ERROR;
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTPollSetAddSocket(pSockInt->hPollSet, pSockInt->hSocket,
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTTcpClientCloseEx(pSockInt->hSocket, false /*fGracefulShutdown*/);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnClientClose */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpClientClose(VDSOCKET Sock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTPollSetRemove(pSockInt->hPollSet, VDSOCKET_POLL_ID_SOCKET);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTTcpClientCloseEx(pSockInt->hSocket, false /*fGracefulShutdown*/);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnIsClientConnected */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(bool) drvvdTcpIsClientConnected(VDSOCKET Sock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOne */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpSelectOne(pSockInt->hSocket, cMillies);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnRead */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpRead(pSockInt->hSocket, pvBuffer, cbBuffer, pcbRead);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnWrite */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer)
51a01524909c95ee04b636218b6a89b29fb81825vboxsync return RTTcpWrite(pSockInt->hSocket, pvBuffer, cbBuffer);
51a01524909c95ee04b636218b6a89b29fb81825vboxsync/** @copydoc VDINTERFACETCPNET::pfnSgWrite */
51a01524909c95ee04b636218b6a89b29fb81825vboxsyncstatic DECLCALLBACK(int) drvvdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf)
51a01524909c95ee04b636218b6a89b29fb81825vboxsync/** @copydoc VDINTERFACETCPNET::pfnReadNB */
51a01524909c95ee04b636218b6a89b29fb81825vboxsyncstatic DECLCALLBACK(int) drvvdTcpReadNB(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead)
51a01524909c95ee04b636218b6a89b29fb81825vboxsync return RTTcpReadNB(pSockInt->hSocket, pvBuffer, cbBuffer, pcbRead);
51a01524909c95ee04b636218b6a89b29fb81825vboxsync/** @copydoc VDINTERFACETCPNET::pfnWriteNB */
51a01524909c95ee04b636218b6a89b29fb81825vboxsyncstatic DECLCALLBACK(int) drvvdTcpWriteNB(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer, size_t *pcbWritten)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpWriteNB(pSockInt->hSocket, pvBuffer, cbBuffer, pcbWritten);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSgWriteNB */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpSgWriteNB(VDSOCKET Sock, PRTSGBUF pSgBuf, size_t *pcbWritten)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpSgWriteNB(pSockInt->hSocket, pSgBuf, pcbWritten);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnFlush */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpFlush(VDSOCKET Sock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSetSendCoalescing */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpSetSendCoalescing(pSockInt->hSocket, fEnable);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetLocalAddress */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpGetLocalAddress(pSockInt->hSocket, pAddr);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetPeerAddress */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr)
217fa436516d137a409bb493cb7d350898f64666vboxsync return RTTcpGetPeerAddress(pSockInt->hSocket, pAddr);
51a01524909c95ee04b636218b6a89b29fb81825vboxsyncstatic int drvvdTcpSelectOneExPoll(VDSOCKET Sock, uint32_t fEvents,
51a01524909c95ee04b636218b6a89b29fb81825vboxsync rc = RTPollSetEventsChange(pSockInt->hPollSet, VDSOCKET_POLL_ID_SOCKET, fPollEvents);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTPoll(pSockInt->hPollSet, cMillies, &fEventsRecv, &id);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync Assert((fEventsRecv & RTPOLL_EVT_VALID_MASK) == RTPOLL_EVT_READ);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync /* We got interrupted, drain the pipe. */
b0b15690f00527424b2d5fb88456d747252322f7vboxsync rc = RTPipeRead(pSockInt->hPipeR, abBuf, sizeof(abBuf), &cbRead);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOneEx */
b0b15690f00527424b2d5fb88456d747252322f7vboxsyncstatic DECLCALLBACK(int) drvvdTcpSelectOneExNoPoll(VDSOCKET Sock, uint32_t fEvents,
b0b15690f00527424b2d5fb88456d747252322f7vboxsync * Only the pipe is configured or the caller doesn't wait for a socket event,
b0b15690f00527424b2d5fb88456d747252322f7vboxsync * wait until there is something to read from the pipe.
b0b15690f00527424b2d5fb88456d747252322f7vboxsync rc = RTPipeReadBlocking(pSockInt->hPipeR, &ch, 1, &cbRead);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync /* Make sure the socket is not in the pollset. */
b0b15690f00527424b2d5fb88456d747252322f7vboxsync rc = RTPollSetRemove(pSockInt->hPollSet, VDSOCKET_POLL_ID_SOCKET);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync Assert(RT_SUCCESS(rc) || rc == VERR_POLL_HANDLE_ID_NOT_FOUND);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync /* Check the socket. */
b0b15690f00527424b2d5fb88456d747252322f7vboxsync rc = RTTcpSelectOneEx(pSockInt->hSocket, fSelectEvents, &fEventsRecv, 0);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync break; /* Quit */
b0b15690f00527424b2d5fb88456d747252322f7vboxsync Assert((fEventsRecv & RTPOLL_EVT_VALID_MASK) == RTPOLL_EVT_READ);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync /* We got interrupted, drain the pipe. */
b0b15690f00527424b2d5fb88456d747252322f7vboxsync rc = RTPipeRead(pSockInt->hPipeR, abBuf, sizeof(abBuf), &cbRead);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync else /* The caller waits for a socket event. */
b0b15690f00527424b2d5fb88456d747252322f7vboxsync /* Loop until we got woken up or a socket event occurred. */
b0b15690f00527424b2d5fb88456d747252322f7vboxsync /** @todo find an adaptive wait algorithm based on the
b0b15690f00527424b2d5fb88456d747252322f7vboxsync * number of wakeups in the past. */
b0b15690f00527424b2d5fb88456d747252322f7vboxsync rc = RTTcpSelectOneEx(pSockInt->hSocket, fSelectEvents, &fEventsRecv, 5);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync /* Check if there is an event pending. */
b0b15690f00527424b2d5fb88456d747252322f7vboxsync rc = RTPipeRead(pSockInt->hPipeR, &ch, 1, &cbRead);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync break; /* Quit */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync break; /* Quit */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnPoke */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpPoke(VDSOCKET Sock)
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync rc = RTPipeWrite(pSockInt->hPipeW, "", 1, &cbWritten);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync/*******************************************************************************
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync* Media interface methods *
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync*******************************************************************************/
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync/** @copydoc PDMIMEDIA::pfnRead */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsyncstatic DECLCALLBACK(int) drvvdRead(PPDMIMEDIA pInterface,
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync LogFlowFunc(("off=%#llx pvBuf=%p cbRead=%d\n", off, pvBuf, cbRead));
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /* Can we serve the request from the buffer? */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync size_t cbToCopy = RT_MIN(cbRead, pThis->offDisk + pThis->cbDataValid - off);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync memcpy(pvBuf, pThis->pbData + (off - pThis->offDisk), cbToCopy);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /* Increase request to the buffer size and read. */
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync pThis->cbDataValid = RT_MIN(pThis->cbDisk - off, pThis->cbBootAccelBuffer);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = VDRead(pThis->pDisk, off, pThis->pbData, pThis->cbDataValid);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync Log2(("%s: off=%#llx pvBuf=%p cbRead=%d %.*Rhxd\n", __FUNCTION__,
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync/** @copydoc PDMIMEDIA::pfnWrite */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsyncstatic DECLCALLBACK(int) drvvdWrite(PPDMIMEDIA pInterface,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync LogFlowFunc(("off=%#llx pvBuf=%p cbWrite=%d\n", off, pvBuf, cbWrite));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync Log2(("%s: off=%#llx pvBuf=%p cbWrite=%d %.*Rhxd\n", __FUNCTION__,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* Invalidate any buffer if boot acceleration is enabled. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync int rc = VDWrite(pThis->pDisk, off, pvBuf, cbWrite);
16a9adc14900ca18e6909679a579f6833425e030vboxsync/** @copydoc PDMIMEDIA::pfnFlush */
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsyncstatic DECLCALLBACK(int) drvvdFlush(PPDMIMEDIA pInterface)
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
16a9adc14900ca18e6909679a579f6833425e030vboxsync/** @copydoc PDMIMEDIA::pfnMerge */
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdMerge(PPDMIMEDIA pInterface,
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* Note: There is an unavoidable race between destruction and another
16a9adc14900ca18e6909679a579f6833425e030vboxsync * thread invoking this function. This is handled safely and gracefully by
16a9adc14900ca18e6909679a579f6833425e030vboxsync * atomically invalidating the lock handle in drvvdDestruct. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync int rc2 = RTSemFastMutexRequest(pThis->MergeCompleteMutex);
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* Take shortcut: PFNSIMPLEPROGRESS is exactly the same type as
16a9adc14900ca18e6909679a579f6833425e030vboxsync * PFNVDPROGRESS, so there's no need for a conversion function. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** @todo maybe introduce a conversion which limits update frequency. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync VDIProgressCallbacks.cbSize = sizeof(VDINTERFACEPROGRESS);
16a9adc14900ca18e6909679a579f6833425e030vboxsync VDIProgressCallbacks.enmInterface = VDINTERFACETYPE_PROGRESS;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync rc2 = VDInterfaceAdd(&VDIProgress, "DrvVD_VDIProgress", VDINTERFACETYPE_PROGRESS,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc2 = RTSemFastMutexRelease(pThis->MergeCompleteMutex);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync/** @copydoc PDMIMEDIA::pfnGetSize */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsyncstatic DECLCALLBACK(uint64_t) drvvdGetSize(PPDMIMEDIA pInterface)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync uint64_t cb = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync/** @copydoc PDMIMEDIA::pfnIsReadOnly */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsyncstatic DECLCALLBACK(bool) drvvdIsReadOnly(PPDMIMEDIA pInterface)
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync/** @copydoc PDMIMEDIA::pfnBiosGetPCHSGeometry */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdBiosGetPCHSGeometry(PPDMIMEDIA pInterface,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync int rc = VDGetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync/** @copydoc PDMIMEDIA::pfnBiosSetPCHSGeometry */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdBiosSetPCHSGeometry(PPDMIMEDIA pInterface,
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync int rc = VDSetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync/** @copydoc PDMIMEDIA::pfnBiosGetLCHSGeometry */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(int) drvvdBiosGetLCHSGeometry(PPDMIMEDIA pInterface,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync int rc = VDGetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync/** @copydoc PDMIMEDIA::pfnBiosSetLCHSGeometry */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdBiosSetLCHSGeometry(PPDMIMEDIA pInterface,
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync int rc = VDSetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsync/** @copydoc PDMIMEDIA::pfnGetUuid */
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsyncstatic DECLCALLBACK(int) drvvdGetUuid(PPDMIMEDIA pInterface, PRTUUID pUuid)
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync LogFlowFunc(("returns %Rrc ({%RTuuid})\n", rc, pUuid));
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync/*******************************************************************************
9496f2d398b49813176939d7a339ae513d5175efvboxsync* Async Media interface methods *
9496f2d398b49813176939d7a339ae513d5175efvboxsync*******************************************************************************/
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsyncstatic void drvvdAsyncReqComplete(void *pvUser1, void *pvUser2, int rcReq)
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync int rc = pThis->pDrvMediaAsyncPort->pfnTransferCompleteNotify(pThis->pDrvMediaAsyncPort,
9496f2d398b49813176939d7a339ae513d5175efvboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, (PPDMBLKCACHEIOXFER)pvUser2, rcReq);
9496f2d398b49813176939d7a339ae513d5175efvboxsyncstatic DECLCALLBACK(int) drvvdStartRead(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync LogFlowFunc(("uOffset=%#llx paSeg=%#p cSeg=%u cbRead=%d pvUser=%#p\n",
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync rc = VDAsyncRead(pThis->pDisk, uOffset, cbRead, &SgBuf,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync rc = PDMR3BlkCacheRead(pThis->pBlkCache, uOffset, &SgBuf, cbRead, pvUser);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsyncstatic DECLCALLBACK(int) drvvdStartWrite(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync LogFlowFunc(("uOffset=%#llx paSeg=%#p cSeg=%u cbWrite=%d pvUser=%#p\n",
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDAsyncWrite(pThis->pDisk, uOffset, cbWrite, &SgBuf,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = PDMR3BlkCacheWrite(pThis->pBlkCache, uOffset, &SgBuf, cbWrite, pvUser);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdStartFlush(PPDMIMEDIAASYNC pInterface, void *pvUser)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDAsyncFlush(pThis->pDisk, drvvdAsyncReqComplete, pThis, pvUser);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc FNPDMBLKCACHEXFERCOMPLETEDRV */
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsyncstatic void drvvdBlkCacheXferComplete(PPDMDRVINS pDrvIns, void *pvUser, int rcReq)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync int rc = pThis->pDrvMediaAsyncPort->pfnTransferCompleteNotify(pThis->pDrvMediaAsyncPort,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc FNPDMBLKCACHEXFERENQUEUEDRV */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic int drvvdBlkCacheXferEnqueue(PPDMDRVINS pDrvIns,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDAsyncRead(pThis->pDisk, off, cbXfer, pcSgBuf, drvvdAsyncReqComplete,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDAsyncWrite(pThis->pDisk, off, cbXfer, pcSgBuf, drvvdAsyncReqComplete,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDAsyncFlush(pThis->pDisk, drvvdAsyncReqComplete, pThis, hIoXfer);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync AssertMsgFailed(("Invalid transfer type %d\n", enmXferDir));
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, VINF_SUCCESS);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync else if (RT_FAILURE(rc) && rc != VERR_VD_ASYNC_IO_IN_PROGRESS)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, rc);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/*******************************************************************************
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync* Base interface methods *
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync*******************************************************************************/
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync * @interface_method_impl{PDMIBASE,pfnQueryInterface}
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(void *) drvvdQueryInterface(PPDMIBASE pInterface, const char *pszIID)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PPDMDRVINS pDrvIns = PDMIBASE_2_DRVINS(pInterface);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIA, &pThis->IMedia);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAASYNC, pThis->fAsyncIOSupported ? &pThis->IMediaAsync : NULL);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/*******************************************************************************
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync* Saved state notification methods *
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync*******************************************************************************/
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * Load done callback for re-opening the image writable during teleportation.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * This is called both for successful and failed load runs, we only care about
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * successful ones.
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * @returns VBox status code.
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * @param pDrvIns The driver instance.
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * @param pSSM The saved state handle.
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsyncstatic DECLCALLBACK(int) drvvdLoadDone(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /* Drop out if we don't have any work to do or if it's a failed load. */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync if (RT_FAILURE(rc)) /** @todo does the bugger set any errors? */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/*******************************************************************************
c7ff622115966b69b482bd2896662e40d823b22fvboxsync* Driver methods *
c7ff622115966b69b482bd2896662e40d823b22fvboxsync*******************************************************************************/
16a9adc14900ca18e6909679a579f6833425e030vboxsync * VM resume notification that we use to undo what the temporary read-only image
16a9adc14900ca18e6909679a579f6833425e030vboxsync * mode set by drvvdSuspend.
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Also switch to runtime error mode if we're resuming after a state load
16a9adc14900ca18e6909679a579f6833425e030vboxsync * without having been powered on first.
16a9adc14900ca18e6909679a579f6833425e030vboxsync * @param pDrvIns The driver instance data.
16a9adc14900ca18e6909679a579f6833425e030vboxsync * @todo The VMSetError vs VMSetRuntimeError mess must be fixed elsewhere,
16a9adc14900ca18e6909679a579f6833425e030vboxsync * we're making assumptions about Main behavior here!
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(void) drvvdResume(PPDMDRVINS pDrvIns)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync * The VM is being suspended, temporarily change to read-only image mode.
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync * This is important for several reasons:
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync * -# It makes sure that there are no pending writes to the image. Most
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * backends implements this by closing and reopening the image in read-only
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * -# It allows Main to read the images during snapshotting without having
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * to account for concurrent writes.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * -# This is essential for making teleportation targets sharing images work
cba6719bd64ec749967bbe931230452664109857vboxsync * right. Both with regards to caching and with regards to file sharing
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * locks (RTFILE_O_DENY_*). (See also drvvdLoadDone.)
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync * @param pDrvIns The driver instance data.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(void) drvvdSuspend(PPDMDRVINS pDrvIns)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync * VM PowerOn notification for undoing the TempReadOnly config option and
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync * changing to runtime error mode.
090d729e786b999dc285f8ea267f9effd1319544vboxsync * @param pDrvIns The driver instance data.
16a9adc14900ca18e6909679a579f6833425e030vboxsync * @todo The VMSetError vs VMSetRuntimeError mess must be fixed elsewhere,
16a9adc14900ca18e6909679a579f6833425e030vboxsync * we're making assumptions about Main behavior here!
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(void) drvvdPowerOn(PPDMDRVINS pDrvIns)
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync * @copydoc FNPDMDRVRESET
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsyncstatic DECLCALLBACK(void) drvvdReset(PPDMDRVINS pDrvIns)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync * @copydoc FNPDMDRVDESTRUCT
9496f2d398b49813176939d7a339ae513d5175efvboxsyncstatic DECLCALLBACK(void) drvvdDestruct(PPDMDRVINS pDrvIns)
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ASMAtomicXchgHandle(&pThis->MergeCompleteMutex, NIL_RTSEMFASTMUTEX, &mutex);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync /* Request the semaphore to wait until a potentially running merge
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync * operation has been finished. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Construct a VBox disk media driver instance.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * @copydoc FNPDMDRVCONSTRUCT
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdConstruct(PPDMDRVINS pDrvIns,
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync char *pszName = NULL; /**< The path of the disk image file. */
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync char *pszFormat = NULL; /**< The format backed to use for this image. */
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync char *pszCachePath = NULL; /**< The path to the cache image. */
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync char *pszCacheFormat = NULL; /**< The format backend to use for the cache image. */
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync bool fReadOnly; /**< True if the media is read-only. */
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync bool fMaybeReadOnly; /**< True if the media may or may not be read-only. */
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync bool fHonorZeroWrites; /**< True if zero blocks should be written. */
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync * Init the static parts.
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync pDrvIns->IBase.pfnQueryInterface = drvvdQueryInterface;
24a0cc1776a88752cc25446a98e2a3881e623216vboxsync /* IMedia */
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync pThis->IMedia.pfnBiosGetPCHSGeometry = drvvdBiosGetPCHSGeometry;
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync pThis->IMedia.pfnBiosSetPCHSGeometry = drvvdBiosSetPCHSGeometry;
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync pThis->IMedia.pfnBiosGetLCHSGeometry = drvvdBiosGetLCHSGeometry;
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync pThis->IMedia.pfnBiosSetLCHSGeometry = drvvdBiosSetLCHSGeometry;
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync /* IMediaAsync */
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->IMediaAsync.pfnStartWrite = drvvdStartWrite;
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync pThis->IMediaAsync.pfnStartFlush = drvvdStartFlush;
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync /* Initialize supported VD interfaces. */
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync pThis->VDIErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync pThis->VDIErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync pThis->VDIErrorCallbacks.pfnError = drvvdErrorCallback;
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync rc = VDInterfaceAdd(&pThis->VDIError, "DrvVD_VDIError", VDINTERFACETYPE_ERROR,
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync &pThis->VDIErrorCallbacks, pDrvIns, &pThis->pVDIfsDisk);
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync /* This is just prepared here, the actual interface is per-image, so it's
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync * added later. No need to have separate callback tables. */
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync pThis->VDIConfigCallbacks.cbSize = sizeof(VDINTERFACECONFIG);
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync pThis->VDIConfigCallbacks.enmInterface = VDINTERFACETYPE_CONFIG;
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync pThis->VDIConfigCallbacks.pfnAreKeysValid = drvvdCfgAreKeysValid;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDIConfigCallbacks.pfnQuerySize = drvvdCfgQuerySize;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDIConfigCallbacks.pfnQuery = drvvdCfgQuery;
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* List of images is empty now. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->pDrvMediaPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAPORT);
16a9adc14900ca18e6909679a579f6833425e030vboxsync return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE,
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* Try to attach async media port interface above.*/
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->pDrvMediaAsyncPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAASYNCPORT);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * Validate configuration and find all parent images.
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * It's sort of up side down from the image dependency tree.
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync bool fHostIP = false;
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync bool fUseNewIo = false;
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync unsigned iLevel = 0;
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync /* Toplevel configuration additionally contains the global image
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync * open flags. Some might be converted to per-image flags later. */
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync "Format\0Path\0"
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync "ReadOnly\0MaybeReadOnly\0TempReadOnly\0Shareable\0HonorZeroWrites\0"
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync "HostIPStack\0UseNewIo\0BootAcceleration\0BootAccelerationBuffer\0"
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync "SetupMerge\0MergeSource\0MergeTarget\0BwGroup\0Type\0BlockCache\0"
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync "CachePath\0CacheFormat\0");
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* All other image configurations only contain image name and
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * the format information. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync fValid = CFGMR3AreValuesValid(pCurNode, "Format\0Path\0"
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync "MergeSource\0MergeTarget\0");
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
c0a370e600bb60153a269fb32b5f709347c35768vboxsync RT_SRC_POS, N_("DrvVD: Configuration error: keys incorrect at level %d"), iLevel);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "HostIPStack", &fHostIP, true);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync N_("DrvVD: Configuration error: Querying \"HostIPStack\" as boolean failed"));
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "HonorZeroWrites", &fHonorZeroWrites, false);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync N_("DrvVD: Configuration error: Querying \"HonorZeroWrites\" as boolean failed"));
b0b15690f00527424b2d5fb88456d747252322f7vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "ReadOnly", &fReadOnly, false);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync N_("DrvVD: Configuration error: Querying \"ReadOnly\" as boolean failed"));
b0b15690f00527424b2d5fb88456d747252322f7vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "MaybeReadOnly", &fMaybeReadOnly, false);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync N_("DrvVD: Configuration error: Querying \"MaybeReadOnly\" as boolean failed"));
b0b15690f00527424b2d5fb88456d747252322f7vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "TempReadOnly", &pThis->fTempReadOnly, false);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync N_("DrvVD: Configuration error: Querying \"TempReadOnly\" as boolean failed"));
efff36b306e370346025647a158689021df2e1d1vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"TempReadOnly\" are set"));
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = CFGMR3QueryBoolDef(pCurNode, "Shareable", &pThis->fShareable, false);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync N_("DrvVD: Configuration error: Querying \"Shareable\" as boolean failed"));
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = CFGMR3QueryBoolDef(pCurNode, "UseNewIo", &fUseNewIo, false);
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync N_("DrvVD: Configuration error: Querying \"UseNewIo\" as boolean failed"));
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "SetupMerge", &pThis->fMergePending, false);
c8cedf818a53e003ce5a59c552d2f15c1b51f64cvboxsync N_("DrvVD: Configuration error: Querying \"SetupMerge\" as boolean failed"));
c8cedf818a53e003ce5a59c552d2f15c1b51f64cvboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"MergePending\" are set"));
037bb2a3e9d81a494a15e37911a8e5cdc565fb5dvboxsync rc = CFGMR3QueryBoolDef(pCurNode, "BootAcceleration", &pThis->fBootAccelEnabled, false);
037bb2a3e9d81a494a15e37911a8e5cdc565fb5dvboxsync N_("DrvVD: Configuration error: Querying \"BootAcceleration\" as boolean failed"));
037bb2a3e9d81a494a15e37911a8e5cdc565fb5dvboxsync rc = CFGMR3QueryU32Def(pCurNode, "BootAccelerationBuffer", (uint32_t *)&pThis->cbBootAccelBuffer, 16 * _1K);
037bb2a3e9d81a494a15e37911a8e5cdc565fb5dvboxsync N_("DrvVD: Configuration error: Querying \"BootAccelerationBuffer\" as integer failed"));
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync rc = CFGMR3QueryBoolDef(pCurNode, "BlockCache", &fUseBlockCache, false);
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Querying \"BlockCache\" as boolean failed"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "BwGroup", &pThis->pszBwGroup);
16a9adc14900ca18e6909679a579f6833425e030vboxsync if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND)
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Querying \"BwGroup\" as string failed"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_BLOCK_NO_TYPE, N_("Failed to obtain the type"));
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_BLOCK_UNKNOWN_TYPE, RT_SRC_POS,
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "CachePath", &pszCachePath);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND)
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync N_("DrvVD: Configuration error: Querying \"CachePath\" as string failed"));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "CacheFormat", &pszCacheFormat);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync N_("DrvVD: Configuration error: Querying \"CacheFormat\" as string failed"));
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync PCFGMNODE pParent = CFGMR3GetChild(pCurNode, "Parent");
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Create the image container and the necessary interfaces.
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* Construct TCPNET callback table depending on the config. This is
16a9adc14900ca18e6909679a579f6833425e030vboxsync * done unconditionally, as uninterested backends will ignore it. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.cbSize = sizeof(VDINTERFACETCPNET);
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.enmInterface = VDINTERFACETYPE_TCPNET;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnSocketCreate = drvvdTcpSocketCreate;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnSocketDestroy = drvvdTcpSocketDestroy;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnClientConnect = drvvdTcpClientConnect;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnIsClientConnected = drvvdTcpIsClientConnected;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnClientClose = drvvdTcpClientClose;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnSelectOne = drvvdTcpSelectOne;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnWrite = drvvdTcpWrite;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnSgWrite = drvvdTcpSgWrite;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnReadNB = drvvdTcpReadNB;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnWriteNB = drvvdTcpWriteNB;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnSgWriteNB = drvvdTcpSgWriteNB;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnFlush = drvvdTcpFlush;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnSetSendCoalescing = drvvdTcpSetSendCoalescing;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnGetLocalAddress = drvvdTcpGetLocalAddress;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->VDITcpNetCallbacks.pfnGetPeerAddress = drvvdTcpGetPeerAddress;
16a9adc14900ca18e6909679a579f6833425e030vboxsync * There is a 15ms delay between receiving the data and marking the socket
16a9adc14900ca18e6909679a579f6833425e030vboxsync * as readable on Windows XP which hurts async I/O performance of
16a9adc14900ca18e6909679a579f6833425e030vboxsync * TCP backends badly. Provide a different select method without
16a9adc14900ca18e6909679a579f6833425e030vboxsync * using poll on XP.
16a9adc14900ca18e6909679a579f6833425e030vboxsync * This is only used on XP because it is not as efficient as the one using poll
16a9adc14900ca18e6909679a579f6833425e030vboxsync * and all other Windows versions are working fine.
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, &szOS[0], sizeof(szOS));
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync if (RT_SUCCESS(rc) && !strncmp(szOS, "Windows XP", 10))
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync LogRel(("VD: Detected Windows XP, disabled poll based waiting for TCP\n"));
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync pThis->VDITcpNetCallbacks.pfnSelectOneEx = drvvdTcpSelectOneExNoPoll;
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pThis->VDITcpNetCallbacks.pfnSelectOneEx = drvvdTcpSelectOneExPoll;
c0a370e600bb60153a269fb32b5f709347c35768vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
c0a370e600bb60153a269fb32b5f709347c35768vboxsync RT_SRC_POS, N_("DrvVD: Configuration error: TCP over Internal Networking not compiled in"));
c0a370e600bb60153a269fb32b5f709347c35768vboxsync#else /* VBOX_WITH_INIP */
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pThis->VDITcpNetCallbacks.cbSize = sizeof(VDINTERFACETCPNET);
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pThis->VDITcpNetCallbacks.enmInterface = VDINTERFACETYPE_TCPNET;
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pThis->VDITcpNetCallbacks.pfnSocketCreate = drvvdINIPSocketCreate;
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pThis->VDITcpNetCallbacks.pfnSocketDestroy = drvvdINIPSocketDestroy;
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pThis->VDITcpNetCallbacks.pfnClientConnect = drvvdINIPClientConnect;
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pThis->VDITcpNetCallbacks.pfnClientClose = drvvdINIPClientClose;
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pThis->VDITcpNetCallbacks.pfnIsClientConnected = drvvdINIPIsClientConnected;
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pThis->VDITcpNetCallbacks.pfnSelectOne = drvvdINIPSelectOne;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDITcpNetCallbacks.pfnWrite = drvvdINIPWrite;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDITcpNetCallbacks.pfnSgWrite = drvvdINIPSgWrite;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDITcpNetCallbacks.pfnFlush = drvvdINIPFlush;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDITcpNetCallbacks.pfnSetSendCoalescing = drvvdINIPSetSendCoalescing;
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync pThis->VDITcpNetCallbacks.pfnGetLocalAddress = drvvdINIPGetLocalAddress;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDITcpNetCallbacks.pfnGetPeerAddress = drvvdINIPGetPeerAddress;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDITcpNetCallbacks.pfnSelectOneEx = drvvdINIPSelectOneEx;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#endif /* VBOX_WITH_INIP */
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync * The image has a bandwidth group but the host cache is enabled.
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync * Use the async I/O framework but tell it to enable the host cache.
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** @todo quick hack to work around problems in the async I/O
9496f2d398b49813176939d7a339ae513d5175efvboxsync * implementation (rw semaphore thread ownership problem)
9496f2d398b49813176939d7a339ae513d5175efvboxsync * while a merge is running. Remove once this is fixed. */
d1bffa158f98ff3c18f7d085e7372c9ea00e9a43vboxsync pThis->VDIIOCallbacks.cbSize = sizeof(VDINTERFACEIO);
24a0cc1776a88752cc25446a98e2a3881e623216vboxsync pThis->VDIIOCallbacks.enmInterface = VDINTERFACETYPE_IO;
d1bffa158f98ff3c18f7d085e7372c9ea00e9a43vboxsync pThis->VDIIOCallbacks.pfnClose = drvvdAsyncIOClose;
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync pThis->VDIIOCallbacks.pfnGetSize = drvvdAsyncIOGetSize;
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync pThis->VDIIOCallbacks.pfnSetSize = drvvdAsyncIOSetSize;
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync pThis->VDIIOCallbacks.pfnReadSync = drvvdAsyncIOReadSync;
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync pThis->VDIIOCallbacks.pfnWriteSync = drvvdAsyncIOWriteSync;
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync pThis->VDIIOCallbacks.pfnFlushSync = drvvdAsyncIOFlushSync;
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync pThis->VDIIOCallbacks.pfnReadAsync = drvvdAsyncIOReadAsync;
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync pThis->VDIIOCallbacks.pfnWriteAsync = drvvdAsyncIOWriteAsync;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDIIOCallbacks.pfnFlushAsync = drvvdAsyncIOFlushAsync;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#else /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
927320c7f81d3acdbccb5f3fea7548b4b7184b98vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync RT_SRC_POS, N_("DrvVD: Configuration error: Async Completion Framework not compiled in"));
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync#endif /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = RTSemFastMutexCreate(&pThis->MergeCompleteMutex);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDIThreadSyncCallbacks.cbSize = sizeof(VDINTERFACETHREADSYNC);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDIThreadSyncCallbacks.enmInterface = VDINTERFACETYPE_THREADSYNC;
76364cddabfeb143dad91862d41a5638d8860b25vboxsync pThis->VDIThreadSyncCallbacks.pfnStartRead = drvvdThreadStartRead;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDIThreadSyncCallbacks.pfnFinishRead = drvvdThreadFinishRead;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDIThreadSyncCallbacks.pfnStartWrite = drvvdThreadStartWrite;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->VDIThreadSyncCallbacks.pfnFinishWrite = drvvdThreadFinishWrite;
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = VDInterfaceAdd(&pThis->VDIThreadSync, "DrvVD_ThreadSync", VDINTERFACETYPE_THREADSYNC,
16a9adc14900ca18e6909679a579f6833425e030vboxsync &pThis->VDIThreadSyncCallbacks, pThis, &pThis->pVDIfsDisk);
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Failed to create semaphores for \"MergePending\""));
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDCreate(pThis->pVDIfsDisk, enmType, &pThis->pDisk);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* Error message is already set correctly. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync unsigned iImageIdx = 0;
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /* Allocate per-image data. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * Read the image configuration.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "Path", &pszName);
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync N_("DrvVD: Configuration error: Querying \"Path\" as string failed"));
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "Format", &pszFormat);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync N_("DrvVD: Configuration error: Querying \"Format\" as string failed"));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "MergeSource", &fMergeSource, false);
5b465a7c1237993faf8bb50120d247f3f0319adavboxsync N_("DrvVD: Configuration error: Querying \"MergeSource\" as boolean failed"));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync N_("DrvVD: Configuration error: Multiple \"MergeSource\" occurrences"));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "MergeTarget", &fMergeTarget, false);
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync N_("DrvVD: Configuration error: Querying \"MergeTarget\" as boolean failed"));
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync N_("DrvVD: Configuration error: Multiple \"MergeTarget\" occurrences"));
9496f2d398b49813176939d7a339ae513d5175efvboxsync PCFGMNODE pCfgVDConfig = CFGMR3GetChild(pCurNode, "VDConfig");
9496f2d398b49813176939d7a339ae513d5175efvboxsync rc = VDInterfaceAdd(&pImage->VDIConfig, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
cba6719bd64ec749967bbe931230452664109857vboxsync &pThis->VDIConfigCallbacks, pCfgVDConfig, &pImage->pVDIfsImage);
cba6719bd64ec749967bbe931230452664109857vboxsync /* Unconditionally insert the TCPNET interface, don't bother to check
cba6719bd64ec749967bbe931230452664109857vboxsync * if an image really needs it. Will be ignored. Since the TCPNET
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * interface is per image we could make this more flexible in the
cba6719bd64ec749967bbe931230452664109857vboxsync * future if we want to. */
if (fUseNewIo)
unsigned uOpenFlags;
if (fHonorZeroWrites)
&& !fReadOnly
&& !fMaybeReadOnly
&& iLevel == 0)
pszName);
iLevel--;
iImageIdx++;
if (fUseNewIo)
rc = VDCacheOpen(pThis->pDisk, pszCacheFormat, pszCachePath, VD_OPEN_FLAGS_NORMAL, pThis->pVDIfsCache);
if ( fUseBlockCache
const char *pcszController;
if (cbStr > 0)
pszId);
return rc;
sizeof(VBOXDISK),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,