diff --git a/block-raw.c b/block-raw.c index 3ed4b32de08d18777b3d8a5e1fe95090efc729e2..3a2843c5d66119dd1a9decfb0f8c1910a4601054 100644 --- a/block-raw.c +++ b/block-raw.c @@ -247,6 +247,17 @@ void qemu_aio_poll(void) the_end: ; } +/* Wait for all IO requests to complete. */ +void qemu_aio_flush(void) +{ + qemu_aio_wait_start(); + qemu_aio_poll(); + while (first_aio) { + qemu_aio_wait(); + } + qemu_aio_wait_end(); +} + /* wait until at least one AIO was handled */ static sigset_t wait_oset; diff --git a/vl.c b/vl.c index 771903099315a7fa52a25ac77d6e5c0a279089ec..32c994366cac8227d4349ad99bd9f23476cecc11 100644 --- a/vl.c +++ b/vl.c @@ -4551,6 +4551,9 @@ void do_savevm(const char *name) return; } + /* ??? Should this occur after vm_stop? */ + qemu_aio_flush(); + saved_vm_running = vm_running; vm_stop(0); @@ -4641,6 +4644,9 @@ void do_loadvm(const char *name) return; } + /* Flush all IO requests so they don't interfere with the new state. */ + qemu_aio_flush(); + saved_vm_running = vm_running; vm_stop(0); diff --git a/vl.h b/vl.h index bd1e6673f4d62e736897c5d12389dcfc2ac9f6a1..14116fa75077566df61474d4f45b7731a7726b2b 100644 --- a/vl.h +++ b/vl.h @@ -580,6 +580,7 @@ void bdrv_aio_cancel(BlockDriverAIOCB *acb); void qemu_aio_init(void); void qemu_aio_poll(void); +void qemu_aio_flush(void); void qemu_aio_wait_start(void); void qemu_aio_wait(void); void qemu_aio_wait_end(void);