migration: bring improved savevm/loadvm/delvm to QMP
v9 cover migration: bring improved savevm/loadvm/delvm to QMP
v1: https://lists.gnu.org/archive/html/qemu-devel/2020-07/msg00866.html
v2: https://lists.gnu.org/archive/html/qemu-devel/2020-07/msg07523.html
v3: https://lists.gnu.org/archive/html/qemu-devel/2020-08/msg07076.html
v4: https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg05221.html
v5: https://lists.gnu.org/archive/html/qemu-devel/2020-10/msg00587.html
v6: https://lists.gnu.org/archive/html/qemu-devel/2020-10/msg02158.html
v7: https://lists.gnu.org/archive/html/qemu-devel/2020-10/msg06205.html
v8: https://lists.gnu.org/archive/html/qemu-devel/2020-11/msg06464.html
This series aims to provide a better designed replacement for the savevm/loadvm/delvm HMP commands, which despite their flaws continue to be actively used in the QMP world via the HMP command passthrough facility.
The main problems addressed are:
- The logic to pick which disk to store the vmstate in is not satsifactory.
The first block driver state cannot be assumed to be the root disk image, it might be OVMF varstore and we don't want to store vmstate in there.
- The logic to decide which disks must be snapshotted is hardwired to all disks which are writable
Again with OVMF there might be a writable varstore, but this can be raw rather than qcow2 format, and thus unable to be snapshotted. While users might wish to snapshot their varstore, in some/many/most cases it is entirely uneccessary. Users are blocked from snapshotting their VM though due to this varstore.
- The commands are synchronous blocking execution and returning errors immediately.
This is partially addressed by integrating with the job framework. This forces the client to use the async commands to determine the completion status or error message from the operations.
In the block code I've only dealt with node names for block devices, as IIUC, this is all that libvirt should need in the -blockdev world it now lives in. IOW, I've made not attempt to cope with people wanting to use these QMP commands in combination with -drive args, as libvirt will never use -drive with a QEMU new enough to have these new commands.
The main limitations of this current impl
- The snapshot process runs serialized in the main thread. ie QEMU guest execution is blocked for the duration. The job framework lets us fix this in future without changing the QMP semantics exposed to the apps.
- Most vmstate loading errors just go to stderr, as they are not using Error **errp reporting. Thus the job framework just reports a fairly generic message
"Error -22 while loading VM state"
Again this can be fixed later without changing the QMP semantics exposed to apps.
I've done some minimal work in libvirt to start to make use of the new commands to validate their functionality, but this isn't finished yet.
My ultimate goal is to make the GNOME Boxes maintainer happy again by having internal snapshots work with OVMF:
https://gitlab.gnome.org/GNOME/gnome-boxes/-/commit/c486da262f6566326fbcb5e=f45c5f64048f16a6e
Changed in v9:
- Rebase to git master to resolve conflicts
- Fixed accidental regression in error handling in previous v8
- Fixed formatting of iotest expected output now that we switched to preserving whitespace in QMP input
Changed in v8:
- Rebase to git master to resolve conflicts
- Updated QAPI since versions to 6.0
Changed in v7:
- Incorporate changes from:
https://lists.gnu.org/archive/html/qemu-devel/2020-10/msg03165.html
- Tweaked error message
Changed in v6:
- Resolve many conflicts with recent replay changes
- Misc typos in QAPI
Changed in v5:
- Fix prevention of tag overwriting
- Refactor and expand test suite coverage to validate more negative scenarios
Changed in v4:
- Make the device lists mandatory, dropping all support for QEMU's built-in heuristics to select devices.
- Improve some error reporting and I/O test coverage
Changed in v3:
- Schedule a bottom half to escape from coroutine context in the jobs. This is needed because the locking in the snapshot code goes horribly wrong when run from a background coroutine instead of the main event thread.
- Re-factor way we iterate over devices, so that we correctly report non-existant devices passed by the user over QMP.
- Add QAPI docs notes about limitations wrt vmstate error reporting (it all goes to stderr not an Error **errp) so QMP only gets a fairly generic error message currently.
- Add I/O test to validate many usage scenarios / errors
- Add I/O test helpers to handle QMP events with a deterministic ordering
- Ensure 'delete-snapshot' reports an error if requesting delete from devices that don't support snapshot, instead of silently succeeding with no erro.
Changed in v2:
- Use new command names "snapshot-{load,save,delete}" to make it clear that these are different from the "savevm|loadvm|delvm" as they use the Job framework
- Use an include list for block devs, not an exclude list
Daniel P. Berrang=C3=A9 (10):
block: push error reporting into bdrv_all_*_snapshot functions
migration: stop returning errno from load_snapshot()
block: add ability to specify list of blockdevs during snapshot
block: allow specifying name of block device for vmstate storage
block: rename and alter bdrv_all_find_snapshot semantics
migration: control whether snapshots are ovewritten
migration: wire up support for snapshot device selection
migration: introduce a delete_snapshot wrapper
iotests: add support for capturing and matching QMP events
migration: introduce snapshot-{save,load,delete} QMP commands
Philippe Mathieu-Daud=C3=A9 (1):
migration: Make save_snapshot() return bool, not 0/-1
block/monitor/block-hmp-cmds.c | 7 +- block/snapshot.c | 256 +++++++++++----- include/block/snapshot.h | 23 +- include/migration/snapshot.h | 47 ++- migration/savevm.c | 296 ++++++++++++++++--- monitor/hmp-cmds.c | 12 +- qapi/job.json | 9 +- qapi/migration.json | 121 ++++++++ replay/replay-debugging.c | 12 +- replay/replay-snapshot.c | 5 +- slirp | 2 +- softmmu/vl.c | 2 +- tests/qemu-iotests/267.out | 12 +- tests/qemu-iotests/310 | 385 ++++++++++++++++++++++++ tests/qemu-iotests/310.out | 520 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/common.qemu | 107 ++++++- tests/qemu-iotests/group | 1 + 17 files changed, 1663 insertions(+), 154 deletions(-) create mode 100755 tests/qemu-iotests/310 create mode 100644 tests/qemu-iotests/310.out
--=20
2.29.2
PATCH v9 1/11 block: push error reporting into bdrv_all_*_snapshot functions
The bdrv_all_*_snapshot functions return a BlockDriverState pointer for the invalid backend, which the callers then use to report an error message. In some cases multiple callers are reporting the same error message, but with slightly different text. In the future there will be more error scenarios for some of these methods, which will benefit from fine grained error message reporting. So it is helpful to push error reporting down a level.
--- block/monitor/block-hmp-cmds.c | 7 ++-- block/snapshot.c | 77 +++++++++++++++++----------------- include/block/snapshot.h | 14 +++---- migration/savevm.c | 39 +++++------------ monitor/hmp-cmds.c | 7 +--- replay/replay-debugging.c | 4 +- tests/qemu-iotests/267.out | 10 ++--- 7 files changed, 68 insertions(+), 90 deletions(-)
block/monitor/block-hmp-cmds.c +4 -3
@@ -899,10 +899,11 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict)ImageEntry *image_entry, *next_ie;SnapshotEntry *snapshot_entry; +Error *err =NULL ; - bs =bdrv_all_find_vmstate_bs (); + bs =bdrv_all_find_vmstate_bs (&err);if (!bs) { -monitor_printf (mon,"No available block device supports snapshots\n" ); +error_report_err (err);return ; } aio_context =bdrv_get_aio_context (bs);
@@ -952,7 +953,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict) total =0 ;for (i =0 ; i < nb_sns; i++) {SnapshotEntry *next_sn; -if (bdrv_all_find_snapshot (sn_tab[i].name, &bs1) ==0 ) { +if (bdrv_all_find_snapshot (sn_tab[i].name,NULL ) ==0 ) { global_snapshots[total] = i; total++; QTAILQ_FOREACH(image_entry, &image_list, next) {
block/snapshot.c +39 -38
185 lines not on this page · raw message
include/block/snapshot.h +6 -8
@@ -77,17 +77,15 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs,* These functions will properly handle dataplane (take aio_context_acquire * when appropriate for appropriate block drivers */ -bool bdrv_all_can_snapshot (BlockDriverState **first_bad_bs); -int bdrv_all_delete_snapshot (const char *name,BlockDriverState **first_bsd_bs, -Error **errp); -int bdrv_all_goto_snapshot (const char *name,BlockDriverState **first_bad_bs, -Error **errp); -int bdrv_all_find_snapshot (const char *name,BlockDriverState **first_bad_bs); +bool bdrv_all_can_snapshot (Error **errp); +int bdrv_all_delete_snapshot (const char *name,Error **errp); +int bdrv_all_goto_snapshot (const char *name,Error **errp); +int bdrv_all_find_snapshot (const char *name,Error **errp);int bdrv_all_create_snapshot (QEMUSnapshotInfo *sn,BlockDriverState *vm_state_bs,uint64_t vm_state_size, -BlockDriverState **first_bad_bs); +Error **errp); -BlockDriverState *bdrv_all_find_vmstate_bs (void ); +BlockDriverState *bdrv_all_find_vmstate_bs (Error **errp);#endif
migration/savevm.c +11 -28
@@ -2731,7 +2731,7 @@ int qemu_load_device_state(QEMUFile *f)int save_snapshot (const char *name,Error **errp) { -BlockDriverState *bs, *bs1; +BlockDriverState *bs;QEMUSnapshotInfo sn1, *sn = &sn1;int ret =-1 , ret2;QEMUFile *f;
@@ -2751,25 +2751,19 @@ int save_snapshot(const char *name, Error **errp)return ret; } -if (!bdrv_all_can_snapshot (&bs)) { -error_setg (errp,"Device '%s' is writable but does not support " -"snapshots" ,bdrv_get_device_or_node_name (bs)); +if (!bdrv_all_can_snapshot (errp)) {return ret; }/* Delete old snapshots of the same name */ if (name) { - ret =bdrv_all_delete_snapshot (name, &bs1, errp); -if (ret <0 ) { -error_prepend (errp,"Error while deleting snapshot on device " -"'%s': " ,bdrv_get_device_or_node_name (bs1)); +if (bdrv_all_delete_snapshot (name, errp) <0 ) {return ret; } } - bs =bdrv_all_find_vmstate_bs (); + bs =bdrv_all_find_vmstate_bs (errp);if (bs ==NULL ) { -error_setg (errp,"No block device can accept snapshots" );return ret; } aio_context =bdrv_get_aio_context (bs);
@@ -2833,11 +2827,9 @@ int save_snapshot(const char *name, Error **errp)aio_context_release (aio_context); aio_context =NULL ; - ret =bdrv_all_create_snapshot (sn, bs, vm_state_size, &bs); + ret =bdrv_all_create_snapshot (sn, bs, vm_state_size, errp);if (ret <0 ) { -error_setg (errp,"Error while creating snapshot on '%s'" , -bdrv_get_device_or_node_name (bs)); -bdrv_all_delete_snapshot (sn->name, &bs,NULL ); +bdrv_all_delete_snapshot (sn->name,NULL ); goto the_end; }
@@ -2940,30 +2932,23 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp)int load_snapshot (const char *name,Error **errp) { -BlockDriverState *bs, *bs_vm_state; +BlockDriverState *bs_vm_state;QEMUSnapshotInfo sn;QEMUFile *f;int ret;AioContext *aio_context;MigrationIncomingState *mis =migration_incoming_get_current (); -if (!bdrv_all_can_snapshot (&bs)) { -error_setg (errp, -"Device '%s' is writable but does not support snapshots" , -bdrv_get_device_or_node_name (bs)); +if (!bdrv_all_can_snapshot (errp)) {return -ENOTSUP ; } - ret =bdrv_all_find_snapshot (name, &bs); + ret =bdrv_all_find_snapshot (name, errp);if (ret <0 ) { -error_setg (errp, -"Device '%s' does not have the requested snapshot '%s'" , -bdrv_get_device_or_node_name (bs), name);return ret; } - bs_vm_state =bdrv_all_find_vmstate_bs (); + bs_vm_state =bdrv_all_find_vmstate_bs (errp);if (!bs_vm_state) { -error_setg (errp,"No block device supports snapshots" );return -ENOTSUP ; } aio_context =bdrv_get_aio_context (bs_vm_state);
@@ -2989,10 +2974,8 @@ int load_snapshot(const char *name, Error **errp)/* Flush all IO requests so they don't interfere with the new state. */ bdrv_drain_all_begin (); - ret =bdrv_all_goto_snapshot (name, &bs, errp); + ret =bdrv_all_goto_snapshot (name, errp);if (ret <0 ) { -error_prepend (errp,"Could not load snapshot '%s' on '%s': " , - name,bdrv_get_device_or_node_name (bs)); goto err_drain; }
monitor/hmp-cmds.c +1 -6
@@ -1146,15 +1146,10 @@ void hmp_savevm(Monitor *mon, const QDict *qdict)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)); - } +bdrv_all_delete_snapshot (name, &err);hmp_handle_error (mon, err); }
replay/replay-debugging.c +2 -2
@@ -148,7 +148,7 @@ static char *replay_find_nearest_snapshot(int64_t icount, *snapshot_icount =-1 ; - bs =bdrv_all_find_vmstate_bs (); + bs =bdrv_all_find_vmstate_bs (NULL );if (!bs) { goto fail; }
@@ -159,7 +159,7 @@ static char *replay_find_nearest_snapshot(int64_t icount,aio_context_release (aio_context);for (i =0 ; i < nb_sns; i++) { -if (bdrv_all_find_snapshot (sn_tab[i].name, &bs) ==0 ) { +if (bdrv_all_find_snapshot (sn_tab[i].name,NULL ) ==0 ) {if (sn_tab[i].icount !=-1ULL && sn_tab[i].icount <= icount && (!nearest || nearest->icount < sn_tab[i].icount)) {
tests/qemu-iotests/267.out +5 -5
@@ -6,9 +6,9 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 Testing: QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 -Error: No block device can accept snapshots +Error: No block device supports snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: No block device supports snapshots (qemu) quit
@@ -22,7 +22,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'none0' is writable but does not support snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: Device 'none0' is writable but does not support snapshots (qemu) quit
@@ -58,7 +58,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'virtio0' is writable but does not support snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: Device 'virtio0' is writable but does not support snapshots (qemu) quit
@@ -83,7 +83,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'file' is writable but does not support snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: Device 'file' is writable but does not support snapshots (qemu) quit
Signature · 1 line
2.29.2
PATCH v9 5/11 block: allow specifying name of block device for vmstate storage
In reply to Daniel P. BerrangéCurrently the vmstate will be stored in the first block device that supports snapshots. Historically this would have usually been the root device, but with UEFI it might be the variable store. There needs to be a way to override the choice of block device to store the state in.
--- block/monitor/block-hmp-cmds.c | 2 +- block/snapshot.c | 26 +++++++++++++++++++++++--- include/block/snapshot.h | 3 ++- migration/savevm.c | 4 ++-- replay/replay-debugging.c | 2 +- tests/qemu-iotests/267.out | 12 ++++++------ 6 files changed, 35 insertions(+), 14 deletions(-)
block/monitor/block-hmp-cmds.c +1 -1
@@ -901,7 +901,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict)SnapshotEntry *snapshot_entry;Error *err =NULL ; - bs =bdrv_all_find_vmstate_bs (false,NULL , &err); + bs =bdrv_all_find_vmstate_bs (NULL , false,NULL , &err);if (!bs) {error_report_err (err);return ;
block/snapshot.c +23 -3
@@ -678,7 +678,9 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn,return 0 ; } -BlockDriverState *bdrv_all_find_vmstate_bs (bool has_devices,strList *devices, + +BlockDriverState *bdrv_all_find_vmstate_bs (const char *vmstate_bs, +bool has_devices,strList *devices,Error **errp) {g_autoptr (GList) bdrvs =NULL ;
@@ -699,13 +701,31 @@ BlockDriverState *bdrv_all_find_vmstate_bs(bool has_devices, strList *devices,bdrv_can_snapshot (bs);aio_context_release (ctx); -if (found) { +if (vmstate_bs) { +if (g_str_equal (vmstate_bs, +bdrv_get_node_name (bs))) { +if (found) { +return bs; + }else { +error_setg (errp, +"vmstate block device '%s' does not support snapshots" , + vmstate_bs); +return NULL ; + } + } + }else if (found) {return bs; } iterbdrvs = iterbdrvs->next; } -error_setg (errp,"No block device supports snapshots" ); +if (vmstate_bs) { +error_setg (errp, +"vmstate block device '%s' does not exist" , vmstate_bs); + }else { +error_setg (errp, +"no block device can store vmstate for snapshot" ); + }return NULL ; }
include/block/snapshot.h +2 -1
@@ -95,7 +95,8 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, strList *devices, Error **errp); -BlockDriverState *bdrv_all_find_vmstate_bs (bool has_devices,strList *devices, +BlockDriverState *bdrv_all_find_vmstate_bs (const char *vmstate_bs, +bool has_devices,strList *devices,Error **errp);#endif
migration/savevm.c +2 -2
@@ -2762,7 +2762,7 @@ bool save_snapshot(const char *name, Error **errp) } } - bs =bdrv_all_find_vmstate_bs (false,NULL , errp); + bs =bdrv_all_find_vmstate_bs (NULL , false,NULL , errp);if (bs ==NULL ) {return false; }
@@ -2947,7 +2947,7 @@ bool load_snapshot(const char *name, Error **errp)return false; } - bs_vm_state =bdrv_all_find_vmstate_bs (false,NULL , errp); + bs_vm_state =bdrv_all_find_vmstate_bs (NULL , false,NULL , errp);if (!bs_vm_state) {return false; }
replay/replay-debugging.c +1 -1
@@ -148,7 +148,7 @@ static char *replay_find_nearest_snapshot(int64_t icount, *snapshot_icount =-1 ; - bs =bdrv_all_find_vmstate_bs (false,NULL ,NULL ); + bs =bdrv_all_find_vmstate_bs (NULL , false,NULL ,NULL );if (!bs) { goto fail; }
tests/qemu-iotests/267.out +6 -6
@@ -6,11 +6,11 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 Testing: QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 -Error: No block device supports snapshots +Error: no block device can store vmstate for snapshot (qemu) info snapshots -No block device supports snapshots +no block device can store vmstate for snapshot (qemu) loadvm snap0 -Error: No block device supports snapshots +Error: no block device can store vmstate for snapshot (qemu) quit
@@ -22,7 +22,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'none0' is writable but does not support snapshots (qemu) info snapshots -No block device supports snapshots +no block device can store vmstate for snapshot (qemu) loadvm snap0 Error: Device 'none0' is writable but does not support snapshots (qemu) quit
@@ -58,7 +58,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'virtio0' is writable but does not support snapshots (qemu) info snapshots -No block device supports snapshots +no block device can store vmstate for snapshot (qemu) loadvm snap0 Error: Device 'virtio0' is writable but does not support snapshots (qemu) quit
@@ -83,7 +83,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'file' is writable but does not support snapshots (qemu) info snapshots -No block device supports snapshots +no block device can store vmstate for snapshot (qemu) loadvm snap0 Error: Device 'file' is writable but does not support snapshots (qemu) quit
Signature · 1 line
2.29.2
PATCH v9 6/11 block: rename and alter bdrv_all_find_snapshot semantics
In reply to Daniel P. BerrangéCurrently bdrv_all_find_snapshot() will return 0 if it finds a snapshot, -1 if an error occurs, or if it fails to find a snapshot. New callers to be added want to distinguish between the error scenario and failing to find a snapshot.
Rename it to bdrv_all_has_snapshot and make it return -1 on error, 0 if no snapshot is found and 1 if snapshot is found.
--- block/monitor/block-hmp-cmds.c | 2 +- block/snapshot.c | 19 ++++++++++++------- include/block/snapshot.h | 6 +++--- migration/savevm.c | 7 ++++++- replay/replay-debugging.c | 6 +++++- 5 files changed, 27 insertions(+), 13 deletions(-)
block/monitor/block-hmp-cmds.c +1 -1
@@ -953,7 +953,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict) total =0 ;for (i =0 ; i < nb_sns; i++) {SnapshotEntry *next_sn; -if (bdrv_all_find_snapshot (sn_tab[i].name, false,NULL ,NULL ) ==0 ) { +if (bdrv_all_has_snapshot (sn_tab[i].name, false,NULL ,NULL ) ==1 ) { global_snapshots[total] = i; total++; QTAILQ_FOREACH(image_entry, &image_list, next) {
block/snapshot.c +12 -7
@@ -603,9 +603,9 @@ int bdrv_all_goto_snapshot(const char *name,return 0 ; } -int bdrv_all_find_snapshot (const char *name, -bool has_devices,strList *devices, -Error **errp) +int bdrv_all_has_snapshot (const char *name, +bool has_devices,strList *devices, +Error **errp) {g_autoptr (GList) bdrvs =NULL ;GList *iterbdrvs;
@@ -627,15 +627,20 @@ int bdrv_all_find_snapshot(const char *name, }aio_context_release (ctx);if (ret <0 ) { -error_setg (errp,"Could not find snapshot '%s' on '%s'" , - name,bdrv_get_device_or_node_name (bs)); -return -1 ; +if (ret == -ENOENT ) { +return 0 ; + }else { +error_setg_errno (errp, errno, +"Could not check snapshot '%s' on '%s'" , + name,bdrv_get_device_or_node_name (bs)); +return -1 ; + } } iterbdrvs = iterbdrvs->next; } -return 0 ; +return 1 ; } int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn,
include/block/snapshot.h +3 -3
@@ -85,9 +85,9 @@ int bdrv_all_delete_snapshot(const char *name,int bdrv_all_goto_snapshot (const char *name,bool has_devices,strList *devices,Error **errp); -int bdrv_all_find_snapshot (const char *name, -bool has_devices,strList *devices, -Error **errp); +int bdrv_all_has_snapshot (const char *name, +bool has_devices,strList *devices, +Error **errp); int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, BlockDriverState *vm_state_bs, uint64_t vm_state_size,
migration/savevm.c +6 -1
@@ -2942,10 +2942,15 @@ bool load_snapshot(const char *name, Error **errp)if (!bdrv_all_can_snapshot (false,NULL , errp)) {return false; } - ret =bdrv_all_find_snapshot (name, false,NULL , errp); + ret =bdrv_all_has_snapshot (name, false,NULL , errp);if (ret <0 ) {return false; } +if (ret ==0 ) { +error_setg (errp,"Snapshot '%s' does not exist in one or more devices" , + name); +return -1 ; + } bs_vm_state =bdrv_all_find_vmstate_bs (NULL , false,NULL , errp);if (!bs_vm_state) {
replay/replay-debugging.c +5 -1
@@ -143,6 +143,7 @@ static char *replay_find_nearest_snapshot(int64_t icount,QEMUSnapshotInfo *sn_tab;QEMUSnapshotInfo *nearest =NULL ;char *ret =NULL ; +int rv;int nb_sns, i;AioContext *aio_context;
@@ -159,7 +160,10 @@ static char *replay_find_nearest_snapshot(int64_t icount,aio_context_release (aio_context);for (i =0 ; i < nb_sns; i++) { -if (bdrv_all_find_snapshot (sn_tab[i].name, false,NULL ,NULL ) ==0 ) { + rv =bdrv_all_has_snapshot (sn_tab[i].name, false,NULL ,NULL ); +if (rv <0 ) + goto fail; +if (rv ==1 ) {if (sn_tab[i].icount !=-1ULL && sn_tab[i].icount <= icount && (!nearest || nearest->icount < sn_tab[i].icount)) {
Signature · 1 line
2.29.2
PATCH v9 2/11 migration: Make save_snapshot() return bool, not 0/-1
In reply to Daniel P. BerrangéFrom: Philippe Mathieu-Daudé <[email protected]>
Just for consistency, following the example documented since commit e3fe3988d7 ("error: Document Error API usage rules"), return a boolean value indicating an error is set or not.
--- include/migration/snapshot.h | 9 ++++++++- migration/savevm.c | 16 ++++++++-------- replay/replay-debugging.c | 2 +- replay/replay-snapshot.c | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-)
include/migration/snapshot.h +8 -1
@@ -15,7 +15,14 @@#ifndef QEMU_MIGRATION_SNAPSHOT_H #define QEMU_MIGRATION_SNAPSHOT_H -int save_snapshot (const char *name,Error **errp); +/** +* save_snapshot: Save an internal snapshot. +* @name: name of internal snapshot +* @errp: pointer to error object +* On success, return %true. +* On failure, store an error through @errp and return %false. +*/ +bool save_snapshot (const char *name,Error **errp);int load_snapshot (const char *name,Error **errp);#endif
migration/savevm.c +8 -8
@@ -2729,7 +2729,7 @@ int qemu_load_device_state(QEMUFile *f)return 0 ; } -int save_snapshot (const char *name,Error **errp) +bool save_snapshot (const char *name,Error **errp) {BlockDriverState *bs;QEMUSnapshotInfo sn1, *sn = &sn1;
@@ -2742,29 +2742,29 @@ int save_snapshot(const char *name, Error **errp)AioContext *aio_context;if (migration_is_blocked (errp)) { -return ret; +return false; }if (!replay_can_snapshot ()) {error_setg (errp,"Record/replay does not allow making snapshot " "right now. Try once more later." ); -return ret; +return false; }if (!bdrv_all_can_snapshot (errp)) { -return ret; +return false; }/* Delete old snapshots of the same name */ if (name) {if (bdrv_all_delete_snapshot (name, errp) <0 ) { -return ret; +return false; } } bs =bdrv_all_find_vmstate_bs (errp);if (bs ==NULL ) { -return ret; +return false; } aio_context =bdrv_get_aio_context (bs);
@@ -2773,7 +2773,7 @@ int save_snapshot(const char *name, Error **errp) ret =global_state_store ();if (ret) {error_setg (errp,"Error saving global state" ); -return ret; +return false; }vm_stop (RUN_STATE_SAVE_VM );
@@ -2845,7 +2845,7 @@ int save_snapshot(const char *name, Error **errp)if (saved_vm_running) {vm_start (); } -return ret; +return ret ==0 ; } void qmp_xen_save_devices_state(const char *filename, bool has_live, bool live,
replay/replay-debugging.c +1 -1
@@ -323,7 +323,7 @@ void replay_gdb_attached(void)*/ if (replay_mode ==REPLAY_MODE_PLAY && !replay_snapshot) { -if (save_snapshot ("start_debugging" ,NULL ) !=0 ) { +if (!save_snapshot ("start_debugging" ,NULL )) {/* Can't create the snapshot. Continue conventional debugging. */ } }
replay/replay-snapshot.c +1 -1
@@ -77,7 +77,7 @@ void replay_vmstate_init(void)if (replay_snapshot) {if (replay_mode ==REPLAY_MODE_RECORD ) { -if (save_snapshot (replay_snapshot, &err) !=0 ) { +if (!save_snapshot (replay_snapshot, &err)) {error_report_err (err);error_report ("Could not create snapshot for icount record" );exit (1 );
Signature · 1 line
2.29.2
PATCH v9 3/11 migration: stop returning errno from load_snapshot()
In reply to Daniel P. BerrangéNone of the callers care about the errno value since there is a full Error object populated. This gives consistency with save_snapshot() which already just returns a boolean value.
--- include/migration/snapshot.h | 10 +++++++++- migration/savevm.c | 19 +++++++++---------- monitor/hmp-cmds.c | 2 +- replay/replay-snapshot.c | 2 +- softmmu/vl.c | 2 +- 5 files changed, 21 insertions(+), 14 deletions(-)
include/migration/snapshot.h +9 -1
@@ -23,6 +23,14 @@* On failure, store an error through @errp and return %false. */ bool save_snapshot (const char *name,Error **errp); -int load_snapshot (const char *name,Error **errp); + +/** +* load_snapshot: Load an internal snapshot. +* @name: name of internal snapshot +* @errp: pointer to error object +* On success, return %true. +* On failure, store an error through @errp and return %false. +*/ +bool load_snapshot (const char *name,Error **errp);#endif
migration/savevm.c +9 -10
@@ -2930,7 +2930,7 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp)migration_incoming_state_destroy (); } -int load_snapshot (const char *name,Error **errp) +bool load_snapshot (const char *name,Error **errp) {BlockDriverState *bs_vm_state;QEMUSnapshotInfo sn;
@@ -2940,16 +2940,16 @@ int load_snapshot(const char *name, Error **errp)MigrationIncomingState *mis =migration_incoming_get_current ();if (!bdrv_all_can_snapshot (errp)) { -return -ENOTSUP ; +return false; } ret =bdrv_all_find_snapshot (name, errp);if (ret <0 ) { -return ret; +return false; } bs_vm_state =bdrv_all_find_vmstate_bs (errp);if (!bs_vm_state) { -return -ENOTSUP ; +return false; } aio_context =bdrv_get_aio_context (bs_vm_state);
@@ -2958,11 +2958,11 @@ int load_snapshot(const char *name, Error **errp) ret =bdrv_snapshot_find (bs_vm_state, &sn, name);aio_context_release (aio_context);if (ret <0 ) { -return ret; +return false; }else if (sn.vm_state_size ==0 ) {error_setg (errp,"This is a disk-only snapshot. Revert to it " " offline using qemu-img" ); -return -EINVAL ; +return false; }/*
@@ -2983,7 +2983,6 @@ int load_snapshot(const char *name, Error **errp) f =qemu_fopen_bdrv (bs_vm_state,0 );if (!f) {error_setg (errp,"Could not open VM state file" ); - ret = -EINVAL ; goto err_drain; }
@@ -3003,14 +3002,14 @@ int load_snapshot(const char *name, Error **errp)if (ret <0 ) {error_setg (errp,"Error %d while loading VM state" , ret); -return ret; +return false; } -return 0 ; +return true; err_drain:bdrv_drain_all_end (); -return ret; +return false; }void vmstate_register_ram (MemoryRegion *mr,DeviceState *dev)
monitor/hmp-cmds.c +1 -1
@@ -1130,7 +1130,7 @@ void hmp_loadvm(Monitor *mon, const QDict *qdict)vm_stop (RUN_STATE_RESTORE_VM ); -if (load_snapshot (name, &err) ==0 && saved_vm_running) { +if (!load_snapshot (name, &err) && saved_vm_running) {vm_start (); }hmp_handle_error (mon, err);
replay/replay-snapshot.c +1 -1
@@ -83,7 +83,7 @@ void replay_vmstate_init(void)exit (1 ); } }else if (replay_mode ==REPLAY_MODE_PLAY ) { -if (load_snapshot (replay_snapshot, &err) !=0 ) { +if (!load_snapshot (replay_snapshot, &err)) {error_report_err (err);error_report ("Could not load snapshot for icount replay" );exit (1 );
softmmu/vl.c +1 -1
@@ -2529,7 +2529,7 @@ void qmp_x_exit_preconfig(Error **errp)if (loadvm) {Error *local_err =NULL ; -if (load_snapshot (loadvm, &local_err) <0 ) { +if (!load_snapshot (loadvm, &local_err)) {error_report_err (local_err); autostart =0 ;exit (1 );
Signature · 1 line
2.29.2
PATCH v9 7/11 migration: control whether snapshots are ovewritten
In reply to Daniel P. BerrangéThe traditional HMP "savevm" command will overwrite an existing snapshot if it already exists with the requested name. This new flag allows this to be controlled allowing for safer behaviour with a future QMP command.
--- include/migration/snapshot.h | 3 ++- migration/savevm.c | 19 ++++++++++++++++--- monitor/hmp-cmds.c | 2 +- replay/replay-debugging.c | 2 +- replay/replay-snapshot.c | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-)
include/migration/snapshot.h +2 -1
@@ -18,11 +18,12 @@/** * save_snapshot: Save an internal snapshot. * @name: name of internal snapshot +* @overwrite: replace existing snapshot with @name * @errp: pointer to error object * On success, return %true. * On failure, store an error through @errp and return %false. */ -bool save_snapshot (const char *name,Error **errp); +bool save_snapshot (const char *name,bool overwrite,Error **errp);/** * load_snapshot: Load an internal snapshot.
migration/savevm.c +16 -3
@@ -2729,7 +2729,7 @@ int qemu_load_device_state(QEMUFile *f)return 0 ; } -bool save_snapshot (const char *name,Error **errp) +bool save_snapshot (const char *name,bool overwrite,Error **errp) {BlockDriverState *bs;QEMUSnapshotInfo sn1, *sn = &sn1;
@@ -2757,8 +2757,21 @@ bool save_snapshot(const char *name, Error **errp)/* Delete old snapshots of the same name */ if (name) { -if (bdrv_all_delete_snapshot (name, false,NULL , errp) <0 ) { -return false; +if (overwrite) { +if (bdrv_all_delete_snapshot (name, false,NULL , errp) <0 ) { +return false; + } + }else { + ret2 =bdrv_all_has_snapshot (name, false,NULL , errp); +if (ret2 <0 ) { +return false; + } +if (ret2 ==1 ) { +error_setg (errp, +"Snapshot '%s' already exists in one or more devices" , + name); +return false; + } } }
monitor/hmp-cmds.c +1 -1
@@ -1140,7 +1140,7 @@ void hmp_savevm(Monitor *mon, const QDict *qdict) {Error *err =NULL ; -save_snapshot (qdict_get_try_str (qdict,"name" ), &err); +save_snapshot (qdict_get_try_str (qdict,"name" ), true, &err);hmp_handle_error (mon, err); }
replay/replay-debugging.c +1 -1
@@ -327,7 +327,7 @@ void replay_gdb_attached(void)*/ if (replay_mode ==REPLAY_MODE_PLAY && !replay_snapshot) { -if (!save_snapshot ("start_debugging" ,NULL )) { +if (!save_snapshot ("start_debugging" , true,NULL )) {/* Can't create the snapshot. Continue conventional debugging. */ } }
replay/replay-snapshot.c +1 -1
@@ -77,7 +77,7 @@ void replay_vmstate_init(void)if (replay_snapshot) {if (replay_mode ==REPLAY_MODE_RECORD ) { -if (!save_snapshot (replay_snapshot, &err)) { +if (!save_snapshot (replay_snapshot, true, &err)) {error_report_err (err);error_report ("Could not create snapshot for icount record" );exit (1 );
Signature · 1 line
2.29.2
PATCH v9 10/11 iotests: add support for capturing and matching QMP events
In reply to Daniel P. BerrangéWhen using the _launch_qemu and _send_qemu_cmd functions from common.qemu, any QMP events get mixed in with the output from the commands and responses.
This makes it difficult to write a test case as the ordering of events in the output is not stable.
This introduces a variable 'capture_events' which can be set to a list of event names. Any events listed in this variable will not be printed, instead collected in the $QEMU_EVENTS environment variable.
A new '_wait_event' function can be invoked to collect events at a fixed point in time. The function will first pull events cached in $QEMU_EVENTS variable, and if none are found, will then read more from QMP.
--- tests/qemu-iotests/common.qemu | 107 ++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-)
tests/qemu-iotests/common.qemu +106 -1
@@ -53,6 +53,15 @@ _in_fd=4 # If $mismatch_only is set, only non-matching responses will # be echoed. # +# If $capture_events is non-empty, then any QMP event names it lists +# will not be echoed out, but instead collected in the $QEMU_EVENTS +# variable. The _wait_event function can later be used to received +# the cached events. +# +# If $only_capture_events is set to anything but an empty string, +# when an error will be raised if a QMP message is seen which is +# not an event listed in $capture_events. +# # If $success_or_failure is set, the meaning of the arguments is # changed as follows: # $2: A string to search for in the response; if found, this indicates
@@ -78,6 +87,32 @@ _timed_wait_for() QEMU_STATUS[$h]=0 while IFS= read -t ${QEMU_COMM_TIMEOUT} resp <&${QEMU_OUT[$h]} do + if [ -n "$capture_events" ]; then + capture=0 + local evname + for evname in $capture_events + do + grep -q "\"event\": \"${evname}\"" < <(echo "${resp}") + if [ $? -eq 0 ]; then + capture=1 + fi + done + if [ $capture = 1 ]; + then + ev=$(echo "${resp}" | tr -d '\r' | tr % .) + QEMU_EVENTS="${QEMU_EVENTS:+${QEMU_EVENTS}%}${ev}" + if [ -n "$only_capture_events" ]; then + return + else + continue + fi + fi + fi + if [ -n "$only_capture_events" ]; then + echo "Only expected $capture_events but got ${resp}" + exit 1 + fi + if [ -z "${silent}" ] && [ -z "${mismatch_only}" ]; then echo "${resp}" | _filter_testdir | _filter_qemu \ | _filter_qemu_io | _filter_qmp | _filter_hmp
@@ -172,12 +207,82 @@ _send_qemu_cmd() let count--; done if [ ${QEMU_STATUS[$h]} -ne 0 ] && [ -z "${qemu_error_no_exit}" ]; then - echo "Timeout waiting for ${1} on handle ${h}" + echo "Timeout waiting for command ${1} response on handle ${h}" exit 1 #Timeout means the test failed fi } +# Check event cache for a named QMP event +# +# Input parameters: +# $1: Name of the QMP event to check for +# +# Checks if the named QMP event that was previously captured +# into $QEMU_EVENTS. When matched, the QMP event will be echoed +# and the $matched variable set to 1. +# +# _wait_event is more suitable for test usage in most cases +_check_cached_events() +{ + local evname=${1} + + local match="\"event\": \"$evname\"" + + matched=0 + if [ -n "$QEMU_EVENTS" ]; then + CURRENT_QEMU_EVENTS=$QEMU_EVENTS + QEMU_EVENTS= + old_IFS=$IFS + IFS="%" + for ev in $CURRENT_QEMU_EVENTS + do + grep -q "$match" < <(echo "${ev}") + if [ $? -eq 0 -a $matched = 0 ]; then + echo "${ev}" | _filter_testdir | _filter_qemu \ + | _filter_qemu_io | _filter_qmp | _filter_hmp + matched=1 + else + QEMU_EVENTS="${QEMU_EVENTS:+${QEMU_EVENTS}%}${ev}" + fi + done + IFS=$old_IFS + fi +} + +# Wait for a named QMP event +# +# Input parameters: +# $1: QEMU handle to use +# $2: Name of the QMP event to wait for +# +# Checks if the named QMP event that was previously captured +# into $QEMU_EVENTS. If none are present, then waits for the +# event to arrive on the QMP channel. When matched, the QMP +# event will be echoed +_wait_event() +{ + local h=${1} + local evname=${2} + + while true + do + _check_cached_events $evname + + if [ $matched = 1 ]; + then + return + fi + + only_capture_events=1 qemu_error_no_exit=1 _timed_wait_for ${h} + + if [ ${QEMU_STATUS[$h]} -ne 0 ] ; then + echo "Timeout waiting for event ${evname} on handle ${h}" + exit 1 #Timeout means the test failed + fi + done +} + # Launch a QEMU process. # # Input parameters:
Signature · 1 line
2.29.2
PATCH v9 4/11 block: add ability to specify list of blockdevs during snapshot
In reply to Daniel P. BerrangéWhen running snapshot operations, there are various rules for which blockdevs are included/excluded. While this provides reasonable default behaviour, there are scenarios that are not well handled by the default logic. Some of the conditions do not have a single correct answer.
Thus there needs to be a way for the mgmt app to provide an explicit list of blockdevs to perform snapshots across. This can be achieved by passing a list of node names that should be used.
--- block/monitor/block-hmp-cmds.c | 4 +- block/snapshot.c | 172 ++++++++++++++++++++++++--------- include/block/snapshot.h | 22 +++-- migration/savevm.c | 18 ++-- monitor/hmp-cmds.c | 2 +- replay/replay-debugging.c | 4 +- 6 files changed, 159 insertions(+), 63 deletions(-)
block/monitor/block-hmp-cmds.c +2 -2
@@ -901,7 +901,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict)SnapshotEntry *snapshot_entry;Error *err =NULL ; - bs =bdrv_all_find_vmstate_bs (&err); + bs =bdrv_all_find_vmstate_bs (false,NULL , &err);if (!bs) {error_report_err (err);return ;
@@ -953,7 +953,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict) total =0 ;for (i =0 ; i < nb_sns; i++) {SnapshotEntry *next_sn; -if (bdrv_all_find_snapshot (sn_tab[i].name,NULL ) ==0 ) { +if (bdrv_all_find_snapshot (sn_tab[i].name, false,NULL ,NULL ) ==0 ) { global_snapshots[total] = i; total++; QTAILQ_FOREACH(image_entry, &image_list, next) {
block/snapshot.c +129 -43
292 lines not on this page · raw message
include/block/snapshot.h +16 -6
@@ -25,7 +25,7 @@#ifndef SNAPSHOT_H #define SNAPSHOT_H - +#include "qapi/qapi-builtin-types.h" #define SNAPSHOT_OPT_BASE "snapshot."#define SNAPSHOT_OPT_ID "snapshot.id"
@@ -77,15 +77,25 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs,* These functions will properly handle dataplane (take aio_context_acquire * when appropriate for appropriate block drivers */ -bool bdrv_all_can_snapshot (Error **errp); -int bdrv_all_delete_snapshot (const char *name,Error **errp); -int bdrv_all_goto_snapshot (const char *name,Error **errp); -int bdrv_all_find_snapshot (const char *name,Error **errp); +bool bdrv_all_can_snapshot (bool has_devices,strList *devices, +Error **errp); +int bdrv_all_delete_snapshot (const char *name, +bool has_devices,strList *devices, +Error **errp); +int bdrv_all_goto_snapshot (const char *name, +bool has_devices,strList *devices, +Error **errp); +int bdrv_all_find_snapshot (const char *name, +bool has_devices,strList *devices, +Error **errp);int bdrv_all_create_snapshot (QEMUSnapshotInfo *sn,BlockDriverState *vm_state_bs,uint64_t vm_state_size, +bool has_devices, +strList *devices,Error **errp); -BlockDriverState *bdrv_all_find_vmstate_bs (Error **errp); +BlockDriverState *bdrv_all_find_vmstate_bs (bool has_devices,strList *devices, +Error **errp);#endif
migration/savevm.c +9 -9
@@ -2751,18 +2751,18 @@ bool save_snapshot(const char *name, Error **errp)return false; } -if (!bdrv_all_can_snapshot (errp)) { +if (!bdrv_all_can_snapshot (false,NULL , errp)) {return false; }/* Delete old snapshots of the same name */ if (name) { -if (bdrv_all_delete_snapshot (name, errp) <0 ) { +if (bdrv_all_delete_snapshot (name, false,NULL , errp) <0 ) {return false; } } - bs =bdrv_all_find_vmstate_bs (errp); + bs =bdrv_all_find_vmstate_bs (false,NULL , errp);if (bs ==NULL ) {return false; }
@@ -2827,9 +2827,9 @@ bool save_snapshot(const char *name, Error **errp)aio_context_release (aio_context); aio_context =NULL ; - ret =bdrv_all_create_snapshot (sn, bs, vm_state_size, errp); + ret =bdrv_all_create_snapshot (sn, bs, vm_state_size, false,NULL , errp);if (ret <0 ) { -bdrv_all_delete_snapshot (sn->name,NULL ); +bdrv_all_delete_snapshot (sn->name, false,NULL ,NULL ); goto the_end; }
@@ -2939,15 +2939,15 @@ bool load_snapshot(const char *name, Error **errp)AioContext *aio_context;MigrationIncomingState *mis =migration_incoming_get_current (); -if (!bdrv_all_can_snapshot (errp)) { +if (!bdrv_all_can_snapshot (false,NULL , errp)) {return false; } - ret =bdrv_all_find_snapshot (name, errp); + ret =bdrv_all_find_snapshot (name, false,NULL , errp);if (ret <0 ) {return false; } - bs_vm_state =bdrv_all_find_vmstate_bs (errp); + bs_vm_state =bdrv_all_find_vmstate_bs (false,NULL , errp);if (!bs_vm_state) {return false; }
@@ -2974,7 +2974,7 @@ bool load_snapshot(const char *name, Error **errp)/* Flush all IO requests so they don't interfere with the new state. */ bdrv_drain_all_begin (); - ret =bdrv_all_goto_snapshot (name, errp); + ret =bdrv_all_goto_snapshot (name, false,NULL , errp);if (ret <0 ) { goto err_drain; }
monitor/hmp-cmds.c +1 -1
@@ -1149,7 +1149,7 @@ void hmp_delvm(Monitor *mon, const QDict *qdict)Error *err =NULL ;const char *name =qdict_get_str (qdict,"name" ); -bdrv_all_delete_snapshot (name, &err); +bdrv_all_delete_snapshot (name, false,NULL , &err);hmp_handle_error (mon, err); }
replay/replay-debugging.c +2 -2
@@ -148,7 +148,7 @@ static char *replay_find_nearest_snapshot(int64_t icount, *snapshot_icount =-1 ; - bs =bdrv_all_find_vmstate_bs (NULL ); + bs =bdrv_all_find_vmstate_bs (false,NULL ,NULL );if (!bs) { goto fail; }
@@ -159,7 +159,7 @@ static char *replay_find_nearest_snapshot(int64_t icount,aio_context_release (aio_context);for (i =0 ; i < nb_sns; i++) { -if (bdrv_all_find_snapshot (sn_tab[i].name,NULL ) ==0 ) { +if (bdrv_all_find_snapshot (sn_tab[i].name, false,NULL ,NULL ) ==0 ) {if (sn_tab[i].icount !=-1ULL && sn_tab[i].icount <= icount && (!nearest || nearest->icount < sn_tab[i].icount)) {
Signature · 1 line
2.29.2
PATCH v9 9/11 migration: introduce a delete_snapshot wrapper
In reply to Daniel P. BerrangéMake snapshot deletion consistent with the snapshot save and load commands by using a wrapper around the blockdev layer. The main difference is that we get upfront validation of the passed in device list (if any).
--- include/migration/snapshot.h | 13 +++++++++++++ migration/savevm.c | 14 ++++++++++++++ monitor/hmp-cmds.c | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-)
include/migration/snapshot.h +13 -0
@@ -48,4 +48,17 @@ bool load_snapshot(const char *name, bool has_devices, strList *devices, Error **errp); +/** +* delete_snapshot: Delete a snapshot. +* @name: path to snapshot +* @has_devices: whether to use explicit device list +* @devices: explicit device list to snapshot +* @errp: pointer to error object +* On success, return %true. +* On failure, store an error through @errp and return %false. +*/ +bool delete_snapshot (const char *name, +bool has_devices,strList *devices, +Error **errp); +#endif
migration/savevm.c +14 -0
@@ -3036,6 +3036,20 @@ err_drain:return false; } +bool delete_snapshot (const char *name,bool has_devices, +strList *devices,Error **errp) +{ +if (!bdrv_all_can_snapshot (has_devices, devices, errp)) { +return false; + } + +if (bdrv_all_delete_snapshot (name, has_devices, devices, errp) <0 ) { +return false; + } + +return true; +} +void vmstate_register_ram (MemoryRegion *mr,DeviceState *dev) { qemu_ram_set_idstr(mr->ram_block,
monitor/hmp-cmds.c +1 -1
@@ -1150,7 +1150,7 @@ void hmp_delvm(Monitor *mon, const QDict *qdict)Error *err =NULL ;const char *name =qdict_get_str (qdict,"name" ); -bdrv_all_delete_snapshot (name, false,NULL , &err); +delete_snapshot (name, false,NULL , &err);hmp_handle_error (mon, err); }
Signature · 1 line
2.29.2
PATCH v9 8/11 migration: wire up support for snapshot device selection
In reply to Daniel P. BerrangéModify load_snapshot/save_snapshot to accept the device list and vmstate node name parameters previously added to the block layer.
--- include/migration/snapshot.h | 18 ++++++++++++++++-- migration/savevm.c | 30 ++++++++++++++++++------------ monitor/hmp-cmds.c | 5 +++-- replay/replay-debugging.c | 4 ++-- replay/replay-snapshot.c | 5 +++-- softmmu/vl.c | 2 +- 6 files changed, 43 insertions(+), 21 deletions(-)
include/migration/snapshot.h +16 -2
@@ -15,23 +15,37 @@#ifndef QEMU_MIGRATION_SNAPSHOT_H #define QEMU_MIGRATION_SNAPSHOT_H +#include "qapi/qapi-builtin-types.h" +/** * save_snapshot: Save an internal snapshot. * @name: name of internal snapshot * @overwrite: replace existing snapshot with @name +* @vmstate: blockdev node name to store VM state in +* @has_devices: whether to use explicit device list +* @devices: explicit device list to snapshot * @errp: pointer to error object * On success, return %true. * On failure, store an error through @errp and return %false. */ -bool save_snapshot (const char *name,bool overwrite,Error **errp); +bool save_snapshot (const char *name,bool overwrite, +const char *vmstate, +bool has_devices,strList *devices, +Error **errp);/** * load_snapshot: Load an internal snapshot. * @name: name of internal snapshot +* @vmstate: blockdev node name to load VM state from +* @has_devices: whether to use explicit device list +* @devices: explicit device list to snapshot * @errp: pointer to error object * On success, return %true. * On failure, store an error through @errp and return %false. */ -bool load_snapshot (const char *name,Error **errp); +bool load_snapshot (const char *name, +const char *vmstate, +bool has_devices,strList *devices, +Error **errp);#endif
migration/savevm.c +18 -12
@@ -43,6 +43,8 @@#include "qapi/error.h" #include "qapi/qapi-commands-migration.h" #include "qapi/qmp/json-writer.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-builtin-visit.h" #include "qapi/qmp/qerror.h" #include "qemu/error-report.h" #include "sysemu/cpus.h"
@@ -2729,7 +2731,8 @@ int qemu_load_device_state(QEMUFile *f)return 0 ; } -bool save_snapshot (const char *name,bool overwrite,Error **errp) +bool save_snapshot (const char *name,bool overwrite,const char *vmstate, +bool has_devices,strList *devices,Error **errp) {BlockDriverState *bs;QEMUSnapshotInfo sn1, *sn = &sn1;
@@ -2751,18 +2754,19 @@ bool save_snapshot(const char *name, bool overwrite, Error **errp)return false; } -if (!bdrv_all_can_snapshot (false,NULL , errp)) { +if (!bdrv_all_can_snapshot (has_devices, devices, errp)) {return false; }/* Delete old snapshots of the same name */ if (name) {if (overwrite) { -if (bdrv_all_delete_snapshot (name, false,NULL , errp) <0 ) { +if (bdrv_all_delete_snapshot (name, has_devices, + devices, errp) <0 ) {return false; } }else { - ret2 =bdrv_all_has_snapshot (name, false,NULL , errp); + ret2 =bdrv_all_has_snapshot (name, has_devices, devices, errp);if (ret2 <0 ) {return false; }
@@ -2775,7 +2779,7 @@ bool save_snapshot(const char *name, bool overwrite, Error **errp) } } - bs =bdrv_all_find_vmstate_bs (NULL , false,NULL , errp); + bs =bdrv_all_find_vmstate_bs (vmstate, has_devices, devices, errp);if (bs ==NULL ) {return false; }
@@ -2840,9 +2844,10 @@ bool save_snapshot(const char *name, bool overwrite, Error **errp)aio_context_release (aio_context); aio_context =NULL ; - ret =bdrv_all_create_snapshot (sn, bs, vm_state_size, false,NULL , errp); + ret =bdrv_all_create_snapshot (sn, bs, vm_state_size, + has_devices, devices, errp);if (ret <0 ) { -bdrv_all_delete_snapshot (sn->name, false,NULL ,NULL ); +bdrv_all_delete_snapshot (sn->name, has_devices, devices,NULL ); goto the_end; }
@@ -2943,7 +2948,8 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp)migration_incoming_state_destroy (); } -bool load_snapshot (const char *name,Error **errp) +bool load_snapshot (const char *name,const char *vmstate, +bool has_devices,strList *devices,Error **errp) {BlockDriverState *bs_vm_state;QEMUSnapshotInfo sn;
@@ -2952,10 +2958,10 @@ bool load_snapshot(const char *name, Error **errp)AioContext *aio_context;MigrationIncomingState *mis =migration_incoming_get_current (); -if (!bdrv_all_can_snapshot (false,NULL , errp)) { +if (!bdrv_all_can_snapshot (has_devices, devices, errp)) {return false; } - ret =bdrv_all_has_snapshot (name, false,NULL , errp); + ret =bdrv_all_has_snapshot (name, has_devices, devices, errp);if (ret <0 ) {return false; }
@@ -2965,7 +2971,7 @@ bool load_snapshot(const char *name, Error **errp)return -1 ; } - bs_vm_state =bdrv_all_find_vmstate_bs (NULL , false,NULL , errp); + bs_vm_state =bdrv_all_find_vmstate_bs (vmstate, has_devices, devices, errp);if (!bs_vm_state) {return false; }
@@ -2992,7 +2998,7 @@ bool load_snapshot(const char *name, Error **errp)/* Flush all IO requests so they don't interfere with the new state. */ bdrv_drain_all_begin (); - ret =bdrv_all_goto_snapshot (name, false,NULL , errp); + ret =bdrv_all_goto_snapshot (name, has_devices, devices, errp);if (ret <0 ) { goto err_drain; }
monitor/hmp-cmds.c +3 -2
@@ -1130,7 +1130,7 @@ void hmp_loadvm(Monitor *mon, const QDict *qdict)vm_stop (RUN_STATE_RESTORE_VM ); -if (!load_snapshot (name, &err) && saved_vm_running) { +if (!load_snapshot (name,NULL , false,NULL , &err) && saved_vm_running) {vm_start (); }hmp_handle_error (mon, err);
@@ -1140,7 +1140,8 @@ void hmp_savevm(Monitor *mon, const QDict *qdict) {Error *err =NULL ; -save_snapshot (qdict_get_try_str (qdict,"name" ), true, &err); +save_snapshot (qdict_get_try_str (qdict,"name" ), + true,NULL , false,NULL , &err);hmp_handle_error (mon, err); }
replay/replay-debugging.c +2 -2
@@ -196,7 +196,7 @@ static void replay_seek(int64_t icount, QEMUTimerCB callback, Error **errp)if (icount <replay_get_current_icount () ||replay_get_current_icount () < snapshot_icount) {vm_stop (RUN_STATE_RESTORE_VM ); -load_snapshot (snapshot, errp); +load_snapshot (snapshot,NULL , false,NULL , errp); }g_free (snapshot); }
@@ -327,7 +327,7 @@ void replay_gdb_attached(void)*/ if (replay_mode ==REPLAY_MODE_PLAY && !replay_snapshot) { -if (!save_snapshot ("start_debugging" , true,NULL )) { +if (!save_snapshot ("start_debugging" , true,NULL , false,NULL ,NULL )) {/* Can't create the snapshot. Continue conventional debugging. */ } }
replay/replay-snapshot.c +3 -2
@@ -77,13 +77,14 @@ void replay_vmstate_init(void)if (replay_snapshot) {if (replay_mode ==REPLAY_MODE_RECORD ) { -if (!save_snapshot (replay_snapshot, true, &err)) { +if (!save_snapshot (replay_snapshot, + true,NULL , false,NULL , &err)) {error_report_err (err);error_report ("Could not create snapshot for icount record" );exit (1 ); } }else if (replay_mode ==REPLAY_MODE_PLAY ) { -if (!load_snapshot (replay_snapshot, &err)) { +if (!load_snapshot (replay_snapshot,NULL , false,NULL , &err)) {error_report_err (err);error_report ("Could not load snapshot for icount replay" );exit (1 );
softmmu/vl.c +1 -1
@@ -2529,7 +2529,7 @@ void qmp_x_exit_preconfig(Error **errp)if (loadvm) {Error *local_err =NULL ; -if (!load_snapshot (loadvm, &local_err)) { +if (!load_snapshot (loadvm,NULL , false,NULL , &local_err)) {error_report_err (local_err); autostart =0 ;exit (1 );
Signature · 1 line
2.29.2
PATCH v9 11/11 migration: introduce snapshot-{save, load, delete} QMP commands
In reply to Daniel P. Berrangésavevm, loadvm and delvm are some of the few HMP commands that have never been converted to use QMP. The reasons for the lack of conversion are that they blocked execution of the event thread, and the semantics around choice of disks were ill-defined.
Despite this downside, however, libvirt and applications using libvirt have 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 problems, they are not a blocker to all 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 new snapshot-{load,save,delete} commands to QMP that are intended to replace the old HMP counterparts. The new commands are given different names, because they will be using the new QEMU job framework and thus will have diverging behaviour from the HMP originals. It would thus be misleading to keep the same name.
While this design uses the generic job framework, the current impl is still blocking. The intention that the blocking problem is fixed later. None the less applications using these new commands should assume that they are asynchronous and thus wait for the job status change event to indicate completion.
In addition to using the job framework, the new commands require the caller to be explicit about all the block device nodes used in the snapshot operations, with no built-in default heuristics in use.
Note that the existing "query-named-block-nodes" can be used to query what snapshots currently exist for block nodes.
--- migration/savevm.c | 186 ++++++++++++- qapi/job.json | 9 +- qapi/migration.json | 121 +++++++++ slirp | 2 +- tests/qemu-iotests/310 | 385 +++++++++++++++++++++++++++ tests/qemu-iotests/310.out | 520 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 7 files changed, 1221 insertions(+), 3 deletions(-) create mode 100755 tests/qemu-iotests/310 create mode 100644 tests/qemu-iotests/310.out
migration/savevm.c +185 -1
@@ -2968,7 +2968,7 @@ bool load_snapshot(const char *name, const char *vmstate,if (ret ==0 ) {error_setg (errp,"Snapshot '%s' does not exist in one or more devices" , name); -return -1 ; +return false; } bs_vm_state =bdrv_all_find_vmstate_bs (vmstate, has_devices, devices, errp);
@@ -3077,3 +3077,187 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd)return !(vmsd && vmsd->unmigratable); } + +typedef struct SnapshotJob { +Job common; +char *tag; +char *vmstate; +strList *devices; +Coroutine *co; +Error **errp; +bool ret; +}SnapshotJob ; + +static void qmp_snapshot_job_free (SnapshotJob *s) +{ +g_free (s->tag); +g_free (s->vmstate); +qapi_free_strList (s->devices); +} + + +static void snapshot_load_job_bh (void *opaque) +{ +Job *job = opaque; +SnapshotJob *s =container_of (job, SnapshotJob, common); +int orig_vm_running; + +job_progress_set_remaining (&s->common,1 ); + + orig_vm_running =runstate_is_running (); +vm_stop (RUN_STATE_RESTORE_VM ); + + s->ret =load_snapshot (s->tag, s->vmstate, true, s->devices, s->errp); +if (s->ret && orig_vm_running) { +vm_start (); + } + +job_progress_update (&s->common,1 ); + +qmp_snapshot_job_free (s); +aio_co_wake (s->co); +} + +static void snapshot_save_job_bh (void *opaque) +{ +Job *job = opaque; +SnapshotJob *s =container_of (job, SnapshotJob, common); + +job_progress_set_remaining (&s->common,1 ); + s->ret =save_snapshot (s->tag, false, s->vmstate, + true, s->devices, s->errp); +job_progress_update (&s->common,1 ); + +qmp_snapshot_job_free (s); +aio_co_wake (s->co); +} + +static void snapshot_delete_job_bh (void *opaque) +{ +Job *job = opaque; +SnapshotJob *s =container_of (job, SnapshotJob, common); + +job_progress_set_remaining (&s->common,1 ); + s->ret =delete_snapshot (s->tag, true, s->devices, s->errp); +job_progress_update (&s->common,1 ); + +qmp_snapshot_job_free (s); +aio_co_wake (s->co); +} + +static int coroutine_fn snapshot_save_job_run(Job *job, Error **errp) +{ +SnapshotJob *s =container_of (job, SnapshotJob, common); + s->errp = errp; + s->co =qemu_coroutine_self (); +aio_bh_schedule_oneshot (qemu_get_aio_context (), + snapshot_save_job_bh, job); +qemu_coroutine_yield (); +return s->ret ?0 :-1 ; +} + +static int coroutine_fn snapshot_load_job_run(Job *job, Error **errp) +{ +SnapshotJob *s =container_of (job, SnapshotJob, common); + s->errp = errp; + s->co =qemu_coroutine_self (); +aio_bh_schedule_oneshot (qemu_get_aio_context (), + snapshot_load_job_bh, job); +qemu_coroutine_yield (); +return s->ret ?0 :-1 ; +} + +static int coroutine_fn snapshot_delete_job_run(Job *job, Error **errp) +{ +SnapshotJob *s =container_of (job, SnapshotJob, common); + s->errp = errp; + s->co =qemu_coroutine_self (); +aio_bh_schedule_oneshot (qemu_get_aio_context (), + snapshot_delete_job_bh, job); +qemu_coroutine_yield (); +return s->ret ?0 :-1 ; +} + + +static const JobDriver snapshot_load_job_driver = { + .instance_size =sizeof (SnapshotJob), + .job_type =JOB_TYPE_SNAPSHOT_LOAD , + .run = snapshot_load_job_run, +}; + +static const JobDriver snapshot_save_job_driver = { + .instance_size =sizeof (SnapshotJob), + .job_type =JOB_TYPE_SNAPSHOT_SAVE , + .run = snapshot_save_job_run, +}; + +static const JobDriver snapshot_delete_job_driver = { + .instance_size =sizeof (SnapshotJob), + .job_type =JOB_TYPE_SNAPSHOT_DELETE , + .run = snapshot_delete_job_run, +}; + + +void qmp_snapshot_save (const char *job_id, +const char *tag, +const char *vmstate, +strList *devices, +Error **errp) +{ +SnapshotJob *s; + + s =job_create (job_id, &snapshot_save_job_driver,NULL , +qemu_get_aio_context (),JOB_MANUAL_DISMISS , +NULL ,NULL , errp); +if (!s) { +return ; + } + + s->tag =g_strdup (tag); + s->vmstate =g_strdup (vmstate); + s->devices =QAPI_CLONE (strList, devices); + +job_start (&s->common); +} + +void qmp_snapshot_load (const char *job_id, +const char *tag, +const char *vmstate, +strList *devices, +Error **errp) +{ +SnapshotJob *s; + + s =job_create (job_id, &snapshot_load_job_driver,NULL , +qemu_get_aio_context (),JOB_MANUAL_DISMISS , +NULL ,NULL , errp); +if (!s) { +return ; + } + + s->tag =g_strdup (tag); + s->vmstate =g_strdup (vmstate); + s->devices =QAPI_CLONE (strList, devices); + +job_start (&s->common); +} + +void qmp_snapshot_delete (const char *job_id, +const char *tag, +strList *devices, +Error **errp) +{ +SnapshotJob *s; + + s =job_create (job_id, &snapshot_delete_job_driver,NULL , +qemu_get_aio_context (),JOB_MANUAL_DISMISS , +NULL ,NULL , errp); +if (!s) { +return ; + } + + s->tag =g_strdup (tag); + s->devices =QAPI_CLONE (strList, devices); + +job_start (&s->common); +}
qapi/job.json +8 -1
@@ -22,10 +22,17 @@ # # @amend: image options amend job type, see "x-blockdev-amend" (since 5.1) # +# @snapshot-load: snapshot load job type, see "snapshot-load" (since 5.2) +# +# @snapshot-save: snapshot save job type, see "snapshot-save" (since 5.2) +# +# @snapshot-delete: snapshot delete job type, see "snapshot-delete" (since 5.2) +# # Since: 1.7 ## { 'enum': 'JobType', - 'data': ['commit', 'stream', 'mirror', 'backup', 'create', 'amend'] } + 'data': ['commit', 'stream', 'mirror', 'backup', 'create', 'amend', + 'snapshot-load', 'snapshot-save', 'snapshot-delete'] } ## # @JobStatus:
qapi/migration.json +121 -0
124 lines not on this page · raw message
slirp +1 -1
@@ -1 +1 @@ -Subproject commit 8f43a99191afb47ca3f3c6972f6306209f367ece +Subproject commit ce94eba2042d52a0ba3d9e252ebce86715e94275
tests/qemu-iotests/310 new file +385 -0
385 lines not on this page · raw message
tests/qemu-iotests/310.out new file +520 -0
520 lines not on this page · raw message
tests/qemu-iotests/group +1 -0
@@ -318,4 +318,5 @@ 307 rw quick export 308 rw 309 rw auto quick +310 rw quick 312 rw quick
Signature · 1 line
2.29.2
Re: [PATCH v9 11/11] migration: introduce snapshot-{save, load, delete} QMP commands
Quoted 32 lines · Daniel P. Berrangé
savevm, loadvm and delvm are some of the few HMP commands that have never been converted to use QMP. The reasons for the lack of conversion are that they blocked execution of the event thread, and the semantics around choice of disks were ill-defined.
Despite this downside, however, libvirt and applications using libvirt have 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 problems, they are not a blocker to all 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 new snapshot-{load,save,delete} commands to QMP that are intended to replace the old HMP counterparts. The new commands are given different names, because they will be using the new QEMU job framework and thus will have diverging behaviour from the HMP originals. It would thus be misleading to keep the same name.
While this design uses the generic job framework, the current impl is still blocking. The intention that the blocking problem is fixed later. None the less applications using these new commands should assume that they are asynchronous and thus wait for the job status change event to indicate completion.
In addition to using the job framework, the new commands require the caller to be explicit about all the block device nodes used in the snapshot operations, with no built-in default heuristics in use.
Quoted 5 lines
Note that the existing "query-named-block-nodes" can be used to query what snapshots currently exist for block nodes.
Signed-off-by Daniel P. Berrangé <[email protected]>
Looks good to me, my Acked-by stands.
Re: [PATCH v9 09/11] migration: introduce a delete_snapshot wrapper
In reply to Daniel P. BerrangéQuoted 5 lines · Daniel P. Berrangé
Make snapshot deletion consistent with the snapshot save and load commands by using a wrapper around the blockdev layer. The main difference is that we get upfront validation of the passed in device list (if any).
Quoted 7 lines
Signed-off-by Daniel P. Berrangé <[email protected]>--- include/migration/snapshot.h | 13 +++++++++++++ migration/savevm.c | 14 ++++++++++++++ monitor/hmp-cmds.c | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v9 08/11] migration: wire up support for snapshot device selection
In reply to Daniel P. BerrangéQuoted 5 lines · Daniel P. Berrangé
Modify load_snapshot/save_snapshot to accept the device list and vmstate node name parameters previously added to the block layer.
Signed-off-by Daniel P. Berrangé <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v9 10/11] iotests: add support for capturing and matching QMP events
In reply to Daniel P. BerrangéQuoted 27 lines · Daniel P. Berrangé
When using the
_launch_qemuand_send_qemu_cmdfunctions from common.qemu, any QMP events get mixed in with the output from the commands and responses.This makes it difficult to write a test case as the ordering of events in the output is not stable.
This introduces a variable '
capture_events' which can be set to a list of event names. Any events listed in this variable will not be printed, instead collected in the $QEMU_EVENTS environment variable.A new '
_wait_event' function can be invoked to collect events at a fixed point in time. The function will first pull events cached in $QEMU_EVENTS variable, and if none are found, will then read more from QMP.Signed-off-by Daniel P. Berrangé <[email protected]>--- tests/qemu-iotests/common.qemu | 107 ++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-)tests/qemu-iotests/common.qemu +0
-0
tests/qemu-iotests/common.qemu _in_fd=4 · line 58
Quoted 6 lines
tests/qemu-iotests/common.qemu +3
-0@@ -53,6 +53,15 @@ _in_fd=4 # If $mismatch_only is set, only non-matching responses will # be echoed. # +# If $capture_events is non-empty, then any QMP event names it lists +# will not be echoed out, but instead collected in the $QEMU_EVENTS +# variable. The _wait_event function can later be used to received
receive
tests/qemu-iotests/common.qemu _in_fd=4 · line 62
Quoted 4 lines
tests/qemu-iotests/common.qemu +4
-0+# the cached events. +# +# If $only_capture_events is set to anything but an empty string, +# when an error will be raised if a QMP message is seen which is
s/when/then/
Quoted 6 lines
tests/qemu-iotests/common.qemu +2
-0+# not an event listed in $capture_events. +# # If $success_or_failure is set, the meaning of the arguments is # changed as follows: # $2: A string to search for in the response; if found, this indicates
tests/qemu-iotests/common.qemu _timed_wait_for() · line 95
Quoted 9 lines
tests/qemu-iotests/common.qemu +6
-0@@ -78,6 +87,32 @@ _timed_wait_for() QEMU_STATUS[$h]=0 while IFS= read -t ${QEMU_COMM_TIMEOUT} resp <&${QEMU_OUT[$h]} do + if [ -n "$capture_events" ]; then + capture=0 + local evname + for evname in $capture_events + do + grep -q "\"event\": \"${evname}\"" < <(echo "${resp}")
What you have works (thanks to the <() bashism), but could be done in fewer processes with:
case ${resp} in
*\"event\":\ \"${evname}\"* ) capture=1 ;;
esac
Quoted 50 lines
tests/qemu-iotests/common.qemu +37
-1+ if [ $? -eq 0 ]; then + capture=1 + fi + done + if [ $capture = 1 ]; + then + ev=$(echo "${resp}" | tr -d '\r' | tr % .) + QEMU_EVENTS="${QEMU_EVENTS:+${QEMU_EVENTS}%}${ev}" + if [ -n "$only_capture_events" ]; then + return + else + continue + fi + fi + fi + if [ -n "$only_capture_events" ]; then + echo "Only expected $capture_events but got ${resp}" + exit 1 + fi + if [ -z "${silent}" ] && [ -z "${mismatch_only}" ]; then echo "${resp}" | _filter_testdir | _filter_qemu \ | _filter_qemu_io | _filter_qmp | _filter_hmp@@ -172,12 +207,82 @@ _send_qemu_cmd() let count--; done if [ ${QEMU_STATUS[$h]} -ne 0 ] && [ -z "${qemu_error_no_exit}" ]; then - echo "Timeout waiting for ${1} on handle ${h}" + echo "Timeout waiting for command ${1} response on handle ${h}" exit 1 #Timeout means the test failed fi } +# Check event cache for a named QMP event +# +# Input parameters: +# $1: Name of the QMP event to check for +# +# Checks if the named QMP event that was previously captured +# into $QEMU_EVENTS. When matched, the QMP event will be echoed +# and the $matched variable set to 1. +# +# _wait_event is more suitable for test usage in most cases +_check_cached_events() +{ + local evname=${1} + + local match="\"event\": \"$evname\"" +
tests/qemu-iotests/common.qemu _send_qemu_cmd() · line 241
Quoted 10 lines
tests/qemu-iotests/common.qemu +10
-0+ matched=0 + if [ -n "$QEMU_EVENTS" ]; then + CURRENT_QEMU_EVENTS=$QEMU_EVENTS + QEMU_EVENTS= + old_IFS=$IFS + IFS="%" + for ev in $CURRENT_QEMU_EVENTS + do + grep -q "$match" < <(echo "${ev}") + if [ $? -eq 0 -a $matched = 0 ]; then
Odd indentation. Use of [ ... -a ... ] is not wise (it happens to work in current bash, but POSIX says it is deprecated); use [ ... ] && [ ... ] instead.
Quoted 8 lines
tests/qemu-iotests/common.qemu +8
-0+ echo "${ev}" | _filter_testdir | _filter_qemu \ + | _filter_qemu_io | _filter_qmp | _filter_hmp + matched=1 + else + QEMU_EVENTS="${QEMU_EVENTS:+${QEMU_EVENTS}%}${ev}" + fi + done + IFS=$old_IFS
tests/qemu-iotests/common.qemu _send_qemu_cmd() · line 259
Quoted 10 lines
tests/qemu-iotests/common.qemu +10
-0+ fi +} + +# Wait for a named QMP event +# +# Input parameters: +# $1: QEMU handle to use +# $2: Name of the QMP event to wait for +# +# Checks if the named QMP event that was previously captured
s/that //
Quoted 20 lines
tests/qemu-iotests/common.qemu +19
-0+# into $QEMU_EVENTS. If none are present, then waits for the +# event to arrive on the QMP channel. When matched, the QMP +# event will be echoed +_wait_event() +{ + local h=${1} + local evname=${2} + + while true + do + _check_cached_events $evname + + if [ $matched = 1 ]; + then + return + fi + + only_capture_events=1 qemu_error_no_exit=1 _timed_wait_for ${h} +
tests/qemu-iotests/common.qemu _send_qemu_cmd() · line 288
Quoted 10 lines
tests/qemu-iotests/common.qemu +7
-0+ if [ ${QEMU_STATUS[$h]} -ne 0 ] ; then + echo "Timeout waiting for event ${evname} on handle ${h}" + exit 1 #Timeout means the test failed + fi + done +} + # Launch a QEMU process. # # Input parameters:
Otherwise makes sense. Using case instead of 'grep -q < <(echo)' is not mandatory, and the rest of my comments are trivial, so with them cleaned up,
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v9 02/11] migration: Make save_snapshot() return bool, not 0/-1
In reply to Daniel P. BerrangéQuoted 18 lines · Daniel P. Berrangé
From: Philippe Mathieu-Daudé <[email protected]>
Just for consistency, following the example documented since commit
e3fe3988d7("error: Document Error API usage rules"), return a boolean value indicating an error is set or not.Acked-by Pavel Dovgalyuk <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/migration/snapshot.h | 9 ++++++++- migration/savevm.c | 16 ++++++++-------- replay/replay-debugging.c | 2 +- replay/replay-snapshot.c | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-)+++
b/migration/savevm.c
migration/savevm.c int qemu_load_device_state(QEMUFile *f) · line 2733
Quoted 6 lines
migration/savevm.c +1
-1@@ -2729,7 +2729,7 @@ int qemu_load_device_state(QEMUFile *f)return 0 ; } -int save_snapshot (const char *name,Error **errp) +bool save_snapshot (const char *name,Error **errp) {
Missing a 'return -1' that must be changed to 'return false' (see patch 11; if not fixed here, you have a window where you are inadvertently returning true on failure).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v9 06/11] block: rename and alter bdrv_all_find_snapshot semantics
In reply to Daniel P. BerrangéQuoted 16 lines · Daniel P. Berrangé
Currently
bdrv_all_find_snapshot()will return 0 if it finds a snapshot, -1 if an error occurs, or if it fails to find a snapshot. New callers to be added want to distinguish between the error scenario and failing to find a snapshot.Rename it to
bdrv_all_has_snapshotand make it return -1 on error, 0 if no snapshot is found and 1 if snapshot is found.Reviewed-by Eric Blake <[email protected]>Signed-off-by Daniel P. Berrangé <[email protected]>---
+++
b/migration/savevm.cmigration/savevm.c +0
-0@@ -2942,10 +2942,15 @@ bool load_snapshot(const char *name, Error **errp)if (!bdrv_all_can_snapshot (false,NULL , errp)) {return false;
migration/savevm.c bool load_snapshot(const char *name, Error **errp) · line 2952
Quoted 10 lines
migration/savevm.c +5
-1} - ret =bdrv_all_find_snapshot (name, false,NULL , errp); + ret =bdrv_all_has_snapshot (name, false,NULL , errp);if (ret <0 ) {return false; } +if (ret ==0 ) { +error_setg (errp,"Snapshot '%s' does not exist in one or more devices" , + name); +return -1 ;
s/-1/false/ (hoist that hunk from 11/11).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v9 02/11] migration: Make save_snapshot() return bool, not 0/-1
In reply to Eric BlakeQuoted 22 lines · Eric Blake
Quoted 21 lines · Daniel P. Berrangé
From: Philippe Mathieu-Daudé <[email protected]>
Just for consistency, following the example documented since commit
e3fe3988d7("error: Document Error API usage rules"), return a boolean value indicating an error is set or not.Acked-by Pavel Dovgalyuk <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/migration/snapshot.h | 9 ++++++++- migration/savevm.c | 16 ++++++++-------- replay/replay-debugging.c | 2 +- replay/replay-snapshot.c | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-)+++
b/migration/savevm.cmigration/savevm.c +0
-0@@ -2729,7 +2729,7 @@ int qemu_load_device_state(QEMUFile *f)return 0 ; }
Quoted 8 lines
migration/savevm.c int qemu_load_device_state(QEMUFile *f) · line 2733
Quoted 3 lines
migration/savevm.c +1
-1-int save_snapshot (const char *name,Error **errp) +bool save_snapshot (const char *name,Error **errp) {Missing a 'return -1' that must be changed to 'return false' (see patch 11; if not fixed here, you have a window where you are inadvertently returning true on failure).
Correction, it was patch 6/11 that introduced the 'return -1' that then got fixed in 11/11; patch 2/11 by itself is okay.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v9 11/11] migration: introduce snapshot-{save, load, delete} QMP commands
In reply to Daniel P. BerrangéQuoted 41 lines · Daniel P. Berrangé
savevm, loadvm and delvm are some of the few HMP commands that have never been converted to use QMP. The reasons for the lack of conversion are that they blocked execution of the event thread, and the semantics around choice of disks were ill-defined.
Despite this downside, however, libvirt and applications using libvirt have 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 problems, they are not a blocker to all 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 new snapshot-{load,save,delete} commands to QMP that are intended to replace the old HMP counterparts. The new commands are given different names, because they will be using the new QEMU job framework and thus will have diverging behaviour from the HMP originals. It would thus be misleading to keep the same name.
While this design uses the generic job framework, the current impl is still blocking. The intention that the blocking problem is fixed later. None the less applications using these new commands should assume that they are asynchronous and thus wait for the job status change event to indicate completion.
In addition to using the job framework, the new commands require the caller to be explicit about all the block device nodes used in the snapshot operations, with no built-in default heuristics in use.
Note that the existing "query-named-block-nodes" can be used to query what snapshots currently exist for block nodes.
Signed-off-by Daniel P. Berrangé <[email protected]>---
+++
b/migration/savevm.c
migration/savevm.c bool load_snapshot(const char *name, const char *vmstate, · line 2971
Quoted 5 lines
migration/savevm.c +1
-1@@ -2968,7 +2968,7 @@ bool load_snapshot(const char *name, const char *vmstate,if (ret ==0 ) {error_setg (errp,"Snapshot '%s' does not exist in one or more devices" , name); -return -1 ; +return false;
This hunk belongs in 6/11.
qapi/job.json line 29
Quoted 10 lines
qapi/job.json +6
-0+++ b/qapi/job.json@@ -22,10 +22,17 @@ # # @amend: image options amend job type, see "x-blockdev-amend" (since 5.1) # +# @snapshot-load: snapshot load job type, see "snapshot-load" (since 5.2) +# +# @snapshot-save: snapshot save job type, see "snapshot-save" (since 5.2) +# +# @snapshot-delete: snapshot delete job type, see "snapshot-delete" (since 5.2)
s/5.2/6.0/g
Quoted 34 lines
qapi/migration.json +30
-0+++ b/qapi/migration.json@@ -1843,3 +1843,124 @@ # Since: 5.2 ## { 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' } + +## +# @snapshot-save: +# +# Save a VM snapshot +# +# @job-id: identifier for the newly created job +# @tag: name of the snapshot to create +# @vmstate: block device node name to save vmstate to +# @devices: list of block device node names to save a snapshot to +# +# Applications should not assume that the snapshot save is complete +# when this command returns. The job commands / events must be used +# to determine completion and to fetch details of any errors that arise. +# +# Note that execution of the guest CPUs may be stopped during the +# time it takes to save the snapshot. A future version of QEMU +# may ensure CPUs are executing continuously. +# +# It is strongly recommended that @devices contain all writable +# block device nodes if a consistent snapshot is required. +# +# If @tag already exists, an error will be reported +# +# Returns: nothing +# +# Example: +# +# -> { "execute": "snapshot-save",
qapi/migration.json line 1884
Quoted 10 lines
qapi/migration.json +10
-0+# "data": { +# "job-id": "snapsave0", +# "tag": "my-snap", +# "vmstate": "disk0", +# "devices": ["disk0", "disk1"] +# } +# } +# <- { "return": { } } +# +# Since: 6.0
The example would be wise to further show waiting for the job completion event.
Quoted 32 lines
qapi/migration.json +32
-0+## +{ 'command': 'snapshot-save', + 'data': { 'job-id': 'str', + 'tag': 'str', + 'vmstate': 'str', + 'devices': ['str'] } } + +## +# @snapshot-load: +# +# Load a VM snapshot +# +# @job-id: identifier for the newly created job +# @tag: name of the snapshot to load. +# @vmstate: block device node name to load vmstate from +# @devices: list of block device node names to load a snapshot from +# +# Applications should not assume that the snapshot load is complete +# when this command returns. The job commands / events must be used +# to determine completion and to fetch details of any errors that arise. +# +# Note that execution of the guest CPUs will be stopped during the +# time it takes to load the snapshot. +# +# It is strongly recommended that @devices contain all writable +# block device nodes that can have changed since the original +# @snapshot-save command execution. +# +# Returns: nothing +# +# Example: +#
qapi/migration.json line 1926
Quoted 10 lines
qapi/migration.json +10
-0+# -> { "execute": "snapshot-load", +# "data": { +# "job-id": "snapload0", +# "tag": "my-snap", +# "vmstate": "disk0", +# "devices": ["disk0", "disk1"] +# } +# } +# <- { "return": { } } +#
Here as well.
Quoted 45 lines
qapi/migration.json +40
-0+# Since: 6.0 +## +{ 'command': 'snapshot-load', + 'data': { 'job-id': 'str', + 'tag': 'str', + 'vmstate': 'str', + 'devices': ['str'] } } + +## +# @snapshot-delete: +# +# Delete a VM snapshot +# +# @job-id: identifier for the newly created job +# @tag: name of the snapshot to delete. +# @devices: list of block device node names to delete a snapshot from +# +# Applications should not assume that the snapshot save is complete +# when this command returns. The job commands / events must be used +# to determine completion and to fetch details of any errors that arise. +# +# Returns: nothing +# +# Example: +# +# -> { "execute": "snapshot-delete", +# "data": { +# "job-id": "snapdelete0", +# "tag": "my-snap", +# "devices": ["disk0", "disk1"] +# } +# } +# <- { "return": { } } +# +# Since: 6.0 +## +{ 'command': 'snapshot-delete', + 'data': { 'job-id': 'str', + 'tag': 'str', + 'devices': ['str'] } }slirp +0
-0
slirp line 1
Quoted 2 lines
slirp +1
-1@@ -1 +1 @@ -Subproject commit 8f43a99191afb47ca3f3c6972f6306209f367ece +Subproject commit ce94eba2042d52a0ba3d9e252ebce86715e94275
Oops. This shouldn't be here.
tests/qemu-iotests/310 line 5
Quoted 11 lines
tests/qemu-iotests/310 new file +5
-0@@ -0,0 +1,385 @@ +#!/usr/bin/env bash +# +# Test which nodes are involved in internal snapshots +# +# Copyright (C) 2020 Red Hat, Inc.
Worth also mentioning 2021?
tests/qemu-iotests/310 line 84
Quoted 5 lines
tests/qemu-iotests/310 new file +5
-0+ # Next events vary depending on job type and + # whether it succeeds or not. + for evname in $@ + do + _wait_event $QEMU_HANDLE $evname
TAB damage throughout this file.
tests/qemu-iotests/310 line 252
Quoted 5 lines
tests/qemu-iotests/310 new file +5
-0+echo +echo "===== Snapshot dual qcow2 image =====" +echo + +# We can snapshot multiple qcow2 disks at the same time
extra space
tests/qemu-iotests/310 line 322
Quoted 7 lines
tests/qemu-iotests/310 new file +2
-0+++ b/tests/qemu-iotests/group@@ -318,4 +318,5 @@ 307 rw quick export 308 rw 309 rw auto quick +310 rw quick 312 rw quick
Vladimir's work to get rid of the 'group' file will be a trivial merge conflict, if it lands first.
Nearly there!
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v9 02/11] migration: Make save_snapshot() return bool, not 0/-1
In reply to Daniel P. BerrangéQuoted 8 lines · * Daniel P. Berrangé ([email protected]) wrote:
From: Philippe Mathieu-Daudé <[email protected]>
Just for consistency, following the example documented since commit
e3fe3988d7("error: Document Error API usage rules"), return a boolean value indicating an error is set or not.Acked-by Pavel Dovgalyuk <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 122 lines
--- include/migration/snapshot.h | 9 ++++++++- migration/savevm.c | 16 ++++++++-------- replay/replay-debugging.c | 2 +- replay/replay-snapshot.c | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-)include/migration/snapshot.h +8
-1@@ -15,7 +15,14 @@#ifndef QEMU_MIGRATION_SNAPSHOT_H #define QEMU_MIGRATION_SNAPSHOT_H -int save_snapshot (const char *name,Error **errp); +/** +* save_snapshot: Save an internal snapshot. +* @name: name of internal snapshot +* @errp: pointer to error object +* On success, return %true. +* On failure, store an error through @errp and return %false. +*/ +bool save_snapshot (const char *name,Error **errp);int load_snapshot (const char *name,Error **errp);#endif migration/savevm.c +8
-8@@ -2729,7 +2729,7 @@ int qemu_load_device_state(QEMUFile *f)return 0 ; } -int save_snapshot (const char *name,Error **errp) +bool save_snapshot (const char *name,Error **errp) {BlockDriverState *bs;QEMUSnapshotInfo sn1, *sn = &sn1;@@ -2742,29 +2742,29 @@ int save_snapshot(const char *name, Error **errp)AioContext *aio_context;if (migration_is_blocked (errp)) { -return ret; +return false; }if (!replay_can_snapshot ()) {error_setg (errp,"Record/replay does not allow making snapshot " "right now. Try once more later." ); -return ret; +return false; }if (!bdrv_all_can_snapshot (errp)) { -return ret; +return false; }/* Delete old snapshots of the same name */ if (name) {if (bdrv_all_delete_snapshot (name, errp) <0 ) { -return ret; +return false; } } bs =bdrv_all_find_vmstate_bs (errp);if (bs ==NULL ) { -return ret; +return false; } aio_context =bdrv_get_aio_context (bs);@@ -2773,7 +2773,7 @@ int save_snapshot(const char *name, Error **errp) ret =global_state_store ();if (ret) {error_setg (errp,"Error saving global state" ); -return ret; +return false; }vm_stop (RUN_STATE_SAVE_VM );@@ -2845,7 +2845,7 @@ int save_snapshot(const char *name, Error **errp)if (saved_vm_running) {vm_start (); } -return ret; +return ret ==0 ; } void qmp_xen_save_devices_state(const char *filename, bool has_live, bool live,replay/replay-debugging.c +1
-1@@ -323,7 +323,7 @@ void replay_gdb_attached(void)*/ if (replay_mode ==REPLAY_MODE_PLAY && !replay_snapshot) { -if (save_snapshot ("start_debugging" ,NULL ) !=0 ) { +if (!save_snapshot ("start_debugging" ,NULL )) {/* Can't create the snapshot. Continue conventional debugging. */ } }replay/replay-snapshot.c +1
-1@@ -77,7 +77,7 @@ void replay_vmstate_init(void)if (replay_snapshot) {if (replay_mode ==REPLAY_MODE_RECORD ) { -if (save_snapshot (replay_snapshot, &err) !=0 ) { +if (!save_snapshot (replay_snapshot, &err)) {error_report_err (err);error_report ("Could not create snapshot for icount record" );exit (1 );Signature · 1 line
2.29.2
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK