From patchwork Thu Mar 10 10:23:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changlong Xie X-Patchwork-Id: 8555051 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0F8679F46A for ; Thu, 10 Mar 2016 10:22:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4FD0020340 for ; Thu, 10 Mar 2016 10:22:06 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 43B5A20328 for ; Thu, 10 Mar 2016 10:22:05 +0000 (UTC) Received: from localhost ([::1]:47429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adxjI-0001EL-J3 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 10 Mar 2016 05:22:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adxjA-0001Bl-7W for qemu-devel@nongnu.org; Thu, 10 Mar 2016 05:21:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adxj6-0006o6-W9 for qemu-devel@nongnu.org; Thu, 10 Mar 2016 05:21:56 -0500 Received: from [59.151.112.132] (port=13809 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adxj5-0006XQ-Nj for qemu-devel@nongnu.org; Thu, 10 Mar 2016 05:21:52 -0500 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="4437256" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 10 Mar 2016 18:21:29 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id EB9FB42B55E4; Thu, 10 Mar 2016 18:21:26 +0800 (CST) Received: from changlox.g08.fujitsu.local (10.167.225.55) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 10 Mar 2016 18:21:26 +0800 From: Changlong Xie To: qemu devel , Juan Quintela , Amit Shah , Eric Blake , Markus Armbruster Date: Thu, 10 Mar 2016 18:23:27 +0800 Message-ID: <1457605407-679-1-git-send-email-xiecl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 MIME-Version: 1.0 X-Originating-IP: [10.167.225.55] X-yoursite-MailScanner-ID: EB9FB42B55E4.A30E4 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 Cc: "Dr. David Alan Gilbert" , zhanghailiang Subject: [Qemu-devel] [PATCH] Introduce "xen-load-devices-state" 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org 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 primay 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's state in any time. Signed-off-by: Wen Congyang Signed-off-by: Changlong Xie --- migration/savevm.c | 36 ++++++++++++++++++++++++++++++++++++ qapi-schema.json | 18 ++++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 96e7db5..aaead12 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -50,6 +50,7 @@ #include "qemu/iov.h" #include "block/snapshot.h" #include "block/qapi.h" +#include "hw/xen/xen.h" #ifndef ETH_P_RARP @@ -1768,6 +1769,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)); @@ -2077,6 +2084,35 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) } } +void qmp_xen_load_devices_state(const char *filename, Error **errp) +{ + QEMUFile *f; + int saved_vm_running; + int ret; + + saved_vm_running = runstate_is_running(); + vm_stop(RUN_STATE_RESTORE_VM); + + f = qemu_fopen(filename, "rb"); + if (!f) { + error_setg_file_open(errp, errno, filename); + goto out; + } + + migration_incoming_state_new(f); + ret = qemu_loadvm_state(f); + qemu_fclose(f); + migration_incoming_state_destroy(); + if (ret < 0) { + error_setg(errp, QERR_IO_ERROR); + } + +out: + if (saved_vm_running) { + vm_start(); + } +} + int load_vmstate(const char *name) { BlockDriverState *bs, *bs_vm_state; diff --git a/qapi-schema.json b/qapi-schema.json index 362c9d8..27416b6 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4122,3 +4122,21 @@ ## { 'enum': 'ReplayMode', '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. +# +# Returns: Nothing on success +# If @filename cannot be opened, OpenFileFailed +# If an I/O error occurs while reading the file, IOError +# +# Since: 2.6 +## +{ 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} } diff --git a/qmp-commands.hx b/qmp-commands.hx index b629673..5af24a0 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,