From: Eric Blake Date: Thu, 1 Sep 2011 21:22:02 +0000 (-0600) Subject: snapshot: fix corner case on OOM during creation X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=c554f6e18be9ce73d5207721f06cc1ff8b0aac7d;p=libvirt.git snapshot: fix corner case on OOM during creation Commit 6766ff10 introduced a corner case bug with snapshot creation: if a snapshot is created, but then we hit OOM while trying to create the return value of the function, then we have polluted the internal directory with the snapshot metadata with no way to clean it up from the running libvirtd. * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Don't write metadata file on OOM condition. --- diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 38138fcc18..3ff9bd6dce 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8583,18 +8583,20 @@ static virDomainSnapshotPtr qemuDomainSnapshotCreateXML(virDomainPtr domain, * do; we've successfully taken the snapshot, and we are now running * on it, so we have to go forward the best we can */ - if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->snapshotDir) < 0) - goto cleanup; - vm->current_snapshot = snap; - snapshot = virGetDomainSnapshot(domain, snap->def->name); cleanup: if (vm) { - if (snapshot) - vm->current_snapshot = snap; - else if (snap) + if (snapshot) { + if (qemuDomainSnapshotWriteMetadata(vm, snap, + driver->snapshotDir) < 0) + VIR_WARN("unable to save metadata for snapshot %s", + snap->def->name); + else + vm->current_snapshot = snap; + } else if (snap) { virDomainSnapshotObjListRemove(&vm->snapshots, snap); + } virDomainObjUnlock(vm); } virDomainSnapshotDefFree(def);