# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1225319502 25200
# Node ID 791b8e26b4ab4c2f1141f9bf807ece19fb08238c
# Parent b070e80c1c0fb2621b5d601c2aa5d57b6501e8b9
(#2) Add graphics device support to VSMS.
Updates from 1 to 2:
-Remove double strdup in graphics_rasd_to_vdev()
-parse_id() returns an int - check return appropriately
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r b070e80c1c0f -r 791b8e26b4ab src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c Wed Oct 29 15:31:42 2008 -0700
+++ b/src/Virt_VirtualSystemManagementService.c Wed Oct 29 15:31:42 2008 -0700
@@ -211,8 +211,7 @@
return 1;
}
-static bool default_graphics_device(CMPIInstance *inst,
- struct domain *domain)
+static bool default_graphics_device(struct domain *domain)
{
free(domain->dev_graphics);
domain->dev_graphics = calloc(1, sizeof(*domain->dev_graphics));
@@ -223,6 +222,19 @@
domain->dev_graphics->dev.graphics.type = strdup("vnc");
domain->dev_graphics->dev.graphics.port = strdup("-1");
+ domain->dev_graphics->dev.graphics.host = strdup("127.0.0.1");
+ domain->dev_graphics->dev.graphics.keymap = strdup("en-us");
+ domain->dev_graphics_ct = 1;
+
+ return true;
+}
+
+static bool add_default_devs(struct domain *domain)
+{
+ if (domain->dev_graphics_ct != 1) {
+ if (!default_graphics_device(domain))
+ return false;
+ }
return true;
}
@@ -275,9 +287,6 @@
else {
CU_DEBUG("Unknown domain prefix: %s", pfx);
}
-
- if (!default_graphics_device(inst, domain))
- ret = 0;
out:
free(pfx);
@@ -554,6 +563,41 @@
return NULL;
}
+static const char *graphics_rasd_to_vdev(CMPIInstance *inst,
+ struct virt_device *dev)
+{
+ const char *val;
+ const char *msg = NULL;
+ const char *keymap;
+ char *addr = NULL;
+ char *port = NULL;
+
+ dev->dev.graphics.type = strdup("vnc");
+
+ /* FIXME: Add logic to prevent address:port collisions */
+ if (cu_get_str_prop(inst, "Address", &val) != CMPI_RC_OK) {
+ dev->dev.graphics.port = strdup("-1");
+ dev->dev.graphics.host = strdup("127.0.0.1");
+ } else if (parse_id(val, &addr, &port) == 1) {
+ dev->dev.graphics.port = strdup(port);
+ dev->dev.graphics.host = strdup(addr);
+ } else {
+ msg = "GraphicsRASD field Address not valid";
+ goto out;
+ }
+
+ if (cu_get_str_prop(inst, "KeyMapping", &keymap) != CMPI_RC_OK)
+ keymap = "en-us";
+
+ dev->dev.graphics.keymap = strdup(keymap);
+
+ out:
+ free(addr);
+ free(port);
+
+ return msg;
+}
+
static const char *_sysvirt_rasd_to_vdev(CMPIInstance *inst,
struct virt_device *dev,
uint16_t type,
@@ -567,6 +611,8 @@
return mem_rasd_to_vdev(inst, dev);
} else if (type == CIM_RES_TYPE_PROC) {
return proc_rasd_to_vdev(inst, dev);
+ } else if (type == CIM_RES_TYPE_GRAPHICS) {
+ return graphics_rasd_to_vdev(inst, dev);
}
return "Resource type not supported on this platform";
@@ -585,6 +631,8 @@
return net_rasd_to_vdev(inst, dev, ns);
} else if (type == CIM_RES_TYPE_PROC) {
return lxc_proc_rasd_to_vdev(inst, dev);
+ } else if (type == CIM_RES_TYPE_GRAPHICS) {
+ return graphics_rasd_to_vdev(inst, dev);
}
return "Resource type not supported on this platform";
@@ -688,6 +736,9 @@
if (!make_space(&domain->dev_net, domain->dev_net_ct, count))
return "Failed to alloc net list";
+ if (!make_space(&domain->dev_graphics, domain->dev_graphics_ct,
count))
+ return "Failed to alloc graphics list";
+
for (i = 0; i < count; i++) {
CMPIObjectPath *op;
CMPIData item;
@@ -748,6 +799,12 @@
domain->dev_net,
ncount,
&domain->dev_net_ct);
+ } else if (type == CIM_RES_TYPE_GRAPHICS) {
+ domain->dev_graphics_ct = 1;
+ msg = rasd_to_vdev(inst,
+ domain,
+ &domain->dev_graphics[0],
+ ns);
}
if (msg != NULL)
return msg;
@@ -993,6 +1050,14 @@
goto out;
}
+ if (!add_default_devs(domain)) {
+ CU_DEBUG("Failed to add default devices");
+ cu_statusf(_BROKER, s,
+ CMPI_RC_ERR_FAILED,
+ "ResourceSettings Error");
+ goto out;
+ }
+
xml = system_to_xml(domain);
CU_DEBUG("System XML:\n%s", xml);
@@ -1264,6 +1329,9 @@
} else if (type == CIM_RES_TYPE_MEM) {
list = &dominfo->dev_mem;
*count = &dominfo->dev_mem_ct;
+ } else if (type == CIM_RES_TYPE_GRAPHICS) {
+ list = &dominfo->dev_graphics;
+ *count = &dominfo->dev_graphics_ct;
}
return list;