Index: trunk/src/VBox/Devices/Storage/DrvVD.cpp
===================================================================
--- trunk/src/VBox/Devices/Storage/DrvVD.cpp	(revision 26146)
+++ trunk/src/VBox/Devices/Storage/DrvVD.cpp	(revision 26147)
@@ -353,5 +353,5 @@
 
     Assert(!pStorageBackend->fSyncIoPending);
-    pStorageBackend->fSyncIoPending = true;
+    ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
     DataSeg.cbSeg = cbRead;
     DataSeg.pvSeg = pvBuf;
@@ -361,7 +361,12 @@
         return rc;
 
-    /* Wait */
-    rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
-    AssertRC(rc);
+    if (rc == VINF_AIO_TASK_PENDING)
+    {
+        /* Wait */
+        rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
+        AssertRC(rc);
+    }
+    else
+        ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
 
     if (pcbRead)
@@ -380,5 +385,5 @@
 
     Assert(!pStorageBackend->fSyncIoPending);
-    pStorageBackend->fSyncIoPending = true;
+    ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
     DataSeg.cbSeg = cbWrite;
     DataSeg.pvSeg = (void *)pvBuf;
@@ -388,7 +393,12 @@
         return rc;
 
-    /* Wait */
-    rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
-    AssertRC(rc);
+    if (rc == VINF_AIO_TASK_PENDING)
+    {
+        /* Wait */
+        rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
+        AssertRC(rc);
+    }
+    else
+        ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
 
     if (pcbWritten)
@@ -405,5 +415,5 @@
 
     Assert(!pStorageBackend->fSyncIoPending);
-    pStorageBackend->fSyncIoPending = true;
+    ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, true);
 
     int rc = PDMR3AsyncCompletionEpFlush(pStorageBackend->pEndpoint, NULL, &pTask);
@@ -411,7 +421,12 @@
         return rc;
 
-    /* Wait */
-    rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
-    AssertRC(rc);
+    if (rc == VINF_AIO_TASK_PENDING)
+    {
+        /* Wait */
+        rc = RTSemEventWait(pStorageBackend->EventSem, RT_INDEFINITE_WAIT);
+        AssertRC(rc);
+    }
+    else
+        ASMAtomicXchgBool(&pStorageBackend->fSyncIoPending, false);
 
     return VINF_SUCCESS;
@@ -1104,5 +1119,5 @@
                 break;
             }
-            rc = CFGMR3QueryBoolDef(pCurNode, "UseNewIo", &fUseNewIo, false);
+            rc = CFGMR3QueryBoolDef(pCurNode, "UseNewIo", &fUseNewIo, true);
             if (RT_FAILURE(rc))
             {
@@ -1248,5 +1263,4 @@
         if (rc == VERR_NOT_SUPPORTED)
         {
-            /* Seems async I/O is not supported by the backend, open in normal mode. */
             pThis->fAsyncIOSupported = false;
             uOpenFlags &= ~VD_OPEN_FLAGS_ASYNC_IO;
Index: trunk/src/VBox/VMM/PDMAsyncCompletion.cpp
===================================================================
--- trunk/src/VBox/VMM/PDMAsyncCompletion.cpp	(revision 26146)
+++ trunk/src/VBox/VMM/PDMAsyncCompletion.cpp	(revision 26147)
@@ -545,34 +545,37 @@
 }
 
-void pdmR3AsyncCompletionCompleteTask(PPDMASYNCCOMPLETIONTASK pTask)
-{
-    LogFlow(("%s: pTask=%p\n", __FUNCTION__, pTask));
-
-    PPDMASYNCCOMPLETIONTEMPLATE pTemplate = pTask->pEndpoint->pTemplate;
-
-    switch (pTemplate->enmType)
-    {
-        case PDMASYNCCOMPLETIONTEMPLATETYPE_DEV:
-        {
-            pTemplate->u.Dev.pfnCompleted(pTemplate->u.Dev.pDevIns, pTask->pvUser);
-            break;
+void pdmR3AsyncCompletionCompleteTask(PPDMASYNCCOMPLETIONTASK pTask, bool fCallCompletionHandler)
+{
+    LogFlow(("%s: pTask=%#p fCallCompletionHandler=%RTbool\n", __FUNCTION__, pTask, fCallCompletionHandler));
+
+    if (fCallCompletionHandler)
+    {
+        PPDMASYNCCOMPLETIONTEMPLATE pTemplate = pTask->pEndpoint->pTemplate;
+
+        switch (pTemplate->enmType)
+        {
+            case PDMASYNCCOMPLETIONTEMPLATETYPE_DEV:
+            {
+                pTemplate->u.Dev.pfnCompleted(pTemplate->u.Dev.pDevIns, pTask->pvUser);
+                break;
+            }
+            case PDMASYNCCOMPLETIONTEMPLATETYPE_DRV:
+            {
+                pTemplate->u.Drv.pfnCompleted(pTemplate->u.Drv.pDrvIns, pTemplate->u.Drv.pvTemplateUser, pTask->pvUser);
+                break;
+            }
+            case PDMASYNCCOMPLETIONTEMPLATETYPE_USB:
+            {
+                pTemplate->u.Usb.pfnCompleted(pTemplate->u.Usb.pUsbIns, pTask->pvUser);
+                break;
+            }
+            case PDMASYNCCOMPLETIONTEMPLATETYPE_INTERNAL:
+            {
+                pTemplate->u.Int.pfnCompleted(pTemplate->pVM, pTask->pvUser, pTemplate->u.Int.pvUser);
+                break;
+            }
+            default:
+                AssertMsgFailed(("Unknown template type!\n"));
         }
-        case PDMASYNCCOMPLETIONTEMPLATETYPE_DRV:
-        {
-            pTemplate->u.Drv.pfnCompleted(pTemplate->u.Drv.pDrvIns, pTemplate->u.Drv.pvTemplateUser, pTask->pvUser);
-            break;
-        }
-        case PDMASYNCCOMPLETIONTEMPLATETYPE_USB:
-        {
-            pTemplate->u.Usb.pfnCompleted(pTemplate->u.Usb.pUsbIns, pTask->pvUser);
-            break;
-        }
-        case PDMASYNCCOMPLETIONTEMPLATETYPE_INTERNAL:
-        {
-            pTemplate->u.Int.pfnCompleted(pTemplate->pVM, pTask->pvUser, pTemplate->u.Int.pvUser);
-            break;
-        }
-        default:
-            AssertMsgFailed(("Unknown template type!\n"));
     }
 
Index: trunk/src/VBox/VMM/PDMAsyncCompletionFile.cpp
===================================================================
--- trunk/src/VBox/VMM/PDMAsyncCompletionFile.cpp	(revision 26146)
+++ trunk/src/VBox/VMM/PDMAsyncCompletionFile.cpp	(revision 26147)
@@ -26,4 +26,5 @@
 #define LOG_GROUP LOG_GROUP_PDM_ASYNC_COMPLETION
 #define RT_STRICT
+//#define DEBUG
 #include "PDMInternal.h"
 #include <VBox/pdm.h>
@@ -321,5 +322,5 @@
     if (pTask->enmTransferType == PDMACTASKFILETRANSFER_FLUSH)
     {
-        pdmR3AsyncCompletionCompleteTask(&pTaskFile->Core);
+        pdmR3AsyncCompletionCompleteTask(&pTaskFile->Core, true);
     }
     else
@@ -329,5 +330,5 @@
         if (!(uOld - pTask->DataSeg.cbSeg)
             && !ASMAtomicXchgBool(&pTaskFile->fCompleted, true))
-            pdmR3AsyncCompletionCompleteTask(&pTaskFile->Core);
+            pdmR3AsyncCompletionCompleteTask(&pTaskFile->Core, true);
     }
 }
@@ -372,7 +373,9 @@
     if (ASMAtomicReadS32(&pTaskFile->cbTransferLeft) == 0
         && !ASMAtomicXchgBool(&pTaskFile->fCompleted, true))
-        pdmR3AsyncCompletionCompleteTask(pTask);
-
-    return VINF_SUCCESS;
+        pdmR3AsyncCompletionCompleteTask(pTask, false);
+    else
+        rc = VINF_AIO_TASK_PENDING;
+
+    return rc;
 }
 
@@ -683,4 +686,10 @@
 
         rc = RTFileGetSize(pEpFile->File, (uint64_t *)&pEpFile->cbFile);
+        if (RT_SUCCESS(rc) && (pEpFile->cbFile == 0))
+        {
+            /* Could be a block device */
+            rc = RTFileSeek(pEpFile->File, 0, RTFILE_SEEK_END, (uint64_t *)&pEpFile->cbFile);
+        }
+
         if (RT_SUCCESS(rc))
         {
@@ -871,4 +880,5 @@
         pIoTask->pfnCompleted    = pdmacFileEpTaskCompleted;
         pdmacFileEpAddTask(pEpFile, pIoTask);
+        rc = VINF_AIO_TASK_PENDING;
     }
 
Index: trunk/src/VBox/VMM/PDMAsyncCompletionFileCache.cpp
===================================================================
--- trunk/src/VBox/VMM/PDMAsyncCompletionFileCache.cpp	(revision 26146)
+++ trunk/src/VBox/VMM/PDMAsyncCompletionFileCache.cpp	(revision 26147)
@@ -45,5 +45,4 @@
 *******************************************************************************/
 #define LOG_GROUP LOG_GROUP_PDM_ASYNC_COMPLETION
-#define RT_STRICT
 #include <iprt/types.h>
 #include <iprt/mem.h>
@@ -558,4 +557,5 @@
     pIoTask->pvUser          = pEntry;
     pIoTask->pfnCompleted    = pdmacFileCacheTaskCompleted;
+    ASMAtomicIncU32(&pEntry->pEndpoint->DataCache.cWritesOutstanding);
 
     /* Send it off to the I/O manager. */
@@ -579,17 +579,5 @@
     if (!(uOld - pTaskSeg->cbTransfer)
         && !ASMAtomicXchgBool(&pTaskSeg->pTask->fCompleted, true))
-    {
-        pdmR3AsyncCompletionCompleteTask(&pTaskSeg->pTask->Core);
-
-        if (pTaskSeg->fWrite)
-        {
-            /* Complete a pending flush if all writes have completed */
-            uint32_t cWritesOutstanding = ASMAtomicDecU32(&pEndpointCache->cWritesOutstanding);
-            PPDMASYNCCOMPLETIONTASKFILE pTaskFlush = (PPDMASYNCCOMPLETIONTASKFILE)ASMAtomicXchgPtr((void * volatile *)&pEndpointCache->pTaskFlush, NULL);
-
-            if (!cWritesOutstanding && pTaskFlush)
-                pdmR3AsyncCompletionCompleteTask(&pTaskFlush->Core);
-        }
-    }
+        pdmR3AsyncCompletionCompleteTask(&pTaskSeg->pTask->Core, true);
 
     RTMemFree(pTaskSeg);
@@ -629,4 +617,7 @@
     if (pTask->enmTransferType == PDMACTASKFILETRANSFER_WRITE)
     {
+        AssertMsg(pEndpointCache->cWritesOutstanding > 0, ("Completed write request but outstanding task count is 0\n"));
+        ASMAtomicDecU32(&pEndpointCache->cWritesOutstanding);
+
         if (pEntry->fFlags & PDMACFILECACHE_ENTRY_IS_DEPRECATED)
         {
@@ -674,4 +665,12 @@
     if (pEntry->fFlags & PDMACFILECACHE_ENTRY_IS_DIRTY)
         pdmacFileCacheWriteToEndpoint(pEntry);
+
+    /* Complete a pending flush if all writes have completed */
+    if (!ASMAtomicReadU32(&pEndpointCache->cWritesOutstanding))
+    {
+        PPDMASYNCCOMPLETIONTASKFILE pTaskFlush = (PPDMASYNCCOMPLETIONTASKFILE)ASMAtomicXchgPtr((void * volatile *)&pEndpointCache->pTaskFlush, NULL);
+        if (pTaskFlush)
+            pdmR3AsyncCompletionCompleteTask(&pTaskFlush->Core, true);
+    }
 
     RTSemRWReleaseWrite(pEndpoint->DataCache.SemRWEntries);
@@ -1497,5 +1496,9 @@
     if (ASMAtomicReadS32(&pTask->cbTransferLeft) == 0
         && !ASMAtomicXchgBool(&pTask->fCompleted, true))
-        pdmR3AsyncCompletionCompleteTask(&pTask->Core);
+        pdmR3AsyncCompletionCompleteTask(&pTask->Core, false);
+    else
+        rc = VINF_AIO_TASK_PENDING;
+
+    LogFlowFunc((": Leave rc=%Rrc\n", rc));
 
    return rc;
@@ -1528,5 +1531,4 @@
     /* Set to completed to make sure that the task is valid while we access it. */
     ASMAtomicWriteBool(&pTask->fCompleted, true);
-    ASMAtomicIncU32(&pEndpointCache->cWritesOutstanding);
 
     int iSegCurr       = 0;
@@ -1931,15 +1933,20 @@
         && !ASMAtomicXchgBool(&pTask->fCompleted, true))
     {
-        pdmR3AsyncCompletionCompleteTask(&pTask->Core);
+        pdmR3AsyncCompletionCompleteTask(&pTask->Core, false);
 
         /* Complete a pending flush if all writes have completed */
-        uint32_t cWritesOutstanding = ASMAtomicDecU32(&pEndpointCache->cWritesOutstanding);
-        PPDMASYNCCOMPLETIONTASKFILE pTaskFlush = (PPDMASYNCCOMPLETIONTASKFILE)ASMAtomicXchgPtr((void * volatile *)&pEndpointCache->pTaskFlush, NULL);
-
-        if (!cWritesOutstanding && pTaskFlush)
-            pdmR3AsyncCompletionCompleteTask(&pTaskFlush->Core);
-    }
-
-    return VINF_SUCCESS;
+        if (!ASMAtomicReadU32(&pEndpointCache->cWritesOutstanding))
+        {
+            PPDMASYNCCOMPLETIONTASKFILE pTaskFlush = (PPDMASYNCCOMPLETIONTASKFILE)ASMAtomicXchgPtr((void * volatile *)&pEndpointCache->pTaskFlush, NULL);
+            if (pTaskFlush)
+                pdmR3AsyncCompletionCompleteTask(&pTaskFlush->Core, true);
+        }
+    }
+    else
+        rc = VINF_AIO_TASK_PENDING;
+
+    LogFlowFunc((": Leave rc=%Rrc\n", rc));
+
+    return rc;
 }
 
@@ -1949,4 +1956,7 @@
 {
     int rc = VINF_SUCCESS;
+
+    LogFlowFunc((": pEndpoint=%#p{%s} pTask=%#p\n",
+                 pEndpoint, pEndpoint->Core.pszUri, pTask));
 
     if (ASMAtomicReadPtr((void * volatile *)&pEndpoint->DataCache.pTaskFlush))
@@ -1955,9 +1965,13 @@
     {
         if (ASMAtomicReadU32(&pEndpoint->DataCache.cWritesOutstanding) > 0)
+        {
             ASMAtomicWritePtr((void * volatile *)&pEndpoint->DataCache.pTaskFlush, pTask);
+            rc = VINF_AIO_TASK_PENDING;
+        }
         else
-            pdmR3AsyncCompletionCompleteTask(&pTask->Core);
-    }
-
+            pdmR3AsyncCompletionCompleteTask(&pTask->Core, false);
+    }
+
+    LogFlowFunc((": Leave rc=%Rrc\n", rc));
     return rc;
 }
Index: trunk/src/VBox/VMM/PDMAsyncCompletionFileFailsafe.cpp
===================================================================
--- trunk/src/VBox/VMM/PDMAsyncCompletionFileFailsafe.cpp	(revision 26146)
+++ trunk/src/VBox/VMM/PDMAsyncCompletionFileFailsafe.cpp	(revision 26147)
@@ -21,5 +21,4 @@
  */
 #define LOG_GROUP LOG_GROUP_PDM_ASYNC_COMPLETION
-#define RT_STRICT
 #include <iprt/types.h>
 #include <iprt/assert.h>
Index: trunk/src/VBox/VMM/PDMAsyncCompletionFileNormal.cpp
===================================================================
--- trunk/src/VBox/VMM/PDMAsyncCompletionFileNormal.cpp	(revision 26146)
+++ trunk/src/VBox/VMM/PDMAsyncCompletionFileNormal.cpp	(revision 26147)
@@ -21,5 +21,4 @@
  */
 #define LOG_GROUP LOG_GROUP_PDM_ASYNC_COMPLETION
-#define RT_STRICT
 #include <iprt/types.h>
 #include <iprt/asm.h>
Index: trunk/src/VBox/VMM/PDMAsyncCompletionInternal.h
===================================================================
--- trunk/src/VBox/VMM/PDMAsyncCompletionInternal.h	(revision 26146)
+++ trunk/src/VBox/VMM/PDMAsyncCompletionInternal.h	(revision 26147)
@@ -269,7 +269,9 @@
  *
  * @returns nothing
- * @param   pTask    Pointer to the finished task.
- */
-void pdmR3AsyncCompletionCompleteTask(PPDMASYNCCOMPLETIONTASK pTask);
+ * @param   pTask                     Pointer to the finished task.
+ * @param   fCallCompletionHandler    Flag whether the completion handler should be called to
+ *                                    inform the owner of the task that it has completed.
+ */
+void pdmR3AsyncCompletionCompleteTask(PPDMASYNCCOMPLETIONTASK pTask, bool fCallCompletionHandler);
 
 RT_C_DECLS_END
