From patchwork Fri Oct 3 17:47:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 396413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 962CB1400E0 for ; Sat, 4 Oct 2014 04:16:21 +1000 (EST) Received: from localhost ([::1]:40760 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xa7Ot-0002KN-Ov for incoming@patchwork.ozlabs.org; Fri, 03 Oct 2014 14:16:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xa6zS-0002Jd-IF for qemu-devel@nongnu.org; Fri, 03 Oct 2014 13:50:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xa6zM-0001iT-Dq for qemu-devel@nongnu.org; Fri, 03 Oct 2014 13:50:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34215) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xa6zM-0001iI-7D for qemu-devel@nongnu.org; Fri, 03 Oct 2014 13:49:56 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s93HnmUb032595 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 3 Oct 2014 13:49:49 -0400 Received: from dgilbert-t530.home.treblig.org (vpn1-5-216.ams2.redhat.com [10.36.5.216]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s93Hlsfl020826; Fri, 3 Oct 2014 13:49:46 -0400 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Fri, 3 Oct 2014 18:47:52 +0100 Message-Id: <1412358473-31398-47-git-send-email-dgilbert@redhat.com> In-Reply-To: <1412358473-31398-1-git-send-email-dgilbert@redhat.com> References: <1412358473-31398-1-git-send-email-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, lilei@linux.vnet.ibm.com, quintela@redhat.com, cristian.klein@cs.umu.se, amit.shah@redhat.com, yanghy@cn.fujitsu.com Subject: [Qemu-devel] [PATCH v4 46/47] postcopy: Wire up loadvm_postcopy_ram_handle_{run, end} commands 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 From: "Dr. David Alan Gilbert" Wire up more of the handlers for the commands on the destination side, in particular loadvm_postcopy_ram_handle_run now has enough to start the guest running. Signed-off-by: Dr. David Alan Gilbert --- savevm.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/savevm.c b/savevm.c index 53e8a2c..805bb21 100644 --- a/savevm.c +++ b/savevm.c @@ -1373,6 +1373,8 @@ static int loadvm_postcopy_ram_handle_listen(MigrationIncomingState *mis) /* After all discards we can start running and asking for pages */ static int loadvm_postcopy_ram_handle_run(MigrationIncomingState *mis) { + Error *local_err = NULL; + DPRINTF("%s", __func__); if (mis->postcopy_ram_state != POSTCOPY_RAM_INCOMING_LISTENING) { error_report("CMD_POSTCOPY_RAM_RUN in wrong postcopy state (%d)", @@ -1381,6 +1383,28 @@ static int loadvm_postcopy_ram_handle_run(MigrationIncomingState *mis) } mis->postcopy_ram_state = POSTCOPY_RAM_INCOMING_RUNNING; + + /* TODO we should move all of this lot into postcopy_ram.c or a shared code + * in migration.c + */ + cpu_synchronize_all_post_init(); + + qemu_announce_self(); + bdrv_clear_incoming_migration_all(); + + /* Make sure all file formats flush their mutable metadata */ + bdrv_invalidate_cache_all(&local_err); + if (local_err) { + qerror_report_err(local_err); + error_free(local_err); + return -1; + } + + DPRINTF("loadvm_postcopy_ram_handle_run: cpu_synchronize_all_post_init"); + cpu_synchronize_all_post_init(); + + DPRINTF("loadvm_postcopy_ram_handle_run: vm_start"); + if (autostart) { /* Hold onto your hats, starting the CPU */ vm_start(); @@ -1389,11 +1413,15 @@ static int loadvm_postcopy_ram_handle_run(MigrationIncomingState *mis) runstate_set(RUN_STATE_PAUSED); } - return 0; + return LOADVM_EXITCODE_QUITLOOP; } -/* The end - with a byte from the source which can tell us to fail. */ -static int loadvm_postcopy_ram_handle_end(MigrationIncomingState *mis) +/* The end - with a byte from the source which can tell us to fail. + * The source sends this either if there is a failure, or if it believes it's + * sent everything + */ +static int loadvm_postcopy_ram_handle_end(MigrationIncomingState *mis, + uint8_t status) { DPRINTF("%s", __func__); if (mis->postcopy_ram_state == POSTCOPY_RAM_INCOMING_NONE) { @@ -1401,7 +1429,32 @@ static int loadvm_postcopy_ram_handle_end(MigrationIncomingState *mis) mis->postcopy_ram_state); return -1; } - return -1; /* TODO - expecting 1 byte good/fail */ + + DPRINTF("loadvm_postcopy_ram_handle_end status=%d", status); + + if (!status) { + bool one_message = false; + /* This looks good, but it's possible that the device loading in the + * main thread hasn't finished yet, and so we might not be in 'RUN' + * state yet. + * TODO: Using an atomic_xchg or something for this + */ + while (mis->postcopy_ram_state == POSTCOPY_RAM_INCOMING_LISTENING) { + if (!one_message) { + DPRINTF("%s: Waiting for RUN", __func__); + one_message = true; + } + } + } + + if (status) { + error_report("CMD_POSTCOPY_RAM_END: error on source host (%d)", + status); + qemu_file_set_error(mis->file, -EPIPE); + } + + /* This will cause the listen thread to exit and call cleanup */ + return LOADVM_EXITCODE_QUITLOOP; } static int loadvm_process_command_simple_lencheck(const char *name, @@ -1548,7 +1601,7 @@ static int loadvm_process_command(QEMUFile *f, len, 1)) { return -1; } - return loadvm_postcopy_ram_handle_end(mis); + return loadvm_postcopy_ram_handle_end(mis, qemu_get_byte(f)); default: error_report("VM_COMMAND 0x%x unknown (len 0x%x)", com, len);