Index: /trunk/src/VBox/Main/MediumImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/MediumImpl.cpp	(revision 24690)
+++ /trunk/src/VBox/Main/MediumImpl.cpp	(revision 24691)
@@ -614,5 +614,5 @@
  */
 class Medium::ImageChain : public Medium::List,
-                             public com::SupportErrorInfoBase
+                           public com::SupportErrorInfoBase
 {
 public:
@@ -671,25 +671,22 @@
         {
             HRESULT rc = S_OK;
-            MediumState_T mediaState;
-            rc = (*it)->LockRead(&mediaState);
-            CheckComRCReturnRC(rc);
-
-            if (mediaState == MediumState_Inaccessible)
+            MediumState_T mediumState = (*it)->state();
+
+            /* accessibility check must be first, otherwise locking
+             * interferes with getting the medium state. */
+            if (mediumState == MediumState_Inaccessible)
             {
-                rc = (*it)->RefreshState(&mediaState);
+                rc = (*it)->RefreshState(&mediumState);
                 CheckComRCReturnRC(rc);
-                Assert(mediaState == MediumState_LockedRead);
-
-                /* Note that we locked the medium already, so use the error
-                 * value to see if there was an accessibility failure */
-                Bstr error;
-                rc = (*it)->COMGETTER(LastAccessError)(error.asOutParam());
-                CheckComRCReturnRC(rc);
-
-                if (!error.isEmpty())
+
+                if (mediumState == MediumState_Inaccessible)
                 {
+                    Bstr error;
+                    rc = (*it)->COMGETTER(LastAccessError)(error.asOutParam());
+                    CheckComRCReturnRC(rc);
+
                     Bstr loc;
                     rc = (*it)->COMGETTER(Location)(loc.asOutParam());
-                    CheckComRCThrowRC(rc);
+                    CheckComRCReturnRC(rc);
 
                     /* collect multiple errors */
@@ -705,4 +702,7 @@
                 }
             }
+
+            rc = (*it)->LockRead(&mediumState);
+            CheckComRCReturnRC(rc);
         }
 
@@ -725,31 +725,22 @@
         {
             HRESULT rc = S_OK;
-            MediumState_T mediaState;
-            if (it == last)
-                rc = (*it)->LockWrite(&mediaState);
-            else
-                rc = (*it)->LockRead(&mediaState);
-            CheckComRCReturnRC(rc);
-
-            if (mediaState == MediumState_Inaccessible)
+            MediumState_T mediumState = (*it)->state();
+
+            /* accessibility check must be first, otherwise locking
+             * interferes with getting the medium state. */
+            if (mediumState == MediumState_Inaccessible)
             {
-                rc = (*it)->RefreshState(&mediaState);
+                rc = (*it)->RefreshState(&mediumState);
                 CheckComRCReturnRC(rc);
-                if (it == last)
-                    Assert(mediaState == MediumState_LockedWrite);
-                else
-                    Assert(mediaState == MediumState_LockedRead);
-
-                /* Note that we locked the medium already, so use the error
-                 * value to see if there was an accessibility failure */
-                Bstr error;
-                rc = (*it)->COMGETTER(LastAccessError)(error.asOutParam());
-                CheckComRCReturnRC(rc);
-
-                if (!error.isEmpty())
+
+                if (mediumState == MediumState_Inaccessible)
                 {
+                    Bstr error;
+                    rc = (*it)->COMGETTER(LastAccessError)(error.asOutParam());
+                    CheckComRCReturnRC(rc);
+
                     Bstr loc;
                     rc = (*it)->COMGETTER(Location)(loc.asOutParam());
-                    CheckComRCThrowRC(rc);
+                    CheckComRCReturnRC(rc);
 
                     /* collect multiple errors */
@@ -765,4 +756,9 @@
                 }
             }
+
+            if (it == last)
+                rc = (*it)->LockWrite(&mediumState);
+            else
+                rc = (*it)->LockRead(&mediumState);
         }
 
