From patchwork Mon Oct 16 06:52:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 826177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yFqRC6T4jz9t2c for ; Mon, 16 Oct 2017 18:17:59 +1100 (AEDT) Received: from localhost ([::1]:59723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3zev-000577-Sl for incoming@patchwork.ozlabs.org; Mon, 16 Oct 2017 03:17:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3zI6-0001qk-NL for qemu-devel@nongnu.org; Mon, 16 Oct 2017 02:54:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3zI5-0003P9-Uu for qemu-devel@nongnu.org; Mon, 16 Oct 2017 02:54:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33626) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e3zI5-0003OA-OR for qemu-devel@nongnu.org; Mon, 16 Oct 2017 02:54:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B891E4E33D; Mon, 16 Oct 2017 06:54:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B891E4E33D Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com Received: from pxdev.xzpeter.org.com (dhcp-15-225.nay.redhat.com [10.66.15.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69BE66269A; Mon, 16 Oct 2017 06:54:18 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 16 Oct 2017 14:52:14 +0800 Message-Id: <20171016065216.18162-31-peterx@redhat.com> In-Reply-To: <20171016065216.18162-1-peterx@redhat.com> References: <20171016065216.18162-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 16 Oct 2017 06:54:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 30/32] migration: delay the postcopy-active state switch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrea Arcangeli , Juan Quintela , Alexey Perevalov , peterx@redhat.com, "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Switch the state until we try to start the VM on destination side. The problem is that without doing this we may have a very small window that we'll be in such a state: - dst VM is in postcopy-active state, - main thread is handling MIG_CMD_PACKAGED message, which loads all the device states, - ram load thread is reading memory data from source. Then if we failed at this point when reading the migration stream we'll also switch to postcopy-paused state, but that is not what we want. If device states failed to load, we should fail the migration directly instead of pause. Postponing the state switch to the point when we have already loaded the devices' states and been ready to start running destination VM. Signed-off-by: Peter Xu --- migration/savevm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index bc87b0e5b1..3bc792e320 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1584,8 +1584,6 @@ static void *postcopy_ram_listen_thread(void *opaque) QEMUFile *f = mis->from_src_file; int load_res; - migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, - MIGRATION_STATUS_POSTCOPY_ACTIVE); qemu_sem_post(&mis->listen_thread_sem); trace_postcopy_ram_listen_thread_start(); @@ -1748,6 +1746,14 @@ static int loadvm_postcopy_handle_run(MigrationIncomingState *mis) return -1; } + /* + * Declare that we are in postcopy now. We should already have + * all the device states loaded ready when reach here, and also + * the ram load thread running. + */ + migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_POSTCOPY_ACTIVE); + data = g_new(HandleRunBhData, 1); data->bh = qemu_bh_new(loadvm_postcopy_handle_run_bh, data); qemu_bh_schedule(data->bh);