Message ID | 20201008174803.2696619-4-philmd@redhat.com |
---|---|
State | New |
Headers | show |
Series | migration: Make save/load_snapshot() return boolean | expand |
On 08.10.2020 20:48, Philippe Mathieu-Daudé wrote: > From: Daniel P. Berrangé <berrange@redhat.com> > > None of the callers care about the errno value since there is a full > Error object populated. This gives consistency with save_snapshot() > which already just returns a boolean value. > > Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> > [PMD: Return false/true instead of -1/0, document function] > Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> Acked-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> > --- > include/migration/snapshot.h | 9 ++++++++- > migration/savevm.c | 19 +++++++++---------- > monitor/hmp-cmds.c | 2 +- > replay/replay-snapshot.c | 2 +- > softmmu/vl.c | 2 +- > 5 files changed, 20 insertions(+), 14 deletions(-) > > diff --git a/include/migration/snapshot.h b/include/migration/snapshot.h > index a40c34307b..9bc989a6b4 100644 > --- a/include/migration/snapshot.h > +++ b/include/migration/snapshot.h > @@ -23,6 +23,13 @@ > * On failure, store an error through @errp and return %false. > */ > bool save_snapshot(const char *name, Error **errp); > -int load_snapshot(const char *name, Error **errp); > +/** > + * save_snapshot: Load a snapshot. > + * @name: path to snapshot > + * @errp: pointer to error object > + * On success, return %true. > + * On failure, store an error through @errp and return %false. > + */ > +bool load_snapshot(const char *name, Error **errp); > > #endif > diff --git a/migration/savevm.c b/migration/savevm.c > index fd2e5e8b66..531bb2eca1 100644 > --- a/migration/savevm.c > +++ b/migration/savevm.c > @@ -2864,7 +2864,7 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp) > migration_incoming_state_destroy(); > } > > -int load_snapshot(const char *name, Error **errp) > +bool load_snapshot(const char *name, Error **errp) > { > BlockDriverState *bs_vm_state; > QEMUSnapshotInfo sn; > @@ -2874,16 +2874,16 @@ int load_snapshot(const char *name, Error **errp) > MigrationIncomingState *mis = migration_incoming_get_current(); > > if (!bdrv_all_can_snapshot(errp)) { > - return -ENOTSUP; > + return false; > } > ret = bdrv_all_find_snapshot(name, errp); > if (ret < 0) { > - return ret; > + return false; > } > > bs_vm_state = bdrv_all_find_vmstate_bs(errp); > if (!bs_vm_state) { > - return -ENOTSUP; > + return false; > } > aio_context = bdrv_get_aio_context(bs_vm_state); > > @@ -2892,11 +2892,11 @@ int load_snapshot(const char *name, Error **errp) > ret = bdrv_snapshot_find(bs_vm_state, &sn, name); > aio_context_release(aio_context); > if (ret < 0) { > - return ret; > + return false; > } else if (sn.vm_state_size == 0) { > error_setg(errp, "This is a disk-only snapshot. Revert to it " > " offline using qemu-img"); > - return -EINVAL; > + return false; > } > > /* > @@ -2917,7 +2917,6 @@ int load_snapshot(const char *name, Error **errp) > f = qemu_fopen_bdrv(bs_vm_state, 0); > if (!f) { > error_setg(errp, "Could not open VM state file"); > - ret = -EINVAL; > goto err_drain; > } > > @@ -2933,14 +2932,14 @@ int load_snapshot(const char *name, Error **errp) > > if (ret < 0) { > error_setg(errp, "Error %d while loading VM state", ret); > - return ret; > + return false; > } > > - return 0; > + return true; > > err_drain: > bdrv_drain_all_end(); > - return ret; > + return false; > } > > void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev) > diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c > index 14848a3381..ff0e3df8a3 100644 > --- a/monitor/hmp-cmds.c > +++ b/monitor/hmp-cmds.c > @@ -1123,7 +1123,7 @@ void hmp_loadvm(Monitor *mon, const QDict *qdict) > > vm_stop(RUN_STATE_RESTORE_VM); > > - if (load_snapshot(name, &err) == 0 && saved_vm_running) { > + if (!load_snapshot(name, &err) && saved_vm_running) { > vm_start(); > } > hmp_handle_error(mon, err); > diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c > index 4f2560d156..b289365937 100644 > --- a/replay/replay-snapshot.c > +++ b/replay/replay-snapshot.c > @@ -83,7 +83,7 @@ void replay_vmstate_init(void) > exit(1); > } > } else if (replay_mode == REPLAY_MODE_PLAY) { > - if (load_snapshot(replay_snapshot, &err) != 0) { > + if (!load_snapshot(replay_snapshot, &err)) { > error_report_err(err); > error_report("Could not load snapshot for icount replay"); > exit(1); > diff --git a/softmmu/vl.c b/softmmu/vl.c > index 5a11a62f78..6eaa6b3a09 100644 > --- a/softmmu/vl.c > +++ b/softmmu/vl.c > @@ -4478,7 +4478,7 @@ void qemu_init(int argc, char **argv, char **envp) > register_global_state(); > if (loadvm) { > Error *local_err = NULL; > - if (load_snapshot(loadvm, &local_err) < 0) { > + if (!load_snapshot(loadvm, &local_err)) { > error_report_err(local_err); > autostart = 0; > exit(1); >
diff --git a/include/migration/snapshot.h b/include/migration/snapshot.h index a40c34307b..9bc989a6b4 100644 --- a/include/migration/snapshot.h +++ b/include/migration/snapshot.h @@ -23,6 +23,13 @@ * On failure, store an error through @errp and return %false. */ bool save_snapshot(const char *name, Error **errp); -int load_snapshot(const char *name, Error **errp); +/** + * save_snapshot: Load a snapshot. + * @name: path to snapshot + * @errp: pointer to error object + * On success, return %true. + * On failure, store an error through @errp and return %false. + */ +bool load_snapshot(const char *name, Error **errp); #endif diff --git a/migration/savevm.c b/migration/savevm.c index fd2e5e8b66..531bb2eca1 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2864,7 +2864,7 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp) migration_incoming_state_destroy(); } -int load_snapshot(const char *name, Error **errp) +bool load_snapshot(const char *name, Error **errp) { BlockDriverState *bs_vm_state; QEMUSnapshotInfo sn; @@ -2874,16 +2874,16 @@ int load_snapshot(const char *name, Error **errp) MigrationIncomingState *mis = migration_incoming_get_current(); if (!bdrv_all_can_snapshot(errp)) { - return -ENOTSUP; + return false; } ret = bdrv_all_find_snapshot(name, errp); if (ret < 0) { - return ret; + return false; } bs_vm_state = bdrv_all_find_vmstate_bs(errp); if (!bs_vm_state) { - return -ENOTSUP; + return false; } aio_context = bdrv_get_aio_context(bs_vm_state); @@ -2892,11 +2892,11 @@ int load_snapshot(const char *name, Error **errp) ret = bdrv_snapshot_find(bs_vm_state, &sn, name); aio_context_release(aio_context); if (ret < 0) { - return ret; + return false; } else if (sn.vm_state_size == 0) { error_setg(errp, "This is a disk-only snapshot. Revert to it " " offline using qemu-img"); - return -EINVAL; + return false; } /* @@ -2917,7 +2917,6 @@ int load_snapshot(const char *name, Error **errp) f = qemu_fopen_bdrv(bs_vm_state, 0); if (!f) { error_setg(errp, "Could not open VM state file"); - ret = -EINVAL; goto err_drain; } @@ -2933,14 +2932,14 @@ int load_snapshot(const char *name, Error **errp) if (ret < 0) { error_setg(errp, "Error %d while loading VM state", ret); - return ret; + return false; } - return 0; + return true; err_drain: bdrv_drain_all_end(); - return ret; + return false; } void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 14848a3381..ff0e3df8a3 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1123,7 +1123,7 @@ void hmp_loadvm(Monitor *mon, const QDict *qdict) vm_stop(RUN_STATE_RESTORE_VM); - if (load_snapshot(name, &err) == 0 && saved_vm_running) { + if (!load_snapshot(name, &err) && saved_vm_running) { vm_start(); } hmp_handle_error(mon, err); diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c index 4f2560d156..b289365937 100644 --- a/replay/replay-snapshot.c +++ b/replay/replay-snapshot.c @@ -83,7 +83,7 @@ void replay_vmstate_init(void) exit(1); } } else if (replay_mode == REPLAY_MODE_PLAY) { - if (load_snapshot(replay_snapshot, &err) != 0) { + if (!load_snapshot(replay_snapshot, &err)) { error_report_err(err); error_report("Could not load snapshot for icount replay"); exit(1); diff --git a/softmmu/vl.c b/softmmu/vl.c index 5a11a62f78..6eaa6b3a09 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -4478,7 +4478,7 @@ void qemu_init(int argc, char **argv, char **envp) register_global_state(); if (loadvm) { Error *local_err = NULL; - if (load_snapshot(loadvm, &local_err) < 0) { + if (!load_snapshot(loadvm, &local_err)) { error_report_err(local_err); autostart = 0; exit(1);