[Libvirt-cim] [PATCH 1 of 2] Add KVM_CDROMDrive class

Dan Smith danms at us.ibm.com
Tue Oct 14 21:01:53 UTC 2008


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1224018018 25200
# Node ID 9e4f5b57f4125904121d650cc03866b6fbf45084
# Parent  b9a93806b73aaaccef8ade2cc43170e77fe01755
Add KVM_CDROMDrive class

This patch makes the Device provider return a KVM_CDROMDrive class where
appropriate.  All the associations that mention LogicalDisk have been updated,
but it would be good to ensure that the test suite is properly checking the
links, despite the classnames of the devices.

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

diff -r b9a93806b73a -r 9e4f5b57f412 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c	Tue Oct 14 12:11:00 2008 -0700
+++ b/libxkutil/device_parsing.c	Tue Oct 14 14:00:18 2008 -0700
@@ -82,7 +82,8 @@
         if (dev == NULL)
                 return; /* free()-like semantics */
 
-        if (dev->type == CIM_RES_TYPE_DISK)
+        if ((dev->type == CIM_RES_TYPE_DISK) ||
+            (dev->type == CIM_RES_TYPE_CDROM))
                 cleanup_disk_device(&dev->dev.disk);
         else if (dev->type == CIM_RES_TYPE_NET)
                 cleanup_net_device(&dev->dev.net);
@@ -235,10 +236,16 @@
                                 goto err;
                 }
         }
-        if ((ddev->source == NULL) || (ddev->virtual_dev == NULL))
+        if (ddev->virtual_dev == NULL)
                 goto err;
 
-        vdev->type = CIM_RES_TYPE_DISK;
+        if ((ddev->source == NULL) && (!STREQC(ddev->device, "cdrom")))
+                goto err;
+
+        if (STREQC(ddev->device, "cdrom"))
+                vdev->type = CIM_RES_TYPE_CDROM;
+        else
+                vdev->type = CIM_RES_TYPE_DISK;
         vdev->id = strdup(ddev->virtual_dev);
 
         *vdevs = vdev;
@@ -479,7 +486,8 @@
         /* point to correct parser function according to type */
         if (type == CIM_RES_TYPE_NET)
                 do_real_parse = &parse_net_device;
-        else if (type == CIM_RES_TYPE_DISK)
+        else if ((type == CIM_RES_TYPE_DISK) ||
+                 (type == CIM_RES_TYPE_CDROM))
                 do_real_parse = &parse_disk_device;
         else if (type == CIM_RES_TYPE_PROC)
                 do_real_parse = parse_vcpu_device;
@@ -547,7 +555,8 @@
 
         if (type == CIM_RES_TYPE_NET)
                 xpathstr = NET_XPATH;
-        else if (type == CIM_RES_TYPE_DISK)
+        else if ((type == CIM_RES_TYPE_DISK) ||
+                 (type == CIM_RES_TYPE_CDROM))
                 xpathstr = DISK_XPATH;
         else if (type == CIM_RES_TYPE_PROC)
                 xpathstr = VCPU_XPATH;
@@ -605,7 +614,8 @@
                 DUP_FIELD(dev, _dev, dev.net.mac);
                 DUP_FIELD(dev, _dev, dev.net.type);
                 DUP_FIELD(dev, _dev, dev.net.source);
-        } else if (dev->type == CIM_RES_TYPE_DISK) {
+        } else if ((dev->type == CIM_RES_TYPE_DISK) ||
+                   (dev->type == CIM_RES_TYPE_CDROM)) {
                 DUP_FIELD(dev, _dev, dev.disk.type);
                 DUP_FIELD(dev, _dev, dev.disk.device);
                 DUP_FIELD(dev, _dev, dev.disk.driver);
diff -r b9a93806b73a -r 9e4f5b57f412 schema/LogicalDisk.mof
--- a/schema/LogicalDisk.mof	Tue Oct 14 12:11:00 2008 -0700
+++ b/schema/LogicalDisk.mof	Tue Oct 14 14:00:18 2008 -0700
@@ -19,6 +19,15 @@
 };
 
 [Description (
+	"A class derived from CIM_CDROMDrive to represent "
+	"the KVM virtual CDROM drive in a guest."),
+ Provider("cmpi::Virt_Device")
+]
+class KVM_CDROMDrive : CIM_CDROMDrive
+{
+};
+
+[Description (
 	"A class derived from CIM_LogicalDisk to represent "
 	"the KVM virtual disks on the system."),
  Provider("cmpi::Virt_Device")
diff -r b9a93806b73a -r 9e4f5b57f412 schema/LogicalDisk.registration
--- a/schema/LogicalDisk.registration	Tue Oct 14 12:11:00 2008 -0700
+++ b/schema/LogicalDisk.registration	Tue Oct 14 14:00:18 2008 -0700
@@ -2,4 +2,5 @@
 # Classname Namespace ProviderName ProviderModule ProviderTypes
 Xen_LogicalDisk root/virt Virt_Device Virt_Device instance
 KVM_LogicalDisk root/virt Virt_Device Virt_Device instance
+KVM_CDROMDrive root/virt Virt_Device Virt_Device instance
 LXC_LogicalDisk root/virt Virt_Device Virt_Device instance
diff -r b9a93806b73a -r 9e4f5b57f412 src/Virt_Device.c
--- a/src/Virt_Device.c	Tue Oct 14 12:11:00 2008 -0700
+++ b/src/Virt_Device.c	Tue Oct 14 14:00:18 2008 -0700
@@ -124,11 +124,26 @@
 {
         CMPIInstance *inst;
         virConnectPtr conn;
+        const char *conntype;
+        const char *basetype;
 
         conn = virDomainGetConnect(dom);
+        conntype = virConnectGetType(conn);
+        if (conntype == NULL) {
+                CU_DEBUG("Unable to get connection type");
+                return NULL;
+        }
+
+        if (STREQ(conntype, "QEMU") && STREQC(dev->device, "cdrom"))
+                basetype = "CDROMDrive";
+        else
+                basetype = "LogicalDisk";
+
+        CU_DEBUG("DISK BASE TYPE: %s, device is %s", basetype, dev->device);
+
         inst = get_typed_instance(broker,
                                   pfx_from_conn(conn),
-                                  "LogicalDisk",
+                                  basetype,
                                   ns);
 
         if (!disk_set_name(inst, dev))
@@ -301,7 +316,8 @@
                                                 &dev->dev.net,
                                                 dom,
                                                 ns);
-                else if (dev->type == CIM_RES_TYPE_DISK)
+                else if ((dev->type == CIM_RES_TYPE_DISK) ||
+                         (dev->type == CIM_RES_TYPE_CDROM))
                         instance = disk_instance(broker,
                                                  &dev->dev.disk,
                                                  dom,
@@ -346,6 +362,8 @@
                 return CIM_RES_TYPE_MEM;
         else if (strstr(classname, "Processor"))
                 return CIM_RES_TYPE_PROC;
+        else if (strstr(classname, "CDROMDrive"))
+                return CIM_RES_TYPE_CDROM;
         else
                 return CIM_RES_TYPE_UNKNOWN;
 }
diff -r b9a93806b73a -r 9e4f5b57f412 src/Virt_DevicePool.c
--- a/src/Virt_DevicePool.c	Tue Oct 14 12:11:00 2008 -0700
+++ b/src/Virt_DevicePool.c	Tue Oct 14 14:00:18 2008 -0700
@@ -476,7 +476,8 @@
                 poolid = strdup("MemoryPool/0");
         else if (type == CIM_RES_TYPE_NET)
                 poolid = netpool_member_of(broker, id, refcn);
-        else if (type == CIM_RES_TYPE_DISK)
+        else if ((type == CIM_RES_TYPE_DISK) ||
+                 (type == CIM_RES_TYPE_CDROM))
                 poolid = diskpool_member_of(broker, id, refcn);
         else
                 return NULL;
diff -r b9a93806b73a -r 9e4f5b57f412 src/Virt_ElementAllocatedFromPool.c
--- a/src/Virt_ElementAllocatedFromPool.c	Tue Oct 14 12:11:00 2008 -0700
+++ b/src/Virt_ElementAllocatedFromPool.c	Tue Oct 14 14:00:18 2008 -0700
@@ -191,6 +191,7 @@
         "KVM_Memory",
         "KVM_NetworkPort",
         "KVM_LogicalDisk",
+        "KVM_CDROMDrive",
         "LXC_Processor",
         "LXC_Memory",
         "LXC_NetworkPort",
diff -r b9a93806b73a -r 9e4f5b57f412 src/Virt_RASD.c
--- a/src/Virt_RASD.c	Tue Oct 14 12:11:00 2008 -0700
+++ b/src/Virt_RASD.c	Tue Oct 14 14:00:18 2008 -0700
@@ -247,7 +247,8 @@
         char *id;
         const char *keys[] = {"InstanceID", NULL};
 
-        if (dev->type == CIM_RES_TYPE_DISK) {
+        if ((dev->type == CIM_RES_TYPE_DISK) ||
+            (dev->type == CIM_RES_TYPE_CDROM)) {
                 type = CIM_RES_TYPE_DISK;
                 base = "DiskResourceAllocationSettingData";
         } else if (dev->type == CIM_RES_TYPE_NET) {
diff -r b9a93806b73a -r 9e4f5b57f412 src/Virt_SettingsDefineState.c
--- a/src/Virt_SettingsDefineState.c	Tue Oct 14 12:11:00 2008 -0700
+++ b/src/Virt_SettingsDefineState.c	Tue Oct 14 14:00:18 2008 -0700
@@ -330,6 +330,7 @@
         "KVM_Memory",
         "KVM_NetworkPort",
         "KVM_LogicalDisk",
+        "KVM_CDROMDrive",
         "LXC_Processor",
         "LXC_Memory",
         "LXC_NetworkPort",
diff -r b9a93806b73a -r 9e4f5b57f412 src/Virt_SystemDevice.c
--- a/src/Virt_SystemDevice.c	Tue Oct 14 12:11:00 2008 -0700
+++ b/src/Virt_SystemDevice.c	Tue Oct 14 14:00:18 2008 -0700
@@ -138,6 +138,7 @@
         "KVM_Memory",
         "KVM_NetworkPort",
         "KVM_LogicalDisk",
+        "KVM_CDROMDrive",
         "LXC_Processor",
         "LXC_Memory",
         "LXC_NetworkPort",
diff -r b9a93806b73a -r 9e4f5b57f412 src/svpc_types.h
--- a/src/svpc_types.h	Tue Oct 14 12:11:00 2008 -0700
+++ b/src/svpc_types.h	Tue Oct 14 14:00:18 2008 -0700
@@ -29,14 +29,16 @@
 #define CIM_RES_TYPE_DISK       17
 #define CIM_RES_TYPE_EMU        1
 #define CIM_RES_TYPE_GRAPHICS   24
+#define CIM_RES_TYPE_CDROM      15
 #define CIM_RES_TYPE_UNKNOWN    1000
 
-#define CIM_RES_TYPE_COUNT 4
+#define CIM_RES_TYPE_COUNT 5
 const static int cim_res_types[CIM_RES_TYPE_COUNT] = 
   {CIM_RES_TYPE_NET,
    CIM_RES_TYPE_DISK,
    CIM_RES_TYPE_MEM,
    CIM_RES_TYPE_PROC,
+   CIM_RES_TYPE_CDROM,
   };
 
 #define CIM_VSSD_RECOVERY_NONE       2




More information about the Libvirt-cim mailing list