[Libvirt-cim] [PATCH 6 of 6] Make VSMS not parse the InstanceID of a RASD, but rather use the proper fields

Dan Smith danms at us.ibm.com
Wed Apr 9 21:31:46 UTC 2008


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1207776680 25200
# Node ID 01e5b1388ee7604332c442cba79c39ac3cca0b6f
# Parent  3d143b851ee9201986ce8d0e6656cc313d361866
Make VSMS not parse the InstanceID of a RASD, but rather use the proper fields

For Network, grab the Address for the MAC and then also try to extract
the PoolID for the network name.  I left it split between KVM and Xen,
because I think as we expand the supported network types, we'll still need
to differentiate in the code.

This means that we no longer examine the InstanceID of the incoming RASDs
for a DefineSystem operation (which is correct).  The test suite will need
to change to use these values correctly instead of generating the InstanceID
and should also have a test that verifies that the InstanceID is not
honored.  I think that the InstanceID should be ignored if specified,
although discussion of this point is certainly welcomed.

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

diff -r 3d143b851ee9 -r 01e5b1388ee7 src/Makefile.am
--- a/src/Makefile.am	Wed Apr 09 14:29:08 2008 -0700
+++ b/src/Makefile.am	Wed Apr 09 14:31:20 2008 -0700
@@ -75,9 +75,9 @@ libVirt_ComputerSystemMigrationIndicatio
 libVirt_ComputerSystemMigrationIndication_la_SOURCES = Virt_ComputerSystemMigrationIndication.c
 libVirt_ComputerSystemMigrationIndication_la_LIBADD = -lVirt_ComputerSystem
 
-libVirt_VirtualSystemManagementService_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_ComputerSystemIndication.la libVirt_RASD.la libVirt_HostSystem.la
+libVirt_VirtualSystemManagementService_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_ComputerSystemIndication.la libVirt_RASD.la libVirt_HostSystem.la libVirt_DevicePool.la
 libVirt_VirtualSystemManagementService_la_SOURCES = Virt_VirtualSystemManagementService.c
-libVirt_VirtualSystemManagementService_la_LIBADD = -lVirt_ComputerSystem -lVirt_ComputerSystemIndication -lVirt_RASD -lVirt_HostSystem
+libVirt_VirtualSystemManagementService_la_LIBADD = -lVirt_ComputerSystem -lVirt_ComputerSystemIndication -lVirt_RASD -lVirt_HostSystem -lVirt_DevicePool
 
 libVirt_VirtualSystemManagementCapabilities_la_DEPENDENCIES = libVirt_HostSystem.la
 libVirt_VirtualSystemManagementCapabilities_la_SOURCES = Virt_VirtualSystemManagementCapabilities.c
diff -r 3d143b851ee9 -r 01e5b1388ee7 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Wed Apr 09 14:29:08 2008 -0700
+++ b/src/Virt_VirtualSystemManagementService.c	Wed Apr 09 14:31:20 2008 -0700
@@ -47,6 +47,7 @@
 #include "Virt_ComputerSystemIndication.h"
 #include "Virt_RASD.h"
 #include "Virt_HostSystem.h"
+#include "Virt_DevicePool.h"
 #include "svpc_types.h"
 
 const static CMPIBroker *_BROKER;
@@ -202,8 +203,16 @@ static int xen_net_rasd_to_vdev(CMPIInst
 static int xen_net_rasd_to_vdev(CMPIInstance *inst,
                                 struct virt_device *dev)
 {
+        const char *val = NULL;
+
         free(dev->dev.net.type);
-        dev->dev.net.type = strdup("bridge");
+        dev->dev.net.type = strdup("network");
+
+        if (cu_get_str_prop(inst, "PoolID", &val) != CMPI_RC_OK)
+                val = "NetworkPool/default";
+
+        free(dev->dev.net.source);
+        dev->dev.net.source = name_from_pool_id(val);
 
         return 1;
 }
@@ -211,11 +220,78 @@ static int kvm_net_rasd_to_vdev(CMPIInst
 static int kvm_net_rasd_to_vdev(CMPIInstance *inst,
                                 struct virt_device *dev)
 {
+        const char *val = NULL;
+
         free(dev->dev.net.type);
         dev->dev.net.type = strdup("network");
 
+        if (cu_get_str_prop(inst, "PoolID", &val) != CMPI_RC_OK)
+                val = "NetworkPool/default";
+
         free(dev->dev.net.source);
-        dev->dev.net.source = strdup("default");
+        dev->dev.net.source = name_from_pool_id(val);
+
+        return 1;
+}
+
+static int net_rasd_to_vdev(CMPIInstance *inst,
+                            struct virt_device *dev)
+{
+        const char *val = NULL;
+        CMPIObjectPath *op;
+
+        if (cu_get_str_prop(inst, "Address", &val) != CMPI_RC_OK)
+                val = "00:00:00:00:00:00";
+
+        free(dev->dev.net.mac);
+        dev->dev.net.mac = strdup(val);
+
+        op = CMGetObjectPath(inst, NULL);
+        if (op == NULL)
+                goto out;
+
+        if (STARTS_WITH(CLASSNAME(op), "Xen"))
+                xen_net_rasd_to_vdev(inst, dev);
+        else if (STARTS_WITH(CLASSNAME(op), "KVM"))
+                kvm_net_rasd_to_vdev(inst, dev);
+        else
+                CU_DEBUG("Unknown class type for net device: %s",
+                         CLASSNAME(op));
+
+ out:
+        return 1;
+}
+
+static int disk_rasd_to_vdev(CMPIInstance *inst,
+                             struct virt_device *dev)
+{
+        const char *val = NULL;
+
+        if (cu_get_str_prop(inst, "VirtualDevice", &val) != CMPI_RC_OK)
+                val = "hda";
+
+        free(dev->dev.disk.virtual_dev);
+        dev->dev.disk.virtual_dev = strdup(val);
+
+        if (cu_get_str_prop(inst, "Address", &val) != CMPI_RC_OK)
+                val = "/dev/null";
+
+        free(dev->dev.disk.source);
+        dev->dev.disk.source = strdup(val);
+        dev->dev.disk.disk_type = disk_type_from_file(val);
+
+        return 1;
+}
+
+static int mem_rasd_to_vdev(CMPIInstance *inst,
+                            struct virt_device *dev)
+{
+        cu_get_u64_prop(inst, "VirtualQuantity", &dev->dev.mem.size);
+        cu_get_u64_prop(inst, "Reservation", &dev->dev.mem.size);
+        dev->dev.mem.maxsize = dev->dev.mem.size;
+        cu_get_u64_prop(inst, "Limit", &dev->dev.mem.maxsize);
+        dev->dev.mem.size <<= 10;
+        dev->dev.mem.maxsize <<= 10;
 
         return 1;
 }
@@ -224,11 +300,8 @@ static int rasd_to_vdev(CMPIInstance *in
                         struct virt_device *dev)
 {
         uint16_t type;
-        const char *id = NULL;
-        const char *val = NULL;
-        char *name = NULL;
-        char *devid = NULL;
         CMPIObjectPath *op;
+        int ret = 0;
 
         op = CMGetObjectPath(inst, NULL);
         if (op == NULL)
@@ -239,50 +312,16 @@ static int rasd_to_vdev(CMPIInstance *in
 
         dev->type = (int)type;
 
-        if (cu_get_str_prop(inst, "InstanceID", &id) != CMPI_RC_OK)
-                goto err;
-
-        if (!parse_fq_devid(id, &name, &devid))
-                goto err;
-
         if (type == CIM_RES_TYPE_DISK) {
-                free(dev->dev.disk.virtual_dev);
-                dev->dev.disk.virtual_dev = devid;
-
-                if (cu_get_str_prop(inst, "Address", &val) != CMPI_RC_OK)
-                        val = "/dev/null";
-
-                free(dev->dev.disk.source);
-                dev->dev.disk.source = strdup(val);
-                dev->dev.disk.disk_type = disk_type_from_file(val);
+                ret = disk_rasd_to_vdev(inst, dev);
         } else if (type == CIM_RES_TYPE_NET) {
-                free(dev->dev.net.mac);
-                dev->dev.net.mac = devid;
-
-                if (STARTS_WITH(CLASSNAME(op), "Xen"))
-                        xen_net_rasd_to_vdev(inst, dev);
-                else if (STARTS_WITH(CLASSNAME(op), "KVM"))
-                        kvm_net_rasd_to_vdev(inst, dev);
-                else
-                        CU_DEBUG("Unknown class type for net device: %s",
-                                 CLASSNAME(op));
-
+                ret = net_rasd_to_vdev(inst, dev);
         } else if (type == CIM_RES_TYPE_MEM) {
-                cu_get_u64_prop(inst, "VirtualQuantity", &dev->dev.mem.size);
-                cu_get_u64_prop(inst, "Reservation", &dev->dev.mem.size);
-                dev->dev.mem.maxsize = dev->dev.mem.size;
-                cu_get_u64_prop(inst, "Limit", &dev->dev.mem.maxsize);
-                dev->dev.mem.size <<= 10;
-                dev->dev.mem.maxsize <<= 10;
-        }
-
-        free(name);
-
-        return 1;
+                ret = mem_rasd_to_vdev(inst, dev);
+        }
+
+        return ret;
  err:
-        free(name);
-        free(devid);
-
         return 0;
 }
 




More information about the Libvirt-cim mailing list