Improve savevm consistency by flushing pending AIO before saving. Index: qemu/vl.c =================================================================== --- qemu.orig/vl.c 2006-09-03 10:45:28.000000000 +0000 +++ qemu/vl.c 2006-09-03 11:06:13.000000000 +0000 @@ -4551,6 +4551,17 @@ return; } + /* Flush pending AIO before saving */ + ret = qemu_aio_poll(); + if (ret) { + qemu_aio_wait_start(); + do { + qemu_aio_wait(); + ret = qemu_aio_poll(); + } while (ret); + qemu_aio_wait_end(); + } + saved_vm_running = vm_running; vm_stop(0); Index: qemu/block-raw.c =================================================================== --- qemu.orig/block-raw.c 2006-09-03 11:00:39.000000000 +0000 +++ qemu/block-raw.c 2006-09-03 11:03:40.000000000 +0000 @@ -206,10 +206,12 @@ #endif } -void qemu_aio_poll(void) +int qemu_aio_poll(void) { RawAIOCB *acb, **pacb; - int ret; + int ret, aios_active; + + aios_active = 0; for(;;) { pacb = &first_aio; @@ -240,11 +242,14 @@ qemu_aio_release(acb); break; } else { + /* aio still active */ pacb = &acb->next; + aios_active = 1; } } } - the_end: ; + the_end: + return aios_active; } /* wait until at least one AIO was handled */ Index: qemu/vl.h =================================================================== --- qemu.orig/vl.h 2006-09-03 11:00:43.000000000 +0000 +++ qemu/vl.h 2006-09-03 11:04:10.000000000 +0000 @@ -579,7 +579,7 @@ void bdrv_aio_cancel(BlockDriverAIOCB *acb); void qemu_aio_init(void); -void qemu_aio_poll(void); +int qemu_aio_poll(void); void qemu_aio_wait_start(void); void qemu_aio_wait(void); void qemu_aio_wait_end(void);