VirtualBox

Changeset 36058 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Feb 22, 2011 11:11:22 PM (14 years ago)
Author:
vboxsync
Message:

Main/BandwidthControl: Don't use direct references to bandwidth group objects in the medium attachment object. It will point to the old uninitialized instance if the settings are changed. Uses the name of the bandwidth group now instead without changing the public interface to make a backport to 4.0 possible

Location:
trunk/src/VBox/Main/src-server
Files:
2 edited

Legend:

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

    r36017 r36058  
    37093709                          aType,
    37103710                          fIndirect,
    3711                           NULL);
     3711                          Utf8Str::Empty);
    37123712    if (FAILED(rc)) return rc;
    37133713
     
    38713871    AutoWriteLock attLock(pAttach COMMA_LOCKVAL_SRC_POS);
    38723872
    3873     pAttach->updateBandwidthGroup(group);
     3873    const Utf8Str strBandwidthGroupOld = pAttach->getBandwidthGroup();
     3874    if (strBandwidthGroupOld.isNotEmpty())
     3875    {
     3876        /* Get the bandwidth group object and release it - this must not fail. */
     3877        ComObjPtr<BandwidthGroup> pBandwidthGroupOld;
     3878        rc = getBandwidthGroup(strBandwidthGroupOld, pBandwidthGroupOld, false);
     3879        Assert(SUCCEEDED(rc));
     3880
     3881        pBandwidthGroupOld->release();
     3882        pAttach->updateBandwidthGroup(Utf8Str::Empty);
     3883    }
     3884
     3885    if (!group.isNull())
     3886    {
     3887        group->reference();
     3888        pAttach->updateBandwidthGroup(group->getName());
     3889    }
    38743890
    38753891    return S_OK;
     
    77467762                                mUserData->s.strName.c_str(),
    77477763                                mData->m_strConfigFileFull.c_str());
     7764            pBwGroup->reference();
    77487765        }
    77497766
     
    77587775                               dev.deviceType,
    77597776                               dev.fPassThrough,
    7760                                pBwGroup);
     7777                               pBwGroup.isNull() ? Utf8Str::Empty : pBwGroup->getName());
    77617778        if (FAILED(rc)) break;
    77627779
     
    86868703        MediumAttachment *pAttach = *it;
    86878704        Medium *pMedium = pAttach->getMedium();
    8688         BandwidthGroup *pBwGroup = pAttach->getBandwidthGroup();
    86898705
    86908706        dev.deviceType = pAttach->getType();
     
    87008716        }
    87018717
    8702         if (pBwGroup)
    8703         {
    8704             dev.strBwGroup = pBwGroup->getName();
    8705         }
     8718        dev.strBwGroup = pAttach->getBandwidthGroup();
    87068719
    87078720        data.llAttachedDevices.push_back(dev);
  • trunk/src/VBox/Main/src-server/MediumAttachmentImpl.cpp

    r35638 r36058  
    4545
    4646    ComObjPtr<Medium>   pMedium;
    47     ComObjPtr<BandwidthGroup> pBwGroup;
    4847    /* Since MediumAttachment is not a first class citizen when it
    4948     * comes to managing settings, having a reference to the storage
     
    5251     * substantial changes to MediumImpl.cpp. */
    5352    const Bstr          bstrControllerName;
     53    /* Same counts for the assigned bandwidth group */
     54    Utf8Str             strBandwidthGroup;
    5455    const LONG          lPort;
    5556    const LONG          lDevice;
     
    110111                               DeviceType_T aType,
    111112                               bool aPassthrough,
    112                                BandwidthGroup *aBandwidthGroup)
     113                               const Utf8Str &strBandwidthGroup)
    113114{
    114115    LogFlowThisFuncEnter();
     
    128129    m->bd.allocate();
    129130    m->bd->pMedium = aMedium;
    130     if (aBandwidthGroup)
    131         aBandwidthGroup->reference();
    132     m->bd->pBwGroup = aBandwidthGroup;
     131    unconst(m->bd->strBandwidthGroup) = strBandwidthGroup;
    133132    unconst(m->bd->bstrControllerName) = aControllerName;
    134133    unconst(m->bd->lPort)   = aPort;
     
    290289    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    291290
    292     m->bd->pBwGroup.queryInterfaceTo(aBwGroup);
    293 
    294     return S_OK;
     291    HRESULT hrc = S_OK;
     292    if (m->bd->strBandwidthGroup.isNotEmpty())
     293    {
     294        ComObjPtr<BandwidthGroup> pBwGroup;
     295        hrc = m->pMachine->getBandwidthGroup(m->bd->strBandwidthGroup, pBwGroup, true /* fSetError */);
     296
     297        Assert(SUCCEEDED(hrc)); /* This is not allowed to fail because the existence of the group was checked when it was attached. */
     298
     299        if (SUCCEEDED(hrc))
     300            pBwGroup.queryInterfaceTo(aBwGroup);
     301    }
     302
     303    return hrc;
    295304}
    296305
     
    318327void MediumAttachment::commit()
    319328{
    320     LogFlowThisFuncEnter();
     329    LogFlowThisFunc(("ENTER - %s\n", getLogName()));
    321330
    322331    /* sanity */
     
    329338        m->bd.commit();
    330339
    331     LogFlowThisFuncLeave();
     340    LogFlowThisFunc(("LEAVE - %s\n", getLogName()));
    332341}
    333342
     
    373382}
    374383
    375 const ComObjPtr<BandwidthGroup>& MediumAttachment::getBandwidthGroup() const
    376 {
    377     return m->bd->pBwGroup;
     384const Utf8Str& MediumAttachment::getBandwidthGroup() const
     385{
     386    return m->bd->strBandwidthGroup;
    378387}
    379388
     
    407416}
    408417
    409 void MediumAttachment::updateBandwidthGroup(const ComObjPtr<BandwidthGroup> &aBandwidthGroup)
    410 {
     418void MediumAttachment::updateBandwidthGroup(const Utf8Str &aBandwidthGroup)
     419{
     420    LogFlowThisFuncEnter();
    411421    Assert(isWriteLockOnCurrentThread());
    412422
    413423    m->bd.backup();
    414     if (!aBandwidthGroup.isNull())
    415         aBandwidthGroup->reference();
    416 
    417     if (!m->bd->pBwGroup.isNull())
    418     {
    419         m->bd->pBwGroup->release();
    420     }
    421     m->bd->pBwGroup = aBandwidthGroup;
    422 }
    423 
     424    m->bd->strBandwidthGroup = aBandwidthGroup;
     425
     426    LogFlowThisFuncLeave();
     427}
     428
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