77b1a2d8b5dbe2c0b5200794914239fee3c8ee5dvboxsync * DrvVD - Generic VBox disk media driver.
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync * Copyright (C) 2006-2015 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.
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. */
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
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
203cad92999b4792bf61b4b65e1e2abfe08f5664vboxsync /** Pointer to the CFGM node containing the config of the crypto filter
203cad92999b4792bf61b4b65e1e2abfe08f5664vboxsync * if enable. */
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync /** Config interface for the encryption filter. */
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsync /** Crypto interface for the encryption filter. */
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsync /** The secret key interface used to retrieve keys. */
eeebcc1f7aedfdbcaf7c4dae90ad932d5d9c03c8vboxsync /** The secret key helper interface used to notify about missing 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);
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsync/*******************************************************************************
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsync* VD Crypto interface implementation for the encryption support *
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsync*******************************************************************************/
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsyncstatic DECLCALLBACK(int) drvvdCryptoKeyRetain(void *pvUser, const char *pszId, const uint8_t **ppbKey, size_t *pcbKey)
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsync rc = pThis->pIfSecKey->pfnKeyRetain(pThis->pIfSecKey, pszId, ppbKey, pcbKey);
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsyncstatic DECLCALLBACK(int) drvvdCryptoKeyRelease(void *pvUser, const char *pszId)
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsync rc = pThis->pIfSecKey->pfnKeyRelease(pThis->pIfSecKey, pszId);
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsyncstatic DECLCALLBACK(int) drvvdCryptoKeyStorePasswordRetain(void *pvUser, const char *pszId, const char **ppszPassword)
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync rc = pThis->pIfSecKey->pfnPasswordRetain(pThis->pIfSecKey, pszId, ppszPassword);
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsyncstatic DECLCALLBACK(int) drvvdCryptoKeyStorePasswordRelease(void *pvUser, const char *pszId)
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync rc = pThis->pIfSecKey->pfnPasswordRelease(pThis->pIfSecKey, pszId);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/*******************************************************************************
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync* VD TCP network stack interface implementation - INIP case *
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync*******************************************************************************/
1e9e76e4273dcc2e3d560a0f3605c46f0013eb7bvboxsync * vvl: this structure duplicate meaning of sockaddr,
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync * perhaps it'd be better to get rid of it.
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPFlush(VDSOCKET Sock);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSocketCreate */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPSocketCreate(uint32_t fFlags, PVDSOCKET pSock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync * The extended select method is not supported because it is impossible to wakeup
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync * the thread.
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync if (fFlags & VD_INTERFACETCPNET_CONNECT_EXTENDED_SELECT)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync pSocketInt = (PINIPSOCKET)RTMemAllocZ(sizeof(INIPSOCKET));
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSocketCreate */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPSocketDestroy(VDSOCKET Sock)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnClientConnect */
d8c1ea9ddf56bd31af2c314604613d9d695f6e89vboxsyncstatic DECLCALLBACK(int) drvvdINIPClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort,
d8c1ea9ddf56bd31af2c314604613d9d695f6e89vboxsync NOREF(cMillies); /** LwIP doesn't support connect timeout. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /* Check whether lwIP is set up in this VM instance. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* Resolve hostname. As there is no standard resolver for lwIP yet,
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * just accept numeric IP addresses for now. */
1e9e76e4273dcc2e3d560a0f3605c46f0013eb7bvboxsync else /* concatination with if */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync LogRelFunc(("cannot resolve IP %s\n", pszAddress));
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* Create socket and connect. */
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync int iSock = lwip_socket(iInetFamily, SOCK_STREAM, 0);
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync && !lwip_connect(iSock, pSockAddr, pSockAddr->sa_len))
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = VERR_NET_CONNECTION_REFUSED; /* @todo real solution needed */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync 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 */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnIsClientConnected */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(bool) drvvdINIPIsClientConnected(VDSOCKET Sock)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOne */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = lwip_select(pSocketInt->hSock + 1, &fdsetR, NULL, &fdsetE, NULL);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = lwip_select(pSocketInt->hSock + 1, &fdsetR, NULL, &fdsetE, &timeout);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution needed */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnRead */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* 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. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync ssize_t cbBytesRead = lwip_recv(pSocketInt->hSock, (char *)pvBuffer + cbRead,
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution */
59a2c1c0a4a0762b46bc5ff056f5705ec9c0a660vboxsync if (cbBytesRead == 0 && errno) /** @todo r=bird: lwip_recv will not touch errno on Windows. This may apply to other hosts as well */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* return partial data */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* read more? */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnWrite */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /** @todo lwip send only supports up to 65535 bytes in a single
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * send (stupid limitation buried in the code), so make sure we
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * don't get any wraparounds. This should be moved to DevINIP
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * stack interface once that's implemented. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync ssize_t cbWritten = lwip_send(pSocketInt->hSock, (void *)pvBuffer,
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution needed */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync AssertMsg(cbBuffer >= (size_t)cbWritten, ("Wrote more than we requested!!! cbWritten=%d cbBuffer=%d\n",
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync/** @copydoc VDINTERFACETCPNET::pfnSgWrite */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf)
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync /* This is an extremely crude emulation, however it's good enough
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync * for our iSCSI code. INIP has no sendmsg(). */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnFlush */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPFlush(VDSOCKET Sock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync lwip_setsockopt(pSocketInt->hSock, IPPROTO_TCP, TCP_NODELAY,
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync lwip_setsockopt(pSocketInt->hSock, IPPROTO_TCP, TCP_NODELAY,
8dbf70ba2345e69b0b6d45c38cf1add0ef10591cvboxsync/** @copydoc VDINTERFACETCPNET::pfnSetSendCoalescing */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPSetSendCoalescing(VDSOCKET Sock, bool fEnable)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync lwip_setsockopt(pSocketInt->hSock, IPPROTO_TCP, TCP_NODELAY,
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetLocalAddress */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync if (!lwip_getsockname(pSocketInt->hSock, &u.Addr, &cbAddr))
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync * Convert the address.
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync memcpy(&pAddr->uAddr.IPv6, &u.Ipv6.sin6_addr, sizeof(RTNETADDRIPV6));
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetPeerAddress */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync if (!lwip_getpeername(pSocketInt->hSock, &u.Addr, &cbAddr))
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync * Convert the address.
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync memcpy(&pAddr->uAddr.IPv6, &u.Ipv6.sin6_addr, sizeof(RTNETADDRIPV6));
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOneEx */
51a01524909c95ee04b636218b6a89b29fb81825vboxsyncstatic DECLCALLBACK(int) drvvdINIPSelectOneEx(VDSOCKET Sock, uint32_t fEvents, uint32_t *pfEvents, RTMSINTERVAL cMillies)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnPoke */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdINIPPoke(VDSOCKET Sock)
efff36b306e370346025647a158689021df2e1d1vboxsync#endif /* VBOX_WITH_INIP */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/*******************************************************************************
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync* VD TCP network stack interface implementation - Host TCP case *
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync*******************************************************************************/
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync * Socket data.
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 /** Flag whether the thread is waiting in the select call. */
51a01524909c95ee04b636218b6a89b29fb81825vboxsync /** 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);
b0b15690f00527424b2d5fb88456d747252322f7vboxsync Assert(RT_SUCCESS(rc) || rc == VERR_POLL_HANDLE_ID_NOT_FOUND);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTPollSetRemove(pSockInt->hPollSet, VDSOCKET_POLL_ID_PIPE);
a2f96875f61628e5a5fd33785f8c0bbb310f981fvboxsync rc = RTTcpClientCloseEx(pSockInt->hSocket, false /*fGracefulShutdown*/);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnClientConnect */
d8c1ea9ddf56bd31af2c314604613d9d695f6e89vboxsyncstatic DECLCALLBACK(int) drvvdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort,
d8c1ea9ddf56bd31af2c314604613d9d695f6e89vboxsync rc = RTTcpClientConnectEx(pszAddress, uPort, &pSockInt->hSocket, cMillies, NULL);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /* Add to the pollset if required. */
51a01524909c95ee04b636218b6a89b29fb81825vboxsync 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);
a2f96875f61628e5a5fd33785f8c0bbb310f981fvboxsync rc = RTTcpClientCloseEx(pSockInt->hSocket, false /*fGracefulShutdown*/);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnIsClientConnected */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(bool) drvvdTcpIsClientConnected(VDSOCKET Sock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOne */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpSelectOne(pSockInt->hSocket, cMillies);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnRead */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpRead(pSockInt->hSocket, pvBuffer, cbBuffer, pcbRead);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnWrite */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpWrite(pSockInt->hSocket, pvBuffer, cbBuffer);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSgWrite */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf)
51a01524909c95ee04b636218b6a89b29fb81825vboxsync/** @copydoc VDINTERFACETCPNET::pfnReadNB */
51a01524909c95ee04b636218b6a89b29fb81825vboxsyncstatic DECLCALLBACK(int) drvvdTcpReadNB(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead)
51a01524909c95ee04b636218b6a89b29fb81825vboxsync return RTTcpReadNB(pSockInt->hSocket, pvBuffer, cbBuffer, pcbRead);
51a01524909c95ee04b636218b6a89b29fb81825vboxsync/** @copydoc VDINTERFACETCPNET::pfnWriteNB */
51a01524909c95ee04b636218b6a89b29fb81825vboxsyncstatic DECLCALLBACK(int) drvvdTcpWriteNB(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer, size_t *pcbWritten)
51a01524909c95ee04b636218b6a89b29fb81825vboxsync return RTTcpWriteNB(pSockInt->hSocket, pvBuffer, cbBuffer, pcbWritten);
51a01524909c95ee04b636218b6a89b29fb81825vboxsync/** @copydoc VDINTERFACETCPNET::pfnSgWriteNB */
51a01524909c95ee04b636218b6a89b29fb81825vboxsyncstatic DECLCALLBACK(int) drvvdTcpSgWriteNB(VDSOCKET Sock, PRTSGBUF pSgBuf, size_t *pcbWritten)
51a01524909c95ee04b636218b6a89b29fb81825vboxsync return RTTcpSgWriteNB(pSockInt->hSocket, pSgBuf, pcbWritten);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnFlush */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpFlush(VDSOCKET Sock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnSetSendCoalescing */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpSetSendCoalescing(pSockInt->hSocket, fEnable);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetLocalAddress */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpGetLocalAddress(pSockInt->hSocket, pAddr);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetPeerAddress */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync return RTTcpGetPeerAddress(pSockInt->hSocket, pAddr);
b0b15690f00527424b2d5fb88456d747252322f7vboxsyncstatic int drvvdTcpSelectOneExPoll(VDSOCKET Sock, uint32_t fEvents,
51a01524909c95ee04b636218b6a89b29fb81825vboxsync rc = RTPollSetEventsChange(pSockInt->hPollSet, VDSOCKET_POLL_ID_SOCKET, fPollEvents);
51a01524909c95ee04b636218b6a89b29fb81825vboxsync rc = RTPoll(pSockInt->hPollSet, cMillies, &fEventsRecv, &id);
217fa436516d137a409bb493cb7d350898f64666vboxsync Assert((fEventsRecv & RTPOLL_EVT_VALID_MASK) == RTPOLL_EVT_READ);
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync /* We got interrupted, drain the pipe. */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync 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 */
b0b15690f00527424b2d5fb88456d747252322f7vboxsync break; /* Quit */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync/** @copydoc VDINTERFACETCPNET::pfnPoke */
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsyncstatic DECLCALLBACK(int) drvvdTcpPoke(VDSOCKET Sock)
cc15c3fa4bb2d3fb91e4d0cd15a73133963f86b0vboxsync rc = RTPipeWrite(pSockInt->hPipeW, "", 1, &cbWritten);
eeebcc1f7aedfdbcaf7c4dae90ad932d5d9c03c8vboxsync * Checks the prerequisites for encrypted I/O.
eeebcc1f7aedfdbcaf7c4dae90ad932d5d9c03c8vboxsync * @returns VBox status code.
eeebcc1f7aedfdbcaf7c4dae90ad932d5d9c03c8vboxsync * @param pThis The VD driver instance data.
eeebcc1f7aedfdbcaf7c4dae90ad932d5d9c03c8vboxsync pThis->pIfSecKeyHlp->pfnKeyMissingNotify(pThis->pIfSecKeyHlp);
eeebcc1f7aedfdbcaf7c4dae90ad932d5d9c03c8vboxsync int rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/*******************************************************************************
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync* Media interface methods *
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync*******************************************************************************/
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnRead */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(int) drvvdRead(PPDMIMEDIA pInterface,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync LogFlowFunc(("off=%#llx pvBuf=%p cbRead=%d\n", off, pvBuf, cbRead));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /* Can we serve the request from the buffer? */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync size_t cbToCopy = RT_MIN(cbRead, pThis->offDisk + pThis->cbDataValid - off);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync memcpy(pvBuf, pThis->pbData + (off - pThis->offDisk), cbToCopy);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /* Increase request to the buffer size and read. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync pThis->cbDataValid = RT_MIN(pThis->cbDisk - off, pThis->cbBootAccelBuffer);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync rc = VDRead(pThis->pDisk, off, pThis->pbData, pThis->cbDataValid);
a0a5ab4e085a7ee5b95bdfae04cec7de95792c3cvboxsync Log2(("%s: off=%#llx pvBuf=%p cbRead=%d\n%.*Rhxd\n", __FUNCTION__,
1fdf058ef3f645ee13c9957807e401ac3c9bc65bvboxsync/** @copydoc PDMIMEDIA::pfnRead */
1fdf058ef3f645ee13c9957807e401ac3c9bc65bvboxsyncstatic DECLCALLBACK(int) drvvdReadPcBios(PPDMIMEDIA pInterface,
1fdf058ef3f645ee13c9957807e401ac3c9bc65bvboxsync LogFlowFunc(("off=%#llx pvBuf=%p cbRead=%d\n", off, pvBuf, cbRead));
1fdf058ef3f645ee13c9957807e401ac3c9bc65bvboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1fdf058ef3f645ee13c9957807e401ac3c9bc65bvboxsync /* Can we serve the request from the buffer? */
1fdf058ef3f645ee13c9957807e401ac3c9bc65bvboxsync size_t cbToCopy = RT_MIN(cbRead, pThis->offDisk + pThis->cbDataValid - off);
1fdf058ef3f645ee13c9957807e401ac3c9bc65bvboxsync memcpy(pvBuf, pThis->pbData + (off - pThis->offDisk), cbToCopy);
1fdf058ef3f645ee13c9957807e401ac3c9bc65bvboxsync /* Increase request to the buffer size and read. */
1fdf058ef3f645ee13c9957807e401ac3c9bc65bvboxsync pThis->cbDataValid = RT_MIN(pThis->cbDisk - off, pThis->cbBootAccelBuffer);
1fdf058ef3f645ee13c9957807e401ac3c9bc65bvboxsync rc = VDRead(pThis->pDisk, off, pThis->pbData, pThis->cbDataValid);
1fdf058ef3f645ee13c9957807e401ac3c9bc65bvboxsync Log2(("%s: off=%#llx pvBuf=%p cbRead=%d\n%.*Rhxd\n", __FUNCTION__,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnWrite */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(int) drvvdWrite(PPDMIMEDIA pInterface,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync LogFlowFunc(("off=%#llx pvBuf=%p cbWrite=%d\n", off, pvBuf, cbWrite));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
a0a5ab4e085a7ee5b95bdfae04cec7de95792c3cvboxsync Log2(("%s: off=%#llx pvBuf=%p cbWrite=%d\n%.*Rhxd\n", __FUNCTION__,
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /* Invalidate any buffer if boot acceleration is enabled. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnFlush */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(int) drvvdFlush(PPDMIMEDIA pInterface)
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
16a9adc14900ca18e6909679a579f6833425e030vboxsync/** @copydoc PDMIMEDIA::pfnMerge */
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdMerge(PPDMIMEDIA pInterface,
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* Note: There is an unavoidable race between destruction and another
16a9adc14900ca18e6909679a579f6833425e030vboxsync * thread invoking this function. This is handled safely and gracefully by
16a9adc14900ca18e6909679a579f6833425e030vboxsync * atomically invalidating the lock handle in drvvdDestruct. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync int rc2 = RTSemFastMutexRequest(pThis->MergeCompleteMutex);
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* Take shortcut: PFNSIMPLEPROGRESS is exactly the same type as
16a9adc14900ca18e6909679a579f6833425e030vboxsync * PFNVDPROGRESS, so there's no need for a conversion function. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** @todo maybe introduce a conversion which limits update frequency. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc2 = VDInterfaceAdd(&VDIfProgress.Core, "DrvVD_VDIProgress", VDINTERFACETYPE_PROGRESS,
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pvUser, sizeof(VDINTERFACEPROGRESS), &pVDIfsOperation);
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc2 = RTSemFastMutexRelease(pThis->MergeCompleteMutex);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync/** @copydoc PDMIMEDIA::pfnSetKey */
eeebcc1f7aedfdbcaf7c4dae90ad932d5d9c03c8vboxsyncstatic DECLCALLBACK(int) drvvdSetSecKeyIf(PPDMIMEDIA pInterface, PPDMISECKEY pIfSecKey, PPDMISECKEYHLP pIfSecKeyHlp)
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsync /* Unload the crypto filter first to make sure it doesn't access the keys anymore. */
f4fd9b62ec1cb6bb79fc7432a2d1a4c5f7c63bfcvboxsync rc = VDFilterRemove(pThis->pDisk, VD_FILTER_FLAGS_DEFAULT);
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsync rc = VDInterfaceAdd(&pThis->VDIfCfg.Core, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
203cad92999b4792bf61b4b65e1e2abfe08f5664vboxsync pThis->pCfgCrypto, sizeof(VDINTERFACECONFIG), &pVDIfFilter);
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsync rc = VDInterfaceAdd(&pThis->VDIfCrypto.Core, "DrvVD_Crypto", VDINTERFACETYPE_CRYPTO,
c5abe3ea9c7ac6dec34f42af30612534bea951ffvboxsync /* Load the crypt filter plugin. */
f4fd9b62ec1cb6bb79fc7432a2d1a4c5f7c63bfcvboxsync rc = VDFilterAdd(pThis->pDisk, "CRYPT", VD_FILTER_FLAGS_DEFAULT, pVDIfFilter);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnGetSize */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(uint64_t) drvvdGetSize(PPDMIMEDIA pInterface)
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync uint64_t cb = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
e18d16f31765f000e2a4a111a3df6d211cd825f1vboxsync/** @copydoc PDMIMEDIA::pfnGetSectorSize */
e18d16f31765f000e2a4a111a3df6d211cd825f1vboxsyncstatic DECLCALLBACK(uint32_t) drvvdGetSectorSize(PPDMIMEDIA pInterface)
e18d16f31765f000e2a4a111a3df6d211cd825f1vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
99afce7a96e1262ce137aa1fd4d2a911ebd644b1vboxsync uint32_t cb = VDGetSectorSize(pThis->pDisk, VD_LAST_IMAGE);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnIsReadOnly */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(bool) drvvdIsReadOnly(PPDMIMEDIA pInterface)
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync/** @copydoc PDMIMEDIA::pfnBiosGetPCHSGeometry */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(int) drvvdBiosGetPCHSGeometry(PPDMIMEDIA pInterface,
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync int rc = VDGetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync/** @copydoc PDMIMEDIA::pfnBiosSetPCHSGeometry */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(int) drvvdBiosSetPCHSGeometry(PPDMIMEDIA pInterface,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync int rc = VDSetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync/** @copydoc PDMIMEDIA::pfnBiosGetLCHSGeometry */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(int) drvvdBiosGetLCHSGeometry(PPDMIMEDIA pInterface,
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync int rc = VDGetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync/** @copydoc PDMIMEDIA::pfnBiosSetLCHSGeometry */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(int) drvvdBiosSetLCHSGeometry(PPDMIMEDIA pInterface,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync int rc = VDSetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnGetUuid */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(int) drvvdGetUuid(PPDMIMEDIA pInterface, PRTUUID pUuid)
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync LogFlowFunc(("returns %Rrc ({%RTuuid})\n", rc, pUuid));
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncstatic DECLCALLBACK(int) drvvdDiscard(PPDMIMEDIA pInterface, PCRTRANGE paRanges, unsigned cRanges)
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync int rc = VDDiscardRanges(pThis->pDisk, paRanges, cRanges);
47579c4cc64e7dff9b4de48841a2c4df3b96ab38vboxsync/** @copydoc PDMIMEDIA::pfnIoBufAlloc */
47579c4cc64e7dff9b4de48841a2c4df3b96ab38vboxsyncstatic DECLCALLBACK(int) drvvdIoBufAlloc(PPDMIMEDIA pInterface, size_t cb, void **ppvNew)
47579c4cc64e7dff9b4de48841a2c4df3b96ab38vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
47579c4cc64e7dff9b4de48841a2c4df3b96ab38vboxsync /* Configured encryption requires locked down memory. */
1bf320fa7c84120347a65cdbbf4d673f50abdbaevboxsync rc = RTMemSaferAllocZEx(ppvNew, cb, RTMEMSAFER_F_REQUIRE_NOT_PAGABLE);
47579c4cc64e7dff9b4de48841a2c4df3b96ab38vboxsync/** @copydoc PDMIMEDIA::pfnIoBufFree */
47579c4cc64e7dff9b4de48841a2c4df3b96ab38vboxsyncstatic DECLCALLBACK(int) drvvdIoBufFree(PPDMIMEDIA pInterface, void *pv, size_t cb)
47579c4cc64e7dff9b4de48841a2c4df3b96ab38vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
9496f2d398b49813176939d7a339ae513d5175efvboxsync/*******************************************************************************
9496f2d398b49813176939d7a339ae513d5175efvboxsync* Async Media interface methods *
9496f2d398b49813176939d7a339ae513d5175efvboxsync*******************************************************************************/
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsyncstatic void drvvdAsyncReqComplete(void *pvUser1, void *pvUser2, int rcReq)
009d45aa55691312278d41edb20154dc208d9cd8vboxsync int rc = pThis->pDrvMediaAsyncPort->pfnTransferCompleteNotify(pThis->pDrvMediaAsyncPort,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, (PPDMBLKCACHEIOXFER)pvUser2, rcReq);
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsyncstatic DECLCALLBACK(int) drvvdStartRead(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync LogFlowFunc(("uOffset=%#llx paSeg=%#p cSeg=%u cbRead=%d pvUser=%#p\n",
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = VDAsyncRead(pThis->pDisk, uOffset, cbRead, &SgBuf,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = PDMR3BlkCacheRead(pThis->pBlkCache, uOffset, &SgBuf, cbRead, pvUser);
9496f2d398b49813176939d7a339ae513d5175efvboxsyncstatic DECLCALLBACK(int) drvvdStartWrite(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync LogFlowFunc(("uOffset=%#llx paSeg=%#p cSeg=%u cbWrite=%d pvUser=%#p\n",
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = VDAsyncWrite(pThis->pDisk, uOffset, cbWrite, &SgBuf,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = PDMR3BlkCacheWrite(pThis->pBlkCache, uOffset, &SgBuf, cbWrite, pvUser);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncstatic DECLCALLBACK(int) drvvdStartFlush(PPDMIMEDIAASYNC pInterface, void *pvUser)
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = VDAsyncFlush(pThis->pDisk, drvvdAsyncReqComplete, pThis, pvUser);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncstatic DECLCALLBACK(int) drvvdStartDiscard(PPDMIMEDIAASYNC pInterface, PCRTRANGE paRanges,
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync LogFlowFunc(("paRanges=%#p cRanges=%u pvUser=%#p\n",
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync rc = VDAsyncDiscardRanges(pThis->pDisk, paRanges, cRanges, drvvdAsyncReqComplete,
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync 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,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = VDAsyncRead(pThis->pDisk, off, cbXfer, pcSgBuf, drvvdAsyncReqComplete,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = VDAsyncWrite(pThis->pDisk, off, cbXfer, pcSgBuf, drvvdAsyncReqComplete,
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = VDAsyncFlush(pThis->pDisk, drvvdAsyncReqComplete, pThis, hIoXfer);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync AssertMsgFailed(("Invalid transfer type %d\n", enmXferDir));
009d45aa55691312278d41edb20154dc208d9cd8vboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, VINF_SUCCESS);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync else if (RT_FAILURE(rc) && rc != VERR_VD_ASYNC_IO_IN_PROGRESS)
009d45aa55691312278d41edb20154dc208d9cd8vboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, rc);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync/** @copydoc FNPDMBLKCACHEXFERENQUEUEDISCARDDRV */
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncstatic int drvvdBlkCacheXferEnqueueDiscard(PPDMDRVINS pDrvIns, PCRTRANGE paRanges,
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync rc = VDAsyncDiscardRanges(pThis->pDisk, paRanges, cRanges,
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, VINF_SUCCESS);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync else if (RT_FAILURE(rc) && rc != VERR_VD_ASYNC_IO_IN_PROGRESS)
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync PDMR3BlkCacheIoXferComplete(pThis->pBlkCache, hIoXfer, rc);
10e818af327731667e40ed25ee3e70ab5ea2cc4cvboxsync * Loads all configured plugins.
10e818af327731667e40ed25ee3e70ab5ea2cc4cvboxsync * @returns VBox status code.
10e818af327731667e40ed25ee3e70ab5ea2cc4cvboxsync * @param pThis The disk instance.
10e818af327731667e40ed25ee3e70ab5ea2cc4cvboxsync * @param pCfg CFGM node holding plugin list.
10e818af327731667e40ed25ee3e70ab5ea2cc4cvboxsyncstatic int drvvdLoadPlugins(PVBOXDISK pThis, PCFGMNODE pCfg)
10e818af327731667e40ed25ee3e70ab5ea2cc4cvboxsync PCFGMNODE pCfgPlugins = CFGMR3GetChild(pCfg, "Plugins");
10e818af327731667e40ed25ee3e70ab5ea2cc4cvboxsync PCFGMNODE pPluginCur = CFGMR3GetFirstChild(pCfgPlugins);
10e818af327731667e40ed25ee3e70ab5ea2cc4cvboxsync rc = CFGMR3QueryStringAlloc(pPluginCur, "Path", &pszPluginFilename);
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)
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync PCFGMNODE pCfgFilter = CFGMR3GetChild(pCfg, "Filters");
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync PCFGMNODE pCfgFilterConfig = CFGMR3GetChild(pCfgFilter, "VDConfig");
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync rc = CFGMR3QueryStringAlloc(pCfgFilter, "FilterName", &pszFilterName);
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync rc = VDInterfaceAdd(&VDIfConfig.Core, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
baacecc94a2d23b6f5086739c08cf06d6b357d0avboxsync pCfgFilterConfig, sizeof(VDINTERFACECONFIG), &pVDIfsFilter);
f4fd9b62ec1cb6bb79fc7432a2d1a4c5f7c63bfcvboxsync rc = VDFilterAdd(pThis->pDisk, pszFilterName, VD_FILTER_FLAGS_DEFAULT, pVDIfsFilter);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/*******************************************************************************
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync* Base interface methods *
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync*******************************************************************************/
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @interface_method_impl{PDMIBASE,pfnQueryInterface}
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsyncstatic DECLCALLBACK(void *) drvvdQueryInterface(PPDMIBASE pInterface, const char *pszIID)
9daee41d5cb5a2e8390f015a486e67a6cd52b836vboxsync PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
a39ea3668b7019c23a68936259545f9b71bce1aavboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIA, &pThis->IMedia);
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAASYNC, pThis->fAsyncIOSupported ? &pThis->IMediaAsync : NULL);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/*******************************************************************************
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync* Saved state notification methods *
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync*******************************************************************************/
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * Load done callback for re-opening the image writable during teleportation.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * This is called both for successful and failed load runs, we only care about
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * 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? */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/*******************************************************************************
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync* Driver methods *
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync*******************************************************************************/
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)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync 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
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * locks (RTFILE_O_DENY_*). (See also drvvdLoadDone.)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @param pDrvIns The driver instance data.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(void) drvvdSuspend(PPDMDRVINS pDrvIns)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * VM PowerOn notification for undoing the TempReadOnly config option and
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * changing to runtime error mode.
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) drvvdPowerOn(PPDMDRVINS pDrvIns)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync * @copydoc FNPDMDRVRESET
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsyncstatic DECLCALLBACK(void) drvvdReset(PPDMDRVINS pDrvIns)
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @copydoc FNPDMDRVDESTRUCT
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(void) drvvdDestruct(PPDMDRVINS pDrvIns)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
c7ff622115966b69b482bd2896662e40d823b22fvboxsync ASMAtomicXchgHandle(&pThis->MergeCompleteMutex, NIL_RTSEMFASTMUTEX, &mutex);
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* Request the semaphore to wait until a potentially running merge
16a9adc14900ca18e6909679a579f6833425e030vboxsync * operation has been finished. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Construct a VBox disk media driver instance.
cba6719bd64ec749967bbe931230452664109857vboxsync * @copydoc FNPDMDRVCONSTRUCT
1e1273b11e17928ec3c3a8fff45121aa7a169413vboxsyncstatic DECLCALLBACK(int) drvvdConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync char *pszName = NULL; /**< The path of the disk image file. */
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync char *pszFormat = NULL; /**< The format backed to use for this image. */
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync char *pszCachePath = NULL; /**< The path to the cache image. */
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync char *pszCacheFormat = NULL; /**< The format backend to use for the cache image. */
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync bool fReadOnly; /**< True if the media is read-only. */
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync bool fMaybeReadOnly; /**< True if the media may or may not be read-only. */
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync bool fHonorZeroWrites; /**< True if zero blocks should be written. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Init the static parts.
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync pDrvIns->IBase.pfnQueryInterface = drvvdQueryInterface;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* IMedia */
e18d16f31765f000e2a4a111a3df6d211cd825f1vboxsync pThis->IMedia.pfnGetSectorSize = drvvdGetSectorSize;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->IMedia.pfnBiosGetPCHSGeometry = drvvdBiosGetPCHSGeometry;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->IMedia.pfnBiosSetPCHSGeometry = drvvdBiosSetPCHSGeometry;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->IMedia.pfnBiosGetLCHSGeometry = drvvdBiosGetLCHSGeometry;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->IMedia.pfnBiosSetLCHSGeometry = drvvdBiosSetLCHSGeometry;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /* IMediaAsync */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->IMediaAsync.pfnStartWrite = drvvdStartWrite;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync pThis->IMediaAsync.pfnStartFlush = drvvdStartFlush;
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync pThis->IMediaAsync.pfnStartDiscard = drvvdStartDiscard;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /* Initialize supported VD interfaces. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = VDInterfaceAdd(&pThis->VDIfError.Core, "DrvVD_VDIError", VDINTERFACETYPE_ERROR,
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pDrvIns, sizeof(VDINTERFACEERROR), &pThis->pVDIfsDisk);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /* List of images is empty now. */
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync pThis->pDrvMediaPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAPORT);
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE,
9496f2d398b49813176939d7a339ae513d5175efvboxsync /* Try to attach async media port interface above.*/
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync pThis->pDrvMediaAsyncPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAASYNCPORT);
10e818af327731667e40ed25ee3e70ab5ea2cc4cvboxsync /* Before we access any VD API load all given plugins. */
10e818af327731667e40ed25ee3e70ab5ea2cc4cvboxsync return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Loading VD plugins failed"));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Validate configuration and find all parent images.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * It's sort of up side down from the image dependency tree.
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync bool fHostIP = false;
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync /* Toplevel configuration additionally contains the global image
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync * open flags. Some might be converted to per-image flags later. */
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync "Format\0Path\0"
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync "ReadOnly\0MaybeReadOnly\0TempReadOnly\0Shareable\0HonorZeroWrites\0"
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync "HostIPStack\0UseNewIo\0BootAcceleration\0BootAccelerationBuffer\0"
009d45aa55691312278d41edb20154dc208d9cd8vboxsync "SetupMerge\0MergeSource\0MergeTarget\0BwGroup\0Type\0BlockCache\0"
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync "CachePath\0CacheFormat\0Discard\0InformAboutZeroBlocks\0"
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync "SkipConsistencyChecks\0");
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync /* All other image configurations only contain image name and
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync * the format information. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync fValid = CFGMR3AreValuesValid(pCurNode, "Format\0Path\0"
16a9adc14900ca18e6909679a579f6833425e030vboxsync "MergeSource\0MergeTarget\0");
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync RT_SRC_POS, N_("DrvVD: Configuration error: keys incorrect at level %d"), iLevel);
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync rc = CFGMR3QueryBoolDef(pCurNode, "HostIPStack", &fHostIP, true);
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync N_("DrvVD: Configuration error: Querying \"HostIPStack\" as boolean failed"));
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync rc = CFGMR3QueryBoolDef(pCurNode, "HonorZeroWrites", &fHonorZeroWrites, false);
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync N_("DrvVD: Configuration error: Querying \"HonorZeroWrites\" as boolean failed"));
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync rc = CFGMR3QueryBoolDef(pCurNode, "ReadOnly", &fReadOnly, false);
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync N_("DrvVD: Configuration error: Querying \"ReadOnly\" as boolean failed"));
24a0cc1776a88752cc25446a98e2a3881e623216vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "MaybeReadOnly", &fMaybeReadOnly, false);
24a0cc1776a88752cc25446a98e2a3881e623216vboxsync N_("DrvVD: Configuration error: Querying \"MaybeReadOnly\" as boolean failed"));
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync rc = CFGMR3QueryBoolDef(pCurNode, "TempReadOnly", &pThis->fTempReadOnly, false);
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync N_("DrvVD: Configuration error: Querying \"TempReadOnly\" as boolean failed"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"TempReadOnly\" are set"));
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "Shareable", &pThis->fShareable, false);
61d064a54f03596920c3918f58ecc7764074a5d8vboxsync N_("DrvVD: Configuration error: Querying \"Shareable\" as boolean failed"));
44fc72ff17b23a9b970505fcf8d6da1019ddcec5vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "UseNewIo", &fUseNewIo, false);
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync N_("DrvVD: Configuration error: Querying \"UseNewIo\" as boolean failed"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "SetupMerge", &pThis->fMergePending, false);
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Querying \"SetupMerge\" as boolean failed"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"MergePending\" are set"));
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "BootAcceleration", &pThis->fBootAccelEnabled, false);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync N_("DrvVD: Configuration error: Querying \"BootAcceleration\" as boolean failed"));
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync rc = CFGMR3QueryU32Def(pCurNode, "BootAccelerationBuffer", (uint32_t *)&pThis->cbBootAccelBuffer, 16 * _1K);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync N_("DrvVD: Configuration error: Querying \"BootAccelerationBuffer\" as integer failed"));
009d45aa55691312278d41edb20154dc208d9cd8vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "BlockCache", &fUseBlockCache, false);
009d45aa55691312278d41edb20154dc208d9cd8vboxsync N_("DrvVD: Configuration error: Querying \"BlockCache\" as boolean failed"));
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "BwGroup", &pThis->pszBwGroup);
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND)
b5ad839a3757b305d4e98d7264da2b53c9cd27f0vboxsync N_("DrvVD: Configuration error: Querying \"BwGroup\" as string failed"));
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "Discard", &fDiscard, false);
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync N_("DrvVD: Configuration error: Querying \"Discard\" as boolean failed"));
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"Discard\" are set"));
c13422b6c2690d4243041112362ef95e0ac23e79vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "InformAboutZeroBlocks", &fInformAboutZeroBlocks, false);
4bc80d07c812dc7ce2b5a329b489cfdb722c9013vboxsync N_("DrvVD: Configuration error: Querying \"InformAboutZeroBlocks\" as boolean failed"));
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "SkipConsistencyChecks", &fSkipConsistencyChecks, true);
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync N_("DrvVD: Configuration error: Querying \"SKipConsistencyChecks\" as boolean failed"));
ee00a0b29854e7f513198772bccb6650f6dd2184vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_BLOCK_NO_TYPE, N_("Failed to obtain the type"));
ee00a0b29854e7f513198772bccb6650f6dd2184vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_BLOCK_UNKNOWN_TYPE, RT_SRC_POS,
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "CachePath", &pszCachePath);
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND)
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync N_("DrvVD: Configuration error: Querying \"CachePath\" as string failed"));
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "CacheFormat", &pszCacheFormat);
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync N_("DrvVD: Configuration error: Querying \"CacheFormat\" as string failed"));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PCFGMNODE pParent = CFGMR3GetChild(pCurNode, "Parent");
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Create the image container and the necessary interfaces.
61b5982fad4660d0fe3dd6ceba9eda85eb32f7e8vboxsync * The image has a bandwidth group but the host cache is enabled.
61b5982fad4660d0fe3dd6ceba9eda85eb32f7e8vboxsync * Use the async I/O framework but tell it to enable the host cache.
c8cedf818a53e003ce5a59c552d2f15c1b51f64cvboxsync /** @todo quick hack to work around problems in the async I/O
c8cedf818a53e003ce5a59c552d2f15c1b51f64cvboxsync * implementation (rw semaphore thread ownership problem)
c8cedf818a53e003ce5a59c552d2f15c1b51f64cvboxsync * while a merge is running. Remove once this is fixed. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = RTSemFastMutexCreate(&pThis->MergeCompleteMutex);
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfThreadSync.pfnStartRead = drvvdThreadStartRead;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfThreadSync.pfnFinishRead = drvvdThreadFinishRead;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfThreadSync.pfnStartWrite = drvvdThreadStartWrite;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfThreadSync.pfnFinishWrite = drvvdThreadFinishWrite;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = VDInterfaceAdd(&pThis->VDIfThreadSync.Core, "DrvVD_ThreadSync", VDINTERFACETYPE_THREADSYNC,
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis, sizeof(VDINTERFACETHREADSYNC), &pThis->pVDIfsDisk);
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Failed to create semaphores for \"MergePending\""));
ee00a0b29854e7f513198772bccb6650f6dd2184vboxsync rc = VDCreate(pThis->pVDIfsDisk, enmType, &pThis->pDisk);
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync /* Error message is already set correctly. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /* Allocate per-image data. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Read the image configuration.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "Path", &pszName);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync N_("DrvVD: Configuration error: Querying \"Path\" as string failed"));
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "Format", &pszFormat);
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync 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"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Multiple \"MergeSource\" occurrences"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = CFGMR3QueryBoolDef(pCurNode, "MergeTarget", &fMergeTarget, false);
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Querying \"MergeTarget\" as boolean failed"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Multiple \"MergeTarget\" occurrences"));
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync PCFGMNODE pCfgVDConfig = CFGMR3GetChild(pCurNode, "VDConfig");
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync 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);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync /* Check VDConfig for encryption config. */
203cad92999b4792bf61b4b65e1e2abfe08f5664vboxsync pThis->pCfgCrypto = CFGMR3GetChild(pCfgVDConfig, "CRYPT");
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync /* Setup VDConfig interface for disk encryption support. */
203cad92999b4792bf61b4b65e1e2abfe08f5664vboxsync pThis->VDIfCfg.pfnAreKeysValid = drvvdCfgAreKeysValid;
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync pThis->VDIfCrypto.pfnKeyRetain = drvvdCryptoKeyRetain;
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync pThis->VDIfCrypto.pfnKeyRelease = drvvdCryptoKeyRelease;
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync pThis->VDIfCrypto.pfnKeyStorePasswordRetain = drvvdCryptoKeyStorePasswordRetain;
d1aab951b0bd1de1a8a51daca46fce06daaed8d7vboxsync pThis->VDIfCrypto.pfnKeyStorePasswordRelease = drvvdCryptoKeyStorePasswordRelease;
c0a370e600bb60153a269fb32b5f709347c35768vboxsync /* Unconditionally insert the TCPNET interface, don't bother to check
c0a370e600bb60153a269fb32b5f709347c35768vboxsync * if an image really needs it. Will be ignored. Since the TCPNET
c0a370e600bb60153a269fb32b5f709347c35768vboxsync * interface is per image we could make this more flexible in the
c0a370e600bb60153a269fb32b5f709347c35768vboxsync * 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
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * TCP backends badly. Provide a different select method without
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * using poll on XP.
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * This is only used on XP because it is not as efficient as the one using poll
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * 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 */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSocketCreate = drvvdINIPSocketCreate;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSocketDestroy = drvvdINIPSocketDestroy;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnClientConnect = drvvdINIPClientConnect;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnClientClose = drvvdINIPClientClose;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnIsClientConnected = drvvdINIPIsClientConnected;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSelectOne = drvvdINIPSelectOne;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSetSendCoalescing = drvvdINIPSetSendCoalescing;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnGetLocalAddress = drvvdINIPGetLocalAddress;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnGetPeerAddress = drvvdINIPGetPeerAddress;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfTcpNet.pfnSelectOneEx = drvvdINIPSelectOneEx;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync#endif /* VBOX_WITH_INIP */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = VDInterfaceAdd(&pImage->VDIfTcpNet.Core, "DrvVD_TCPNET",
c0a370e600bb60153a269fb32b5f709347c35768vboxsync /* Insert the custom I/O interface only if we're told to use new IO.
c0a370e600bb60153a269fb32b5f709347c35768vboxsync * Since the I/O interface is per image we could make this more
c0a370e600bb60153a269fb32b5f709347c35768vboxsync * flexible in the future if we want to. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfIo.pfnWriteSync = drvvdAsyncIOWriteSync;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfIo.pfnFlushSync = drvvdAsyncIOFlushSync;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfIo.pfnReadAsync = drvvdAsyncIOReadAsync;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfIo.pfnWriteAsync = drvvdAsyncIOWriteAsync;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pImage->VDIfIo.pfnFlushAsync = drvvdAsyncIOFlushAsync;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync#else /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync RT_SRC_POS, N_("DrvVD: Configuration error: Async Completion Framework not compiled in"));
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync#endif /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = VDInterfaceAdd(&pImage->VDIfIo.Core, "DrvVD_IO", VDINTERFACETYPE_IO,
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis, sizeof(VDINTERFACEIO), &pImage->pVDIfsImage);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Open the image.
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync if (fReadOnly || pThis->fTempReadOnly || iLevel != 0)
c13422b6c2690d4243041112362ef95e0ac23e79vboxsync uOpenFlags |= VD_OPEN_FLAGS_INFORM_ABOUT_ZERO_BLOCKS;
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync uOpenFlags |= VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS;
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync /* Try to open backend in async I/O mode first. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
e2ebb3d022edb845fd1158d6338e3def1d0e2159vboxsync rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
1189c7dde5d7f6c26f338ced3d40fc830b822e68vboxsync VDIsReadOnly(pThis->pDisk) ? "read-only" : "read-write"));
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_VD_IMAGE_READ_ONLY, RT_SRC_POS,
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync N_("Failed to open image '%s' for writing due to wrong permissions"),
fdab0fffeebe7ad5dfee549841f0c5482de95c34vboxsync N_("Failed to open image '%s' in %s mode"), pszName,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync (uOpenFlags & VD_OPEN_FLAGS_READONLY) ? "read-only" : "read-write", rc);
6437cb19ad6d607a74ccf8d8f25c7e7af761b316vboxsync LogRel(("VD: Opening the disk took %lld ns\n", RTTimeNanoTS() - tsStart));
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync /* Open the cache image if set. */
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync /* Insert the custom I/O interface only if we're told to use new IO.
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync * Since the I/O interface is per image we could make this more
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync * flexible in the future if we want to. */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfIoCache.pfnGetSize = drvvdAsyncIOGetSize;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfIoCache.pfnSetSize = drvvdAsyncIOSetSize;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfIoCache.pfnReadSync = drvvdAsyncIOReadSync;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfIoCache.pfnWriteSync = drvvdAsyncIOWriteSync;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfIoCache.pfnFlushSync = drvvdAsyncIOFlushSync;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfIoCache.pfnReadAsync = drvvdAsyncIOReadAsync;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfIoCache.pfnWriteAsync = drvvdAsyncIOWriteAsync;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis->VDIfIoCache.pfnFlushAsync = drvvdAsyncIOFlushAsync;
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync#else /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync RT_SRC_POS, N_("DrvVD: Configuration error: Async Completion Framework not compiled in"));
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync#endif /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync rc = VDInterfaceAdd(&pThis->VDIfIoCache.Core, "DrvVD_IO", VDINTERFACETYPE_IO,
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync pThis, sizeof(VDINTERFACEIO), &pThis->pVDIfsCache);
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync rc = VDCacheOpen(pThis->pDisk, pszCacheFormat, pszCachePath, VD_OPEN_FLAGS_NORMAL, pThis->pVDIfsCache);
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, rc, N_("DrvVD: Could not open cache image"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
16a9adc14900ca18e6909679a579f6833425e030vboxsync N_("DrvVD: Configuration error: Inconsistent image merge data"));
009d45aa55691312278d41edb20154dc208d9cd8vboxsync /* Create the block cache if enabled. */
203cad92999b4792bf61b4b65e1e2abfe08f5664vboxsync && !pThis->pCfgCrypto /* Disk encryption disables the block cache for security reasons */
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * We need a unique ID for the block cache (to identify the owner of data
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * blocks in a saved state). UUIDs are not really suitable because
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * there are image formats which don't support them. Furthermore it is
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * possible that a new diff image was attached after a saved state
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * which changes the UUID.
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * However the device "name + device instance + LUN" triple the disk is
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * attached to is always constant for saved states.
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync rc = pThis->pDrvMediaPort->pfnQueryDeviceLocation(pThis->pDrvMediaPort, &pcszController,
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync N_("DrvVD: Configuration error: Could not query device data"));
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync int cbStr = RTStrAPrintf(&pszId, "%s-%d-%d", pcszController, iInstance, iLUN);
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync rc = PDMDrvHlpBlkCacheRetain(pDrvIns, &pThis->pBlkCache,
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync N_("DrvVD: Out of memory when creating block cache"));
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * Register a load-done callback so we can undo TempReadOnly config before
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * we get to drvvdResume. Autoamtically deregistered upon destruction.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = PDMDrvHlpSSMRegisterEx(pDrvIns, 0 /* version */, 0 /* cbGuess */,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync NULL /*pfnLivePrep*/, NULL /*pfnLiveExec*/, NULL /*pfnLiveVote*/,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync NULL /*pfnSavePrep*/, NULL /*pfnSaveExec*/, NULL /*pfnSaveDone*/,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync NULL /*pfnDonePrep*/, NULL /*pfnLoadExec*/, drvvdLoadDone);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync /* Setup the boot acceleration stuff if enabled. */
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync pThis->cbDisk = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync pThis->pbData = (uint8_t *)RTMemAllocZ(pThis->cbBootAccelBuffer);
63c12491acc2b8b95c8ac454f1c48b98eec8f7d8vboxsync LogRel(("VD: Boot acceleration, out of memory, disabled\n"));
4a23807f02e9920d92c8449bd93d84501add460avboxsync /* drvvdDestruct does the rest. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * VBox disk container media driver registration record.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* u32Version */
5b465a7c1237993faf8bb50120d247f3f0319adavboxsync /* szName */
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync /* szRCMod */
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync /* szR0Mod */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* pszDescription */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync "Generic VBox disk media driver.",
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* fFlags */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* fClass. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* cMaxInstances */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* cbInstance */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* pfnConstruct */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* pfnDestruct */
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync /* pfnRelocate */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* pfnIOCtl */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* pfnPowerOn */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* pfnReset */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* pfnSuspend */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* pfnResume */
cba6719bd64ec749967bbe931230452664109857vboxsync /* pfnAttach */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* pfnDetach */
9496f2d398b49813176939d7a339ae513d5175efvboxsync /* pfnPowerOff */
cba6719bd64ec749967bbe931230452664109857vboxsync /* pfnSoftReset */
cba6719bd64ec749967bbe931230452664109857vboxsync /* u32EndVersion */