[PATCH 4/4] libxl: handle on_crash coredump actions

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

 



Add support for coredump-{destroy,restart} actions of <on_crash> event.

Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx>
---
 src/libxl/libxl_driver.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index e18fead..7640801 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -251,6 +251,50 @@ error:
 }
 
 /*
+ * Core dump domain to default dump path.
+ *
+ * virDomainObjPtr should be locked on invocation
+ */
+static int
+libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,
+                        virDomainObjPtr vm)
+{
+    libxlDomainObjPrivatePtr priv = vm->privateData;
+    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    time_t curtime = time(NULL);
+    char timestr[100];
+    struct tm time_info;
+    char *dumpfile = NULL;
+    int ret = -1;
+
+    localtime_r(&curtime, &time_info);
+    strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info);
+
+    if (virAsprintf(&dumpfile, "%s/%s-%s",
+                    cfg->autoDumpDir,
+                    vm->def->name,
+                    timestr) < 0)
+        goto cleanup;
+
+    if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+        goto cleanup;
+
+    /* Unlock virDomainObj while dumping core */
+    virObjectUnlock(vm);
+    libxl_domain_core_dump(priv->ctx, vm->def->id, dumpfile, NULL);
+    virObjectLock(vm);
+
+    ignore_value(libxlDomainObjEndJob(driver, vm));
+    ret = 0;
+
+cleanup:
+    VIR_FREE(dumpfile);
+    virObjectUnref(cfg);
+
+    return ret;
+}
+
+/*
  * Cleanup function for domain that has reached shutoff state.
  *
  * virDomainObjPtr should be locked on invocation
@@ -403,6 +447,12 @@ libxlDomainShutdownThread(void *opaque)
             goto restart;
         case VIR_DOMAIN_LIFECYCLE_CRASH_PRESERVE:
             goto cleanup;
+        case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_DESTROY:
+            libxlDomainAutoCoreDump(driver, vm);
+            goto destroy;
+        case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_RESTART:
+            libxlDomainAutoCoreDump(driver, vm);
+            goto restart;
         }
     } else if (xl_reason == LIBXL_SHUTDOWN_REASON_REBOOT) {
         dom_event = virDomainEventLifecycleNewFromObj(vm,
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]