Received: from eggs.gnu.org ([2001:4830:134:3::10]:53185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhYwN-0003CF-6E for qemu-devel@nongnu.org; Fri, 24 Oct 2014 03:05:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XhYwH-0000I8-G2 for qemu-devel@nongnu.org; Fri, 24 Oct 2014 03:05:39 -0400 Received: from [59.151.112.132] (port=44819 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhYwG-0000GY-Mb for qemu-devel@nongnu.org; Fri, 24 Oct 2014 03:05:33 -0400 From: Wen Congyang Date: Fri, 24 Oct 2014 15:06:17 +0800 Message-ID: <1414134377-19665-20-git-send-email-wency@cn.fujitsu.com> In-Reply-To: <1414134377-19665-1-git-send-email-wency@cn.fujitsu.com> References: <1414134377-19665-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH 19/18] Introduce "xen-load-devices-state" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: xen devel Cc: Ian Campbell , Stefano Stabellini , Ian Jackson , Jiang Yunhong , Dong Eddie , qemu-devl , Paolo Bonzini , Yang Hongyang , Lai Jiangshan 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 Cc: qemu-devl Cc: Stefano Stabellini Cc: Paolo Bonzini --- qapi-schema.json | 18 ++++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ savevm.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index 391356f..c569856 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4689,3 +4689,21 @@ 'btn' : 'InputBtnEvent', 'rel' : 'InputMoveEvent', 'abs' : 'InputMoveEvent' } } + +## +# @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.0 +## +{ 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} } diff --git a/qmp-commands.hx b/qmp-commands.hx index ed3ab92..b796be5 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -586,6 +586,33 @@ Example: EQMP { + .name = "xen-load-devices-state", + .args_type = "filename:F", + .mhandler.cmd_new = qmp_marshal_input_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_input_xen_set_global_dirty_log, diff --git a/savevm.c b/savevm.c index 22123be..3ebc01f 100644 --- a/savevm.c +++ b/savevm.c @@ -41,6 +41,7 @@ #include "qemu/iov.h" #include "block/snapshot.h" #include "block/qapi.h" +#include "hw/xen/xen.h" #define SELF_ANNOUNCE_ROUNDS 5 @@ -802,6 +803,14 @@ int qemu_loadvm_state(QEMUFile *f) goto out; } + /* Validate if it is a device's state */ + if (xen_enabled() && se->is_ram) { + fprintf(stderr, "loadvm: %s RAM loading not allowed on Xen\n", + idstr); + ret = -EINVAL; + goto out; + } + /* Add entry */ le = g_malloc0(sizeof(*le)); @@ -1027,6 +1036,33 @@ 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; + } + + ret = qemu_loadvm_state(f); + qemu_fclose(f); + if (ret < 0) { + error_set(errp, QERR_IO_ERROR); + } + +out: + if (saved_vm_running) { + vm_start(); + } +} + int load_vmstate(const char *name) { BlockDriverState *bs, *bs_vm_state; -- 1.9.3