Index: /trunk/src/VBox/Main/src-server/MachineImplCloneVM.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/MachineImplCloneVM.cpp	(revision 56576)
+++ /trunk/src/VBox/Main/src-server/MachineImplCloneVM.cpp	(revision 56577)
@@ -46,4 +46,5 @@
 {
     RTCList<MEDIUMTASK>     chain;
+    DeviceType_T            devType;
     bool                    fCreateDiffs;
     bool                    fAttachLinked;
@@ -270,6 +271,7 @@
             if (FAILED(rc)) return rc;
 
-            /* Only harddisk's are of interest. */
-            if (type != DeviceType_HardDisk)
+            /* Only harddisks and floppies are of interest. */
+            if (   type != DeviceType_HardDisk
+                && type != DeviceType_Floppy)
                 continue;
 
@@ -278,4 +280,5 @@
             rc = pAtt->COMGETTER(Medium)(pSrcMedium.asOutParam());
             if (FAILED(rc)) return rc;
+
             if (pSrcMedium.isNull())
                 continue;
@@ -284,4 +287,5 @@
              * contain one image only. */
             MEDIUMTASKCHAIN mtc;
+            mtc.devType       = type;
             mtc.fCreateDiffs  = fCreateDiffs;
             mtc.fAttachLinked = fAttachLinked;
@@ -377,6 +381,7 @@
             if (FAILED(rc)) return rc;
 
-            /* Only harddisk's are of interest. */
-            if (type != DeviceType_HardDisk)
+            /* Only harddisks and floppies are of interest. */
+            if (   type != DeviceType_HardDisk
+                && type != DeviceType_Floppy)
                 continue;
 
@@ -390,4 +395,5 @@
 
             MEDIUMTASKCHAIN mtc;
+            mtc.devType       = type;
             mtc.fCreateDiffs  = fCreateDiffs;
             mtc.fAttachLinked = fAttachLinked;
@@ -520,6 +526,7 @@
             if (FAILED(rc)) return rc;
 
-            /* Only harddisk's are of interest. */
-            if (type != DeviceType_HardDisk)
+            /* Only harddisks and floppies are of interest. */
+            if (   type != DeviceType_HardDisk
+                && type != DeviceType_Floppy)
                 continue;
 
@@ -528,4 +535,5 @@
             rc = pAtt->COMGETTER(Medium)(pSrcMedium.asOutParam());
             if (FAILED(rc)) return rc;
+
             if (pSrcMedium.isNull())
                 continue;
@@ -535,4 +543,5 @@
              * will not create a full copy of the base/child relationship.) */
             MEDIUMTASKCHAIN mtc;
+            mtc.devType       = type;
             mtc.fCreateDiffs  = fCreateDiffs;
             mtc.fAttachLinked = fAttachLinked;
@@ -646,5 +655,6 @@
              ++it4)
         {
-            if (   it4->deviceType == DeviceType_HardDisk
+            if (   (   it4->deviceType == DeviceType_HardDisk
+                    || it4->deviceType == DeviceType_Floppy)
                 && it4->uuid == bstrOldId)
             {
@@ -996,4 +1006,6 @@
         /* Reset media registry. */
         trgMCF.mediaRegistry.llHardDisks.clear();
+        trgMCF.mediaRegistry.llDvdImages.clear();
+        trgMCF.mediaRegistry.llFloppyImages.clear();
         /* If we got a valid snapshot id, replace the hardware/storage section
          * with the stuff from the snapshot. */
@@ -1147,5 +1159,9 @@
                         /* Default format? */
                         Utf8Str strDefaultFormat;
-                        p->mParent->i_getDefaultHardDiskFormat(strDefaultFormat);
+                        if (mtc.devType == DeviceType_HardDisk)
+                            p->mParent->i_getDefaultHardDiskFormat(strDefaultFormat);
+                        else
+                            strDefaultFormat = "RAW";
+
                         Bstr bstrSrcFormat(strDefaultFormat);
 
@@ -1225,5 +1241,5 @@
                                            strFile,
                                            Guid::Empty /* empty media registry */,
-                                           DeviceType_HardDisk);
+                                           mtc.devType);
                         if (FAILED(rc)) throw rc;
 
@@ -1231,9 +1247,9 @@
                         pTarget->i_updateId(newId);
 
-                        srcLock.release();
                         /* Do the disk cloning. */
                         ComPtr<IProgress> progress2;
 
                         ComObjPtr<Medium> pLMedium = static_cast<Medium*>((IMedium*)pMedium);
+                        srcLock.release();
                         rc = pLMedium->i_cloneToEx(pTarget,
                                                    srcVar,
@@ -1242,7 +1258,9 @@
                                                    uSrcParentIdx,
                                                    uTrgParentIdx);
+                        srcLock.acquire();
                         if (FAILED(rc)) throw rc;
 
                         /* Wait until the async process has finished. */
+                        srcLock.release();
                         rc = d->pProgress->WaitForAsyncProgressCompletion(progress2);
                         srcLock.acquire();
@@ -1264,12 +1282,16 @@
                         rc = pMedium->COMGETTER(Type)(&type);
                         if (FAILED(rc)) throw rc;
+                        trgLock.release();
+                        srcLock.release();
                         rc = pTarget->COMSETTER(Type)(type);
+                        srcLock.acquire();
+                        trgLock.acquire();
                         if (FAILED(rc)) throw rc;
                         map.insert(TStrMediumPair(Utf8Str(bstrSrcId), pTarget));
-                        /* register the new harddisk */
+                        /* register the new medium */
                         {
                             AutoWriteLock tlock(p->mParent->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
                             rc = p->mParent->i_registerMedium(pTarget, &pTarget,
-                                                            tlock);
+                                                              tlock);
                             if (FAILED(rc)) throw rc;
                         }
@@ -1463,4 +1485,7 @@
     catch (HRESULT rc2)
     {
+        /* Error handling code only works correctly without locks held. */
+        trgLock.release();
+        srcLock.release();
         rc = rc2;
     }
@@ -1488,5 +1513,5 @@
             const ComObjPtr<Medium> &pMedium = newMedia.at(i - 1);
             mrc = pMedium->i_deleteStorage(NULL /* aProgress */,
-                                         true /* aWait */);
+                                           true /* aWait */);
             pMedium->Close();
         }
