]> xenbits.xensource.com Git - libvirt.git/commitdiff
snapshot: fix corner case on OOM during creation
authorEric Blake <eblake@redhat.com>
Thu, 1 Sep 2011 21:22:02 +0000 (15:22 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 2 Sep 2011 14:50:01 +0000 (08:50 -0600)
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.

src/qemu/qemu_driver.c

index 38138fcc18d280dd912958b90608d1137b413a5c..3ff9bd6dcee2eb62058ec46eb88a65a84a0d3977 100644 (file)
@@ -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);