[Libvirt-cim] [PATCH] Fix the problem that libvirt-cim can't find cdrom device that do not have disk

Wayne Xia xiawenc at linux.vnet.ibm.com
Fri Sep 16 06:58:09 UTC 2011


# HG changeset patch
# User Wayne Xia <xiawenc at linux.vnet.ibm.com>
# Date 1316154275 -28800
# Node ID 04b73e1cdc3087a390b9790c13b42ebacbc5d5ba
# Parent  fb09136deb494008eb3aacee420ad74da7d7c294
Fix the problem that libvirt-cim can't find cdrom device that do not have disk

This patch would allow define a system with a empty CDROM device, and allow method modify
resource settings to insert ISO files into an empty CDROM device.
Examples:
InvokeMethod(ModifyResourceSettings):
ResourceSettings: ['instance of KVM_DiskResourceAllocationSettingData {\nResourceType = 17;\nInstanceID = "test/hdc";\nEmulatedType = 1;\nVirtualDevice = "hdc";\nAddress = "";\n};']
InvokeMethod(ModifyResourceSettings):
ResourceSettings: ['instance of KVM_DiskResourceAllocationSettingData {\nResourceType = 17;\nInstanceID = "test/hdc";\nEmulatedType = 1;\nVirtualDevice = "hdc";\nAddress = "/var/lib/libvirt/images/test-disk.iso";\n};']
Note that the Address property should be set to "", not None(not set), to tell that user want
an ejection.

Signed-off-by: Wayne Xia <xiawenc at linux.vnet.ibm.com>

diff -r fb09136deb49 -r 04b73e1cdc30 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c	Tue Aug 30 08:48:36 2011 -0700
+++ b/libxkutil/device_parsing.c	Fri Sep 16 14:24:35 2011 +0800
@@ -287,6 +287,12 @@
                         ddev->shareable = true;
                 }
         }
+
+        if ((XSTREQ(ddev->device, "cdrom")) && (ddev->source == NULL)) {
+                ddev->source = strdup("");
+                ddev->disk_type = DISK_FILE;
+        }
+
         if ((ddev->source == NULL) || (ddev->virtual_dev == NULL))
                 goto err;
 
diff -r fb09136deb49 -r 04b73e1cdc30 libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c	Tue Aug 30 08:48:36 2011 -0700
+++ b/libxkutil/xmlgen.c	Fri Sep 16 14:24:35 2011 +0800
@@ -110,10 +110,15 @@
                         xmlNewProp(tmp, BAD_CAST "cache", BAD_CAST dev->cache);
         }
 
-        tmp = xmlNewChild(disk, NULL, BAD_CAST "source", NULL);
-        if (tmp == NULL)
-                return XML_ERROR;
-        xmlNewProp(tmp, BAD_CAST "file", BAD_CAST dev->source);
+        if ((XSTREQ(dev->device, "cdrom")) &&
+                        (XSTREQ(dev->source, ""))) {
+                /* do nothing */
+        } else {
+                tmp = xmlNewChild(disk, NULL, BAD_CAST "source", NULL);
+                if (tmp == NULL)
+                        return XML_ERROR;
+                xmlNewProp(tmp, BAD_CAST "file", BAD_CAST dev->source);
+        }
 
         tmp = xmlNewChild(disk, NULL, BAD_CAST "target", NULL);
         if (tmp == NULL)
diff -r fb09136deb49 -r 04b73e1cdc30 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Tue Aug 30 08:48:36 2011 -0700
+++ b/src/Virt_VirtualSystemManagementService.c	Fri Sep 16 14:24:35 2011 +0800
@@ -879,6 +879,12 @@
                 dev->dev.disk.device = strdup("disk");
         else if (type == VIRT_DISK_TYPE_CDROM) {
                 dev->dev.disk.device = strdup("cdrom");
+                if ((XSTREQ(dev->dev.disk.source, "/dev/null")) ||
+                        (XSTREQ(dev->dev.disk.source, ""))) {
+                        dev->dev.disk.disk_type = DISK_FILE;
+                        free(dev->dev.disk.source);
+                        dev->dev.disk.source = strdup("");
+                }
                 if (dev->dev.disk.disk_type == DISK_UNKNOWN)
                         dev->dev.disk.disk_type = DISK_PHY;
         }




More information about the Libvirt-cim mailing list