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.
This commit is contained in:
Eric Blake 2011-08-12 10:20:24 -06:00
parent 3881a47088
commit 19f8c980ef

View File

@ -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) {