VirtualBox

Changeset 31308 in vbox for trunk


Ignore:
Timestamp:
Aug 2, 2010 2:55:22 PM (14 years ago)
Author:
vboxsync
Message:

Main: storage controller/attachment cleanup

Location:
trunk/src/VBox/Main
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/MachineImpl.cpp

    r31307 r31308  
    31533153    if (FAILED(rc)) return rc;
    31543154
    3155     /* check that the port and device are not out of range. */
    3156     ULONG portCount;
    3157     ULONG devicesPerPort;
    3158     rc = ctl->COMGETTER(PortCount)(&portCount);
     3155    // check that the port and device are not out of range
     3156    rc = ctl->checkPortAndDeviceValid(aControllerPort, aDevice);
    31593157    if (FAILED(rc)) return rc;
    3160     rc = ctl->COMGETTER(MaxDevicesPerPortCount)(&devicesPerPort);
    3161     if (FAILED(rc)) return rc;
    3162 
    3163     if (   (aControllerPort < 0)
    3164         || (aControllerPort >= (LONG)portCount)
    3165         || (aDevice < 0)
    3166         || (aDevice >= (LONG)devicesPerPort)
    3167        )
    3168         return setError(E_INVALIDARG,
    3169                         tr("The port and/or count parameter are out of range [%lu:%lu]"),
    3170                         portCount,
    3171                         devicesPerPort);
    31723158
    31733159    /* check if the device slot is already busy */
     
    32303216                        medium->getLocationFull().raw());
    32313217
    3232     bool indirect = false;
     3218    bool fImplicit = false;
    32333219    if (!medium.isNull())
    3234         indirect = medium->isReadOnly();
     3220        fImplicit = medium->isReadOnly();
    32353221    bool associate = true;
    32363222
     
    32463232            if ((pAttachTemp = findAttachment(oldAtts, medium)))
    32473233            {
    3248                 AssertReturn(!indirect, E_FAIL);
     3234                AssertReturn(!fImplicit, E_FAIL);
    32493235
    32503236                /* see if it's the same bus/channel/device */
     
    32653251
    32663252        /* go further only if the attachment is to be indirect */
    3267         if (!indirect)
     3253        if (!fImplicit)
    32683254            break;
    32693255
     
    33333319                    mediumLock.attach(medium);
    33343320                    /* not implicit, doesn't require association with this VM */
    3335                     indirect = false;
     3321                    fImplicit = false;
    33363322                    associate = false;
    33373323                    /* go right to the MediumAttachment creation */
     
    34773463    ComObjPtr<MediumAttachment> attachment;
    34783464    attachment.createObject();
    3479     rc = attachment->init(this, medium, aControllerName, aControllerPort, aDevice, aType, indirect, 0 /* No bandwidth limit */);
     3465    rc = attachment->init(this,
     3466                          medium,
     3467                          aControllerName,
     3468                          aControllerPort,
     3469                          aDevice,
     3470                          aType,
     3471                          fImplicit,
     3472                          0 /* No bandwidth limit */);
    34803473    if (FAILED(rc)) return rc;
    34813474
  • trunk/src/VBox/Main/MediumImpl.cpp

    r31306 r31308  
    32363236    {
    32373237        /* use the default format if not */
    3238         AutoReadLock propsLock(m->pVirtualBox->systemProperties() COMMA_LOCKVAL_SRC_POS);
     3238        AutoReadLock propsLock(m->pVirtualBox->getSystemProperties() COMMA_LOCKVAL_SRC_POS);
    32393239        strFormat = m->pVirtualBox->getDefaultHardDiskFormat();
    32403240    }
     
    48434843    /* get the format object first */
    48444844    {
    4845         AutoReadLock propsLock(m->pVirtualBox->systemProperties() COMMA_LOCKVAL_SRC_POS);
    4846 
    4847         unconst(m->formatObj)
    4848             = m->pVirtualBox->systemProperties()->mediumFormat(aFormat);
     4845        SystemProperties *pSysProps = m->pVirtualBox->getSystemProperties();
     4846        AutoReadLock propsLock(pSysProps COMMA_LOCKVAL_SRC_POS);
     4847
     4848        unconst(m->formatObj) = pSysProps->mediumFormat(aFormat);
    48494849        if (m->formatObj.isNull())
    48504850            return setError(E_INVALIDARG,
  • trunk/src/VBox/Main/StorageControllerImpl.cpp

    r29686 r31308  
    2121#include "MachineImpl.h"
    2222#include "VirtualBoxImpl.h"
     23#include "SystemPropertiesImpl.h"
    2324
    2425#include <iprt/string.h>
     
    7980{
    8081    Data()
    81         : pParent(NULL)
     82        : pVirtualBox(NULL),
     83          pSystemProperties(NULL),
     84          pParent(NULL)
    8285    { }
     86
     87    VirtualBox * const                  pVirtualBox;
     88    SystemProperties * const            pSystemProperties;
    8389
    8490    Machine * const                     pParent;
     
    131137
    132138    m = new Data();
     139
     140    unconst(m->pVirtualBox) = aParent->getVirtualBox();
     141    unconst(m->pSystemProperties) = m->pVirtualBox->getSystemProperties();
    133142
    134143    unconst(m->pParent) = aParent;
     
    412421
    413422    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    414 
    415     ComPtr<IVirtualBox> VBox;
    416     HRESULT rc = m->pParent->COMGETTER(Parent)(VBox.asOutParam());
    417     if (FAILED(rc))
    418         return rc;
    419 
    420     ComPtr<ISystemProperties> sysProps;
    421     rc = VBox->COMGETTER(SystemProperties)(sysProps.asOutParam());
    422     if (FAILED(rc))
    423         return rc;
    424 
    425     rc = sysProps->GetMaxDevicesPerPortForStorageBus(m->bd->mStorageBus, aMaxDevices);
     423    HRESULT rc = m->pSystemProperties->GetMaxDevicesPerPortForStorageBus(m->bd->mStorageBus, aMaxDevices);
     424
    426425    return rc;
    427426}
     
    751750}
    752751
     752/**
     753 * Returns S_OK if the given port and device numbers are within the range supported
     754 * by this controller. If not, it sets an error and returns E_INVALIDARG.
     755 * @param ulPort
     756 * @param ulDevice
     757 * @return
     758 */
     759HRESULT StorageController::checkPortAndDeviceValid(LONG aControllerPort,
     760                                                   LONG aDevice)
     761{
     762    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     763
     764    ULONG portCount = m->bd->mPortCount;
     765    ULONG devicesPerPort;
     766    HRESULT rc = m->pSystemProperties->GetMaxDevicesPerPortForStorageBus(m->bd->mStorageBus, &devicesPerPort);
     767    if (FAILED(rc)) return rc;
     768
     769    if (   (aControllerPort < 0)
     770        || (aControllerPort >= (LONG)portCount)
     771        || (aDevice < 0)
     772        || (aDevice >= (LONG)devicesPerPort)
     773       )
     774        return setError(E_INVALIDARG,
     775                        tr("The port and/or count parameter are out of range [%lu:%lu]"),
     776                        portCount,
     777                        devicesPerPort);
     778
     779    return S_OK;
     780}
     781
    753782/** @note Locks objects for writing! */
    754783void StorageController::rollback()
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r31300 r31308  
    29392939}
    29402940
    2941 const ComObjPtr<SystemProperties>& VirtualBox::systemProperties() const
     2941SystemProperties* VirtualBox::getSystemProperties() const
    29422942{
    29432943    return m->pSystemProperties;
  • trunk/src/VBox/Main/include/MachineImpl.h

    r31307 r31308  
    821821    Machine* const          mPeer;
    822822
    823     VirtualBox* const       mParent;
     823    VirtualBox * const      mParent;
    824824
    825825    Shareable<Data>         mData;
  • trunk/src/VBox/Main/include/StorageControllerImpl.h

    r30739 r31308  
    8585    ULONG getInstance() const;
    8686
     87    HRESULT checkPortAndDeviceValid(LONG aControllerPort,
     88                                    LONG aDevice);
     89
    8790    void rollback();
    8891    void commit();
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r31296 r31308  
    237237
    238238    const ComObjPtr<Host>& host() const;
    239     const ComObjPtr<SystemProperties>& systemProperties() const;
     239    SystemProperties* getSystemProperties() const;
    240240#ifdef VBOX_WITH_RESOURCE_USAGE_API
    241241    const ComObjPtr<PerformanceCollector>& performanceCollector() const;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette