VirtualBox

Changeset 15318 in vbox for trunk/src


Ignore:
Timestamp:
Dec 11, 2008 5:27:02 PM (16 years ago)
Author:
vboxsync
Message:

Main: Fixed a deadlock in VBoxSVC when attaching a hard disk indirectly, through creating a new diff for it.

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

Legend:

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

    r15064 r15318  
    932932    CheckComRCReturnRC (rc);
    933933
    934     /*
    935      *  we can safely cast child to Machine * here because only Machine
    936      *  implementations of IMachine can be among our children
    937      */
     934    /* We need the children map lock here to keep the getDependentChild() result
     935     * valid until we finish */
     936    AutoReadLock chLock (childrenLock());
     937
     938    /* We can safely cast child to Machine * here because only Machine
     939     * implementations of IMachine can be among our children. */
    938940    Machine *machine = static_cast <Machine *> (getDependentChild (aMachine));
    939     if (!machine)
    940     {
    941         /*
    942          *  this machine was not created by CreateMachine()
    943          *  or opened by OpenMachine() or loaded during startup
    944          */
     941    if (machine == NULL)
     942    {
     943        /* this machine was not created by CreateMachine() or opened by
     944         * OpenMachine() or loaded during startup */
    945945        return setError (VBOX_E_INVALID_OBJECT_STATE,
    946946            tr ("The machine named '%ls' is not created within this "
     
    35893589 * @param aTo       Where to store a reference to the underlying object.
    35903590 *
    3591  * @note Locks this object for reading.
     3591 * @note Locks #childrenLock() for reading.
    35923592 */
    35933593HRESULT VirtualBox::cast (IHardDisk2 *aFrom, ComObjPtr <HardDisk2> &aTo)
     
    35983598    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
    35993599
    3600     AutoReadLock alock (this);
     3600    /* We need the children map lock here to keep the getDependentChild() result
     3601     * valid until we finish */
     3602    AutoReadLock chLock (childrenLock());
    36013603
    36023604    VirtualBoxBase *child = getDependentChild (aFrom);
  • trunk/src/VBox/Main/include/HardDisk2Impl.h

    r15051 r15318  
    224224     *    object lock.
    225225     */
    226     RWLockHandle *treeLock() { return mVirtualBox->hardDiskTreeHandle(); }
     226    RWLockHandle *treeLock() { return mVirtualBox->hardDiskTreeLockHandle(); }
    227227
    228228    /** Reimplements VirtualBoxWithTypedChildren::childrenLock() to return
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r15051 r15318  
    362362     *    object lock.
    363363     */
    364     RWLockHandle *hardDiskTreeHandle() { return &mHardDiskTreeHandle; }
     364    RWLockHandle *hardDiskTreeLockHandle() { return &mHardDiskTreeLockHandle; }
    365365
    366366    /* for VirtualBoxSupportErrorInfoImpl */
     
    380380
    381381    typedef std::map <Guid, ComObjPtr <HardDisk2> > HardDisk2Map;
     382
     383    /**
     384     * Reimplements VirtualBoxWithTypedChildren::childrenLock() to return a
     385     * dedicated lock instead of the main object lock. The dedicated lock for
     386     * child map operations frees callers of init() methods of these children
     387     * from acquiring a write parent (VirtualBox) lock (which would be mandatory
     388     * otherwise). Since VirtualBox has a lot of heterogenous children which
     389     * init() methods are called here and there, it definitely makes sense.
     390     */
     391    RWLockHandle *childrenLock() { return &mChildrenMapLockHandle; }
    382392
    383393    HRESULT checkMediaForConflicts2 (const Guid &aId, const Bstr &aLocation,
     
    490500    RWLockHandle mSafeLock;
    491501
    492     RWLockHandle mHardDiskTreeHandle;
     502    RWLockHandle mHardDiskTreeLockHandle;
     503    RWLockHandle mChildrenMapLockHandle;
    493504
    494505    static Bstr sVersion;
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