VirtualBox

Changeset 25182 in vbox for trunk/src


Ignore:
Timestamp:
Dec 4, 2009 10:50:15 AM (15 years ago)
Author:
vboxsync
Message:

Backed out 55600; unable to create new VMs

Location:
trunk/src/VBox/Main
Files:
1 deleted
12 edited

Legend:

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

    r25170 r25182  
    5252        return;
    5353
     54//    /* we uninit children and reset mParent
     55//     * and VirtualBox::removeDependentChild() needs a write lock */
     56//    AutoMultiWriteLock2 alock (mVirtualBox->lockHandle(), this->treeLock());
     57
     58    mVirtualBox->removeDependentChild (this);
     59
    5460    unconst(mVirtualBox).setNull();
    5561}
     
    7278    m.upperIP = "0.0.0.0";
    7379
     80    /* register with VirtualBox early, since uninit() will
     81     * unconditionally unregister on failure */
     82    aVirtualBox->addDependentChild (this);
     83
    7484    /* Confirm a successful initialization */
    7585    autoInitSpan.setSucceeded();
     
    8797    /* share VirtualBox weakly (parent remains NULL so far) */
    8898    unconst(mVirtualBox) = aVirtualBox;
     99
     100    aVirtualBox->addDependentChild (this);
    89101
    90102    unconst(mName) = data.strNetworkName;
  • trunk/src/VBox/Main/MachineImpl.cpp

    r25179 r25182  
    395395    unconst(mParent) = aParent;
    396396
     397    /* register with parent early, since uninit() will unconditionally
     398     * unregister on failure */
     399    mParent->addDependentChild (this);
     400
    397401    /* allocate the essential machine data structure (the rest will be
    398402     * allocated later by initDataAndChildObjects() */
     
    687691    /* free the essential data structure last */
    688692    mData.free();
     693
     694    mParent->removeDependentChild (this);
    689695
    690696    LogFlowThisFuncLeave();
     
    54585464    for (ULONG slot = 0; slot < RT_ELEMENTS (mNetworkAdapters); slot ++)
    54595465    {
    5460         if (mNetworkAdapters[slot])
    5461         {
    5462             mNetworkAdapters[slot]->uninit();
    5463             unconst(mNetworkAdapters[slot]).setNull();
     5466        if (mNetworkAdapters [slot])
     5467        {
     5468            mNetworkAdapters [slot]->uninit();
     5469            unconst(mNetworkAdapters [slot]).setNull();
    54645470        }
    54655471    }
     
    54795485    for (ULONG slot = 0; slot < RT_ELEMENTS (mParallelPorts); slot ++)
    54805486    {
    5481         if (mParallelPorts[slot])
    5482         {
    5483             mParallelPorts[slot]->uninit();
    5484             unconst(mParallelPorts[slot]).setNull();
     5487        if (mParallelPorts [slot])
     5488        {
     5489            mParallelPorts [slot]->uninit();
     5490            unconst(mParallelPorts [slot]).setNull();
    54855491        }
    54865492    }
     
    54885494    for (ULONG slot = 0; slot < RT_ELEMENTS (mSerialPorts); slot ++)
    54895495    {
    5490         if (mSerialPorts[slot])
    5491         {
    5492             mSerialPorts[slot]->uninit();
    5493             unconst(mSerialPorts[slot]).setNull();
     5496        if (mSerialPorts [slot])
     5497        {
     5498            mSerialPorts [slot]->uninit();
     5499            unconst(mSerialPorts [slot]).setNull();
    54945500        }
    54955501    }
     
    90189024    ComAssertRet (!control.isNull(), E_INVALIDARG);
    90199025
    9020     /* Creating a Progress object requires the VirtualBox lock, and
     9026    /* Creating a Progress object requires the VirtualBox children lock, and
    90219027     * thus locking it here is required by the lock order rules. */
    9022     AutoMultiWriteLock2 alock(mParent->lockHandle(), this->lockHandle());
    9023 
    9024     if (control.equalsTo(mData->mSession.mDirectControl))
     9028    AutoMultiWriteLock2 alock(mParent->childrenLock(), this->lockHandle());
     9029
     9030    if (control.equalsTo (mData->mSession.mDirectControl))
    90259031    {
    90269032        ComAssertRet (aProgress, E_POINTER);
  • trunk/src/VBox/Main/MediumImpl.cpp

    r25170 r25182  
    896896    unconst(m->pVirtualBox) = aVirtualBox;
    897897
     898    /* register with VirtualBox early, since uninit() will
     899     * unconditionally unregister on failure */
     900    aVirtualBox->addDependentChild(this);
     901
    898902    /* no storage yet */
    899903    m->state = MediumState_NotCreated;
     
    991995    unconst(m->pVirtualBox) = aVirtualBox;
    992996
     997    /* register with VirtualBox early, since uninit() will
     998     * unconditionally unregister on failure */
     999    aVirtualBox->addDependentChild(this);
     1000
    9931001    /* there must be a storage unit */
    9941002    m->state = MediumState_Created;
     
    10741082    /* register with VirtualBox/parent early, since uninit() will
    10751083     * unconditionally unregister on failure */
    1076     if (aParent)
     1084    if (aParent == NULL)
     1085        // base disk: add to global list
     1086        aVirtualBox->addDependentChild(this);
     1087    else
    10771088    {
    10781089        // differencing image: add to parent
     
    12151226    /* share VirtualBox weakly (parent remains NULL so far) */
    12161227    unconst(m->pVirtualBox) = aVirtualBox;
     1228    aVirtualBox->addDependentChild(this);
    12171229
    12181230    /* fake up a UUID which is unique, but also reproducible */
     
    13021314            deparent();
    13031315        }
     1316        else
     1317            // base image: remove it from the global list
     1318            m->pVirtualBox->removeDependentChild(this);
    13041319    }
    13051320
     
    23182333    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    23192334
    2320     ComObjPtr<Medium> diff = static_cast<Medium*>(aTarget);
     2335    ComObjPtr<Medium> diff;
     2336    HRESULT rc = m->pVirtualBox->cast(aTarget, diff);
     2337    if (FAILED(rc)) return rc;
    23212338
    23222339    AutoWriteLock alock(this);
     
    23292346    /* We want to be locked for reading as long as our diff child is being
    23302347     * created */
    2331     HRESULT rc = LockRead(NULL);
     2348    rc = LockRead(NULL);
    23322349    if (FAILED(rc)) return rc;
    23332350
     
    23692386    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    23702387
    2371     ComObjPtr<Medium> target = static_cast<Medium*>(aTarget);
    2372     ComObjPtr<Medium> parent;
     2388    ComObjPtr <Medium> target;
     2389    HRESULT rc = m->pVirtualBox->cast(aTarget, target);
     2390    if (FAILED(rc)) return rc;
     2391    ComObjPtr <Medium> parent;
    23732392    if (aParent)
    2374         parent = static_cast<Medium*>(aParent);
     2393    {
     2394        rc = m->pVirtualBox->cast(aParent, parent);
     2395        if (FAILED(rc)) return rc;
     2396    }
    23752397
    23762398    AutoMultiWriteLock3 alock(this, target, parent);
    23772399
    2378     ComObjPtr<Progress> progress;
    2379     HRESULT rc = S_OK;
     2400    ComObjPtr <Progress> progress;
    23802401
    23812402    try
     
    38553876                    }
    38563877
     3878                    /* deassociate from VirtualBox, associate with parent */
     3879
     3880                    m->pVirtualBox->removeDependentChild(this);
     3881
    38573882                    /* we set mParent & children() */
    38583883                    AutoWriteLock treeLock(m->pVirtualBox->hardDiskTreeLockHandle());
     
    46784703
    46794704    if (m->pParent)
     4705    {
     4706        /* deassociate from the parent, associate with VirtualBox */
     4707        m->pVirtualBox->addDependentChild(this);
    46804708        deparent();
     4709    }
    46814710
    46824711    HRESULT rc = E_FAIL;
     
    46844713    {
    46854714        case DeviceType_DVD:
    4686             rc = m->pVirtualBox->unregisterImage(this, DeviceType_DVD);
     4715            rc = m->pVirtualBox->unregisterDVDImage(this);
    46874716            break;
    46884717        case DeviceType_Floppy:
    4689             rc = m->pVirtualBox->unregisterImage(this, DeviceType_Floppy);
     4718            rc = m->pVirtualBox->unregisterFloppyImage(this);
    46904719            break;
    46914720        case DeviceType_HardDisk:
     
    47044733            m->pParent = pParentBackup;
    47054734            m->pParent->m->llChildren.push_back(this);
     4735            m->pVirtualBox->removeDependentChild(this);
    47064736        }
    47074737    }
     
    51095139                Assert(target->m->pParent.isNull());
    51105140
    5111                 /* associate the child with the parent */
     5141                /* associate the child with the parent and deassociate from
     5142                 * VirtualBox */
    51125143                target->m->pParent = that;
    51135144                that->m->llChildren.push_back(target);
     5145                target->m->pVirtualBox->removeDependentChild(target);
    51145146
    51155147                /** @todo r=klaus neither target nor that->base() are locked,
     
    51265158
    51275159                if (FAILED(rc))
     5160                {
    51285161                    /* break the parent association on failure to register */
     5162                    target->m->pVirtualBox->addDependentChild(target);
    51295163                    that->deparent();
     5164                }
    51305165            }
    51315166
     
    53375372                        source->deparent();
    53385373                    }
     5374                    else
     5375                    {
     5376                        target->m->pVirtualBox->addDependentChild(target);
     5377                        target->m->pVirtualBox->removeDependentChild(source);
     5378                    }
    53395379
    53405380                    /* then, register again */
     
    56105650                        target->m->pParent = parent;
    56115651                        parent->m->llChildren.push_back(target);
     5652                        target->m->pVirtualBox->removeDependentChild(target);
    56125653
    56135654                        /* register with mVirtualBox as the last step and move to
     
    56175658
    56185659                        if (FAILED(rc))
     5660                        {
    56195661                            /* break parent association on failure to register */
     5662                            target->m->pVirtualBox->addDependentChild(target);
    56205663                            target->deparent();     // removes target from parent
     5664                        }
    56215665                    }
    56225666                    else
  • trunk/src/VBox/Main/PerformanceImpl.cpp

    r25149 r25182  
    528528    if (!SUCCEEDED(autoCaller.rc())) return;
    529529
     530    Log(("PerformanceCollector::suspendSampling\n"));
    530531    int rc = RTTimerLRStop(m.sampler);
    531532    AssertRC(rc);
     
    537538    if (!SUCCEEDED(autoCaller.rc())) return;
    538539
     540    Log(("PerformanceCollector::resumeSampling\n"));
    539541    int rc = RTTimerLRStart(m.sampler, 0);
    540542    AssertRC(rc);
     
    554556    if (collector->mMagic == MAGIC)
    555557    {
     558Log(("staticSamplerCallback %RX64\n", RTTimeNanoTS()));
    556559        collector->samplerCallback();
    557560    }
  • trunk/src/VBox/Main/ProgressImpl.cpp

    r25170 r25182  
    121121    /* share parent weakly */
    122122    unconst(mParent) = aParent;
     123
     124    /* register with parent early, since uninit() will unconditionally
     125     * unregister on failure */
     126    mParent->addDependentChild (this);
    123127#endif
    124128
     
    190194        if (aAutoUninitSpan.initFailed() && !mId.isEmpty())
    191195            mParent->removeProgress (mId);
     196
     197        mParent->removeDependentChild (this);
    192198
    193199        unconst(mParent).setNull();
  • trunk/src/VBox/Main/SharedFolderImpl.cpp

    r25170 r25182  
    161161    unconst(mVirtualBox) = aVirtualBox;
    162162
    163     HRESULT rc = protectedInit(aVirtualBox, aName, aHostPath, aWritable);
     163    HRESULT rc = protectedInit (aVirtualBox, aName, aHostPath, aWritable);
    164164
    165165    /* Confirm a successful initialization when it's the case */
     
    176176 *      Must be called from under the object's lock!
    177177 */
    178 HRESULT SharedFolder::protectedInit(VirtualBoxBase *aParent,
    179                                     CBSTR aName,
    180                                     CBSTR aHostPath,
    181                                     BOOL aWritable)
     178HRESULT SharedFolder::protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent,
     179                                     CBSTR aName, CBSTR aHostPath, BOOL aWritable)
    182180{
    183181    LogFlowThisFunc(("aName={%ls}, aHostPath={%ls}, aWritable={%d}\n",
     
    223221    unconst(mParent) = aParent;
    224222
     223    /* register with parent */
     224    mParent->addDependentChild (this);
     225
    225226    unconst(m.name) = aName;
    226227    unconst(m.hostPath) = hostPath;
     
    242243    if (autoUninitSpan.uninitDone())
    243244        return;
     245
     246    if (mParent)
     247        mParent->removeDependentChild (this);
    244248
    245249    unconst(mParent) = NULL;
  • trunk/src/VBox/Main/VirtualBoxBase.cpp

    r25170 r25182  
    3838#include "Logging.h"
    3939
    40 #include "objectslist.h"
    41 
    42 ////////////////////////////////////////////////////////////////////////////////
    43 //
    44 // VirtualBoxBaseProto
    45 //
     40// VirtualBoxBaseProto methods
    4641////////////////////////////////////////////////////////////////////////////////
    4742
     
    291286}
    292287
    293 ////////////////////////////////////////////////////////////////////////////////
    294 //
    295288// VirtualBoxBaseProto::AutoInitSpan methods
    296 //
    297289////////////////////////////////////////////////////////////////////////////////
    298290
     
    645637}
    646638
    647 ////////////////////////////////////////////////////////////////////////////////
    648 //
    649 // VirtualBoxBase
    650 //
     639// VirtualBoxBase methods
    651640////////////////////////////////////////////////////////////////////////////////
    652641
     
    686675}
    687676
    688 ////////////////////////////////////////////////////////////////////////////////
    689 //
    690 // VirtualBoxSupportTranslationBase
    691 //
     677// VirtualBoxSupportTranslationBase methods
    692678////////////////////////////////////////////////////////////////////////////////
    693679
     
    752738}
    753739
    754 ////////////////////////////////////////////////////////////////////////////////
    755 //
    756 // VirtualBoxSupportErrorInfoImplBase
    757 //
     740// VirtualBoxSupportErrorInfoImplBase methods
    758741////////////////////////////////////////////////////////////////////////////////
    759742
     
    929912}
    930913
     914// VirtualBoxBaseWithChildrenNEXT methods
     915////////////////////////////////////////////////////////////////////////////////
    931916
    932917/**
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r25170 r25182  
    7070
    7171#include "Logging.h"
    72 #include "objectslist.h"
    7372
    7473#ifdef RT_OS_WINDOWS
     
    8382
    8483#define VBOX_GLOBAL_SETTINGS_FILE "VirtualBox.xml"
     84
     85typedef std::vector< ComObjPtr<Machine> > MachineVector;
     86
     87typedef std::list< ComObjPtr<Machine> > MachineList;
     88typedef std::vector< ComObjPtr<SessionMachine> > SessionMachineVector;
     89typedef std::list< ComObjPtr<GuestOSType> > GuestOSTypeList;
     90
     91typedef std::map<Guid, ComPtr<IProgress> > ProgressMap;
     92
     93typedef std::list <ComObjPtr<SharedFolder> > SharedFolderList;
     94typedef std::list <ComObjPtr<DHCPServer> > DHCPServerList;
     95
     96typedef std::map<Guid, ComObjPtr<Medium> > HardDiskMap;
     97
    8598
    8699////////////////////////////////////////////////////////////////////////////////
     
    156169#endif
    157170
    158 typedef ObjectsList<Machine> MachinesOList;
    159 typedef ObjectsList<Medium> MediaOList;
    160 typedef ObjectsList<GuestOSType> GuestOSTypesOList;
    161 typedef ObjectsList<SharedFolder> SharedFoldersOList;
    162 typedef ObjectsList<DHCPServer> DHCPServersOList;
    163 
    164 typedef std::map<Guid, ComPtr<IProgress> > ProgressMap;
    165 typedef std::map<Guid, ComObjPtr<Medium> > HardDiskMap;
    166 
    167171/**
    168172 *  Main VirtualBox data structure.
     
    194198#endif /* VBOX_WITH_RESOURCE_USAGE_API */
    195199
    196     // the following lists all have an RWLockHandle as a member and are locked
    197     // individually; getting the VirtualBox object lock is NOT necessary, but
    198     // see the remarks which ObjectsList method lock themselves and which require
    199     // external locking
    200     MachinesOList                       ollMachines;
    201     GuestOSTypesOList                   ollGuestOSTypes;
    202 
    203     MediaOList                          ollHardDisks,           // only base hard disks; the RWLockHandle in here is also used
    204                                                                 // for hardDiskTreeLockHandle()
    205                                         ollDVDImages,
    206                                         ollFloppyImages;
    207     SharedFoldersOList                  ollSharedFolders;
    208     DHCPServersOList                    ollDHCPServers;
    209 
    210     // the hard disks map is an additional map sorted by UUID for quick lookup
    211     // and contains ALL hard disks (base and differencing);
    212     // the map must also be protected by ollHardDisks.getLockHandle()!
     200    MachineList                         llMachines;
     201    GuestOSTypeList                     llGuestOSTypes;
     202
     203    ProgressMap                         mapProgressOperations;
     204
     205    MediaList                           llHardDisks,
     206                                        llDVDImages,
     207                                        llFloppyImages;
     208    SharedFolderList                    llSharedFolders;
     209    DHCPServerList                      llDHCPServers;
     210
     211    /// @todo NEWMEDIA do we really need this map? Used only in
     212    /// find() it seems
    213213    HardDiskMap                         mapHardDisks;
    214214
    215     ProgressMap                         mapProgressOperations;
    216215    CallbackList                        llCallbacks;
    217216
    218217    RWLockHandle                        mtxProgressOperations;
    219218            // protects mutex operations; "leaf" lock, no other lock may be requested after this
     219    RWLockHandle                        mtxHardDiskTree;
     220            // protects the hard disk tree; this is implemented here, but only requested through
     221            // Medium::treeLock, which returns exactly this
     222    RWLockHandle                        mtxChildrenMap;
     223            // used for VirtualBoxWithChildrenNEXT management
    220224
    221225    // the following are data for the client watcher thread
     
    369373                                          Global::sOSTypes [i].numSerialEnabled);
    370374                if (SUCCEEDED(rc))
    371                     m->ollGuestOSTypes.addChild(guestOSTypeObj);
     375                    m->llGuestOSTypes.push_back (guestOSTypeObj);
    372376            }
    373377            ComAssertComRCThrowRC (rc);
     
    529533        if (FAILED(rc)) return rc;
    530534
    531         rc = registerImage(pImage, DeviceType_DVD, false /* aSaveRegistry */);
     535        rc = registerDVDImage(pImage, false /* aSaveRegistry */);
    532536        if (FAILED(rc)) return rc;
    533537    }
     
    544548        if (FAILED(rc)) return rc;
    545549
    546         rc = registerImage(pImage, DeviceType_Floppy, false /* aSaveRegistry */);
     550        rc = registerFloppyImage(pImage, false /* aSaveRegistry */);
    547551        if (FAILED(rc)) return rc;
    548552    }
     
    564568    /* tell all our child objects we've been uninitialized */
    565569
    566     LogFlowThisFunc(("Uninitializing machines (%d)...\n", m->ollMachines.size()));
    567     m->ollMachines.uninitAll();
    568     m->ollFloppyImages.uninitAll();
    569     m->ollDVDImages.uninitAll();
    570     m->ollHardDisks.uninitAll();
    571     m->ollDHCPServers.uninitAll();
     570    LogFlowThisFunc(("Uninitializing machines (%d)...\n", m->llMachines.size()));
     571    if (m->llMachines.size())
     572    {
     573        MachineList::iterator it = m->llMachines.begin();
     574        while (it != m->llMachines.end())
     575            (*it++)->uninit();
     576        m->llMachines.clear();
     577    }
     578
     579    /* Uninit all other children still referenced by clients (unregistered
     580     * machines, hard disks, DVD/floppy images, server-side progress
     581     * operations). */
     582    uninitDependentChildren();
     583
     584    m->mapHardDisks.clear();
     585
     586    m->llFloppyImages.clear();
     587    m->llDVDImages.clear();
     588    m->llHardDisks.clear();
     589    m->llDHCPServers.clear();
    572590
    573591    m->mapProgressOperations.clear();
    574592
    575     m->ollGuestOSTypes.uninitAll();
     593    m->llGuestOSTypes.clear();
    576594
    577595    /* Note that we release singleton children after we've all other children.
     
    770788    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    771789
    772     AutoReadLock al(m->ollMachines.getLockHandle());
    773     SafeIfaceArray<IMachine> machines(m->ollMachines.getList());
     790    AutoReadLock alock(this);
     791
     792    SafeIfaceArray<IMachine> machines(m->llMachines);
    774793    machines.detachTo(ComSafeArrayOutArg(aMachines));
    775794
     
    785804    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    786805
    787     AutoReadLock al(m->ollHardDisks.getLockHandle());
    788     SafeIfaceArray<IMedium> hardDisks(m->ollHardDisks.getList());
     806    AutoReadLock alock(this);
     807
     808    SafeIfaceArray<IMedium> hardDisks(m->llHardDisks);
    789809    hardDisks.detachTo(ComSafeArrayOutArg(aHardDisks));
    790810
     
    792812}
    793813
    794 STDMETHODIMP VirtualBox::COMGETTER(DVDImages) (ComSafeArrayOut(IMedium *, aDVDImages))
     814STDMETHODIMP
     815VirtualBox::COMGETTER(DVDImages) (ComSafeArrayOut(IMedium *, aDVDImages))
    795816{
    796817    if (ComSafeArrayOutIsNull(aDVDImages))
     
    800821    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    801822
    802     AutoReadLock al(m->ollDVDImages.getLockHandle());
    803     SafeIfaceArray<IMedium> images(m->ollDVDImages.getList());
     823    AutoReadLock alock(this);
     824
     825    SafeIfaceArray<IMedium> images(m->llDVDImages);
    804826    images.detachTo(ComSafeArrayOutArg(aDVDImages));
    805827
     
    807829}
    808830
    809 STDMETHODIMP VirtualBox::COMGETTER(FloppyImages) (ComSafeArrayOut(IMedium *, aFloppyImages))
     831STDMETHODIMP
     832VirtualBox::COMGETTER(FloppyImages) (ComSafeArrayOut(IMedium *, aFloppyImages))
    810833{
    811834    if (ComSafeArrayOutIsNull(aFloppyImages))
     
    815838    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    816839
    817     AutoReadLock al(m->ollFloppyImages.getLockHandle());
    818     SafeIfaceArray<IMedium> images(m->ollFloppyImages.getList());
     840    AutoReadLock alock(this);
     841
     842    SafeIfaceArray<IMedium> images(m->llFloppyImages);
    819843    images.detachTo(ComSafeArrayOutArg(aFloppyImages));
    820844
     
    831855    /* protect mProgressOperations */
    832856    AutoReadLock safeLock(m->mtxProgressOperations);
     857
    833858    SafeIfaceArray<IProgress> progress(m->mapProgressOperations);
    834859    progress.detachTo(ComSafeArrayOutArg(aOperations));
     
    844869    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    845870
    846     AutoReadLock al(m->ollGuestOSTypes.getLockHandle());
    847     SafeIfaceArray<IGuestOSType> ostypes(m->ollGuestOSTypes.getList());
     871    AutoReadLock alock(this);
     872
     873    SafeIfaceArray<IGuestOSType> ostypes(m->llGuestOSTypes);
    848874    ostypes.detachTo(ComSafeArrayOutArg(aGuestOSTypes));
    849875
     
    851877}
    852878
    853 STDMETHODIMP VirtualBox::COMGETTER(SharedFolders) (ComSafeArrayOut(ISharedFolder *, aSharedFolders))
     879STDMETHODIMP
     880VirtualBox::COMGETTER(SharedFolders) (ComSafeArrayOut(ISharedFolder *, aSharedFolders))
    854881{
    855882#ifndef RT_OS_WINDOWS
     
    892919    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    893920
    894     AutoReadLock al(m->ollDHCPServers.getLockHandle());
    895     SafeIfaceArray<IDHCPServer> svrs (m->ollDHCPServers.getList());
     921    AutoReadLock alock(this);
     922
     923    SafeIfaceArray<IDHCPServer> svrs (m->llDHCPServers);
    896924    svrs.detachTo(ComSafeArrayOutArg(aDHCPServers));
    897925
     
    11491177
    11501178/** @note Locks objects! */
    1151 STDMETHODIMP VirtualBox::RegisterMachine(IMachine *aMachine)
     1179STDMETHODIMP VirtualBox::RegisterMachine (IMachine *aMachine)
    11521180{
    11531181    CheckComArgNotNull(aMachine);
     
    11621190    if (FAILED(rc)) return rc;
    11631191
     1192    /* We need the children map lock here to keep the getDependentChild() result
     1193     * valid until we finish */
     1194    AutoReadLock chLock (childrenLock());
     1195
    11641196    /* We can safely cast child to Machine * here because only Machine
    11651197     * implementations of IMachine can be among our children. */
    1166     Machine *pMachine = static_cast<Machine*>(aMachine);
    1167 
    1168     AutoCaller machCaller(pMachine);
    1169     ComAssertComRCRetRC(machCaller.rc());
    1170 
    1171     rc = registerMachine(pMachine);
     1198    Machine *machine = static_cast <Machine *> (getDependentChild (aMachine));
     1199    if (machine == NULL)
     1200    {
     1201        /* this machine was not created by CreateMachine() or opened by
     1202         * OpenMachine() or loaded during startup */
     1203        return setError (VBOX_E_INVALID_OBJECT_STATE,
     1204            tr ("The machine named '%ls' is not created within this "
     1205                "VirtualBox instance"), name.raw());
     1206    }
     1207
     1208    AutoCaller machCaller (machine);
     1209    ComAssertComRCRetRC (machCaller.rc());
     1210
     1211    rc = registerMachine (machine);
     1212
    11721213    /* fire an event */
    11731214    if (SUCCEEDED(rc))
    1174         onMachineRegistered(pMachine->getId(), TRUE);
     1215        onMachineRegistered(machine->getId(), TRUE);
    11751216
    11761217    return rc;
     
    11781219
    11791220/** @note Locks objects! */
    1180 STDMETHODIMP VirtualBox::GetMachine(IN_BSTR aId, IMachine **aMachine)
     1221STDMETHODIMP VirtualBox::GetMachine (IN_BSTR aId, IMachine **aMachine)
    11811222{
    11821223    CheckComArgOutSafeArrayPointerValid(aMachine);
     
    11951236
    11961237/** @note Locks this object for reading, then some machine objects for reading. */
    1197 STDMETHODIMP VirtualBox::FindMachine(IN_BSTR aName, IMachine **aMachine)
     1238STDMETHODIMP VirtualBox::FindMachine (IN_BSTR aName, IMachine **aMachine)
    11981239{
    11991240    LogFlowThisFuncEnter();
     
    12071248
    12081249    /* start with not found */
    1209     ComObjPtr<Machine> pMachineFound;
    1210 
    1211     AutoReadLock al(m->ollMachines.getLockHandle());
    1212     for (MachinesOList::iterator it = m->ollMachines.begin();
    1213          it != m->ollMachines.end();
    1214          ++it)
     1250    ComObjPtr<Machine> machine;
     1251    MachineList machines;
     1252    {
     1253        /* take a copy for safe iteration outside the lock */
     1254        AutoReadLock alock(this);
     1255        machines = m->llMachines;
     1256    }
     1257
     1258    for (MachineList::iterator it = machines.begin();
     1259         !machine && it != machines.end();
     1260         ++ it)
    12151261    {
    12161262        ComObjPtr<Machine> &pMachine2 = *it;
     
    12231269            AutoReadLock machLock(pMachine2);
    12241270            if (pMachine2->getName() == aName)
    1225             {
    1226                 pMachineFound = pMachine2;
    1227                 break;
    1228             }
     1271                machine = pMachine2;
    12291272        }
    12301273    }
    12311274
    12321275    /* this will set (*machine) to NULL if machineObj is null */
    1233     pMachineFound.queryInterfaceTo(aMachine);
    1234 
    1235     HRESULT rc = pMachineFound
     1276    machine.queryInterfaceTo(aMachine);
     1277
     1278    HRESULT rc = machine
    12361279        ? S_OK
    1237         : setError(VBOX_E_OBJECT_NOT_FOUND,
    1238                    tr("Could not find a registered machine named '%ls'"), aName);
     1280        : setError (VBOX_E_OBJECT_NOT_FOUND,
     1281            tr ("Could not find a registered machine named '%ls'"), aName);
    12391282
    12401283    LogFlowThisFunc(("aName=\"%ls\", aMachine=%p, rc=%08X\n", aName, *aMachine, rc));
     
    12451288
    12461289/** @note Locks objects! */
    1247 STDMETHODIMP VirtualBox::UnregisterMachine(IN_BSTR  aId,
    1248                                            IMachine **aMachine)
     1290STDMETHODIMP VirtualBox::UnregisterMachine (IN_BSTR  aId,
     1291                                            IMachine **aMachine)
    12491292{
    12501293    Guid id(aId);
     
    12551298    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    12561299
    1257     // find machine from the given ID
    1258     ComObjPtr<Machine> pMachine;
    1259     HRESULT rc = findMachine(id, true /* setError */, &pMachine);
     1300    AutoWriteLock alock(this);
     1301
     1302    ComObjPtr<Machine> machine;
     1303
     1304    HRESULT rc = findMachine (id, true /* setError */, &machine);
    12601305    if (FAILED(rc)) return rc;
    12611306
    1262     rc = pMachine->trySetRegistered(FALSE);
     1307    rc = machine->trySetRegistered (FALSE);
    12631308    if (FAILED(rc)) return rc;
    12641309
    12651310    /* remove from the collection of registered machines */
    1266     m->ollMachines.removeChild(pMachine);
     1311    m->llMachines.remove (machine);
    12671312
    12681313    /* save the global registry */
    1269     AutoWriteLock alock(this);
    12701314    rc = saveSettings();
    12711315
    12721316    /* return the unregistered machine to the caller */
    1273     pMachine.queryInterfaceTo(aMachine);
     1317    machine.queryInterfaceTo(aMachine);
    12741318
    12751319    /* fire an event */
    1276     onMachineRegistered(id, FALSE);
     1320    onMachineRegistered (id, FALSE);
    12771321
    12781322    return rc;
     
    14171461    if (SUCCEEDED(rc))
    14181462    {
    1419         rc = registerImage(image, DeviceType_DVD);
     1463        rc = registerDVDImage (image);
    14201464
    14211465        if (SUCCEEDED(rc))
     
    14841528    if (SUCCEEDED(rc))
    14851529    {
    1486         rc = registerImage(image, DeviceType_Floppy);
     1530        rc = registerFloppyImage (image);
    14871531
    14881532        if (SUCCEEDED(rc))
     
    15721616    *aType = NULL;
    15731617
    1574     AutoReadLock alock(m->ollGuestOSTypes.getLockHandle());
    1575     for (GuestOSTypesOList::iterator it = m->ollGuestOSTypes.begin();
    1576          it != m->ollGuestOSTypes.end();
    1577          ++it)
     1618    AutoReadLock alock(this);
     1619
     1620    for (GuestOSTypeList::iterator it = m->llGuestOSTypes.begin();
     1621         it != m->llGuestOSTypes.end();
     1622         ++ it)
    15781623    {
    15791624        const Bstr &typeId = (*it)->id();
     
    15921637}
    15931638
    1594 STDMETHODIMP VirtualBox::CreateSharedFolder(IN_BSTR aName, IN_BSTR aHostPath, BOOL /* aWritable */)
     1639STDMETHODIMP
     1640VirtualBox::CreateSharedFolder (IN_BSTR aName, IN_BSTR aHostPath, BOOL /* aWritable */)
    15951641{
    15961642    CheckComArgNotNull(aName);
     
    16031649}
    16041650
    1605 STDMETHODIMP VirtualBox::RemoveSharedFolder(IN_BSTR aName)
     1651STDMETHODIMP VirtualBox::RemoveSharedFolder (IN_BSTR aName)
    16061652{
    16071653    CheckComArgNotNull(aName);
     
    19602006void VirtualBox::dumpAllBackRefs()
    19612007{
    1962     {
    1963         AutoReadLock al(m->ollHardDisks.getLockHandle());
    1964         for (MediaList::const_iterator mt = m->ollHardDisks.begin();
    1965              mt != m->ollHardDisks.end();
    1966              ++mt)
    1967         {
    1968             ComObjPtr<Medium> pMedium = *mt;
    1969             pMedium->dumpBackRefs();
    1970         }
    1971     }
    1972     {
    1973         AutoReadLock al(m->ollDVDImages.getLockHandle());
    1974         for (MediaList::const_iterator mt = m->ollDVDImages.begin();
    1975              mt != m->ollDVDImages.end();
    1976              ++mt)
    1977         {
    1978             ComObjPtr<Medium> pMedium = *mt;
    1979             pMedium->dumpBackRefs();
    1980         }
     2008    for (MediaList::const_iterator mt = m->llHardDisks.begin();
     2009         mt != m->llHardDisks.end();
     2010         ++mt)
     2011    {
     2012        ComObjPtr<Medium> pMedium = *mt;
     2013        pMedium->dumpBackRefs();
     2014    }
     2015    for (MediaList::const_iterator mt = m->llDVDImages.begin();
     2016         mt != m->llDVDImages.end();
     2017         ++mt)
     2018    {
     2019        ComObjPtr<Medium> pMedium = *mt;
     2020        pMedium->dumpBackRefs();
    19812021    }
    19822022}
     
    26222662{
    26232663    ComObjPtr<GuestOSType> type;
     2664
    26242665    AutoCaller autoCaller(this);
    26252666    AssertComRCReturn(autoCaller.rc(), type);
    26262667
     2668    AutoReadLock alock(this);
     2669
    26272670    /* unknown type must always be the first */
    2628     ComAssertRet(m->ollGuestOSTypes.size() > 0, type);
    2629 
    2630     return m->ollGuestOSTypes.front();
     2671    ComAssertRet (m->llGuestOSTypes.size() > 0, type);
     2672
     2673    type = m->llGuestOSTypes.front();
     2674    return type;
    26312675}
    26322676
     
    26592703    AutoReadLock alock(this);
    26602704
    2661     for (MachinesOList::iterator it = m->ollMachines.begin();
    2662          it != m->ollMachines.end();
     2705    for (MachineList::iterator it = m->llMachines.begin();
     2706         it != m->llMachines.end();
    26632707         ++it)
    26642708    {
     
    26952739                                ComObjPtr<Machine> *aMachine /* = NULL */)
    26962740{
    2697     HRESULT rc = VBOX_E_OBJECT_NOT_FOUND;
    2698 
    26992741    AutoCaller autoCaller(this);
    27002742    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    27012743
    2702     {
    2703         AutoReadLock al(m->ollMachines.getLockHandle());
    2704 
    2705         for (MachinesOList::iterator it = m->ollMachines.begin();
    2706              it != m->ollMachines.end();
    2707              ++it)
     2744    bool found = false;
     2745
     2746    {
     2747        AutoReadLock alock(this);
     2748
     2749        for (MachineList::iterator it = m->llMachines.begin();
     2750             !found && it != m->llMachines.end();
     2751             ++ it)
    27082752        {
    27092753            ComObjPtr<Machine> pMachine2 = *it;
     
    27122756            AssertComRC(machCaller.rc());
    27132757
    2714             if (pMachine2->getId() == aId)
    2715             {
    2716                 rc = S_OK;
    2717                 if (aMachine)
    2718                     *aMachine = pMachine2;
    2719                 break;
    2720             }
    2721         }
    2722     }
    2723 
    2724     if (aSetError && FAILED(rc))
    2725         setError(VBOX_E_OBJECT_NOT_FOUND,
    2726                  tr("Could not find a registered machine with UUID {%RTuuid}"),
    2727                  aId.raw());
     2758            found = pMachine2->getId() == aId;
     2759            if (found && aMachine)
     2760                *aMachine = pMachine2;
     2761        }
     2762    }
     2763
     2764    HRESULT rc = found ? S_OK : VBOX_E_OBJECT_NOT_FOUND;
     2765
     2766    if (aSetError && !found)
     2767    {
     2768        setError (VBOX_E_OBJECT_NOT_FOUND,
     2769            tr ("Could not find a registered machine with UUID {%RTuuid}"),
     2770            aId.raw());
     2771    }
    27282772
    27292773    return rc;
     
    27522796    AssertReturn(aId || aLocation, E_INVALIDARG);
    27532797
    2754     // we use the hard disks map, but it is protected by the
    2755     // hard disk _list_ lock handle
    2756     AutoReadLock alock(m->ollHardDisks.getLockHandle());
     2798    AutoReadLock alock(this);
    27572799
    27582800    /* first, look up by UUID in the map if UUID is provided */
    27592801    if (aId)
    27602802    {
    2761         HardDiskMap::const_iterator it = m->mapHardDisks.find(*aId);
     2803        HardDiskMap::const_iterator it = m->mapHardDisks.find (*aId);
    27622804        if (it != m->mapHardDisks.end())
    27632805        {
     
    28452887    }
    28462888
    2847     AutoReadLock alock(m->ollDVDImages.getLockHandle());
     2889    AutoReadLock alock(this);
    28482890
    28492891    bool found = false;
    28502892
    2851     for (MediaList::const_iterator it = m->ollDVDImages.begin();
    2852          it != m->ollDVDImages.end();
     2893    for (MediaList::const_iterator it = m->llDVDImages.begin();
     2894         it != m->llDVDImages.end();
    28532895         ++ it)
    28542896    {
     
    29212963    }
    29222964
    2923     AutoReadLock alock(m->ollFloppyImages.getLockHandle());
     2965    AutoReadLock alock(this);
    29242966
    29252967    bool found = false;
    29262968
    2927     for (MediaList::const_iterator it = m->ollFloppyImages.begin();
    2928          it != m->ollFloppyImages.end();
     2969    for (MediaList::const_iterator it = m->llFloppyImages.begin();
     2970         it != m->llFloppyImages.end();
    29292971         ++ it)
    29302972    {
     
    29673009                                    GuestOSType*& pGuestOSType)
    29683010{
     3011    AutoReadLock alock(this);
     3012
    29693013    /* Look for a GuestOSType object */
    2970     AssertMsg(m->ollGuestOSTypes.size() != 0,
     3014    AssertMsg(m->llGuestOSTypes.size() != 0,
    29713015              ("Guest OS types array must be filled"));
    29723016
     
    29773021    }
    29783022
    2979     AutoReadLock alock(m->ollGuestOSTypes.getLockHandle());
    2980     for (GuestOSTypesOList::const_iterator it = m->ollGuestOSTypes.begin();
    2981          it != m->ollGuestOSTypes.end();
     3023    for (GuestOSTypeList::const_iterator it = m->llGuestOSTypes.begin();
     3024         it != m->llGuestOSTypes.end();
    29823025         ++it)
    29833026    {
     
    31233166 * @note Locks this object and media objects for reading.
    31243167 */
    3125 HRESULT VirtualBox::checkMediaForConflicts2(const Guid &aId,
    3126                                             const Utf8Str &aLocation,
    3127                                             Utf8Str &aConflict)
     3168HRESULT VirtualBox::checkMediaForConflicts2 (const Guid &aId,
     3169                                             const Utf8Str &aLocation,
     3170                                             Utf8Str &aConflict)
    31283171{
    31293172    aConflict.setNull();
     
    31963239    HRESULT rc = S_OK;
    31973240
     3241    /* serialize file access (prevents concurrent reads and writes) */
     3242    AutoWriteLock alock(this);
     3243
    31983244    try
    31993245    {
    32003246        // machines
    3201         settings::MachinesRegistry machinesTemp;
    3202         {
    3203             AutoReadLock al(m->ollMachines.getLockHandle());
    3204             for (MachinesOList::iterator it = m->ollMachines.begin();
    3205                  it != m->ollMachines.end();
    3206                  ++it)
    3207             {
    3208                 settings::MachineRegistryEntry mre;
    3209                 rc = (*it)->saveRegistryEntry(mre);
    3210                 machinesTemp.push_back(mre);
    3211             }
     3247        m->pMainConfigFile->llMachines.clear();
     3248        for (MachineList::iterator it = m->llMachines.begin();
     3249             it != m->llMachines.end();
     3250             ++it)
     3251        {
     3252            settings::MachineRegistryEntry mre;
     3253            rc = (*it)->saveRegistryEntry(mre);
     3254            m->pMainConfigFile->llMachines.push_back(mre);
    32123255        }
    32133256
    32143257        // hard disks
    3215         settings::MediaList hardDisksTemp;
    3216         {
    3217             AutoReadLock al(m->ollHardDisks.getLockHandle());
    3218             for (MediaList::const_iterator it = m->ollHardDisks.begin();
    3219                  it != m->ollHardDisks.end();
    3220                  ++it)
    3221             {
    3222                 settings::Medium med;
    3223                 rc = (*it)->saveSettings(med);
    3224                 if (FAILED(rc)) throw rc;
    3225                 hardDisksTemp.push_back(med);
    3226             }
     3258        m->pMainConfigFile->llHardDisks.clear();
     3259        for (MediaList::const_iterator it = m->llHardDisks.begin();
     3260             it != m->llHardDisks.end();
     3261             ++it)
     3262        {
     3263            settings::Medium med;
     3264            rc = (*it)->saveSettings(med);
     3265            m->pMainConfigFile->llHardDisks.push_back(med);
     3266            if (FAILED(rc)) throw rc;
    32273267        }
    32283268
    32293269        /* CD/DVD images */
    3230         settings::MediaList dvdsTemp;
    3231         {
    3232             AutoReadLock al(m->ollDVDImages.getLockHandle());
    3233             for (MediaList::const_iterator it = m->ollDVDImages.begin();
    3234                  it != m->ollDVDImages.end();
    3235                  ++it)
    3236             {
    3237                 settings::Medium med;
    3238                 rc = (*it)->saveSettings(med);
    3239                 if (FAILED(rc)) throw rc;
    3240                 dvdsTemp.push_back(med);
    3241             }
     3270        m->pMainConfigFile->llDvdImages.clear();
     3271        for (MediaList::const_iterator it = m->llDVDImages.begin();
     3272             it != m->llDVDImages.end();
     3273             ++it)
     3274        {
     3275            settings::Medium med;
     3276            rc = (*it)->saveSettings(med);
     3277            if (FAILED(rc)) throw rc;
     3278            m->pMainConfigFile->llDvdImages.push_back(med);
    32423279        }
    32433280
    32443281        /* floppy images */
    3245         settings::MediaList floppiesTemp;
    3246         {
    3247             AutoReadLock al(m->ollFloppyImages.getLockHandle());
    3248             for (MediaList::const_iterator it = m->ollFloppyImages.begin();
    3249                  it != m->ollFloppyImages.end();
    3250                  ++it)
    3251             {
    3252                 settings::Medium med;
    3253                 rc = (*it)->saveSettings(med);
    3254                 if (FAILED(rc)) throw rc;
    3255                 floppiesTemp.push_back(med);
    3256             }
    3257         }
    3258 
    3259         settings::DHCPServersList dhcpServersTemp;
    3260         {
    3261             AutoReadLock al(m->ollDHCPServers.getLockHandle());
    3262             for (DHCPServersOList::const_iterator it = m->ollDHCPServers.begin();
    3263                  it != m->ollDHCPServers.end();
    3264                  ++it)
    3265             {
    3266                 settings::DHCPServer d;
    3267                 rc = (*it)->saveSettings(d);
    3268                 if (FAILED(rc)) throw rc;
    3269                 dhcpServersTemp.push_back(d);
    3270             }
    3271         }
    3272 
    3273         /* finally, lock VirtualBox object for writing */
    3274         AutoWriteLock alock(this);
    3275 
    3276         /* now copy the temp data to the config file under the VirtualBox lock */
    3277         m->pMainConfigFile->llMachines = machinesTemp;
    3278         m->pMainConfigFile->llHardDisks = hardDisksTemp;
    3279         m->pMainConfigFile->llDvdImages = dvdsTemp;
    3280         m->pMainConfigFile->llFloppyImages = floppiesTemp;
    3281         m->pMainConfigFile->llDhcpServers = dhcpServersTemp;
    3282 
    3283         // leave extra data alone, it's still in the config file
     3282        m->pMainConfigFile->llFloppyImages.clear();
     3283        for (MediaList::const_iterator it = m->llFloppyImages.begin();
     3284             it != m->llFloppyImages.end();
     3285             ++it)
     3286        {
     3287            settings::Medium med;
     3288            rc = (*it)->saveSettings(med);
     3289            if (FAILED(rc)) throw rc;
     3290            m->pMainConfigFile->llFloppyImages.push_back(med);
     3291        }
     3292
     3293        m->pMainConfigFile->llDhcpServers.clear();
     3294        for (DHCPServerList::const_iterator it =
     3295                m->llDHCPServers.begin();
     3296                it != m->llDHCPServers.end();
     3297                ++ it)
     3298        {
     3299            settings::DHCPServer d;
     3300            rc = (*it)->saveSettings(d);
     3301            if (FAILED(rc)) throw rc;
     3302            m->pMainConfigFile->llDhcpServers.push_back(d);
     3303        }
    32843304
    32853305        /* host data (USB filters) */
     
    32903310        if (FAILED(rc)) throw rc;
    32913311
    3292         // and write out the XML, still under the lock
     3312        // now write out the XML
    32933313        m->pMainConfigFile->write(m->strSettingsFilePath);
    32943314    }
     
    33283348    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    33293349
     3350    AutoWriteLock alock(this);
     3351
    33303352    HRESULT rc = S_OK;
    33313353
     
    33573379
    33583380    /* add to the collection of registered machines */
    3359     m->ollMachines.addChild(aMachine);
     3381    m->llMachines.push_back(aMachine);
    33603382
    33613383    if (autoCaller.state() != InInit)
     
    33883410    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    33893411
    3390     AutoCaller hardDiskCaller(aHardDisk);
     3412    AutoWriteLock alock(this);
     3413
     3414    AutoCaller hardDiskCaller (aHardDisk);
    33913415    AssertComRCReturn(hardDiskCaller.rc(), hardDiskCaller.rc());
    33923416
    3393     Guid id;
    3394     Utf8Str strLocationFull;
    3395     ComObjPtr<Medium> pParent;
    3396     {
    3397         AutoReadLock hardDiskLock(aHardDisk);
    3398         id = aHardDisk->getId();
    3399         strLocationFull = aHardDisk->getLocationFull();
    3400         pParent = aHardDisk->getParent();
    3401     }
    3402 
    3403     HRESULT rc;
    3404     {
    3405         // lock the hard disk lists (list + map) while checking for conflicts
    3406         AutoWriteLock al(m->ollHardDisks.getLockHandle());
    3407 
    3408         Utf8Str strConflict;
    3409         rc = checkMediaForConflicts2(id,
    3410                                      strLocationFull,
    3411                                      strConflict);
    3412         if (FAILED(rc)) return rc;
    3413         if (strConflict.length())
    3414             return setError(E_INVALIDARG,
    3415                             tr("Cannot register the hard disk '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
    3416                             strLocationFull.raw(),
    3417                             id.raw(),
    3418                             strConflict.raw(),
    3419                             m->strSettingsFilePath.raw());
    3420 
    3421         // store base (root) hard disks in the list
    3422         if (pParent.isNull())
    3423             m->ollHardDisks.getList().push_back(aHardDisk);
    3424                     // access the list directly because we already locked the list above
    3425 
    3426         // store all hard disks (even differencing images) in the map
    3427         m->mapHardDisks[id] = aHardDisk;
    3428     }
     3417    AutoReadLock hardDiskLock (aHardDisk);
     3418
     3419    Utf8Str strConflict;
     3420    HRESULT rc = checkMediaForConflicts2(aHardDisk->getId(),
     3421                                         aHardDisk->getLocationFull(),
     3422                                         strConflict);
     3423    if (FAILED(rc)) return rc;
     3424
     3425    if (strConflict.length())
     3426    {
     3427        return setError(E_INVALIDARG,
     3428                        tr("Cannot register the hard disk '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
     3429                        aHardDisk->getLocationFull().raw(),
     3430                        aHardDisk->getId().raw(),
     3431                        strConflict.raw(),
     3432                        m->strSettingsFilePath.raw());
     3433    }
     3434
     3435    if (aHardDisk->getParent().isNull())
     3436    {
     3437        /* base (root) hard disk */
     3438        m->llHardDisks.push_back (aHardDisk);
     3439    }
     3440
     3441    m->mapHardDisks.insert(HardDiskMap::value_type(aHardDisk->getId(),
     3442                                                   HardDiskMap::mapped_type(aHardDisk)));
    34293443
    34303444    if (aSaveRegistry)
    34313445    {
    34323446        rc = saveSettings();
    3433         if (FAILED(rc))
     3447        if (FAILED (rc))
    34343448            unregisterHardDisk(aHardDisk, false /* aSaveRegistry */);
    34353449    }
     
    34613475    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    34623476
     3477    AutoWriteLock alock(this);
     3478
    34633479    AutoCaller hardDiskCaller (aHardDisk);
    34643480    AssertComRCReturn(hardDiskCaller.rc(), hardDiskCaller.rc());
    34653481
    3466     Guid id;
    3467     ComObjPtr<Medium> pParent;
    3468     {
    3469         AutoReadLock hardDiskLock(aHardDisk);
    3470         id = aHardDisk->getId();
    3471         pParent = aHardDisk->getParent();
    3472     }
    3473 
    3474     {
    3475         // lock the hard disk lists (list + map)
    3476         AutoWriteLock al(m->ollHardDisks.getLockHandle());
    3477 
    3478         // remove base (root) hard disks from the list
    3479         if (pParent.isNull())
    3480             m->ollHardDisks.getList().remove(aHardDisk);
    3481                     // access the list directly because we already locked the list above
    3482 
    3483         // remove all hard disks (even differencing images) from map
    3484         size_t cnt = m->mapHardDisks.erase(id);
    3485         Assert(cnt == 1);
    3486         NOREF(cnt);
     3482    AutoReadLock hardDiskLock (aHardDisk);
     3483
     3484    size_t cnt = m->mapHardDisks.erase(aHardDisk->getId());
     3485    Assert(cnt == 1);
     3486    NOREF(cnt);
     3487
     3488    if (aHardDisk->getParent().isNull())
     3489    {
     3490        /* base (root) hard disk */
     3491        m->llHardDisks.remove(aHardDisk);
    34873492    }
    34883493
     
    34923497    {
    34933498        rc = saveSettings();
    3494         if (FAILED(rc))
     3499        if (FAILED (rc))
    34953500            registerHardDisk(aHardDisk, false /* aSaveRegistry */);
    34963501    }
     
    35003505
    35013506/**
    3502  * Remembers the given image by storing it in the CD/DVD or floppy image registry.
    3503  *
    3504  * @param argImage      Image object to remember.
    3505  * @param argType       Either DeviceType_DVD or DeviceType_Floppy.
     3507 * Remembers the given image by storing it in the CD/DVD image registry.
     3508 *
     3509 * @param aImage        Image object to remember.
    35063510 * @param aSaveRegistry @c true to save the image registry to disk (default).
    35073511 *
     
    35153519 * @note Locks this object for writing and @a aImage for reading.
    35163520 */
    3517 HRESULT VirtualBox::registerImage(Medium *argImage,
    3518                                   DeviceType_T argType,
    3519                                   bool argSaveRegistry /*= true*/)
    3520 {
    3521     AssertReturn(argImage != NULL, E_INVALIDARG);
     3521HRESULT VirtualBox::registerDVDImage (Medium *aImage,
     3522                                      bool aSaveRegistry /*= true*/)
     3523{
     3524    AssertReturn(aImage != NULL, E_INVALIDARG);
    35223525
    35233526    AutoCaller autoCaller(this);
    35243527    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    35253528
    3526     AutoCaller imageCaller(argImage);
     3529    AutoWriteLock alock(this);
     3530
     3531    AutoCaller imageCaller (aImage);
    35273532    AssertComRCReturn(imageCaller.rc(), imageCaller.rc());
    35283533
    3529     Guid id;
    3530     Utf8Str strLocationFull;
    3531     ComObjPtr<Medium> pParent;
    3532     {
    3533         AutoReadLock al(argImage);
    3534         id = argImage->getId();
    3535         strLocationFull = argImage->getLocationFull();
    3536         pParent = argImage->getParent();
    3537     }
    3538 
    3539     // work on DVDs or floppies list?
    3540     ObjectsList<Medium> &oll = (argType == DeviceType_DVD) ? m->ollDVDImages : m->ollFloppyImages;
    3541 
    3542     HRESULT rc;
    3543     {
    3544         // lock the images lists (list + map) while checking for conflicts
    3545         AutoWriteLock al(oll.getLockHandle());
    3546 
    3547         Utf8Str strConflict;
    3548         rc = checkMediaForConflicts2(id,
    3549                                      strLocationFull,
    3550                                      strConflict);
    3551         if (FAILED(rc)) return rc;
    3552 
    3553         if (strConflict.length())
    3554             return setError(VBOX_E_INVALID_OBJECT_STATE,
    3555                             tr("Cannot register the image '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
    3556                             strLocationFull.raw(),
    3557                             id.raw(),
    3558                             strConflict.raw(),
    3559                             m->strSettingsFilePath.raw());
    3560 
    3561         // add to the collection
    3562         oll.getList().push_back(argImage);
    3563                 // access the list directly because we already locked the list above
    3564     }
    3565 
    3566     if (argSaveRegistry)
     3534    AutoReadLock imageLock (aImage);
     3535
     3536    Utf8Str strConflict;
     3537    HRESULT rc = checkMediaForConflicts2(aImage->getId(),
     3538                                         aImage->getLocationFull(),
     3539                                         strConflict);
     3540    if (FAILED(rc)) return rc;
     3541
     3542    if (strConflict.length())
     3543    {
     3544        return setError(VBOX_E_INVALID_OBJECT_STATE,
     3545                        tr("Cannot register the CD/DVD image '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
     3546                        aImage->getLocationFull().raw(),
     3547                        aImage->getId().raw(),
     3548                        strConflict.raw(),
     3549                        m->strSettingsFilePath.raw());
     3550    }
     3551
     3552    /* add to the collection */
     3553    m->llDVDImages.push_back (aImage);
     3554
     3555    if (aSaveRegistry)
    35673556    {
    35683557        rc = saveSettings();
    3569         if (FAILED(rc))
    3570             unregisterImage(argImage, argType, false /* aSaveRegistry */);
     3558        if (FAILED (rc))
     3559            unregisterDVDImage (aImage, false /* aSaveRegistry */);
    35713560    }
    35723561
     
    35753564
    35763565/**
    3577  * Removes the given image from the CD/DVD or floppy image registry.
    3578  *
    3579  * @param argImage        Image object to remove.
    3580  * @param argType         Either DeviceType_DVD or DeviceType_Floppy.
    3581  * @param argSaveRegistry @c true to save hard disk registry to disk (default).
     3566 * Removes the given image from the CD/DVD image registry registry.
     3567 *
     3568 * @param aImage        Image object to remove.
     3569 * @param aSaveRegistry @c true to save hard disk registry to disk (default).
    35823570 *
    35833571 * When @a aSaveRegistry is @c true, this operation may fail because of the
     
    35903578 * @note Locks this object for writing and @a aImage for reading.
    35913579 */
    3592 HRESULT VirtualBox::unregisterImage(Medium *argImage,
    3593                                     DeviceType_T argType,
    3594                                     bool argSaveRegistry /*= true*/)
    3595 {
    3596     AssertReturn(argImage != NULL, E_INVALIDARG);
     3580HRESULT VirtualBox::unregisterDVDImage (Medium *aImage,
     3581                                        bool aSaveRegistry /*= true*/)
     3582{
     3583    AssertReturn(aImage != NULL, E_INVALIDARG);
    35973584
    35983585    AutoCaller autoCaller(this);
    35993586    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    36003587
    3601     AutoCaller imageCaller(argImage);
     3588    AutoWriteLock alock(this);
     3589
     3590    AutoCaller imageCaller (aImage);
    36023591    AssertComRCReturn(imageCaller.rc(), imageCaller.rc());
    36033592
    3604     Guid id;
    3605     ComObjPtr<Medium> pParent;
    3606     {
    3607         AutoReadLock al(argImage);
    3608         id = argImage->getId();
    3609         pParent = argImage->getParent();
    3610     }
    3611 
    3612     // work on DVDs or floppies list?
    3613     ObjectsList<Medium> &oll = (argType == DeviceType_DVD) ? m->ollDVDImages : m->ollFloppyImages;
    3614 
    3615     oll.removeChild(argImage);
     3593    AutoReadLock imageLock (aImage);
     3594
     3595    m->llDVDImages.remove (aImage);
    36163596
    36173597    HRESULT rc = S_OK;
    36183598
    3619     if (argSaveRegistry)
     3599    if (aSaveRegistry)
    36203600    {
    36213601        rc = saveSettings();
    3622         if (FAILED(rc))
    3623             registerImage(argImage, argType, false /* aSaveRegistry */);
     3602        if (FAILED (rc))
     3603            registerDVDImage (aImage, false /* aSaveRegistry */);
    36243604    }
    36253605
    36263606    return rc;
     3607}
     3608
     3609/**
     3610 * Remembers the given image by storing it in the floppy image registry.
     3611 *
     3612 * @param aImage        Image object to remember.
     3613 * @param aSaveRegistry @c true to save the image registry to disk (default).
     3614 *
     3615 * When @a aSaveRegistry is @c true, this operation may fail because of the
     3616 * failed #saveSettings() method it calls. In this case, the image object
     3617 * will not be remembered. It is therefore the responsibility of the caller to
     3618 * call this method as the last step of some action that requires registration
     3619 * in order to make sure that only fully functional image objects get
     3620 * registered.
     3621 *
     3622 * @note Locks this object for writing and @a aImage for reading.
     3623 */
     3624HRESULT VirtualBox::registerFloppyImage(Medium *aImage,
     3625                                        bool aSaveRegistry /*= true*/)
     3626{
     3627    AssertReturn(aImage != NULL, E_INVALIDARG);
     3628
     3629    AutoCaller autoCaller(this);
     3630    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
     3631
     3632    AutoWriteLock alock(this);
     3633
     3634    AutoCaller imageCaller (aImage);
     3635    AssertComRCReturn(imageCaller.rc(), imageCaller.rc());
     3636
     3637    AutoReadLock imageLock (aImage);
     3638
     3639    Utf8Str strConflict;
     3640    HRESULT rc = checkMediaForConflicts2(aImage->getId(),
     3641                                         aImage->getLocationFull(),
     3642                                         strConflict);
     3643    if (FAILED(rc)) return rc;
     3644
     3645    if (strConflict.length())
     3646    {
     3647        return setError(VBOX_E_INVALID_OBJECT_STATE,
     3648                        tr("Cannot register the floppy image '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
     3649                        aImage->getLocationFull().raw(),
     3650                        aImage->getId().raw(),
     3651                        strConflict.raw(),
     3652                        m->strSettingsFilePath.raw());
     3653    }
     3654
     3655    /* add to the collection */
     3656    m->llFloppyImages.push_back (aImage);
     3657
     3658    if (aSaveRegistry)
     3659    {
     3660        rc = saveSettings();
     3661        if (FAILED (rc))
     3662            unregisterFloppyImage(aImage, false /* aSaveRegistry */);
     3663    }
     3664
     3665    return rc;
     3666}
     3667
     3668/**
     3669 * Removes the given image from the floppy image registry registry.
     3670 *
     3671 * @param aImage        Image object to remove.
     3672 * @param aSaveRegistry @c true to save hard disk registry to disk (default).
     3673 *
     3674 * When @a aSaveRegistry is @c true, this operation may fail because of the
     3675 * failed #saveSettings() method it calls. In this case, the image object
     3676 * will NOT be removed from the registry when this method returns. It is
     3677 * therefore the responsibility of the caller to call this method as the first
     3678 * step of some action that requires unregistration, before calling uninit() on
     3679 * @a aImage.
     3680 *
     3681 * @note Locks this object for writing and @a aImage for reading.
     3682 */
     3683HRESULT VirtualBox::unregisterFloppyImage(Medium *aImage,
     3684                                          bool aSaveRegistry /*= true*/)
     3685{
     3686    AssertReturn(aImage != NULL, E_INVALIDARG);
     3687
     3688    AutoCaller autoCaller(this);
     3689    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
     3690
     3691    AutoWriteLock alock(this);
     3692
     3693    AutoCaller imageCaller (aImage);
     3694    AssertComRCReturn(imageCaller.rc(), imageCaller.rc());
     3695
     3696    AutoReadLock imageLock (aImage);
     3697
     3698    m->llFloppyImages.remove (aImage);
     3699
     3700    HRESULT rc = S_OK;
     3701
     3702    if (aSaveRegistry)
     3703    {
     3704        rc = saveSettings();
     3705        if (FAILED (rc))
     3706            registerFloppyImage (aImage, false /* aSaveRegistry */);
     3707    }
     3708
     3709    return rc;
     3710}
     3711
     3712/**
     3713 * Attempts to cast from a raw interface pointer to an underlying object.
     3714 * On success, @a aTo will contain the object reference. On failure, @a aTo will
     3715 * be set to @c null and an extended error info will be returned.
     3716 *
     3717 * @param aFrom     Interface pointer to cast from.
     3718 * @param aTo       Where to store a reference to the underlying object.
     3719 *
     3720 * @note Locks #childrenLock() for reading.
     3721 */
     3722HRESULT VirtualBox::cast (IMedium *aFrom, ComObjPtr<Medium> &aTo)
     3723{
     3724    AssertReturn(aFrom != NULL, E_INVALIDARG);
     3725
     3726    AutoCaller autoCaller(this);
     3727    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
     3728
     3729    /* We need the children map lock here to keep the getDependentChild() result
     3730     * valid until we finish */
     3731    AutoReadLock chLock (childrenLock());
     3732
     3733    VirtualBoxBase *child = getDependentChild (aFrom);
     3734    if (!child)
     3735        return setError (E_FAIL, tr ("The given hard disk object is not created "
     3736                                     "within this VirtualBox instance"));
     3737
     3738    /* we can safely cast child to Medium * here because only Medium
     3739     * implementations of IMedium can be among our children */
     3740
     3741    aTo = static_cast<Medium*>(child);
     3742
     3743    return S_OK;
    36273744}
    36283745
     
    36373754 * @note Locks this object + DVD, Floppy and HardDisk children for writing.
    36383755 */
    3639 HRESULT VirtualBox::updateSettings(const char *aOldPath, const char *aNewPath)
     3756HRESULT VirtualBox::updateSettings (const char *aOldPath, const char *aNewPath)
    36403757{
    36413758    LogFlowThisFunc(("aOldPath={%s} aNewPath={%s}\n", aOldPath, aNewPath));
     
    36473764    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    36483765
    3649     ObjectsList<Medium> ollAll;
    3650     ollAll.appendOtherList(m->ollDVDImages);
    3651     ollAll.appendOtherList(m->ollFloppyImages);
    3652     ollAll.appendOtherList(m->ollHardDisks);
    3653 
    3654     for (MediaList::iterator it = ollAll.begin();
    3655          it != ollAll.end();
     3766    AutoWriteLock alock(this);
     3767
     3768    /* check DVD paths */
     3769    for (MediaList::iterator it = m->llDVDImages.begin();
     3770         it != m->llDVDImages.end();
    36563771         ++ it)
    36573772    {
    36583773        (*it)->updatePath(aOldPath, aNewPath);
     3774    }
     3775
     3776    /* check Floppy paths */
     3777    for (MediaList::iterator it = m->llFloppyImages.begin();
     3778         it != m->llFloppyImages  .end();
     3779         ++ it)
     3780    {
     3781        (*it)->updatePath(aOldPath, aNewPath);
     3782    }
     3783
     3784    /* check HardDisk paths */
     3785    for (MediaList::const_iterator it = m->llHardDisks.begin();
     3786         it != m->llHardDisks.end();
     3787         ++ it)
     3788    {
     3789        (*it)->updatePaths(aOldPath, aNewPath);
    36593790    }
    36603791
     
    37683899RWLockHandle& VirtualBox::hardDiskTreeLockHandle()
    37693900{
    3770     return m->ollHardDisks.getLockHandle();
     3901    return m->mtxHardDiskTree;
     3902}
     3903
     3904/**
     3905 * Reimplements VirtualBoxWithTypedChildren::childrenLock() to return a
     3906 * dedicated lock instead of the main object lock. The dedicated lock for
     3907 * child map operations frees callers of init() methods of these children
     3908 * from acquiring a write parent (VirtualBox) lock (which would be mandatory
     3909 * otherwise). Since VirtualBox has a lot of heterogenous children which
     3910 * init() methods are called here and there, it definitely makes sense.
     3911 */
     3912RWLockHandle* VirtualBox::childrenLock()
     3913{
     3914    return &m->mtxChildrenMap;
    37713915}
    37723916
     
    37803924    LogFlowFuncEnter();
    37813925
    3782     VirtualBox *that = (VirtualBox*)pvUser;
    3783     Assert(that);
    3784 
    3785     typedef std::vector< ComObjPtr<Machine> > MachineVector;
    3786     typedef std::vector< ComObjPtr<SessionMachine> > SessionMachineVector;
     3926    VirtualBox *that = (VirtualBox *) pvUser;
     3927    Assert (that);
    37873928
    37883929    SessionMachineVector machines;
     
    38373978            {
    38383979                /* machine mutex is released */
    3839                 (machines[rc - WAIT_OBJECT_0 - 1])->checkForDeath();
     3980                (machines [rc - WAIT_OBJECT_0 - 1])->checkForDeath();
    38403981                update = true;
    38413982            }
     
    38433984            {
    38443985                /* machine mutex is abandoned due to client process termination */
    3845                 (machines[rc - WAIT_ABANDONED_0 - 1])->checkForDeath();
     3986                (machines [rc - WAIT_ABANDONED_0 - 1])->checkForDeath();
    38463987                update = true;
    38473988            }
     
    38573998            {
    38583999                /* close old process handles */
    3859                 for (size_t i = 1 + cnt; i < 1 + cnt + cntSpawned; ++i)
    3860                     CloseHandle(handles[i]);
    3861 
    3862                 // lock the machines list for reading
    3863                 AutoReadLock thatLock(that->m->ollMachines.getLockHandle());
     4000                for (size_t i = 1 + cnt; i < 1 + cnt + cntSpawned; ++ i)
     4001                    CloseHandle (handles [i]);
     4002
     4003                AutoReadLock thatLock (that);
    38644004
    38654005                /* obtain a new set of opened machines */
     
    38674007                machines.clear();
    38684008
    3869                 for (MachinesOList::iterator it = that->m->ollMachines.begin();
    3870                      it != that->m->ollMachines.end();
    3871                      ++it)
     4009                for (MachineList::iterator it = that->m->llMachines.begin();
     4010                     it != that->m->llMachines.end(); ++ it)
    38724011                {
    38734012                    /// @todo handle situations with more than 64 objects
     
    38774016                    ComObjPtr<SessionMachine> sm;
    38784017                    HANDLE ipcSem;
    3879                     if ((*it)->isSessionOpenOrClosing(sm, NULL, &ipcSem))
     4018                    if ((*it)->isSessionOpenOrClosing (sm, NULL, &ipcSem))
    38804019                    {
    3881                         machines.push_back(sm);
    3882                         handles[1 + cnt] = ipcSem;
    3883                         ++cnt;
     4020                        machines.push_back (sm);
     4021                        handles [1 + cnt] = ipcSem;
     4022                        ++ cnt;
    38844023                    }
    38854024                }
     
    38914030                spawnedMachines.clear();
    38924031
    3893                 for (MachinesOList::iterator it = that->m->ollMachines.begin();
    3894                      it != that->m->ollMachines.end();
    3895                      ++it)
     4032                for (MachineList::iterator it = that->m->llMachines.begin();
     4033                     it != that->m->llMachines.end(); ++ it)
    38964034                {
    38974035                    /// @todo handle situations with more than 64 objects
     
    39004038
    39014039                    RTPROCESS pid;
    3902                     if ((*it)->isSessionSpawning(&pid))
     4040                    if ((*it)->isSessionSpawning (&pid))
    39034041                    {
    3904                         HANDLE ph = OpenProcess(SYNCHRONIZE, FALSE, pid);
     4042                        HANDLE ph = OpenProcess (SYNCHRONIZE, FALSE, pid);
    39054043                        AssertMsg (ph != NULL, ("OpenProcess (pid=%d) failed with %d\n",
    39064044                                                pid, GetLastError()));
    39074045                        if (rc == 0)
    39084046                        {
    3909                             spawnedMachines.push_back(*it);
    3910                             handles[1 + cnt + cntSpawned] = ph;
    3911                             ++cntSpawned;
     4047                            spawnedMachines.push_back (*it);
     4048                            handles [1 + cnt + cntSpawned] = ph;
     4049                            ++ cntSpawned;
    39124050                        }
    39134051                    }
     
    39154053
    39164054                LogFlowFunc (("UPDATE: spawned session count = %d\n", cntSpawned));
    3917 
    3918                 // machines lock unwinds here
    39194055            }
    39204056        }
     
    39544090            autoCaller.release();
    39554091
    3956             int vrc = RTSemEventWait(that->m->updateReq, 500);
     4092            int vrc = RTSemEventWait (that->m->updateReq, 500);
    39574093
    39584094            /* Restore the caller before using VirtualBox. If it fails, this
     
    39934129#ifdef DEBUG
    39944130                            {
    3995                                 AutoReadLock machineLock(machines[semId]);
     4131                                AutoReadLock machineLock (machines [semId]);
    39964132                                LogFlowFunc (("released mutex: machine='%ls'\n",
    3997                                               machines[semId]->name().raw()));
     4133                                              machines [semId]->name().raw()));
    39984134                            }
    39994135#endif
    4000                             machines[semId]->checkForDeath();
     4136                            machines [semId]->checkForDeath();
    40014137                        }
    40024138                        update = true;
     
    40234159#ifdef DEBUG
    40244160                                    {
    4025                                         AutoReadLock machineLock(machines[semId]);
    4026                                         LogFlowFunc(("mutex owner dead: machine='%ls'\n",
    4027                                                      machines[i]->name().raw()));
     4161                                        AutoReadLock machineLock (machines [semId]);
     4162                                        LogFlowFunc (("mutex owner dead: machine='%ls'\n",
     4163                                                      machines [i]->name().raw()));
    40284164                                    }
    40294165#endif
    4030                                     machines[i]->checkForDeath();
     4166                                    machines [i]->checkForDeath();
    40314167                                }
    40324168                            }
     
    40624198                    machines.clear();
    40634199
    4064                     for (MachinesOList::iterator it = that->m->llMachines.begin();
     4200                    for (MachineList::iterator it = that->m->llMachines.begin();
    40654201                         it != that->m->llMachines.end(); ++ it)
    40664202                    {
     
    40754211                        {
    40764212                            machines.push_back (sm);
    4077                             handles[cnt].hsemCur = (HSEM) ipcSem;
    4078                             handles[cnt].ulUser = cnt;
     4213                            handles [cnt].hsemCur = (HSEM) ipcSem;
     4214                            handles [cnt].ulUser = cnt;
    40794215                            ++ cnt;
    40804216                        }
     
    41004236                    spawnedMachines.clear();
    41014237
    4102                     for (MachinesOList::iterator it = that->m->llMachines.begin();
     4238                    for (MachineList::iterator it = that->m->llMachines.begin();
    41034239                         it != that->m->llMachines.end(); ++ it)
    41044240                    {
     
    41544290                /* RT_SUCCESS(rc) means an update event is signaled */
    41554291
    4156                 // lock the machines list for reading
    4157                 AutoReadLock thatLock(that->m->ollMachines.getLockHandle());
     4292                AutoReadLock thatLock (that);
    41584293
    41594294                if (RT_SUCCESS(rc) || update)
     
    41624297                    machines.clear();
    41634298
    4164                     for (MachinesOList::iterator it = that->m->ollMachines.begin();
    4165                          it != that->m->ollMachines.end();
    4166                          ++it)
     4299                    for (MachineList::iterator it = that->m->llMachines.begin();
     4300                         it != that->m->llMachines.end(); ++ it)
    41674301                    {
    41684302                        ComObjPtr<SessionMachine> sm;
    4169                         if ((*it)->isSessionOpenOrClosing(sm))
    4170                             machines.push_back(sm);
     4303                        if ((*it)->isSessionOpenOrClosing (sm))
     4304                            machines.push_back (sm);
    41714305                    }
    41724306
    41734307                    cnt = machines.size();
    4174                     LogFlowFunc(("UPDATE: direct session count = %d\n", cnt));
     4308                    LogFlowFunc (("UPDATE: direct session count = %d\n", cnt));
    41754309                }
    41764310
     
    41804314                    spawnedMachines.clear();
    41814315
    4182                     for (MachinesOList::iterator it = that->m->ollMachines.begin();
    4183                          it != that->m->ollMachines.end();
    4184                          ++it)
     4316                    for (MachineList::iterator it = that->m->llMachines.begin();
     4317                         it != that->m->llMachines.end(); ++ it)
    41854318                    {
    41864319                        if ((*it)->isSessionSpawning())
    4187                             spawnedMachines.push_back(*it);
     4320                            spawnedMachines.push_back (*it);
    41884321                    }
    41894322
    41904323                    cntSpawned = spawnedMachines.size();
    4191                     LogFlowFunc(("UPDATE: spawned session count = %d\n", cntSpawned));
     4324                    LogFlowFunc (("UPDATE: spawned session count = %d\n", cntSpawned));
    41924325                }
    4193 
    4194                 // machines lock unwinds here
    41954326            }
    41964327
     
    43594490}
    43604491
    4361 STDMETHODIMP VirtualBox::FindDHCPServerByNetworkName(IN_BSTR aName, IDHCPServer ** aServer)
     4492//STDMETHODIMP VirtualBox::FindDHCPServerForInterface (IHostNetworkInterface * aIinterface, IDHCPServer ** aServer)
     4493//{
     4494//    return E_NOTIMPL;
     4495//}
     4496
     4497STDMETHODIMP VirtualBox::FindDHCPServerByNetworkName (IN_BSTR aName, IDHCPServer ** aServer)
    43624498{
    43634499    CheckComArgNotNull(aName);
     
    43664502    AutoCaller autoCaller(this);
    43674503    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     4504
     4505    AutoWriteLock alock(this);
    43684506
    43694507    HRESULT rc;
     
    43714509    ComPtr<DHCPServer> found;
    43724510
    4373     AutoReadLock alock(m->ollDHCPServers.getLockHandle());
    4374 
    4375     for (DHCPServersOList::const_iterator it = m->ollDHCPServers.begin();
    4376          it != m->ollDHCPServers.end();
    4377          ++it)
    4378     {
    4379         rc = (*it)->COMGETTER(NetworkName)(bstr.asOutParam());
     4511    for (DHCPServerList::const_iterator it =
     4512            m->llDHCPServers.begin();
     4513         it != m->llDHCPServers.end();
     4514         ++ it)
     4515    {
     4516        rc = (*it)->COMGETTER(NetworkName) (bstr.asOutParam());
    43804517        if (FAILED(rc)) throw rc;
    43814518
    4382         if (bstr == aName)
     4519        if(bstr == aName)
    43834520        {
    43844521            found = *it;
     
    44214558 */
    44224559HRESULT VirtualBox::registerDHCPServer(DHCPServer *aDHCPServer,
    4423                                        bool aSaveRegistry /*= true*/)
     4560                                     bool aSaveRegistry /*= true*/)
    44244561{
    44254562    AssertReturn(aDHCPServer != NULL, E_INVALIDARG);
     
    44284565    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    44294566
    4430     AutoCaller dhcpServerCaller(aDHCPServer);
     4567    AutoWriteLock alock(this);
     4568
     4569    AutoCaller dhcpServerCaller (aDHCPServer);
    44314570    AssertComRCReturn(dhcpServerCaller.rc(), dhcpServerCaller.rc());
     4571
     4572    AutoReadLock dhcpServerLock (aDHCPServer);
    44324573
    44334574    Bstr name;
    44344575    HRESULT rc;
    4435     rc = aDHCPServer->COMGETTER(NetworkName)(name.asOutParam());
     4576    rc = aDHCPServer->COMGETTER(NetworkName) (name.asOutParam());
    44364577    if (FAILED(rc)) return rc;
    44374578
    44384579    ComPtr<IDHCPServer> existing;
    44394580    rc = FindDHCPServerByNetworkName(name.mutableRaw(), existing.asOutParam());
    4440     if (SUCCEEDED(rc))
     4581    if(SUCCEEDED(rc))
    44414582    {
    44424583        return E_INVALIDARG;
    44434584    }
    4444 
    44454585    rc = S_OK;
    44464586
    4447     m->ollDHCPServers.addChild(aDHCPServer);
     4587    m->llDHCPServers.push_back (aDHCPServer);
    44484588
    44494589    if (aSaveRegistry)
     
    44854625    AssertComRCReturn(dhcpServerCaller.rc(), dhcpServerCaller.rc());
    44864626
    4487     m->ollDHCPServers.removeChild(aDHCPServer);
     4627    AutoReadLock dhcpServerLock (aDHCPServer);
     4628
     4629    m->llDHCPServers.remove (aDHCPServer);
    44884630
    44894631    HRESULT rc = S_OK;
  • trunk/src/VBox/Main/include/SharedFolderImpl.h

    r25170 r25182  
    3131
    3232class ATL_NO_VTABLE SharedFolder :
    33     public VirtualBoxBaseWithChildrenNEXT,
     33    public VirtualBoxBase,
    3434    public VirtualBoxSupportErrorInfoImpl<SharedFolder, ISharedFolder>,
    3535    public VirtualBoxSupportTranslation<SharedFolder>,
     
    9494protected:
    9595
    96     HRESULT protectedInit(VirtualBoxBase *aParent,
    97                           CBSTR aName, CBSTR aHostPath, BOOL aWritable);
     96    HRESULT protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent,
     97                           CBSTR aName, CBSTR aHostPath, BOOL aWritable);
    9898
    9999private:
    100100
    101     VirtualBoxBase *const mParent;
     101    VirtualBoxBaseWithChildrenNEXT *const mParent;
    102102
    103103    /* weak parents (only one of them is not null) */
  • trunk/src/VBox/Main/include/StorageControllerImpl.h

    r25170 r25182  
    3232
    3333class ATL_NO_VTABLE StorageController :
    34     public VirtualBoxBase,
     34    public VirtualBoxBaseWithChildrenNEXT,
    3535    public VirtualBoxSupportErrorInfoImpl<StorageController, IStorageController>,
    3636    public VirtualBoxSupportTranslation<StorageController>,
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r25170 r25182  
    6060
    6161class ATL_NO_VTABLE VirtualBox :
    62     public VirtualBoxBase,
     62    public VirtualBoxBaseWithChildrenNEXT,
    6363    public VirtualBoxSupportErrorInfoImpl<VirtualBox, IVirtualBox>,
    6464    public VirtualBoxSupportTranslation<VirtualBox>,
     
    257257    HRESULT unregisterHardDisk(Medium *aHardDisk, bool aSaveRegistry = true);
    258258
    259     HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool aSaveRegistry = true);
    260     HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool aSaveRegistry = true);
     259    HRESULT registerDVDImage(Medium *aImage, bool aSaveRegistry = true);
     260    HRESULT unregisterDVDImage(Medium *aImage, bool aSaveRegistry = true);
     261
     262    HRESULT registerFloppyImage (Medium *aImage, bool aSaveRegistry = true);
     263    HRESULT unregisterFloppyImage (Medium *aImage, bool aSaveRegistry = true);
     264
     265    HRESULT cast (IMedium *aFrom, ComObjPtr<Medium> &aTo);
    261266
    262267    HRESULT saveSettings();
     
    270275
    271276    RWLockHandle& hardDiskTreeLockHandle();
     277    RWLockHandle* childrenLock();
    272278
    273279    /* for VirtualBoxSupportErrorInfoImpl */
  • trunk/src/VBox/Main/xml/VirtualBox-settings-common.xsd

    r24551 r25182  
    489489    <xsd:element name="PAE" type="TPAEType" minOccurs="0"/>
    490490    <xsd:element name="SyntheticCpu" type="TSyntheticCpuType" minOccurs="0"/>
    491     <xsd:element name="CpuIdTree" type="TCpuIdTree" minOccurs="0">
     491    <xsd:element name="CpuIdTree" type="TCpuIdTree">
    492492      <xsd:unique name="TCPU-CpuIdTree-CpuIdLeaf">
    493493        <xsd:selector xpath="vb:CpuIdLeaf"/>
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