diff mbox

[RFC,15/16,v6] auto cancel dumping after vm state is changed to run

Message ID 4F333EA3.60900@cn.fujitsu.com
State New
Headers show

Commit Message

Wen Congyang Feb. 9, 2012, 3:33 a.m. UTC
The command dump does not support to dump while vm is running. If the user resume
the vm, we should auto cancel dumping and set the status to failed.

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
 dump.c |   19 +++++++++++++++++++
 vl.c   |    5 +++--
 2 files changed, 22 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/dump.c b/dump.c
index a921b76..6322d1a 100644
--- a/dump.c
+++ b/dump.c
@@ -83,6 +83,7 @@  typedef struct DumpState {
     ram_addr_t start;
     target_phys_addr_t offset;
     QEMUTimer *timer;
+    VMChangeStateEntry *handler;
 } DumpState;
 
 #define DEFAULT_THROTTLE  (32 << 20)      /* Default dump speed throttling */
@@ -114,6 +115,11 @@  static int dump_cleanup(DumpState *s)
         qemu_free_timer(s->timer);
     }
 
+    if (s->handler) {
+        qemu_del_vm_change_state_handler(s->handler);
+        s->handler = NULL;
+    }
+
     qemu_resume_monitor();
 
     return ret;
@@ -670,6 +676,17 @@  static int create_vmcore(DumpState *s)
     return 0;
 }
 
+static void dump_vm_state_change(void *opaque, int running, RunState state)
+{
+    DumpState *s = opaque;
+
+    if (running) {
+        qmp_dump_cancel(NULL);
+        s->state = DUMP_STATE_ERROR;
+        s->error = g_strdup("vm state is changed to run\n");
+    }
+}
+
 void qmp_dump(bool detach, const char *file, Error **errp)
 {
     const char *p;
@@ -704,6 +721,8 @@  void qmp_dump(bool detach, const char *file, Error **errp)
         return;
     }
 
+    s->handler = qemu_add_vm_change_state_handler(dump_vm_state_change, s);
+
     if (create_vmcore(s) < 0) {
         error_set(errp, QERR_IO_ERROR);
     }
diff --git a/vl.c b/vl.c
index 2d464cf..863e91c 100644
--- a/vl.c
+++ b/vl.c
@@ -1248,11 +1248,12 @@  void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
 
 void vm_state_notify(int running, RunState state)
 {
-    VMChangeStateEntry *e;
+    VMChangeStateEntry *e, *next;
 
     trace_vm_state_notify(running, state);
 
-    for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
+    /* e->cb() may remove itself */
+    QLIST_FOREACH_SAFE(e, &vm_change_state_head, entries, next) {
         e->cb(e->opaque, running, state);
     }
 }