DrvVD.cpp revision 548ca31b6b47c36bacce49bed3339cb8075b9681
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** $Id$ */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @file
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * VBox storage devices:
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Media implementation for VBox disk container
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Copyright (C) 2006-2008 Sun Microsystems, Inc.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * available from http://www.virtualbox.org. This file is free software;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * you can redistribute it and/or modify it under the terms of the GNU
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * General Public License (GPL) as published by the Free Software
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * additional information or have any questions.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Header files *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#define LOG_GROUP LOG_GROUP_DRV_VD
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <VBox/VBoxHDD-new.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <VBox/pdmdrv.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <iprt/alloc.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <iprt/assert.h>
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync#include <iprt/uuid.h>
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync#include <iprt/file.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <iprt/string.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <iprt/cache.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include "Builtins.h"
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Defined types, constants and macros *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync*******************************************************************************/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Converts a pointer to VDIDISK::IMedia to a PVBOXDISK. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync#define PDMIMEDIA_2_VBOXDISK(pInterface) \
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync ( (PVBOXDISK)((uintptr_t)pInterface - RT_OFFSETOF(VBOXDISK, IMedia)) )
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Converts a pointer to PDMDRVINS::IBase to a PPDMDRVINS. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync#define PDMIBASE_2_DRVINS(pInterface) \
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync ( (PPDMDRVINS)((uintptr_t)pInterface - RT_OFFSETOF(PDMDRVINS, IBase)) )
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Converts a pointer to PDMDRVINS::IBase to a PVBOXDISK. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync#define PDMIBASE_2_VBOXDISK(pInterface) \
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync ( PDMINS_2_DATA(PDMIBASE_2_DRVINS(pInterface), PVBOXDISK) )
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Converts a pointer to VBOXDISK::IMediaAsync to a PVBOXDISK. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync#define PDMIMEDIAASYNC_2_VBOXDISK(pInterface) \
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync ( (PVBOXDISK)((uintptr_t)pInterface - RT_OFFSETOF(VBOXDISK, IMediaAsync)) )
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Converts a pointer to VBOXDISK::ITransportAsyncPort to a PVBOXDISK. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync#define PDMITRANSPORTASYNCPORT_2_VBOXDISK(pInterface) \
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync ( (PVBOXDISK)((uintptr_t)pInterface - RT_OFFSETOF(VBOXDISK, ITransportAsyncPort)) )
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync/**
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync * Structure for an async I/O task.
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsynctypedef struct DRVVDASYNCTASK
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync{
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Callback which is called on completion. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync PFNVDCOMPLETED pfnCompleted;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Opqaue user data which is passed on completion. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync void *pvUser;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Opaque user data the caller passed on transfer initiation. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync void *pvUserCaller;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync} DRVVDASYNCTASK, *PDRVVDASYNCTASK;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/**
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * VBox disk container media main structure, private part.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsynctypedef struct VBOXDISK
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** The VBox disk container. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PVBOXHDD pDisk;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** The media interface. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync PDMIMEDIA IMedia;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Pointer to the driver instance. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync PPDMDRVINS pDrvIns;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Flag whether suspend has changed image open mode to read only. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync bool fTempReadOnly;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Common structure for the supported error interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync VDINTERFACE VDIError;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Callback table for error interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync VDINTERFACEERROR VDIErrorCallbacks;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Common structure for the supported async I/O interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync VDINTERFACE VDIAsyncIO;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Callback table for async I/O interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync VDINTERFACEASYNCIO VDIAsyncIOCallbacks;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Common structure for the configuration information interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync VDINTERFACE VDIConfig;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Callback table for the configuration information interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync VDINTERFACECONFIG VDIConfigCallbacks;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Flag whether opened disk suppports async I/O operations. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync bool fAsyncIOSupported;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** The async media interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDMIMEDIAASYNC IMediaAsync;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** The async media port interface above. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PPDMIMEDIAASYNCPORT pDrvMediaAsyncPort;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Pointer to the asynchronous media driver below. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PPDMITRANSPORTASYNC pDrvTransportAsync;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Async transport port interface. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDMITRANSPORTASYNCPORT ITransportAsyncPort;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Our cache to reduce allocation overhead. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PRTOBJCACHE pCache;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync} VBOXDISK, *PVBOXDISK;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Error reporting callback *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic void drvvdErrorCallback(void *pvUser, int rc, RT_SRC_POS_DECL,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync const char *pszFormat, va_list va)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PPDMDRVINS pDrvIns = (PPDMDRVINS)pvUser;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pDrvIns->pDrvHlp->pfnVMSetErrorV(pDrvIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/*******************************************************************************
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync* VD Async I/O interface implementation *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync*******************************************************************************/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOOpen(void *pvUser, const char *pszLocation, bool fReadonly, void **ppStorage)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pDrvVD = (PVBOXDISK)pvUser;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pDrvVD->pDrvTransportAsync->pfnOpen(pDrvVD->pDrvTransportAsync, pszLocation, fReadonly, ppStorage);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOClose(void *pvUser, void *pStorage)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pDrvVD = (PVBOXDISK)pvUser;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return pDrvVD->pDrvTransportAsync->pfnClose(pDrvVD->pDrvTransportAsync, pStorage);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdAsyncIORead(void *pvUser, void *pStorage, uint64_t uOffset,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbRead, void *pvBuf, size_t *pcbRead)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PVBOXDISK pDrvVD = (PVBOXDISK)pvUser;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return pDrvVD->pDrvTransportAsync->pfnReadSynchronous(pDrvVD->pDrvTransportAsync,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pStorage,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uOffset, pvBuf, cbRead, pcbRead);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOWrite(void *pvUser, void *pStorage, uint64_t uOffset,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbWrite, const void *pvBuf, size_t *pcbWritten)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pDrvVD = (PVBOXDISK)pvUser;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync return pDrvVD->pDrvTransportAsync->pfnWriteSynchronous(pDrvVD->pDrvTransportAsync,
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync pStorage,
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync uOffset, pvBuf, cbWrite, pcbWritten);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOFlush(void *pvUser, void *pStorage)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync PVBOXDISK pDrvVD = (PVBOXDISK)pvUser;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return pDrvVD->pDrvTransportAsync->pfnFlushSynchronous(pDrvVD->pDrvTransportAsync, pStorage);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync}
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOPrepareRead(void *pvUser, void *pStorage, uint64_t uOffset, void *pvBuf, size_t cbRead, void **ppTask)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pDrvVD = (PVBOXDISK)pvUser;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pDrvVD->pDrvTransportAsync->pfnPrepareRead(pDrvVD->pDrvTransportAsync, pStorage, uOffset, pvBuf, cbRead, ppTask);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOPrepareWrite(void *pvUser, void *pStorage, uint64_t uOffset, void *pvBuf, size_t cbWrite, void **ppTask)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PVBOXDISK pDrvVD = (PVBOXDISK)pvUser;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pDrvVD->pDrvTransportAsync->pfnPrepareWrite(pDrvVD->pDrvTransportAsync, pStorage, uOffset, pvBuf, cbWrite, ppTask);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOTasksSubmit(void *pvUser, void *apTasks[], unsigned cTasks, void *pvUser2,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync void *pvUserCaller, PFNVDCOMPLETED pfnTasksCompleted)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync{
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync PVBOXDISK pDrvVD = (PVBOXDISK)pvUser;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVVDASYNCTASK pDrvVDAsyncTask;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync int rc;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync rc = RTCacheRequest(pDrvVD->pCache, (void **)&pDrvVDAsyncTask);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync if (RT_FAILURE(rc))
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return rc;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pDrvVDAsyncTask->pfnCompleted = pfnTasksCompleted;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pDrvVDAsyncTask->pvUser = pvUser2;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pDrvVDAsyncTask->pvUserCaller = pvUserCaller;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pDrvVD->pDrvTransportAsync->pfnTasksSubmit(pDrvVD->pDrvTransportAsync, apTasks, cTasks, pDrvVDAsyncTask);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* VD Configuration interface implementation *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic bool drvvdCfgAreValuesValid(PVDCFGNODE pNode, const char *pszzValid)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3AreValuesValid((PCFGMNODE)pNode, pszzValid);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic int drvvdCfgQueryType(PVDCFGNODE pNode, const char *pszName, PVDCFGVALUETYPE penmType)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync Assert(VDCFGVALUETYPE_INTEGER == CFGMVALUETYPE_INTEGER);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Assert(VDCFGVALUETYPE_STRING == CFGMVALUETYPE_STRING);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync Assert(VDCFGVALUETYPE_BYTES == CFGMVALUETYPE_BYTES);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3QueryType((PCFGMNODE)pNode, pszName, (PCFGMVALUETYPE)penmType);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync}
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsyncstatic int drvvdCfgQuerySize(PVDCFGNODE pNode, const char *pszName, size_t *pcb)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync{
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3QuerySize((PCFGMNODE)pNode, pszName, pcb);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync}
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsyncstatic int drvvdCfgQueryInteger(PVDCFGNODE pNode, const char *pszName, uint64_t *pu64)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync{
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3QueryInteger((PCFGMNODE)pNode, pszName, pu64);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync}
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsyncstatic int drvvdCfgQueryIntegerDef(PVDCFGNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync{
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3QueryInteger((PCFGMNODE)pNode, pszName, pu64);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync}
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsyncstatic int drvvdCfgQueryString(PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync{
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3QueryString((PCFGMNODE)pNode, pszName, pszString, cchString);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync}
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic int drvvdCfgQueryStringDef(PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return CFGMR3QueryStringDef((PCFGMNODE)pNode, pszName, pszString, cchString, pszDef);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic int drvvdCfgQueryBytes(PVDCFGNODE pNode, const char *pszName, void *pvData, size_t cbData)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return CFGMR3QueryBytes((PCFGMNODE)pNode, pszName, pvData, cbData);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/*******************************************************************************
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync* Media interface methods *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync*******************************************************************************/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnRead */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdRead(PPDMIMEDIA pInterface,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uint64_t off, void *pvBuf, size_t cbRead)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: off=%#llx pvBuf=%p cbRead=%d\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync off, pvBuf, cbRead));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDRead(pThis->pDisk, off, pvBuf, cbRead);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (RT_SUCCESS(rc))
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Log2(("%s: off=%#llx pvBuf=%p cbRead=%d %.*Vhxd\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync off, pvBuf, cbRead, cbRead, pvBuf));
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync LogFlow(("%s: returns %Vrc\n", __FUNCTION__, rc));
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync return rc;
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnWrite */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdWrite(PPDMIMEDIA pInterface,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uint64_t off, const void *pvBuf,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbWrite)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: off=%#llx pvBuf=%p cbWrite=%d\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync off, pvBuf, cbWrite));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Log2(("%s: off=%#llx pvBuf=%p cbWrite=%d %.*Vhxd\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync off, pvBuf, cbWrite, cbWrite, pvBuf));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDWrite(pThis->pDisk, off, pvBuf, cbWrite);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Vrc\n", __FUNCTION__, rc));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnFlush */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdFlush(PPDMIMEDIA pInterface)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s:\n", __FUNCTION__));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDFlush(pThis->pDisk);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Vrc\n", __FUNCTION__, rc));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnGetSize */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(uint64_t) drvvdGetSize(PPDMIMEDIA pInterface)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s:\n", __FUNCTION__));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uint64_t cb = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %#llx (%llu)\n", __FUNCTION__, cb, cb));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return cb;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnIsReadOnly */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(bool) drvvdIsReadOnly(PPDMIMEDIA pInterface)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s:\n", __FUNCTION__));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync bool f = VDIsReadOnly(pThis->pDisk);
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync LogFlow(("%s: returns %d\n", __FUNCTION__, f));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return f;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnBiosGetPCHSGeometry */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdBiosGetPCHSGeometry(PPDMIMEDIA pInterface,
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync PPDMMEDIAGEOMETRY pPCHSGeometry)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync LogFlow(("%s:\n", __FUNCTION__));
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync int rc = VDGetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, pPCHSGeometry);
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync if (RT_FAILURE(rc))
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync {
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync Log(("%s: geometry not available.\n", __FUNCTION__));
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync rc = VERR_PDM_GEOMETRY_NOT_SET;
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync }
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync LogFlow(("%s: returns %Vrc (CHS=%d/%d/%d)\n", __FUNCTION__,
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIMEDIA::pfnBiosSetPCHSGeometry */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdBiosSetPCHSGeometry(PPDMIMEDIA pInterface,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PCPDMMEDIAGEOMETRY pPCHSGeometry)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: CHS=%d/%d/%d\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDSetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, pPCHSGeometry);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Vrc\n", __FUNCTION__, rc));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnBiosGetLCHSGeometry */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdBiosGetLCHSGeometry(PPDMIMEDIA pInterface,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PPDMMEDIAGEOMETRY pLCHSGeometry)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s:\n", __FUNCTION__));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDGetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, pLCHSGeometry);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (RT_FAILURE(rc))
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Log(("%s: geometry not available.\n", __FUNCTION__));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync rc = VERR_PDM_GEOMETRY_NOT_SET;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Vrc (CHS=%d/%d/%d)\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnBiosSetLCHSGeometry */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdBiosSetLCHSGeometry(PPDMIMEDIA pInterface,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PCPDMMEDIAGEOMETRY pLCHSGeometry)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: CHS=%d/%d/%d\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDSetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, pLCHSGeometry);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Vrc\n", __FUNCTION__, rc));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnGetUuid */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdGetUuid(PPDMIMEDIA pInterface, PRTUUID pUuid)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s:\n", __FUNCTION__));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDGetUuid(pThis->pDisk, 0, pUuid);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Vrc ({%Vuuid})\n", __FUNCTION__, rc, pUuid));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/*******************************************************************************
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync* Async Media interface methods *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync*******************************************************************************/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdStartRead(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PPDMDATASEG paSeg, unsigned cSeg,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbRead, void *pvUser)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: uOffset=%#llx paSeg=%#p cSeg=%u cbRead=%d\n pvUser=%#p", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uOffset, paSeg, cSeg, cbRead, pvUser));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDAsyncRead(pThis->pDisk, uOffset, cbRead, paSeg, cSeg, pvUser);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Vrc\n", __FUNCTION__, rc));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdStartWrite(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PPDMDATASEG paSeg, unsigned cSeg,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbWrite, void *pvUser)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: uOffset=%#llx paSeg=%#p cSeg=%u cbWrite=%d\n pvUser=%#p", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uOffset, paSeg, cSeg, cbWrite, pvUser));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDAsyncWrite(pThis->pDisk, uOffset, cbWrite, paSeg, cSeg, pvUser);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Vrc\n", __FUNCTION__, rc));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/*******************************************************************************
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync* Async transport port interface methods *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync*******************************************************************************/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdTasksCompleteNotify(PPDMITRANSPORTASYNCPORT pInterface, void *pvUser)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMITRANSPORTASYNCPORT_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVVDASYNCTASK pDrvVDAsyncTask = (PDRVVDASYNCTASK)pvUser;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VINF_VDI_ASYNC_IO_FINISHED;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* Having a completion callback for a task is not mandatory. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (pDrvVDAsyncTask->pfnCompleted)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync rc = pDrvVDAsyncTask->pfnCompleted(pDrvVDAsyncTask->pvUser);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* Check if the request is finished. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (rc == VINF_VDI_ASYNC_IO_FINISHED)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = pThis->pDrvMediaAsyncPort->pfnTransferCompleteNotify(pThis->pDrvMediaAsyncPort, pDrvVDAsyncTask->pvUserCaller);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync else if (rc == VERR_VDI_ASYNC_IO_IN_PROGRESS)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = VINF_SUCCESS;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = RTCacheInsert(pThis->pCache, pDrvVDAsyncTask);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertRC(rc);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return rc;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Base interface methods *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIBASE::pfnQueryInterface */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(void *) drvvdQueryInterface(PPDMIBASE pInterface,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDMINTERFACE enmInterface)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PPDMDRVINS pDrvIns = PDMIBASE_2_DRVINS(pInterface);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync switch (enmInterface)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync case PDMINTERFACE_BASE:
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return &pDrvIns->IBase;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync case PDMINTERFACE_MEDIA:
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return &pThis->IMedia;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync case PDMINTERFACE_MEDIA_ASYNC:
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pThis->fAsyncIOSupported ? &pThis->IMediaAsync : NULL;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync case PDMINTERFACE_TRANSPORT_ASYNC_PORT:
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return &pThis->ITransportAsyncPort;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync default:
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return NULL;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Driver methods *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/**
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Construct a VBox disk media driver instance.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * @returns VBox status.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * @param pDrvIns The driver instance data.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * If the registration structure is needed, pDrvIns->pDrvReg points to it.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * of the driver instance. It's also found in pDrvIns->pCfgHandle as it's expected
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * to be used frequently in this function.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdConstruct(PPDMDRVINS pDrvIns,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PCFGMNODE pCfgHandle)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync LogFlow(("%s:\n", __FUNCTION__));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync int rc = VINF_SUCCESS;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync char *pszName = NULL; /**< The path of the disk image file. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync char *pszFormat = NULL; /**< The format backed to use for this image. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync bool fReadOnly; /**< True if the media is readonly. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync bool fHonorZeroWrites; /**< True if zero blocks should be written. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /*
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Init the static parts.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pDrvIns->IBase.pfnQueryInterface = drvvdQueryInterface;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->pDrvIns = pDrvIns;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->fTempReadOnly = false;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->pDisk = NULL;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* IMedia */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMedia.pfnRead = drvvdRead;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMedia.pfnWrite = drvvdWrite;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMedia.pfnFlush = drvvdFlush;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMedia.pfnGetSize = drvvdGetSize;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMedia.pfnIsReadOnly = drvvdIsReadOnly;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMedia.pfnBiosGetPCHSGeometry = drvvdBiosGetPCHSGeometry;
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync pThis->IMedia.pfnBiosSetPCHSGeometry = drvvdBiosSetPCHSGeometry;
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync pThis->IMedia.pfnBiosGetLCHSGeometry = drvvdBiosGetLCHSGeometry;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMedia.pfnBiosSetLCHSGeometry = drvvdBiosSetLCHSGeometry;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMedia.pfnGetUuid = drvvdGetUuid;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* IMediaAsync */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMediaAsync.pfnStartRead = drvvdStartRead;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMediaAsync.pfnStartWrite = drvvdStartWrite;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* ITransportAsyncPort */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->ITransportAsyncPort.pfnTaskCompleteNotify = drvvdTasksCompleteNotify;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* Initialize supported VD interfaces. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->VDIErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->VDIErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIErrorCallbacks.pfnError = drvvdErrorCallback;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = VDInterfaceCreate(&pThis->VDIError, "DrvVD_VDIError", VDINTERFACETYPE_ERROR,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync &pThis->VDIErrorCallbacks, pDrvIns, NULL);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertRC(rc);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.cbSize = sizeof(VDINTERFACEASYNCIO);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.enmInterface = VDINTERFACETYPE_ASYNCIO;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnOpen = drvvdAsyncIOOpen;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnClose = drvvdAsyncIOClose;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnRead = drvvdAsyncIORead;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnWrite = drvvdAsyncIOWrite;
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync pThis->VDIAsyncIOCallbacks.pfnFlush = drvvdAsyncIOFlush;
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync pThis->VDIAsyncIOCallbacks.pfnPrepareRead = drvvdAsyncIOPrepareRead;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnPrepareWrite = drvvdAsyncIOPrepareWrite;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnTasksSubmit = drvvdAsyncIOTasksSubmit;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = VDInterfaceCreate(&pThis->VDIAsyncIO, "DrvVD_AsyncIO", VDINTERFACETYPE_ASYNCIO,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync &pThis->VDIAsyncIOCallbacks, pThis, &pThis->VDIError);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertRC(rc);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.cbSize = sizeof(VDINTERFACECONFIG);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.enmInterface = VDINTERFACETYPE_CONFIG;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnAreValuesValid = drvvdCfgAreValuesValid;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryType = drvvdCfgQueryType;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQuerySize = drvvdCfgQuerySize;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryInteger = drvvdCfgQueryInteger;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryIntegerDef = drvvdCfgQueryIntegerDef;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryString = drvvdCfgQueryString;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryStringDef = drvvdCfgQueryStringDef;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryBytes = drvvdCfgQueryBytes;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** @todo TEMP! this isn't really correct - this needs to be made per image,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * as CFGM needs access to the right configuration node for each image.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * At the moment this is harmless, as iSCSI can only be used as a base
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * image, and no other backend uses the private data for these callbacks. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = VDInterfaceCreate(&pThis->VDIConfig, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync &pThis->VDIConfigCallbacks, NULL /**< @todo TEMP */, &pThis->VDIAsyncIO);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertRC(rc);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Try to attach async media port interface above.*/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->pDrvMediaAsyncPort = (PPDMIMEDIAASYNCPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_MEDIA_ASYNC_PORT);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /*
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Attach the async transport driver below of the device above us implements the
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * async interface.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (pThis->pDrvMediaAsyncPort)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Try to attach the driver. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PPDMIBASE pBase;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = pDrvIns->pDrvHlp->pfnAttach(pDrvIns, &pBase);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /*
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Though the device supports async I/O the backend seems to not support it.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Revert to non async I/O.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->pDrvMediaAsyncPort = NULL;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync else if (RT_FAILURE(rc))
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertMsgFailed(("Failed to attach async transport driver below rc=%Vrc\n", rc));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync else
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Success query the async transport interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->pDrvTransportAsync = (PPDMITRANSPORTASYNC)pBase->pfnQueryInterface(pBase, PDMINTERFACE_TRANSPORT_ASYNC);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (!pThis->pDrvTransportAsync)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Whoops. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertMsgFailed(("Configuration error: No async transport interface below!\n"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return VERR_PDM_MISSING_INTERFACE_ABOVE;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /*
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Validate configuration and find all parent images.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * It's sort of up side down from the image dependency tree.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync unsigned iLevel = 0;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PCFGMNODE pCurNode = pCfgHandle;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync for (;;)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync bool fValid;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (pCurNode == pCfgHandle)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Toplevel configuration additionally contains the global image
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * open flags. Some might be converted to per-image flags later. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync fValid = CFGMR3AreValuesValid(pCurNode,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync "Format\0Path\0"
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync "ReadOnly\0HonorZeroWrites\0");
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync else
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* All other image configurations only contain image name and
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * the format information. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync fValid = CFGMR3AreValuesValid(pCurNode, "Format\0Path\0");
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (!fValid)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RT_SRC_POS, N_("DrvVD: Configuration error: keys incorrect at level %d"), iLevel);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync break;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PCFGMNODE pParent = CFGMR3GetChild(pCurNode, "Parent");
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (!pParent)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync break;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pCurNode = pParent;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync iLevel++;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /*
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Open the images.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (RT_SUCCESS(rc))
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** @todo TEMP! later the iSCSI config callbacks won't be included here */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = VDCreate(&pThis->VDIConfig, &pThis->pDisk);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Error message is already set correctly. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync unsigned cImages = iLevel;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync while (pCurNode && RT_SUCCESS(rc))
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /*
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Read the image configuration.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "Path", &pszName);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (RT_FAILURE(rc))
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = PDMDRV_SET_ERROR(pDrvIns, rc,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync N_("DrvVD: Configuration error: Querying \"Path\" as string failed"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync break;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = CFGMR3QueryStringAlloc(pCfgHandle, "Format", &pszFormat);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (RT_FAILURE(rc))
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = PDMDRV_SET_ERROR(pDrvIns, rc,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync N_("DrvVD: Configuration error: Querying \"Format\" as string failed"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync break;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (iLevel == 0)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = CFGMR3QueryBool(pCurNode, "ReadOnly", &fReadOnly);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (rc == VERR_CFGM_VALUE_NOT_FOUND)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync fReadOnly = false;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync else if (RT_FAILURE(rc))
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = PDMDRV_SET_ERROR(pDrvIns, rc,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync N_("DrvVD: Configuration error: Querying \"ReadOnly\" as boolean failed"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync break;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = CFGMR3QueryBool(pCfgHandle, "HonorZeroWrites", &fHonorZeroWrites);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (rc == VERR_CFGM_VALUE_NOT_FOUND)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync fHonorZeroWrites = false;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync else if (RT_FAILURE(rc))
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = PDMDRV_SET_ERROR(pDrvIns, rc,
N_("DrvVD: Configuration error: Querying \"HonorZeroWrites\" as boolean failed"));
break;
}
}
else
{
fReadOnly = true;
fHonorZeroWrites = false;
}
/** @todo TEMP! Later this needs to be done for each image. */
if (iLevel == cImages)
{
PCFGMNODE pCfg = CFGMR3GetChild(pCurNode, "VDConfig");
pThis->VDIConfig.pvUser = pCfg; /**< @todo TEMP! */
}
/*
* Open the image.
*/
unsigned uOpenFlags;
if (fReadOnly)
uOpenFlags = VD_OPEN_FLAGS_READONLY;
else
uOpenFlags = VD_OPEN_FLAGS_NORMAL;
if (fHonorZeroWrites)
uOpenFlags |= VD_OPEN_FLAGS_HONOR_ZEROES;
if (pThis->pDrvMediaAsyncPort)
uOpenFlags |= VD_OPEN_FLAGS_ASYNC_IO;
/** Try to open backend in asyc I/O mode first. */
rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags);
if (rc == VERR_NOT_SUPPORTED)
{
/* Seems async I/O is not supported by the backend, open in normal mode. */
uOpenFlags &= ~VD_OPEN_FLAGS_ASYNC_IO;
rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags);
}
if (RT_SUCCESS(rc))
Log(("%s: %d - Opened '%s' in %s mode\n", __FUNCTION__,
iLevel, pszName,
VDIsReadOnly(pThis->pDisk) ? "read-only" : "read-write"));
else
{
AssertMsgFailed(("Failed to open image '%s' rc=%Vrc\n", pszName, rc));
break;
}
MMR3HeapFree(pszName);
pszName = NULL;
MMR3HeapFree(pszFormat);
pszFormat = NULL;
/* next */
iLevel--;
pCurNode = CFGMR3GetParent(pCurNode);
}
if (RT_FAILURE(rc))
{
if (VALID_PTR(pThis->pDisk))
{
VDDestroy(pThis->pDisk);
pThis->pDisk = NULL;
}
if (VALID_PTR(pszName))
MMR3HeapFree(pszName);
if (VALID_PTR(pszFormat))
MMR3HeapFree(pszFormat);
}
/*
* Check for async I/O support. Every opened image has to support
* it.
*/
pThis->fAsyncIOSupported = true;
for (unsigned i = 0; i < VDGetCount(pThis->pDisk); i++)
{
VDBACKENDINFO vdBackendInfo;
rc = VDBackendInfoSingle(pThis->pDisk, i, &vdBackendInfo);
AssertRC(rc);
if (vdBackendInfo.uBackendCaps & VD_CAP_ASYNC)
{
/*
* Backend indicates support for at least some files.
* Check if current file is supported with async I/O)
*/
rc = VDImageIsAsyncIOSupported(pThis->pDisk, i, &pThis->fAsyncIOSupported);
AssertRC(rc);
/*
* Check if current image is supported.
* If not we can stop checking because
* at least one does not support it.
*/
if (!pThis->fAsyncIOSupported)
break;
}
else
{
pThis->fAsyncIOSupported = false;
break;
}
}
/* Create cache if async I/O is supported. */
if (pThis->fAsyncIOSupported)
{
rc = RTCacheCreate(&pThis->pCache, 0, sizeof(DRVVDASYNCTASK), RTOBJCACHE_PROTECT_INSERT);
AssertMsg(RT_SUCCESS(rc), ("Failed to create cache rc=%Vrc\n", rc));
}
LogFlow(("%s: returns %Vrc\n", __FUNCTION__, rc));
return rc;
}
/**
* Destruct a driver instance.
*
* Most VM resources are freed by the VM. This callback is provided so that any non-VM
* resources can be freed correctly.
*
* @param pDrvIns The driver instance data.
*/
static DECLCALLBACK(void) drvvdDestruct(PPDMDRVINS pDrvIns)
{
int rc;
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
LogFlow(("%s:\n", __FUNCTION__));
if (pThis->pCache)
{
rc = RTCacheDestroy(pThis->pCache);
AssertRC(rc);
}
}
/**
* When the VM has been suspended we'll change the image mode to read-only
* so that main and others can read the VDIs. This is important when
* saving state and so forth.
*
* @param pDrvIns The driver instance data.
*/
static DECLCALLBACK(void) drvvdSuspend(PPDMDRVINS pDrvIns)
{
LogFlow(("%s:\n", __FUNCTION__));
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
if (!VDIsReadOnly(pThis->pDisk))
{
unsigned uOpenFlags;
int rc = VDGetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, &uOpenFlags);
AssertRC(rc);
uOpenFlags |= VD_OPEN_FLAGS_READONLY;
rc = VDSetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, uOpenFlags);
AssertRC(rc);
pThis->fTempReadOnly = true;
}
}
/**
* Before the VM resumes we'll have to undo the read-only mode change
* done in drvvdSuspend.
*
* @param pDrvIns The driver instance data.
*/
static DECLCALLBACK(void) drvvdResume(PPDMDRVINS pDrvIns)
{
LogFlow(("%s:\n", __FUNCTION__));
PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
if (pThis->fTempReadOnly)
{
unsigned uOpenFlags;
int rc = VDGetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, &uOpenFlags);
AssertRC(rc);
uOpenFlags &= ~VD_OPEN_FLAGS_READONLY;
rc = VDSetOpenFlags(pThis->pDisk, VD_LAST_IMAGE, uOpenFlags);
AssertRC(rc);
pThis->fTempReadOnly = false;
}
}
static DECLCALLBACK(void) drvvdPowerOff(PPDMDRVINS pDrvIns)
{
LogFlow(("%s:\n", __FUNCTION__));
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);
}
/**
* VBox disk container media driver registration record.
*/
const PDMDRVREG g_DrvVD =
{
/* u32Version */
PDM_DRVREG_VERSION,
/* szDriverName */
"VD",
/* 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,
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
NULL,
/* pfnSuspend */
drvvdSuspend,
/* pfnResume */
drvvdResume,
/* pfnDetach */
NULL,
/* pfnPowerOff */
drvvdPowerOff
};