make load_vmstate() return errors

Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Juan Quintela 2009-08-20 19:42:22 +02:00 committed by Anthony Liguori
parent c8d41b2c29
commit 05f2401eb2
4 changed files with 14 additions and 10 deletions

View File

@ -1727,8 +1727,7 @@ static void do_loadvm(Monitor *mon, const char *name)
vm_stop(0); vm_stop(0);
load_vmstate(mon, name); if (load_vmstate(mon, name) >= 0 && saved_vm_running)
if (saved_vm_running)
vm_start(); vm_start();
} }

View File

@ -1174,7 +1174,7 @@ void do_savevm(Monitor *mon, const char *name)
vm_start(); vm_start();
} }
void load_vmstate(Monitor *mon, const char *name) int load_vmstate(Monitor *mon, const char *name)
{ {
DriveInfo *dinfo; DriveInfo *dinfo;
BlockDriverState *bs, *bs1; BlockDriverState *bs, *bs1;
@ -1185,7 +1185,7 @@ void load_vmstate(Monitor *mon, const char *name)
bs = get_bs_snapshots(); bs = get_bs_snapshots();
if (!bs) { if (!bs) {
monitor_printf(mon, "No block device supports snapshots\n"); 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. */ /* 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 */ /* fatal on snapshot block device */
if (bs == bs1) 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 */ /* Don't even try to load empty VM states */
ret = bdrv_snapshot_find(bs, &sn, name); ret = bdrv_snapshot_find(bs, &sn, name);
if ((ret >= 0) && (sn.vm_state_size == 0)) if ((ret >= 0) && (sn.vm_state_size == 0))
return; return -EINVAL;
/* restore the VM state */ /* restore the VM state */
f = qemu_fopen_bdrv(bs, 0); f = qemu_fopen_bdrv(bs, 0);
if (!f) { if (!f) {
monitor_printf(mon, "Could not open VM state file\n"); monitor_printf(mon, "Could not open VM state file\n");
return; return -EINVAL;
} }
ret = qemu_loadvm_state(f); ret = qemu_loadvm_state(f);
qemu_fclose(f); qemu_fclose(f);
if (ret < 0) { if (ret < 0) {
monitor_printf(mon, "Error %d while loading VM state\n", ret); monitor_printf(mon, "Error %d while loading VM state\n", ret);
return ret;
} }
return 0;
} }
void do_delvm(Monitor *mon, const char *name) void do_delvm(Monitor *mon, const char *name)

View File

@ -51,7 +51,7 @@ extern qemu_irq qemu_system_powerdown;
void qemu_system_reset(void); void qemu_system_reset(void);
void do_savevm(Monitor *mon, const char *name); 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_delvm(Monitor *mon, const char *name);
void do_info_snapshots(Monitor *mon); void do_info_snapshots(Monitor *mon);

7
vl.c
View File

@ -6030,8 +6030,11 @@ int main(int argc, char **argv, char **envp)
exit(1); exit(1);
} }
if (loadvm) if (loadvm) {
load_vmstate(cur_mon, loadvm); if (load_vmstate(cur_mon, loadvm) < 0) {
autostart = 0;
}
}
if (incoming) { if (incoming) {
qemu_start_incoming_migration(incoming); qemu_start_incoming_migration(incoming);