Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/qemu/qemu_snapshot.c | 94 ++++++++++++++++++++++------------------
1 file changed, 53 insertions(+), 41 deletions(-)
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index b5e6a87566..d40d75e75d 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -2310,18 +2310,62 @@ qemuSnapshotDeleteSingle(virDomainObj *vm,
}
-int
-qemuSnapshotDelete(virDomainObj *vm,
- virDomainSnapshotPtr snapshot,
- unsigned int flags)
+static int
+qemuSnapshotDeleteChildren(virDomainObj *vm,
+ virDomainMomentObj *snap,
+ virQEMUDriver *driver,
+ bool metadata_only,
+ unsigned int flags)
{
- virQEMUDriver *driver = snapshot->domain->conn->privateData;
- int ret = -1;
- virDomainMomentObj *snap = NULL;
virQEMUMomentRemove rem;
+ g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
+
+ rem.driver = driver;
+ rem.vm = vm;
+ rem.metadata_only = metadata_only;
+ rem.err = 0;
+ rem.current = virDomainSnapshotGetCurrent(vm->snapshots);
+ rem.found = false;
+ rem.momentDiscard = qemuDomainSnapshotDiscard;
+ virDomainMomentForEachDescendant(snap, qemuDomainMomentDiscardAll,
+ &rem);
+ if (rem.err < 0)
+ return -1;
+ if (rem.found) {
+ qemuSnapshotSetCurrent(vm, snap);
+
+ if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) {
+ if (qemuDomainSnapshotWriteMetadata(vm, snap,
+ driver->xmlopt,
+ cfg->snapshotDir) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("failed to set snapshot '%s' as
current"),
+ snap->def->name);
+ virDomainSnapshotSetCurrent(vm->snapshots, NULL);
+ return -1;
+ }
+ }
+ }
+
+ if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) {
+ virDomainMomentDropChildren(snap);
+ return 0;
+ }
+
+ return qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata_only);
+}
+
+
+int
+qemuSnapshotDelete(virDomainObj *vm,
+ virDomainSnapshotPtr snapshot,
+ unsigned int flags)
+{
+ virQEMUDriver *driver = snapshot->domain->conn->privateData;
+ int ret = -1;
+ virDomainMomentObj *snap = NULL;
bool metadata_only = !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY);
int external = 0;
- g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY |
@@ -2352,39 +2396,7 @@ qemuSnapshotDelete(virDomainObj *vm,
if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) {
- rem.driver = driver;
- rem.vm = vm;
- rem.metadata_only = metadata_only;
- rem.err = 0;
- rem.current = virDomainSnapshotGetCurrent(vm->snapshots);
- rem.found = false;
- rem.momentDiscard = qemuDomainSnapshotDiscard;
- virDomainMomentForEachDescendant(snap, qemuDomainMomentDiscardAll,
- &rem);
- if (rem.err < 0)
- goto endjob;
- if (rem.found) {
- qemuSnapshotSetCurrent(vm, snap);
-
- if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) {
- if (qemuDomainSnapshotWriteMetadata(vm, snap,
- driver->xmlopt,
- cfg->snapshotDir) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to set snapshot '%s' as
current"),
- snap->def->name);
- virDomainSnapshotSetCurrent(vm->snapshots, NULL);
- goto endjob;
- }
- }
- }
-
- if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) {
- virDomainMomentDropChildren(snap);
- ret = 0;
- } else {
- ret = qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata_only);
- }
+ ret = qemuSnapshotDeleteChildren(vm, snap, driver, metadata_only, flags);
} else {
ret = qemuSnapshotDeleteSingle(vm, snap, driver, metadata_only);
}
--
2.37.2