diff --git a/monitor.c b/monitor.c index 57ce68b6d13e9243b93a3c6c8ea4ef3201b235e3..ae0fdaa3482573ced6cc59a5e5b802238671a880 100644 --- a/monitor.c +++ b/monitor.c @@ -1727,8 +1727,7 @@ static void do_loadvm(Monitor *mon, const char *name) vm_stop(0); - load_vmstate(mon, name); - if (saved_vm_running) + if (load_vmstate(mon, name) >= 0 && saved_vm_running) vm_start(); } diff --git a/savevm.c b/savevm.c index f14487cad265bfe020abc8a8f209fb1647a633d5..f273cb98bd4e61caa6de7a86a6631741edbd1ef0 100644 --- a/savevm.c +++ b/savevm.c @@ -1174,7 +1174,7 @@ void do_savevm(Monitor *mon, const char *name) vm_start(); } -void load_vmstate(Monitor *mon, const char *name) +int load_vmstate(Monitor *mon, const char *name) { DriveInfo *dinfo; BlockDriverState *bs, *bs1; @@ -1185,7 +1185,7 @@ void load_vmstate(Monitor *mon, const char *name) bs = get_bs_snapshots(); if (!bs) { monitor_printf(mon, "No block device supports snapshots\n"); - return; + return -EINVAL; } /* Flush all IO requests so they don't interfere with the new state. */ @@ -1216,7 +1216,7 @@ void load_vmstate(Monitor *mon, const char *name) } /* fatal on snapshot block device */ if (bs == bs1) - return; + return 0; } } } @@ -1224,19 +1224,21 @@ void load_vmstate(Monitor *mon, const char *name) /* Don't even try to load empty VM states */ ret = bdrv_snapshot_find(bs, &sn, name); if ((ret >= 0) && (sn.vm_state_size == 0)) - return; + return -EINVAL; /* restore the VM state */ f = qemu_fopen_bdrv(bs, 0); if (!f) { monitor_printf(mon, "Could not open VM state file\n"); - return; + return -EINVAL; } ret = qemu_loadvm_state(f); qemu_fclose(f); if (ret < 0) { monitor_printf(mon, "Error %d while loading VM state\n", ret); + return ret; } + return 0; } void do_delvm(Monitor *mon, const char *name) diff --git a/sysemu.h b/sysemu.h index cabe79d36b8ff5dc5de4f72da0da110fb36330d1..18fa0727c16e932f6aee5c2a5c01dd58e9d3c58b 100644 --- a/sysemu.h +++ b/sysemu.h @@ -51,7 +51,7 @@ extern qemu_irq qemu_system_powerdown; void qemu_system_reset(void); void do_savevm(Monitor *mon, const char *name); -void load_vmstate(Monitor *mon, const char *name); +int load_vmstate(Monitor *mon, const char *name); void do_delvm(Monitor *mon, const char *name); void do_info_snapshots(Monitor *mon); diff --git a/vl.c b/vl.c index 95ed5110611803bbe098364d95d736e6765150fe..9b2bf00a725400a311e37a56db0429b180c0616c 100644 --- a/vl.c +++ b/vl.c @@ -6030,8 +6030,11 @@ int main(int argc, char **argv, char **envp) exit(1); } - if (loadvm) - load_vmstate(cur_mon, loadvm); + if (loadvm) { + if (load_vmstate(cur_mon, loadvm) < 0) { + autostart = 0; + } + } if (incoming) { qemu_start_incoming_migration(incoming);