From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:57306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rnk4V-0002cC-Bn for qemu-devel@nongnu.org; Wed, 18 Jan 2012 23:58:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rnk4U-0007Pl-6c for qemu-devel@nongnu.org; Wed, 18 Jan 2012 23:57:59 -0500 Received: from [222.73.24.84] (port=51366 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rnk4T-0007PO-Jk for qemu-devel@nongnu.org; Wed, 18 Jan 2012 23:57:58 -0500 Message-ID: <4F17890B.4000408@cn.fujitsu.com> Date: Thu, 19 Jan 2012 11:07:55 +0800 From: Wen Congyang MIME-Version: 1.0 References: <4F1784EE.2040800@cn.fujitsu.com> In-Reply-To: <4F1784EE.2040800@cn.fujitsu.com> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1 Subject: [Qemu-devel] [RFC][PATCH 15/15 v5] 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 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 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