DrvVD.cpp revision 1189c7dde5d7f6c26f338ced3d40fc830b822e68
77b1a2d8b5dbe2c0b5200794914239fee3c8ee5dvboxsync/* $Id$ */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @file
77b1a2d8b5dbe2c0b5200794914239fee3c8ee5dvboxsync * DrvVD - Generic VBox disk media driver.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/*
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync * Copyright (C) 2006-2010 Oracle Corporation
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync *
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.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync */
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync/*******************************************************************************
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync* Header files *
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync*******************************************************************************/
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#define LOG_GROUP LOG_GROUP_DRV_VD
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#include <VBox/VBoxHDD.h>
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#include <VBox/pdmdrv.h>
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#include <VBox/pdmasynccompletion.h>
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#include <iprt/asm.h>
662d52947eeb3fc8fca3b23991a5eee47077f896vboxsync#include <iprt/alloc.h>
da957c069c2a3c582fe265ff88170ce4c42b499dvboxsync#include <iprt/assert.h>
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync#include <iprt/uuid.h>
16a9adc14900ca18e6909679a579f6833425e030vboxsync#include <iprt/file.h>
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#include <iprt/string.h>
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#include <iprt/tcp.h>
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#include <iprt/semaphore.h>
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#include <iprt/sg.h>
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#include <iprt/poll.h>
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync#include <iprt/pipe.h>
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync#include <iprt/system.h>
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync#ifdef VBOX_WITH_INIP
efff36b306e370346025647a158689021df2e1d1vboxsync/* All lwip header files are not C++ safe. So hack around this. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncRT_C_DECLS_BEGIN
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync#include <lwip/inet.h>
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync#include <lwip/tcp.h>
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync#include <lwip/sockets.h>
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncRT_C_DECLS_END
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync#endif /* VBOX_WITH_INIP */
efff36b306e370346025647a158689021df2e1d1vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#include "Builtins.h"
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#ifdef VBOX_WITH_INIP
efff36b306e370346025647a158689021df2e1d1vboxsync/* Small hack to get at lwIP initialized status */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncextern bool DevINIPConfigured(void);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync#endif /* VBOX_WITH_INIP */
efff36b306e370346025647a158689021df2e1d1vboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/*******************************************************************************
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync* Defined types, constants and macros *
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync*******************************************************************************/
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** Converts a pointer to VBOXDISK::IMedia to a PVBOXDISK. */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync#define PDMIMEDIA_2_VBOXDISK(pInterface) \
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync ( (PVBOXDISK)((uintptr_t)pInterface - RT_OFFSETOF(VBOXDISK, IMedia)) )
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** Converts a pointer to PDMDRVINS::IBase to a PPDMDRVINS. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#define PDMIBASE_2_DRVINS(pInterface) \
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync ( (PPDMDRVINS)((uintptr_t)pInterface - RT_OFFSETOF(PDMDRVINS, IBase)) )
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** Converts a pointer to PDMDRVINS::IBase to a PVBOXDISK. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#define PDMIBASE_2_VBOXDISK(pInterface) \
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync ( PDMINS_2_DATA(PDMIBASE_2_DRVINS(pInterface), PVBOXDISK) )
0abd77741a608f6c41c8dfcd4781b8b84adf1044vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** Converts a pointer to VBOXDISK::IMediaAsync to a PVBOXDISK. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync#define PDMIMEDIAASYNC_2_VBOXDISK(pInterface) \
9496f2d398b49813176939d7a339ae513d5175efvboxsync ( (PVBOXDISK)((uintptr_t)pInterface - RT_OFFSETOF(VBOXDISK, IMediaAsync)) )
9496f2d398b49813176939d7a339ae513d5175efvboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync/**
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * VBox disk container, image information, private part.
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsynctypedef struct VBOXIMAGE
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync{
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Pointer to next image. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync struct VBOXIMAGE *pNext;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Pointer to list of VD interfaces. Per-image. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync PVDINTERFACE pVDIfsImage;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Common structure for the configuration information interface. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync VDINTERFACE VDIConfig;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync} VBOXIMAGE, *PVBOXIMAGE;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync/**
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync * Storage backend data.
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsynctypedef struct DRVVDSTORAGEBACKEND
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync{
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /** PDM async completion end point. */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PPDMASYNCCOMPLETIONENDPOINT pEndpoint;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /** The template. */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PPDMASYNCCOMPLETIONTEMPLATE pTemplate;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /** Event semaphore for synchronous operations. */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync RTSEMEVENT EventSem;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /** Flag whether a synchronous operation is currently pending. */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync volatile bool fSyncIoPending;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /** Return code of the last completed request. */
7766bf675357fd940d8c49e69a5d72dc6eaa6be4vboxsync int rcReqLast;
7766bf675357fd940d8c49e69a5d72dc6eaa6be4vboxsync /** Callback routine */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PFNVDCOMPLETED pfnCompleted;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync /** Pointer to the optional thread synchronization interface of the disk. */
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync PVDINTERFACE pInterfaceThreadSync;
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync /** Pointer to the optional thread synchronization callbacks of the disk. */
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync PVDINTERFACETHREADSYNC pInterfaceThreadSyncCallbacks;
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync} DRVVDSTORAGEBACKEND, *PDRVVDSTORAGEBACKEND;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync/**
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * VBox disk container media main structure, private part.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync *
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMIMEDIA
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMIMEDIAASYNC
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements VDINTERFACEERROR
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements VDINTERFACETCPNET
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements VDINTERFACEASYNCIO
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements VDINTERFACECONFIG
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsynctypedef struct VBOXDISK
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync{
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /** The VBox disk container. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXHDD pDisk;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** The media interface. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PDMIMEDIA IMedia;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Pointer to the driver instance. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PPDMDRVINS pDrvIns;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Flag whether suspend has changed image open mode to read only. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync bool fTempReadOnly;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Flag whether to use the runtime (true) or startup error facility. */
21029597fc4b76d0db0c9542daee201447281781vboxsync bool fErrorUseRuntime;
21029597fc4b76d0db0c9542daee201447281781vboxsync /** Pointer to list of VD interfaces. Per-disk. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync PVDINTERFACE pVDIfsDisk;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Common structure for the supported error interface. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync VDINTERFACE VDIError;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Callback table for error interface. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync VDINTERFACEERROR VDIErrorCallbacks;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Common structure for the supported TCP network stack interface. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync VDINTERFACE VDITcpNet;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /** Callback table for TCP network stack interface. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync VDINTERFACETCPNET VDITcpNetCallbacks;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /** Common structure for the supported async I/O interface. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync VDINTERFACE VDIAsyncIO;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Callback table for async I/O interface. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync VDINTERFACEASYNCIO VDIAsyncIOCallbacks;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Common structure for the supported thread synchronization interface. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync VDINTERFACE VDIThreadSync;
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Callback table for thread synchronization interface. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync VDINTERFACETHREADSYNC VDIThreadSyncCallbacks;
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Callback table for the configuration information interface. */
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync VDINTERFACECONFIG VDIConfigCallbacks;
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync /** Flag whether opened disk suppports async I/O operations. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync bool fAsyncIOSupported;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** The async media interface. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync PDMIMEDIAASYNC IMediaAsync;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** The async media port interface above. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync PPDMIMEDIAASYNCPORT pDrvMediaAsyncPort;
9496f2d398b49813176939d7a339ae513d5175efvboxsync /** Pointer to the list of data we need to keep per image. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync PVBOXIMAGE pImages;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Flag whether the media should allow concurrent open for writing. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync bool fShareable;
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Flag whether a merge operation has been set up. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync bool fMergePending;
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Synchronization to prevent destruction before merge finishes. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync RTSEMFASTMUTEX MergeCompleteMutex;
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Synchronization between merge and other image accesses. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync RTSEMRW MergeLock;
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Source image index for merging. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync unsigned uMergeSource;
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** Target image index for merging. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync unsigned uMergeTarget;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /** Flag whether boot acceleration is enabled. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync bool fBootAccelEnabled;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /** Flag whether boot acceleration is currently active. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync bool fBootAccelActive;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /** Size of the disk, used for read truncation. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync size_t cbDisk;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Size of the configured buffer. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync size_t cbBootAccelBuffer;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Start offset for which the buffer holds data. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync uint64_t offDisk;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** Number of valid bytes in the buffer. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync size_t cbDataValid;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync /** The disk buffer. */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync uint8_t *pbData;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync} VBOXDISK, *PVBOXDISK;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync/*******************************************************************************
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync* Internal Functions *
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync*******************************************************************************/
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync/**
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * Internal: allocate new image descriptor and put it in the list
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsyncstatic PVBOXIMAGE drvvdNewImage(PVBOXDISK pThis)
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync{
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync AssertPtr(pThis);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync PVBOXIMAGE pImage = (PVBOXIMAGE)RTMemAllocZ(sizeof(VBOXIMAGE));
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync if (pImage)
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync {
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync pImage->pVDIfsImage = NULL;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync PVBOXIMAGE *pp = &pThis->pImages;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync while (*pp != NULL)
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync pp = &(*pp)->pNext;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync *pp = pImage;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync pImage->pNext = NULL;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync }
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return pImage;
16a9adc14900ca18e6909679a579f6833425e030vboxsync}
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync/**
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Internal: free the list of images descriptors.
16a9adc14900ca18e6909679a579f6833425e030vboxsync */
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic void drvvdFreeImages(PVBOXDISK pThis)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync while (pThis->pImages != NULL)
16a9adc14900ca18e6909679a579f6833425e030vboxsync {
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXIMAGE p = pThis->pImages;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pThis->pImages = pThis->pImages->pNext;
16a9adc14900ca18e6909679a579f6833425e030vboxsync RTMemFree(p);
16a9adc14900ca18e6909679a579f6833425e030vboxsync }
16a9adc14900ca18e6909679a579f6833425e030vboxsync}
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync/**
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Make the image temporarily read-only.
16a9adc14900ca18e6909679a579f6833425e030vboxsync *
16a9adc14900ca18e6909679a579f6833425e030vboxsync * @returns VBox status code.
16a9adc14900ca18e6909679a579f6833425e030vboxsync * @param pThis The driver instance data.
16a9adc14900ca18e6909679a579f6833425e030vboxsync */
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic int drvvdSetReadonly(PVBOXDISK pThis)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync int rc = VINF_SUCCESS;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync if (!VDIsReadOnly(pThis->pDisk))
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync {
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync unsigned uOpenFlags;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDGetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, &uOpenFlags);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync AssertRC(rc);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync uOpenFlags |= VD_OPEN_FLAGS_READONLY;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDSetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, uOpenFlags);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync AssertRC(rc);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync pThis->fTempReadOnly = true;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync }
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return rc;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/**
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * Undo the temporary read-only status of the image.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync *
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @returns VBox status code.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @param pThis The driver instance data.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic int drvvdSetWritable(PVBOXDISK pThis)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync int rc = VINF_SUCCESS;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync if (pThis->fTempReadOnly)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync {
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync unsigned uOpenFlags;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDGetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, &uOpenFlags);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync AssertRC(rc);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync uOpenFlags &= ~VD_OPEN_FLAGS_READONLY;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = VDSetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, uOpenFlags);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync if (RT_SUCCESS(rc))
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync pThis->fTempReadOnly = false;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync else
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync AssertRC(rc);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync }
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return rc;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
a9d49c8f2b28a72e6a4db86eee91e4569290157bvboxsync
a9d49c8f2b28a72e6a4db86eee91e4569290157bvboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/*******************************************************************************
a9d49c8f2b28a72e6a4db86eee91e4569290157bvboxsync* Error reporting callback *
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync*******************************************************************************/
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsyncstatic void drvvdErrorCallback(void *pvUser, int rc, RT_SRC_POS_DECL,
9496f2d398b49813176939d7a339ae513d5175efvboxsync const char *pszFormat, va_list va)
9496f2d398b49813176939d7a339ae513d5175efvboxsync{
9496f2d398b49813176939d7a339ae513d5175efvboxsync PPDMDRVINS pDrvIns = (PPDMDRVINS)pvUser;
59d7f5939d42ad9d344fbad8401e00a900db92c5vboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
59d7f5939d42ad9d344fbad8401e00a900db92c5vboxsync if (pThis->fErrorUseRuntime)
22ec733a5e041fcdfe02fce2eafc9faf8b0077ddvboxsync /* We must not pass VMSETRTERR_FLAGS_FATAL as it could lead to a
9496f2d398b49813176939d7a339ae513d5175efvboxsync * deadlock: We are probably executed in a thread context != EMT
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync * and the EM thread would wait until every thread is suspended
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync * but we would wait for the EM thread ... */
9496f2d398b49813176939d7a339ae513d5175efvboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDMDrvHlpVMSetRuntimeErrorV(pDrvIns, /* fFlags=*/ 0, "DrvVD", pszFormat, va);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync else
7766bf675357fd940d8c49e69a5d72dc6eaa6be4vboxsync PDMDrvHlpVMSetErrorV(pDrvIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
5d0d754550d06b7d59a935e59caaf814462d53ccvboxsync}
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync/*******************************************************************************
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync* VD Async I/O interface implementation *
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync*******************************************************************************/
d5ea45cc92d7f1d3ade8189944531f665bfe8ed5vboxsync
5d0d754550d06b7d59a935e59caaf814462d53ccvboxsync#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
d5ea45cc92d7f1d3ade8189944531f665bfe8ed5vboxsync
d5ea45cc92d7f1d3ade8189944531f665bfe8ed5vboxsyncstatic DECLCALLBACK(void) drvvdAsyncTaskCompleted(PPDMDRVINS pDrvIns, void *pvTemplateUser, void *pvUser, int rcReq)
d5ea45cc92d7f1d3ade8189944531f665bfe8ed5vboxsync{
5d0d754550d06b7d59a935e59caaf814462d53ccvboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pvTemplateUser;
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync LogFlowFunc(("pDrvIns=%#p pvTemplateUser=%#p pvUser=%#p rcReq\n",
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync pDrvIns, pvTemplateUser, pvUser, rcReq));
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync if (pStorageBackend->fSyncIoPending)
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync {
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync Assert(!pvUser);
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync pStorageBackend->rcReqLast = rcReq;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync pStorageBackend->fSyncIoPending = false;
9496f2d398b49813176939d7a339ae513d5175efvboxsync RTSemEventSignal(pStorageBackend->EventSem);
9496f2d398b49813176939d7a339ae513d5175efvboxsync }
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync else
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync {
468c2bcb36eb9a032f5dd0fcb34db10bd58e9996vboxsync int rc;
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync AssertPtr(pvUser);
9496f2d398b49813176939d7a339ae513d5175efvboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync AssertPtr(pStorageBackend->pfnCompleted);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync rc = pStorageBackend->pfnCompleted(pvUser, rcReq);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync AssertRC(rc);
9496f2d398b49813176939d7a339ae513d5175efvboxsync }
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync}
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOOpen(void *pvUser, const char *pszLocation,
7766bf675357fd940d8c49e69a5d72dc6eaa6be4vboxsync uint32_t fOpen,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PFNVDCOMPLETED pfnCompleted,
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync PVDINTERFACE pVDIfsDisk,
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync void **ppStorage)
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync{
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)RTMemAllocZ(sizeof(DRVVDSTORAGEBACKEND));
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync int rc = VINF_SUCCESS;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
ffbe6daf773e38167f3cabaf1f063d84ecd063e9vboxsync if (pStorageBackend)
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync {
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync pStorageBackend->fSyncIoPending = false;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pStorageBackend->rcReqLast = VINF_SUCCESS;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync pStorageBackend->pfnCompleted = pfnCompleted;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync pStorageBackend->pInterfaceThreadSync = NULL;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync pStorageBackend->pInterfaceThreadSyncCallbacks = NULL;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
5d0d754550d06b7d59a935e59caaf814462d53ccvboxsync pStorageBackend->pInterfaceThreadSync = VDInterfaceGet(pVDIfsDisk, VDINTERFACETYPE_THREADSYNC);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync if (RT_UNLIKELY(pStorageBackend->pInterfaceThreadSync))
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync pStorageBackend->pInterfaceThreadSyncCallbacks = VDGetInterfaceThreadSync(pStorageBackend->pInterfaceThreadSync);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync rc = RTSemEventCreate(&pStorageBackend->EventSem);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync if (RT_SUCCESS(rc))
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync {
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync rc = PDMDrvHlpAsyncCompletionTemplateCreate(pThis->pDrvIns, &pStorageBackend->pTemplate,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync drvvdAsyncTaskCompleted, pStorageBackend, "AsyncTaskCompleted");
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync if (RT_SUCCESS(rc))
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync {
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync uint32_t fFlags = (fOpen & RTFILE_O_ACCESS_MASK) == RTFILE_O_READ
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync ? PDMACEP_FILE_FLAGS_READ_ONLY | PDMACEP_FILE_FLAGS_CACHING
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync : 0;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync if (pThis->fShareable)
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync {
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync Assert((fOpen & RTFILE_O_DENY_MASK) == RTFILE_O_DENY_NONE);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync fFlags |= PDMACEP_FILE_FLAGS_DONT_LOCK;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync }
9496f2d398b49813176939d7a339ae513d5175efvboxsync else
9496f2d398b49813176939d7a339ae513d5175efvboxsync fFlags |= PDMACEP_FILE_FLAGS_CACHING;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync rc = PDMR3AsyncCompletionEpCreateForFile(&pStorageBackend->pEndpoint,
9496f2d398b49813176939d7a339ae513d5175efvboxsync pszLocation, fFlags,
16a9adc14900ca18e6909679a579f6833425e030vboxsync pStorageBackend->pTemplate);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync if (RT_SUCCESS(rc))
9496f2d398b49813176939d7a339ae513d5175efvboxsync {
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync *ppStorage = pStorageBackend;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync return VINF_SUCCESS;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync }
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync PDMR3AsyncCompletionTemplateDestroy(pStorageBackend->pTemplate);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync }
9496f2d398b49813176939d7a339ae513d5175efvboxsync RTSemEventDestroy(pStorageBackend->EventSem);
9496f2d398b49813176939d7a339ae513d5175efvboxsync }
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync RTMemFree(pStorageBackend);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync }
9496f2d398b49813176939d7a339ae513d5175efvboxsync else
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = VERR_NO_MEMORY;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync return rc;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync}
9496f2d398b49813176939d7a339ae513d5175efvboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOClose(void *pvUser, void *pStorage)
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync{
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
9496f2d398b49813176939d7a339ae513d5175efvboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDMR3AsyncCompletionEpClose(pStorageBackend->pEndpoint);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDMR3AsyncCompletionTemplateDestroy(pStorageBackend->pTemplate);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync RTSemEventDestroy(pStorageBackend->EventSem);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync RTMemFree(pStorageBackend);
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync return VINF_SUCCESS;;
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync}
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOReadSync(void *pvUser, void *pStorage, uint64_t uOffset,
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync void *pvBuf, size_t cbRead, size_t *pcbRead)
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync{
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync RTSGSEG DataSeg;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PPDMASYNCCOMPLETIONTASK pTask;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
7766bf675357fd940d8c49e69a5d72dc6eaa6be4vboxsync Assert(!pStorageBackend->fSyncIoPending);
9496f2d398b49813176939d7a339ae513d5175efvboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
9496f2d398b49813176939d7a339ae513d5175efvboxsync DataSeg.cbSeg = cbRead;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync DataSeg.pvSeg = pvBuf;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync int rc = PDMR3AsyncCompletionEpRead(pStorageBackend->pEndpoint, uOffset, &DataSeg, 1, cbRead, NULL, &pTask);
16a9adc14900ca18e6909679a579f6833425e030vboxsync if (RT_FAILURE(rc))
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync return rc;
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync if (rc == VINF_AIO_TASK_PENDING)
9496f2d398b49813176939d7a339ae513d5175efvboxsync {
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /* Wait */
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync AssertRC(rc);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync }
9496f2d398b49813176939d7a339ae513d5175efvboxsync else
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync if (pcbRead)
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync *pcbRead = cbRead;
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync return pStorageBackend->rcReqLast;
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync}
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOWriteSync(void *pvUser, void *pStorage, uint64_t uOffset,
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync const void *pvBuf, size_t cbWrite, size_t *pcbWritten)
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync{
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync RTSGSEG DataSeg;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PPDMASYNCCOMPLETIONTASK pTask;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
7766bf675357fd940d8c49e69a5d72dc6eaa6be4vboxsync Assert(!pStorageBackend->fSyncIoPending);
9496f2d398b49813176939d7a339ae513d5175efvboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
9496f2d398b49813176939d7a339ae513d5175efvboxsync DataSeg.cbSeg = cbWrite;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync DataSeg.pvSeg = (void *)pvBuf;
9496f2d398b49813176939d7a339ae513d5175efvboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync int rc = PDMR3AsyncCompletionEpWrite(pStorageBackend->pEndpoint, uOffset, &DataSeg, 1, cbWrite, NULL, &pTask);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync if (RT_FAILURE(rc))
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync return rc;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync if (rc == VINF_AIO_TASK_PENDING)
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync {
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync /* Wait */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync AssertRC(rc);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync }
9496f2d398b49813176939d7a339ae513d5175efvboxsync else
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync if (pcbWritten)
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync *pcbWritten = cbWrite;
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync return pStorageBackend->rcReqLast;
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync}
ce03ea57fdcf3d48523b1de5b894feb75e1b34davboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOFlushSync(void *pvUser, void *pStorage)
7766bf675357fd940d8c49e69a5d72dc6eaa6be4vboxsync{
9496f2d398b49813176939d7a339ae513d5175efvboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
9496f2d398b49813176939d7a339ae513d5175efvboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PPDMASYNCCOMPLETIONTASK pTask;
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync LogFlowFunc(("pvUser=%#p pStorage=%#p\n", pvUser, pStorage));
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync Assert(!pStorageBackend->fSyncIoPending);
16a9adc14900ca18e6909679a579f6833425e030vboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync int rc = PDMR3AsyncCompletionEpFlush(pStorageBackend->pEndpoint, NULL, &pTask);
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync if (RT_FAILURE(rc))
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync return rc;
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync if (rc == VINF_AIO_TASK_PENDING)
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync {
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync /* Wait */
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync LogFlowFunc(("Waiting for flush to complete\n"));
9496f2d398b49813176939d7a339ae513d5175efvboxsync rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync AssertRC(rc);
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync }
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync else
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync return pStorageBackend->rcReqLast;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync}
9496f2d398b49813176939d7a339ae513d5175efvboxsync
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOReadAsync(void *pvUser, void *pStorage, uint64_t uOffset,
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync PCRTSGSEG paSegments, size_t cSegments,
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync size_t cbRead, void *pvCompletion,
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync void **ppTask)
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync{
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
9496f2d398b49813176939d7a339ae513d5175efvboxsync
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync int rc = PDMR3AsyncCompletionEpRead(pStorageBackend->pEndpoint, uOffset, paSegments, cSegments, cbRead,
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync pvCompletion, (PPPDMASYNCCOMPLETIONTASK)ppTask);
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync if (rc == VINF_AIO_TASK_PENDING)
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = VERR_VD_ASYNC_IO_IN_PROGRESS;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync return rc;
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync}
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOWriteAsync(void *pvUser, void *pStorage, uint64_t uOffset,
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync PCRTSGSEG paSegments, size_t cSegments,
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync size_t cbWrite, void *pvCompletion,
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync void **ppTask)
9496f2d398b49813176939d7a339ae513d5175efvboxsync{
9496f2d398b49813176939d7a339ae513d5175efvboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync int rc = PDMR3AsyncCompletionEpWrite(pStorageBackend->pEndpoint, uOffset, paSegments, cSegments, cbWrite,
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync pvCompletion, (PPPDMASYNCCOMPLETIONTASK)ppTask);
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync if (rc == VINF_AIO_TASK_PENDING)
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync rc = VERR_VD_ASYNC_IO_IN_PROGRESS;
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync return rc;
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync}
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOFlushAsync(void *pvUser, void *pStorage,
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync void *pvCompletion, void **ppTask)
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync{
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync int rc = PDMR3AsyncCompletionEpFlush(pStorageBackend->pEndpoint, pvCompletion,
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync (PPPDMASYNCCOMPLETIONTASK)ppTask);
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync if (rc == VINF_AIO_TASK_PENDING)
369a8817da53dbd5ea6ac360ca0376dba003cde4vboxsync rc = VERR_VD_ASYNC_IO_IN_PROGRESS;
59d7f5939d42ad9d344fbad8401e00a900db92c5vboxsync
59d7f5939d42ad9d344fbad8401e00a900db92c5vboxsync return rc;
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync}
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOGetSize(void *pvUser, void *pStorage, uint64_t *pcbSize)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXDISK pDrvVD = (PVBOXDISK)pvUser;
16a9adc14900ca18e6909679a579f6833425e030vboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync return PDMR3AsyncCompletionEpGetSize(pStorageBackend->pEndpoint, pcbSize);
16a9adc14900ca18e6909679a579f6833425e030vboxsync}
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOSetSize(void *pvUser, void *pStorage, uint64_t cbSize)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXDISK pDrvVD = (PVBOXDISK)pvUser;
16a9adc14900ca18e6909679a579f6833425e030vboxsync PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync int rc = drvvdAsyncIOFlushSync(pvUser, pStorage);
16a9adc14900ca18e6909679a579f6833425e030vboxsync if (RT_SUCCESS(rc))
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = PDMR3AsyncCompletionEpSetSize(pStorageBackend->pEndpoint, cbSize);
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync return rc;
16a9adc14900ca18e6909679a579f6833425e030vboxsync}
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync#endif /* VBOX_WITH_PDM_ASYNC_COMPLETION */
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync/*******************************************************************************
16a9adc14900ca18e6909679a579f6833425e030vboxsync* VD Thread Synchronization interface implementation *
16a9adc14900ca18e6909679a579f6833425e030vboxsync*******************************************************************************/
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdThreadStartRead(void *pvUser)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync return RTSemRWRequestRead(pThis->MergeLock, RT_INDEFINITE_WAIT);
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync}
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsyncstatic DECLCALLBACK(int) drvvdThreadFinishRead(void *pvUser)
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync{
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync return RTSemRWReleaseRead(pThis->MergeLock);
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync}
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsyncstatic DECLCALLBACK(int) drvvdThreadStartWrite(void *pvUser)
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync{
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync return RTSemRWRequestWrite(pThis->MergeLock, RT_INDEFINITE_WAIT);
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync}
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsyncstatic DECLCALLBACK(int) drvvdThreadFinishWrite(void *pvUser)
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync{
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser;
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync
efff36b306e370346025647a158689021df2e1d1vboxsync return RTSemRWReleaseWrite(pThis->MergeLock);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync}
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/*******************************************************************************
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync* VD Configuration interface implementation *
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync*******************************************************************************/
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic bool drvvdCfgAreKeysValid(void *pvUser, const char *pszzValid)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync{
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return CFGMR3AreValuesValid((PCFGMNODE)pvUser, pszzValid);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync}
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic int drvvdCfgQuerySize(void *pvUser, const char *pszName, size_t *pcb)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync{
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return CFGMR3QuerySize((PCFGMNODE)pvUser, pszName, pcb);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync}
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic int drvvdCfgQuery(void *pvUser, const char *pszName, char *pszString, size_t cchString)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync{
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return CFGMR3QueryString((PCFGMNODE)pvUser, pszName, pszString, cchString);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync}
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync#ifdef VBOX_WITH_INIP
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/*******************************************************************************
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync* VD TCP network stack interface implementation - INIP case *
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync*******************************************************************************/
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsynctypedef union INIPSOCKADDRUNION
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync{
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync struct sockaddr Addr;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync struct sockaddr_in Ipv4;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync} INIPSOCKADDRUNION;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsynctypedef struct INIPSOCKET
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync{
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync int hSock;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync} INIPSOCKET, *PINIPSOCKET;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPFlush(VDSOCKET Sock);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnSocketCreate */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPSocketCreate(uint32_t fFlags, PVDSOCKET pSock)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync{
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync PINIPSOCKET pSocketInt = NULL;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /*
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * The extended select method is not supported because it is impossible to wakeup
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * the thread.
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (fFlags & VD_INTERFACETCPNET_CONNECT_EXTENDED_SELECT)
7b067f3f07310bff46d1d6a4ac94d8b9bb7ccccdvboxsync return VERR_NOT_SUPPORTED;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync pSocketInt = (PINIPSOCKET)RTMemAllocZ(sizeof(INIPSOCKET));
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (pSocketInt)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync {
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync pSocketInt->hSock = INT32_MAX;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync *pSock = (VDSOCKET)pSocketInt;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VINF_SUCCESS;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync }
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VERR_NO_MEMORY;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync}
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnSocketCreate */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPSocketDestroy(VDSOCKET Sock)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync{
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync RTMemFree(pSocketInt);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VINF_SUCCESS;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync}
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnClientConnect */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync{
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync int rc = VINF_SUCCESS;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* Check whether lwIP is set up in this VM instance. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (!DevINIPConfigured())
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync {
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync LogRelFunc(("no IP stack\n"));
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VERR_NET_HOST_UNREACHABLE;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync }
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* Resolve hostname. As there is no standard resolver for lwIP yet,
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * just accept numeric IP addresses for now. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync struct in_addr ip;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (!lwip_inet_aton(pszAddress, &ip))
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync {
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync LogRelFunc(("cannot resolve IP %s\n", pszAddress));
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VERR_NET_HOST_UNREACHABLE;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync }
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* Create socket and connect. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync int iSock = lwip_socket(PF_INET, SOCK_STREAM, 0);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (iSock != -1)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync {
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync struct sockaddr_in InAddr = {0};
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync InAddr.sin_family = AF_INET;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync InAddr.sin_port = htons(uPort);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync InAddr.sin_addr = ip;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (!lwip_connect(iSock, (struct sockaddr *)&InAddr, sizeof(InAddr)))
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync {
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync pSocketInt->hSock = iSock;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VINF_SUCCESS;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync }
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = VERR_NET_CONNECTION_REFUSED; /* @todo real solution needed */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync lwip_close(iSock);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync }
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync else
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = VERR_NET_CONNECTION_REFUSED; /* @todo real solution needed */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return rc;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync}
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnClientClose */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPClientClose(VDSOCKET Sock)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync{
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync lwip_close(pSocketInt->hSock);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync pSocketInt->hSock = INT32_MAX;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VINF_SUCCESS; /** @todo real solution needed */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync}
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnIsClientConnected */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(bool) drvvdINIPIsClientConnected(VDSOCKET Sock)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync{
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return pSocketInt->hSock != INT32_MAX;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync}
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOne */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsyncstatic DECLCALLBACK(int) drvvdINIPSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync{
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync fd_set fdsetR;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync FD_ZERO(&fdsetR);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync FD_SET((uintptr_t)Sock, &fdsetR);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync fd_set fdsetE = fdsetR;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync int rc;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (cMillies == RT_INDEFINITE_WAIT)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = lwip_select(pSocketInt->hSock + 1, &fdsetR, NULL, &fdsetE, NULL);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync else
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync {
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync struct timeval timeout;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync timeout.tv_sec = cMillies / 1000;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync timeout.tv_usec = (cMillies % 1000) * 1000;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = lwip_select(pSocketInt->hSock + 1, &fdsetR, NULL, &fdsetE, &timeout);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync }
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (rc > 0)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync return VINF_SUCCESS;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (rc == 0)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync return VERR_TIMEOUT;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution needed */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync}
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync/** @copydoc VDINTERFACETCPNET::pfnRead */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsyncstatic DECLCALLBACK(int) drvvdINIPRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync{
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync /* Do params checking */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync if (!pvBuffer || !cbBuffer)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync {
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync AssertMsgFailed(("Invalid params\n"));
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync return VERR_INVALID_PARAMETER;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync }
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync /*
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync * Read loop.
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync * If pcbRead is NULL we have to fill the entire buffer!
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync size_t cbRead = 0;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync size_t cbToRead = cbBuffer;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync for (;;)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync {
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync /** @todo this clipping here is just in case (the send function
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync * needed it, so I added it here, too). Didn't investigate if this
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync * really has issues. Better be safe than sorry. */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync ssize_t cbBytesRead = lwip_recv(pSocketInt->hSock, (char *)pvBuffer + cbRead,
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync RT_MIN(cbToRead, 32768), 0);
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync if (cbBytesRead < 0)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync if (cbBytesRead == 0 && errno) /** @todo r=bird: lwip_recv will not touch errno on Windows. This may apply to other hosts as well */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync if (pcbRead)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync {
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync /* return partial data */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync *pcbRead = cbBytesRead;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync break;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync }
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync /* read more? */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync cbRead += cbBytesRead;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync if (cbRead == cbBuffer)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync break;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync /* next */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync cbToRead = cbBuffer - cbRead;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync }
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync return VINF_SUCCESS;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync}
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync/** @copydoc VDINTERFACETCPNET::pfnWrite */
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsyncstatic DECLCALLBACK(int) drvvdINIPWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer)
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync{
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync do
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync {
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync /** @todo lwip send only supports up to 65535 bytes in a single
efff36b306e370346025647a158689021df2e1d1vboxsync * 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. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync ssize_t cbWritten = lwip_send(pSocketInt->hSock, (void *)pvBuffer,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync RT_MIN(cbBuffer, 32768), 0);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync if (cbWritten < 0)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return VERR_NET_CONNECTION_REFUSED; /** @todo real solution needed */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync AssertMsg(cbBuffer >= (size_t)cbWritten, ("Wrote more than we requested!!! cbWritten=%d cbBuffer=%d\n",
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync cbWritten, cbBuffer));
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync cbBuffer -= cbWritten;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pvBuffer = (const char *)pvBuffer + cbWritten;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync } while (cbBuffer);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync return VINF_SUCCESS;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync}
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync
ff88d4153cd65650577e8c2d1a5a3fdfa0404a80vboxsync/** @copydoc VDINTERFACETCPNET::pfnSgWrite */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdINIPSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf)
fe813b3594039ba864493438e78ee0e7132bc445vboxsync{
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync int rc = VINF_SUCCESS;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* This is an extremely crude emulation, however it's good enough
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * for our iSCSI code. INIP has no sendmsg(). */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync for (unsigned i = 0; i < pSgBuf->cSegs; i++)
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync {
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync rc = drvvdINIPWrite(Sock, pSgBuf->paSegs[i].pvSeg,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pSgBuf->paSegs[i].cbSeg);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync if (RT_FAILURE(rc))
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync break;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync }
ff88d4153cd65650577e8c2d1a5a3fdfa0404a80vboxsync if (RT_SUCCESS(rc))
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync drvvdINIPFlush(Sock);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync
fe813b3594039ba864493438e78ee0e7132bc445vboxsync return rc;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc VDINTERFACETCPNET::pfnFlush */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdINIPFlush(VDSOCKET Sock)
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync{
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync int fFlag = 1;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync lwip_setsockopt(pSocketInt->hSock, IPPROTO_TCP, TCP_NODELAY,
fe813b3594039ba864493438e78ee0e7132bc445vboxsync (const char *)&fFlag, sizeof(fFlag));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync fFlag = 0;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync lwip_setsockopt(pSocketInt->hSock, IPPROTO_TCP, TCP_NODELAY,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync (const char *)&fFlag, sizeof(fFlag));
16a9adc14900ca18e6909679a579f6833425e030vboxsync return VINF_SUCCESS;
16a9adc14900ca18e6909679a579f6833425e030vboxsync}
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync/** @copydoc VDINTERFACETCPNET::pfnSetSendCoalescing */
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdINIPSetSendCoalescing(VDSOCKET Sock, bool fEnable)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync int fFlag = fEnable ? 0 : 1;
16a9adc14900ca18e6909679a579f6833425e030vboxsync lwip_setsockopt(pSocketInt->hSock, IPPROTO_TCP, TCP_NODELAY,
16a9adc14900ca18e6909679a579f6833425e030vboxsync (const char *)&fFlag, sizeof(fFlag));
16a9adc14900ca18e6909679a579f6833425e030vboxsync return VINF_SUCCESS;
16a9adc14900ca18e6909679a579f6833425e030vboxsync}
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetLocalAddress */
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdINIPGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
16a9adc14900ca18e6909679a579f6833425e030vboxsync INIPSOCKADDRUNION u;
16a9adc14900ca18e6909679a579f6833425e030vboxsync socklen_t cbAddr = sizeof(u);
16a9adc14900ca18e6909679a579f6833425e030vboxsync RT_ZERO(u);
16a9adc14900ca18e6909679a579f6833425e030vboxsync if (!lwip_getsockname(pSocketInt->hSock, &u.Addr, &cbAddr))
16a9adc14900ca18e6909679a579f6833425e030vboxsync {
16a9adc14900ca18e6909679a579f6833425e030vboxsync /*
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Convert the address.
16a9adc14900ca18e6909679a579f6833425e030vboxsync */
16a9adc14900ca18e6909679a579f6833425e030vboxsync if ( cbAddr == sizeof(struct sockaddr_in)
16a9adc14900ca18e6909679a579f6833425e030vboxsync && u.Addr.sa_family == AF_INET)
16a9adc14900ca18e6909679a579f6833425e030vboxsync {
16a9adc14900ca18e6909679a579f6833425e030vboxsync RT_ZERO(*pAddr);
16a9adc14900ca18e6909679a579f6833425e030vboxsync pAddr->enmType = RTNETADDRTYPE_IPV4;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pAddr->uPort = RT_N2H_U16(u.Ipv4.sin_port);
16a9adc14900ca18e6909679a579f6833425e030vboxsync pAddr->uAddr.IPv4.u = u.Ipv4.sin_addr.s_addr;
16a9adc14900ca18e6909679a579f6833425e030vboxsync }
16a9adc14900ca18e6909679a579f6833425e030vboxsync else
16a9adc14900ca18e6909679a579f6833425e030vboxsync return VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED;
16a9adc14900ca18e6909679a579f6833425e030vboxsync return VINF_SUCCESS;
16a9adc14900ca18e6909679a579f6833425e030vboxsync }
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return VERR_NET_OPERATION_NOT_SUPPORTED;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetPeerAddress */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsyncstatic DECLCALLBACK(int) drvvdINIPGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr)
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync{
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync INIPSOCKADDRUNION u;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync socklen_t cbAddr = sizeof(u);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync RT_ZERO(u);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync if (!lwip_getpeername(pSocketInt->hSock, &u.Addr, &cbAddr))
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync {
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /*
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Convert the address.
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync if ( cbAddr == sizeof(struct sockaddr_in)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync && u.Addr.sa_family == AF_INET)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync {
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync RT_ZERO(*pAddr);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pAddr->enmType = RTNETADDRTYPE_IPV4;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync pAddr->uPort = RT_N2H_U16(u.Ipv4.sin_port);
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync pAddr->uAddr.IPv4.u = u.Ipv4.sin_addr.s_addr;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync }
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync else
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync return VINF_SUCCESS;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync }
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync return VERR_NET_OPERATION_NOT_SUPPORTED;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOneEx */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdINIPSelectOneEx(VDSOCKET Sock, uint32_t fEvents, uint32_t *pfEvents, RTMSINTERVAL cMillies)
fe813b3594039ba864493438e78ee0e7132bc445vboxsync{
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync AssertMsgFailed(("Not supported!\n"));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return VERR_NOT_SUPPORTED;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync/** @copydoc VDINTERFACETCPNET::pfnPoke */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsyncstatic DECLCALLBACK(int) drvvdINIPPoke(VDSOCKET Sock)
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync{
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync AssertMsgFailed(("Not supported!\n"));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return VERR_NOT_SUPPORTED;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync}
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync#endif /* VBOX_WITH_INIP */
594521f7faf13f7a88f31e6cd76629bd67340229vboxsync
e04eeee1b306d610b0441cee9bf1c750100254d5vboxsync
fe813b3594039ba864493438e78ee0e7132bc445vboxsync/*******************************************************************************
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync* VD TCP network stack interface implementation - Host TCP case *
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync*******************************************************************************/
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync/**
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync * Socket data.
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsynctypedef struct VDSOCKETINT
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync{
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync /** IPRT socket handle. */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync RTSOCKET hSocket;
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync /** Pollset with the wakeup pipe and socket. */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync RTPOLLSET hPollSet;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync /** Pipe endpoint - read (in the pollset). */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync RTPIPE hPipeR;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync /** Pipe endpoint - write. */
fe813b3594039ba864493438e78ee0e7132bc445vboxsync RTPIPE hPipeW;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync /** Flag whether the thread was woken up. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync volatile bool fWokenUp;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /** Flag whether the thread is waiting in the select call. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync volatile bool fWaiting;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync /** Old event mask. */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync uint32_t fEventsOld;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync} VDSOCKETINT, *PVDSOCKETINT;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync/** Pollset id of the socket. */
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync#define VDSOCKET_POLL_ID_SOCKET 0
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync/** Pollset id of the pipe. */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync#define VDSOCKET_POLL_ID_PIPE 1
594521f7faf13f7a88f31e6cd76629bd67340229vboxsync
e04eeee1b306d610b0441cee9bf1c750100254d5vboxsync/** @copydoc VDINTERFACETCPNET::pfnSocketCreate */
fe813b3594039ba864493438e78ee0e7132bc445vboxsyncstatic DECLCALLBACK(int) drvvdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync{
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync int rc = VINF_SUCCESS;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync int rc2 = VINF_SUCCESS;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVDSOCKETINT pSockInt = NULL;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pSockInt = (PVDSOCKETINT)RTMemAllocZ(sizeof(VDSOCKETINT));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync if (!pSockInt)
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync return VERR_NO_MEMORY;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync
af90f37ee9175da3aed36bda13519a917cc4effbvboxsync pSockInt->hSocket = NIL_RTSOCKET;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pSockInt->hPollSet = NIL_RTPOLLSET;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pSockInt->hPipeR = NIL_RTPIPE;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pSockInt->hPipeW = NIL_RTPIPE;
9496f2d398b49813176939d7a339ae513d5175efvboxsync pSockInt->fWokenUp = false;
9496f2d398b49813176939d7a339ae513d5175efvboxsync pSockInt->fWaiting = false;
9496f2d398b49813176939d7a339ae513d5175efvboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync if (fFlags & VD_INTERFACETCPNET_CONNECT_EXTENDED_SELECT)
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync {
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync /* Init pipe and pollset. */
7a3f491705173bc08122f2c7d26d48a8b4c5ceecvboxsync rc = RTPipeCreate(&pSockInt->hPipeR, &pSockInt->hPipeW, 0);
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync if (RT_SUCCESS(rc))
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync {
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync rc = RTPollSetCreate(&pSockInt->hPollSet);
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync if (RT_SUCCESS(rc))
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync {
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync rc = RTPollSetAddPipe(pSockInt->hPollSet, pSockInt->hPipeR,
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync RTPOLL_EVT_READ, VDSOCKET_POLL_ID_PIPE);
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync if (RT_SUCCESS(rc))
9496f2d398b49813176939d7a339ae513d5175efvboxsync {
9496f2d398b49813176939d7a339ae513d5175efvboxsync *pSock = pSockInt;
9496f2d398b49813176939d7a339ae513d5175efvboxsync return VINF_SUCCESS;
9496f2d398b49813176939d7a339ae513d5175efvboxsync }
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync RTPollSetRemove(pSockInt->hPollSet, VDSOCKET_POLL_ID_PIPE);
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync rc2 = RTPollSetDestroy(pSockInt->hPollSet);
fe813b3594039ba864493438e78ee0e7132bc445vboxsync AssertRC(rc2);
9496f2d398b49813176939d7a339ae513d5175efvboxsync }
9496f2d398b49813176939d7a339ae513d5175efvboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync rc2 = RTPipeClose(pSockInt->hPipeR);
9496f2d398b49813176939d7a339ae513d5175efvboxsync AssertRC(rc2);
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync rc2 = RTPipeClose(pSockInt->hPipeW);
9496f2d398b49813176939d7a339ae513d5175efvboxsync AssertRC(rc2);
9496f2d398b49813176939d7a339ae513d5175efvboxsync }
9496f2d398b49813176939d7a339ae513d5175efvboxsync }
9496f2d398b49813176939d7a339ae513d5175efvboxsync else
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync {
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync *pSock = pSockInt;
c7551981eb6d97331da479f68f14a9c56247e4f7vboxsync return VINF_SUCCESS;
fe813b3594039ba864493438e78ee0e7132bc445vboxsync }
9496f2d398b49813176939d7a339ae513d5175efvboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync RTMemFree(pSockInt);
9496f2d398b49813176939d7a339ae513d5175efvboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return rc;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc VDINTERFACETCPNET::pfnSocketDestroy */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdTcpSocketDestroy(VDSOCKET Sock)
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync{
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync int rc = VINF_SUCCESS;
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync /* Destroy the pipe and pollset if necessary. */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync if (pSockInt->hPollSet != NIL_RTPOLLSET)
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync {
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync if (pSockInt->hSocket != NIL_RTSOCKET)
a39ea3668b7019c23a68936259545f9b71bce1aavboxsync {
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync rc = RTPollSetRemove(pSockInt->hPollSet, VDSOCKET_POLL_ID_SOCKET);
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync Assert(RT_SUCCESS(rc) || rc == VERR_POLL_HANDLE_ID_NOT_FOUND);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync }
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = RTPollSetRemove(pSockInt->hPollSet, VDSOCKET_POLL_ID_PIPE);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync AssertRC(rc);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = RTPollSetDestroy(pSockInt->hPollSet);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync AssertRC(rc);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = RTPipeClose(pSockInt->hPipeR);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync AssertRC(rc);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = RTPipeClose(pSockInt->hPipeW);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync AssertRC(rc);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync }
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync if (pSockInt->hSocket != NIL_RTSOCKET)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = RTTcpClientClose(pSockInt->hSocket);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync RTMemFree(pSockInt);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return rc;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc VDINTERFACETCPNET::pfnClientConnect */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync int rc = VINF_SUCCESS;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = RTTcpClientConnect(pszAddress, uPort, &pSockInt->hSocket);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync if (RT_SUCCESS(rc))
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync {
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* Add to the pollset if required. */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync if (pSockInt->hPollSet != NIL_RTPOLLSET)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync {
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync pSockInt->fEventsOld = RTPOLL_EVT_READ | RTPOLL_EVT_WRITE | RTPOLL_EVT_ERROR;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = RTPollSetAddSocket(pSockInt->hPollSet, pSockInt->hSocket,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync pSockInt->fEventsOld, VDSOCKET_POLL_ID_SOCKET);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync }
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync if (RT_SUCCESS(rc))
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return VINF_SUCCESS;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = RTTcpClientClose(pSockInt->hSocket);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync }
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return rc;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc VDINTERFACETCPNET::pfnClientClose */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdTcpClientClose(VDSOCKET Sock)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync int rc = VINF_SUCCESS;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync if (pSockInt->hPollSet != NIL_RTPOLLSET)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync {
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = RTPollSetRemove(pSockInt->hPollSet, VDSOCKET_POLL_ID_SOCKET);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync AssertRC(rc);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync }
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync rc = RTTcpClientClose(pSockInt->hSocket);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync pSockInt->hSocket = NIL_RTSOCKET;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return rc;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc VDINTERFACETCPNET::pfnIsClientConnected */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(bool) drvvdTcpIsClientConnected(VDSOCKET Sock)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return pSockInt->hSocket != NIL_RTSOCKET;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOne */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return RTTcpSelectOne(pSockInt->hSocket, cMillies);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc VDINTERFACETCPNET::pfnRead */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return RTTcpRead(pSockInt->hSocket, pvBuffer, cbBuffer, pcbRead);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc VDINTERFACETCPNET::pfnWrite */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync return RTTcpWrite(pSockInt->hSocket, pvBuffer, cbBuffer);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc VDINTERFACETCPNET::pfnSgWrite */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return RTTcpSgWrite(pSockInt->hSocket, pSgBuf);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc VDINTERFACETCPNET::pfnReadNB */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdTcpReadNB(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return RTTcpReadNB(pSockInt->hSocket, pvBuffer, cbBuffer, pcbRead);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc VDINTERFACETCPNET::pfnWriteNB */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdTcpWriteNB(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer, size_t *pcbWritten)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return RTTcpWriteNB(pSockInt->hSocket, pvBuffer, cbBuffer, pcbWritten);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync/** @copydoc VDINTERFACETCPNET::pfnSgWriteNB */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdTcpSgWriteNB(VDSOCKET Sock, PRTSGBUF pSgBuf, size_t *pcbWritten)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync return RTTcpSgWriteNB(pSockInt->hSocket, pSgBuf, pcbWritten);
16a9adc14900ca18e6909679a579f6833425e030vboxsync}
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync/** @copydoc VDINTERFACETCPNET::pfnFlush */
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdTcpFlush(VDSOCKET Sock)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync return RTTcpFlush(pSockInt->hSocket);
16a9adc14900ca18e6909679a579f6833425e030vboxsync}
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync/** @copydoc VDINTERFACETCPNET::pfnSetSendCoalescing */
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync return RTTcpSetSendCoalescing(pSockInt->hSocket, fEnable);
16a9adc14900ca18e6909679a579f6833425e030vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetLocalAddress */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return RTTcpGetLocalAddress(pSockInt->hSocket, pAddr);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc VDINTERFACETCPNET::pfnGetPeerAddress */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr)
cba6719bd64ec749967bbe931230452664109857vboxsync{
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync return RTTcpGetPeerAddress(pSockInt->hSocket, pAddr);
cba6719bd64ec749967bbe931230452664109857vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic int drvvdTcpSelectOneExPoll(VDSOCKET Sock, uint32_t fEvents,
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync uint32_t *pfEvents, RTMSINTERVAL cMillies)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync{
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync int rc = VINF_SUCCESS;
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync uint32_t id = 0;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync uint32_t fEventsRecv = 0;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync *pfEvents = 0;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync if ( pSockInt->fEventsOld != fEvents
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync && pSockInt->hSocket != NIL_RTSOCKET)
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync {
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync uint32_t fPollEvents = 0;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync if (fEvents & VD_INTERFACETCPNET_EVT_READ)
090d729e786b999dc285f8ea267f9effd1319544vboxsync fPollEvents |= RTPOLL_EVT_READ;
16a9adc14900ca18e6909679a579f6833425e030vboxsync if (fEvents & VD_INTERFACETCPNET_EVT_WRITE)
16a9adc14900ca18e6909679a579f6833425e030vboxsync fPollEvents |= RTPOLL_EVT_WRITE;
16a9adc14900ca18e6909679a579f6833425e030vboxsync if (fEvents & VD_INTERFACETCPNET_EVT_ERROR)
16a9adc14900ca18e6909679a579f6833425e030vboxsync fPollEvents |= RTPOLL_EVT_ERROR;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = RTPollSetEventsChange(pSockInt->hPollSet, VDSOCKET_POLL_ID_SOCKET, fPollEvents);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync if (RT_FAILURE(rc))
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync return rc;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync pSockInt->fEventsOld = fEvents;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync }
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ASMAtomicXchgBool(&pSockInt->fWaiting, true);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync if (ASMAtomicXchgBool(&pSockInt->fWokenUp, false))
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync {
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ASMAtomicXchgBool(&pSockInt->fWaiting, false);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync return VERR_INTERRUPTED;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync }
9496f2d398b49813176939d7a339ae513d5175efvboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync rc = RTPoll(pSockInt->hPollSet, cMillies, &fEventsRecv, &id);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync Assert(RT_SUCCESS(rc) || rc == VERR_TIMEOUT);
9496f2d398b49813176939d7a339ae513d5175efvboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync ASMAtomicXchgBool(&pSockInt->fWaiting, false);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync
68a4ee3a31a0807abd03eae881c1bbaf4d42ee6dvboxsync if (RT_SUCCESS(rc))
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync {
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync if (id == VDSOCKET_POLL_ID_SOCKET)
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync {
caf54c14752060b187e3fca12a6f71f4b13126b8vboxsync fEventsRecv &= RTPOLL_EVT_VALID_MASK;
9496f2d398b49813176939d7a339ae513d5175efvboxsync
68a4ee3a31a0807abd03eae881c1bbaf4d42ee6dvboxsync if (fEventsRecv & RTPOLL_EVT_READ)
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync *pfEvents |= VD_INTERFACETCPNET_EVT_READ;
9496f2d398b49813176939d7a339ae513d5175efvboxsync if (fEventsRecv & RTPOLL_EVT_WRITE)
9496f2d398b49813176939d7a339ae513d5175efvboxsync *pfEvents |= VD_INTERFACETCPNET_EVT_WRITE;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync if (fEventsRecv & RTPOLL_EVT_ERROR)
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync *pfEvents |= VD_INTERFACETCPNET_EVT_ERROR;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync }
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync else
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync {
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync size_t cbRead = 0;
975ad9d9bc9c4dc96b41d9f67a65228b1b338e2avboxsync uint8_t abBuf[10];
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync Assert(id == VDSOCKET_POLL_ID_PIPE);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync Assert((fEventsRecv & RTPOLL_EVT_VALID_MASK) == RTPOLL_EVT_READ);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync /* We got interrupted, drain the pipe. */
9496f2d398b49813176939d7a339ae513d5175efvboxsync rc = RTPipeRead(pSockInt->hPipeR, abBuf, sizeof(abBuf), &cbRead);
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync AssertRC(rc);
9496f2d398b49813176939d7a339ae513d5175efvboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync ASMAtomicXchgBool(&pSockInt->fWokenUp, false);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = VERR_INTERRUPTED;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync }
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync }
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return rc;
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync}
090d729e786b999dc285f8ea267f9effd1319544vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc VDINTERFACETCPNET::pfnSelectOneEx */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdTcpSelectOneExNoPoll(VDSOCKET Sock, uint32_t fEvents,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync uint32_t *pfEvents, RTMSINTERVAL cMillies)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync{
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync int rc = VINF_SUCCESS;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync *pfEvents = 0;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync ASMAtomicXchgBool(&pSockInt->fWaiting, true);
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync if (ASMAtomicXchgBool(&pSockInt->fWokenUp, false))
16a9adc14900ca18e6909679a579f6833425e030vboxsync {
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync ASMAtomicXchgBool(&pSockInt->fWaiting, false);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return VERR_INTERRUPTED;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync }
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync if ( pSockInt->hSocket == NIL_RTSOCKET
16a9adc14900ca18e6909679a579f6833425e030vboxsync || !fEvents)
16a9adc14900ca18e6909679a579f6833425e030vboxsync {
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /*
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Only the pipe is configured or the caller doesn't wait for a socket event,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * wait until there is something to read from the pipe.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync size_t cbRead = 0;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync char ch = 0;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = RTPipeReadBlocking(pSockInt->hPipeR, &ch, 1, &cbRead);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync if (RT_SUCCESS(rc))
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync {
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync Assert(cbRead == 1);
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync rc = VERR_INTERRUPTED;
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync ASMAtomicXchgBool(&pSockInt->fWokenUp, false);
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync }
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync }
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync else
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync {
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync uint32_t fSelectEvents = 0;
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync if (fEvents & VD_INTERFACETCPNET_EVT_READ)
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync fSelectEvents |= RTSOCKET_EVT_READ;
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync if (fEvents & VD_INTERFACETCPNET_EVT_WRITE)
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync fSelectEvents |= RTSOCKET_EVT_WRITE;
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync if (fEvents & VD_INTERFACETCPNET_EVT_ERROR)
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync fSelectEvents |= RTSOCKET_EVT_ERROR;
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync if (fEvents & VD_INTERFACETCPNET_HINT_INTERRUPT)
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync {
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync uint32_t fEventsRecv = 0;
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync /* Make sure the socket is not in the pollset. */
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync rc = RTPollSetRemove(pSockInt->hPollSet, VDSOCKET_POLL_ID_SOCKET);
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync Assert(RT_SUCCESS(rc) || rc == VERR_POLL_HANDLE_ID_NOT_FOUND);
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync for (;;)
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync {
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync uint32_t id = 0;
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync rc = RTPoll(pSockInt->hPollSet, 5, &fEvents, &id);
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync if (rc == VERR_TIMEOUT)
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync {
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync /* Check the socket. */
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync rc = RTTcpSelectOneEx(pSockInt->hSocket, fSelectEvents, &fEventsRecv, 0);
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync if (RT_SUCCESS(rc))
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync {
16a9adc14900ca18e6909679a579f6833425e030vboxsync if (fEventsRecv & RTSOCKET_EVT_READ)
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync *pfEvents |= VD_INTERFACETCPNET_EVT_READ;
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync if (fEventsRecv & RTSOCKET_EVT_WRITE)
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync *pfEvents |= VD_INTERFACETCPNET_EVT_WRITE;
81c82bebae20d8743f59b8f3c38f0b1b7310abb3vboxsync if (fEventsRecv & RTSOCKET_EVT_ERROR)
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync *pfEvents |= VD_INTERFACETCPNET_EVT_ERROR;
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync break; /* Quit */
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync }
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync else if (rc != VERR_TIMEOUT)
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync break;
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync }
16a9adc14900ca18e6909679a579f6833425e030vboxsync else if (RT_SUCCESS(rc))
16a9adc14900ca18e6909679a579f6833425e030vboxsync {
16a9adc14900ca18e6909679a579f6833425e030vboxsync size_t cbRead = 0;
16a9adc14900ca18e6909679a579f6833425e030vboxsync uint8_t abBuf[10];
16a9adc14900ca18e6909679a579f6833425e030vboxsync Assert(id == VDSOCKET_POLL_ID_PIPE);
16a9adc14900ca18e6909679a579f6833425e030vboxsync Assert((fEventsRecv & RTPOLL_EVT_VALID_MASK) == RTPOLL_EVT_READ);
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* We got interrupted, drain the pipe. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = RTPipeRead(pSockInt->hPipeR, abBuf, sizeof(abBuf), &cbRead);
16a9adc14900ca18e6909679a579f6833425e030vboxsync AssertRC(rc);
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync ASMAtomicXchgBool(&pSockInt->fWokenUp, false);
16a9adc14900ca18e6909679a579f6833425e030vboxsync
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync rc = VERR_INTERRUPTED;
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync break;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync }
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync else
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync break;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync }
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync }
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync else /* The caller waits for a socket event. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync {
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync uint32_t fEventsRecv = 0;
16a9adc14900ca18e6909679a579f6833425e030vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync /* Loop until we got woken up or a socket event occurred. */
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync for (;;)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync {
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /** @todo find an adaptive wait algorithm based on the
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * number of wakeups in the past. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = RTTcpSelectOneEx(pSockInt->hSocket, fSelectEvents, &fEventsRecv, 5);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (rc == VERR_TIMEOUT)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync {
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /* Check if there is an event pending. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync size_t cbRead = 0;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync char ch = 0;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = RTPipeRead(pSockInt->hPipeR, &ch, 1, &cbRead);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (RT_SUCCESS(rc) && rc != VINF_TRY_AGAIN)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync {
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync Assert(cbRead == 1);
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = VERR_INTERRUPTED;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync ASMAtomicXchgBool(&pSockInt->fWokenUp, false);
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync break; /* Quit */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync }
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync else
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync Assert(rc == VINF_TRY_AGAIN);
efff36b306e370346025647a158689021df2e1d1vboxsync }
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync else if (RT_SUCCESS(rc))
efff36b306e370346025647a158689021df2e1d1vboxsync {
efff36b306e370346025647a158689021df2e1d1vboxsync if (fEventsRecv & RTSOCKET_EVT_READ)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync *pfEvents |= VD_INTERFACETCPNET_EVT_READ;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (fEventsRecv & RTSOCKET_EVT_WRITE)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync *pfEvents |= VD_INTERFACETCPNET_EVT_WRITE;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync if (fEventsRecv & RTSOCKET_EVT_ERROR)
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync *pfEvents |= VD_INTERFACETCPNET_EVT_ERROR;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync break; /* Quit */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync }
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync else
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync break;
d571b6e3237f0ce89ea27f6fa4635d41c5ee3d88vboxsync }
efff36b306e370346025647a158689021df2e1d1vboxsync }
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync }
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync ASMAtomicXchgBool(&pSockInt->fWaiting, false);
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync return rc;
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync}
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync/** @copydoc VDINTERFACETCPNET::pfnPoke */
27b178e99b06a68ef52353b15bc647674d2006bcvboxsyncstatic DECLCALLBACK(int) drvvdTcpPoke(VDSOCKET Sock)
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync{
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync int rc = VINF_SUCCESS;
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync size_t cbWritten = 0;
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync ASMAtomicXchgBool(&pSockInt->fWokenUp, true);
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync if (ASMAtomicReadBool(&pSockInt->fWaiting))
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync {
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync rc = RTPipeWrite(pSockInt->hPipeW, "", 1, &cbWritten);
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync Assert(RT_SUCCESS(rc) || cbWritten == 0);
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync }
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync return VINF_SUCCESS;
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync}
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync/*******************************************************************************
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync* Media interface methods *
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync*******************************************************************************/
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync/** @copydoc PDMIMEDIA::pfnRead */
27b178e99b06a68ef52353b15bc647674d2006bcvboxsyncstatic DECLCALLBACK(int) drvvdRead(PPDMIMEDIA pInterface,
27b178e99b06a68ef52353b15bc647674d2006bcvboxsync uint64_t off, void *pvBuf, size_t cbRead)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync int rc = VINF_SUCCESS;
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync LogFlowFunc(("off=%#llx pvBuf=%p cbRead=%d\n", off, pvBuf, cbRead));
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync if (!pThis->fBootAccelActive)
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = VDRead(pThis->pDisk, off, pvBuf, cbRead);
16a9adc14900ca18e6909679a579f6833425e030vboxsync else
16a9adc14900ca18e6909679a579f6833425e030vboxsync {
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* Can we serve the request from the buffer? */
16a9adc14900ca18e6909679a579f6833425e030vboxsync if ( off >= pThis->offDisk
16a9adc14900ca18e6909679a579f6833425e030vboxsync && off - pThis->offDisk < pThis->cbDataValid)
16a9adc14900ca18e6909679a579f6833425e030vboxsync {
16a9adc14900ca18e6909679a579f6833425e030vboxsync size_t cbToCopy = RT_MIN(cbRead, pThis->offDisk + pThis->cbDataValid - off);
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync memcpy(pvBuf, pThis->pbData + (off - pThis->offDisk), cbToCopy);
16a9adc14900ca18e6909679a579f6833425e030vboxsync cbRead -= cbToCopy;
16a9adc14900ca18e6909679a579f6833425e030vboxsync off += cbToCopy;
16a9adc14900ca18e6909679a579f6833425e030vboxsync pvBuf = (char *)pvBuf + cbToCopy;
16a9adc14900ca18e6909679a579f6833425e030vboxsync }
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync if ( cbRead > 0
bbede9c189def47a9880f0ffb03c0c230c774185vboxsync && cbRead < pThis->cbBootAccelBuffer)
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync {
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync /* Increase request to the buffer size and read. */
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync pThis->cbDataValid = RT_MIN(pThis->cbDisk - off, pThis->cbBootAccelBuffer);
a3369a746b56a8966dd78619f4d191c9662f400dvboxsync pThis->offDisk = off;
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync rc = VDRead(pThis->pDisk, off, pThis->pbData, pThis->cbDataValid);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync if (RT_FAILURE(rc))
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->cbDataValid = 0;
d5ea45cc92d7f1d3ade8189944531f665bfe8ed5vboxsync else
5d0d754550d06b7d59a935e59caaf814462d53ccvboxsync memcpy(pvBuf, pThis->pbData, cbRead);
5d0d754550d06b7d59a935e59caaf814462d53ccvboxsync }
16a9adc14900ca18e6909679a579f6833425e030vboxsync else if (cbRead >= pThis->cbBootAccelBuffer)
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync {
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->fBootAccelActive = false; /* Deactiviate */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync }
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync }
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync if (RT_SUCCESS(rc))
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync Log2(("%s: off=%#llx pvBuf=%p cbRead=%d %.*Rhxd\n", __FUNCTION__,
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync off, pvBuf, cbRead, cbRead, pvBuf));
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync LogFlowFunc(("returns %Rrc\n", rc));
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync return rc;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnWrite */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdWrite(PPDMIMEDIA pInterface,
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync uint64_t off, const void *pvBuf,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync size_t cbWrite)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync{
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync LogFlowFunc(("off=%#llx pvBuf=%p cbWrite=%d\n", off, pvBuf, cbWrite));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync Log2(("%s: off=%#llx pvBuf=%p cbWrite=%d %.*Rhxd\n", __FUNCTION__,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync off, pvBuf, cbWrite, cbWrite, pvBuf));
0ccdfa1953b2f57311fb9ec01a2baf5e1e366f5avboxsync
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync /* Invalidate any buffer if boot acceleration is enabled. */
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync if (pThis->fBootAccelActive)
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync {
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync pThis->cbDataValid = 0;
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync pThis->offDisk = 0;
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync }
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync int rc = VDWrite(pThis->pDisk, off, pvBuf, cbWrite);
16a9adc14900ca18e6909679a579f6833425e030vboxsync LogFlowFunc(("returns %Rrc\n", rc));
16a9adc14900ca18e6909679a579f6833425e030vboxsync return rc;
16a9adc14900ca18e6909679a579f6833425e030vboxsync}
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync/** @copydoc PDMIMEDIA::pfnFlush */
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdFlush(PPDMIMEDIA pInterface)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync LogFlowFunc(("\n"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
16a9adc14900ca18e6909679a579f6833425e030vboxsync int rc = VDFlush(pThis->pDisk);
16a9adc14900ca18e6909679a579f6833425e030vboxsync LogFlowFunc(("returns %Rrc\n", rc));
16a9adc14900ca18e6909679a579f6833425e030vboxsync return rc;
16a9adc14900ca18e6909679a579f6833425e030vboxsync}
16a9adc14900ca18e6909679a579f6833425e030vboxsync
16a9adc14900ca18e6909679a579f6833425e030vboxsync/** @copydoc PDMIMEDIA::pfnMerge */
16a9adc14900ca18e6909679a579f6833425e030vboxsyncstatic DECLCALLBACK(int) drvvdMerge(PPDMIMEDIA pInterface,
16a9adc14900ca18e6909679a579f6833425e030vboxsync PFNSIMPLEPROGRESS pfnProgress,
16a9adc14900ca18e6909679a579f6833425e030vboxsync void *pvUser)
16a9adc14900ca18e6909679a579f6833425e030vboxsync{
16a9adc14900ca18e6909679a579f6833425e030vboxsync LogFlowFunc(("\n"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
16a9adc14900ca18e6909679a579f6833425e030vboxsync int rc = VINF_SUCCESS;
16a9adc14900ca18e6909679a579f6833425e030vboxsync
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 AssertRC(rc2);
16a9adc14900ca18e6909679a579f6833425e030vboxsync if (RT_SUCCESS(rc2) && pThis->fMergePending)
16a9adc14900ca18e6909679a579f6833425e030vboxsync {
16a9adc14900ca18e6909679a579f6833425e030vboxsync /* Take shortcut: PFNSIMPLEPROGRESS is exactly the same type as
16a9adc14900ca18e6909679a579f6833425e030vboxsync * PFNVDPROGRESS, so there's no need for a conversion function. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync /** @todo maybe introduce a conversion which limits update frequency. */
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVDINTERFACE pVDIfsOperation = NULL;
16a9adc14900ca18e6909679a579f6833425e030vboxsync VDINTERFACE VDIProgress;
16a9adc14900ca18e6909679a579f6833425e030vboxsync VDINTERFACEPROGRESS VDIProgressCallbacks;
16a9adc14900ca18e6909679a579f6833425e030vboxsync VDIProgressCallbacks.cbSize = sizeof(VDINTERFACEPROGRESS);
16a9adc14900ca18e6909679a579f6833425e030vboxsync VDIProgressCallbacks.enmInterface = VDINTERFACETYPE_PROGRESS;
16a9adc14900ca18e6909679a579f6833425e030vboxsync VDIProgressCallbacks.pfnProgress = pfnProgress;
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync rc2 = VDInterfaceAdd(&VDIProgress, "DrvVD_VDIProgress", VDINTERFACETYPE_PROGRESS,
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync &VDIProgressCallbacks, pvUser, &pVDIfsOperation);
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync AssertRC(rc2);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync pThis->fMergePending = false;
9c149a2789022f5011e88fb62f02a1cc8068e88fvboxsync rc = VDMerge(pThis->pDisk, pThis->uMergeSource,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pThis->uMergeTarget, pVDIfsOperation);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync }
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc2 = RTSemFastMutexRelease(pThis->MergeCompleteMutex);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync AssertRC(rc2);
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync LogFlowFunc(("returns %Rrc\n", rc));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return rc;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnGetSize */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(uint64_t) drvvdGetSize(PPDMIMEDIA pInterface)
5d0d754550d06b7d59a935e59caaf814462d53ccvboxsync{
9496f2d398b49813176939d7a339ae513d5175efvboxsync LogFlowFunc(("\n"));
9496f2d398b49813176939d7a339ae513d5175efvboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync uint64_t cb = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync LogFlowFunc(("returns %#llx (%llu)\n", cb, cb));
9496f2d398b49813176939d7a339ae513d5175efvboxsync return cb;
9496f2d398b49813176939d7a339ae513d5175efvboxsync}
5d0d754550d06b7d59a935e59caaf814462d53ccvboxsync
9496f2d398b49813176939d7a339ae513d5175efvboxsync/** @copydoc PDMIMEDIA::pfnIsReadOnly */
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsyncstatic DECLCALLBACK(bool) drvvdIsReadOnly(PPDMIMEDIA pInterface)
9496f2d398b49813176939d7a339ae513d5175efvboxsync{
9496f2d398b49813176939d7a339ae513d5175efvboxsync LogFlowFunc(("\n"));
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync bool f = VDIsReadOnly(pThis->pDisk);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync LogFlowFunc(("returns %d\n", f));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return f;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync}
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync
d1bffa158f98ff3c18f7d085e7372c9ea00e9a43vboxsync/** @copydoc PDMIMEDIA::pfnBiosGetPCHSGeometry */
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsyncstatic DECLCALLBACK(int) drvvdBiosGetPCHSGeometry(PPDMIMEDIA pInterface,
d1bffa158f98ff3c18f7d085e7372c9ea00e9a43vboxsync PPDMMEDIAGEOMETRY pPCHSGeometry)
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync{
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync LogFlowFunc(("\n"));
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
f35c44bfc9e1036d0cb376fb144cdae416c7ef3avboxsync VDGEOMETRY geo;
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync int rc = VDGetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync if (RT_SUCCESS(rc))
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync {
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pPCHSGeometry->cCylinders = geo.cCylinders;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pPCHSGeometry->cHeads = geo.cHeads;
927320c7f81d3acdbccb5f3fea7548b4b7184b98vboxsync pPCHSGeometry->cSectors = geo.cSectors;
6b223679d40f5e57e55e867e806a9f194e2cde12vboxsync }
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync else
9496f2d398b49813176939d7a339ae513d5175efvboxsync {
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync LogFunc(("geometry not available.\n"));
9496f2d398b49813176939d7a339ae513d5175efvboxsync rc = VERR_PDM_GEOMETRY_NOT_SET;
9496f2d398b49813176939d7a339ae513d5175efvboxsync }
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync LogFlowFunc(("returns %Rrc (CHS=%d/%d/%d)\n",
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync return rc;
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnBiosSetPCHSGeometry */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdBiosSetPCHSGeometry(PPDMIMEDIA pInterface,
16a9adc14900ca18e6909679a579f6833425e030vboxsync PCPDMMEDIAGEOMETRY pPCHSGeometry)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync{
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync LogFlowFunc(("CHS=%d/%d/%d\n",
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
16a9adc14900ca18e6909679a579f6833425e030vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
16a9adc14900ca18e6909679a579f6833425e030vboxsync VDGEOMETRY geo;
16a9adc14900ca18e6909679a579f6833425e030vboxsync geo.cCylinders = pPCHSGeometry->cCylinders;
16a9adc14900ca18e6909679a579f6833425e030vboxsync geo.cHeads = pPCHSGeometry->cHeads;
16a9adc14900ca18e6909679a579f6833425e030vboxsync geo.cSectors = pPCHSGeometry->cSectors;
16a9adc14900ca18e6909679a579f6833425e030vboxsync int rc = VDSetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
16a9adc14900ca18e6909679a579f6833425e030vboxsync if (rc == VERR_VD_GEOMETRY_NOT_SET)
16a9adc14900ca18e6909679a579f6833425e030vboxsync rc = VERR_PDM_GEOMETRY_NOT_SET;
16a9adc14900ca18e6909679a579f6833425e030vboxsync LogFlowFunc(("returns %Rrc\n", rc));
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync return rc;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync}
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync/** @copydoc PDMIMEDIA::pfnBiosGetLCHSGeometry */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncstatic DECLCALLBACK(int) drvvdBiosGetLCHSGeometry(PPDMIMEDIA pInterface,
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PPDMMEDIAGEOMETRY pLCHSGeometry)
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync{
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync LogFlowFunc(("\n"));
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync VDGEOMETRY geo;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync int rc = VDGetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync if (RT_SUCCESS(rc))
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync {
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync pLCHSGeometry->cCylinders = geo.cCylinders;
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync pLCHSGeometry->cHeads = geo.cHeads;
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync pLCHSGeometry->cSectors = geo.cSectors;
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync }
4a23807f02e9920d92c8449bd93d84501add460avboxsync else
d9d5fbda1b8f7a6f7fae555db60d0e636fd03af8vboxsync {
4a23807f02e9920d92c8449bd93d84501add460avboxsync LogFunc(("geometry not available.\n"));
fe813b3594039ba864493438e78ee0e7132bc445vboxsync rc = VERR_PDM_GEOMETRY_NOT_SET;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync }
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync LogFlowFunc(("returns %Rrc (CHS=%d/%d/%d)\n",
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return rc;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnBiosSetLCHSGeometry */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdBiosSetLCHSGeometry(PPDMIMEDIA pInterface,
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PCPDMMEDIAGEOMETRY pLCHSGeometry)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync{
5b465a7c1237993faf8bb50120d247f3f0319adavboxsync LogFlowFunc(("CHS=%d/%d/%d\n",
09127e6ed46502ff8a6a521713ee8ace53667683vboxsync pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync VDGEOMETRY geo;
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync geo.cCylinders = pLCHSGeometry->cCylinders;
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync geo.cHeads = pLCHSGeometry->cHeads;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync geo.cSectors = pLCHSGeometry->cSectors;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync int rc = VDSetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync if (rc == VERR_VD_GEOMETRY_NOT_SET)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync rc = VERR_PDM_GEOMETRY_NOT_SET;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync LogFlowFunc(("returns %Rrc\n", rc));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync return rc;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/** @copydoc PDMIMEDIA::pfnGetUuid */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic DECLCALLBACK(int) drvvdGetUuid(PPDMIMEDIA pInterface, PRTUUID pUuid)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync{
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync LogFlowFunc(("\n"));
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync int rc = VDGetUuid(pThis->pDisk, 0, pUuid);
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync LogFlowFunc(("returns %Rrc ({%RTuuid})\n", rc, pUuid));
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync return rc;
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync}
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync/*******************************************************************************
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync* Async Media interface methods *
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync*******************************************************************************/
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncstatic void drvvdAsyncReqComplete(void *pvUser1, void *pvUser2, int rcReq)
8083a259c13e6e26e56ca2582edbad4a8cfac25avboxsync{
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync PVBOXDISK pThis = (PVBOXDISK)pvUser1;
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync
cba6719bd64ec749967bbe931230452664109857vboxsync int rc = pThis->pDrvMediaAsyncPort->pfnTransferCompleteNotify(pThis->pDrvMediaAsyncPort,
cba6719bd64ec749967bbe931230452664109857vboxsync pvUser2, rcReq);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync AssertRC(rc);
9496f2d398b49813176939d7a339ae513d5175efvboxsync}
9496f2d398b49813176939d7a339ae513d5175efvboxsync
cba6719bd64ec749967bbe931230452664109857vboxsyncstatic DECLCALLBACK(int) drvvdStartRead(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
cba6719bd64ec749967bbe931230452664109857vboxsync PCRTSGSEG paSeg, unsigned cSeg,
cba6719bd64ec749967bbe931230452664109857vboxsync size_t cbRead, void *pvUser)
cba6719bd64ec749967bbe931230452664109857vboxsync{
cba6719bd64ec749967bbe931230452664109857vboxsync LogFlowFunc(("uOffset=%#llx paSeg=%#p cSeg=%u cbRead=%d\n pvUser=%#p",
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync uOffset, paSeg, cSeg, cbRead, pvUser));
cba6719bd64ec749967bbe931230452664109857vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
pThis->fBootAccelActive = false;
int rc = VDAsyncRead(pThis->pDisk, uOffset, cbRead, paSeg, cSeg,
drvvdAsyncReqComplete, pThis, pvUser);
LogFlowFunc(("returns %Rrc\n", rc));
return rc;
}
static DECLCALLBACK(int) drvvdStartWrite(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
PCRTSGSEG paSeg, unsigned cSeg,
size_t cbWrite, void *pvUser)
{
LogFlowFunc(("uOffset=%#llx paSeg=%#p cSeg=%u cbWrite=%d pvUser=%#p\n",
uOffset, paSeg, cSeg, cbWrite, pvUser));
PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
pThis->fBootAccelActive = false;
int rc = VDAsyncWrite(pThis->pDisk, uOffset, cbWrite, paSeg, cSeg,
drvvdAsyncReqComplete, pThis, pvUser);
LogFlowFunc(("returns %Rrc\n", rc));
return rc;
}
static DECLCALLBACK(int) drvvdStartFlush(PPDMIMEDIAASYNC pInterface, void *pvUser)
{
LogFlowFunc(("pvUser=%#p\n", pvUser));
PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
int rc = VDAsyncFlush(pThis->pDisk, drvvdAsyncReqComplete, pThis, pvUser);
LogFlowFunc(("returns %Rrc\n", rc));
return rc;
}
/*******************************************************************************
* Base interface methods *
*******************************************************************************/
/**
* @interface_method_impl{PDMIBASE,pfnQueryInterface}
*/
static DECLCALLBACK(void *) drvvdQueryInterface(PPDMIBASE pInterface, const char *pszIID)
{
PPDMDRVINS pDrvIns = PDMIBASE_2_DRVINS(pInterface);
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIA, &pThis->IMedia);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAASYNC, pThis->fAsyncIOSupported ? &pThis->IMediaAsync : NULL);
return NULL;
}
/*******************************************************************************
* Saved state notification methods *
*******************************************************************************/
/**
* Load done callback for re-opening the image writable during teleportation.
*
* This is called both for successful and failed load runs, we only care about
* successfull ones.
*
* @returns VBox status code.
* @param pDrvIns The driver instance.
* @param pSSM The saved state handle.
*/
static DECLCALLBACK(int) drvvdLoadDone(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
{
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
Assert(!pThis->fErrorUseRuntime);
/* Drop out if we don't have any work to do or if it's a failed load. */
if ( !pThis->fTempReadOnly
|| RT_FAILURE(SSMR3HandleGetStatus(pSSM)))
return VINF_SUCCESS;
int rc = drvvdSetWritable(pThis);
if (RT_FAILURE(rc)) /** @todo does the bugger set any errors? */
return SSMR3SetLoadError(pSSM, rc, RT_SRC_POS,
N_("Failed to write lock the images"));
return VINF_SUCCESS;
}
/*******************************************************************************
* Driver methods *
*******************************************************************************/
static DECLCALLBACK(void) drvvdPowerOff(PPDMDRVINS pDrvIns)
{
LogFlowFunc(("\n"));
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
/*
* We must close the disk here to ensure that
* the backend closes all files before the
* async transport driver is destructed.
*/
int rc = VDCloseAll(pThis->pDisk);
AssertRC(rc);
}
/**
* VM resume notification that we use to undo what the temporary read-only image
* mode set by drvvdSuspend.
*
* Also switch to runtime error mode if we're resuming after a state load
* without having been powered on first.
*
* @param pDrvIns The driver instance data.
*
* @todo The VMSetError vs VMSetRuntimeError mess must be fixed elsewhere,
* we're making assumptions about Main behavior here!
*/
static DECLCALLBACK(void) drvvdResume(PPDMDRVINS pDrvIns)
{
LogFlowFunc(("\n"));
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
drvvdSetWritable(pThis);
pThis->fErrorUseRuntime = true;
}
/**
* The VM is being suspended, temporarily change to read-only image mode.
*
* This is important for several reasons:
* -# It makes sure that there are no pending writes to the image. Most
* backends implements this by closing and reopening the image in read-only
* mode.
* -# It allows Main to read the images during snapshotting without having
* to account for concurrent writes.
* -# This is essential for making teleportation targets sharing images work
* right. Both with regards to caching and with regards to file sharing
* locks (RTFILE_O_DENY_*). (See also drvvdLoadDone.)
*
* @param pDrvIns The driver instance data.
*/
static DECLCALLBACK(void) drvvdSuspend(PPDMDRVINS pDrvIns)
{
LogFlowFunc(("\n"));
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
drvvdSetReadonly(pThis);
}
/**
* VM PowerOn notification for undoing the TempReadOnly config option and
* changing to runtime error mode.
*
* @param pDrvIns The driver instance data.
*
* @todo The VMSetError vs VMSetRuntimeError mess must be fixed elsewhere,
* we're making assumptions about Main behavior here!
*/
static DECLCALLBACK(void) drvvdPowerOn(PPDMDRVINS pDrvIns)
{
LogFlowFunc(("\n"));
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
drvvdSetWritable(pThis);
pThis->fErrorUseRuntime = true;
}
/**
* @copydoc FNPDMDRVRESET
*/
static DECLCALLBACK(void) drvvdReset(PPDMDRVINS pDrvIns)
{
LogFlowFunc(("\n"));
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
if (pThis->fBootAccelEnabled)
{
pThis->fBootAccelActive = true;
pThis->cbDataValid = 0;
pThis->offDisk = 0;
}
}
/**
* @copydoc FNPDMDRVDESTRUCT
*/
static DECLCALLBACK(void) drvvdDestruct(PPDMDRVINS pDrvIns)
{
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
LogFlowFunc(("\n"));
PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
RTSEMFASTMUTEX mutex;
ASMAtomicXchgHandle(&pThis->MergeCompleteMutex, NIL_RTSEMFASTMUTEX, &mutex);
if (mutex != NIL_RTSEMFASTMUTEX)
{
/* Request the semaphore to wait until a potentially running merge
* operation has been finished. */
int rc = RTSemFastMutexRequest(mutex);
AssertRC(rc);
pThis->fMergePending = false;
rc = RTSemFastMutexRelease(mutex);
AssertRC(rc);
rc = RTSemFastMutexDestroy(mutex);
AssertRC(rc);
}
if (VALID_PTR(pThis->pDisk))
{
VDDestroy(pThis->pDisk);
pThis->pDisk = NULL;
}
drvvdFreeImages(pThis);
if (pThis->MergeLock != NIL_RTSEMRW)
{
int rc = RTSemRWDestroy(pThis->MergeLock);
AssertRC(rc);
pThis->MergeLock = NIL_RTSEMRW;
}
if (pThis->pbData)
RTMemFree(pThis->pbData);
}
/**
* Construct a VBox disk media driver instance.
*
* @copydoc FNPDMDRVCONSTRUCT
*/
static DECLCALLBACK(int) drvvdConstruct(PPDMDRVINS pDrvIns,
PCFGMNODE pCfg,
uint32_t fFlags)
{
LogFlowFunc(("\n"));
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
int rc = VINF_SUCCESS;
char *pszName = NULL; /**< The path of the disk image file. */
char *pszFormat = NULL; /**< The format backed to use for this image. */
bool fReadOnly; /**< True if the media is read-only. */
bool fMaybeReadOnly; /**< True if the media may or may not be read-only. */
bool fHonorZeroWrites; /**< True if zero blocks should be written. */
PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
/*
* Init the static parts.
*/
pDrvIns->IBase.pfnQueryInterface = drvvdQueryInterface;
pThis->pDrvIns = pDrvIns;
pThis->fTempReadOnly = false;
pThis->pDisk = NULL;
pThis->fAsyncIOSupported = false;
pThis->fShareable = false;
pThis->fMergePending = false;
pThis->MergeCompleteMutex = NIL_RTSEMFASTMUTEX;
pThis->uMergeSource = VD_LAST_IMAGE;
pThis->uMergeTarget = VD_LAST_IMAGE;
/* IMedia */
pThis->IMedia.pfnRead = drvvdRead;
pThis->IMedia.pfnWrite = drvvdWrite;
pThis->IMedia.pfnFlush = drvvdFlush;
pThis->IMedia.pfnMerge = drvvdMerge;
pThis->IMedia.pfnGetSize = drvvdGetSize;
pThis->IMedia.pfnIsReadOnly = drvvdIsReadOnly;
pThis->IMedia.pfnBiosGetPCHSGeometry = drvvdBiosGetPCHSGeometry;
pThis->IMedia.pfnBiosSetPCHSGeometry = drvvdBiosSetPCHSGeometry;
pThis->IMedia.pfnBiosGetLCHSGeometry = drvvdBiosGetLCHSGeometry;
pThis->IMedia.pfnBiosSetLCHSGeometry = drvvdBiosSetLCHSGeometry;
pThis->IMedia.pfnGetUuid = drvvdGetUuid;
/* IMediaAsync */
pThis->IMediaAsync.pfnStartRead = drvvdStartRead;
pThis->IMediaAsync.pfnStartWrite = drvvdStartWrite;
pThis->IMediaAsync.pfnStartFlush = drvvdStartFlush;
/* Initialize supported VD interfaces. */
pThis->pVDIfsDisk = NULL;
pThis->VDIErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
pThis->VDIErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
pThis->VDIErrorCallbacks.pfnError = drvvdErrorCallback;
pThis->VDIErrorCallbacks.pfnMessage = NULL;
rc = VDInterfaceAdd(&pThis->VDIError, "DrvVD_VDIError", VDINTERFACETYPE_ERROR,
&pThis->VDIErrorCallbacks, pDrvIns, &pThis->pVDIfsDisk);
AssertRC(rc);
/* This is just prepared here, the actual interface is per-image, so it's
* added later. No need to have separate callback tables. */
pThis->VDIConfigCallbacks.cbSize = sizeof(VDINTERFACECONFIG);
pThis->VDIConfigCallbacks.enmInterface = VDINTERFACETYPE_CONFIG;
pThis->VDIConfigCallbacks.pfnAreKeysValid = drvvdCfgAreKeysValid;
pThis->VDIConfigCallbacks.pfnQuerySize = drvvdCfgQuerySize;
pThis->VDIConfigCallbacks.pfnQuery = drvvdCfgQuery;
/* List of images is empty now. */
pThis->pImages = NULL;
/* Try to attach async media port interface above.*/
pThis->pDrvMediaAsyncPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAASYNCPORT);
/*
* Validate configuration and find all parent images.
* It's sort of up side down from the image dependency tree.
*/
bool fHostIP = false;
bool fUseNewIo = false;
unsigned iLevel = 0;
PCFGMNODE pCurNode = pCfg;
for (;;)
{
bool fValid;
if (pCurNode == pCfg)
{
/* Toplevel configuration additionally contains the global image
* open flags. Some might be converted to per-image flags later. */
fValid = CFGMR3AreValuesValid(pCurNode,
"Format\0Path\0"
"ReadOnly\0MaybeReadOnly\0TempReadOnly\0Shareable\0HonorZeroWrites\0"
"HostIPStack\0UseNewIo\0BootAcceleration\0BootAccelerationBuffer\0"
"SetupMerge\0MergeSource\0MergeTarget\0");
}
else
{
/* All other image configurations only contain image name and
* the format information. */
fValid = CFGMR3AreValuesValid(pCurNode, "Format\0Path\0"
"MergeSource\0MergeTarget\0");
}
if (!fValid)
{
rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
RT_SRC_POS, N_("DrvVD: Configuration error: keys incorrect at level %d"), iLevel);
break;
}
if (pCurNode == pCfg)
{
rc = CFGMR3QueryBoolDef(pCurNode, "HostIPStack", &fHostIP, true);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"HostIPStack\" as boolean failed"));
break;
}
rc = CFGMR3QueryBoolDef(pCurNode, "HonorZeroWrites", &fHonorZeroWrites, false);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"HonorZeroWrites\" as boolean failed"));
break;
}
rc = CFGMR3QueryBoolDef(pCurNode, "ReadOnly", &fReadOnly, false);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"ReadOnly\" as boolean failed"));
break;
}
rc = CFGMR3QueryBoolDef(pCurNode, "MaybeReadOnly", &fMaybeReadOnly, false);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"MaybeReadOnly\" as boolean failed"));
break;
}
rc = CFGMR3QueryBoolDef(pCurNode, "TempReadOnly", &pThis->fTempReadOnly, false);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"TempReadOnly\" as boolean failed"));
break;
}
if (fReadOnly && pThis->fTempReadOnly)
{
rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"TempReadOnly\" are set"));
break;
}
rc = CFGMR3QueryBoolDef(pCurNode, "Shareable", &pThis->fShareable, false);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"Shareable\" as boolean failed"));
break;
}
rc = CFGMR3QueryBoolDef(pCurNode, "UseNewIo", &fUseNewIo, false);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"UseNewIo\" as boolean failed"));
break;
}
rc = CFGMR3QueryBoolDef(pCurNode, "SetupMerge", &pThis->fMergePending, false);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"SetupMerge\" as boolean failed"));
break;
}
if (fReadOnly && pThis->fMergePending)
{
rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"MergePending\" are set"));
break;
}
rc = CFGMR3QueryBoolDef(pCurNode, "BootAcceleration", &pThis->fBootAccelEnabled, false);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"BootAcceleration\" as boolean failed"));
break;
}
rc = CFGMR3QueryU32Def(pCurNode, "BootAccelerationBuffer", (uint32_t *)&pThis->cbBootAccelBuffer, 16 * _1K);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"BootAccelerationBuffer\" as integer failed"));
break;
}
}
PCFGMNODE pParent = CFGMR3GetChild(pCurNode, "Parent");
if (!pParent)
break;
pCurNode = pParent;
iLevel++;
}
/*
* Create the image container and the necessary interfaces.
*/
if (RT_SUCCESS(rc))
{
/* First of all figure out what kind of TCP networking stack interface
* to use. This is done unconditionally, as backends which don't need
* it will just ignore it. */
if (fHostIP)
{
pThis->VDITcpNetCallbacks.cbSize = sizeof(VDINTERFACETCPNET);
pThis->VDITcpNetCallbacks.enmInterface = VDINTERFACETYPE_TCPNET;
pThis->VDITcpNetCallbacks.pfnSocketCreate = drvvdTcpSocketCreate;
pThis->VDITcpNetCallbacks.pfnSocketDestroy = drvvdTcpSocketDestroy;
pThis->VDITcpNetCallbacks.pfnClientConnect = drvvdTcpClientConnect;
pThis->VDITcpNetCallbacks.pfnIsClientConnected = drvvdTcpIsClientConnected;
pThis->VDITcpNetCallbacks.pfnClientClose = drvvdTcpClientClose;
pThis->VDITcpNetCallbacks.pfnSelectOne = drvvdTcpSelectOne;
pThis->VDITcpNetCallbacks.pfnRead = drvvdTcpRead;
pThis->VDITcpNetCallbacks.pfnWrite = drvvdTcpWrite;
pThis->VDITcpNetCallbacks.pfnSgWrite = drvvdTcpSgWrite;
pThis->VDITcpNetCallbacks.pfnReadNB = drvvdTcpReadNB;
pThis->VDITcpNetCallbacks.pfnWriteNB = drvvdTcpWriteNB;
pThis->VDITcpNetCallbacks.pfnSgWriteNB = drvvdTcpSgWriteNB;
pThis->VDITcpNetCallbacks.pfnFlush = drvvdTcpFlush;
pThis->VDITcpNetCallbacks.pfnSetSendCoalescing = drvvdTcpSetSendCoalescing;
pThis->VDITcpNetCallbacks.pfnGetLocalAddress = drvvdTcpGetLocalAddress;
pThis->VDITcpNetCallbacks.pfnGetPeerAddress = drvvdTcpGetPeerAddress;
/*
* There is a 15ms delay between receiving the data and marking the socket
* as readable on Windows XP which hurts async I/O performance of
* TCP backends badly. Provide a different select method without
* using poll on XP.
* This is only used on XP because it is not as efficient as the one using poll
* and all other Windows versions are working fine.
*/
char szOS[64];
memset(szOS, 0, sizeof(szOS));
rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, &szOS[0], sizeof(szOS));
if (RT_SUCCESS(rc) && !strncmp(szOS, "Windows XP", 10))
{
LogRel(("VD: Detected Windows XP, disabled poll based waiting for TCP\n"));
pThis->VDITcpNetCallbacks.pfnSelectOneEx = drvvdTcpSelectOneExNoPoll;
}
else
pThis->VDITcpNetCallbacks.pfnSelectOneEx = drvvdTcpSelectOneExPoll;
pThis->VDITcpNetCallbacks.pfnPoke = drvvdTcpPoke;
}
else
{
#ifndef VBOX_WITH_INIP
rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
RT_SRC_POS, N_("DrvVD: Configuration error: TCP over Internal Networking not compiled in"));
#else /* VBOX_WITH_INIP */
pThis->VDITcpNetCallbacks.cbSize = sizeof(VDINTERFACETCPNET);
pThis->VDITcpNetCallbacks.enmInterface = VDINTERFACETYPE_TCPNET;
pThis->VDITcpNetCallbacks.pfnSocketCreate = drvvdINIPSocketCreate;
pThis->VDITcpNetCallbacks.pfnSocketDestroy = drvvdINIPSocketDestroy;
pThis->VDITcpNetCallbacks.pfnClientConnect = drvvdINIPClientConnect;
pThis->VDITcpNetCallbacks.pfnClientClose = drvvdINIPClientClose;
pThis->VDITcpNetCallbacks.pfnIsClientConnected = drvvdINIPIsClientConnected;
pThis->VDITcpNetCallbacks.pfnSelectOne = drvvdINIPSelectOne;
pThis->VDITcpNetCallbacks.pfnRead = drvvdINIPRead;
pThis->VDITcpNetCallbacks.pfnWrite = drvvdINIPWrite;
pThis->VDITcpNetCallbacks.pfnSgWrite = drvvdINIPSgWrite;
pThis->VDITcpNetCallbacks.pfnFlush = drvvdINIPFlush;
pThis->VDITcpNetCallbacks.pfnSetSendCoalescing = drvvdINIPSetSendCoalescing;
pThis->VDITcpNetCallbacks.pfnGetLocalAddress = drvvdINIPGetLocalAddress;
pThis->VDITcpNetCallbacks.pfnGetPeerAddress = drvvdINIPGetPeerAddress;
pThis->VDITcpNetCallbacks.pfnSelectOneEx = drvvdINIPSelectOneEx;
pThis->VDITcpNetCallbacks.pfnPoke = drvvdINIPPoke;
#endif /* VBOX_WITH_INIP */
}
if (RT_SUCCESS(rc))
{
rc = VDInterfaceAdd(&pThis->VDITcpNet, "DrvVD_INIP",
VDINTERFACETYPE_TCPNET,
&pThis->VDITcpNetCallbacks, NULL,
&pThis->pVDIfsDisk);
}
/** @todo quick hack to work around problems in the async I/O
* implementation (rw semaphore thread ownership problem)
* while a merge is running. Remove once this is fixed. */
if (pThis->fMergePending)
fUseNewIo = false;
if (RT_SUCCESS(rc) && fUseNewIo)
{
#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
pThis->VDIAsyncIOCallbacks.cbSize = sizeof(VDINTERFACEASYNCIO);
pThis->VDIAsyncIOCallbacks.enmInterface = VDINTERFACETYPE_ASYNCIO;
pThis->VDIAsyncIOCallbacks.pfnOpen = drvvdAsyncIOOpen;
pThis->VDIAsyncIOCallbacks.pfnClose = drvvdAsyncIOClose;
pThis->VDIAsyncIOCallbacks.pfnGetSize = drvvdAsyncIOGetSize;
pThis->VDIAsyncIOCallbacks.pfnSetSize = drvvdAsyncIOSetSize;
pThis->VDIAsyncIOCallbacks.pfnReadSync = drvvdAsyncIOReadSync;
pThis->VDIAsyncIOCallbacks.pfnWriteSync = drvvdAsyncIOWriteSync;
pThis->VDIAsyncIOCallbacks.pfnFlushSync = drvvdAsyncIOFlushSync;
pThis->VDIAsyncIOCallbacks.pfnReadAsync = drvvdAsyncIOReadAsync;
pThis->VDIAsyncIOCallbacks.pfnWriteAsync = drvvdAsyncIOWriteAsync;
pThis->VDIAsyncIOCallbacks.pfnFlushAsync = drvvdAsyncIOFlushAsync;
rc = VDInterfaceAdd(&pThis->VDIAsyncIO, "DrvVD_AsyncIO", VDINTERFACETYPE_ASYNCIO,
&pThis->VDIAsyncIOCallbacks, pThis, &pThis->pVDIfsDisk);
#else /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
RT_SRC_POS, N_("DrvVD: Configuration error: Async Completion Framework not compiled in"));
#endif /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
}
if (RT_SUCCESS(rc) && pThis->fMergePending)
{
rc = RTSemFastMutexCreate(&pThis->MergeCompleteMutex);
if (RT_SUCCESS(rc))
rc = RTSemRWCreate(&pThis->MergeLock);
if (RT_SUCCESS(rc))
{
pThis->VDIThreadSyncCallbacks.cbSize = sizeof(VDINTERFACETHREADSYNC);
pThis->VDIThreadSyncCallbacks.enmInterface = VDINTERFACETYPE_THREADSYNC;
pThis->VDIThreadSyncCallbacks.pfnStartRead = drvvdThreadStartRead;
pThis->VDIThreadSyncCallbacks.pfnFinishRead = drvvdThreadFinishRead;
pThis->VDIThreadSyncCallbacks.pfnStartWrite = drvvdThreadStartWrite;
pThis->VDIThreadSyncCallbacks.pfnFinishWrite = drvvdThreadFinishWrite;
rc = VDInterfaceAdd(&pThis->VDIThreadSync, "DrvVD_ThreadSync", VDINTERFACETYPE_THREADSYNC,
&pThis->VDIThreadSyncCallbacks, pThis, &pThis->pVDIfsDisk);
}
else
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Failed to create semaphores for \"MergePending\""));
}
}
if (RT_SUCCESS(rc))
{
rc = VDCreate(pThis->pVDIfsDisk, &pThis->pDisk);
/* Error message is already set correctly. */
}
}
if (pThis->pDrvMediaAsyncPort && fUseNewIo)
pThis->fAsyncIOSupported = true;
unsigned iImageIdx = 0;
while (pCurNode && RT_SUCCESS(rc))
{
/* Allocate per-image data. */
PVBOXIMAGE pImage = drvvdNewImage(pThis);
if (!pImage)
{
rc = VERR_NO_MEMORY;
break;
}
/*
* Read the image configuration.
*/
rc = CFGMR3QueryStringAlloc(pCurNode, "Path", &pszName);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"Path\" as string failed"));
break;
}
rc = CFGMR3QueryStringAlloc(pCurNode, "Format", &pszFormat);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"Format\" as string failed"));
break;
}
bool fMergeSource;
rc = CFGMR3QueryBoolDef(pCurNode, "MergeSource", &fMergeSource, false);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"MergeSource\" as boolean failed"));
break;
}
if (fMergeSource)
{
if (pThis->uMergeSource == VD_LAST_IMAGE)
pThis->uMergeSource = iImageIdx;
else
{
rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
N_("DrvVD: Configuration error: Multiple \"MergeSource\" occurrences"));
break;
}
}
bool fMergeTarget;
rc = CFGMR3QueryBoolDef(pCurNode, "MergeTarget", &fMergeTarget, false);
if (RT_FAILURE(rc))
{
rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"MergeTarget\" as boolean failed"));
break;
}
if (fMergeTarget)
{
if (pThis->uMergeTarget == VD_LAST_IMAGE)
pThis->uMergeTarget = iImageIdx;
else
{
rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
N_("DrvVD: Configuration error: Multiple \"MergeTarget\" occurrences"));
break;
}
}
PCFGMNODE pCfgVDConfig = CFGMR3GetChild(pCurNode, "VDConfig");
rc = VDInterfaceAdd(&pImage->VDIConfig, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
&pThis->VDIConfigCallbacks, pCfgVDConfig, &pImage->pVDIfsImage);
AssertRC(rc);
/*
* Open the image.
*/
unsigned uOpenFlags;
if (fReadOnly || pThis->fTempReadOnly || iLevel != 0)
uOpenFlags = VD_OPEN_FLAGS_READONLY;
else
uOpenFlags = VD_OPEN_FLAGS_NORMAL;
if (fHonorZeroWrites)
uOpenFlags |= VD_OPEN_FLAGS_HONOR_ZEROES;
if (pThis->fAsyncIOSupported)
uOpenFlags |= VD_OPEN_FLAGS_ASYNC_IO;
if (pThis->fShareable)
uOpenFlags |= VD_OPEN_FLAGS_SHAREABLE;
/* Try to open backend in async I/O mode first. */
rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
if (rc == VERR_NOT_SUPPORTED)
{
pThis->fAsyncIOSupported = false;
uOpenFlags &= ~VD_OPEN_FLAGS_ASYNC_IO;
rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
}
if (RT_SUCCESS(rc))
{
LogFunc(("%d - Opened '%s' in %s mode\n",
iLevel, pszName,
VDIsReadOnly(pThis->pDisk) ? "read-only" : "read-write"));
if ( VDIsReadOnly(pThis->pDisk)
&& !fReadOnly
&& !fMaybeReadOnly
&& !pThis->fTempReadOnly
&& iLevel == 0)
{
rc = PDMDrvHlpVMSetError(pDrvIns, VERR_VD_IMAGE_READ_ONLY, RT_SRC_POS,
N_("Failed to open image '%s' for writing due to wrong permissions"),
pszName);
break;
}
}
else
{
rc = PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
N_("Failed to open image '%s' in %s mode rc=%Rrc"), pszName,
(uOpenFlags & VD_OPEN_FLAGS_READONLY) ? "read-only" : "read-write", rc);
break;
}
MMR3HeapFree(pszName);
pszName = NULL;
MMR3HeapFree(pszFormat);
pszFormat = NULL;
/* next */
iLevel--;
iImageIdx++;
pCurNode = CFGMR3GetParent(pCurNode);
}
if ( RT_SUCCESS(rc)
&& pThis->fMergePending
&& ( pThis->uMergeSource == VD_LAST_IMAGE
|| pThis->uMergeTarget == VD_LAST_IMAGE))
{
rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
N_("DrvVD: Configuration error: Inconsistent image merge data"));
}
/*
* Register a load-done callback so we can undo TempReadOnly config before
* we get to drvvdResume. Autoamtically deregistered upon destruction.
*/
if (RT_SUCCESS(rc))
rc = PDMDrvHlpSSMRegisterEx(pDrvIns, 0 /* version */, 0 /* cbGuess */,
NULL /*pfnLivePrep*/, NULL /*pfnLiveExec*/, NULL /*pfnLiveVote*/,
NULL /*pfnSavePrep*/, NULL /*pfnSaveExec*/, NULL /*pfnSaveDone*/,
NULL /*pfnDonePrep*/, NULL /*pfnLoadExec*/, drvvdLoadDone);
/* Setup the boot acceleration stuff if enabled. */
if (RT_SUCCESS(rc) && pThis->fBootAccelEnabled)
{
pThis->cbDisk = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
Assert(pThis->cbDisk > 0);
pThis->pbData = (uint8_t *)RTMemAllocZ(pThis->cbBootAccelBuffer);
if (pThis->pbData)
{
pThis->fBootAccelActive = true;
pThis->offDisk = 0;
pThis->cbDataValid = 0;
LogRel(("VD: Boot acceleration enabled\n"));
}
else
LogRel(("VD: Boot acceleration, out of memory, disabled\n"));
}
if (RT_FAILURE(rc))
{
if (VALID_PTR(pszName))
MMR3HeapFree(pszName);
if (VALID_PTR(pszFormat))
MMR3HeapFree(pszFormat);
/* drvvdDestruct does the rest. */
}
LogFlowFunc(("returns %Rrc\n", rc));
return rc;
}
/**
* VBox disk container media driver registration record.
*/
const PDMDRVREG g_DrvVD =
{
/* u32Version */
PDM_DRVREG_VERSION,
/* szName */
"VD",
/* szRCMod */
"",
/* szR0Mod */
"",
/* pszDescription */
"Generic VBox disk media driver.",
/* fFlags */
PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
/* fClass. */
PDM_DRVREG_CLASS_MEDIA,
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(VBOXDISK),
/* pfnConstruct */
drvvdConstruct,
/* pfnDestruct */
drvvdDestruct,
/* pfnRelocate */
NULL,
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
drvvdPowerOn,
/* pfnReset */
drvvdReset,
/* pfnSuspend */
drvvdSuspend,
/* pfnResume */
drvvdResume,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnPowerOff */
drvvdPowerOff,
/* pfnSoftReset */
NULL,
/* u32EndVersion */
PDM_DRVREG_VERSION
};