File ac4a12db-libxl-fix-hasManagedSave.patch of Package libvirt.8367

commit ac4a12db715cdb764281cdb89cabd478f8ec9d09
Author: Jim Fehlig <jfehlig@suse.com>
Date:   Mon May 14 14:45:05 2018 -0600

    libxl: don't set hasManagedSave when performing save
    
    libxlDoDomainSave() is used in both the save and managedsave code
    paths but was unconditionally setting hasManagedSave to true on
    success. As a result, undefine would fail after a non-managed
    save/restore operation. E.g.
    
    virsh define; virsh start
    virsh save; virsh restore
    virsh shutdown
    virsh undefine
    error: Refusing to undefine while domain managed save image exists
    
    Modify libxlDoDomainSave() to take an additional parameter to
    specify managed vs non-managed save, and change callers to use it.
    
    Signed-off-by: Jim Fehlig <jfehlig@suse.com>
    Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Index: libvirt-4.0.0/src/libxl/libxl_driver.c
===================================================================
--- libvirt-4.0.0.orig/src/libxl/libxl_driver.c
+++ libvirt-4.0.0/src/libxl/libxl_driver.c
@@ -1689,8 +1689,10 @@ libxlDomainGetState(virDomainPtr dom,
  * virDomainObjPtr must be locked on invocation
  */
 static int
-libxlDoDomainSave(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
-                  const char *to)
+libxlDoDomainSave(libxlDriverPrivatePtr driver,
+                  virDomainObjPtr vm,
+                  const char *to,
+                  bool managed)
 {
     libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
     libxlSavefileHeader hdr;
@@ -1761,7 +1763,7 @@ libxlDoDomainSave(libxlDriverPrivatePtr
     }
 
     libxlDomainCleanup(driver, vm);
-    vm->hasManagedSave = true;
+    vm->hasManagedSave = managed;
     ret = 0;
 
  cleanup:
@@ -1811,7 +1813,7 @@ libxlDomainSaveFlags(virDomainPtr dom, c
         goto endjob;
     }
 
-    if (libxlDoDomainSave(driver, vm, to) < 0)
+    if (libxlDoDomainSave(driver, vm, to, false) < 0)
         goto endjob;
 
     if (!vm->persistent)
@@ -2047,7 +2049,7 @@ libxlDomainManagedSave(virDomainPtr dom,
 
     VIR_INFO("Saving state to %s", name);
 
-    if (libxlDoDomainSave(driver, vm, name) < 0)
+    if (libxlDoDomainSave(driver, vm, name, true) < 0)
         goto endjob;
 
     if (!vm->persistent)