[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands
From: |
Daniel P . Berrangé |
Subject: |
[PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands |
Date: |
Thu, 2 Jul 2020 18:57:50 +0100 |
savevm, loadvm and delvm are some of the few commands that have never
been converted to use QMP. The primary reason for this lack of
conversion is that they block execution of the thread for as long as
they run.
Despite this downside, however, libvirt and applications using libvirt
has used these commands for as long as QMP has existed, via the
"human-monitor-command" passthrough command. IOW, while it is clearly
desirable to be able to fix the blocking problem, this is not an
immediate obstacle to real world usage.
Meanwhile there is a need for other features which involve adding new
parameters to the commands. This is possible with HMP passthrough, but
it provides no reliable way for apps to introspect features, so using
QAPI modelling is highly desirable.
This patch thus introduces trival savevm, loadvm, delvm commands
to QMP that are functionally identical to the HMP counterpart, including
the blocking problem.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
migration/savevm.c | 27 ++++++++++++++++
monitor/hmp-cmds.c | 18 ++---------
qapi/migration.json | 76 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+), 15 deletions(-)
diff --git a/migration/savevm.c b/migration/savevm.c
index 72dbad95ed..53586a6406 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2943,3 +2943,30 @@ bool vmstate_check_only_migratable(const
VMStateDescription *vmsd)
return !(vmsd && vmsd->unmigratable);
}
+
+void qmp_savevm(const char *tag, Error **errp)
+{
+ save_snapshot(tag, errp);
+}
+
+void qmp_loadvm(const char *tag, Error **errp)
+{
+ int saved_vm_running = runstate_is_running();
+
+ vm_stop(RUN_STATE_RESTORE_VM);
+
+ if (load_snapshot(tag, errp) == 0 && saved_vm_running) {
+ vm_start();
+ }
+}
+
+void qmp_delvm(const char *tag, Error **errp)
+{
+ BlockDriverState *bs;
+
+ if (bdrv_all_delete_snapshot(tag, &bs, errp) < 0) {
+ error_prepend(errp,
+ "deleting snapshot on device '%s': ",
+ bdrv_get_device_or_node_name(bs));
+ }
+}
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 2b0b58a336..26a5a1a701 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -1089,15 +1089,9 @@ void hmp_balloon(Monitor *mon, const QDict *qdict)
void hmp_loadvm(Monitor *mon, const QDict *qdict)
{
- int saved_vm_running = runstate_is_running();
- const char *name = qdict_get_str(qdict, "name");
Error *err = NULL;
- vm_stop(RUN_STATE_RESTORE_VM);
-
- if (load_snapshot(name, &err) == 0 && saved_vm_running) {
- vm_start();
- }
+ qmp_loadvm(qdict_get_str(qdict, "name"), &err);
hmp_handle_error(mon, err);
}
@@ -1105,21 +1099,15 @@ void hmp_savevm(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;
- save_snapshot(qdict_get_try_str(qdict, "name"), &err);
+ qmp_savevm(qdict_get_try_str(qdict, "name"), &err);
hmp_handle_error(mon, err);
}
void hmp_delvm(Monitor *mon, const QDict *qdict)
{
- BlockDriverState *bs;
Error *err = NULL;
- const char *name = qdict_get_str(qdict, "name");
- if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
- error_prepend(&err,
- "deleting snapshot on device '%s': ",
- bdrv_get_device_name(bs));
- }
+ qmp_delvm(qdict_get_str(qdict, "name"), &err);
hmp_handle_error(mon, err);
}
diff --git a/qapi/migration.json b/qapi/migration.json
index d5000558c6..849de38fb0 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -1621,3 +1621,79 @@
##
{ 'event': 'UNPLUG_PRIMARY',
'data': { 'device-id': 'str' } }
+
+##
+# @savevm:
+#
+# Save a VM snapshot
+#
+# @tag: name of the snapshot to create. If it already
+# exists it will be replaced.
+#
+# Note that execution of the VM will be paused during the time
+# it takes to save the snapshot
+#
+# Returns: nothing
+#
+# Example:
+#
+# -> { "execute": "savevm",
+# "data": {
+# "tag": "my-snap"
+# }
+# }
+# <- { "return": { } }
+#
+# Since: 5.2
+##
+{ 'command': 'savevm',
+ 'data': { 'tag': 'str' } }
+
+##
+# @loadvm:
+#
+# Load a VM snapshot
+#
+# @tag: name of the snapshot to load.
+#
+# Returns: nothing
+#
+# Example:
+#
+# -> { "execute": "loadvm",
+# "data": {
+# "tag": "my-snap"
+# }
+# }
+# <- { "return": { } }
+#
+# Since: 5.2
+##
+{ 'command': 'loadvm',
+ 'data': { 'tag': 'str' } }
+
+##
+# @delvm:
+#
+# Delete a VM snapshot
+#
+# @tag: name of the snapshot to delete.
+#
+# Note that execution of the VM will be paused during the time
+# it takes to delete the snapshot
+#
+# Returns: nothing
+#
+# Example:
+#
+# -> { "execute": "delvm",
+# "data": {
+# "tag": "my-snap"
+# }
+# }
+# <- { "return": { } }
+#
+# Since: 5.2
+##
+{ 'command': 'delvm',
+ 'data': { 'tag': 'str' } }
--
2.26.2
- [PATCH 0/6] migration: bring savevm/loadvm/delvm over to QMP, Daniel P . Berrangé, 2020/07/02
- [PATCH 1/6] migration: improve error reporting of block driver state name, Daniel P . Berrangé, 2020/07/02
- [PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands,
Daniel P . Berrangé <=
- Re: [PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands, Eric Blake, 2020/07/02
- Re: [PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands, Daniel P . Berrangé, 2020/07/02
- Re: [PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands, Dr. David Alan Gilbert, 2020/07/03
- Re: [PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands, Daniel P . Berrangé, 2020/07/03
- Re: [PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands, Dr. David Alan Gilbert, 2020/07/03
- Re: [PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands, Daniel P . Berrangé, 2020/07/03
- Re: [PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands, Dr. David Alan Gilbert, 2020/07/03
- Re: [PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands, Daniel P . Berrangé, 2020/07/03
- Re: [PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands, Dr. David Alan Gilbert, 2020/07/03
- Re: [PATCH 2/6] migration: introduce savevm, loadvm, delvm QMP commands, Daniel P . Berrangé, 2020/07/03