Signed-off-by: Nikolay Shirokovskiy <nikolay.shirokovskiy(a)openvz.org>
---
src/qemu/qemu_snapshot.c | 54 ++++++++++++++++++++++++++++++++++------
1 file changed, 46 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 605288f6c5..fb34c21495 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -267,6 +267,50 @@ qemuSnapshotWaitJob(virQEMUDriver *driver,
}
+static int
+qemuSnapshotDiscardDataActive(virQEMUDriver *driver,
+ virDomainObj *vm,
+ virDomainMomentObj *snap)
+{
+ qemuDomainObjPrivate *priv = vm->privateData;
+ bool modern = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_SNAPSHOT_SAVE);
+ virDomainSnapshotDef *snapdef = virDomainSnapshotObjGetDef(snap);
+ g_autoptr(GPtrArray) devices = g_ptr_array_new();
+ int rc;
+
+ if (!modern) {
+ if (qemuDomainObjEnterMonitorAsync(driver, vm,
+ VIR_ASYNC_JOB_SNAPSHOT_DELETE) < 0)
+ return -1;
+
+ rc = qemuMonitorDeleteSnapshot(priv->mon, snap->def->name);
+ qemuDomainObjExitMonitor(vm);
+ if (rc < 0)
+ return -1;
+
+ return 0;
+ }
+
+ if (!(devices = qemuSnapshotGetDisksNodes(snapdef, vm->def, NULL)))
+ return -1;
+
+ if (qemuDomainObjEnterMonitorAsync(driver, vm,
+ VIR_ASYNC_JOB_SNAPSHOT_DELETE) < 0)
+ return -1;
+ rc = qemuMonitorSnapshotDelete(priv->mon,
+ "snapshot-delete",
+ snap->def->name,
+ (const char **)devices->pdata,
+ devices->len);
+ qemuDomainObjExitMonitor(vm);
+ if (rc < 0)
+ return -1;
+
+ return qemuSnapshotWaitJob(driver, vm, VIR_ASYNC_JOB_SNAPSHOT_DELETE,
+ "snapshot-delete");
+}
+
+
/* Discard one snapshot (or its metadata), without reparenting any children. */
static int
qemuSnapshotDiscard(virQEMUDriver *driver,
@@ -276,7 +320,6 @@ qemuSnapshotDiscard(virQEMUDriver *driver,
bool metadata_only)
{
g_autofree char *snapFile = NULL;
- qemuDomainObjPrivate *priv;
virDomainMomentObj *parentsnap = NULL;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
@@ -301,13 +344,8 @@ qemuSnapshotDiscard(virQEMUDriver *driver,
if (qemuSnapshotForEachQcow2(driver, def, snap, "-d", true) <
0)
return -1;
} else {
- priv = vm->privateData;
- if (qemuDomainObjEnterMonitorAsync(driver, vm,
- VIR_ASYNC_JOB_SNAPSHOT) == 0) {
- /* we continue on even in the face of error */
- qemuMonitorDeleteSnapshot(priv->mon, snap->def->name);
- qemuDomainObjExitMonitor(vm);
- }
+ /* we continue on even in the face of error */
+ qemuSnapshotDiscardDataActive(driver, vm, snap);
}
}
--
2.35.1