[Libvirt-cim] [PATCH 5/6] Controller Device Details

John Ferlan jferlan at redhat.com
Wed Mar 19 02:49:09 UTC 2014


Set the various fields for the KVM_Contoller instance based on the read XML
from the virtual controller device structure.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/Virt_Device.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/src/Virt_Device.c b/src/Virt_Device.c
index 12ae6bd..5f48fae 100644
--- a/src/Virt_Device.c
+++ b/src/Virt_Device.c
@@ -366,6 +366,83 @@ static CMPIInstance *input_instance(const CMPIBroker *broker,
         return inst;
 }
 
+static int controller_set_attr(const CMPIBroker *broker,
+                               CMPIInstance *instance,
+                               struct controller_device *dev)
+{
+        const char *type_str;
+
+        type_str = controller_protocol_type_IDToStr(dev->type);
+        if (type_str == NULL) {
+            CU_DEBUG("controller type=%d fails to return string", dev->type);
+            return 0;
+        }
+
+        /* Use 0 for unknown or unlimited - although probably
+         * unnecessary since the struct is calloc'd
+         */
+        CMSetProperty(instance, "MaxNumberControlled",
+                      0, CMPI_uint32);
+
+        CMSetProperty(instance, "ProtocolSupported",
+                      (CMPIValue *)dev->type,
+                      CMPI_uint16);
+
+        CMSetProperty(instance, "Index",
+                      (CMPIValue *)dev->index,
+                      CMPI_uint64);
+
+        if (dev->model)
+            CMSetProperty(instance, "ProtocolDescription",
+                          (CMPIValue *)dev->model,
+                          CMPI_chars);
+        if (dev->ports)
+            CMSetProperty(instance, "Ports",
+                          (CMPIValue *)dev->ports,
+                          CMPI_chars);
+        if (dev->vectors)
+            CMSetProperty(instance, "Vectors",
+                          (CMPIValue *)dev->vectors,
+                          CMPI_chars);
+        if (dev->queues)
+            CMSetProperty(instance, "Queues",
+                          (CMPIValue *)dev->queues,
+                          CMPI_chars);
+        if (dev->address.ct > 0)
+            set_device_address(broker, &dev->address, instance);
+
+        return 1;
+}
+
+static CMPIInstance *controller_instance(const CMPIBroker *broker,
+                                         struct controller_device *dev,
+                                         const virDomainPtr dom,
+                                         const char *ns)
+{
+        CMPIInstance *inst;
+        virConnectPtr conn;
+
+        conn = virDomainGetConnect(dom);
+        inst = get_typed_instance(broker,
+                                  pfx_from_conn(conn),
+                                  "Controller",
+                                  ns,
+                                  true);
+        if (inst == NULL) {
+                CU_DEBUG("Failed to get instance of %s_Controller",
+                         pfx_from_conn(conn));
+                return NULL;
+        }
+
+
+        if (!controller_set_attr(broker, inst, dev)) {
+                CU_DEBUG("Failed to set contoller attributes of %s_Controller",
+                         pfx_from_conn(conn));
+                return NULL;
+        }
+
+        return inst;
+}
 static int device_set_devid(CMPIInstance *instance,
                             struct virt_device *dev,
                             const virDomainPtr dom)
@@ -521,6 +598,11 @@ static bool device_instances(const CMPIBroker *broker,
                                                   &dev->dev.input,
                                                   dom,
                                                   ns);
+                 else if (dev->type == CIM_RES_TYPE_CONTROLLER)
+                        instance = controller_instance(broker,
+                                                       &dev->dev.controller,
+                                                       dom,
+                                                       ns);
                 else
                         return false;
 
@@ -555,6 +637,8 @@ uint16_t res_type_from_device_classname(const char *classname)
                 return CIM_RES_TYPE_GRAPHICS;
         else if (strstr(classname, "PointingDevice"))
                 return CIM_RES_TYPE_INPUT;
+        else if (strstr(classname, "Controller"))
+                return CIM_RES_TYPE_CONTROLLER;
         else
                 return CIM_RES_TYPE_UNKNOWN;
 }
-- 
1.8.5.3




More information about the Libvirt-cim mailing list