@@ -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;
@@ -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();
}
}
@@ -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'} }
@@ -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,
+ },
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 <den@openvz.org> CC: Juan Quintela <quintela@redhat.com> CC: Amit Shah <amit.shah@redhat.com> CC: Markus Armbruster <armbru@redhat.com> CC: Eric Blake <eblake@redhat.com> --- migration/savevm.c | 10 ++++++++++ monitor.c | 8 ++------ qapi-schema.json | 13 +++++++++++++ qmp-commands.hx | 23 +++++++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-)