@@ -899,7 +899,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
ImageEntry *image_entry, *next_ie;
SnapshotEntry *snapshot_entry;
- bs = bdrv_all_find_vmstate_bs(NULL);
+ bs = bdrv_all_find_vmstate_bs(NULL, NULL, NULL);
if (!bs) {
monitor_printf(mon, "No available block device supports snapshots\n");
return;
@@ -552,7 +552,9 @@ fail:
return err;
}
-BlockDriverState *bdrv_all_find_vmstate_bs(strList *exclude_bs)
+BlockDriverState *bdrv_all_find_vmstate_bs(const char *vmstate_bs,
+ strList *exclude_bs,
+ Error **errp)
{
BlockDriverState *bs;
BdrvNextIterator it;
@@ -560,16 +562,39 @@ BlockDriverState *bdrv_all_find_vmstate_bs(strList *exclude_bs)
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
AioContext *ctx = bdrv_get_aio_context(bs);
bool found;
+ Error *err = NULL;
aio_context_acquire(ctx);
- found = bdrv_all_snapshots_includes_bs(bs, exclude_bs) &&
- bdrv_can_snapshot(bs);
+ if (vmstate_bs == NULL) {
+ found = bdrv_all_snapshots_includes_bs(bs, exclude_bs) &&
+ bdrv_can_snapshot(bs);
+ } else {
+ if (g_str_equal(vmstate_bs, bdrv_get_node_name(bs))) {
+ found = bdrv_all_snapshots_includes_bs(bs, exclude_bs) &&
+ bdrv_can_snapshot(bs);
+ if (!found) {
+ error_setg(&err,
+ "block device '%s' cannot accept snapshots",
+ vmstate_bs);
+ }
+ } else {
+ found = false;
+ }
+ }
aio_context_release(ctx);
- if (found) {
+ if (found || err) {
bdrv_next_cleanup(&it);
+ if (err) {
+ error_propagate(errp, err);
+ return NULL;
+ }
break;
}
}
+
+ if (!bs) {
+ error_setg(errp, "No block device can accept snapshots");
+ }
return bs;
}
@@ -90,6 +90,8 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn,
strList *exclude_bs,
BlockDriverState **first_bad_bs);
-BlockDriverState *bdrv_all_find_vmstate_bs(strList *exclude_bs);
+BlockDriverState *bdrv_all_find_vmstate_bs(const char *vmstate_bs,
+ strList *exclude_bs,
+ Error **errp);
#endif
@@ -2662,9 +2662,8 @@ int save_snapshot(const char *name, Error **errp)
}
}
- bs = bdrv_all_find_vmstate_bs(NULL);
+ bs = bdrv_all_find_vmstate_bs(NULL, NULL, errp);
if (bs == NULL) {
- error_setg(errp, "No block device can accept snapshots");
return ret;
}
aio_context = bdrv_get_aio_context(bs);
@@ -2857,9 +2856,8 @@ int load_snapshot(const char *name, Error **errp)
return ret;
}
- bs_vm_state = bdrv_all_find_vmstate_bs(NULL);
+ bs_vm_state = bdrv_all_find_vmstate_bs(NULL, NULL, errp);
if (!bs_vm_state) {
- error_setg(errp, "No block device supports snapshots");
return -ENOTSUP;
}
aio_context = bdrv_get_aio_context(bs_vm_state);
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. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- block/monitor/block-hmp-cmds.c | 2 +- block/snapshot.c | 33 +++++++++++++++++++++++++++++---- include/block/snapshot.h | 4 +++- migration/savevm.c | 6 ++---- 4 files changed, 35 insertions(+), 10 deletions(-)