@@ -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);
}
@@ -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);
}
}
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(-)