StorageControllerImpl.cpp revision 32529464ff2d4288a3c949ab8042126b0fa903de
/* $Id$ */
/** @file
*
* Implementation of IStorageController.
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "StorageControllerImpl.h"
#include "MachineImpl.h"
#include "VirtualBoxImpl.h"
#include "Logging.h"
#include <iprt/cpputils.h>
#include <VBox/settings.h>
#include <algorithm>
// defines
/////////////////////////////////////////////////////////////////////////////
// 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.
*/
{
if ( (aStorageBus <= StorageBus_Null)
|| (aStorageBus > StorageBus_SCSI))
return setError (E_INVALIDARG,
tr ("Invalid storage connection type"));
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* mPeer is left null */
/* register with parent early, since uninit() will unconditionally
* unregister on failure */
mParent->addDependentChild (this);
switch (aStorageBus)
{
case StorageBus_IDE:
break;
case StorageBus_SATA:
break;
case StorageBus_SCSI:
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 */
mParent->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);
/* mPeer is left null */
mParent->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;
mParent->removeDependentChild (this);
}
// IStorageController properties
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
/* mName is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
AutoReadLock alock(this);
return S_OK;
}
STDMETHODIMP StorageController::COMGETTER(ControllerType) (StorageControllerType_T *aControllerType)
{
AutoCaller autoCaller(this);
AutoReadLock alock(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
switch (mData->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;
}
default:
}
tr ("Invalid controller type %d"),
return S_OK;
}
{
AutoCaller autoCaller(this);
AutoReadLock alock(this);
switch (mData->mStorageBus)
{
case StorageBus_SATA:
case StorageBus_SCSI:
{
/* SATA and both SCSI controllers only support one device per port. */
*aMaxDevices = 1;
break;
}
case StorageBus_IDE:
{
/* The IDE controllers support 2 devices. One as master and one as slave. */
*aMaxDevices = 2;
break;
}
default:
}
return S_OK;
}
{
AutoCaller autoCaller(this);
AutoReadLock alock(this);
switch (mData->mStorageBus)
{
case StorageBus_SATA:
{
*aMinPortCount = 1;
break;
}
case StorageBus_SCSI:
{
*aMinPortCount = 16;
break;
}
case StorageBus_IDE:
{
*aMinPortCount = 2;
break;
}
default:
}
return S_OK;
}
{
AutoCaller autoCaller(this);
AutoReadLock alock(this);
switch (mData->mStorageBus)
{
case StorageBus_SATA:
{
*aMaxPortCount = 30;
break;
}
case StorageBus_SCSI:
{
*aMaxPortCount = 16;
break;
}
case StorageBus_IDE:
{
*aMaxPortCount = 2;
break;
}
default:
}
return S_OK;
}
{
AutoCaller autoCaller(this);
AutoReadLock alock(this);
return S_OK;
}
{
switch (mData->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;
}
default:
}
AutoCaller autoCaller(this);
/* the machine needs to be mutable */
AutoWriteLock alock(this);
{
/* leave the lock for safety */
}
return S_OK;
}
{
AutoCaller autoCaller(this);
/* The machine doesn't need to be mutable. */
AutoReadLock alock(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
/* The machine doesn't need to be mutable. */
AutoWriteLock alock(this);
return S_OK;
}
// IStorageController methods
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
AutoReadLock alock(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 */
AutoWriteLock alock(this);
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
/////////////////////////////////////////////////////////////////////////////
/** @note Locks objects for writing! */
bool StorageController::rollback()
{
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
bool dataChanged = false;
if (mData.isBackedUp())
{
/* we need to check all data to see whether anything will be changed
* after rollback */
}
return dataChanged;
}
/**
* @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 (mPeer is "master" so locked
* first) */
if (mData.isBackedUp())
{
if (mPeer)
{
// 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 (mPeer is "master" so locked
* first) */
{
if (!mData.isBackedUp())
}
}
// private methods
/////////////////////////////////////////////////////////////////////////////
/* vi: set tabstop=4 shiftwidth=4 expandtab: */