DrvVD.cpp revision c5abe3ea9c7ac6dec34f42af30612534bea951ff
77b1a2d8b5dbe2c0b5200794914239fee3c8ee5dvboxsync * DrvVD - Generic VBox disk media driver.
be41e59f051a3abb5cd05e7fe270ab2fea791f5avboxsync * Copyright (C) 2006-2013 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*******************************************************************************/
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/* All lwip header files are not C++ safe. So hack around this. */
efff36b306e370346025647a158689021df2e1d1vboxsync#endif /* VBOX_WITH_INIP */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/* Small hack to get at lwIP initialized status */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncextern bool DevINIPConfigured(void);
efff36b306e370346025647a158689021df2e1d1vboxsync#endif /* VBOX_WITH_INIP */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/*******************************************************************************
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync* Defined types, constants and macros *
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync*******************************************************************************/
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** Converts a pointer to VBOXDISK::IMedia to a PVBOXDISK. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync ( (PVBOXDISK)((uintptr_t)pInterface - RT_OFFSETOF(VBOXDISK, IMedia)) )
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. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync /** Configuration information interface. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync /** TCP network stack interface. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync /** 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. */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync volatile bool fSyncIoPending;
7766bf675357fd940d8c49e69a5d72dc6eaa6be4vboxsync /** Return code of the last completed request. */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /** Callback routine */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * VBox disk container media main structure, private part.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMIMEDIA
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMIMEDIAASYNC
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements VDINTERFACEERROR
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements VDINTERFACETCPNET
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements VDINTERFACEASYNCIO
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements VDINTERFACECONFIG
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsynctypedef struct VBOXDISK
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /** The VBox disk container. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /** The media interface. */
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync /** Media port. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /** Pointer to the driver instance. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /** Flag whether suspend has changed image open mode to read only. */
21029597fc4b76d0db0c9542daee201447281781vboxsync /** Flag whether to use the runtime (true) or startup error facility. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Pointer to list of VD interfaces. Per-disk. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync /** Error interface. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync /** Thread synchronization interface. */
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync /** Flag whether opened disk supports async I/O operations. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** The async media interface. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** The async media port interface above. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Pointer to the list of data we need to keep per image. */
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync /** 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. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** 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. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /** The disk buffer. */
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync /** Bandwidth group the disk is assigned to. */
61b5982fad4660d0fe3dd6ceba9eda85eb32f7e8vboxsync /** Flag whether async I/O using the host cache is enabled. */
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync /** I/O interface for a cache image. */
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync /** Interface list for the cache image. */
009d45aa55691312278d41edb20154dc208d9cd8vboxsync /** The block cache handle if configured. */
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync /** Cryptographic support
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync /** Used algorithm, NULL means no encryption. */
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync /** Stored key id, queried from the crypto filter. */
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync /** Config interface for the encryption filter. */
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync /** Crypto interface for the encryption filter. */
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync /** The secret key interface used to retrieve keys. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/*******************************************************************************
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync* Internal Functions *
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync*******************************************************************************/
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * Internal: allocate new image descriptor and put it in the list
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync PVBOXIMAGE pImage = (PVBOXIMAGE)RTMemAllocZ(sizeof(VBOXIMAGE));
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * 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.
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = VDGetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, &uOpenFlags);
16a9adc14900ca18e6909679a579f6833425e030vboxsync 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/*******************************************************************************
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync* Error reporting callback *
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync*******************************************************************************/
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic void drvvdErrorCallback(void *pvUser, int rc, RT_SRC_POS_DECL,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* We must not pass VMSETRTERR_FLAGS_FATAL as it could lead to a
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * deadlock: We are probably executed in a thread context != EMT
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * and the EM thread would wait until every thread is suspended
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * but we would wait for the EM thread ... */
a9d49c8f2b28a72e6a4db86eee91e4569290157bvboxsync PDMDrvHlpVMSetRuntimeErrorV(pDrvIns, /* fFlags=*/ 0, "DrvVD", pszFormat, va);
a9d49c8f2b28a72e6a4db86eee91e4569290157bvboxsync PDMDrvHlpVMSetErrorV(pDrvIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
9496f2d398b49813176939d7a339ae513d5175efvboxsync/*******************************************************************************
9496f2d398b49813176939d7a339ae513d5175efvboxsync* VD Async I/O interface implementation *
9496f2d398b49813176939d7a339ae513d5175efvboxsync*******************************************************************************/
22ec733a5e041fcdfe02fce2eafc9faf8b0077ddvboxsyncstatic DECLCALLBACK(void) drvvdAsyncTaskCompleted(PPDMDRVINS pDrvIns, void *pvTemplateUser, void *pvUser, int rcReq)
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pvTemplateUser;
aa834e89e076db44fa8fe82d177748f0a45d14c2vboxsync LogFlowFunc(("pDrvIns=%#p pvTemplateUser=%#p pvUser=%#p rcReq=%d\n",
a0a5ab4e085a7ee5b95bdfae04cec7de95792c3cvboxsync ASMAtomicWriteBool(&pStorageBackend->fSyncIoPending, false);
bbede9c189def47a9880f0ffb03c0c230c774185vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOOpen(void *pvUser, const char *pszLocation,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)RTMemAllocZ(sizeof(DRVVDSTORAGEBACKEND));
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync rc = PDMDrvHlpAsyncCompletionTemplateCreate(pThis->pDrvIns, &pStorageBackend->pTemplate,
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync drvvdAsyncTaskCompleted, pStorageBackend, "AsyncTaskCompleted");
a0a5ab4e085a7ee5b95bdfae04cec7de95792c3cvboxsync uint32_t fFlags = (fOpen & RTFILE_O_ACCESS_MASK) == RTFILE_O_READ
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync Assert((fOpen & RTFILE_O_DENY_MASK) == RTFILE_O_DENY_NONE);
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync rc = PDMR3AsyncCompletionEpCreateForFile(&pStorageBackend->pEndpoint,
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync rc = PDMR3AsyncCompletionEpSetBwMgr(pStorageBackend->pEndpoint, pThis->pszBwGroup);
a0a5ab4e085a7ee5b95bdfae04cec7de95792c3cvboxsync LogFlow(("drvvdAsyncIOOpen: Successfully opened '%s'; fOpen=%#x pStorage=%p\n",
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync PDMR3AsyncCompletionEpClose(pStorageBackend->pEndpoint);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDMR3AsyncCompletionTemplateDestroy(pStorageBackend->pTemplate);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOClose(void *pvUser, void *pStorage)
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDMR3AsyncCompletionEpClose(pStorageBackend->pEndpoint);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDMR3AsyncCompletionTemplateDestroy(pStorageBackend->pTemplate);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOReadSync(void *pvUser, void *pStorage, uint64_t uOffset,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
a0a5ab4e085a7ee5b95bdfae04cec7de95792c3cvboxsync bool fOld = ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync int rc = PDMR3AsyncCompletionEpRead(pStorageBackend->pEndpoint, uOffset, &DataSeg, 1, cbRead, NULL, &pTask);
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOWriteSync(void *pvUser, void *pStorage, uint64_t uOffset,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync const void *pvBuf, size_t cbWrite, size_t *pcbWritten)
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
a0a5ab4e085a7ee5b95bdfae04cec7de95792c3cvboxsync bool fOld = ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync int rc = PDMR3AsyncCompletionEpWrite(pStorageBackend->pEndpoint, uOffset, &DataSeg, 1, cbWrite, NULL, &pTask);
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOFlushSync(void *pvUser, void *pStorage)
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync LogFlowFunc(("pvUser=%#p pStorage=%#p\n", pvUser, pStorage));
a0a5ab4e085a7ee5b95bdfae04cec7de95792c3cvboxsync bool fOld = ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync int rc = PDMR3AsyncCompletionEpFlush(pStorageBackend->pEndpoint, NULL, &pTask);
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOReadAsync(void *pvUser, void *pStorage, uint64_t uOffset,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
a0a5ab4e085a7ee5b95bdfae04cec7de95792c3cvboxsync int rc = PDMR3AsyncCompletionEpRead(pStorageBackend->pEndpoint, uOffset, paSegments, (unsigned)cSegments, cbRead,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOWriteAsync(void *pvUser, void *pStorage, uint64_t uOffset,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
a0a5ab4e085a7ee5b95bdfae04cec7de95792c3cvboxsync int rc = PDMR3AsyncCompletionEpWrite(pStorageBackend->pEndpoint, uOffset, paSegments, (unsigned)cSegments, cbWrite,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOFlushAsync(void *pvUser, void *pStorage,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync 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);
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOSetSize(void *pvUser, void *pStorage, uint64_t cbSize)
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync return PDMR3AsyncCompletionEpSetSize(pStorageBackend->pEndpoint, cbSize);
59d7f5939d42ad9d344fbad8401e00a900db92c5vboxsync#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)
16a9adc14900ca18e6909679a579f6833425e030vboxsync return RTSemRWRequestWrite(pThis->MergeLock, RT_INDEFINITE_WAIT);
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdThreadFinishWrite(void *pvUser)
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync/*******************************************************************************
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync* VD Configuration interface implementation *
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync*******************************************************************************/
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsyncstatic bool drvvdCfgAreKeysValid(void *pvUser, const char *pszzValid)
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync return CFGMR3AreValuesValid((PCFGMNODE)pvUser, pszzValid);
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsyncstatic int drvvdCfgQuerySize(void *pvUser, const char *pszName, size_t *pcb)
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync return CFGMR3QuerySize((PCFGMNODE)pvUser, pszName, pcb);
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsyncstatic int drvvdCfgQuery(void *pvUser, const char *pszName, char *pszString, size_t cchString)
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync return CFGMR3QueryString((PCFGMNODE)pvUser, pszName, pszString, cchString);
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsyncstatic int drvvdCfgQueryBytes(void *pvUser, const char *pszName, void *ppvData, size_t cbData)
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync return CFGMR3QueryBytes((PCFGMNODE)pvUser, pszName, ppvData, cbData);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync/*******************************************************************************
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync* VD Configuration interface implementation for the encryption support *
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync*******************************************************************************/
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsyncstatic bool drvvdCfgEncAreKeysValid(void *pvUser, const char *pszValid)
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync return true;
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsyncstatic int drvvdCfgEncQuerySize(void *pvUser, const char *pszName, size_t *pcb)
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsyncstatic int drvvdCfgEncQuery(void *pvUser, const char *pszName, char *pszString, size_t cchString)
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync rc = RTStrCopy(pszString, cchString, pThis->pszEncryptionAlgorithm);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync rc = RTStrCopy(pszString, cchString, pThis->pszKeyId);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync/*******************************************************************************
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync* VD Crypto interface implementation for the encryption support *
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync*******************************************************************************/
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsyncstatic DECLCALLBACK(int) drvvdCryptoKeyRetain(void *pvUser, const char *pszId, const uint8_t **ppbKey, size_t *pcbKey)
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync rc = pThis->pIfSecKey->pfnKeyRetain(pThis->pIfSecKey, pszId, ppbKey, pcbKey);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdCryptoKeyRelease(void *pvUser, const char *pszId)
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync rc = pThis->pIfSecKey->pfnKeyRelease(pThis->pIfSecKey, pszId);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/*******************************************************************************
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync* VD TCP network stack interface implementation - INIP case *
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync*******************************************************************************/
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync * vvl: this structure duplicate meaning of sockaddr,
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync * perhaps it'd be better to get rid of it.
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));
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync/** @copydoc VDINTERFACETCPNET::pfnSocketCreate */
1e9e76e4273dcc2e3d560a0f3605c46f0013eb7bvboxsyncstatic DECLCALLBACK(int) drvvdINIPSocketDestroy(VDSOCKET Sock)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnClientConnect */
30c39307775310ba50de9d9b74f1ea9e12524102vboxsyncstatic DECLCALLBACK(int) drvvdINIPClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* Check whether lwIP is set up in this VM instance. */
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync /* Resolve hostname. As there is no standard resolver for lwIP yet,
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync * just accept numeric IP addresses for now. */
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync else /* concatination with if */
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync LogRelFunc(("cannot resolve IP %s\n", pszAddress));
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync /* Create socket and connect. */
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync int iSock = lwip_socket(iInetFamily, SOCK_STREAM, 0);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync && !lwip_connect(iSock, pSockAddr, pSockAddr->sa_len))
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = VERR_NET_CONNECTION_REFUSED; /* @todo real solution needed */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = VERR_NET_CONNECTION_REFUSED; /* @todo real solution needed */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnClientClose */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPClientClose(VDSOCKET Sock)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VINF_SUCCESS; /** @todo real solution needed */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnIsClientConnected */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(bool) drvvdINIPIsClientConnected(VDSOCKET Sock)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOne */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync 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)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /* Do params checking */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * 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 */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /* return partial data */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* read more? */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnWrite */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /** @todo lwip send only supports up to 65535 bytes in a single
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync * send (stupid limitation buried in the code), so make sure we
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync * don't get any wraparounds. This should be moved to DevINIP
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync * stack interface once that's implemented. */
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync ssize_t cbWritten = lwip_send(pSocketInt->hSock, (void *)pvBuffer,
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution needed */
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync 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)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /* This is an extremely crude emulation, however it's good enough
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync * for our iSCSI code. INIP has no sendmsg(). */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnFlush */
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsyncstatic DECLCALLBACK(int) drvvdINIPFlush(VDSOCKET Sock)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync lwip_setsockopt(pSocketInt->hSock, IPPROTO_TCP, TCP_NODELAY,
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync lwip_setsockopt(pSocketInt->hSock, IPPROTO_TCP, TCP_NODELAY,
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSetSendCoalescing */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsyncstatic 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)
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync if (!lwip_getsockname(pSocketInt->hSock, &u.Addr, &cbAddr))
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync * Convert the address.
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync memcpy(&pAddr->uAddr.IPv6, &u.Ipv6.sin6_addr, sizeof(RTNETADDRIPV6));
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetPeerAddress */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsyncstatic DECLCALLBACK(int) drvvdINIPGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr)
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync if (!lwip_getpeername(pSocketInt->hSock, &u.Addr, &cbAddr))
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync * Convert the address.
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync memcpy(&pAddr->uAddr.IPv6, &u.Ipv6.sin6_addr, sizeof(RTNETADDRIPV6));
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOneEx */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic 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.
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsynctypedef 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,
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync 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. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync 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*/);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync/** @copydoc VDINTERFACETCPNET::pfnClientConnect */
b0b15690f00527424b2d5fb88456d747252322f7vboxsyncstatic DECLCALLBACK(int) drvvdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync 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,
a2f96875f61628e5a5fd33785f8c0bbb310f981fvboxsync 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);
51a01524909c95ee04b636218b6a89b29fb81825vboxsync/** @copydoc VDINTERFACETCPNET::pfnWrite */
51a01524909c95ee04b636218b6a89b29fb81825vboxsyncstatic 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);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnWriteNB */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic 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);
217fa436516d137a409bb493cb7d350898f64666vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetPeerAddress */
217fa436516d137a409bb493cb7d350898f64666vboxsyncstatic DECLCALLBACK(int) drvvdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr)
51a01524909c95ee04b636218b6a89b29fb81825vboxsync return RTTcpGetPeerAddress(pSockInt->hSocket, pAddr);
51a01524909c95ee04b636218b6a89b29fb81825vboxsyncstatic int drvvdTcpSelectOneExPoll(VDSOCKET Sock, uint32_t fEvents,
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTPollSetEventsChange(pSockInt->hPollSet, VDSOCKET_POLL_ID_SOCKET, fPollEvents);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTPoll(pSockInt->hPollSet, cMillies, &fEventsRecv, &id);
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/** @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 */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdTcpPoke(VDSOCKET Sock)
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync rc = RTPipeWrite(pSockInt->hPipeW, "", 1, &cbWritten);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync/*******************************************************************************
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync* Media interface methods *
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync*******************************************************************************/
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 rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
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);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync /* Increase request to the buffer size and read. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->cbDataValid = RT_MIN(pThis->cbDisk - off, pThis->cbBootAccelBuffer);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = VDRead(pThis->pDisk, off, pThis->pbData, pThis->cbDataValid);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync Log2(("%s: off=%#llx pvBuf=%p cbRead=%d\n%.*Rhxd\n", __FUNCTION__,
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync/** @copydoc PDMIMEDIA::pfnWrite */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsyncstatic DECLCALLBACK(int) drvvdWrite(PPDMIMEDIA pInterface,
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync LogFlowFunc(("off=%#llx pvBuf=%p cbWrite=%d\n", off, pvBuf, cbWrite));
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync Log2(("%s: off=%#llx pvBuf=%p cbWrite=%d\n%.*Rhxd\n", __FUNCTION__,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync int rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync /* Invalidate any buffer if boot acceleration is enabled. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync int rc = VDWrite(pThis->pDisk, off, pvBuf, cbWrite);
16a9adc14900ca18e6909679a579f6833425e030vboxsync/** @copydoc PDMIMEDIA::pfnFlush */
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic 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
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync * PFNVDPROGRESS, so there's no need for a conversion function. */
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync /** @todo maybe introduce a conversion which limits update frequency. */
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync rc2 = VDInterfaceAdd(&VDIfProgress.Core, "DrvVD_VDIProgress", VDINTERFACETYPE_PROGRESS,
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync pvUser, sizeof(VDINTERFACEPROGRESS), &pVDIfsOperation);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync rc2 = RTSemFastMutexRelease(pThis->MergeCompleteMutex);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync/** @copydoc PDMIMEDIA::pfnSetKey */
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsyncstatic DECLCALLBACK(int) drvvdSetSecKeyIf(PPDMIMEDIA pInterface, PPDMISECKEY pIfSecKey)
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync /* Unload the crypto filter first to make sure it doesn't access the keys anymore. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = VDInterfaceAdd(&pThis->VDIfCfg.Core, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
e18d16f31765f000e2a4a111a3df6d211cd825f1vboxsync rc = VDInterfaceAdd(&pThis->VDIfCrypto.Core, "DrvVD_Crypto", VDINTERFACETYPE_CRYPTO,
e18d16f31765f000e2a4a111a3df6d211cd825f1vboxsync /* Load the crypt filter plugin. */
e18d16f31765f000e2a4a111a3df6d211cd825f1vboxsync rc = VDFilterAdd(pThis->pDisk, "CRYPT", pVDIfFilter);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnGetSize */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(uint64_t) drvvdGetSize(PPDMIMEDIA pInterface)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync uint64_t cb = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync/** @copydoc PDMIMEDIA::pfnGetSectorSize */
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsyncstatic DECLCALLBACK(uint32_t) drvvdGetSectorSize(PPDMIMEDIA pInterface)
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync uint32_t cb = VDGetSectorSize(pThis->pDisk, VD_LAST_IMAGE);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync/** @copydoc PDMIMEDIA::pfnIsReadOnly */
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsyncstatic DECLCALLBACK(bool) drvvdIsReadOnly(PPDMIMEDIA pInterface)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync/** @copydoc PDMIMEDIA::pfnBiosGetPCHSGeometry */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsyncstatic DECLCALLBACK(int) drvvdBiosGetPCHSGeometry(PPDMIMEDIA pInterface,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
594521f7faf13f7a88f31e6cd76629bd67340229vboxsync int rc = VDGetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync/** @copydoc PDMIMEDIA::pfnBiosSetPCHSGeometry */
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsyncstatic DECLCALLBACK(int) drvvdBiosSetPCHSGeometry(PPDMIMEDIA pInterface,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync int rc = VDSetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync/** @copydoc PDMIMEDIA::pfnBiosGetLCHSGeometry */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsyncstatic DECLCALLBACK(int) drvvdBiosGetLCHSGeometry(PPDMIMEDIA pInterface,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
594521f7faf13f7a88f31e6cd76629bd67340229vboxsync int rc = VDGetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync/** @copydoc PDMIMEDIA::pfnBiosSetLCHSGeometry */
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsyncstatic DECLCALLBACK(int) drvvdBiosSetLCHSGeometry(PPDMIMEDIA pInterface,
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
9496f2d398b49813176939d7a339ae513d5175efvboxsync int rc = VDSetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync/** @copydoc PDMIMEDIA::pfnGetUuid */
009d45aa55691312278d41edb20154dc208d9cd8vboxsyncstatic DECLCALLBACK(int) drvvdGetUuid(PPDMIMEDIA pInterface, PRTUUID pUuid)
009d45aa55691312278d41edb20154dc208d9cd8vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync LogFlowFunc(("returns %Rrc ({%RTuuid})\n", rc, pUuid));
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsyncstatic DECLCALLBACK(int) drvvdDiscard(PPDMIMEDIA pInterface, PCRTRANGE paRanges, unsigned cRanges)
009d45aa55691312278d41edb20154dc208d9cd8vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync int rc = VDDiscardRanges(pThis->pDisk, paRanges, cRanges);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync/*******************************************************************************
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync* Async Media interface methods *
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync*******************************************************************************/
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsyncstatic void drvvdAsyncReqComplete(void *pvUser1, void *pvUser2, int rcReq)
19badc2a6bdaeb1208f71b7de06feec1aa7c59c9vboxsync int rc = pThis->pDrvMediaAsyncPort->pfnTransferCompleteNotify(pThis->pDrvMediaAsyncPort,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, (PPDMBLKCACHEIOXFER)pvUser2, rcReq);
009d45aa55691312278d41edb20154dc208d9cd8vboxsyncstatic DECLCALLBACK(int) drvvdStartRead(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync LogFlowFunc(("uOffset=%#llx paSeg=%#p cSeg=%u cbRead=%d pvUser=%#p\n",
9496f2d398b49813176939d7a339ae513d5175efvboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
9496f2d398b49813176939d7a339ae513d5175efvboxsync rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync rc = VDAsyncRead(pThis->pDisk, uOffset, cbRead, &SgBuf,
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync rc = PDMR3BlkCacheRead(pThis->pBlkCache, uOffset, &SgBuf, cbRead, pvUser);
009d45aa55691312278d41edb20154dc208d9cd8vboxsyncstatic DECLCALLBACK(int) drvvdStartWrite(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync LogFlowFunc(("uOffset=%#llx paSeg=%#p cSeg=%u cbWrite=%d pvUser=%#p\n",
9496f2d398b49813176939d7a339ae513d5175efvboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
bdaae7f756db4f5cf2d62f495a2a80acaf581a0cvboxsync rc = VDAsyncWrite(pThis->pDisk, uOffset, cbWrite, &SgBuf,
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync rc = PDMR3BlkCacheWrite(pThis->pBlkCache, uOffset, &SgBuf, cbWrite, pvUser);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncstatic DECLCALLBACK(int) drvvdStartFlush(PPDMIMEDIAASYNC pInterface, void *pvUser)
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync rc = VDAsyncFlush(pThis->pDisk, drvvdAsyncReqComplete, pThis, pvUser);
009d45aa55691312278d41edb20154dc208d9cd8vboxsyncstatic DECLCALLBACK(int) drvvdStartDiscard(PPDMIMEDIAASYNC pInterface, PCRTRANGE paRanges,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync LogFlowFunc(("paRanges=%#p cRanges=%u pvUser=%#p\n",
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = VDAsyncDiscardRanges(pThis->pDisk, paRanges, cRanges, drvvdAsyncReqComplete,
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync rc = PDMR3BlkCacheDiscard(pThis->pBlkCache, paRanges, cRanges, pvUser);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync/** @copydoc FNPDMBLKCACHEXFERCOMPLETEDRV */
009d45aa55691312278d41edb20154dc208d9cd8vboxsyncstatic void drvvdBlkCacheXferComplete(PPDMDRVINS pDrvIns, void *pvUser, int rcReq)
009d45aa55691312278d41edb20154dc208d9cd8vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync int rc = pThis->pDrvMediaAsyncPort->pfnTransferCompleteNotify(pThis->pDrvMediaAsyncPort,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync/** @copydoc FNPDMBLKCACHEXFERENQUEUEDRV */
009d45aa55691312278d41edb20154dc208d9cd8vboxsyncstatic int drvvdBlkCacheXferEnqueue(PPDMDRVINS pDrvIns,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync rc = VDAsyncRead(pThis->pDisk, off, cbXfer, pcSgBuf, drvvdAsyncReqComplete,
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync rc = VDAsyncWrite(pThis->pDisk, off, cbXfer, pcSgBuf, drvvdAsyncReqComplete,
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync rc = VDAsyncFlush(pThis->pDisk, drvvdAsyncReqComplete, pThis, hIoXfer);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync AssertMsgFailed(("Invalid transfer type %d\n", enmXferDir));
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, VINF_SUCCESS);
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync else if (RT_FAILURE(rc) && rc != VERR_VD_ASYNC_IO_IN_PROGRESS)
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, rc);
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync/** @copydoc FNPDMBLKCACHEXFERENQUEUEDISCARDDRV */
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsyncstatic int drvvdBlkCacheXferEnqueueDiscard(PPDMDRVINS pDrvIns, PCRTRANGE paRanges,
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync rc = VDAsyncDiscardRanges(pThis->pDisk, paRanges, cRanges,
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, VINF_SUCCESS);
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync else if (RT_FAILURE(rc) && rc != VERR_VD_ASYNC_IO_IN_PROGRESS)
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, rc);
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync * Sets up the disk filter chain.
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync * @returns VBox status code.
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync * @param pThis The disk instance.
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync * @param pCfg CFGM node holding the filter parameters.
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsyncstatic int drvvdSetupFilters(PVBOXDISK pThis, PCFGMNODE pCfg)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PCFGMNODE pCfgFilter = CFGMR3GetChild(pCfg, "Filters");
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync PCFGMNODE pCfgFilterConfig = CFGMR3GetChild(pCfgFilter, "VDConfig");
9daee41d5cb5a2e8390f015a486e67a6cd52b836vboxsync rc = CFGMR3QueryStringAlloc(pCfgFilter, "FilterName", &pszFilterName);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = VDInterfaceAdd(&VDIfConfig.Core, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pCfgFilterConfig, sizeof(VDINTERFACECONFIG), &pVDIfsFilter);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDFilterAdd(pThis->pDisk, pszFilterName, pVDIfsFilter);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/*******************************************************************************
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync* Base interface methods *
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync*******************************************************************************/
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @interface_method_impl{PDMIBASE,pfnQueryInterface}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(void *) drvvdQueryInterface(PPDMIBASE pInterface, const char *pszIID)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(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 *
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync*******************************************************************************/
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * 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
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * successful ones.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @returns VBox status code.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @param pDrvIns The driver instance.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @param pSSM The saved state handle.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdLoadDone(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* 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/*******************************************************************************
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync* Driver methods *
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync*******************************************************************************/
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * VM resume notification that we use to undo what the temporary read-only image
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * mode set by drvvdSuspend.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * Also switch to runtime error mode if we're resuming after a state load
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * without having been powered on first.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @param pDrvIns The driver instance data.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @todo The VMSetError vs VMSetRuntimeError mess must be fixed elsewhere,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * we're making assumptions about Main behavior here!
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(void) drvvdResume(PPDMDRVINS pDrvIns)
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * The VM is being suspended, temporarily change to read-only image mode.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * This is important for several reasons:
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * -# 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
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * -# It allows Main to read the images during snapshotting without having
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * to account for concurrent writes.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * -# This is essential for making teleportation targets sharing images work
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * right. Both with regards to caching and with regards to file sharing
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync * locks (RTFILE_O_DENY_*). (See also drvvdLoadDone.)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @param pDrvIns The driver instance data.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(void) drvvdSuspend(PPDMDRVINS pDrvIns)
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
ff5f52502d5dff6a8f353c85702ef49cc25c2f6bvboxsync * VM PowerOn notification for undoing the TempReadOnly config option and
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * changing to runtime error mode.
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * @param pDrvIns The driver instance data.
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * @todo The VMSetError vs VMSetRuntimeError mess must be fixed elsewhere,
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * we're making assumptions about Main behavior here!
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsyncstatic DECLCALLBACK(void) drvvdPowerOn(PPDMDRVINS pDrvIns)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @copydoc FNPDMDRVRESET
c7ff622115966b69b482bd2896662e40d823b22fvboxsyncstatic DECLCALLBACK(void) drvvdReset(PPDMDRVINS pDrvIns)
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
1e1273b11e17928ec3c3a8fff45121aa7a169413vboxsync * @copydoc FNPDMDRVDESTRUCT
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(void) drvvdDestruct(PPDMDRVINS pDrvIns)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
76364cddabfeb143dad91862d41a5638d8860b25vboxsync ASMAtomicXchgHandle(&pThis->MergeCompleteMutex, NIL_RTSEMFASTMUTEX, &mutex);
76364cddabfeb143dad91862d41a5638d8860b25vboxsync /* Request the semaphore to wait until a potentially running merge
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * operation has been finished. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Construct a VBox disk media driver instance.
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync * @copydoc FNPDMDRVCONSTRUCT
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsyncstatic DECLCALLBACK(int) drvvdConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
e18d16f31765f000e2a4a111a3df6d211cd825f1vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync char *pszName = NULL; /**< The path of the disk image file. */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync char *pszFormat = NULL; /**< The format backed to use for this image. */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync char *pszCachePath = NULL; /**< The path to the cache image. */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync char *pszCacheFormat = NULL; /**< The format backend to use for the cache image. */
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync bool fReadOnly; /**< True if the media is read-only. */
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync bool fMaybeReadOnly; /**< True if the media may or may not be read-only. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync bool fHonorZeroWrites; /**< True if zero blocks should be written. */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync * Init the static parts.
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync pDrvIns->IBase.pfnQueryInterface = drvvdQueryInterface;
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync /* IMedia */
9496f2d398b49813176939d7a339ae513d5175efvboxsync pThis->IMedia.pfnGetSectorSize = drvvdGetSectorSize;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->IMedia.pfnBiosGetPCHSGeometry = drvvdBiosGetPCHSGeometry;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->IMedia.pfnBiosSetPCHSGeometry = drvvdBiosSetPCHSGeometry;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->IMedia.pfnBiosGetLCHSGeometry = drvvdBiosGetLCHSGeometry;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync pThis->IMedia.pfnBiosSetLCHSGeometry = drvvdBiosSetLCHSGeometry;
c13422b6c2690d4243041112362ef95e0ac23e79vboxsync /* IMediaAsync */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->IMediaAsync.pfnStartWrite = drvvdStartWrite;
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync pThis->IMediaAsync.pfnStartFlush = drvvdStartFlush;
ee00a0b29854e7f513198772bccb6650f6dd2184vboxsync pThis->IMediaAsync.pfnStartDiscard = drvvdStartDiscard;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* Initialize supported VD interfaces. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = VDInterfaceAdd(&pThis->VDIfError.Core, "DrvVD_VDIError", VDINTERFACETYPE_ERROR,
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync pDrvIns, sizeof(VDINTERFACEERROR), &pThis->pVDIfsDisk);
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync /* List of images is empty now. */
009d45aa55691312278d41edb20154dc208d9cd8vboxsync pThis->pDrvMediaPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAPORT);
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* Try to attach async media port interface above.*/
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync pThis->pDrvMediaAsyncPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAASYNCPORT);
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Validate configuration and find all parent images.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * It's sort of up side down from the image dependency tree.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync bool fHostIP = false;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync bool fUseNewIo = false;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync bool fDiscard = false;
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync unsigned iLevel = 0;
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync /* Toplevel configuration additionally contains the global image
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync * open flags. Some might be converted to per-image flags later. */
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync "Format\0Path\0"
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync "ReadOnly\0MaybeReadOnly\0TempReadOnly\0Shareable\0HonorZeroWrites\0"
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync "HostIPStack\0UseNewIo\0BootAcceleration\0BootAccelerationBuffer\0"
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync "SetupMerge\0MergeSource\0MergeTarget\0BwGroup\0Type\0BlockCache\0"
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync "CachePath\0CacheFormat\0Discard\0InformAboutZeroBlocks\0"
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync "SkipConsistencyChecks\0");
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync /* All other image configurations only contain image name and
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync * the format information. */
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync fValid = CFGMR3AreValuesValid(pCurNode, "Format\0Path\0"
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync "MergeSource\0MergeTarget\0");
24a0cc1776a88752cc25446a98e2a3881e623216vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
24a0cc1776a88752cc25446a98e2a3881e623216vboxsync RT_SRC_POS, N_("DrvVD: Configuration error: keys incorrect at level %d"), iLevel);
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync rc = CFGMR3QueryBoolDef(pCurNode, "HostIPStack", &fHostIP, true);
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync N_("DrvVD: Configuration error: Querying \"HostIPStack\" as boolean failed"));
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync rc = CFGMR3QueryBoolDef(pCurNode, "HonorZeroWrites", &fHonorZeroWrites, false);
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync N_("DrvVD: Configuration error: Querying \"HonorZeroWrites\" as boolean failed"));
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "ReadOnly", &fReadOnly, false);
44fc72ff17b23a9b970505fcf8d6da1019ddcec5vboxsync N_("DrvVD: Configuration error: Querying \"ReadOnly\" as boolean failed"));
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync rc = CFGMR3QueryBoolDef(pCurNode, "MaybeReadOnly", &fMaybeReadOnly, false);
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Querying \"MaybeReadOnly\" as boolean failed"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "TempReadOnly", &pThis->fTempReadOnly, false);
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Querying \"TempReadOnly\" as boolean failed"));
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"TempReadOnly\" are set"));
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "Shareable", &pThis->fShareable, false);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync N_("DrvVD: Configuration error: Querying \"Shareable\" as boolean failed"));
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "UseNewIo", &fUseNewIo, false);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync N_("DrvVD: Configuration error: Querying \"UseNewIo\" as boolean failed"));
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "SetupMerge", &pThis->fMergePending, false);
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync N_("DrvVD: Configuration error: Querying \"SetupMerge\" as boolean failed"));
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"MergePending\" are set"));
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "BootAcceleration", &pThis->fBootAccelEnabled, false);
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync N_("DrvVD: Configuration error: Querying \"BootAcceleration\" as boolean failed"));
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync rc = CFGMR3QueryU32Def(pCurNode, "BootAccelerationBuffer", (uint32_t *)&pThis->cbBootAccelBuffer, 16 * _1K);
c13422b6c2690d4243041112362ef95e0ac23e79vboxsync N_("DrvVD: Configuration error: Querying \"BootAccelerationBuffer\" as integer failed"));
c13422b6c2690d4243041112362ef95e0ac23e79vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "BlockCache", &fUseBlockCache, false);
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync N_("DrvVD: Configuration error: Querying \"BlockCache\" as boolean failed"));
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "BwGroup", &pThis->pszBwGroup);
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND)
ee00a0b29854e7f513198772bccb6650f6dd2184vboxsync N_("DrvVD: Configuration error: Querying \"BwGroup\" as string failed"));
ee00a0b29854e7f513198772bccb6650f6dd2184vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "Discard", &fDiscard, false);
ee00a0b29854e7f513198772bccb6650f6dd2184vboxsync N_("DrvVD: Configuration error: Querying \"Discard\" as boolean failed"));
ee00a0b29854e7f513198772bccb6650f6dd2184vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
ee00a0b29854e7f513198772bccb6650f6dd2184vboxsync N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"Discard\" are set"));
ee00a0b29854e7f513198772bccb6650f6dd2184vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "InformAboutZeroBlocks", &fInformAboutZeroBlocks, false);
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync N_("DrvVD: Configuration error: Querying \"InformAboutZeroBlocks\" as boolean failed"));
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "SkipConsistencyChecks", &fSkipConsistencyChecks, true);
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync N_("DrvVD: Configuration error: Querying \"SKipConsistencyChecks\" as boolean failed"));
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_BLOCK_NO_TYPE, N_("Failed to obtain the type"));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_BLOCK_UNKNOWN_TYPE, RT_SRC_POS,
61b5982fad4660d0fe3dd6ceba9eda85eb32f7e8vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "CachePath", &pszCachePath);
61b5982fad4660d0fe3dd6ceba9eda85eb32f7e8vboxsync if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND)
61b5982fad4660d0fe3dd6ceba9eda85eb32f7e8vboxsync N_("DrvVD: Configuration error: Querying \"CachePath\" as string failed"));
c8cedf818a53e003ce5a59c552d2f15c1b51f64cvboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "CacheFormat", &pszCacheFormat);
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Querying \"CacheFormat\" as string failed"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync PCFGMNODE pParent = CFGMR3GetChild(pCurNode, "Parent");
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Create the image container and the necessary interfaces.
16a9adc14900ca18e6909679a579f6833425e030vboxsync * The image has a bandwidth group but the host cache is enabled.
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Use the async I/O framework but tell it to enable the host cache.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /** @todo quick hack to work around problems in the async I/O
d5ea45cc92d7f1d3ade8189944531f665bfe8ed5vboxsync * implementation (rw semaphore thread ownership problem)
5d0d754550d06b7d59a935e59caaf814462d53ccvboxsync * while a merge is running. Remove once this is fixed. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = RTSemFastMutexCreate(&pThis->MergeCompleteMutex);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync pThis->VDIfThreadSync.pfnStartRead = drvvdThreadStartRead;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync pThis->VDIfThreadSync.pfnFinishRead = drvvdThreadFinishRead;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync pThis->VDIfThreadSync.pfnStartWrite = drvvdThreadStartWrite;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync pThis->VDIfThreadSync.pfnFinishWrite = drvvdThreadFinishWrite;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = VDInterfaceAdd(&pThis->VDIfThreadSync.Core, "DrvVD_ThreadSync", VDINTERFACETYPE_THREADSYNC,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis, sizeof(VDINTERFACETHREADSYNC), &pThis->pVDIfsDisk);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync N_("DrvVD: Failed to create semaphores for \"MergePending\""));
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync rc = VDCreate(pThis->pVDIfsDisk, enmType, &pThis->pDisk);
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync /* Error message is already set correctly. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync unsigned iImageIdx = 0;
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* Allocate per-image data. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Read the image configuration.
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "Path", &pszName);
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Querying \"Path\" as string failed"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "Format", &pszFormat);
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Querying \"Format\" as string failed"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "MergeSource", &fMergeSource, false);
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Querying \"MergeSource\" as boolean failed"));
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync N_("DrvVD: Configuration error: Multiple \"MergeSource\" occurrences"));
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "MergeTarget", &fMergeTarget, false);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync N_("DrvVD: Configuration error: Querying \"MergeTarget\" as boolean failed"));
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync N_("DrvVD: Configuration error: Multiple \"MergeTarget\" occurrences"));
c0a370e600bb60153a269fb32b5f709347c35768vboxsync PCFGMNODE pCfgVDConfig = CFGMR3GetChild(pCurNode, "VDConfig");
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pImage->VDIfConfig.pfnAreKeysValid = drvvdCfgAreKeysValid;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfConfig.pfnQuerySize = drvvdCfgQuerySize;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = VDInterfaceAdd(&pImage->VDIfConfig.Core, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pCfgVDConfig, sizeof(VDINTERFACECONFIG), &pImage->pVDIfsImage);
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync /* Check VDConfig for encryption config. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = CFGMR3QueryStringAlloc(pCfgVDConfig, "EncryptionAlgorithm", &pThis->pszEncryptionAlgorithm);
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND)
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync N_("DrvVD: Configuration error: Querying \"EncryptionAlgorithm\" as string failed"));
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = CFGMR3QueryStringAlloc(pCfgVDConfig, "KeyId", &pThis->pszKeyId);
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync N_("DrvVD: Configuration error: Querying \"KeyId\" as string failed"));
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync /* Setup VDConfig interface for disk encryption support. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfCfg.pfnAreKeysValid = drvvdCfgEncAreKeysValid;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfCfg.pfnQuerySize = drvvdCfgEncQuerySize;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfCrypto.pfnKeyRetain = drvvdCryptoKeyRetain;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfCrypto.pfnKeyRelease = drvvdCryptoKeyRelease;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync /* Unconditionally insert the TCPNET interface, don't bother to check
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * if an image really needs it. Will be ignored. Since the TCPNET
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * interface is per image we could make this more flexible in the
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * future if we want to. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync /* Construct TCPNET callback table depending on the config. This is
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * done unconditionally, as uninterested backends will ignore it. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSocketCreate = drvvdTcpSocketCreate;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSocketDestroy = drvvdTcpSocketDestroy;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnClientConnect = drvvdTcpClientConnect;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnIsClientConnected = drvvdTcpIsClientConnected;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnClientClose = drvvdTcpClientClose;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSelectOne = drvvdTcpSelectOne;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSgWriteNB = drvvdTcpSgWriteNB;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSetSendCoalescing = drvvdTcpSetSendCoalescing;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnGetLocalAddress = drvvdTcpGetLocalAddress;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnGetPeerAddress = drvvdTcpGetPeerAddress;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * There is a 15ms delay between receiving the data and marking the socket
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * as readable on Windows XP which hurts async I/O performance of
c0a370e600bb60153a269fb32b5f709347c35768vboxsync * TCP backends badly. Provide a different select method without
c0a370e600bb60153a269fb32b5f709347c35768vboxsync * using poll on XP.
c0a370e600bb60153a269fb32b5f709347c35768vboxsync * This is only used on XP because it is not as efficient as the one using poll
c0a370e600bb60153a269fb32b5f709347c35768vboxsync * and all other Windows versions are working fine.
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, &szOS[0], sizeof(szOS));
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync if (RT_SUCCESS(rc) && !strncmp(szOS, "Windows XP", 10))
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync LogRel(("VD: Detected Windows XP, disabled poll based waiting for TCP\n"));
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSelectOneEx = drvvdTcpSelectOneExNoPoll;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSelectOneEx = drvvdTcpSelectOneExPoll;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync RT_SRC_POS, N_("DrvVD: Configuration error: TCP over Internal Networking not compiled in"));
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync#else /* VBOX_WITH_INIP */
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pImage->VDIfTcpNet.pfnSocketCreate = drvvdINIPSocketCreate;
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pImage->VDIfTcpNet.pfnSocketDestroy = drvvdINIPSocketDestroy;
c0a370e600bb60153a269fb32b5f709347c35768vboxsync pImage->VDIfTcpNet.pfnClientConnect = drvvdINIPClientConnect;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pImage->VDIfTcpNet.pfnClientClose = drvvdINIPClientClose;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pImage->VDIfTcpNet.pfnIsClientConnected = drvvdINIPIsClientConnected;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pImage->VDIfTcpNet.pfnSelectOne = drvvdINIPSelectOne;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pImage->VDIfTcpNet.pfnSetSendCoalescing = drvvdINIPSetSendCoalescing;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pImage->VDIfTcpNet.pfnGetLocalAddress = drvvdINIPGetLocalAddress;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pImage->VDIfTcpNet.pfnGetPeerAddress = drvvdINIPGetPeerAddress;
5d0d754550d06b7d59a935e59caaf814462d53ccvboxsync pImage->VDIfTcpNet.pfnSelectOneEx = drvvdINIPSelectOneEx;
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync#endif /* VBOX_WITH_INIP */
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync rc = VDInterfaceAdd(&pImage->VDIfTcpNet.Core, "DrvVD_TCPNET",
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync /* Insert the custom I/O interface only if we're told to use new IO.
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync * Since the I/O interface is per image we could make this more
9496f2d398b49813176939d7a339ae513d5175efvboxsync * flexible in the future if we want to. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync pImage->VDIfIo.pfnWriteSync = drvvdAsyncIOWriteSync;
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync pImage->VDIfIo.pfnFlushSync = drvvdAsyncIOFlushSync;
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync pImage->VDIfIo.pfnReadAsync = drvvdAsyncIOReadAsync;
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync pImage->VDIfIo.pfnWriteAsync = drvvdAsyncIOWriteAsync;
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync pImage->VDIfIo.pfnFlushAsync = drvvdAsyncIOFlushAsync;
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync#else /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync RT_SRC_POS, N_("DrvVD: Configuration error: Async Completion Framework not compiled in"));
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync#endif /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync rc = VDInterfaceAdd(&pImage->VDIfIo.Core, "DrvVD_IO", VDINTERFACETYPE_IO,
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync pThis, sizeof(VDINTERFACEIO), &pImage->pVDIfsImage);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync * Open the image.
24a0cc1776a88752cc25446a98e2a3881e623216vboxsync if (fReadOnly || pThis->fTempReadOnly || iLevel != 0)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync uOpenFlags |= VD_OPEN_FLAGS_INFORM_ABOUT_ZERO_BLOCKS;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync uOpenFlags |= VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* Try to open backend in async I/O mode first. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync VDIsReadOnly(pThis->pDisk) ? "read-only" : "read-write"));
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_VD_IMAGE_READ_ONLY, RT_SRC_POS,
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync N_("Failed to open image '%s' for writing due to wrong permissions"),
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync N_("Failed to open image '%s' in %s mode rc=%Rrc"), pszName,
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync (uOpenFlags & VD_OPEN_FLAGS_READONLY) ? "read-only" : "read-write", rc);
16a9adc14900ca18e6909679a579f6833425e030vboxsync LogRel(("VD: Opening the disk took %lld ns\n", RTTimeNanoTS() - tsStart));
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* Open the cache image if set. */
009d45aa55691312278d41edb20154dc208d9cd8vboxsync /* Insert the custom I/O interface only if we're told to use new IO.
009d45aa55691312278d41edb20154dc208d9cd8vboxsync * Since the I/O interface is per image we could make this more
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * flexible in the future if we want to. */
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync pThis->VDIfIoCache.pfnGetSize = drvvdAsyncIOGetSize;
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync pThis->VDIfIoCache.pfnSetSize = drvvdAsyncIOSetSize;
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync pThis->VDIfIoCache.pfnReadSync = drvvdAsyncIOReadSync;
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync pThis->VDIfIoCache.pfnWriteSync = drvvdAsyncIOWriteSync;
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync pThis->VDIfIoCache.pfnFlushSync = drvvdAsyncIOFlushSync;
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync pThis->VDIfIoCache.pfnReadAsync = drvvdAsyncIOReadAsync;
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync pThis->VDIfIoCache.pfnWriteAsync = drvvdAsyncIOWriteAsync;
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync pThis->VDIfIoCache.pfnFlushAsync = drvvdAsyncIOFlushAsync;
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync#else /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync RT_SRC_POS, N_("DrvVD: Configuration error: Async Completion Framework not compiled in"));
009d45aa55691312278d41edb20154dc208d9cd8vboxsync#endif /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync rc = VDInterfaceAdd(&pThis->VDIfIoCache.Core, "DrvVD_IO", VDINTERFACETYPE_IO,
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync pThis, sizeof(VDINTERFACEIO), &pThis->pVDIfsCache);
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync rc = VDCacheOpen(pThis->pDisk, pszCacheFormat, pszCachePath, VD_OPEN_FLAGS_NORMAL, pThis->pVDIfsCache);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, rc, N_("DrvVD: Could not open cache image"));
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync N_("DrvVD: Configuration error: Inconsistent image merge data"));
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync /* Create the block cache if enabled. */
009d45aa55691312278d41edb20154dc208d9cd8vboxsync && !pThis->pszEncryptionAlgorithm /* Disk encryption disables the block cache for security reasons */
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync * We need a unique ID for the block cache (to identify the owner of data
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync * blocks in a saved state). UUIDs are not really suitable because
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * there are image formats which don't support them. Furthermore it is
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * possible that a new diff image was attached after a saved state
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * which changes the UUID.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * However the device "name + device instance + LUN" triple the disk is
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * attached to is always constant for saved states.
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync rc = pThis->pDrvMediaPort->pfnQueryDeviceLocation(pThis->pDrvMediaPort, &pcszController,
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync N_("DrvVD: Configuration error: Could not query device data"));
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync int cbStr = RTStrAPrintf(&pszId, "%s-%d-%d", pcszController, iInstance, iLUN);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync rc = PDMDrvHlpBlkCacheRetain(pDrvIns, &pThis->pBlkCache,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync N_("DrvVD: Out of memory when creating block cache"));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Register a load-done callback so we can undo TempReadOnly config before
5b465a7c1237993faf8bb50120d247f3f0319adavboxsync * we get to drvvdResume. Autoamtically deregistered upon destruction.
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync rc = PDMDrvHlpSSMRegisterEx(pDrvIns, 0 /* version */, 0 /* cbGuess */,
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync NULL /*pfnLivePrep*/, NULL /*pfnLiveExec*/, NULL /*pfnLiveVote*/,
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync NULL /*pfnSavePrep*/, NULL /*pfnSaveExec*/, NULL /*pfnSaveDone*/,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync NULL /*pfnDonePrep*/, NULL /*pfnLoadExec*/, drvvdLoadDone);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* Setup the boot acceleration stuff if enabled. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->cbDisk = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
ad48e47654d22f79b025dc4b21cb162cb123801avboxsync pThis->pbData = (uint8_t *)RTMemAllocZ(pThis->cbBootAccelBuffer);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync LogRel(("VD: Boot acceleration, out of memory, disabled\n"));
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* drvvdDestruct does the rest. */
cba6719bd64ec749967bbe931230452664109857vboxsync * VBox disk container media driver registration record.
cba6719bd64ec749967bbe931230452664109857vboxsync /* u32Version */
sizeof(VBOXDISK),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,