[PATCH] libvirt incorrectly reports crashed domains as shutoff

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

 



Hi, I've noticed that libvirt seems to report crashed domains as shutoff. Here's an example:

[root@XXXXX ~]# virsh list
 Id Name                 State
----------------------------------
  0 Domain-0             running
 27 test03               blocked
 34 test01               shut off
 36 onetwentyeight       blocked

[root@XXXXX ~]# xm list
Name                              ID Mem(MiB) VCPUs State  Time(s)
Domain-0                           0      356     1 r-----  3655.4
onetwentyeight                    36      128     1 -b----    16.7
test01                            34      256     1 ----c-     7.4
test03                            27      256     1 -b----   231.7

The reason is because xen_internal.c does not interpret the additional shutdown flags when it checks the domain's state. Attached is a patch which correctly checks these flags and reports the crashed state. I wasn't sure of the best way to react to the other shutdown flags, so I just defaulted to "SHUTOFF" for everything else.

Pete

Index: src/xen_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xen_internal.c,v
retrieving revision 1.45
diff -u -r1.45 xen_internal.c
--- src/xen_internal.c	2 Oct 2006 22:13:12 -0000	1.45
+++ src/xen_internal.c	11 Oct 2006 15:46:10 -0000
@@ -27,6 +27,9 @@
 #include <xen/xen.h>
 #include <xen/linux/privcmd.h>
 
+/* required for shutdown flags */
+#include <xen/sched.h>
+
 /* #define DEBUG */
 /*
  * so far there is 2 versions of the structures usable for doing
@@ -81,6 +84,17 @@
 #define DOMFLAGS_SHUTDOWNSHIFT 16
 #endif
 
+/*
+ * These flags explain why a system is in the state of "shutdown".  Normally,
+ * They are defined in xen/sched.h
+ */
+#ifndef SHUTDOWN_poweroff
+#define SHUTDOWN_poweroff   0  /* Domain exited normally. Clean up and kill. */
+#define SHUTDOWN_reboot     1  /* Clean up, kill, and then restart.          */
+#define SHUTDOWN_suspend    2  /* Clean up, save suspend info, kill.         */
+#define SHUTDOWN_crash      3  /* Tell controller we've crashed.             */
+#endif
+
 #define XEN_V0_OP_GETDOMAININFOLIST	38
 #define XEN_V1_OP_GETDOMAININFOLIST	38
 #define XEN_V2_OP_GETDOMAININFOLIST	6
@@ -1500,6 +1514,7 @@
     xen_getdomaininfo dominfo;
     int ret;
     static int kb_per_pages = 0;
+    uint32_t domain_flags, domain_state, domain_shutdown_cause;
 
     if (kb_per_pages == 0) {
         kb_per_pages = sysconf(_SC_PAGESIZE) / 1024;
@@ -1518,12 +1533,22 @@
     if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != id))
         return (-1);
 
-    switch (XEN_GETDOMAININFO_FLAGS(dominfo) & 0xFF) {
+    domain_flags = XEN_GETDOMAININFO_FLAGS(dominfo);
+    domain_state = domain_flags & 0xFF;
+    switch (domain_state) {
 	case DOMFLAGS_DYING:
 	    info->state = VIR_DOMAIN_SHUTDOWN;
 	    break;
 	case DOMFLAGS_SHUTDOWN:
-	    info->state = VIR_DOMAIN_SHUTOFF;
+            /* The domain is shutdown.  Determine the cause. */
+            domain_shutdown_cause = domain_flags >> DOMFLAGS_SHUTDOWNSHIFT;
+            switch (domain_shutdown_cause) {
+                case SHUTDOWN_crash:
+                    info->state = VIR_DOMAIN_CRASHED;
+                    break;
+                default:
+                    info->state = VIR_DOMAIN_SHUTOFF;
+            }
 	    break;
 	case DOMFLAGS_PAUSED:
 	    info->state = VIR_DOMAIN_PAUSED;

[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]