Patchwork [RFC,14/14,v4] auto cancel dumping after vm state is changed to run

login
register
mail settings
Submitter Wen Congyang
Date Jan. 4, 2012, 6:17 a.m.
Message ID <4F03EEDD.2000109@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/134219/
State New
Headers show

Comments

Wen Congyang - Jan. 4, 2012, 6:17 a.m.
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 |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

Patch

diff --git a/dump.c b/dump.c
index 4276cb8..2053c3e 100644
--- a/dump.c
+++ b/dump.c
@@ -82,6 +82,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 */
@@ -113,6 +114,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;
+    }
+
     if (!s->detach && s->error) {
         monitor_printf(s->mon, "%s", s->error);
     }
@@ -675,6 +681,16 @@  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;
+    }
+}
+
 int do_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     const char *file = qdict_get_str(qdict, "file");
@@ -712,6 +728,8 @@  int do_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
         return -1;
     }
 
+    s->handler = qemu_add_vm_change_state_handler(dump_vm_state_change, s);
+
     if (s->detach) {
         s->mon = NULL;
     }