From patchwork Fri Jun 3 09:58:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changlong Xie X-Patchwork-Id: 9152383 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7042E60221 for ; Fri, 3 Jun 2016 09:55:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61D79282E8 for ; Fri, 3 Jun 2016 09:55:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5444B28309; Fri, 3 Jun 2016 09:55:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CEA55282E8 for ; Fri, 3 Jun 2016 09:55:11 +0000 (UTC) Received: from localhost ([::1]:53797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8los-0006eP-3D for patchwork-qemu-devel@patchwork.kernel.org; Fri, 03 Jun 2016 05:55:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8loW-0006eD-W1 for qemu-devel@nongnu.org; Fri, 03 Jun 2016 05:54:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8loR-0000f0-CE for qemu-devel@nongnu.org; Fri, 03 Jun 2016 05:54:47 -0400 Received: from [59.151.112.132] (port=3837 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8loP-0000de-7D for qemu-devel@nongnu.org; Fri, 03 Jun 2016 05:54:43 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="7302027" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 03 Jun 2016 17:54:30 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 541D0498F58C; Fri, 3 Jun 2016 17:54:28 +0800 (CST) Received: from changlox.g08.fujitsu.local (10.167.225.55) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.279.2; Fri, 3 Jun 2016 17:54:27 +0800 From: Changlong Xie To: qemu devel , Stefano Stabellini , Anthony PERARD , Juan Quintela , Amit Shah , Eric Blake , Markus Armbruster Date: Fri, 3 Jun 2016 17:58:34 +0800 Message-ID: <1464947914-28143-2-git-send-email-xiecl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1464947914-28143-1-git-send-email-xiecl.fnst@cn.fujitsu.com> References: <1464947914-28143-1-git-send-email-xiecl.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.225.55] X-yoursite-MailScanner-ID: 541D0498F58C.A0FEE X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xiecl.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH v6 1/1] Introduce "xen-load-devices-state" 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: Changlong Xie , "Dr. David Alan Gilbert" , zhanghailiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Wen Congyang Introduce a "xen-load-devices-state" QAPI command that can be used to load the state of all devices, but not the RAM or the block devices of the VM. We only have hmp commands savevm/loadvm, and qmp commands xen-save-devices-state. We use this new command for COLO: 1. suspend both primary vm and secondary vm 2. sync the state 3. resume both primary vm and secondary vm In such case, we need to update all devices' state in any time. Signed-off-by: Wen Congyang Signed-off-by: Changlong Xie Reviewed-by: Anthony PERARD Reviewed-by: Dr. David Alan Gilbert --- migration/savevm.c | 37 +++++++++++++++++++++++++++++++++++++ qapi-schema.json | 14 ++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 6c21231..ae2ef8b 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -31,6 +31,7 @@ #include "hw/boards.h" #include "hw/hw.h" #include "hw/qdev.h" +#include "hw/xen/xen.h" #include "net/net.h" #include "monitor/monitor.h" #include "sysemu/sysemu.h" @@ -1754,6 +1755,12 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) return -EINVAL; } + /* Validate if it is a device's state */ + if (xen_enabled() && se->is_ram) { + error_report("loadvm: %s RAM loading not allowed on Xen", idstr); + return -EINVAL; + } + /* Add entry */ le = g_malloc0(sizeof(*le)); @@ -2064,6 +2071,36 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) } } +void qmp_xen_load_devices_state(const char *filename, Error **errp) +{ + QEMUFile *f; + QIOChannelFile *ioc; + int ret; + + /* Guest must be paused before loading the device state; the RAM state + * will already have been loaded by xc + */ + if (runstate_is_running()) { + error_setg(errp, "Cannot update device state while vm is running"); + return; + } + vm_stop(RUN_STATE_RESTORE_VM); + + ioc = qio_channel_file_new_path(filename, O_RDONLY | O_BINARY, 0, errp); + if (!ioc) { + return; + } + f = qemu_fopen_channel_input(QIO_CHANNEL(ioc)); + + migration_incoming_state_new(f); + ret = qemu_loadvm_state(f); + qemu_fclose(f); + if (ret < 0) { + error_setg(errp, QERR_IO_ERROR); + } + migration_incoming_state_destroy(); +} + int load_vmstate(const char *name) { BlockDriverState *bs, *bs_vm_state; diff --git a/qapi-schema.json b/qapi-schema.json index 8483bdf..48c3a6f 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4201,6 +4201,20 @@ 'data': [ 'none', 'record', 'play' ] } ## +# @xen-load-devices-state: +# +# Load the state of all devices from file. The RAM and the block devices +# of the VM are not loaded by this command. +# +# @filename: the file to load the state of the devices from as binary +# data. See xen-save-devices-state.txt for a description of the binary +# format. +# +# Since: 2.7 +## +{ 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} } + +## # @GICCapability: # # The struct describes capability for a specific GIC (Generic diff --git a/qmp-commands.hx b/qmp-commands.hx index 28801a2..780e7f2 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -587,6 +587,33 @@ Example: EQMP { + .name = "xen-load-devices-state", + .args_type = "filename:F", + .mhandler.cmd_new = qmp_marshal_xen_load_devices_state, + }, + +SQMP +xen-load-devices-state +---------------------- + +Load the state of all devices from file. The RAM and the block devices +of the VM are not loaded by this command. + +Arguments: + +- "filename": the file to load the state of the devices from as binary +data. See xen-save-devices-state.txt for a description of the binary +format. + +Example: + +-> { "execute": "xen-load-devices-state", + "arguments": { "filename": "/tmp/resume" } } +<- { "return": {} } + +EQMP + + { .name = "xen-set-global-dirty-log", .args_type = "enable:b", .mhandler.cmd_new = qmp_marshal_xen_set_global_dirty_log,