[PATCH 0 of 3] Add input support to VSMS

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1227634876 28800 # Node ID 145a9c11532328a4dccaa1f42cd91e8bfbda9446 # Parent db393eb037a0782d2e8328d2e2fd0582e185f08b Add input support to xmlgen, add get_input_type_bus_from_cap() to Virt_Device Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r db393eb037a0 -r 145a9c115323 libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Mon Nov 24 10:27:55 2008 -0800 +++ b/libxkutil/xmlgen.c Tue Nov 25 09:41:16 2008 -0800 @@ -383,6 +383,26 @@ return true; } +static bool input_to_xml(char **xml, struct virt_device *dev) +{ + int ret; + char *_xml; + struct input_device *input = &dev->dev.input; + + ret = asprintf(&_xml, + "<input type='%s' bus='%s'/>\n", + input->type != NULL ? input->type: "mouse", + input->bus != NULL ? input->bus : "ps2"); + if (ret == -1) + return false; + else + astrcat(xml, _xml); + + free(_xml); + + return true; +} + static bool concat_devxml(char **xml, struct virt_device *list, int count, @@ -430,6 +450,9 @@ break; case CIM_RES_TYPE_GRAPHICS: func = graphics_to_xml; + break; + case CIM_RES_TYPE_INPUT: + func = input_to_xml; break; default: return NULL; @@ -706,6 +729,12 @@ dominfo->dev_graphics_ct, graphics_to_xml); + if (dominfo->dev_input) + concat_devxml(&devxml, + dominfo->dev_input, + dominfo->dev_input_ct, + input_to_xml); + console_xml(dominfo, &devxml); concat_devxml(&sysdevxml, diff -r db393eb037a0 -r 145a9c115323 src/Virt_Device.c --- a/src/Virt_Device.c Mon Nov 24 10:27:55 2008 -0800 +++ b/src/Virt_Device.c Tue Nov 25 09:41:16 2008 -0800 @@ -254,6 +254,42 @@ } return 1; +} + +int get_input_type_bus_from_cap(const char *cap, + char **type, + char **bus, + char **virt_type) +{ + if (sscanf(cap, "%a[^ ] %a[^ ] %as", virt_type, bus, type) != 3) { + if (sscanf(cap, "%a[^ ] %as", bus, type) != 2) + goto out; + else { + free(*virt_type); + *virt_type = NULL; + } + } + + if (STREQC(*type, "Mouse")) + *type = strdup("mouse"); + else if (STREQC(*type, "Tablet")) + *type = strdup("tablet"); + else + goto out; + + if (STREQC(*bus, "USB")) + *bus = strdup("usb"); + else if (STREQC(*bus, "PS2")) + *bus = strdup("ps2"); + else if (STREQC(*bus, "Xen")) + *bus = strdup("xen"); + else + goto out; + + return 1; + + out: + return 0; } static int input_set_attr(CMPIInstance *instance, diff -r db393eb037a0 -r 145a9c115323 src/Virt_Device.h --- a/src/Virt_Device.h Mon Nov 24 10:27:55 2008 -0800 +++ b/src/Virt_Device.h Tue Nov 25 09:41:16 2008 -0800 @@ -75,6 +75,11 @@ const char *bus, char **cap); +int get_input_type_bus_from_cap(const char *cap, + char **type, + char **bus, + char **virt_type); + #endif /*

KR> +int get_input_type_bus_from_cap(const char *cap, KR> + char **type, KR> + char **bus, KR> + char **virt_type) KR> +{ KR> + if (sscanf(cap, "%a[^ ] %a[^ ] %as", virt_type, bus, type) != 3) { KR> + if (sscanf(cap, "%a[^ ] %as", bus, type) != 2) I don't like this at all. I think the caption field should be rather free-form and human-oriented. If we do this, then we have to update this cascading if to support more and more caption formats in the future. Can we do this in a different way? -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1227634876 28800 # Node ID 8a1f369f8f70a23eea6771ed09cd06ce74992be2 # Parent 145a9c11532328a4dccaa1f42cd91e8bfbda9446 Add input support to DefneSystem() Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 145a9c115323 -r 8a1f369f8f70 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Tue Nov 25 09:41:16 2008 -0800 +++ b/src/Virt_VirtualSystemManagementService.c Tue Nov 25 09:41:16 2008 -0800 @@ -229,10 +229,39 @@ return true; } +static bool default_input_device(struct domain *domain) +{ + free(domain->dev_input); + domain->dev_input = calloc(1, sizeof(*domain->dev_input)); + if (domain->dev_input == NULL) { + CU_DEBUG("Failed to allocate default input device"); + return false; + } + + domain->dev_input->dev.input.type = strdup("mouse"); + + if (domain->type == DOMAIN_LXC) { + domain->dev_input->dev.input.bus = strdup("usb"); + } else if (domain->type == DOMAIN_XENPV) { + domain->dev_input->dev.input.bus = strdup("xen"); + } else { + domain->dev_input->dev.input.bus = strdup("ps2"); + } + + domain->dev_input_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; + } + + if (domain->dev_input_ct < 1) { + if (!default_input_device(domain)) return false; } @@ -597,6 +626,50 @@ return msg; } +static const char *input_rasd_to_vdev(CMPIInstance *inst, + struct virt_device *dev) +{ + CMPIObjectPath *op = NULL; + const char *val; + const char *msg; + char *type = NULL; + char *bus = NULL; + char *vtype = NULL; + + if (cu_get_str_prop(inst, "ResourceSubType", &val) != CMPI_RC_OK) { + msg = "InputRASD ResourceSubType field not valid"; + goto out; + } + + dev->dev.input.type = strdup(val); + + op = CMGetObjectPath(inst, NULL); + if (op == NULL) { + CU_DEBUG("Unable to determine class of InputRASD"); + return NULL; + } + + if ((cu_get_str_prop(inst, "Caption", &val) != CMPI_RC_OK) || + (get_input_type_bus_from_cap(val, &type, &bus, &vtype) != 1)) { + if (STREQC(dev->dev.input.type, "mouse")) + dev->dev.input.bus = strdup("ps2"); + else if (STREQC(dev->dev.input.type, "tablet")) + dev->dev.input.bus = strdup("usb"); + else { + msg = "Invalid value for ResourceSubType in InputRASD"; + goto out; + } + } else + dev->dev.input.bus = strdup(bus); + + out: + free(type); + free(bus); + free(vtype); + + return NULL; +} + static const char *_sysvirt_rasd_to_vdev(CMPIInstance *inst, struct virt_device *dev, uint16_t type, @@ -612,6 +685,8 @@ return proc_rasd_to_vdev(inst, dev); } else if (type == CIM_RES_TYPE_GRAPHICS) { return graphics_rasd_to_vdev(inst, dev); + } else if (type == CIM_RES_TYPE_INPUT) { + return input_rasd_to_vdev(inst, dev); } return "Resource type not supported on this platform"; @@ -632,6 +707,8 @@ return lxc_proc_rasd_to_vdev(inst, dev); } else if (type == CIM_RES_TYPE_GRAPHICS) { return graphics_rasd_to_vdev(inst, dev); + } else if (type == CIM_RES_TYPE_INPUT) { + return input_rasd_to_vdev(inst, dev); } return "Resource type not supported on this platform"; @@ -738,6 +815,9 @@ if (!make_space(&domain->dev_graphics, domain->dev_graphics_ct, count)) return "Failed to alloc graphics list"; + if (!make_space(&domain->dev_input, domain->dev_input_ct, count)) + return "Failed to alloc input list"; + for (i = 0; i < count; i++) { CMPIObjectPath *op; CMPIData item; @@ -803,6 +883,12 @@ msg = rasd_to_vdev(inst, domain, &domain->dev_graphics[0], + ns); + } else if (type == CIM_RES_TYPE_INPUT) { + domain->dev_input_ct = 1; + msg = rasd_to_vdev(inst, + domain, + &domain->dev_input[0], ns); } if (msg != NULL)

KR> +static bool default_input_device(struct domain *domain) KR> +{ KR> + free(domain->dev_input); KR> + domain->dev_input = calloc(1, sizeof(*domain->dev_input)); KR> + if (domain->dev_input == NULL) { KR> + CU_DEBUG("Failed to allocate default input device"); KR> + return false; KR> + } KR> + KR> + domain->dev_input->dev.input.type = strdup("mouse"); KR> + KR> + if (domain->type == DOMAIN_LXC) { KR> + domain->dev_input->dev.input.bus = strdup("usb"); I don't think we should have a default for LXC. The fact that the LXC driver even allows that in the domain definition is a bug, IMHO. If/when that gets fixed, this code will break us. KR> +static const char *input_rasd_to_vdev(CMPIInstance *inst, KR> + struct virt_device *dev) KR> +{ KR> + CMPIObjectPath *op = NULL; KR> + const char *val; KR> + const char *msg; KR> + char *type = NULL; KR> + char *bus = NULL; KR> + char *vtype = NULL; KR> + KR> + if (cu_get_str_prop(inst, "ResourceSubType", &val) != CMPI_RC_OK) { KR> + msg = "InputRASD ResourceSubType field not valid"; KR> + goto out; KR> + } KR> + KR> + dev->dev.input.type = strdup(val); For this, KR> + KR> + op = CMGetObjectPath(inst, NULL); KR> + if (op == NULL) { KR> + CU_DEBUG("Unable to determine class of InputRASD"); KR> + return NULL; KR> + } KR> + KR> + if ((cu_get_str_prop(inst, "Caption", &val) != CMPI_RC_OK) || KR> + (get_input_type_bus_from_cap(val, &type, &bus, &vtype) != 1)) { KR> + if (STREQC(dev->dev.input.type, "mouse")) KR> + dev->dev.input.bus = strdup("ps2"); KR> + else if (STREQC(dev->dev.input.type, "tablet")) KR> + dev->dev.input.bus = strdup("usb"); KR> + else { KR> + msg = "Invalid value for ResourceSubType in InputRASD"; KR> + goto out; KR> + } KR> + } else KR> + dev->dev.input.bus = strdup(bus); ...and this, we should make sure that an invalid input type properly rejects with the libvirt error when we try to define it. Now that we have that infrastructure in place, it would be nice to make sure that if we don't do input checking here, a reasonable error makes it back to the user. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

KR> + KR> + op = CMGetObjectPath(inst, NULL); KR> + if (op == NULL) { KR> + CU_DEBUG("Unable to determine class of InputRASD"); KR> + return NULL; KR> + } KR> + KR> + if ((cu_get_str_prop(inst, "Caption", &val) != CMPI_RC_OK) || KR> + (get_input_type_bus_from_cap(val, &type, &bus, &vtype) != 1)) { KR> + if (STREQC(dev->dev.input.type, "mouse")) KR> + dev->dev.input.bus = strdup("ps2"); KR> + else if (STREQC(dev->dev.input.type, "tablet")) KR> + dev->dev.input.bus = strdup("usb"); KR> + else { KR> + msg = "Invalid value for ResourceSubType in InputRASD"; KR> + goto out; KR> + } KR> + } else KR> + dev->dev.input.bus = strdup(bus);
...and this, we should make sure that an invalid input type properly rejects with the libvirt error when we try to define it. Now that we have that infrastructure in place, it would be nice to make sure that if we don't do input checking here, a reasonable error makes it back to the user.
This is handled by the error message patch you recently pushed into the tree. You'll see failure messages like: <ERROR CODE="1" DESCRIPTION="CIM_ERR_FAILED: Failed to define domain: internal error unknown input device type 'invalid'"/> <ERROR CODE="1" DESCRIPTION="CIM_ERR_FAILED: Failed to define domain: internal error unknown input bus type 'invalid'"/> I'll submit a new patch set to fix the other issues. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1227636080 28800 # Node ID fe39b8a3b9bc769e8af3e3a39be3b77c34227c25 # Parent 8a1f369f8f70a23eea6771ed09cd06ce74992be2 Add input support to Mod/Del/Add methods. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 8a1f369f8f70 -r fe39b8a3b9bc src/Makefile.am --- a/src/Makefile.am Tue Nov 25 09:41:16 2008 -0800 +++ b/src/Makefile.am Tue Nov 25 10:01:20 2008 -0800 @@ -87,9 +87,9 @@ libVirt_ComputerSystemMigrationIndication_la_SOURCES = Virt_ComputerSystemMigrationIndication.c libVirt_ComputerSystemMigrationIndication_la_LIBADD = -lVirt_ComputerSystem -libVirt_VirtualSystemManagementService_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_ComputerSystemIndication.la libVirt_RASD.la libVirt_HostSystem.la libVirt_DevicePool.la +libVirt_VirtualSystemManagementService_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_ComputerSystemIndication.la libVirt_RASD.la libVirt_HostSystem.la libVirt_DevicePool.la libVirt_Device.la libVirt_VirtualSystemManagementService_la_SOURCES = Virt_VirtualSystemManagementService.c -libVirt_VirtualSystemManagementService_la_LIBADD = -lVirt_ComputerSystem -lVirt_ComputerSystemIndication -lVirt_RASD -lVirt_HostSystem -lVirt_DevicePool +libVirt_VirtualSystemManagementService_la_LIBADD = -lVirt_ComputerSystem -lVirt_ComputerSystemIndication -lVirt_RASD -lVirt_HostSystem -lVirt_DevicePool -lVirt_Device libVirt_VirtualSystemManagementCapabilities_la_DEPENDENCIES = libVirt_HostSystem.la libVirt_VirtualSystemManagementCapabilities_la_SOURCES = Virt_VirtualSystemManagementCapabilities.c diff -r 8a1f369f8f70 -r fe39b8a3b9bc src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Tue Nov 25 09:41:16 2008 -0800 +++ b/src/Virt_VirtualSystemManagementService.c Tue Nov 25 10:01:20 2008 -0800 @@ -50,6 +50,7 @@ #include "Virt_RASD.h" #include "Virt_HostSystem.h" #include "Virt_DevicePool.h" +#include "Virt_Device.h" #include "svpc_types.h" #include "config.h" @@ -1417,6 +1418,9 @@ } else if (type == CIM_RES_TYPE_GRAPHICS) { list = &dominfo->dev_graphics; *count = &dominfo->dev_graphics_ct; + } else if (type == CIM_RES_TYPE_INPUT) { + list = &dominfo->dev_input; + *count = &dominfo->dev_input_ct; } return list; @@ -1535,7 +1539,8 @@ if (STREQ(dev->id, devid)) { dev->type = CIM_RES_TYPE_UNKNOWN; - if (type == CIM_RES_TYPE_GRAPHICS) + if ((type == CIM_RES_TYPE_GRAPHICS) || + (type == CIM_RES_TYPE_INPUT)) cu_statusf(_BROKER, &s, CMPI_RC_OK, ""); else { s = _resource_dynamic(dominfo, @@ -1611,7 +1616,7 @@ dev->type = type; rasd_to_vdev(rasd, dominfo, dev, ns); - if (type == CIM_RES_TYPE_GRAPHICS) { + if ((type == CIM_RES_TYPE_GRAPHICS) || (type == CIM_RES_TYPE_INPUT)) { (*count)++; cu_statusf(_BROKER, &s, CMPI_RC_OK, ""); goto out; @@ -1674,7 +1679,8 @@ if (STREQ(dev->id, devid)) { rasd_to_vdev(rasd, dominfo, dev, ns); - if (type == CIM_RES_TYPE_GRAPHICS) + if ((type == CIM_RES_TYPE_GRAPHICS) || + (type == CIM_RES_TYPE_INPUT)) cu_statusf(_BROKER, &s, CMPI_RC_OK, ""); else { s = _resource_dynamic(dominfo,
participants (2)
-
Dan Smith
-
Kaitlin Rupert