@@ -900,7 +900,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(NULL, &err);
if (!bs) {
error_report_err(err);
return;
@@ -952,7 +952,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, NULL, NULL) == 0) {
global_snapshots[total] = i;
total++;
QTAILQ_FOREACH(image_entry, &image_list, next) {
@@ -385,22 +385,34 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs,
return ret;
}
-static bool bdrv_all_snapshots_includes_bs(BlockDriverState *bs)
+static bool bdrv_all_snapshots_includes_bs(BlockDriverState *bs,
+ strList *devices)
{
- if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) {
+ if (devices) {
+ const char *node_name = bdrv_get_node_name(bs);
+ while (devices) {
+ if (g_str_equal(node_name, devices->value)) {
+ return true;
+ }
+ devices = devices->next;
+ }
return false;
- }
+ } else {
+ if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) {
+ return false;
+ }
- /* Include all nodes that are either in use by a BlockBackend, or that
- * aren't attached to any node, but owned by the monitor. */
- return bdrv_has_blk(bs) || QLIST_EMPTY(&bs->parents);
+ /* Include all nodes that are either in use by a BlockBackend, or that
+ * aren't attached to any node, but owned by the monitor. */
+ return bdrv_has_blk(bs) || QLIST_EMPTY(&bs->parents);
+ }
}
/* Group operations. All block drivers are involved.
* These functions will properly handle dataplane (take aio_context_acquire
* when appropriate for appropriate block drivers) */
-bool bdrv_all_can_snapshot(Error **errp)
+bool bdrv_all_can_snapshot(strList *devices, Error **errp)
{
BlockDriverState *bs;
BdrvNextIterator it;
@@ -410,7 +422,7 @@ bool bdrv_all_can_snapshot(Error **errp)
bool ok;
aio_context_acquire(ctx);
- if (bdrv_all_snapshots_includes_bs(bs)) {
+ if (bdrv_all_snapshots_includes_bs(bs, devices)) {
ok = bdrv_can_snapshot(bs);
}
aio_context_release(ctx);
@@ -425,7 +437,7 @@ bool bdrv_all_can_snapshot(Error **errp)
return true;
}
-int bdrv_all_delete_snapshot(const char *name, Error **errp)
+int bdrv_all_delete_snapshot(const char *name, strList *devices, Error **errp)
{
BlockDriverState *bs;
BdrvNextIterator it;
@@ -436,7 +448,7 @@ int bdrv_all_delete_snapshot(const char *name, Error **errp)
int ret;
aio_context_acquire(ctx);
- if (bdrv_all_snapshots_includes_bs(bs) &&
+ if (bdrv_all_snapshots_includes_bs(bs, devices) &&
bdrv_snapshot_find(bs, snapshot, name) >= 0)
{
ret = bdrv_snapshot_delete(bs, snapshot->id_str,
@@ -455,7 +467,7 @@ int bdrv_all_delete_snapshot(const char *name, Error **errp)
}
-int bdrv_all_goto_snapshot(const char *name, Error **errp)
+int bdrv_all_goto_snapshot(const char *name, strList *devices, Error **errp)
{
BlockDriverState *bs;
BdrvNextIterator it;
@@ -465,7 +477,7 @@ int bdrv_all_goto_snapshot(const char *name, Error **errp)
int ret;
aio_context_acquire(ctx);
- if (bdrv_all_snapshots_includes_bs(bs)) {
+ if (bdrv_all_snapshots_includes_bs(bs, devices)) {
ret = bdrv_snapshot_goto(bs, name, errp);
}
aio_context_release(ctx);
@@ -480,7 +492,7 @@ int bdrv_all_goto_snapshot(const char *name, Error **errp)
return 0;
}
-int bdrv_all_find_snapshot(const char *name, Error **errp)
+int bdrv_all_find_snapshot(const char *name, strList *devices, Error **errp)
{
QEMUSnapshotInfo sn;
BlockDriverState *bs;
@@ -491,7 +503,7 @@ int bdrv_all_find_snapshot(const char *name, Error **errp)
int ret;
aio_context_acquire(ctx);
- if (bdrv_all_snapshots_includes_bs(bs)) {
+ if (bdrv_all_snapshots_includes_bs(bs, devices)) {
ret = bdrv_snapshot_find(bs, &sn, name);
}
aio_context_release(ctx);
@@ -509,6 +521,7 @@ 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,
+ strList *devices,
Error **errp)
{
BlockDriverState *bs;
@@ -522,7 +535,7 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn,
if (bs == vm_state_bs) {
sn->vm_state_size = vm_state_size;
ret = bdrv_snapshot_create(bs, sn);
- } else if (bdrv_all_snapshots_includes_bs(bs)) {
+ } else if (bdrv_all_snapshots_includes_bs(bs, devices)) {
sn->vm_state_size = 0;
ret = bdrv_snapshot_create(bs, sn);
}
@@ -538,7 +551,7 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn,
return 0;
}
-BlockDriverState *bdrv_all_find_vmstate_bs(Error **errp)
+BlockDriverState *bdrv_all_find_vmstate_bs(strList *devices, Error **errp)
{
BlockDriverState *bs;
BdrvNextIterator it;
@@ -548,7 +561,8 @@ BlockDriverState *bdrv_all_find_vmstate_bs(Error **errp)
bool found;
aio_context_acquire(ctx);
- found = bdrv_all_snapshots_includes_bs(bs) && bdrv_can_snapshot(bs);
+ found = bdrv_all_snapshots_includes_bs(bs, devices) &&
+ bdrv_can_snapshot(bs);
aio_context_release(ctx);
if (found) {
@@ -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"
@@ -76,15 +76,16 @@ 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(strList *devices, Error **errp);
+int bdrv_all_delete_snapshot(const char *name, strList *devices, Error **errp);
+int bdrv_all_goto_snapshot(const char *name, strList *devices, Error **errp);
+int bdrv_all_find_snapshot(const char *name, strList *devices, Error **errp);
int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn,
BlockDriverState *vm_state_bs,
uint64_t vm_state_size,
+ strList *devices,
Error **errp);
-BlockDriverState *bdrv_all_find_vmstate_bs(Error **errp);
+BlockDriverState *bdrv_all_find_vmstate_bs(strList *devices, Error **errp);
#endif
@@ -2653,18 +2653,18 @@ int save_snapshot(const char *name, Error **errp)
return ret;
}
- if (!bdrv_all_can_snapshot(errp)) {
+ if (!bdrv_all_can_snapshot(NULL, errp)) {
return ret;
}
/* Delete old snapshots of the same name */
if (name) {
- if (bdrv_all_delete_snapshot(name, errp) < 0) {
+ if (bdrv_all_delete_snapshot(name, NULL, errp) < 0) {
return ret;
}
}
- bs = bdrv_all_find_vmstate_bs(errp);
+ bs = bdrv_all_find_vmstate_bs(NULL, errp);
if (bs == NULL) {
return ret;
}
@@ -2730,7 +2730,7 @@ 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, errp);
+ ret = bdrv_all_create_snapshot(sn, bs, vm_state_size, NULL, errp);
if (ret < 0) {
goto the_end;
}
@@ -2846,15 +2846,15 @@ int load_snapshot(const char *name, Error **errp)
return -1;
}
- if (!bdrv_all_can_snapshot(errp)) {
+ if (!bdrv_all_can_snapshot(NULL, errp)) {
return -1;
}
- ret = bdrv_all_find_snapshot(name, errp);
+ ret = bdrv_all_find_snapshot(name, NULL, errp);
if (ret < 0) {
return -1;
}
- bs_vm_state = bdrv_all_find_vmstate_bs(errp);
+ bs_vm_state = bdrv_all_find_vmstate_bs(NULL, errp);
if (!bs_vm_state) {
return -1;
}
@@ -2875,7 +2875,7 @@ 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, errp);
+ ret = bdrv_all_goto_snapshot(name, NULL, errp);
if (ret < 0) {
goto err_drain;
}
@@ -1114,7 +1114,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, NULL, &err);
hmp_handle_error(mon, err);
}
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. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- block/monitor/block-hmp-cmds.c | 4 +-- block/snapshot.c | 48 ++++++++++++++++++++++------------ include/block/snapshot.h | 13 ++++----- migration/savevm.c | 16 ++++++------ monitor/hmp-cmds.c | 2 +- 5 files changed, 49 insertions(+), 34 deletions(-)