Signed-off-by: Pavel Hrdina <phrdina(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 591d6db39b..42bc410078 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -2469,6 +2469,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,
@@ -2478,7 +2505,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 |
@@ -2491,20 +2517,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.37.2