File da4b0fd9-libxl-support-soft-reset.patch of Package libvirt.16766

commit da4b0fd9d3cdd117427e7e1981e8639bc859e844
Author: Jim Fehlig <jfehlig@suse.com>
Date:   Wed Oct 31 11:03:37 2018 -0600

    libxl: add support for soft reset
    
    The pvops Linux kernel implements machine_ops.crash_shutdown as
    
    static void xen_hvm_crash_shutdown(struct pt_regs *regs)
    {
            native_machine_crash_shutdown(regs);
            xen_reboot(SHUTDOWN_soft_reset);
    }
    
    but currently the libxl driver does not handle the soft reset
    shutdown event. As a result, the guest domain never proceeds
    past xen_reboot(), making it impossible for HVM domains to save
    a crash dump using kexec.
    
    This patch adds support for handling the soft reset event by
    calling libxl_domain_soft_reset() and re-enabling domain death
    events, which is similar to the xl tool handling of soft reset
    shutdown event.
    
    Signed-off-by: Jim Fehlig <jfehlig@suse.com>
    ACKed-by: Michal Privoznik <mprivozn@redhat.com>

Index: libvirt-4.0.0/src/libxl/libxl_domain.c
===================================================================
--- libvirt-4.0.0.orig/src/libxl/libxl_domain.c
+++ libvirt-4.0.0/src/libxl/libxl_domain.c
@@ -465,8 +465,10 @@ libxlDomainShutdownThread(void *opaque)
     virObjectEventPtr dom_event = NULL;
     libxl_shutdown_reason xl_reason = ev->u.domain_shutdown.shutdown_reason;
     libxlDriverConfigPtr cfg;
+    libxl_domain_config d_config;
 
     cfg = libxlDriverConfigGet(driver);
+    libxl_domain_config_init(&d_config);
 
     vm = virDomainObjListFindByIDRef(driver->domains, ev->domid);
     if (!vm) {
@@ -546,6 +548,34 @@ libxlDomainShutdownThread(void *opaque)
         case VIR_DOMAIN_LIFECYCLE_ACTION_LAST:
             goto endjob;
         }
+#ifdef LIBXL_HAVE_SOFT_RESET
+    } else if (xl_reason == LIBXL_SHUTDOWN_REASON_SOFT_RESET) {
+        libxlDomainObjPrivatePtr priv = vm->privateData;
+
+        if (libxl_retrieve_domain_configuration(cfg->ctx, vm->def->id,
+                                                &d_config) != 0) {
+            VIR_ERROR(_("Failed to retrieve config for VM '%s'. "
+                        "Unable to perform soft reset. Destroying VM"),
+                      vm->def->name);
+            libxlDomainShutdownHandleDestroy(driver, vm);
+            goto endjob;
+        }
+
+        if (priv->deathW) {
+            libxl_evdisable_domain_death(cfg->ctx, priv->deathW);
+            priv->deathW = NULL;
+        }
+
+        if (libxl_domain_soft_reset(cfg->ctx, &d_config, vm->def->id,
+                                    NULL, NULL) != 0) {
+            VIR_ERROR(_("Failed to soft reset VM '%s'. Destroying VM"),
+                      vm->def->name);
+            libxlDomainShutdownHandleDestroy(driver, vm);
+            goto endjob;
+        }
+        libxl_evenable_domain_death(cfg->ctx, vm->def->id, 0, &priv->deathW);
+        libxl_domain_unpause(cfg->ctx, vm->def->id);
+#endif
     } else {
         VIR_INFO("Unhandled shutdown_reason %d", xl_reason);
     }
@@ -559,6 +589,7 @@ libxlDomainShutdownThread(void *opaque)
         libxlDomainEventQueue(driver, dom_event);
     libxl_event_free(cfg->ctx, ev);
     VIR_FREE(shutdown_info);
+    libxl_domain_config_dispose(&d_config);
     virObjectUnref(cfg);
 }
 
openSUSE Build Service is sponsored by