[Libvirt-cim] [PATCH] Ensure graphics devices have unique IDs

Chip Vincent cvincent at linux.vnet.ibm.com
Wed May 11 16:39:43 UTC 2011


# HG changeset patch
# User Chip Vincent <cvincent at us.ibm.com>
# Date 1305131981 14400
# Node ID 90f8c9f2388e0563baa311c84024ca41a61e1890
# Parent  8b428df21c360d1eaedba7157b0dfd429d2db121
Ensure graphics devices have unique IDs

Now that multiple graphics device types are supported, it important that they have unique names that are consistent over time. This patch updates the graphics->id to replace 'graphics' with <graphics_type> for vnc and <graphics_type>:<port> for serial/console. The port is ommitted from vnc connections because it changes when VM started if autoport is enabled and only one connection is currently supported. The source path is ommitted from serial/console connections because it is present only when the VM is running. Since libvirt limits the number of serial/console pty resources and ensures they have unique ports, the source path is not necessary to ensure consistent unique names.

Examples of new graphics id format:
InstanceID="test_domain/serial:0"
InstanceID="test_domain/serial:1"
InstanceID="test_domain/console:0"
InstanceID="test_domain/vnc"

Signed-off-by: Chip Vincent <cvincent at us.ibm.com>

diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -503,6 +503,7 @@
         struct virt_device *vdev = NULL;
         struct graphics_device *gdev = NULL;
         xmlNode *child = NULL;
+        int ret;
 
         vdev = calloc(1, sizeof(*vdev));
         if (vdev == NULL)
@@ -547,14 +548,16 @@
         }
 
         vdev->type = CIM_RES_TYPE_GRAPHICS;
-        vdev->id = strdup("graphics");
+        
+        if (STREQC(gdev->type, "vnc")) 
+                ret = asprintf(&vdev->id, "%s", gdev->type);
+        else
+                ret = asprintf(&vdev->id, "%s:%s", gdev->type, gdev->port);
 
-        /* FIXME: IDs should be unique, but that breaks existing tests.
-        ret = asprintf(&vdev->id, "graphics:%s", gdev->type);
-        if(ret == -1) {
+        if (ret == -1) {
                 CU_DEBUG("Failed to create graphics is string");
                 goto err;
-        } */
+        }
 
         *vdevs = vdev;
 




More information about the Libvirt-cim mailing list