Index: trunk/src/VBox/Main/idl/VirtualBox.xidl
===================================================================
--- trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 72702)
+++ trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 72703)
@@ -15186,5 +15186,5 @@
     </attribute>
 
-    <attribute name="description" type="wstring">
+    <attribute name="description" type="wstring" wrap-hint-server="passcaller">
       <desc>
         Optional description of the medium. For a newly created medium the value
@@ -16145,5 +16145,5 @@
     <!-- other methods -->
 
-    <method name="setLocation">
+    <method name="setLocation" wrap-hint-server="passcaller">
       <desc>
         Changes the location of this medium. Some medium types may support
@@ -16307,5 +16307,5 @@
     </method>
 
-    <method name="getEncryptionSettings" const="yes">
+    <method name="getEncryptionSettings" const="yes" wrap-hint-server="passcaller">
       <desc>
         Returns the encryption settings for this medium.
Index: trunk/src/VBox/Main/include/MediumImpl.h
===================================================================
--- trunk/src/VBox/Main/include/MediumImpl.h	(revision 72702)
+++ trunk/src/VBox/Main/include/MediumImpl.h	(revision 72703)
@@ -230,6 +230,6 @@
     // wrapped IMedium properties
     HRESULT getId(com::Guid &aId);
-    HRESULT getDescription(com::Utf8Str &aDescription);
-    HRESULT setDescription(const com::Utf8Str &aDescription);
+    HRESULT getDescription(AutoCaller &autoCaller, com::Utf8Str &aDescription);
+    HRESULT setDescription(AutoCaller &autoCaller, const com::Utf8Str &aDescription);
     HRESULT getState(MediumState_T *aState);
     HRESULT getVariant(std::vector<MediumVariant_T> &aVariant);
@@ -293,5 +293,6 @@
                         const std::vector<MediumVariant_T> &aVariant,
                         ComPtr<IProgress> &aProgress);
-    HRESULT setLocation(const com::Utf8Str &aLocation,
+    HRESULT setLocation(AutoCaller &autoCaller,
+                        const com::Utf8Str &aLocation,
                         ComPtr<IProgress> &aProgress);
     HRESULT compact(ComPtr<IProgress> &aProgress);
@@ -302,5 +303,5 @@
                              const com::Utf8Str &aNewPassword, const com::Utf8Str &aNewPasswordId,
                              ComPtr<IProgress> &aProgress);
-    HRESULT getEncryptionSettings(com::Utf8Str &aCipher, com::Utf8Str &aPasswordId);
+    HRESULT getEncryptionSettings(AutoCaller &autoCaller, com::Utf8Str &aCipher, com::Utf8Str &aPasswordId);
     HRESULT checkEncryptionPassword(const com::Utf8Str &aPassword);
 
Index: trunk/src/VBox/Main/src-server/MediumImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/MediumImpl.cpp	(revision 72702)
+++ trunk/src/VBox/Main/src-server/MediumImpl.cpp	(revision 72703)
@@ -1607,6 +1607,7 @@
 }
 
-HRESULT Medium::getDescription(com::Utf8Str &aDescription)
-{
+HRESULT Medium::getDescription(AutoCaller &autoCaller, com::Utf8Str &aDescription)
+{
+    NOREF(autoCaller);
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
 
@@ -1616,5 +1617,5 @@
 }
 
-HRESULT Medium::setDescription(const com::Utf8Str &aDescription)
+HRESULT Medium::setDescription(AutoCaller &autoCaller, const com::Utf8Str &aDescription)
 {
     /// @todo update m->strDescription and save the global registry (and local
@@ -1628,16 +1629,19 @@
     try
     {
+        autoCaller.release();
+
         // locking: we need the tree lock first because we access parent pointers
         // and we need to write-lock the media involved
-        uint32_t    cHandles    = 2;
-        LockHandle* pHandles[2] = { &m->pVirtualBox->i_getMediaTreeLockHandle(),
-                                    this->lockHandle() };
-
-        AutoWriteLock alock(cHandles,
-                            pHandles
-                            COMMA_LOCKVAL_SRC_POS);
+        AutoWriteLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
+
+        autoCaller.add();
+        AssertComRCThrowRC(autoCaller.rc());
+
+        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
         /* Build the lock list. */
         alock.release();
+        autoCaller.release();
+        treeLock.release();
         rc = i_createMediumLockList(true /* fFailIfInaccessible */,
                                     this /* pToLockWrite */,
@@ -1645,4 +1649,7 @@
                                     NULL,
                                     *pMediumLockList);
+        treeLock.acquire();
+        autoCaller.add();
+        AssertComRCThrowRC(autoCaller.rc());
         alock.acquire();
 
@@ -1655,5 +1662,10 @@
 
         alock.release();
+        autoCaller.release();
+        treeLock.release();
         rc = pMediumLockList->Lock();
+        treeLock.acquire();
+        autoCaller.add();
+        AssertComRCThrowRC(autoCaller.rc());
         alock.acquire();
 
@@ -1673,4 +1685,6 @@
         // save the settings
         alock.release();
+        autoCaller.release();
+        treeLock.release();
         i_markRegistriesModified();
         m->pVirtualBox->i_saveModifiedRegistries();
@@ -1906,4 +1920,5 @@
     // save the settings
     mlock.release();
+    autoCaller.release();
     treeLock.release();
     i_markRegistriesModified();
@@ -2638,7 +2653,4 @@
                                   ComPtr<IProgress> &aProgress)
 {
-    /** @todo r=klaus The code below needs to be double checked with regard
-     * to lock order violations, it probably causes lock order issues related
-     * to the AutoCaller usage. */
     IMedium *aT = aTarget;
     ComObjPtr<Medium> diff = static_cast<Medium*>(aT);
@@ -2656,5 +2668,5 @@
     if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
-    AutoMultiWriteLock2 alock(this->lockHandle(), diff->lockHandle() COMMA_LOCKVAL_SRC_POS);
+    AutoMultiWriteLock2 alock(this, diff COMMA_LOCKVAL_SRC_POS);
 
     if (m->type == MediumType_Writethrough)
@@ -2674,4 +2686,5 @@
     MediumLockList *pMediumLockList(new MediumLockList());
     alock.release();
+    autoCaller.release();
     treeLock.release();
     HRESULT rc = diff->i_createMediumLockList(true /* fFailIfInaccessible */,
@@ -2681,4 +2694,7 @@
                                               *pMediumLockList);
     treeLock.acquire();
+    autoCaller.add();
+    if (FAILED(autoCaller.rc()))
+        rc = autoCaller.rc();
     alock.acquire();
     if (FAILED(rc))
@@ -2689,7 +2705,11 @@
 
     alock.release();
+    autoCaller.release();
     treeLock.release();
     rc = pMediumLockList->Lock();
     treeLock.acquire();
+    autoCaller.add();
+    if (FAILED(autoCaller.rc()))
+        rc = autoCaller.rc();
     alock.acquire();
     if (FAILED(rc))
@@ -2707,11 +2727,14 @@
         diff->m->llRegistryIDs.push_back(parentMachineRegistry);
         alock.release();
+        autoCaller.release();
         treeLock.release();
         diff->i_markRegistriesModified();
         treeLock.acquire();
+        autoCaller.add();
         alock.acquire();
     }
 
     alock.release();
+    autoCaller.release();
     treeLock.release();
 
@@ -2739,8 +2762,4 @@
                         ComPtr<IProgress> &aProgress)
 {
-
-    /** @todo r=klaus The code below needs to be double checked with regard
-     * to lock order violations, it probably causes lock order issues related
-     * to the AutoCaller usage. */
     IMedium *aT = aTarget;
 
@@ -2926,7 +2945,6 @@
 }
 
-HRESULT Medium::setLocation(const com::Utf8Str &aLocation, ComPtr<IProgress> &aProgress)
-{
-
+HRESULT Medium::setLocation(AutoCaller &autoCaller, const com::Utf8Str &aLocation, ComPtr<IProgress> &aProgress)
+{
     ComObjPtr<Medium> pParent;
     ComObjPtr<Progress> pProgress;
@@ -2945,13 +2963,14 @@
     /// this medium), this will also require to add the mRegistered flag to data
 
+        autoCaller.release();
+
         // locking: we need the tree lock first because we access parent pointers
         // and we need to write-lock the media involved
-        uint32_t    cHandles    = 2;
-        LockHandle* pHandles[2] = { &m->pVirtualBox->i_getMediaTreeLockHandle(),
-                                    this->lockHandle() };
-
-        AutoWriteLock alock(cHandles,
-                            pHandles
-                            COMMA_LOCKVAL_SRC_POS);
+        AutoWriteLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
+
+        autoCaller.add();
+        AssertComRCThrowRC(autoCaller.rc());
+
+        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
         /* play with locations */
@@ -3096,5 +3115,10 @@
 
             alock.release();
+            autoCaller.release();
+            treeLock.release();
             rc = m->pVirtualBox->i_findMachine(id, false, true, &aMachine);
+            treeLock.acquire();
+            autoCaller.add();
+            AssertComRCThrowRC(autoCaller.rc());
             alock.acquire();
 
@@ -3105,5 +3129,10 @@
 
                 alock.release();
+                autoCaller.release();
+                treeLock.release();
                 bool ses = aMachine->i_isSessionOpenVM(sm, &ctl);
+                treeLock.acquire();
+                autoCaller.add();
+                AssertComRCThrowRC(autoCaller.rc());
                 alock.acquire();
 
@@ -3123,4 +3152,6 @@
         MediumLockList *pMediumLockList(new MediumLockList());
         alock.release();
+        autoCaller.release();
+        treeLock.release();
         rc = i_createMediumLockList(true /* fFailIfInaccessible */,
                                     this /* pToLockWrite */,
@@ -3128,4 +3159,7 @@
                                     NULL,
                                     *pMediumLockList);
+        treeLock.acquire();
+        autoCaller.add();
+        AssertComRCThrowRC(autoCaller.rc());
         alock.acquire();
         if (FAILED(rc))
@@ -3137,5 +3171,10 @@
         }
         alock.release();
+        autoCaller.release();
+        treeLock.release();
         rc = pMediumLockList->Lock();
+        treeLock.acquire();
+        autoCaller.add();
+        AssertComRCThrowRC(autoCaller.rc());
         alock.acquire();
         if (FAILED(rc))
@@ -3551,5 +3590,5 @@
 }
 
-HRESULT Medium::getEncryptionSettings(com::Utf8Str &aCipher, com::Utf8Str &aPasswordId)
+HRESULT Medium::getEncryptionSettings(AutoCaller &autoCaller, com::Utf8Str &aCipher, com::Utf8Str &aPasswordId)
 {
 #ifndef VBOX_WITH_EXTPACK
@@ -3560,5 +3599,9 @@
     try
     {
+        autoCaller.release();
         ComObjPtr<Medium> pBase = i_getBase();
+        autoCaller.add();
+        if (FAILED(autoCaller.rc()))
+            throw rc;
         AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
@@ -4997,11 +5040,5 @@
                               bool aWait)
 {
-    /** @todo r=klaus The code below needs to be double checked with regard
-     * to lock order violations, it probably causes lock order issues related
-     * to the AutoCaller usage. */
     AssertReturn(aProgress != NULL || aWait == true, E_FAIL);
-
-    AutoCaller autoCaller(this);
-    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     HRESULT rc = S_OK;
@@ -5012,7 +5049,11 @@
     {
         /* we're accessing the media tree, and canClose() needs it too */
-        AutoMultiWriteLock2 multilock(&m->pVirtualBox->i_getMediaTreeLockHandle(),
-                                      this->lockHandle()
-                                      COMMA_LOCKVAL_SRC_POS);
+        AutoWriteLock treelock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
+
+        AutoCaller autoCaller(this);
+        AssertComRCThrowRC(autoCaller.rc());
+
+        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
+
         LogFlowThisFunc(("aWait=%RTbool locationFull=%s\n", aWait, i_getLocationFull().c_str() ));
 
@@ -5030,5 +5071,7 @@
             while (m->queryInfoRunning)
             {
-                multilock.release();
+                alock.release();
+                autoCaller.release();
+                treelock.release();
                 /* Must not hold the media tree lock or the object lock, as
                  * Medium::i_queryInfo needs this lock and thus we would run
@@ -5039,5 +5082,8 @@
                     AutoReadLock qlock(m->queryInfoSem COMMA_LOCKVAL_SRC_POS);
                 }
-                multilock.acquire();
+                treelock.acquire();
+                autoCaller.add();
+                AssertComRCThrowRC(autoCaller.rc());
+                alock.acquire();
             }
         }
@@ -5097,5 +5143,7 @@
         /* Build the medium lock list. */
         MediumLockList *pMediumLockList(new MediumLockList());
-        multilock.release();
+        alock.release();
+        autoCaller.release();
+        treelock.release();
         rc = i_createMediumLockList(true /* fFailIfInaccessible */,
                                     this /* pToLockWrite */,
@@ -5103,5 +5151,8 @@
                                     NULL,
                                     *pMediumLockList);
-        multilock.acquire();
+        treelock.acquire();
+        autoCaller.add();
+        AssertComRCThrowRC(autoCaller.rc());
+        alock.acquire();
         if (FAILED(rc))
         {
@@ -5110,7 +5161,12 @@
         }
 
-        multilock.release();
+        alock.release();
+        autoCaller.release();
+        treelock.release();
         rc = pMediumLockList->Lock();
-        multilock.acquire();
+        treelock.acquire();
+        autoCaller.add();
+        AssertComRCThrowRC(autoCaller.rc());
+        alock.acquire();
         if (FAILED(rc))
         {
@@ -5129,5 +5185,7 @@
             throw rc;
         // no longer need lock
-        multilock.release();
+        alock.release();
+        autoCaller.release();
+        treelock.release();
         i_markRegistriesModified();
 
@@ -5286,17 +5344,7 @@
                                                bool &fMergeForward)
 {
-    /** @todo r=klaus The code below needs to be double checked with regard
-     * to lock order violations, it probably causes lock order issues related
-     * to the AutoCaller usage. Likewise the code using this method seems
-     * problematic. */
     AssertReturn(pOther != NULL, E_FAIL);
     AssertReturn(pOther != this, E_FAIL);
 
-    AutoCaller autoCaller(this);
-    AssertComRCReturnRC(autoCaller.rc());
-
-    AutoCaller otherCaller(pOther);
-    AssertComRCReturnRC(otherCaller.rc());
-
     HRESULT rc = S_OK;
     bool fThisParent = false; /**<< Flag whether this medium is the parent of pOther. */
@@ -5306,4 +5354,10 @@
         // locking: we need the tree lock first because we access parent pointers
         AutoWriteLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
+
+        AutoCaller autoCaller(this);
+        AssertComRCThrowRC(autoCaller.rc());
+
+        AutoCaller otherCaller(pOther);
+        AssertComRCThrowRC(otherCaller.rc());
 
         /* more sanity checking and figuring out the current merge direction */
@@ -5415,16 +5469,6 @@
                                  MediumLockList * &aMediumLockList)
 {
-    /** @todo r=klaus The code below needs to be double checked with regard
-     * to lock order violations, it probably causes lock order issues related
-     * to the AutoCaller usage. Likewise the code using this method seems
-     * problematic. */
     AssertReturn(pTarget != NULL, E_FAIL);
     AssertReturn(pTarget != this, E_FAIL);
-
-    AutoCaller autoCaller(this);
-    AssertComRCReturnRC(autoCaller.rc());
-
-    AutoCaller targetCaller(pTarget);
-    AssertComRCReturnRC(targetCaller.rc());
 
     HRESULT rc = S_OK;
@@ -5441,4 +5485,10 @@
         AutoWriteLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
 
+        AutoCaller autoCaller(this);
+        AssertComRCThrowRC(autoCaller.rc());
+
+        AutoCaller targetCaller(pTarget);
+        AssertComRCThrowRC(targetCaller.rc());
+
         /* more sanity checking and figuring out the merge direction */
         ComObjPtr<Medium> pMedium = i_getParent();
@@ -5471,4 +5521,6 @@
         /* Build the lock list. */
         aMediumLockList = new MediumLockList();
+        targetCaller.release();
+        autoCaller.release();
         treeLock.release();
         if (fMergeForward)
@@ -5485,4 +5537,8 @@
                                         *aMediumLockList);
         treeLock.acquire();
+        autoCaller.add();
+        AssertComRCThrowRC(autoCaller.rc());
+        targetCaller.add();
+        AssertComRCThrowRC(targetCaller.rc());
         if (FAILED(rc))
             throw rc;
@@ -5627,7 +5683,13 @@
             if (fLockMedia && aChildrenToReparent)
             {
+                targetCaller.release();
+                autoCaller.release();
                 treeLock.release();
                 rc = aChildrenToReparent->Lock();
                 treeLock.acquire();
+                autoCaller.add();
+                AssertComRCThrowRC(autoCaller.rc());
+                targetCaller.add();
+                AssertComRCThrowRC(targetCaller.rc());
                 if (FAILED(rc))
                     throw rc;
@@ -5674,7 +5736,13 @@
         if (fLockMedia)
         {
+            targetCaller.release();
+            autoCaller.release();
             treeLock.release();
             rc = aMediumLockList->Lock();
             treeLock.acquire();
+            autoCaller.add();
+            AssertComRCThrowRC(autoCaller.rc());
+            targetCaller.add();
+            AssertComRCThrowRC(targetCaller.rc());
             if (FAILED(rc))
             {
@@ -5795,5 +5863,5 @@
 
     AutoCaller autoCaller(this);
-    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+    AssertComRCReturnRC(autoCaller.rc());
 
     AutoCaller targetCaller(pTarget);
