From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:42163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvKiU-0005T5-OK for qemu-devel@nongnu.org; Wed, 08 Feb 2012 22:30:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RvKiT-00036w-I0 for qemu-devel@nongnu.org; Wed, 08 Feb 2012 22:30:38 -0500 Received: from [222.73.24.84] (port=53152 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvKiT-00036i-1f for qemu-devel@nongnu.org; Wed, 08 Feb 2012 22:30:37 -0500 Message-ID: <4F333EA3.60900@cn.fujitsu.com> Date: Thu, 09 Feb 2012 11:33:55 +0800 From: Wen Congyang MIME-Version: 1.0 References: <4F333AAA.1070601@cn.fujitsu.com> In-Reply-To: <4F333AAA.1070601@cn.fujitsu.com> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1 Subject: [Qemu-devel] [RFC][PATCH 15/16 v6] auto cancel dumping after vm state is changed to run List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel , Jan Kiszka , Dave Anderson , HATAYAMA Daisuke , Luiz Capitulino , Eric Blake 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 --- dump.c | 19 +++++++++++++++++++ vl.c | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) 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); } } -- 1.7.1