From patchwork Thu Oct 18 07:30:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 192219 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 52EC92C008F for ; Thu, 18 Oct 2012 18:56:15 +1100 (EST) Received: from localhost ([::1]:41305 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOkZy-0006DR-Qf for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2012 03:31:42 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOkZD-00054M-8Z for qemu-devel@nongnu.org; Thu, 18 Oct 2012 03:31:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOkZ5-0000PW-Lu for qemu-devel@nongnu.org; Thu, 18 Oct 2012 03:30:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOkZ5-0000PP-Bt for qemu-devel@nongnu.org; Thu, 18 Oct 2012 03:30:47 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9I7Uk1V021573 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 18 Oct 2012 03:30:46 -0400 Received: from trasno.mitica (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9I7URnP020816; Thu, 18 Oct 2012 03:30:45 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2012 09:30:02 +0200 Message-Id: <1350545426-23172-7-git-send-email-quintela@redhat.com> In-Reply-To: <1350545426-23172-1-git-send-email-quintela@redhat.com> References: <1350545426-23172-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/30] migration: stop all cpus correctly X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org You can only stop all cpus from the iothread or an vcpu. As we want to do it from the migration_thread, we need to do this dance with the botton handlers. This patch is a request for ideas. I can move this function to cpus.c, but wondered if there is an easy way of doing this? Signed-off-by: Juan Quintela --- migration.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/migration.c b/migration.c index 02f4ffa..05ef1a3 100644 --- a/migration.c +++ b/migration.c @@ -20,6 +20,7 @@ #include "sysemu.h" #include "block.h" #include "qemu_socket.h" +#include "qemu-thread.h" #include "block-migration.h" #include "qmp-commands.h" @@ -322,11 +323,22 @@ ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data, void migrate_fd_put_ready(MigrationState *s) { int ret; + static bool first_time = true; if (s->state != MIG_STATE_ACTIVE) { DPRINTF("put_ready returning because of non-active state\n"); return; } + if (first_time) { + first_time = false; + DPRINTF("beginning savevm\n"); + ret = qemu_savevm_state_begin(s->file, &s->params); + if (ret < 0) { + DPRINTF("failed, %d\n", ret); + migrate_fd_error(s); + return; + } + } DPRINTF("iterate\n"); ret = qemu_savevm_state_iterate(s->file); @@ -339,7 +351,11 @@ void migrate_fd_put_ready(MigrationState *s) DPRINTF("done iterating\n"); start_time = qemu_get_clock_ms(rt_clock); qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); - vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); + if (old_vm_running) { + vm_stop(RUN_STATE_FINISH_MIGRATE); + } else { + vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); + } if (qemu_savevm_state_complete(s->file) < 0) { migrate_fd_error(s); @@ -428,19 +444,8 @@ bool migration_has_failed(MigrationState *s) void migrate_fd_connect(MigrationState *s) { - int ret; - s->state = MIG_STATE_ACTIVE; qemu_fopen_ops_buffered(s); - - DPRINTF("beginning savevm\n"); - ret = qemu_savevm_state_begin(s->file, &s->params); - if (ret < 0) { - DPRINTF("failed, %d\n", ret); - migrate_fd_error(s); - return; - } - migrate_fd_put_ready(s); } static MigrationState *migrate_init(const MigrationParams *params)