QMP wrappers for VM snapshot operations
v3 cover QMP wrappers for VM snapshot operations
EFI based VM with pflash storage for NVRAM could not be snapshoted as libvirt configures storage as 'raw' and writable. OK, this is a libvirt problem.
Another problem is that libvirt can not detect this failure at all as it uses HMP for this operation. This create snapshot/delete snapshot sequence passes silently.
The patchset adds QMP wrappers for the purpose.
Changes from v2:
- patches 1/2 are resplit to move processing HMP specific handling of snapshot name generation to exclusive HMP code
- removed all '.' at the end of error_setg strings
- fixed too long lines with '-' in qmp-commands.hx
- error_setg_errno errno passing is fixed (-ret)
- fixed logical error in hmp_loadvm (vm_start on error)
- NOT switched to error_prepend code (it is not yet merged). Can we do this later? This will make my life easear merging code to our downstream.
Changes from v1:
- cosmetic fixes suggested by Markus. I pray I have added all of them
- patch 5 is rewritten completely. Original one was deadbeaf
Denis V. Lunev (5):
qmp: process system-reset event in paused state
qmp: create qmp_savevm command
qmp: create qmp_delvm command
migration: improve error reporting for load_vmstate
qmp: create QMP implementation of loadvm command
hmp.c | 14 +++++++-- include/migration/migration.h | 2 -- include/sysemu/sysemu.h | 2 +- migration/savevm.c | 56 ++++++++++++++++++++-------------- monitor.c | 9 +++--- qapi-schema.json | 39 ++++++++++++++++++++++++ qmp-commands.hx | 71 +++++++++++++++++++++++++++++++++++++++++++ qmp.c | 4 +++ vl.c | 4 ++- 9 files changed, 168 insertions(+), 33 deletions(-)
Signature · 1 line
2.5.0
PATCH v3 1/5 qmp: process system-reset event in paused state
With pvpanic or HyperV panic devices could be moved into the paused state with ' <on_crash>preserve</on_crash>'. In this state VM reacts only to 'virsh destroy' or 'continue'.
'virsh reset' command is usually used to force guest reset. The expectation of the behavior of this command is that the guest will be force restarted. This is not true at the moment.
Thus it is quite natural to process 'virh reset' aka qmp_system_reset this way, i.e. allow to reset the guest. This behavior is similar to one observed with 'reset' button on real hardware :)
--- qmp.c | 4 ++++ 1 file changed, 4 insertions(+)
qmp.c +4 -0
@@ -112,6 +112,10 @@ void qmp_stop(Error **errp)void qmp_system_reset (Error **errp) {qemu_system_reset_request (); + +if (!runstate_is_running ()) { +vm_start (); + } }void qmp_system_powerdown (Error **erp)
Signature · 1 line
2.5.0
PATCH v3 2/5 qmp: create qmp_savevm command
In reply to Denis V. Lunev'name' attribute is made mandatory in distinction with HMP command.
The patch also moves hmp_savevm implementation into hmp.c. This function is just a simple wrapper now and does not have knowledge about migration internals.
--- hmp.c | 3 +-- include/migration/migration.h | 2 -- migration/savevm.c | 2 +- qapi-schema.json | 13 +++++++++++++ qmp-commands.hx | 25 +++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 5 deletions(-)
hmp.c +1 -2
@@ -33,7 +33,6 @@#include "ui/console.h" #include "block/qapi.h" #include "qemu-io.h" -#include "migration/migration.h" #ifdef CONFIG_SPICE #include <spice/enums.h>
@@ -2406,7 +2405,7 @@ void hmp_savevm(Monitor *mon, const QDict *qdict) name = name_buf; } -migrate_savevm (name, &local_err); +qmp_savevm (name, &local_err);if (local_err !=NULL ) {error_report_err (local_err);
include/migration/migration.h +0 -2
@@ -277,8 +277,6 @@ int migrate_compress_threads(void);int migrate_decompress_threads (void );bool migrate_use_events (void ); -void migrate_savevm (const char *name,Error **errp); -/* Sending on the return path - generic and then for each message type */ void migrate_send_rp_message(MigrationIncomingState *mis, enum mig_rp_message_type message_type,
migration/savevm.c +1 -1
@@ -1905,7 +1905,7 @@ int qemu_loadvm_state(QEMUFile *f)return ret; } -void migrate_savevm (const char *name,Error **errp) +void qmp_savevm (const char *name,Error **errp) {BlockDriverState *bs, *bs1;QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
qapi-schema.json +13 -0
@@ -4054,3 +4054,16 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @savevm +# +# Save a VM snapshot. Old snapshot with the same name will be deleted if exists. +# +# @name: identifier of a snapshot to be created +# +# Returns: Nothing on success +# +# Since 2.6 +## +{ 'command': 'savevm', 'data': {'name': 'str'} }
qmp-commands.hx +25 -0
@@ -4795,3 +4795,28 @@ Example: {"type": 0, "out-pport": 0, "pport": 0, "vlan-id": 3840, "pop-vlan": 1, "id": 251658240} ]} + +EQMP + +SQMP +savevm +------ + +Save a VM snapshot. Old snapshot with the same name will be deleted if exists. + +Arguments: + +- "name": snapshot name + +Example: + +-> { "execute": "savevm", "arguments": { "name": "snapshot1" } } +<- { "return": {} } + +EQMP + + { + .name = "savevm", + .args_type = "name:s", + .mhandler.cmd_new = qmp_marshal_savevm, + },
Signature · 1 line
2.5.0
PATCH v3 3/5 qmp: create qmp_delvm command
In reply to Denis V. LunevThe patch also moves hmp_delvm implementation into hmp.c. This function is just a simple wrapper now and does not have knowledge about migration internals.
--- hmp.c | 11 +++++++++++ migration/savevm.c | 16 +++++++--------- qapi-schema.json | 13 +++++++++++++ qmp-commands.hx | 23 +++++++++++++++++++++++ 4 files changed, 54 insertions(+), 9 deletions(-)
hmp.c +11 -0
@@ -2411,3 +2411,14 @@ void hmp_savevm(Monitor *mon, const QDict *qdict)error_report_err (local_err); } } + +void hmp_delvm (Monitor *mon,const QDict *qdict) +{ +Error *local_err =NULL ; + +qmp_delvm (qdict_get_str (qdict,"name" ), &local_err); + +if (local_err !=NULL ) { +error_report_err (local_err); + } +}
migration/savevm.c +7 -9
@@ -2092,17 +2092,15 @@ int load_vmstate(const char *name)return 0 ; } -void hmp_delvm (Monitor *mon,const QDict *qdict) +void qmp_delvm (const char *name,Error **errp) {BlockDriverState *bs; -Error *err; -const char *name =qdict_get_str (qdict,"name" ); - -if (bdrv_all_delete_snapshot (name, &bs, &err) <0 ) { -monitor_printf (mon, -"Error while deleting snapshot on device '%s': %s\n" , -bdrv_get_device_name (bs),error_get_pretty (err)); -error_free (err); +Error *local_err =NULL ; + +if (bdrv_all_delete_snapshot (name, &bs, &local_err) <0 ) { +error_setg (errp,"Error while deleting snapshot on device '%s': %s" , +bdrv_get_device_name (bs),error_get_pretty (local_err)); +error_free (local_err); } }
qapi-schema.json +13 -0
@@ -4067,3 +4067,16 @@ # Since 2.6 ## { 'command': 'savevm', 'data': {'name': 'str'} } + +## +# @delvm +# +# Delete a VM snapshot +# +# @name: identifier of a snapshot to be deleted +# +# Returns: Nothing on success +# +# Since 2.6 +## +{ 'command': 'delvm', 'data': {'name': 'str'} }
qmp-commands.hx +23 -0
@@ -4820,3 +4820,26 @@ EQMP .args_type = "name:s", .mhandler.cmd_new = qmp_marshal_savevm, }, + +SQMP +delvm +----- + +Delete a VM snapshot + +Arguments: + +- "name": snapshot name + +Example: + +-> { "execute": "delvm", "arguments": { "name": "snapshot1" } } +<- { "return": {} } + +EQMP + + { + .name = "delvm", + .args_type = "name:s", + .mhandler.cmd_new = qmp_marshal_delvm, + },
Signature · 1 line
2.5.0
PATCH v3 4/5 migration: improve error reporting for load_vmstate
In reply to Denis V. LunevThe patch adds Error ** parameter to load_vmstate call and fills error inside. The caller after that properly reports error either through monitor or via local stderr facility during VM start.
This helper will be useful too for qmp_loadvm implementation.
--- include/sysemu/sysemu.h | 2 +- migration/savevm.c | 28 ++++++++++++++++------------ monitor.c | 5 ++++- vl.c | 4 +++- 4 files changed, 24 insertions(+), 15 deletions(-)
include/sysemu/sysemu.h +1 -1
@@ -78,7 +78,7 @@ void qemu_remove_exit_notifier(Notifier *notify);void qemu_add_machine_init_done_notifier (Notifier *notify);void hmp_savevm (Monitor *mon,const QDict *qdict); -int load_vmstate (const char *name); +int load_vmstate (const char *name,Error **errp);void hmp_delvm (Monitor *mon,const QDict *qdict);void hmp_info_snapshots (Monitor *mon,const QDict *qdict);
migration/savevm.c +16 -12
@@ -2019,7 +2019,7 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) } } -int load_vmstate (const char *name) +int load_vmstate (const char *name,Error **errp) {BlockDriverState *bs, *bs_vm_state;QEMUSnapshotInfo sn;
@@ -2028,20 +2028,22 @@ int load_vmstate(const char *name)AioContext *aio_context;if (!bdrv_all_can_snapshot (&bs)) { -error_report ("Device '%s' is writable but does not support snapshots." , -bdrv_get_device_name (bs)); +error_setg (errp, +"Device '%s' is writable but does not support snapshots" , +bdrv_get_device_name (bs));return -ENOTSUP ; } ret =bdrv_all_find_snapshot (name, &bs);if (ret <0 ) { -error_report ("Device '%s' does not have the requested snapshot '%s'" , -bdrv_get_device_name (bs), name); +error_setg (errp, +"Device '%s' does not have the requested snapshot '%s'" , +bdrv_get_device_name (bs), name);return ret; } bs_vm_state =bdrv_all_find_vmstate_bs ();if (!bs_vm_state) { -error_report ("No block device supports snapshots" ); +error_setg (errp,"No block device supports snapshots" );return -ENOTSUP ; } aio_context =bdrv_get_aio_context (bs_vm_state);
@@ -2051,10 +2053,11 @@ int load_vmstate(const char *name) ret =bdrv_snapshot_find (bs_vm_state, &sn, name);aio_context_release (aio_context);if (ret <0 ) { +error_setg_errno (errp, -ret,"Snapshot '%s' not found" , name);return ret; }else if (sn.vm_state_size ==0 ) { -error_report ("This is a disk-only snapshot. Revert to it offline " -"using qemu-img." ); +error_setg (errp,"Snapshot '%s' is a disk-only snapshot and must be " +"reverted offline using qemu-img" , name);return -EINVAL ; }
@@ -2063,15 +2066,16 @@ int load_vmstate(const char *name) ret =bdrv_all_goto_snapshot (name, &bs);if (ret <0 ) { -error_report ("Error %d while activating snapshot '%s' on '%s'" , - ret, name,bdrv_get_device_name (bs)); +error_setg_errno (errp, -ret, +"Error while activating snapshot '%s' on '%s'" , + name,bdrv_get_device_name (bs));return ret; }/* restore the VM state */ f =qemu_fopen_bdrv (bs_vm_state,0 );if (!f) { -error_report ("Could not open VM state file" ); +error_setg (errp,"Could not open VM state file" );return -EINVAL ; }
@@ -2085,7 +2089,7 @@ int load_vmstate(const char *name)migration_incoming_state_destroy ();if (ret <0 ) { -error_report ("Error %d while loading VM state" , ret); +error_setg_errno (errp, -ret,"Error while loading VM state" );return ret; }
monitor.c +4 -1
@@ -1739,10 +1739,13 @@ 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) ==0 && saved_vm_running) { +if (load_vmstate (name, &local_err) <0 ) { +error_report_err (local_err); + }else if (saved_vm_running) {vm_start (); } }
vl.c +3 -1
@@ -4648,8 +4648,10 @@ int main(int argc, char **argv, char **envp)qemu_system_reset (VMRESET_SILENT );register_global_state ();if (loadvm) { -if (load_vmstate (loadvm) <0 ) { +Error *local_err =NULL ; +if (load_vmstate (loadvm, &local_err) <0 ) { autostart =0 ; +error_report_err (local_err); } }
Signature · 1 line
2.5.0
PATCH v3 5/5 qmp: create QMP implementation of loadvm command
In reply to Denis V. LunevUnfortunately 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.
--- migration/savevm.c | 10 ++++++++++ monitor.c | 8 ++------ qapi-schema.json | 13 +++++++++++++ qmp-commands.hx | 23 +++++++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-)
migration/savevm.c +10 -0
@@ -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;
monitor.c +2 -6
@@ -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 (); } }
qapi-schema.json +13 -0
@@ -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'} }
qmp-commands.hx +23 -0
@@ -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, + },
Signature · 1 line
2.5.0
Quoted 37 lines · Denis V. Lunev
EFI based VM with pflash storage for NVRAM could not be snapshoted as libvirt configures storage as 'raw' and writable. OK, this is a libvirt problem.
Another problem is that libvirt can not detect this failure at all as it uses HMP for this operation. This create snapshot/delete snapshot sequence passes silently.
The patchset adds QMP wrappers for the purpose.
Signed-off-by "Denis V. Lunev" <[email protected]>CC Juan Quintela <[email protected]>CC Amit Shah <[email protected]>CC Markus Armbruster <[email protected]>CC Eric Blake <[email protected]>Changes from v2:
- patches 1/2 are resplit to move processing HMP specific handling of snapshot name generation to exclusive HMP code
- removed all '.' at the end oferror_setgstrings
- fixed too long lines with '-' in qmp-commands.hx
-error_setg_errnoerrno passing is fixed (-ret)
- fixed logical error inhmp_loadvm(vm_starton error)
- NOT switched toerror_prependcode (it is not yet merged). Can we do this later? This will make my life easear merging code to our downstream.Changes from v1:
- cosmetic fixes suggested by Markus. I pray I have added all of them
- patch 5 is rewritten completely. Original one was deadbeafDenis V. Lunev (5):
qmp: process system-reset event in paused state
qmp: createqmp_savevmcommand
qmp: createqmp_delvmcommand
migration: improve error reporting forload_vmstate
qmp: create QMP implementation of loadvm command
Quoted 11 lines
hmp.c | 14 +++++++-- include/migration/migration.h | 2 -- include/sysemu/sysemu.h | 2 +- migration/savevm.c | 56 ++++++++++++++++++++-------------- monitor.c | 9 +++--- qapi-schema.json | 39 ++++++++++++++++++++++++ qmp-commands.hx | 71 +++++++++++++++++++++++++++++++++++++++++++ qmp.c | 4 +++ vl.c | 4 ++- 9 files changed, 168 insertions(+), 33 deletions(-)
pls disregard this. patch 1 is stale and from the different set.
Sorry :(