Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
Reviewed-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_snapshot.c | 42 ++++++++++++++++++++++++++--------------
1 file changed, 28 insertions(+), 14 deletions(-)
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 4ea3f578e9..11427716e4 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -2485,6 +2485,33 @@ qemuSnapshotDeleteChildren(virDomainObj *vm,
}
+static int
+qemuSnapshotDeleteValidate(virDomainMomentObj *snap,
+ unsigned int flags)
+{
+ int external = 0;
+
+ if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) &&
+ virDomainSnapshotIsExternal(snap))
+ external++;
+
+ if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
+ VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY))
+ virDomainMomentForEachDescendant(snap,
+ qemuSnapshotCountExternal,
+ &external);
+
+ if (external) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("deletion of %d external disk snapshots not "
+ "supported yet"), external);
+ return -1;
+ }
+
+ return 0;
+}
+
+
int
qemuSnapshotDelete(virDomainObj *vm,
virDomainSnapshotPtr snapshot,
@@ -2493,7 +2520,6 @@ qemuSnapshotDelete(virDomainObj *vm,
int ret = -1;
virDomainMomentObj *snap = NULL;
bool metadata_only = !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY);
- int external = 0;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY |
@@ -2506,20 +2532,8 @@ qemuSnapshotDelete(virDomainObj *vm,
goto endjob;
if (!metadata_only) {
- if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) &&
- virDomainSnapshotIsExternal(snap))
- external++;
- if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
- VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY))
- virDomainMomentForEachDescendant(snap,
- qemuSnapshotCountExternal,
- &external);
- if (external) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("deletion of %d external disk snapshots not "
- "supported yet"), external);
+ if (qemuSnapshotDeleteValidate(snap, flags) < 0)
goto endjob;
- }
}
if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
--
2.38.1