On 12/05/2013 09:17 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy(a)linux.vnet.ibm.com>
This patch is to parse USB keyboard qemu command line
s/parse/format/
and add test cases for it.
Signed-off-by: Li Zhang <zhlcindy(a)linux.vnet.ibm.com>
---
src/qemu/qemu_command.c | 18 +++++++++++++++---
.../qemuxml2argv-pseries-usb-kbd.args | 9 +++++++++
.../qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.xml | 19 +++++++++++++++++++
tests/qemuxml2argvtest.c | 3 +++
4 files changed, 46 insertions(+), 3 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.xml
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 9539be7..d65fe27 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5307,9 +5307,21 @@ qemuBuildUSBInputDevStr(virDomainDefPtr def,
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
- virBufferAsprintf(&buf, "%s,id=%s",
- dev->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ?
- "usb-mouse" : "usb-tablet",
dev->info.alias);
+ switch (dev->type) {
+ case VIR_DOMAIN_INPUT_TYPE_MOUSE:
+ virBufferAsprintf(&buf, "usb-mouse,id=%s", dev->info.alias);
+ break;
+ case VIR_DOMAIN_INPUT_TYPE_TABLET:
+ virBufferAsprintf(&buf, "usb-tablet,id=%s", dev->info.alias);
+ break;
+ case VIR_DOMAIN_INPUT_TYPE_KBD:
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_KBD))
Missing virReportError.
+ goto error;
+ virBufferAsprintf(&buf, "usb-kbd,id=%s", dev->info.alias);
+ break;
This would add a tablet if QEMU_CAPS_DEVICE is not supported:
if (input->bus == VIR_DOMAIN_INPUT_BUS_USB) {
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
char *optstr;
virCommandAddArg(cmd, "-device");
if (!(optstr = qemuBuildUSBInputDevStr(def, input, qemuCaps)))
goto error;
virCommandAddArg(cmd, optstr);
VIR_FREE(optstr);
} else {
virCommandAddArgList(cmd, "-usbdevice",
input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE
? "mouse" : "tablet", NULL);
}
}