]> git.proxmox.com Git - mirror_qemu.git/blobdiff - block/block-backend.c
block: fix QEMU crash with scsi-hd and drive_del
[mirror_qemu.git] / block / block-backend.c
index 2d1a3463e84b1e5a21e6760463036de7aff98b9d..6b75bca31760ee3b1e0cbefcdac1cd5dae51a231 100644 (file)
@@ -767,6 +767,11 @@ void blk_remove_bs(BlockBackend *blk)
 
     blk_update_root_state(blk);
 
+    /* bdrv_root_unref_child() will cause blk->root to become stale and may
+     * switch to a completion coroutine later on. Let's drain all I/O here
+     * to avoid that and a potential QEMU crash.
+     */
+    blk_drain(blk);
     bdrv_root_unref_child(blk->root);
     blk->root = NULL;
 }