From patchwork Fri Jan 8 14:10:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 564823 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 1BBF1140213 for ; Sat, 9 Jan 2016 01:11:14 +1100 (AEDT) Received: from localhost ([::1]:36235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHXl1-0004GT-RD for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2016 09:11:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHXkM-00030k-3T for qemu-devel@nongnu.org; Fri, 08 Jan 2016 09:10:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aHXkK-0007Mg-Rl for qemu-devel@nongnu.org; Fri, 08 Jan 2016 09:10:30 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:35930 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHXkK-0007M7-CD for qemu-devel@nongnu.org; Fri, 08 Jan 2016 09:10:28 -0500 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u0739Zh0026825; Thu, 7 Jan 2016 06:09:45 +0300 (MSK) From: "Denis V. Lunev" To: Date: Fri, 8 Jan 2016 17:10:16 +0300 Message-Id: <1452262216-4545-6-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452262216-4545-1-git-send-email-den@openvz.org> References: <1452262216-4545-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: Juan Quintela , qemu-devel@nongnu.org, Markus Armbruster , Amit Shah , "Denis V. Lunev" Subject: [Qemu-devel] [PATCH 5/5] qmp: create QMP implementation of loadvm command 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 Unfortunately load_vmstate has a return code (int) and this code is checked in the other places. Thus we could not just rename it to qmp_loadvm as returns void. Signed-off-by: Denis V. Lunev CC: Juan Quintela CC: Amit Shah CC: Markus Armbruster CC: Eric Blake --- migration/savevm.c | 10 ++++++++++ monitor.c | 8 ++------ qapi-schema.json | 13 +++++++++++++ qmp-commands.hx | 23 +++++++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 3de917e..6b34017 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2096,6 +2096,16 @@ int load_vmstate(const char *name, Error **errp) return 0; } +void qmp_loadvm(const char *name, Error **errp) +{ + int saved_vm_running = runstate_is_running(); + vm_stop(RUN_STATE_RESTORE_VM); + + if (load_vmstate(name, errp) == 0 && saved_vm_running) { + vm_start(); + } +} + void qmp_delvm(const char *name, Error **errp) { BlockDriverState *bs; diff --git a/monitor.c b/monitor.c index 2ddf6c1..c1e998c 100644 --- a/monitor.c +++ b/monitor.c @@ -1737,16 +1737,12 @@ void qmp_closefd(const char *fdname, Error **errp) static void hmp_loadvm(Monitor *mon, const QDict *qdict) { - int saved_vm_running = runstate_is_running(); const char *name = qdict_get_str(qdict, "name"); Error *local_err = NULL; - vm_stop(RUN_STATE_RESTORE_VM); - - if (load_vmstate(name, &local_err) < 0) { + qmp_loadvm(name, &local_err); + if (local_err != NULL) { error_report_err(local_err); - } else if (saved_vm_running) { - vm_start(); } } diff --git a/qapi-schema.json b/qapi-schema.json index 94a2764..7d48948 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4080,3 +4080,16 @@ # Since 2.6 ## { 'command': 'delvm', 'data': {'name': 'str'} } + +## +# @loadvm +# +# Load a VM snapshot +# +# @name: identifier of a snapshot to be loaded +# +# Returns: Nothing on success +# +# Since 2.6 +## +{ 'command': 'loadvm', 'data': {'name': 'str'} } diff --git a/qmp-commands.hx b/qmp-commands.hx index 5e6f573..9cd1bfe 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -4843,3 +4843,26 @@ EQMP .args_type = "name:s", .mhandler.cmd_new = qmp_marshal_delvm, }, + +SQMP +loadvm +------ + +Load a VM snapshot + +Arguments: + +- "name": snapshot name + +Example: + +-> { "execute": "loadvm", "arguments": { "name": "snapshot1" } } +<- { "return": {} } + +EQMP + + { + .name = "loadvm", + .args_type = "name:s", + .mhandler.cmd_new = qmp_marshal_loadvm, + },