A nice benefit of deleting all snapshots at undefine time is that
you don't have to do any reparenting or subtree identification - since
everything goes, this is an O(n) process, whereas using multiple
virDomainSnapshotDelete calls would be O(n^2) or worse.
* src/qemu/qemu_driver.c (qemuDomainDestroyFlags)
(qemuDomainUndefineFlags): Honor new flags.
---
src/qemu/qemu_driver.c | 51 ++++++++++++++++++++++++++++++++++++++---------
1 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5a18309..f79d9bc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1778,7 +1778,8 @@ qemuDomainDestroyFlags(virDomainPtr dom,
qemuDomainObjPrivatePtr priv;
int nsnapshots;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_DESTROY_SNAPSHOTS_METADATA |
+ VIR_DOMAIN_DESTROY_SNAPSHOTS_FULL, -1);
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -1792,10 +1793,24 @@ qemuDomainDestroyFlags(virDomainPtr dom,
if (!vm->persistent &&
(nsnapshots = virDomainSnapshotObjListNum(&vm->snapshots, 0))) {
- qemuReportError(VIR_ERR_OPERATION_INVALID,
- _("cannot delete transient domain with %d snapshots"),
- nsnapshots);
- goto cleanup;
+ struct snap_remove rem;
+
+ if ((flags & (VIR_DOMAIN_DESTROY_SNAPSHOTS_METADATA |
+ VIR_DOMAIN_DESTROY_SNAPSHOTS_FULL)) == 0) {
+ qemuReportError(VIR_ERR_OPERATION_INVALID,
+ _("cannot delete transient domain with %d "
+ "snapshots"),
+ nsnapshots);
+ goto cleanup;
+ }
+
+ rem.driver = driver;
+ rem.vm = vm;
+ rem.metadata_only = !(flags & VIR_DOMAIN_DESTROY_SNAPSHOTS_FULL);
+ rem.err = 0;
+ virHashForEach(vm->snapshots.objs, qemuDomainSnapshotDiscardAll, &rem);
+ if (rem.err < 0)
+ goto cleanup;
}
priv = vm->privateData;
@@ -4919,7 +4934,9 @@ qemuDomainUndefineFlags(virDomainPtr dom,
int ret = -1;
int nsnapshots;
- virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE, -1);
+ virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
+ VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA |
+ VIR_DOMAIN_UNDEFINE_SNAPSHOTS_FULL, -1);
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -4934,10 +4951,24 @@ qemuDomainUndefineFlags(virDomainPtr dom,
if (!virDomainObjIsActive(vm) &&
(nsnapshots = virDomainSnapshotObjListNum(&vm->snapshots, 0))) {
- qemuReportError(VIR_ERR_OPERATION_INVALID,
- _("cannot delete inactive domain with %d snapshots"),
- nsnapshots);
- goto cleanup;
+ struct snap_remove rem;
+
+ if ((flags & (VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA |
+ VIR_DOMAIN_UNDEFINE_SNAPSHOTS_FULL)) == 0) {
+ qemuReportError(VIR_ERR_OPERATION_INVALID,
+ _("cannot delete inactive domain with %d "
+ "snapshots"),
+ nsnapshots);
+ goto cleanup;
+ }
+
+ rem.driver = driver;
+ rem.vm = vm;
+ rem.metadata_only = !(flags & VIR_DOMAIN_UNDEFINE_SNAPSHOTS_FULL);
+ rem.err = 0;
+ virHashForEach(vm->snapshots.objs, qemuDomainSnapshotDiscardAll, &rem);
+ if (rem.err < 0)
+ goto cleanup;
}
if (!vm->persistent) {
--
1.7.4.4