VirtualBox

Changeset 56820 in vbox


Ignore:
Timestamp:
Jul 6, 2015 3:05:40 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
101471
Message:

Main/StorageController: Fix storage controller renaming, it needs updating all corresponding attachments (otherwise they get instantly lost). Also eliminates some Utf8Str/Bstr conversions, and a bit of whitespace cleanup

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/MachineImpl.h

    r56788 r56820  
    594594                                         bool aSetError = false);
    595595
     596    HRESULT i_getMediumAttachmentsOfController(const Utf8Str &aName,
     597                                               MediaData::AttachmentList &aAttachments);
     598
    596599    HRESULT i_getUSBControllerByName(const Utf8Str &aName,
    597600                                     ComObjPtr<USBController> &aUSBController,
     
    650653                                 bool aSetError = false);
    651654
    652     HRESULT i_getMediumAttachmentsOfController(const Utf8Str &aName,
    653                                                MediaData::AttachmentList &aAttachments);
    654 
    655655    ULONG   i_getUSBControllerCountByType(USBControllerType_T enmType);
    656656
     
    687687
    688688    MediumAttachment* i_findAttachment(const MediaData::AttachmentList &ll,
    689                                        IN_BSTR aControllerName,
     689                                       const Utf8Str &aControllerName,
    690690                                       LONG aControllerPort,
    691691                                       LONG aDevice);
  • trunk/src/VBox/Main/include/MediumAttachmentImpl.h

    r55401 r56820  
    66
    77/*
    8  * Copyright (C) 2006-2013 Oracle Corporation
     8 * Copyright (C) 2006-2015 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3535    HRESULT init(Machine *aParent,
    3636                 Medium *aMedium,
    37                  const Bstr &aControllerName,
     37                 const Utf8Str &aControllerName,
    3838                 LONG aPort,
    3939                 LONG aDevice,
     
    5959
    6060    const ComObjPtr<Medium>& i_getMedium() const;
    61     const Bstr i_getControllerName() const;
     61    const Utf8Str &i_getControllerName() const;
    6262    LONG i_getPort() const;
    6363    LONG i_getDevice() const;
     
    7070    bool i_getHotPluggable() const;
    7171
    72     bool i_matches(CBSTR aControllerName, LONG aPort, LONG aDevice);
     72    bool i_matches(const Utf8Str &aControllerName, LONG aPort, LONG aDevice);
     73
     74    /** Must be called from under this object's write lock. */
     75    void i_updateName(const Utf8Str &aName);
    7376
    7477    /** Must be called from under this object's write lock. */
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r56788 r56820  
    95809580        AutoReadLock attLock(pAtt COMMA_LOCKVAL_SRC_POS);
    95819581
    9582         if (pAtt->i_getControllerName() == Bstr(aName).raw())
     9582        if (pAtt->i_getControllerName() == aName)
    95839583            atts.push_back(pAtt);
    95849584    }
     
    1106711067 */
    1106811068MediumAttachment* Machine::i_findAttachment(const MediaData::AttachmentList &ll,
    11069                                             IN_BSTR aControllerName,
     11069                                            const Utf8Str &aControllerName,
    1107011070                                            LONG aControllerPort,
    1107111071                                            LONG aDevice)
  • trunk/src/VBox/Main/src-server/MediumAttachmentImpl.cpp

    r55401 r56820  
    5353     * to the old, uninitialized instance. Changing this requires
    5454     * substantial changes to MediumImpl.cpp. */
    55     const Bstr          bstrControllerName;
     55    const Utf8Str       strControllerName;
    5656    /* Same counts for the assigned bandwidth group */
    5757    Utf8Str             strBandwidthGroup;
     
    118118HRESULT MediumAttachment::init(Machine *aParent,
    119119                               Medium *aMedium,
    120                                const Bstr &aControllerName,
     120                               const Utf8Str &aControllerName,
    121121                               LONG aPort,
    122122                               LONG aDevice,
     
    131131{
    132132    LogFlowThisFuncEnter();
    133     LogFlowThisFunc(("aParent=%p aMedium=%p aControllerName=%ls aPort=%d aDevice=%d aType=%d aImplicit=%d aPassthrough=%d aTempEject=%d aNonRotational=%d aDiscard=%d aHotPluggable=%d strBandwithGroup=%s\n", aParent, aMedium, aControllerName.raw(), aPort, aDevice, aType, aImplicit, aPassthrough, aTempEject, aNonRotational, aDiscard, aHotPluggable, strBandwidthGroup.c_str()));
     133    LogFlowThisFunc(("aParent=%p aMedium=%p aControllerName=%s aPort=%d aDevice=%d aType=%d aImplicit=%d aPassthrough=%d aTempEject=%d aNonRotational=%d aDiscard=%d aHotPluggable=%d strBandwithGroup=%s\n", aParent, aMedium, aControllerName.c_str(), aPort, aDevice, aType, aImplicit, aPassthrough, aTempEject, aNonRotational, aDiscard, aHotPluggable, strBandwidthGroup.c_str()));
    134134
    135135    if (aType == DeviceType_HardDisk)
     
    147147    m->bd->pMedium = aMedium;
    148148    unconst(m->bd->strBandwidthGroup) = strBandwidthGroup;
    149     unconst(m->bd->bstrControllerName) = aControllerName;
     149    unconst(m->bd->strControllerName) = aControllerName;
    150150    unconst(m->bd->lPort)   = aPort;
    151151    unconst(m->bd->lDevice) = aDevice;
     
    250250
    251251    /* m->controller is constant during life time, no need to lock */
    252     aController = Utf8Str(m->bd->bstrControllerName);
     252    aController = Utf8Str(m->bd->strControllerName);
    253253
    254254    LogFlowThisFuncLeave();
     
    442442}
    443443
    444 const Bstr MediumAttachment::i_getControllerName() const
    445 {
    446     return m->bd->bstrControllerName;
     444const Utf8Str &MediumAttachment::i_getControllerName() const
     445{
     446    return m->bd->strControllerName;
    447447}
    448448
     
    497497}
    498498
    499 bool MediumAttachment::i_matches(CBSTR aControllerName, LONG aPort, LONG aDevice)
    500 {
    501     return (    aControllerName == m->bd->bstrControllerName
     499bool MediumAttachment::i_matches(const Utf8Str &aControllerName, LONG aPort, LONG aDevice)
     500{
     501    return (    aControllerName == m->bd->strControllerName
    502502             && aPort == m->bd->lPort
    503503             && aDevice == m->bd->lDevice);
     504}
     505
     506/** Must be called from under this object's write lock. */
     507void MediumAttachment::i_updateName(const Utf8Str &aName)
     508{
     509    Assert(isWriteLockOnCurrentThread());
     510
     511    m->bd.backup();
     512    unconst(m->bd->strControllerName) = aName;
    504513}
    505514
  • trunk/src/VBox/Main/src-server/SnapshotImpl.cpp

    r56030 r56820  
    26892689                pOnlineMediumAttachment =
    26902690                    i_findAttachment(mMediaData->mAttachments,
    2691                                      pAttach->i_getControllerName().raw(),
     2691                                     pAttach->i_getControllerName(),
    26922692                                     pAttach->i_getPort(),
    26932693                                     pAttach->i_getDevice());
  • trunk/src/VBox/Main/src-server/StorageControllerImpl.cpp

    r56477 r56820  
    234234
    235235        unconst(aThat->m->pPeer) = this;
    236         m->bd.attach (aThat->m->bd);
     236        m->bd.attach(aThat->m->bd);
    237237    }
    238238    else
     
    241241
    242242        AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS);
    243         m->bd.share (aThat->m->bd);
     243        m->bd.share(aThat->m->bd);
    244244    }
    245245
     
    331331                            aName.c_str());
    332332
     333        Machine::MediaData::AttachmentList atts;
     334        rc = m->pParent->i_getMediumAttachmentsOfController(m->bd->strName, atts);
     335        for (Machine::MediaData::AttachmentList::const_iterator it = atts.begin();
     336             it != atts.end();
     337             ++it)
     338        {
     339            IMediumAttachment *iA = *it;
     340            MediumAttachment *pAttach = static_cast<MediumAttachment *>(iA);
     341            AutoWriteLock attlock(pAttach COMMA_LOCKVAL_SRC_POS);
     342            pAttach->i_updateName(aName);
     343        }
     344
     345
    333346        m->bd.backup();
    334347        m->bd->strName = aName;
     
    419432    if (!SUCCEEDED(rc))
    420433        return setError(rc,
    421                         tr ("Invalid controller type %d"),
     434                        tr("Invalid controller type %d"),
    422435                        aControllerType);
    423436
     
    730743    /* sanity */
    731744    AutoCaller autoCaller(this);
    732     AssertComRCReturnVoid (autoCaller.rc());
     745    AssertComRCReturnVoid(autoCaller.rc());
    733746
    734747    /* sanity too */
    735     AutoCaller peerCaller (m->pPeer);
    736     AssertComRCReturnVoid (peerCaller.rc());
     748    AutoCaller peerCaller(m->pPeer);
     749    AssertComRCReturnVoid(peerCaller.rc());
    737750
    738751    /* lock both for writing since we modify both (m->pPeer is "master" so locked
     
    746759        {
    747760            // attach new data to the peer and reshare it
    748             m->pPeer->m->bd.attach (m->bd);
     761            m->pPeer->m->bd.attach(m->bd);
    749762        }
    750763    }
     
    762775    /* sanity */
    763776    AutoCaller autoCaller(this);
    764     AssertComRCReturnVoid (autoCaller.rc());
     777    AssertComRCReturnVoid(autoCaller.rc());
    765778
    766779    /* sanity too */
    767     AutoCaller peerCaller (m->pPeer);
    768     AssertComRCReturnVoid (peerCaller.rc());
     780    AutoCaller peerCaller(m->pPeer);
     781    AssertComRCReturnVoid(peerCaller.rc());
    769782
    770783    /* peer is not modified, lock it for reading (m->pPeer is "master" so locked
Note: See TracChangeset for help on using the changeset viewer.

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