migration: Pass Error ** argument to {save,load}_vmstate

This way we use the "normal" way of printing errors for hmp commands.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
This commit is contained in:
Juan Quintela 2017-04-18 18:12:35 +02:00
parent 2bf3aa85f0
commit 927d663819
5 changed files with 43 additions and 33 deletions

9
hmp.c
View File

@ -1274,17 +1274,22 @@ void hmp_loadvm(Monitor *mon, const QDict *qdict)
{ {
int saved_vm_running = runstate_is_running(); int saved_vm_running = runstate_is_running();
const char *name = qdict_get_str(qdict, "name"); const char *name = qdict_get_str(qdict, "name");
Error *err = NULL;
vm_stop(RUN_STATE_RESTORE_VM); vm_stop(RUN_STATE_RESTORE_VM);
if (load_vmstate(name) == 0 && saved_vm_running) { if (load_vmstate(name, &err) == 0 && saved_vm_running) {
vm_start(); vm_start();
} }
hmp_handle_error(mon, &err);
} }
void hmp_savevm(Monitor *mon, const QDict *qdict) void hmp_savevm(Monitor *mon, const QDict *qdict)
{ {
save_vmstate(qdict_get_try_str(qdict, "name")); Error *err = NULL;
save_vmstate(qdict_get_try_str(qdict, "name"), &err);
hmp_handle_error(mon, &err);
} }
void hmp_delvm(Monitor *mon, const QDict *qdict) void hmp_delvm(Monitor *mon, const QDict *qdict)

View File

@ -75,8 +75,8 @@ void qemu_remove_exit_notifier(Notifier *notify);
void qemu_add_machine_init_done_notifier(Notifier *notify); void qemu_add_machine_init_done_notifier(Notifier *notify);
void qemu_remove_machine_init_done_notifier(Notifier *notify); void qemu_remove_machine_init_done_notifier(Notifier *notify);
int save_vmstate(const char *name); int save_vmstate(const char *name, Error **errp);
int load_vmstate(const char *name); int load_vmstate(const char *name, Error **errp);
void qemu_announce_self(void); void qemu_announce_self(void);

View File

@ -2069,7 +2069,7 @@ int qemu_loadvm_state(QEMUFile *f)
return ret; return ret;
} }
int save_vmstate(const char *name) int save_vmstate(const char *name, Error **errp)
{ {
BlockDriverState *bs, *bs1; BlockDriverState *bs, *bs1;
QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1; QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
@ -2079,29 +2079,27 @@ int save_vmstate(const char *name)
uint64_t vm_state_size; uint64_t vm_state_size;
qemu_timeval tv; qemu_timeval tv;
struct tm tm; struct tm tm;
Error *local_err = NULL;
AioContext *aio_context; AioContext *aio_context;
if (!bdrv_all_can_snapshot(&bs)) { if (!bdrv_all_can_snapshot(&bs)) {
error_report("Device '%s' is writable but does not support snapshots", error_setg(errp, "Device '%s' is writable but does not support "
bdrv_get_device_name(bs)); "snapshots", bdrv_get_device_name(bs));
return ret; return ret;
} }
/* Delete old snapshots of the same name */ /* Delete old snapshots of the same name */
if (name) { if (name) {
ret = bdrv_all_delete_snapshot(name, &bs1, &local_err); ret = bdrv_all_delete_snapshot(name, &bs1, errp);
if (ret < 0) { if (ret < 0) {
error_reportf_err(local_err, error_prepend(errp, "Error while deleting snapshot on device "
"Error while deleting snapshot on device '%s': ", "'%s': ", bdrv_get_device_name(bs1));
bdrv_get_device_name(bs1));
return ret; return ret;
} }
} }
bs = bdrv_all_find_vmstate_bs(); bs = bdrv_all_find_vmstate_bs();
if (bs == NULL) { if (bs == NULL) {
error_report("No block device can accept snapshots"); error_setg(errp, "No block device can accept snapshots");
return ret; return ret;
} }
aio_context = bdrv_get_aio_context(bs); aio_context = bdrv_get_aio_context(bs);
@ -2110,7 +2108,7 @@ int save_vmstate(const char *name)
ret = global_state_store(); ret = global_state_store();
if (ret) { if (ret) {
error_report("Error saving global state"); error_setg(errp, "Error saving global state");
return ret; return ret;
} }
vm_stop(RUN_STATE_SAVE_VM); vm_stop(RUN_STATE_SAVE_VM);
@ -2142,21 +2140,20 @@ int save_vmstate(const char *name)
/* save the VM state */ /* save the VM state */
f = qemu_fopen_bdrv(bs, 1); f = qemu_fopen_bdrv(bs, 1);
if (!f) { if (!f) {
error_report("Could not open VM state file"); error_setg(errp, "Could not open VM state file");
goto the_end; goto the_end;
} }
ret = qemu_savevm_state(f, &local_err); ret = qemu_savevm_state(f, errp);
vm_state_size = qemu_ftell(f); vm_state_size = qemu_ftell(f);
qemu_fclose(f); qemu_fclose(f);
if (ret < 0) { if (ret < 0) {
error_report_err(local_err);
goto the_end; goto the_end;
} }
ret = bdrv_all_create_snapshot(sn, bs, vm_state_size, &bs); ret = bdrv_all_create_snapshot(sn, bs, vm_state_size, &bs);
if (ret < 0) { if (ret < 0) {
error_report("Error while creating snapshot on '%s'", error_setg(errp, "Error while creating snapshot on '%s'",
bdrv_get_device_name(bs)); bdrv_get_device_name(bs));
goto the_end; goto the_end;
} }
@ -2229,7 +2226,7 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp)
migration_incoming_state_destroy(); migration_incoming_state_destroy();
} }
int load_vmstate(const char *name) int load_vmstate(const char *name, Error **errp)
{ {
BlockDriverState *bs, *bs_vm_state; BlockDriverState *bs, *bs_vm_state;
QEMUSnapshotInfo sn; QEMUSnapshotInfo sn;
@ -2239,20 +2236,22 @@ int load_vmstate(const char *name)
MigrationIncomingState *mis = migration_incoming_get_current(); MigrationIncomingState *mis = migration_incoming_get_current();
if (!bdrv_all_can_snapshot(&bs)) { if (!bdrv_all_can_snapshot(&bs)) {
error_report("Device '%s' is writable but does not support snapshots", error_setg(errp,
bdrv_get_device_name(bs)); "Device '%s' is writable but does not support snapshots",
bdrv_get_device_name(bs));
return -ENOTSUP; return -ENOTSUP;
} }
ret = bdrv_all_find_snapshot(name, &bs); ret = bdrv_all_find_snapshot(name, &bs);
if (ret < 0) { if (ret < 0) {
error_report("Device '%s' does not have the requested snapshot '%s'", error_setg(errp,
bdrv_get_device_name(bs), name); "Device '%s' does not have the requested snapshot '%s'",
bdrv_get_device_name(bs), name);
return ret; return ret;
} }
bs_vm_state = bdrv_all_find_vmstate_bs(); bs_vm_state = bdrv_all_find_vmstate_bs();
if (!bs_vm_state) { if (!bs_vm_state) {
error_report("No block device supports snapshots"); error_setg(errp, "No block device supports snapshots");
return -ENOTSUP; return -ENOTSUP;
} }
aio_context = bdrv_get_aio_context(bs_vm_state); aio_context = bdrv_get_aio_context(bs_vm_state);
@ -2264,8 +2263,8 @@ int load_vmstate(const char *name)
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} else if (sn.vm_state_size == 0) { } else if (sn.vm_state_size == 0) {
error_report("This is a disk-only snapshot. Revert to it offline " error_setg(errp, "This is a disk-only snapshot. Revert to it "
"using qemu-img."); " offline using qemu-img");
return -EINVAL; return -EINVAL;
} }
@ -2274,7 +2273,7 @@ int load_vmstate(const char *name)
ret = bdrv_all_goto_snapshot(name, &bs); ret = bdrv_all_goto_snapshot(name, &bs);
if (ret < 0) { if (ret < 0) {
error_report("Error %d while activating snapshot '%s' on '%s'", error_setg(errp, "Error %d while activating snapshot '%s' on '%s'",
ret, name, bdrv_get_device_name(bs)); ret, name, bdrv_get_device_name(bs));
return ret; return ret;
} }
@ -2282,7 +2281,7 @@ int load_vmstate(const char *name)
/* restore the VM state */ /* restore the VM state */
f = qemu_fopen_bdrv(bs_vm_state, 0); f = qemu_fopen_bdrv(bs_vm_state, 0);
if (!f) { if (!f) {
error_report("Could not open VM state file"); error_setg(errp, "Could not open VM state file");
return -EINVAL; return -EINVAL;
} }
@ -2296,7 +2295,7 @@ int load_vmstate(const char *name)
migration_incoming_state_destroy(); migration_incoming_state_destroy();
if (ret < 0) { if (ret < 0) {
error_report("Error %d while loading VM state", ret); error_setg(errp, "Error %d while loading VM state", ret);
return ret; return ret;
} }

View File

@ -62,14 +62,18 @@ void replay_vmstate_register(void)
void replay_vmstate_init(void) void replay_vmstate_init(void)
{ {
Error *err = NULL;
if (replay_snapshot) { if (replay_snapshot) {
if (replay_mode == REPLAY_MODE_RECORD) { if (replay_mode == REPLAY_MODE_RECORD) {
if (save_vmstate(replay_snapshot) != 0) { if (save_vmstate(replay_snapshot, &err) != 0) {
error_report_err(err);
error_report("Could not create snapshot for icount record"); error_report("Could not create snapshot for icount record");
exit(1); exit(1);
} }
} else if (replay_mode == REPLAY_MODE_PLAY) { } else if (replay_mode == REPLAY_MODE_PLAY) {
if (load_vmstate(replay_snapshot) != 0) { if (load_vmstate(replay_snapshot, &err) != 0) {
error_report_err(err);
error_report("Could not load snapshot for icount replay"); error_report("Could not load snapshot for icount replay");
exit(1); exit(1);
} }

4
vl.c
View File

@ -4701,7 +4701,9 @@ int main(int argc, char **argv, char **envp)
if (replay_mode != REPLAY_MODE_NONE) { if (replay_mode != REPLAY_MODE_NONE) {
replay_vmstate_init(); replay_vmstate_init();
} else if (loadvm) { } else if (loadvm) {
if (load_vmstate(loadvm) < 0) { Error *local_err = NULL;
if (load_vmstate(loadvm, &local_err) < 0) {
error_report_err(local_err);
autostart = 0; autostart = 0;
} }
} }