[Libvirt-cim] [PATCH] Patch to allow cdrom media change

Sharad Mishra snmishra at us.ibm.com
Wed Dec 8 20:57:35 UTC 2010


# HG changeset patch
# User Sharad Mishra <snmishra at us.ibm.com>
# Date 1291839626 28800
# Node ID b52f1a92d324cb63a942e56ea99c6984c043e2a8
# Parent  e82f482d4bd2eae19970f9b9a42caecaf46ebeab
Patch to allow cdrom media change.

This  patch allows VMs with  cdrom to change media from one iso to another.
This  is equivalent to virsh command "virsh attach-disk <vm> <path to iso file> hdc --type cdrom --mode readonly
--driver file"

Signed-off-by: Sharad Mishra <snmishra at us.ibm.com>

diff -r e82f482d4bd2 -r b52f1a92d324 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c	Tue Nov 30 13:33:45 2010 -0500
+++ b/libxkutil/device_parsing.c	Wed Dec 08 12:20:26 2010 -0800
@@ -1179,6 +1179,28 @@
 
 }
 
+static int change_disk(virDomainPtr dom,
+                       struct virt_device *dev)
+{
+       
+        char *xml = NULL;
+        int ret = 0;
+
+        xml = device_to_xml(dev);
+
+        CU_DEBUG("New XML is %s", xml);
+        
+        if (virDomainAttachDevice(dom, xml) != 0) {
+                goto out;
+        }
+
+        ret = 1;
+ out:
+        free(xml);
+
+        return ret;
+}
+
 static int change_memory(virDomainPtr dom,
                          struct virt_device *dev)
 {
@@ -1246,8 +1268,10 @@
 {
         if (dev->type == CIM_RES_TYPE_MEM)
                 return change_memory(dom, dev);
-        else if (dev->type == CIM_RES_TYPE_PROC)
+        if (dev->type == CIM_RES_TYPE_PROC)
                 return change_vcpus(dom, dev);
+        if (dev->type == CIM_RES_TYPE_DISK)
+                return change_disk(dom, dev) ;
 
         CU_DEBUG("Unhandled device type %i", dev->type);
 
diff -r e82f482d4bd2 -r b52f1a92d324 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Tue Nov 30 13:33:45 2010 -0500
+++ b/src/Virt_VirtualSystemManagementService.c	Wed Dec 08 12:20:26 2010 -0800
@@ -836,6 +836,7 @@
         const char *val = NULL;
         uint16_t type;
 
+        CU_DEBUG("Enter disk_rasd_to_vdev");
         if (cu_get_str_prop(inst, "VirtualDevice", &val) != CMPI_RC_OK)
                 return "Missing `VirtualDevice' property";
 
@@ -863,6 +864,8 @@
                 dev->dev.disk.device = strdup("floppy");
         else
                 return "Invalid value for EmulatedType";
+        
+        CU_DEBUG("device type is %s", dev->dev.disk.device);
 
         free(dev->dev.disk.bus_type);
         if (cu_get_str_prop(inst, "BusType", &val) != CMPI_RC_OK) 
@@ -1411,6 +1414,7 @@
         virConnectPtr conn = NULL;
         virDomainPtr dom = NULL;
 
+        CU_DEBUG("Enter update_dominfo");
         if (dominfo->dev_vcpu_ct != 1) {
                 /* Right now, we only have extra info for processors */
                 CU_DEBUG("Domain has no vcpu devices!");
@@ -1444,10 +1448,12 @@
         infostore_set_u64(ctx, "limit", dev->dev.vcpu.limit);
 
         dev = dominfo->dev_graphics;
-        if (dev->dev.graphics.passwd != NULL)
-                infostore_set_bool(ctx, "has_vnc_passwd", true);
-        else
-                infostore_set_bool(ctx, "has_vnc_passwd", false);
+        if(dev != NULL){
+                if (dev->dev.graphics.passwd != NULL)
+                        infostore_set_bool(ctx, "has_vnc_passwd", true);
+                else
+                        infostore_set_bool(ctx, "has_vnc_passwd", false);
+        }
 
  out:
         infostore_close(ctx);
@@ -2068,6 +2074,7 @@
         virDomainPtr dom;
         int (*func)(virDomainPtr, struct virt_device *);
 
+        CU_DEBUG("Enter _resource_dynamic");
         if (action == RESOURCE_ADD)
                 func = attach_device;
         else if (action == RESOURCE_DEL)
@@ -2292,6 +2299,7 @@
         int i;
         const char *msg = NULL;
 
+        CU_DEBUG("Enter resource_mod");
         if (devid == NULL) {
                 cu_statusf(_BROKER, &s,
                            CMPI_RC_ERR_INVALID_PARAMETER,
@@ -2361,8 +2369,10 @@
         const char *indication;
         CMPIObjectPath *op;
         struct inst_list list;
-        CMPIInstance  *prev_inst = NULL;
+        CMPIInstance *prev_inst = NULL;
+        CMPIInstance *orig_inst = NULL;
 
+        CU_DEBUG("Enter _update_resources_for");
         inst_list_init(&list);
         if (!get_dominfo(dom, &dominfo)) {
                 virt_set_status(_BROKER, &s,
@@ -2406,14 +2416,23 @@
                                      dummy_name,
                                      type,
                                      NULL,
-                                     &prev_inst);
+                                     &orig_inst);
                 free(dummy_name);
 
                 if (s.rc != CMPI_RC_OK) {
                         CU_DEBUG("Failed to get Previous Instance");
                         goto out;
                 }
-        }
+
+                s = cu_merge_instances(rasd, orig_inst);
+                if (s.rc != CMPI_RC_OK) {
+                        CU_DEBUG("Failed to merge Instances");
+                        goto out;
+                }
+                prev_inst = orig_inst;
+                rasd = orig_inst;
+        
+        } 
 
         s = func(dominfo, rasd, type, devid, NAMESPACE(ref));
         if (s.rc != CMPI_RC_OK) {
@@ -2487,6 +2506,7 @@
         int count;
         uint32_t rc = CIM_SVPC_RETURN_FAILED;
 
+        CU_DEBUG("Enter _update_resource_settings");
         conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
         if (conn == NULL) {
                 cu_statusf(_BROKER, &s,
@@ -2731,6 +2751,7 @@
         CMPIArray *res = NULL;
         struct inst_list list;
 
+        CU_DEBUG("Enter mod_resource_settings");
         inst_list_init(&list);
 
         if (cu_get_array_arg(argsin, "ResourceSettings", &arr) != CMPI_RC_OK) {




More information about the Libvirt-cim mailing list