[Libvirt-cim] [PATCH] (#3) For pause, reboot, and enable add support for guests in the NOSTATE state

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Thu Aug 7 18:42:27 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1218134457 25200
# Node ID 1c6d0148299eef6b19c9eecad01063ca53fe0175
# Parent  9f2f9b117797907bfa2b89a499b4eb5bb62cd458
(#3) For pause, reboot, and enable add support for guests in the NOSTATE state.

It's possible that a XenFV guest might return no state instead of blocked or running.  This can occur when the guest is active, but isn't running of the CPU or blocked waiting for it.

This should be a safe approach - we return an error if the guest is in some other state or if libvirt is unable to successfully change the state of the guest.

Updates from 2 to 3:
  -Add logic to check connection type so NOSTATE only applied to Xen guests.

Updates from 1 to 2:
  -For the reboot and reset operations, add support for paused guests (per the VSP).
  -If the guest returns VIR_DOMAIN_NOSTATE, the provider should return the value CIM_STATE_ENABLED, not CIM_STATE_UNKNOWN.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r 9f2f9b117797 -r 1c6d0148299e src/Virt_ComputerSystem.c
--- a/src/Virt_ComputerSystem.c	Mon Aug 04 11:57:27 2008 -0700
+++ b/src/Virt_ComputerSystem.c	Thu Aug 07 11:40:57 2008 -0700
@@ -242,6 +242,22 @@
         return state;
 }
 
+static uint16_t adjust_state_if_nostate_xen(virDomainPtr dom,
+                                            uint16_t state)
+{
+        virConnectPtr conn;
+
+        if (state != CIM_STATE_UNKNOWN)
+                return state;
+
+        conn = virDomainGetConnect(dom);
+
+        if (STREQC(virConnectGetType(conn), "Xen"))
+                return CIM_STATE_ENABLED;
+
+        return state;
+}
+
 static int set_state_from_dom(const CMPIBroker *broker,
                               virDomainPtr dom,
                               CMPIInstance *instance)
@@ -262,6 +278,7 @@
 
         cim_state = state_lv_to_cim((const int)info.state);
         cim_state = adjust_state_if_saved(virDomainGetName(dom), cim_state);
+        cim_state = adjust_state_if_nostate_xen(dom, cim_state);
         CMSetProperty(instance, "EnabledState",
                       (CMPIValue *)&cim_state, CMPI_uint16);
 
@@ -810,9 +827,19 @@
 static CMPIStatus state_change_pause(virDomainPtr dom, virDomainInfoPtr info)
 {
         CMPIStatus s = {CMPI_RC_OK, NULL};
+        virConnectPtr conn;
+        unsigned char state; 
         int ret = 0;
 
-        switch (info->state) {
+        state = info->state;
+        conn = virDomainGetConnect(dom);
+
+        if ((STREQC(virConnectGetType(conn), "Xen")) && 
+           (state == VIR_DOMAIN_NOSTATE)) {
+           state = VIR_DOMAIN_RUNNING;
+        }
+
+        switch (state) {
         case VIR_DOMAIN_RUNNING:
         case VIR_DOMAIN_BLOCKED:
                 CU_DEBUG("Pause domain");
@@ -835,11 +862,22 @@
 static CMPIStatus state_change_reboot(virDomainPtr dom, virDomainInfoPtr info)
 {
         CMPIStatus s = {CMPI_RC_OK, NULL};
+        virConnectPtr conn;
+        unsigned char state; 
         int ret = 0;
 
-        switch (info->state) {
+        state = info->state;
+        conn = virDomainGetConnect(dom);
+
+        if ((STREQC(virConnectGetType(conn), "Xen")) && 
+           (state == VIR_DOMAIN_NOSTATE)) {
+           state = VIR_DOMAIN_RUNNING;
+        }
+
+        switch (state) {
         case VIR_DOMAIN_RUNNING:
         case VIR_DOMAIN_BLOCKED:
+        case VIR_DOMAIN_PAUSED:
                 CU_DEBUG("Reboot domain");
                 ret = virDomainReboot(dom, 0);
                 break;
@@ -860,11 +898,22 @@
 static CMPIStatus state_change_reset(virDomainPtr dom, virDomainInfoPtr info)
 {
         CMPIStatus s = {CMPI_RC_OK, NULL};
+        virConnectPtr conn;
+        unsigned char state; 
         int ret = 0;
 
-        switch (info->state) {
+        state = info->state;
+        conn = virDomainGetConnect(dom);
+
+        if ((STREQC(virConnectGetType(conn), "Xen")) && 
+           (state == VIR_DOMAIN_NOSTATE)) {
+           state = VIR_DOMAIN_RUNNING;
+        }
+
+        switch (state) {
         case VIR_DOMAIN_RUNNING:
         case VIR_DOMAIN_BLOCKED:
+        case VIR_DOMAIN_PAUSED:
                 CU_DEBUG("Reset domain");
                 ret = domain_reset(dom);
                 break;




More information about the Libvirt-cim mailing list