[Libvirt-cim] [PATCH] Make VCPU RASD Add/Remove fail and Modify behave correctly

Dan Smith danms at us.ibm.com
Thu May 29 16:37:36 UTC 2008


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1212078794 25200
# Node ID 3f3dd6c106e07bc3c1dfc9a53947180ab893e44d
# Parent  05a5ba2fda5d03facdea4e0cdfdc26d4a47d80fd
Make VCPU RASD Add/Remove fail and Modify behave correctly

With the recent VCPU changes, this needs to be in place for VSMS to function
properly.

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

diff -r 05a5ba2fda5d -r 3f3dd6c106e0 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c	Wed May 28 14:04:50 2008 -0700
+++ b/libxkutil/device_parsing.c	Thu May 29 09:33:14 2008 -0700
@@ -1002,29 +1002,26 @@
         return 1;
 }
 
-static int change_vcpus(virDomainPtr dom, int delta)
+static int change_vcpus(virDomainPtr dom, struct virt_device *dev)
 {
         int ret;
-        virDomainInfo info;
 
-        ret = virDomainGetInfo(dom, &info);
-        if (ret == -1) {
-                CU_DEBUG("Failed to get domain info for %s",
-                         virDomainGetName(dom));
+        if (dev->dev.vcpu.quantity <= 0) {
+                CU_DEBUG("Unable to set VCPU count to %i",
+                         dev->dev.vcpu.quantity);
                 return 0;
         }
 
-        ret = virDomainSetVcpus(dom, info.nrVirtCpu + delta);
+        ret = virDomainSetVcpus(dom, dev->dev.vcpu.quantity);
         if (ret == -1) {
                 CU_DEBUG("Failed to set domain vcpus to %i",
-                         info.nrVirtCpu + delta);
+                         dev->dev.vcpu.quantity);
                 return 0;
         }
 
-        CU_DEBUG("Changed %s vcpus from %i to %i",
+        CU_DEBUG("Changed %s vcpus to %i",
                  virDomainGetName(dom),
-                 info.nrVirtCpu,
-                 info.nrVirtCpu + delta);
+                 dev->dev.vcpu.quantity);
 
         return 1;
 }
@@ -1034,8 +1031,6 @@
         if ((dev->type == CIM_RES_TYPE_NET) ||
             (dev->type == CIM_RES_TYPE_DISK))
                 return _change_device(dom, dev, true);
-        else if (dev->type == CIM_RES_TYPE_PROC)
-                return change_vcpus(dom, 1);
 
         CU_DEBUG("Unhandled device type %i", dev->type);
 
@@ -1047,8 +1042,6 @@
         if ((dev->type == CIM_RES_TYPE_NET) ||
             (dev->type == CIM_RES_TYPE_DISK))
                 return _change_device(dom, dev, false);
-        else if (dev->type == CIM_RES_TYPE_PROC)
-                return change_vcpus(dom, -1);
 
         CU_DEBUG("Unhandled device type %i", dev->type);
 
@@ -1059,6 +1052,8 @@
 {
         if (dev->type == CIM_RES_TYPE_MEM)
                 return change_memory(dom, dev);
+        else if (dev->type == CIM_RES_TYPE_PROC)
+                return change_vcpus(dom, dev);
 
         CU_DEBUG("Unhandled device type %i", dev->type);
 
diff -r 05a5ba2fda5d -r 3f3dd6c106e0 libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c	Wed May 28 14:04:50 2008 -0700
+++ b/libxkutil/xmlgen.c	Thu May 29 09:33:14 2008 -0700
@@ -254,21 +254,17 @@
 
 static bool vcpu_to_xml(char **xml, struct virt_device *dev)
 {
-        int count;
         int ret;
+        char *_xml;
 
-        if (*xml == NULL) {
-                ret = asprintf(xml, "<vcpu>1</vcpu>");
-                return ret != -1;
-        }
+        ret = asprintf(&_xml, "<vcpu>%" PRIu64 "</vcpu>\n",
+                       dev->dev.vcpu.quantity);
+        if (ret == -1)
+                return false;
+        else
+                astrcat(xml, _xml);
 
-        if (sscanf(*xml, "<vcpu>%i</vcpu>\n", &count) != 1)
-                return false;
-
-        free(*xml);
-        ret = asprintf(xml, "<vcpu>%i</vcpu>\n", count + 1);
-
-        return ret != -1;
+        return true;
 }
 
 static bool mem_to_xml(char **xml, struct virt_device *dev)
diff -r 05a5ba2fda5d -r 3f3dd6c106e0 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Wed May 28 14:04:50 2008 -0700
+++ b/src/Virt_VirtualSystemManagementService.c	Thu May 29 09:33:14 2008 -0700
@@ -447,6 +447,14 @@
         return NULL;
 }
 
+static const char *proc_rasd_to_vdev(CMPIInstance *inst,
+                                     struct virt_device *dev)
+{
+        cu_get_u64_prop(inst, "VirtualQuantity", &dev->dev.vcpu.quantity);
+
+        return NULL;
+}
+
 static const char *_sysvirt_rasd_to_vdev(CMPIInstance *inst,
                                          struct virt_device *dev,
                                          uint16_t type)
@@ -458,7 +466,7 @@
         } else if (type == CIM_RES_TYPE_MEM) {
                 return mem_rasd_to_vdev(inst, dev);
         } else if (type == CIM_RES_TYPE_PROC) {
-                return NULL; /* FIXME: replace when processor is done */
+                return proc_rasd_to_vdev(inst, dev);
         }
 
         return "Resource type not supported on this platform";




More information about the Libvirt-cim mailing list