[1/2] save_vmstate: Convert to Error** from Monitor *

Submitted by Dave Gilbert on March 20, 2017, 5:38 p.m.

Details

Message ID 20170320173840.3626-2-dgilbert@redhat.com
State New
Headers show

Commit Message

Dave Gilbert March 20, 2017, 5:38 p.m.
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

A bit more consistent and it removes one of the less necessary uses
of cur_mon.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 include/sysemu/sysemu.h  |  2 +-
 migration/savevm.c       | 31 ++++++++++++++++++-------------
 replay/replay-snapshot.c |  6 ++++--
 3 files changed, 23 insertions(+), 16 deletions(-)

Comments

Juan Quintela March 20, 2017, 6:05 p.m.
"Dr. David Alan Gilbert (git)" <dgilbert@redhat.com> wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>
> A bit more consistent and it removes one of the less necessary uses
> of cur_mon.
>
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>


> @@ -2094,16 +2094,17 @@ int save_vmstate(Monitor *mon, const char *name)
>      if (name) {
>          ret = bdrv_all_delete_snapshot(name, &bs1, &local_err);
>          if (ret < 0) {
> -            error_reportf_err(local_err,
> -                              "Error while deleting snapshot on device '%s': ",
> -                              bdrv_get_device_name(bs1));
> +            error_propagate(errp, local_err);
> +            error_prepend(errp,
> +                          "Error while deleting snapshot on device '%s': ",
> +                          bdrv_get_device_name(bs1));

This is just magic O:-)

Patch hide | download patch | download mbox

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 576c7ce..26e1a7e 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -76,7 +76,7 @@  void qemu_add_machine_init_done_notifier(Notifier *notify);
 void qemu_remove_machine_init_done_notifier(Notifier *notify);
 
 void hmp_savevm(Monitor *mon, const QDict *qdict);
-int save_vmstate(Monitor *mon, const char *name);
+int save_vmstate(const char *name, Error **errp);
 int load_vmstate(const char *name);
 void hmp_delvm(Monitor *mon, const QDict *qdict);
 void hmp_info_snapshots(Monitor *mon, const QDict *qdict);
diff --git a/migration/savevm.c b/migration/savevm.c
index 3b19a4a..361a926 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2071,7 +2071,7 @@  int qemu_loadvm_state(QEMUFile *f)
     return ret;
 }
 
-int save_vmstate(Monitor *mon, const char *name)
+int save_vmstate(const char *name, Error **errp)
 {
     BlockDriverState *bs, *bs1;
     QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
@@ -2085,8 +2085,8 @@  int save_vmstate(Monitor *mon, const char *name)
     AioContext *aio_context;
 
     if (!bdrv_all_can_snapshot(&bs)) {
-        monitor_printf(mon, "Device '%s' is writable but does not "
-                       "support snapshots.\n", bdrv_get_device_name(bs));
+        error_setg(errp, "Device '%s' is writable but does not "
+                   "support snapshots", bdrv_get_device_name(bs));
         return ret;
     }
 
@@ -2094,16 +2094,17 @@  int save_vmstate(Monitor *mon, const char *name)
     if (name) {
         ret = bdrv_all_delete_snapshot(name, &bs1, &local_err);
         if (ret < 0) {
-            error_reportf_err(local_err,
-                              "Error while deleting snapshot on device '%s': ",
-                              bdrv_get_device_name(bs1));
+            error_propagate(errp, local_err);
+            error_prepend(errp,
+                          "Error while deleting snapshot on device '%s': ",
+                          bdrv_get_device_name(bs1));
             return ret;
         }
     }
 
     bs = bdrv_all_find_vmstate_bs();
     if (bs == NULL) {
-        monitor_printf(mon, "No block device can accept snapshots\n");
+        error_setg(errp, "No block device can accept snapshots");
         return ret;
     }
     aio_context = bdrv_get_aio_context(bs);
@@ -2112,7 +2113,7 @@  int save_vmstate(Monitor *mon, const char *name)
 
     ret = global_state_store();
     if (ret) {
-        monitor_printf(mon, "Error saving global state\n");
+        error_setg(errp, "Error saving global state");
         return ret;
     }
     vm_stop(RUN_STATE_SAVE_VM);
@@ -2144,21 +2145,21 @@  int save_vmstate(Monitor *mon, const char *name)
     /* save the VM state */
     f = qemu_fopen_bdrv(bs, 1);
     if (!f) {
-        monitor_printf(mon, "Could not open VM state file\n");
+        error_setg(errp, "Could not open VM state file");
         goto the_end;
     }
     ret = qemu_savevm_state(f, &local_err);
     vm_state_size = qemu_ftell(f);
     qemu_fclose(f);
     if (ret < 0) {
-        error_report_err(local_err);
+        error_propagate(errp, local_err);
         goto the_end;
     }
 
     ret = bdrv_all_create_snapshot(sn, bs, vm_state_size, &bs);
     if (ret < 0) {
-        monitor_printf(mon, "Error while creating snapshot on '%s'\n",
-                       bdrv_get_device_name(bs));
+        error_setg(errp, "Error while creating snapshot on '%s'",
+                   bdrv_get_device_name(bs));
         goto the_end;
     }
 
@@ -2174,7 +2175,11 @@  int save_vmstate(Monitor *mon, const char *name)
 
 void hmp_savevm(Monitor *mon, const QDict *qdict)
 {
-    save_vmstate(mon, qdict_get_try_str(qdict, "name"));
+    Error *local_err = NULL;
+    save_vmstate(qdict_get_try_str(qdict, "name"), &local_err);
+    if (local_err) {
+        error_report_err(local_err);
+    }
 }
 
 void qmp_xen_save_devices_state(const char *filename, Error **errp)
diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c
index 65e2d37..49b21f0 100644
--- a/replay/replay-snapshot.c
+++ b/replay/replay-snapshot.c
@@ -64,8 +64,10 @@  void replay_vmstate_init(void)
 {
     if (replay_snapshot) {
         if (replay_mode == REPLAY_MODE_RECORD) {
-            if (save_vmstate(cur_mon, replay_snapshot) != 0) {
-                error_report("Could not create snapshot for icount record");
+            Error *local_err = NULL;
+            if (save_vmstate(replay_snapshot, &local_err) != 0) {
+                error_reportf_err(local_err,
+                              "Could not create snapshot for icount record: ");
                 exit(1);
             }
         } else if (replay_mode == REPLAY_MODE_PLAY) {