[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv3 00.5/43] 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.
---
 src/qemu/qemu_driver.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index cce11c3..77b7609 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8583,18 +8583,21 @@ 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);
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]