[Libvirt-cim] [PATCH 3 of 3] Add support for representing a cdrom device using the DiskDrive class

Richard Maciel rmaciel at linux.vnet.ibm.com
Fri Apr 24 20:53:58 UTC 2009


# HG changeset patch
# User Richard Maciel <rmaciel at linux.vnet.ibm.com>
# Date 1239995297 10800
# Node ID c2f18f10ab7eb1049998f8e1ae393fecd914910d
# Parent  33c94f360449aa4324eb42d7a630b7959c36613c
Add support for representing a cdrom device using the DiskDrive class

Signed-off-by: Richard Maciel <rmaciel at linux.vnet.ibm.com>

diff -r 33c94f360449 -r c2f18f10ab7e libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c	Thu Apr 02 17:18:52 2009 -0300
+++ b/libxkutil/device_parsing.c	Fri Apr 17 16:08:17 2009 -0300
@@ -92,7 +92,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_DRIVE))
                 cleanup_disk_device(&dev->dev.disk);
         else if (dev->type == CIM_RES_TYPE_NET)
                 cleanup_net_device(&dev->dev.net);
@@ -254,7 +255,14 @@
         if ((ddev->source == NULL) || (ddev->virtual_dev == NULL))
                 goto err;
 
-        vdev->type = CIM_RES_TYPE_DISK;
+        if (STREQ(ddev->device, "disk")) {
+                vdev->type = CIM_RES_TYPE_DISK;
+        } else if (STREQ(ddev->device, "cdrom")) {
+                vdev->type = CIM_RES_TYPE_DRIVE;
+        } else {
+                goto err;
+        }
+                
         vdev->id = strdup(ddev->virtual_dev);
 
         *vdevs = vdev;
@@ -513,6 +521,57 @@
         return true;
 }
 
+static bool filter_list_by_type(int type, struct virt_device **list, int *size)
+{
+        struct virt_device *filtd_list = NULL;
+        struct virt_device *_list = NULL;
+        int filtd_count = 0;
+        int devlstidx = 0;
+
+        filtd_list = calloc(*size, sizeof(**list));
+        if (filtd_list == NULL)
+                goto err;
+
+        /* To be valid, item from list must have the same type
+         * than the provided in type parameter
+         */
+        for (devlstidx = 0; devlstidx < *size; devlstidx++) {
+                if (list[devlstidx]->type == type) {
+                        CU_DEBUG("Item from list (id `%s') accepted by filter", 
+                                 list[devlstidx]->id);
+
+                        memcpy(&filtd_list[filtd_count], 
+                               list[devlstidx], 
+                               sizeof(**list));
+                        
+                        filtd_count++;
+                }
+        }        
+       
+        CU_DEBUG("Number of filtered items: %d", filtd_count);
+
+        _list = realloc(filtd_list, 
+                        filtd_count * sizeof(*filtd_list));
+        
+        if (_list == NULL && filtd_count != 0)
+                goto err;
+
+        free(*list);
+
+        *list = _list;
+        
+        *size = filtd_count;
+
+        return true;
+
+ err:
+        free(filtd_list);
+        
+        CU_DEBUG("Error when filtering list");
+
+        return false;
+}
+
 static int do_parse(xmlNodeSet *nsv, int type, struct virt_device **l)
 {
         int devidx;
@@ -525,7 +584,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_DRIVE))
                 do_real_parse = &parse_disk_device;
         else if (type == CIM_RES_TYPE_PROC)
                 do_real_parse = parse_vcpu_device;
@@ -558,6 +618,15 @@
                 if (devices <= 0)
                         continue;
 
+                if ((type == CIM_RES_TYPE_DISK) || 
+                   (type == CIM_RES_TYPE_DRIVE)) {
+                        if (!filter_list_by_type(type, &tmp_list, &devices)) {
+                                goto end;
+                        }
+                        if (devices == 0)
+                                goto end;
+                }
+
                 if (!resize_devlist(&list, lstidx + devices)) {
                         /* Skip these devices and try again for the
                          * next cycle, which will probably fail, but
@@ -595,7 +664,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_DRIVE))
                 xpathstr = DISK_XPATH;
         else if (type == CIM_RES_TYPE_PROC)
                 xpathstr = VCPU_XPATH;
diff -r 33c94f360449 -r c2f18f10ab7e src/Virt_Device.c
--- a/src/Virt_Device.c	Thu Apr 02 17:18:52 2009 -0300
+++ b/src/Virt_Device.c	Fri Apr 17 16:08:17 2009 -0300
@@ -140,6 +140,26 @@
         return inst;
 }
 
+static CMPIInstance *drive_instance(const CMPIBroker *broker,
+                                    struct disk_device *dev,
+                                    const virDomainPtr dom,
+                                    const char *ns)
+{
+        CMPIInstance *inst;
+        virConnectPtr conn;
+
+        conn = virDomainGetConnect(dom);
+        inst = get_typed_instance(broker,
+                                  pfx_from_conn(conn),
+                                  "DiskDrive",
+                                  ns);
+
+        if (!disk_set_name(inst, dev))
+                return NULL;
+
+        return inst;
+}
+
 static int mem_set_size(CMPIInstance *instance,
                         struct mem_device *dev)
 {
@@ -440,6 +460,11 @@
                                                  &dev->dev.disk,
                                                  dom,
                                                  ns);
+                else if (dev->type == CIM_RES_TYPE_DRIVE)
+                        instance = drive_instance(broker,
+                                                  &dev->dev.disk,
+                                                  dom,
+                                                  ns);
                 else if (dev->type == CIM_RES_TYPE_MEM)
                         instance = mem_instance(broker,
                                                 &dev->dev.mem,
@@ -486,6 +511,8 @@
                 return CIM_RES_TYPE_NET;
         else if (strstr(classname, "LogicalDisk"))
                 return CIM_RES_TYPE_DISK;
+        else if (strstr(classname, "DiskDrive"))
+                return CIM_RES_TYPE_DRIVE;
         else if (strstr(classname, "Memory"))
                 return CIM_RES_TYPE_MEM;
         else if (strstr(classname, "Processor"))
diff -r 33c94f360449 -r c2f18f10ab7e src/svpc_types.h
--- a/src/svpc_types.h	Thu Apr 02 17:18:52 2009 -0300
+++ b/src/svpc_types.h	Fri Apr 17 16:08:17 2009 -0300
@@ -27,12 +27,13 @@
 #define CIM_RES_TYPE_MEM        4
 #define CIM_RES_TYPE_NET        10
 #define CIM_RES_TYPE_DISK       31
+#define CIM_RES_TYPE_DRIVE      17
 #define CIM_RES_TYPE_EMU        1
 #define CIM_RES_TYPE_GRAPHICS   24
 #define CIM_RES_TYPE_INPUT      13 
 #define CIM_RES_TYPE_UNKNOWN    1000
 
-#define CIM_RES_TYPE_COUNT 6
+#define CIM_RES_TYPE_COUNT 7 
 const static int cim_res_types[CIM_RES_TYPE_COUNT] = 
   {CIM_RES_TYPE_NET,
    CIM_RES_TYPE_DISK,
@@ -40,6 +41,7 @@
    CIM_RES_TYPE_PROC,
    CIM_RES_TYPE_GRAPHICS,
    CIM_RES_TYPE_INPUT,
+   CIM_RES_TYPE_DRIVE,
   };
 
 #define CIM_VSSD_RECOVERY_NONE       2




More information about the Libvirt-cim mailing list