From 19f8c980efbbb7cf01e7f5059c9521c8dc5799ec Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 12 Aug 2011 10:20:24 -0600 Subject: [PATCH] snapshot: support new undefine flags in qemu 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. But it is only doable for snapshot metadata, where we are in control of the data being deleted; for the actual snapshots, there's too much likelihood of something going wrong, and requiring even more API calls to figure out what failed in the meantime, so callers are better off deleting the snapshot data themselves one snapshot at a time where they can deal with failures as they happen. * src/qemu/qemu_driver.c (qemuDomainUndefineFlags): Honor new flags. --- src/qemu/qemu_driver.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a4f7c62dc8..0e022ad4aa 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5073,7 +5073,8 @@ 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, -1); qemuDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); @@ -5088,10 +5089,23 @@ 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) { + qemuReportError(VIR_ERR_OPERATION_INVALID, + _("cannot delete inactive domain with %d " + "snapshots"), + nsnapshots); + goto cleanup; + } + + rem.driver = driver; + rem.vm = vm; + rem.metadata_only = true; + rem.err = 0; + virHashForEach(vm->snapshots.objs, qemuDomainSnapshotDiscardAll, &rem); + if (rem.err < 0) + goto cleanup; } if (!vm->persistent) { -- 2.39.5