VirtualBox

Changeset 42825 in vbox for trunk/src


Ignore:
Timestamp:
Aug 15, 2012 1:59:01 PM (12 years ago)
Author:
vboxsync
Message:

Main/Machine+NetworkAdapter: properly fix resizing of vector containing network adapters, previously it wasn't handling commit correctly. xtracker 5997

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

Legend:

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

    r42551 r42825  
    9090    // public initializer/uninitializer for internal purposes only
    9191    HRESULT init(Machine *aParent, ULONG aSlot);
    92     HRESULT init(Machine *aParent, NetworkAdapter *aThat);
     92    HRESULT init(Machine *aParent, NetworkAdapter *aThat, bool aReshare = false);
    9393    HRESULT initCopy(Machine *aParent, NetworkAdapter *aThat);
    9494    void uninit();
     
    148148    void applyDefaults(GuestOSType *aOsType);
    149149
     150    ComObjPtr<NetworkAdapter> getPeer();
     151
    150152private:
    151153
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r42823 r42825  
    91019101                Utf8Str newConfigBaseDir(newConfigDir);
    91029102                newConfigDir.append(newGroupPlusName);
     9103                /* consistency: use \ if appropriate on the platform */
     9104                RTPathChangeToDosSlashes(newConfigDir.mutableRaw(), false);
    91039105                /* new dir and old dir cannot be equal here because of 'if'
    91049106                 * above and because name != newName */
     
    1101711019    mBandwidthControl->commit();
    1101811020
    11019     /* Keep the original network adapter count until this point, so that
    11020      * discarding a chipset type change will not lose settings. */
    11021     mNetworkAdapters.resize(Global::getMaxNetworkAdapters(mHWData->mChipsetType));
    11022     for (ULONG slot = 0; slot < mNetworkAdapters.size(); slot++)
    11023         mNetworkAdapters[slot]->commit();
     11021    /* Since mNetworkAdapters is a list which might have been changed (resized)
     11022     * without using the Backupable<> template we need to handle the copying
     11023     * of the list entries manually, including the creation of peers for the
     11024     * new objects. */
     11025    bool commitNetworkAdapters = false;
     11026    size_t newSize = Global::getMaxNetworkAdapters(mHWData->mChipsetType);
     11027    if (mPeer)
     11028    {
     11029        /* commit everything, even the ones which will go away */
     11030        for (size_t slot = 0; slot < mNetworkAdapters.size(); slot++)
     11031            mNetworkAdapters[slot]->commit();
     11032        /* copy over the new entries, creating a peer and uninit the original */
     11033        mPeer->mNetworkAdapters.resize(RT_MAX(newSize, mPeer->mNetworkAdapters.size()));
     11034        for (size_t slot = 0; slot < newSize; slot++)
     11035        {
     11036            /* look if this adapter has a peer device */
     11037            ComObjPtr<NetworkAdapter> peer = mNetworkAdapters[slot]->getPeer();
     11038            if (!peer)
     11039            {
     11040                /* no peer means the adapter is a newly created one;
     11041                 * create a peer owning data this data share it with */
     11042                peer.createObject();
     11043                peer->init(mPeer, mNetworkAdapters[slot], true /* aReshare */);
     11044            }
     11045            mPeer->mNetworkAdapters[slot] = peer;
     11046        }
     11047        /* uninit any no longer needed network adapters */
     11048        for (size_t slot = newSize; slot < mNetworkAdapters.size(); slot++)
     11049            mNetworkAdapters[slot]->uninit();
     11050        for (size_t slot = newSize; slot < mPeer->mNetworkAdapters.size(); slot++)
     11051        {
     11052            if (mPeer->mNetworkAdapters[slot])
     11053                mPeer->mNetworkAdapters[slot]->uninit();
     11054        }
     11055        /* Keep the original network adapter count until this point, so that
     11056         * discarding a chipset type change will not lose settings. */
     11057        mNetworkAdapters.resize(newSize);
     11058        mPeer->mNetworkAdapters.resize(newSize);
     11059    }
     11060    else
     11061    {
     11062        /* we have no peer (our parent is the newly created machine);
     11063         * just commit changes to the network adapters */
     11064        commitNetworkAdapters = true;
     11065    }
     11066    if (commitNetworkAdapters)
     11067    {
     11068        for (size_t slot = 0; slot < mNetworkAdapters.size(); slot++)
     11069            mNetworkAdapters[slot]->commit();
     11070    }
     11071
    1102411072    for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); slot++)
    1102511073        mSerialPorts[slot]->commit();
     
    1103511083        if (mPeer)
    1103611084        {
    11037             AutoWriteLock peerlock(mPeer COMMA_LOCKVAL_SRC_POS);
    11038 
    1103911085            /* Commit all changes to new controllers (this will reshare data with
    1104011086             * peers for those who have peers) */
  • trunk/src/VBox/Main/src-server/NetworkAdapterImpl.cpp

    r42551 r42825  
    108108 *  the object passed as an argument.
    109109 *
     110 *  @param  aReshare
     111 *      When false, the original object will remain a data owner.
     112 *      Otherwise, data ownership will be transferred from the original
     113 *      object to this one.
     114 *
    110115 *  @note This object must be destroyed before the original object
    111116 *  it shares data with is destroyed.
     
    113118 *  @note Locks @a aThat object for reading.
    114119 */
    115 HRESULT NetworkAdapter::init(Machine *aParent, NetworkAdapter *aThat)
    116 {
    117     LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat));
     120HRESULT NetworkAdapter::init(Machine *aParent, NetworkAdapter *aThat, bool aReshare /* = false */)
     121{
     122    LogFlowThisFunc(("aParent=%p, aThat=%p, aReshare=%RTbool\n", aParent, aThat, aReshare));
    118123
    119124    ComAssertRet(aParent && aThat, E_INVALIDARG);
     
    124129
    125130    unconst(mParent) = aParent;
    126     unconst(mPeer) = aThat;
    127131    unconst(mNATEngine).createObject();
    128132    mNATEngine->init(aParent, this, aThat->mNATEngine);
    129133
     134    /* sanity */
    130135    AutoCaller thatCaller(aThat);
    131136    AssertComRCReturnRC(thatCaller.rc());
    132137
    133     AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS);
    134     mData.share(aThat->mData);
     138    if (aReshare)
     139    {
     140        AutoWriteLock thatLock(aThat COMMA_LOCKVAL_SRC_POS);
     141
     142        unconst(aThat->mPeer) = this;
     143        mData.attach(aThat->mData);
     144    }
     145    else
     146    {
     147        unconst(mPeer) = aThat;
     148
     149        AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS);
     150        mData.share(aThat->mData);
     151    }
    135152
    136153    /* Confirm a successful initialization */
     
    13721389}
    13731390
     1391ComObjPtr<NetworkAdapter> NetworkAdapter::getPeer()
     1392{
     1393    return mPeer;
     1394}
     1395
     1396
    13741397// private methods
    13751398////////////////////////////////////////////////////////////////////////////////
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