Patchwork [04/23] make load_vmstate() return errors

login
register
mail settings
Submitter Juan Quintela
Date Aug. 20, 2009, 5:42 p.m.
Message ID <f849340dcc7238be6364b733cee168b56891b363.1250788880.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/31753/
State Superseded
Headers show

Comments

Juan Quintela - Aug. 20, 2009, 5:42 p.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 monitor.c |    3 +--
 savevm.c  |   12 +++++++-----
 sysemu.h  |    2 +-
 vl.c      |    7 +++++--
 4 files changed, 14 insertions(+), 10 deletions(-)

Patch

diff --git a/monitor.c b/monitor.c
index b8a47ca..ea5c33a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1782,8 +1782,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 d0ed2ad..4868285 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1145,7 +1145,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;
@@ -1156,7 +1156,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.  */
@@ -1187,7 +1187,7 @@  void load_vmstate(Monitor *mon, const char *name)
                 }
                 /* fatal on snapshot block device */
                 if (bs == bs1)
-                    return;
+                    return 0;
             }
         }
     }
@@ -1195,19 +1195,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 330386c..e0338ce 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 13a2b74..0a104a6 100644
--- a/vl.c
+++ b/vl.c
@@ -6036,8 +6036,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) {
         autostart = 0;