From patchwork Mon Jun 13 10:57:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9172685 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 C66C56086B for ; Mon, 13 Jun 2016 10:59:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B881D200E7 for ; Mon, 13 Jun 2016 10:59:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD9D627AC2; Mon, 13 Jun 2016 10:59:36 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1616820499 for ; Mon, 13 Jun 2016 10:59:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCPYZ-0003HN-Pv; Mon, 13 Jun 2016 10:57:23 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCPYX-0003H8-P5 for xen-devel@lists.xen.org; Mon, 13 Jun 2016 10:57:21 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id BB/33-16475-0919E575; Mon, 13 Jun 2016 10:57:20 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsVybKJsh+6EiXH hBo+ey1gs+biYxYHR4+ju30wBjFGsmXlJ+RUJrBk/ek+xFTxQrLh8sJmlgXGNdBcjF4eQwFRG iYNrNjNDOL1MEr+X3gFyODnYBAwl/j7ZxAZiiwjISHReWsQIUsQssItRYs3L24wgCWEBM4n7T /aCNbAIqErM+voCLM4r4CbxccYjMFtCQE7i5LHJrCA2p4C7xLlDD9khtrUxSrTvXMsCUZQhMa 9nDiuE7SWx6MYlKFtN4uq5TcwTGPkWMDKsYlQvTi0qSy3SNdJLKspMzyjJTczM0TU0MNXLTS0 uTkxPzUlMKtZLzs/dxAgMFQYg2MH4/Y/TIUZJDiYlUV4Jn7hwIb6k/JTKjMTijPii0pzU4kOM MhwcShK8j/qBcoJFqempFWmZOcCghUlLcPAoifCeBEnzFhck5hZnpkOkTjEqSonzfgFJCIAkM krz4NpgkXKJUVZKmJcR6BAhnoLUotzMElT5V4ziHIxKwrw/QKbwZOaVwE1/BbSYCWgxx75okM UliQgpqQZGv4/sx9be6OxYsX3/YdUFYvk2h8v1t+asmv5QitnlWvg/sxvsilFLtm3tOau0qu/ z+p+nnPmOsu4+VD/9IsMF1qgnkWfamdfqTf8ben/NIwFL37DjrfvV9Ht3+dusTnRd7HG1rH5D 0LVlKc7nvhx4PKfmwZn2Lx4zOpvX7n58Tzlzmq2wL0PUDSWW4oxEQy3mouJEACAoYbaPAgAA X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-2.tower-206.messagelabs.com!1465815438!28534967!1 X-Originating-IP: [198.145.29.136] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 62534 invoked from network); 13 Jun 2016 10:57:20 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.136) by server-2.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 13 Jun 2016 10:57:20 -0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BE1962010F; Mon, 13 Jun 2016 10:57:17 +0000 (UTC) Received: from localhost.localdomain (60.99.208.46.dyn.plus.net [46.208.99.60]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2E05320109; Mon, 13 Jun 2016 10:57:14 +0000 (UTC) From: Stefano Stabellini To: peter.maydell@linaro.org Date: Mon, 13 Jun 2016 11:57:07 +0100 Message-Id: <1465815427-22041-2-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465815427-22041-1-git-send-email-sstabellini@kernel.org> References: <1465815427-22041-1-git-send-email-sstabellini@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP Cc: Changlong Xie , Wen Congyang , qemu-devel@nongnu.org, xen-devel@lists.xen.org, sstabellini@kernel.org, anthony.perard@citrix.com Subject: [Xen-devel] [PULL 2/2] Introduce "xen-load-devices-state" X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-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 Signed-off-by: Stefano Stabellini --- 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,