qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC][PATCH 15/15 v5] auto cancel dumping after vm state is


From: Wen Congyang
Subject: [Qemu-devel] [RFC][PATCH 15/15 v5] auto cancel dumping after vm state is changed to run
Date: Thu, 19 Jan 2012 11:07:55 +0800
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4

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 <address@hidden>
---
 dump.c |   19 +++++++++++++++++++
 vl.c   |    5 +++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/dump.c b/dump.c
index b681a2e..b3847a0 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 ba55b35..2d9df0f 100644
--- a/vl.c
+++ b/vl.c
@@ -1247,11 +1247,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);
     }
 }
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]