StorageControllerImpl.cpp revision 3e729152bacbdd8ae206df8fafe3187bb9fb7614
/* $Id$ */
/** @file
*
* Implementation of IStorageController.
*/
/*
* Copyright (C) 2008-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "StorageControllerImpl.h"
#include "MachineImpl.h"
#include "VirtualBoxImpl.h"
#include "SystemPropertiesImpl.h"
#include <VBox/settings.h>
#include <algorithm>
#include "AutoStateDep.h"
#include "AutoCaller.h"
#include "Logging.h"
// defines
/////////////////////////////////////////////////////////////////////////////
{
/* Constructor. */
mInstance(0),
mPortCount(2),
fUseHostIOCache(true),
mPortIde0Master(0),
mPortIde0Slave(1),
mPortIde1Master(2),
{ }
/** Unique name of the storage controller. */
/** The connection type of the storage controller. */
/** Type of the Storage controller. */
/** Instance number of the storage controller. */
/** Number of usable ports. */
/** Whether to use the host IO caches. */
/** The following is only for the SATA controller atm. */
/** Port which acts as primary master for ide emulation. */
/** Port which acts as primary slave for ide emulation. */
/** Port which acts as secondary master for ide emulation. */
/** Port which acts as secondary slave for ide emulation. */
};
struct StorageController::Data
{
: pVirtualBox(NULL),
{
}
VirtualBox * const pVirtualBox;
SystemProperties * const pSystemProperties;
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void StorageController::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the storage controller object.
*
* @returns COM result indicator.
* @param aParent Pointer to our parent object.
* @param aName Name of the storage controller.
* @param aInstance Instance number of the storage controller.
*/
{
LogFlowThisFunc(("aParent=%p aName=\"%s\" aInstance=%u\n",
if ( (aStorageBus <= StorageBus_Null)
|| (aStorageBus > StorageBus_SAS))
return setError(E_INVALIDARG,
tr("Invalid storage connection type"));
HRESULT rc = aParent->getVirtualBox()->getSystemProperties()->GetMaxInstancesOfStorageBus(aStorageBus, &maxInstances);
return rc;
if (aInstance >= maxInstances)
return setError(E_INVALIDARG,
tr("Too many storage controllers of this type"));
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* m->pPeer is left null */
/* register with parent early, since uninit() will unconditionally
* unregister on failure */
m->pParent->addDependentChild(this);
if ( aStorageBus != StorageBus_IDE
&& aStorageBus != StorageBus_Floppy)
m->bd->fUseHostIOCache = false;
else
m->bd->fUseHostIOCache = true;
switch (aStorageBus)
{
case StorageBus_IDE:
break;
case StorageBus_SATA:
break;
case StorageBus_SCSI:
break;
case StorageBus_Floppy:
break;
case StorageBus_SAS:
break;
}
/* Confirm a successful initialization */
return S_OK;
}
/**
* Initializes the object given another object
* (a kind of copy constructor). This object shares data with
* the object passed as an argument.
*
* @param aReshare
* When false, the original object will remain a data owner.
* Otherwise, data ownership will be transferred from the original
* object to this one.
*
* @note This object must be destroyed before the original object
* it shares data with is destroyed.
*
* @note Locks @a aThat object for writing if @a aReshare is @c true, or for
* reading if @a aReshare is false.
*/
bool aReshare /* = false */)
{
LogFlowThisFunc(("aParent=%p, aThat=%p, aReshare=%RTbool\n",
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* register with parent early, since uninit() will unconditionally
* unregister on failure */
m->pParent->addDependentChild(this);
/* sanity */
if (aReshare)
{
}
else
{
}
/* Confirm successful initialization */
return S_OK;
}
/**
* Initializes the storage controller object given another guest object
* (a kind of copy constructor). This object makes a private copy of data
* of the original object passed as an argument.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* m->pPeer is left null */
m->pParent->addDependentChild(this);
/* Confirm a successful initialization */
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void StorageController::uninit()
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
m->pParent->removeDependentChild(this);
delete m;
m = NULL;
}
// IStorageController properties
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
/* mName is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
STDMETHODIMP StorageController::COMGETTER(ControllerType) (StorageControllerType_T *aControllerType)
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
switch (m->bd->mStorageBus)
{
case StorageBus_IDE:
{
if ( (aControllerType != StorageControllerType_PIIX3)
rc = E_INVALIDARG;
break;
}
case StorageBus_SATA:
{
rc = E_INVALIDARG;
break;
}
case StorageBus_SCSI:
{
rc = E_INVALIDARG;
break;
}
case StorageBus_Floppy:
{
rc = E_INVALIDARG;
break;
}
case StorageBus_SAS:
{
rc = E_INVALIDARG;
break;
}
default:
}
tr ("Invalid controller type %d"),
return S_OK;
}
{
AutoCaller autoCaller(this);
HRESULT rc = m->pSystemProperties->GetMaxDevicesPerPortForStorageBus(m->bd->mStorageBus, aMaxDevices);
return rc;
}
{
AutoCaller autoCaller(this);
return rc;
}
{
AutoCaller autoCaller(this);
return rc;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
switch (m->bd->mStorageBus)
{
case StorageBus_SATA:
{
/* AHCI SATA supports a maximum of 30 ports. */
return setError(E_INVALIDARG,
tr("Invalid port count: %lu (must be in range [%lu, %lu])"),
break;
}
case StorageBus_SCSI:
{
/*
* SCSI does not support setting different ports.
* (doesn't make sense here either).
* The maximum and minimum is 16 and unless the callee
* tries to set a different value we return an error.
*/
if (aPortCount != 16)
return setError(E_INVALIDARG,
tr("Invalid port count: %lu (must be in range [%lu, %lu])"),
break;
}
case StorageBus_IDE:
{
/*
* The port count is fixed to 2.
*/
if (aPortCount != 2)
return setError(E_INVALIDARG,
tr("Invalid port count: %lu (must be in range [%lu, %lu])"),
break;
}
case StorageBus_Floppy:
{
/*
* The port count is fixed to 1.
*/
if (aPortCount != 1)
return setError(E_INVALIDARG,
tr("Invalid port count: %lu (must be in range [%lu, %lu])"),
break;
}
case StorageBus_SAS:
{
/*
* The port count is fixed to 8.
*/
if (aPortCount != 8)
return setError(E_INVALIDARG,
tr("Invalid port count: %lu (must be in range [%lu, %lu])"),
break;
}
default:
}
AutoCaller autoCaller(this);
/* the machine needs to be mutable */
{
m->pParent->onStorageControllerChange();
}
return S_OK;
}
{
AutoCaller autoCaller(this);
/* The machine doesn't need to be mutable. */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* The machine doesn't need to be mutable. */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* The machine doesn't need to be mutable. */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* the machine needs to be mutable */
{
m->pParent->onStorageControllerChange();
}
return S_OK;
}
// IStorageController methods
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
tr("Invalid controller type"));
switch (DevicePosition)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
return E_INVALIDARG;
}
return S_OK;
}
{
AutoCaller autoCaller(this);
/* the machine needs to be mutable */
tr("Invalid controller type"));
return setError(E_INVALIDARG,
tr("Invalid port number: %l (must be in range [%lu, %lu])"),
aPortNumber, 0, 29);
switch (DevicePosition)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
return E_INVALIDARG;
}
return S_OK;
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
{
}
{
return m->bd->mStorageControllerType;
}
{
return m->bd->mStorageBus;
}
{
}
/**
* Returns S_OK if the given port and device numbers are within the range supported
* by this controller. If not, it sets an error and returns E_INVALIDARG.
* @param ulPort
* @param ulDevice
* @return
*/
{
HRESULT rc = m->pSystemProperties->GetMaxDevicesPerPortForStorageBus(m->bd->mStorageBus, &devicesPerPort);
if ( (aControllerPort < 0)
|| (aDevice < 0)
)
return setError(E_INVALIDARG,
return S_OK;
}
/** @note Locks objects for writing! */
void StorageController::rollback()
{
AutoCaller autoCaller(this);
}
/**
* @note Locks this object for writing, together with the peer object (also
* for writing) if there is one.
*/
void StorageController::commit()
{
/* sanity */
AutoCaller autoCaller(this);
/* sanity too */
/* lock both for writing since we modify both (m->pPeer is "master" so locked
* first) */
if (m->bd.isBackedUp())
{
if (m->pPeer)
{
// attach new data to the peer and reshare it
}
}
}
/**
* Cancels sharing (if any) by making an independent copy of data.
* This operation also resets this object's peer to NULL.
*
* @note Locks this object for writing, together with the peer object
* represented by @a aThat (locked for reading).
*/
void StorageController::unshare()
{
/* sanity */
AutoCaller autoCaller(this);
/* sanity too */
/* peer is not modified, lock it for reading (m->pPeer is "master" so locked
* first) */
{
if (!m->bd.isBackedUp())
}
}
{
return m->pParent;
}
{
return m->pPeer;
}
// private methods
/////////////////////////////////////////////////////////////////////////////
/* vi: set tabstop=4 shiftwidth=4 expandtab: */