[libvirt] [PATCH v6 0/6] Support keyboard device

From: Li Zhang <zhlcindy@linux.vnet.ibm.com> This patchset is to add keyboard input device. For PPC64, it doesn't support a default keyboard device when the graphic is enabled. Libvirt supports QEMU command line as "-device VGA" which won't create any keyboard device for it. So it requires libvirt to add a default USB keyboard device for it. This patchset is to add keyboard input device and a default USB keyboard for PPC64. The related discussion in QEMU community: http://lists.nongnu.org/archive/html/qemu-devel/2013-11/msg01734.html Li Zhang (6): conf: Add a keyboard input device type conf: Add one interface to add default input devices conf: Remove the implicit PS2 mouse for non-X86 platforms and add an implicit PS2 keyboard device for X86 platforms. qemu_cap: Add USB keyboard capability qemu: parse qemu command line for USB keyboard Add a default USB keyboard and USB mouse for PPC64 v6 -> v5: * Change kbd to keyboard, and correct -usbdevice parameter. * Remove implicit PS/2 keyboard output in XML in case older libvirtd can read it. (Jan Tomko) * Remove implicit keyboard for XEN to make it safer. v5 -> v4: * Add PS/2 KBD definition in XML file. (Daniel.P.Berrange) * Allow PS/2 KBD devices and set KBD default bus as PS2 for X86, USB for non-x86. (Daniel.P.Berrange) * Add an implicit PS/2 KBD as PS/2 mouse. (Danniel.P.Berrange) v4 -> v3: * Don't remove PS2 mouse device for other virtualization drivers (Jan Tomko). v3 -> v2: * Handle the KBD device type in xen and QEMU driver. (Daniel.P.Berrange) * Remove PS2 mouse device for non-X86 platforms. * Move virDomainDefMaybeAddInput to a new patch. (Jan Tomko) * Replace VIR_REALLOC_N with VIR_APPEND_ELEMENT. (Jan Tomoko) * Fix several typos. (Jan Tomoko) * Add a virReportError when QEMU_CAPS_DEVICE_USB_KBD can't be gotten. (Jan Tomoko) v2 -> v1: * change ifs to switch clause. * reconstruct the patches docs/schemas/domaincommon.rng | 1 + src/conf/domain_conf.c | 115 ++++++++++++++------- src/conf/domain_conf.h | 5 + src/libvirt_private.syms | 1 + src/qemu/qemu_capabilities.c | 3 + src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 41 ++++++-- src/qemu/qemu_domain.c | 23 ++++- src/util/virarch.h | 2 + src/xenxs/xen_sxpr.c | 27 +++-- src/xenxs/xen_xm.c | 30 ++++-- tests/qemucapabilitiesdata/caps_1.2.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.3.1-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.4.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.5.3-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 + tests/qemuhelptest.c | 8 ++ .../qemuxml2argvdata/qemuxml2argv-pseries-disk.xml | 3 +- .../qemuxml2argv-pseries-usb-kbd.args | 9 ++ .../qemuxml2argv-pseries-usb-kbd.xml | 19 ++++ tests/qemuxml2argvtest.c | 3 + 22 files changed, 229 insertions(+), 68 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.xml -- 1.8.2.1

From: Li Zhang <zhlcindy@linux.vnet.ibm.com> There is no keyboard for non-x86 platforms when graphics are enabled. It's preferred to add one USB keyboard. This patch is to add keyboard input device type. Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- docs/schemas/domaincommon.rng | 1 + src/conf/domain_conf.c | 20 +++++++++++++------- src/conf/domain_conf.h | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index c1efcd2..601e7ac 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3269,6 +3269,7 @@ <choice> <value>tablet</value> <value>mouse</value> + <value>keyboard</value> </choice> </attribute> <optional> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f6065ed..9d344bc 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -506,7 +506,8 @@ VIR_ENUM_IMPL(virDomainVideo, VIR_DOMAIN_VIDEO_TYPE_LAST, VIR_ENUM_IMPL(virDomainInput, VIR_DOMAIN_INPUT_TYPE_LAST, "mouse", - "tablet") + "tablet", + "keyboard") VIR_ENUM_IMPL(virDomainInputBus, VIR_DOMAIN_INPUT_BUS_LAST, "ps2", @@ -7796,8 +7797,9 @@ virDomainInputDefParseXML(const char *ostype, } if (STREQ(ostype, "hvm")) { - if (def->bus == VIR_DOMAIN_INPUT_BUS_PS2 && /* Only allow mouse for ps2 */ - def->type != VIR_DOMAIN_INPUT_TYPE_MOUSE) { + if (def->bus == VIR_DOMAIN_INPUT_BUS_PS2 && /* PS2 can be mouse or keyboard */ + !(def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + def->type == VIR_DOMAIN_INPUT_TYPE_KBD)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("ps2 bus does not support %s input device"), type); @@ -7815,7 +7817,8 @@ virDomainInputDefParseXML(const char *ostype, _("unsupported input bus %s"), bus); } - if (def->type != VIR_DOMAIN_INPUT_TYPE_MOUSE) { + if (def->type != VIR_DOMAIN_INPUT_TYPE_MOUSE && + def->type != VIR_DOMAIN_INPUT_TYPE_KBD) { virReportError(VIR_ERR_INTERNAL_ERROR, _("xen bus does not support %s input device"), type); @@ -7824,7 +7827,8 @@ virDomainInputDefParseXML(const char *ostype, } } else { if (STREQ(ostype, "hvm")) { - if (def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE) + if (def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + def->type == VIR_DOMAIN_INPUT_TYPE_KBD) def->bus = VIR_DOMAIN_INPUT_BUS_PS2; else def->bus = VIR_DOMAIN_INPUT_BUS_USB; @@ -12422,10 +12426,12 @@ virDomainDefParseXML(xmlDocPtr xml, * XXX will this be true for other virt types ? */ if ((STREQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_PS2 && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE) || + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD)) || (STRNEQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_XEN && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE)) { + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD))) { virDomainInputDefFree(input); continue; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4895e81..98706d5 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1239,6 +1239,7 @@ struct _virDomainTPMDef { enum virDomainInputType { VIR_DOMAIN_INPUT_TYPE_MOUSE, VIR_DOMAIN_INPUT_TYPE_TABLET, + VIR_DOMAIN_INPUT_TYPE_KBD, VIR_DOMAIN_INPUT_TYPE_LAST }; -- 1.8.2.1

On 02/13/2014 09:48 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
There is no keyboard for non-x86 platforms when graphics are enabled. It's preferred to add one USB keyboard.
This patch is to add keyboard input device type.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- docs/schemas/domaincommon.rng | 1 + src/conf/domain_conf.c | 20 +++++++++++++------- src/conf/domain_conf.h | 1 + 3 files changed, 15 insertions(+), 7 deletions(-)
ACK Jan

On Thu, Feb 13, 2014 at 04:48:21PM +0800, Li Zhang wrote:
@@ -12422,10 +12426,12 @@ virDomainDefParseXML(xmlDocPtr xml, * XXX will this be true for other virt types ? */ if ((STREQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_PS2 && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE) || + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD)) || (STRNEQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_XEN && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE)) { + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD))) { virDomainInputDefFree(input); continue;
Later on in this function there is /* If graphics are enabled, there's an implicit PS2 mouse */ if (def->ngraphics > 0) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) { goto error; } if (STREQ(def->os.type, "hvm")) { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; input->bus = VIR_DOMAIN_INPUT_BUS_PS2; } else { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; input->bus = VIR_DOMAIN_INPUT_BUS_XEN; } if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) { virDomainInputDefFree(input); goto error; } def->inputs[def->ninputs] = input; def->ninputs++; } which needs to take care of keyboards too now. And some more similar logic in virDomainDefFormatInternal which needs updating Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 2014年02月14日 00:39, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:48:21PM +0800, Li Zhang wrote:
@@ -12422,10 +12426,12 @@ virDomainDefParseXML(xmlDocPtr xml, * XXX will this be true for other virt types ? */ if ((STREQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_PS2 && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE) || + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD)) || (STRNEQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_XEN && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE)) { + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD))) { virDomainInputDefFree(input); continue; Later on in this function there is
/* If graphics are enabled, there's an implicit PS2 mouse */ if (def->ngraphics > 0) { virDomainInputDefPtr input;
if (VIR_ALLOC(input) < 0) { goto error; } if (STREQ(def->os.type, "hvm")) { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; input->bus = VIR_DOMAIN_INPUT_BUS_PS2; } else { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; input->bus = VIR_DOMAIN_INPUT_BUS_XEN; }
if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) { virDomainInputDefFree(input); goto error; } def->inputs[def->ninputs] = input; def->ninputs++; }
which needs to take care of keyboards too now.
And some more similar logic in virDomainDefFormatInternal which needs updating
ok, I will do it in next version soon. :)
Daniel

On 2014年02月14日 00:39, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:48:21PM +0800, Li Zhang wrote:
@@ -12422,10 +12426,12 @@ virDomainDefParseXML(xmlDocPtr xml, * XXX will this be true for other virt types ? */ if ((STREQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_PS2 && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE) || + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD)) || (STRNEQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_XEN && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE)) { + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD))) { virDomainInputDefFree(input); continue; Later on in this function there is
/* If graphics are enabled, there's an implicit PS2 mouse */ if (def->ngraphics > 0) { virDomainInputDefPtr input;
if (VIR_ALLOC(input) < 0) { goto error; } if (STREQ(def->os.type, "hvm")) { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; input->bus = VIR_DOMAIN_INPUT_BUS_PS2; } else { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; input->bus = VIR_DOMAIN_INPUT_BUS_XEN; }
if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) { virDomainInputDefFree(input); goto error; } def->inputs[def->ninputs] = input; def->ninputs++; }
which needs to take care of keyboards too now.
And some more similar logic in virDomainDefFormatInternal which needs updating
I have add the keyboard device in this function in this version [3/6]. But Jan suggested to remove it from virDomainDefFormatInternal in v5. Because it would make the XML unreadable by older libvirtd that didn't know the keyboard input type.
Daniel

On 02/14/2014 10:02 AM, Li Zhang wrote:
On 2014年02月14日 00:39, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:48:21PM +0800, Li Zhang wrote:
@@ -12422,10 +12426,12 @@ virDomainDefParseXML(xmlDocPtr xml, * XXX will this be true for other virt types ? */ if ((STREQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_PS2 && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE) || + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD)) || (STRNEQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_XEN && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE)) { + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD))) { virDomainInputDefFree(input); continue; Later on in this function there is
/* If graphics are enabled, there's an implicit PS2 mouse */ if (def->ngraphics > 0) { virDomainInputDefPtr input;
if (VIR_ALLOC(input) < 0) { goto error; } if (STREQ(def->os.type, "hvm")) { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; input->bus = VIR_DOMAIN_INPUT_BUS_PS2; } else { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; input->bus = VIR_DOMAIN_INPUT_BUS_XEN; }
if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) { virDomainInputDefFree(input); goto error; } def->inputs[def->ninputs] = input; def->ninputs++; }
which needs to take care of keyboards too now.
And some more similar logic in virDomainDefFormatInternal which needs updating
I have add the keyboard device in this function in this version [3/6].
But Jan suggested to remove it from virDomainDefFormatInternal in v5. Because it would make the XML unreadable by older libvirtd that didn't know the keyboard input type.
Sorry about that, it seems we only care about XML to be readable by older libvirt if virDomainDefFormat* is called with the VIR_DOMAIN_XML_MIGRATABLE flag, so we can safely format it when this flag is not set. Jan

On 2014年02月14日 17:36, Ján Tomko wrote:
On 02/14/2014 10:02 AM, Li Zhang wrote:
On 2014年02月14日 00:39, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:48:21PM +0800, Li Zhang wrote:
@@ -12422,10 +12426,12 @@ virDomainDefParseXML(xmlDocPtr xml, * XXX will this be true for other virt types ? */ if ((STREQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_PS2 && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE) || + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD)) || (STRNEQ(def->os.type, "hvm") && input->bus == VIR_DOMAIN_INPUT_BUS_XEN && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE)) { + (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + input->type == VIR_DOMAIN_INPUT_TYPE_KBD))) { virDomainInputDefFree(input); continue; Later on in this function there is
/* If graphics are enabled, there's an implicit PS2 mouse */ if (def->ngraphics > 0) { virDomainInputDefPtr input;
if (VIR_ALLOC(input) < 0) { goto error; } if (STREQ(def->os.type, "hvm")) { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; input->bus = VIR_DOMAIN_INPUT_BUS_PS2; } else { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; input->bus = VIR_DOMAIN_INPUT_BUS_XEN; }
if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) { virDomainInputDefFree(input); goto error; } def->inputs[def->ninputs] = input; def->ninputs++; }
which needs to take care of keyboards too now.
And some more similar logic in virDomainDefFormatInternal which needs updating I have add the keyboard device in this function in this version [3/6].
But Jan suggested to remove it from virDomainDefFormatInternal in v5. Because it would make the XML unreadable by older libvirtd that didn't know the keyboard input type.
Sorry about that,
it seems we only care about XML to be readable by older libvirt if virDomainDefFormat* is called with the VIR_DOMAIN_XML_MIGRATABLE flag, so we can safely format it when this flag is not set.
I see. I will add this device when this flag is not set. :)
Jan

From: Li Zhang <zhlcindy@linux.vnet.ibm.com> This patch is to add one new interface to add input devices. Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/conf/domain_conf.c | 29 +++++++++++++++++++++++++++++ src/conf/domain_conf.h | 4 ++++ src/libvirt_private.syms | 1 + 3 files changed, 34 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9d344bc..786f9d1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11043,6 +11043,35 @@ virDomainDefMaybeAddController(virDomainDefPtr def, return 0; } +int +virDomainDefMaybeAddInput(virDomainDefPtr def, + int type, + int bus) +{ + size_t i; + virDomainInputDefPtr input; + + for (i = 0; i < def->ninputs; i++) { + if (def->inputs[i]->type == type && + def->inputs[i]->bus == bus) + return 0; + } + + if (VIR_ALLOC(input) < 0) + return -1; + + input->type = type; + input->bus = bus; + + if (VIR_APPEND_ELEMENT(def->inputs, def->ninputs, input) < 0) { + VIR_FREE(input); + return -1; + } + + return 0; +} + + /* Parse a memory element located at XPATH within CTXT, and store the * result into MEM. If REQUIRED, then the value must exist; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 98706d5..2740152 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2805,6 +2805,10 @@ virDomainDefMaybeAddController(virDomainDefPtr def, int type, int idx, int model); +int +virDomainDefMaybeAddInput(virDomainDefPtr def, + int type, + int bus); char *virDomainDefGetDefaultEmulator(virDomainDefPtr def, virCapsPtr caps); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2c9536a..1256444 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -165,6 +165,7 @@ virDomainDefGenSecurityLabelDef; virDomainDefGetDefaultEmulator; virDomainDefGetSecurityLabelDef; virDomainDefMaybeAddController; +virDomainDefMaybeAddInput; virDomainDefNew; virDomainDefParseFile; virDomainDefParseNode; -- 1.8.2.1

On 02/13/2014 09:48 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
This patch is to add one new interface to add input devices.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/conf/domain_conf.c | 29 +++++++++++++++++++++++++++++ src/conf/domain_conf.h | 4 ++++ src/libvirt_private.syms | 1 + 3 files changed, 34 insertions(+)
ACK.
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9d344bc..786f9d1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11043,6 +11043,35 @@ virDomainDefMaybeAddController(virDomainDefPtr def, return 0; }
+int +virDomainDefMaybeAddInput(virDomainDefPtr def, + int type, + int bus) +{ + size_t i; + virDomainInputDefPtr input; + + for (i = 0; i < def->ninputs; i++) { + if (def->inputs[i]->type == type && + def->inputs[i]->bus == bus) + return 0; + } + + if (VIR_ALLOC(input) < 0) + return -1; + + input->type = type; + input->bus = bus; + + if (VIR_APPEND_ELEMENT(def->inputs, def->ninputs, input) < 0) { + VIR_FREE(input); + return -1; + } + + return 0; +} + +
Nitpick: I'd move this extra line above the function, to have them separated evenly by 2 lines.
/* Parse a memory element located at XPATH within CTXT, and store the * result into MEM. If REQUIRED, then the value must exist;
Jan

On 2014年02月13日 20:37, Ján Tomko wrote:
On 02/13/2014 09:48 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
This patch is to add one new interface to add input devices.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/conf/domain_conf.c | 29 +++++++++++++++++++++++++++++ src/conf/domain_conf.h | 4 ++++ src/libvirt_private.syms | 1 + 3 files changed, 34 insertions(+) ACK.
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9d344bc..786f9d1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11043,6 +11043,35 @@ virDomainDefMaybeAddController(virDomainDefPtr def, return 0; }
+int +virDomainDefMaybeAddInput(virDomainDefPtr def, + int type, + int bus) +{ + size_t i; + virDomainInputDefPtr input; + + for (i = 0; i < def->ninputs; i++) { + if (def->inputs[i]->type == type && + def->inputs[i]->bus == bus) + return 0; + } + + if (VIR_ALLOC(input) < 0) + return -1; + + input->type = type; + input->bus = bus; + + if (VIR_APPEND_ELEMENT(def->inputs, def->ninputs, input) < 0) { + VIR_FREE(input); + return -1; + } + + return 0; +} + + Nitpick: I'd move this extra line above the function, to have them separated evenly by 2 lines.
Ah, I will remove it in next version :)
/* Parse a memory element located at XPATH within CTXT, and store the * result into MEM. If REQUIRED, then the value must exist;
Jan

From: Li Zhang <zhlcindy@linux.vnet.ibm.com> PS2 device only works for X86 platform, other platforms may need USB mouse. Athough it doesn't influence the QEMU command line, but it's not right to add one PS2 mouse for non-X86 platform. What's more, PS2 keyboard can be supported for X86. So, this patch is to remove PS2 mouse for non-x86 platforms and also add an implicit PS2 keyboard device for X86. Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/conf/domain_conf.c | 70 +++++++++++----------- src/util/virarch.h | 2 + .../qemuxml2argvdata/qemuxml2argv-pseries-disk.xml | 1 - 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 786f9d1..fed79a5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7763,7 +7763,7 @@ error: /* Parse the XML definition for an input device */ static virDomainInputDefPtr -virDomainInputDefParseXML(const char *ostype, +virDomainInputDefParseXML(const virDomainDef *dom, xmlNodePtr node, unsigned int flags) { @@ -7796,7 +7796,7 @@ virDomainInputDefParseXML(const char *ostype, goto error; } - if (STREQ(ostype, "hvm")) { + if (STREQ(dom->os.type, "hvm")) { if (def->bus == VIR_DOMAIN_INPUT_BUS_PS2 && /* PS2 can be mouse or keyboard */ !(def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || def->type == VIR_DOMAIN_INPUT_TYPE_KBD)) { @@ -7826,9 +7826,10 @@ virDomainInputDefParseXML(const char *ostype, } } } else { - if (STREQ(ostype, "hvm")) { - if (def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || - def->type == VIR_DOMAIN_INPUT_TYPE_KBD) + if (STREQ(dom->os.type, "hvm")) { + if ((def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || + def->type == VIR_DOMAIN_INPUT_TYPE_KBD) && + ARCH_IS_X86(dom->os.arch)) def->bus = VIR_DOMAIN_INPUT_BUS_PS2; else def->bus = VIR_DOMAIN_INPUT_BUS_USB; @@ -9850,7 +9851,7 @@ virDomainDeviceDefParse(const char *xmlStr, goto error; break; case VIR_DOMAIN_DEVICE_INPUT: - if (!(dev->data.input = virDomainInputDefParseXML(def->os.type, + if (!(dev->data.input = virDomainInputDefParseXML(def, node, flags))) goto error; break; @@ -12435,7 +12436,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; for (i = 0; i < n; i++) { - virDomainInputDefPtr input = virDomainInputDefParseXML(def->os.type, + virDomainInputDefPtr input = virDomainInputDefParseXML(def, nodes[i], flags); if (!input) @@ -12486,30 +12487,28 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); - /* If graphics are enabled, there's an implicit PS2 mouse */ - if (def->ngraphics > 0) { - virDomainInputDefPtr input; + /* If graphics are enabled, there's an implicit PS2 mouse and PS2 keyboard */ + if (def->ngraphics > 0 && + ARCH_IS_X86(def->os.arch)) { + int input_bus = VIR_DOMAIN_INPUT_BUS_XEN; - if (VIR_ALLOC(input) < 0) { - goto error; - } - if (STREQ(def->os.type, "hvm")) { - input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; - input->bus = VIR_DOMAIN_INPUT_BUS_PS2; - } else { - input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; - input->bus = VIR_DOMAIN_INPUT_BUS_XEN; - } + if (STREQ(def->os.type, "hvm")) + input_bus = VIR_DOMAIN_INPUT_BUS_PS2; - if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) { - virDomainInputDefFree(input); + if (virDomainDefMaybeAddInput(def, + VIR_DOMAIN_INPUT_TYPE_MOUSE, + input_bus) < 0) goto error; + + /*Ignore keyboard for XEN, only add a PS2 keyboard device for hvm*/ + if (STREQ(def->os.type, "hvm")) { + if (virDomainDefMaybeAddInput(def, + VIR_DOMAIN_INPUT_TYPE_KBD, + input_bus) < 0) + goto error; } - def->inputs[def->ninputs] = input; - def->ninputs++; } - /* analysis of the sound devices */ if ((n = virXPathNodeSet("./devices/sound", ctxt, &nodes)) < 0) { goto error; @@ -17525,16 +17524,17 @@ virDomainDefFormatInternal(virDomainDefPtr def, } if (def->ngraphics > 0) { - /* If graphics is enabled, add the implicit mouse */ - virDomainInputDef autoInput = { - VIR_DOMAIN_INPUT_TYPE_MOUSE, - STREQ(def->os.type, "hvm") ? - VIR_DOMAIN_INPUT_BUS_PS2 : VIR_DOMAIN_INPUT_BUS_XEN, - { .alias = NULL }, - }; - - if (virDomainInputDefFormat(buf, &autoInput, flags) < 0) - goto error; + /* If graphics is enabled, add the implicit mouse/keyboard */ + if (ARCH_IS_X86(def->os.arch)) { + virDomainInputDef autoInput = { + VIR_DOMAIN_INPUT_TYPE_MOUSE, + STREQ(def->os.type, "hvm") ? + VIR_DOMAIN_INPUT_BUS_PS2 : VIR_DOMAIN_INPUT_BUS_XEN, + { .alias = NULL }, + }; + if (virDomainInputDefFormat(buf, &autoInput, flags) < 0) + goto error; + } for (n = 0; n < def->ngraphics; n++) if (virDomainGraphicsDefFormat(buf, def->graphics[n], flags) < 0) diff --git a/src/util/virarch.h b/src/util/virarch.h index b180400..9b66e43 100644 --- a/src/util/virarch.h +++ b/src/util/virarch.h @@ -70,6 +70,8 @@ typedef enum { VIR_ARCH_LAST, } virArch; +#define ARCH_IS_X86(arch) ((arch) == VIR_ARCH_X86_64 ||\ + (arch) == VIR_ARCH_I686) typedef enum { VIR_ARCH_LITTLE_ENDIAN, diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml b/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml index dbbd6aa..8dde776 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml @@ -30,7 +30,6 @@ <controller type='usb' index='0'/> <controller type='scsi' index='0'/> <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> <graphics type='sdl'/> <video> <model type='cirrus' vram='9216' heads='1'/> -- 1.8.2.1

On 02/13/2014 09:48 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
PS2 device only works for X86 platform, other platforms may need USB mouse. Athough it doesn't influence the QEMU command line, but it's not right to add one PS2 mouse for non-X86 platform.
What's more, PS2 keyboard can be supported for X86.
So, this patch is to remove PS2 mouse for non-x86 platforms and also add an implicit PS2 keyboard device for X86.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/conf/domain_conf.c | 70 +++++++++++----------- src/util/virarch.h | 2 + .../qemuxml2argvdata/qemuxml2argv-pseries-disk.xml | 1 - 3 files changed, 37 insertions(+), 36 deletions(-)
@@ -17525,16 +17524,17 @@ virDomainDefFormatInternal(virDomainDefPtr def, }
if (def->ngraphics > 0) { - /* If graphics is enabled, add the implicit mouse */ - virDomainInputDef autoInput = { - VIR_DOMAIN_INPUT_TYPE_MOUSE, - STREQ(def->os.type, "hvm") ? - VIR_DOMAIN_INPUT_BUS_PS2 : VIR_DOMAIN_INPUT_BUS_XEN, - { .alias = NULL }, - }; - - if (virDomainInputDefFormat(buf, &autoInput, flags) < 0) - goto error; + /* If graphics is enabled, add the implicit mouse/keyboard */
Just mouse.
+ if (ARCH_IS_X86(def->os.arch)) {
This fails 'make check' in 'sexpr2xmltest'. It seems arch is set to 'NONE' when we convert xen s-expression to our XML. I think we should add these for VIR_ARCH_NONE as well.
+ virDomainInputDef autoInput = { + VIR_DOMAIN_INPUT_TYPE_MOUSE, + STREQ(def->os.type, "hvm") ? + VIR_DOMAIN_INPUT_BUS_PS2 : VIR_DOMAIN_INPUT_BUS_XEN, + { .alias = NULL }, + }; + if (virDomainInputDefFormat(buf, &autoInput, flags) < 0) + goto error; + }
for (n = 0; n < def->ngraphics; n++) if (virDomainGraphicsDefFormat(buf, def->graphics[n], flags) < 0) diff --git a/src/util/virarch.h b/src/util/virarch.h index b180400..9b66e43 100644 --- a/src/util/virarch.h +++ b/src/util/virarch.h @@ -70,6 +70,8 @@ typedef enum { VIR_ARCH_LAST, } virArch;
+#define ARCH_IS_X86(arch) ((arch) == VIR_ARCH_X86_64 ||\ + (arch) == VIR_ARCH_I686)
This fails 'make syntax-check': cppi: src/util/virarch.h: line 73: not properly indented There should be a space between # and define, see: http://libvirt.org/hacking.html#preprocessor Other than that, this patch looks okay to me. Jan

On 2014年02月13日 20:37, Ján Tomko wrote:
On 02/13/2014 09:48 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
PS2 device only works for X86 platform, other platforms may need USB mouse. Athough it doesn't influence the QEMU command line, but it's not right to add one PS2 mouse for non-X86 platform.
What's more, PS2 keyboard can be supported for X86.
So, this patch is to remove PS2 mouse for non-x86 platforms and also add an implicit PS2 keyboard device for X86.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/conf/domain_conf.c | 70 +++++++++++----------- src/util/virarch.h | 2 + .../qemuxml2argvdata/qemuxml2argv-pseries-disk.xml | 1 - 3 files changed, 37 insertions(+), 36 deletions(-) @@ -17525,16 +17524,17 @@ virDomainDefFormatInternal(virDomainDefPtr def, }
if (def->ngraphics > 0) { - /* If graphics is enabled, add the implicit mouse */ - virDomainInputDef autoInput = { - VIR_DOMAIN_INPUT_TYPE_MOUSE, - STREQ(def->os.type, "hvm") ? - VIR_DOMAIN_INPUT_BUS_PS2 : VIR_DOMAIN_INPUT_BUS_XEN, - { .alias = NULL }, - }; - - if (virDomainInputDefFormat(buf, &autoInput, flags) < 0) - goto error; + /* If graphics is enabled, add the implicit mouse/keyboard */ Just mouse.
Oh, right, I forgot change it.
+ if (ARCH_IS_X86(def->os.arch)) { This fails 'make check' in 'sexpr2xmltest'. It seems arch is set to 'NONE' when we convert xen s-expression to our XML.
I think we should add these for VIR_ARCH_NONE as well.
Ok, I will do it in next version.
+ virDomainInputDef autoInput = { + VIR_DOMAIN_INPUT_TYPE_MOUSE, + STREQ(def->os.type, "hvm") ? + VIR_DOMAIN_INPUT_BUS_PS2 : VIR_DOMAIN_INPUT_BUS_XEN, + { .alias = NULL }, + }; + if (virDomainInputDefFormat(buf, &autoInput, flags) < 0) + goto error; + }
for (n = 0; n < def->ngraphics; n++) if (virDomainGraphicsDefFormat(buf, def->graphics[n], flags) < 0) diff --git a/src/util/virarch.h b/src/util/virarch.h index b180400..9b66e43 100644 --- a/src/util/virarch.h +++ b/src/util/virarch.h @@ -70,6 +70,8 @@ typedef enum { VIR_ARCH_LAST, } virArch;
+#define ARCH_IS_X86(arch) ((arch) == VIR_ARCH_X86_64 ||\ + (arch) == VIR_ARCH_I686) This fails 'make syntax-check': cppi: src/util/virarch.h: line 73: not properly indented
I will correct it in next version soon.
There should be a space between # and define, see: http://libvirt.org/hacking.html#preprocessor
Other than that, this patch looks okay to me.
Thanks. :)
Jan

From: Li Zhang <zhlcindy@linux.vnet.ibm.com> QEMU can support USB keyboard but libvirt haven't supportted it yet. This patch is to add USB keyboard capabilities and test cases. Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_1.2.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.3.1-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.4.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.5.3-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 + tests/qemuhelptest.c | 8 ++++++++ 9 files changed, 18 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index e7d953a..0433607 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -249,6 +249,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "enable-fips", "spice-file-xfer-disable", "spiceport", + + "usb-kbd", /*165*/ ); struct _virQEMUCaps { @@ -1403,6 +1405,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "virtio-mmio", QEMU_CAPS_DEVICE_VIRTIO_MMIO }, { "ich9-intel-hda", QEMU_CAPS_DEVICE_ICH9_INTEL_HDA }, { "pvpanic", QEMU_CAPS_DEVICE_PANIC }, + { "usb-kbd", QEMU_CAPS_DEVICE_USB_KBD }, }; static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index a4eecb6..dbc4c9a 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -203,6 +203,7 @@ enum virQEMUCapsFlags { QEMU_CAPS_ENABLE_FIPS = 162, /* -enable-fips */ QEMU_CAPS_SPICE_FILE_XFER_DISABLE = 163, /* -spice disable-agent-file-xfer */ QEMU_CAPS_CHARDEV_SPICEPORT = 164, /* -chardev spiceport */ + QEMU_CAPS_DEVICE_USB_KBD = 165, /*-device usb-kbd*/ QEMU_CAPS_LAST, /* this must always be the last item */ }; diff --git a/tests/qemucapabilitiesdata/caps_1.2.2-1.caps b/tests/qemucapabilitiesdata/caps_1.2.2-1.caps index c3ae814..436cecd 100644 --- a/tests/qemucapabilitiesdata/caps_1.2.2-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.2.2-1.caps @@ -113,4 +113,5 @@ <flag name='usb-storage.removable'/> <flag name='kvm-pit-lost-tick-policy'/> <flag name='enable-fips'/> + <flag name='usb-kbd'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.3.1-1.caps b/tests/qemucapabilitiesdata/caps_1.3.1-1.caps index da15d8b..6b4a8f0 100644 --- a/tests/qemucapabilitiesdata/caps_1.3.1-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.3.1-1.caps @@ -126,4 +126,5 @@ <flag name='usb-storage'/> <flag name='usb-storage.removable'/> <flag name='kvm-pit-lost-tick-policy'/> + <flag name='usb-kbd'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.4.2-1.caps b/tests/qemucapabilitiesdata/caps_1.4.2-1.caps index c419068..e3d0047 100644 --- a/tests/qemucapabilitiesdata/caps_1.4.2-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.4.2-1.caps @@ -127,4 +127,5 @@ <flag name='usb-storage.removable'/> <flag name='ich9-intel-hda'/> <flag name='kvm-pit-lost-tick-policy'/> + <flag name='usb-kbd'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.5.3-1.caps b/tests/qemucapabilitiesdata/caps_1.5.3-1.caps index adf8531..01b4d27 100644 --- a/tests/qemucapabilitiesdata/caps_1.5.3-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.5.3-1.caps @@ -135,4 +135,5 @@ <flag name='pvpanic'/> <flag name='reboot-timeout'/> <flag name='spiceport'/> + <flag name='usb-kbd'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps index e6b2f76..597f873 100644 --- a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps @@ -141,4 +141,5 @@ <flag name='enable-fips'/> <flag name='spice-file-xfer-disable'/> <flag name='spiceport'/> + <flag name='usb-kbd'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps index e6b8117..0c1dd87 100644 --- a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps @@ -139,4 +139,5 @@ <flag name='reboot-timeout'/> <flag name='spice-file-xfer-disable'/> <flag name='spiceport'/> + <flag name='usb-kbd'/> </qemuCaps> diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c index 3628fbe..6e0a5f8 100644 --- a/tests/qemuhelptest.c +++ b/tests/qemuhelptest.c @@ -403,6 +403,7 @@ mymain(void) QEMU_CAPS_DEVICE_VMWARE_SVGA, QEMU_CAPS_DEVICE_USB_SERIAL, QEMU_CAPS_DEVICE_USB_NET, + QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_PCI_BRIDGE); DO_TEST("qemu-kvm-0.12.3", 12003, 1, 0, QEMU_CAPS_VNC_COLON, @@ -515,6 +516,7 @@ mymain(void) QEMU_CAPS_DEVICE_USB_NET, QEMU_CAPS_DEVICE_PCI_BRIDGE, QEMU_CAPS_DEVICE_SCSI_GENERIC, + QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_USB_STORAGE); DO_TEST("qemu-kvm-0.12.1.2-rhel61", 12001, 1, 0, QEMU_CAPS_VNC_COLON, @@ -581,6 +583,7 @@ mymain(void) QEMU_CAPS_DEVICE_VMWARE_SVGA, QEMU_CAPS_DEVICE_USB_SERIAL, QEMU_CAPS_DEVICE_USB_NET, + QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_PCI_BRIDGE); DO_TEST("qemu-kvm-0.12.1.2-rhel62-beta", 12001, 1, 0, QEMU_CAPS_VNC_COLON, @@ -655,6 +658,7 @@ mymain(void) QEMU_CAPS_DEVICE_VGA, QEMU_CAPS_DEVICE_CIRRUS_VGA, QEMU_CAPS_DEVICE_PCI_BRIDGE, + QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_USB_STORAGE); DO_TEST("qemu-1.0", 1000000, 0, 0, QEMU_CAPS_VNC_COLON, @@ -739,6 +743,7 @@ mymain(void) QEMU_CAPS_DEVICE_USB_NET, QEMU_CAPS_DEVICE_SCSI_GENERIC, QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX, + QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_USB_STORAGE); DO_TEST("qemu-1.1.0", 1001000, 0, 0, QEMU_CAPS_VNC_COLON, @@ -835,6 +840,7 @@ mymain(void) QEMU_CAPS_DEVICE_SCSI_GENERIC, QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX, QEMU_CAPS_VNC_SHARE_POLICY, + QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_USB_STORAGE); DO_TEST("qemu-1.2.0", 1002000, 0, 0, QEMU_CAPS_VNC_COLON, @@ -943,6 +949,7 @@ mymain(void) QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX, QEMU_CAPS_VNC_SHARE_POLICY, QEMU_CAPS_DEVICE_USB_STORAGE, + QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_USB_STORAGE_REMOVABLE); DO_TEST("qemu-kvm-1.2.0", 1002000, 1, 0, QEMU_CAPS_VNC_COLON, @@ -1056,6 +1063,7 @@ mymain(void) QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX, QEMU_CAPS_VNC_SHARE_POLICY, QEMU_CAPS_DEVICE_USB_STORAGE, + QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_USB_STORAGE_REMOVABLE); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; -- 1.8.2.1

On 02/13/2014 09:48 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
QEMU can support USB keyboard but libvirt haven't supportted it yet. This patch is to add USB keyboard capabilities and test cases.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_1.2.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.3.1-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.4.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.5.3-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 + tests/qemuhelptest.c | 8 ++++++++ 9 files changed, 18 insertions(+)
ACK
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index e7d953a..0433607 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -249,6 +249,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "enable-fips", "spice-file-xfer-disable", "spiceport", + + "usb-kbd", /*165*/
There should be spaces around the comment: /* 165 */
);
struct _virQEMUCaps { @@ -1403,6 +1405,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "virtio-mmio", QEMU_CAPS_DEVICE_VIRTIO_MMIO }, { "ich9-intel-hda", QEMU_CAPS_DEVICE_ICH9_INTEL_HDA }, { "pvpanic", QEMU_CAPS_DEVICE_PANIC }, + { "usb-kbd", QEMU_CAPS_DEVICE_USB_KBD }, };
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index a4eecb6..dbc4c9a 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -203,6 +203,7 @@ enum virQEMUCapsFlags { QEMU_CAPS_ENABLE_FIPS = 162, /* -enable-fips */ QEMU_CAPS_SPICE_FILE_XFER_DISABLE = 163, /* -spice disable-agent-file-xfer */ QEMU_CAPS_CHARDEV_SPICEPORT = 164, /* -chardev spiceport */ + QEMU_CAPS_DEVICE_USB_KBD = 165, /*-device usb-kbd*/
Same here.
QEMU_CAPS_LAST, /* this must always be the last item */ };
Jan

On 2014年02月13日 20:37, Ján Tomko wrote:
On 02/13/2014 09:48 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
QEMU can support USB keyboard but libvirt haven't supportted it yet. This patch is to add USB keyboard capabilities and test cases.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_1.2.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.3.1-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.4.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.5.3-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 + tests/qemuhelptest.c | 8 ++++++++ 9 files changed, 18 insertions(+)
ACK
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index e7d953a..0433607 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -249,6 +249,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "enable-fips", "spice-file-xfer-disable", "spiceport", + + "usb-kbd", /*165*/ There should be spaces around the comment: /* 165 */
got it.
);
struct _virQEMUCaps { @@ -1403,6 +1405,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "virtio-mmio", QEMU_CAPS_DEVICE_VIRTIO_MMIO }, { "ich9-intel-hda", QEMU_CAPS_DEVICE_ICH9_INTEL_HDA }, { "pvpanic", QEMU_CAPS_DEVICE_PANIC }, + { "usb-kbd", QEMU_CAPS_DEVICE_USB_KBD }, };
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index a4eecb6..dbc4c9a 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -203,6 +203,7 @@ enum virQEMUCapsFlags { QEMU_CAPS_ENABLE_FIPS = 162, /* -enable-fips */ QEMU_CAPS_SPICE_FILE_XFER_DISABLE = 163, /* -spice disable-agent-file-xfer */ QEMU_CAPS_CHARDEV_SPICEPORT = 164, /* -chardev spiceport */ + QEMU_CAPS_DEVICE_USB_KBD = 165, /*-device usb-kbd*/
Same here.
QEMU_CAPS_LAST, /* this must always be the last item */ };
Jan

From: Li Zhang <zhlcindy@linux.vnet.ibm.com> This patch is to format qemu command line and xen driver for USB keyboard and add test cases for it. Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_command.c | 41 ++++++++++++++++------ src/xenxs/xen_sxpr.c | 27 +++++++++----- src/xenxs/xen_xm.c | 30 +++++++++++----- .../qemuxml2argv-pseries-usb-kbd.args | 9 +++++ .../qemuxml2argv-pseries-usb-kbd.xml | 19 ++++++++++ tests/qemuxml2argvtest.c | 3 ++ 6 files changed, 103 insertions(+), 26 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 e499d54..d7d39b3 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5306,9 +5306,19 @@ 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)) + goto error; + virBufferAsprintf(&buf, "usb-kbd,id=%s", dev->info.alias); + break; + } if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) goto error; @@ -9044,9 +9054,17 @@ qemuBuildCommandLine(virConnectPtr conn, virCommandAddArg(cmd, optstr); VIR_FREE(optstr); } else { - virCommandAddArgList(cmd, "-usbdevice", - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE - ? "mouse" : "tablet", NULL); + switch (input->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + virCommandAddArgList(cmd, "-usbdevice", "mouse", NULL); + break; + case VIR_DOMAIN_INPUT_TYPE_TABLET: + virCommandAddArgList(cmd, "-usbdevice", "tablet", NULL); + break; + case VIR_DOMAIN_INPUT_TYPE_KBD: + virCommandAddArgList(cmd, "-usbdevice", "keyboard", NULL); + break; + } } } } @@ -11720,20 +11738,23 @@ qemuParseCommandLine(virCapsPtr qemuCaps, } else if (STREQ(arg, "-usbdevice")) { WANT_VALUE(); if (STREQ(val, "tablet") || - STREQ(val, "mouse")) { + STREQ(val, "mouse") || + STREQ(val, "keyboard")) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) goto error; input->bus = VIR_DOMAIN_INPUT_BUS_USB; if (STREQ(val, "tablet")) input->type = VIR_DOMAIN_INPUT_TYPE_TABLET; - else + else if (STREQ(val, "mouse")) input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; - if (VIR_REALLOC_N(def->inputs, def->ninputs+1) < 0) { + else + input->type = VIR_DOMAIN_INPUT_TYPE_KBD; + + if (VIR_APPEND_ELEMENT(def->inputs, def->ninputs, input) < 0) { virDomainInputDefFree(input); goto error; } - def->inputs[def->ninputs++] = input; } else if (STRPREFIX(val, "disk:")) { if (VIR_ALLOC(disk) < 0) goto error; diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index d514725..79cc20e 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -724,21 +724,23 @@ xenParseSxprUSB(virDomainDefPtr def, tmp = sexpr_node(node, "usbdevice"); if (tmp && *tmp) { if (STREQ(tmp, "tablet") || - STREQ(tmp, "mouse")) { + STREQ(tmp, "mouse") || + STREQ(tmp, "keyboard")) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) goto error; input->bus = VIR_DOMAIN_INPUT_BUS_USB; if (STREQ(tmp, "tablet")) input->type = VIR_DOMAIN_INPUT_TYPE_TABLET; - else + else if (STREQ(tmp, "mouse")) input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; + else + input->type = VIR_DOMAIN_INPUT_TYPE_KBD; - if (VIR_REALLOC_N(def->inputs, def->ninputs+1) < 0) { + if (VIR_APPEND_ELEMENT(def->inputs, def->ninputs, input) < 0) { VIR_FREE(input); goto error; } - def->inputs[def->ninputs++] = input; } else { /* XXX Handle other non-input USB devices later */ } @@ -2144,15 +2146,24 @@ xenFormatSxprInput(virDomainInputDefPtr input, return 0; if (input->type != VIR_DOMAIN_INPUT_TYPE_MOUSE && - input->type != VIR_DOMAIN_INPUT_TYPE_TABLET) { + input->type != VIR_DOMAIN_INPUT_TYPE_TABLET && + input->type != VIR_DOMAIN_INPUT_TYPE_KBD) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected input type %d"), input->type); return -1; } - virBufferAsprintf(buf, "(usbdevice %s)", - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ? - "mouse" : "tablet"); + switch (input->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + virBufferAsprintf(buf, "(usbdevice %s)","mouse") + break; + case VIR_DOMAIN_INPUT_TYPE_TABLET: + virBufferAsprintf(buf, "(usbdevice %s)","tablet") + break; + case VIR_DOMAIN_INPUT_TYPE_KBD: + virBufferAsprintf(buf, "(usbdevice %s)","keyboard") + break; + } return 0; } diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 5e89876..b448e99 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -886,14 +886,18 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; if (str && (STREQ(str, "tablet") || - STREQ(str, "mouse"))) { + STREQ(str, "mouse") || + STREQ(str, "keyboard"))) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) goto cleanup; input->bus = VIR_DOMAIN_INPUT_BUS_USB; - input->type = STREQ(str, "tablet") ? - VIR_DOMAIN_INPUT_TYPE_TABLET : - VIR_DOMAIN_INPUT_TYPE_MOUSE; + if (STREQ(str, "mouse")) + input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; + else if (STREQ(str, "tablet")) + input->type = VIR_DOMAIN_INPUT_TYPE_TABLET; + else (STREQ(str, "keyboard")) + input->type = VIR_DOMAIN_INPUT_TYPE_KBD; if (VIR_ALLOC_N(def->inputs, 1) < 0) { virDomainInputDefFree(input); goto cleanup; @@ -1746,10 +1750,20 @@ virConfPtr xenFormatXM(virConnectPtr conn, if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { if (xenXMConfigSetInt(conf, "usb", 1) < 0) goto cleanup; - if (xenXMConfigSetString(conf, "usbdevice", - def->inputs[i]->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ? - "mouse" : "tablet") < 0) - goto cleanup; + switch (def->inputs[i]->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0) + goto cleanup; + break; + case VIR_DOMAIN_INPUT_TYPE_TABLET: + if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0) + goto cleanup; + break; + case VIR_DOMAIN_INPUT_TYPE_KBD: + if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0) + goto cleanup; + break; + } break; } } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args new file mode 100644 index 0000000..373c72a --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args @@ -0,0 +1,9 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-ppc64 -S -M pseries -m 512 -smp 1 \ +-nographic -nodefconfig -nodefaults \ +-chardev socket,id=charmonitor,path=/tmp/test-monitor,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=readline -no-acpi -boot c \ +-device pci-ohci,id=usb,bus=pci,addr=0x1 \ +-chardev pty,id=charserial0 \ +-device spapr-vty,chardev=charserial0,reg=0x30000000 \ +-device usb-kbd,id=input0 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.xml b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.xml new file mode 100644 index 0000000..5bd4c37 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.xml @@ -0,0 +1,19 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid> + <memory unit='KiB'>524288</memory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='ppc64' machine='pseries'>hvm</type> + </os> + <clock offset='utc'/> + <devices> + <emulator>/usr/bin/qemu-system-ppc64</emulator> + <console type='pty'> + <address type="spapr-vio"/> + </console> + <memballoon model="none"/> + <controller type='usb' index='0' model='pci-ohci'/> + <input type='keyboard' bus='usb'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 7a5b50d..23b5652 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1206,6 +1206,9 @@ mymain(void) DO_TEST_ERROR("pseries-vio-address-clash", QEMU_CAPS_DRIVE, QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); DO_TEST("pseries-nvram", QEMU_CAPS_DEVICE_NVRAM); + DO_TEST("pseries-usb-kbd", QEMU_CAPS_PCI_OHCI, + QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_CHARDEV, + QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); DO_TEST_FAILURE("pseries-cpu-exact", QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); DO_TEST("disk-ide-drive-split", QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, -- 1.8.2.1

On 02/13/2014 09:48 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
This patch is to format qemu command line and xen driver for USB keyboard and add test cases for it.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_command.c | 41 ++++++++++++++++------ src/xenxs/xen_sxpr.c | 27 +++++++++----- src/xenxs/xen_xm.c | 30 +++++++++++----- .../qemuxml2argv-pseries-usb-kbd.args | 9 +++++ .../qemuxml2argv-pseries-usb-kbd.xml | 19 ++++++++++ tests/qemuxml2argvtest.c | 3 ++ 6 files changed, 103 insertions(+), 26 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.xml
I'd split the patch in two - one for qemu, one for xen.
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index d514725..79cc20e 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -724,21 +724,23 @@ xenParseSxprUSB(virDomainDefPtr def, tmp = sexpr_node(node, "usbdevice"); if (tmp && *tmp) { if (STREQ(tmp, "tablet") || - STREQ(tmp, "mouse")) { + STREQ(tmp, "mouse") || + STREQ(tmp, "keyboard")) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) goto error; input->bus = VIR_DOMAIN_INPUT_BUS_USB; if (STREQ(tmp, "tablet")) input->type = VIR_DOMAIN_INPUT_TYPE_TABLET; - else + else if (STREQ(tmp, "mouse")) input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; + else + input->type = VIR_DOMAIN_INPUT_TYPE_KBD;
- if (VIR_REALLOC_N(def->inputs, def->ninputs+1) < 0) { + if (VIR_APPEND_ELEMENT(def->inputs, def->ninputs, input) < 0) { VIR_FREE(input); goto error; } - def->inputs[def->ninputs++] = input; } else { /* XXX Handle other non-input USB devices later */ } @@ -2144,15 +2146,24 @@ xenFormatSxprInput(virDomainInputDefPtr input, return 0;
if (input->type != VIR_DOMAIN_INPUT_TYPE_MOUSE && - input->type != VIR_DOMAIN_INPUT_TYPE_TABLET) { + input->type != VIR_DOMAIN_INPUT_TYPE_TABLET && + input->type != VIR_DOMAIN_INPUT_TYPE_KBD) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected input type %d"), input->type); return -1; }
- virBufferAsprintf(buf, "(usbdevice %s)", - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ? - "mouse" : "tablet"); + switch (input->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + virBufferAsprintf(buf, "(usbdevice %s)","mouse") + break; + case VIR_DOMAIN_INPUT_TYPE_TABLET: + virBufferAsprintf(buf, "(usbdevice %s)","tablet") + break; + case VIR_DOMAIN_INPUT_TYPE_KBD: + virBufferAsprintf(buf, "(usbdevice %s)","keyboard") + break; + }
In all three cases there is a space missing between arguments and a semicolon missing at the end.
return 0; } diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 5e89876..b448e99 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -886,14 +886,18 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; if (str && (STREQ(str, "tablet") || - STREQ(str, "mouse"))) { + STREQ(str, "mouse") || + STREQ(str, "keyboard"))) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) goto cleanup; input->bus = VIR_DOMAIN_INPUT_BUS_USB; - input->type = STREQ(str, "tablet") ? - VIR_DOMAIN_INPUT_TYPE_TABLET : - VIR_DOMAIN_INPUT_TYPE_MOUSE; + if (STREQ(str, "mouse")) + input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; + else if (STREQ(str, "tablet")) + input->type = VIR_DOMAIN_INPUT_TYPE_TABLET; + else (STREQ(str, "keyboard"))
s/else/else if/
+ input->type = VIR_DOMAIN_INPUT_TYPE_KBD; if (VIR_ALLOC_N(def->inputs, 1) < 0) { virDomainInputDefFree(input); goto cleanup;
ACK to the QEMU part. The xen part looks fine to me. Jan

On 2014年02月13日 20:37, Ján Tomko wrote:
On 02/13/2014 09:48 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
This patch is to format qemu command line and xen driver for USB keyboard and add test cases for it.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_command.c | 41 ++++++++++++++++------ src/xenxs/xen_sxpr.c | 27 +++++++++----- src/xenxs/xen_xm.c | 30 +++++++++++----- .../qemuxml2argv-pseries-usb-kbd.args | 9 +++++ .../qemuxml2argv-pseries-usb-kbd.xml | 19 ++++++++++ tests/qemuxml2argvtest.c | 3 ++ 6 files changed, 103 insertions(+), 26 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.xml I'd split the patch in two - one for qemu, one for xen.
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index d514725..79cc20e 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -724,21 +724,23 @@ xenParseSxprUSB(virDomainDefPtr def, tmp = sexpr_node(node, "usbdevice"); if (tmp && *tmp) { if (STREQ(tmp, "tablet") || - STREQ(tmp, "mouse")) { + STREQ(tmp, "mouse") || + STREQ(tmp, "keyboard")) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) goto error; input->bus = VIR_DOMAIN_INPUT_BUS_USB; if (STREQ(tmp, "tablet")) input->type = VIR_DOMAIN_INPUT_TYPE_TABLET; - else + else if (STREQ(tmp, "mouse")) input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; + else + input->type = VIR_DOMAIN_INPUT_TYPE_KBD;
- if (VIR_REALLOC_N(def->inputs, def->ninputs+1) < 0) { + if (VIR_APPEND_ELEMENT(def->inputs, def->ninputs, input) < 0) { VIR_FREE(input); goto error; } - def->inputs[def->ninputs++] = input; } else { /* XXX Handle other non-input USB devices later */ } @@ -2144,15 +2146,24 @@ xenFormatSxprInput(virDomainInputDefPtr input, return 0;
if (input->type != VIR_DOMAIN_INPUT_TYPE_MOUSE && - input->type != VIR_DOMAIN_INPUT_TYPE_TABLET) { + input->type != VIR_DOMAIN_INPUT_TYPE_TABLET && + input->type != VIR_DOMAIN_INPUT_TYPE_KBD) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected input type %d"), input->type); return -1; }
- virBufferAsprintf(buf, "(usbdevice %s)", - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ? - "mouse" : "tablet"); + switch (input->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + virBufferAsprintf(buf, "(usbdevice %s)","mouse") + break; + case VIR_DOMAIN_INPUT_TYPE_TABLET: + virBufferAsprintf(buf, "(usbdevice %s)","tablet") + break; + case VIR_DOMAIN_INPUT_TYPE_KBD: + virBufferAsprintf(buf, "(usbdevice %s)","keyboard") + break; + } In all three cases there is a space missing between arguments and a semicolon missing at the end.
ah, sorry for that. :(
return 0; } diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 5e89876..b448e99 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -886,14 +886,18 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; if (str && (STREQ(str, "tablet") || - STREQ(str, "mouse"))) { + STREQ(str, "mouse") || + STREQ(str, "keyboard"))) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) goto cleanup; input->bus = VIR_DOMAIN_INPUT_BUS_USB; - input->type = STREQ(str, "tablet") ? - VIR_DOMAIN_INPUT_TYPE_TABLET : - VIR_DOMAIN_INPUT_TYPE_MOUSE; + if (STREQ(str, "mouse")) + input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; + else if (STREQ(str, "tablet")) + input->type = VIR_DOMAIN_INPUT_TYPE_TABLET; + else (STREQ(str, "keyboard"))
s/else/else if/
I will change it.
+ input->type = VIR_DOMAIN_INPUT_TYPE_KBD; if (VIR_ALLOC_N(def->inputs, 1) < 0) { virDomainInputDefFree(input); goto cleanup; ACK to the QEMU part. The xen part looks fine to me.
Jan

From: Li Zhang <zhlcindy@linux.vnet.ibm.com> There is no keyboard working on PPC64 and PS2 mouse is only for PPC64 when graphics are enabled. It needs to add a USB keyboard and USB mouse for it. This patch is to add a USB keyboard and USB mouse when graphics are enabled. Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_domain.c | 23 +++++++++++++++++++++- .../qemuxml2argvdata/qemuxml2argv-pseries-disk.xml | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a665061..7f4ff0e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -691,6 +691,8 @@ qemuDomainDefPostParse(virDomainDefPtr def, bool addPCIRoot = false; bool addPCIeRoot = false; bool addDefaultMemballoon = true; + bool addDefaultUSBKBD = false; + bool addDefaultUSBMouse = false; /* check for emulator and create a default one if needed */ if (!def->emulator && @@ -732,9 +734,14 @@ qemuDomainDefPostParse(virDomainDefPtr def, addDefaultMemballoon = false; break; + case VIR_ARCH_PPC64: + addPCIRoot = true; + addDefaultUSBKBD = true; + addDefaultUSBMouse = true; + break; + case VIR_ARCH_ALPHA: case VIR_ARCH_PPC: - case VIR_ARCH_PPC64: case VIR_ARCH_PPCEMB: case VIR_ARCH_SH4: case VIR_ARCH_SH4EB: @@ -787,6 +794,20 @@ qemuDomainDefPostParse(virDomainDefPtr def, def->memballoon = memballoon; } + if (addDefaultUSBKBD && + def->ngraphics > 0 && + virDomainDefMaybeAddInput(def, + VIR_DOMAIN_INPUT_TYPE_KBD, + VIR_DOMAIN_INPUT_BUS_USB) < 0) + return -1; + + if (addDefaultUSBMouse && + def->ngraphics > 0 && + virDomainDefMaybeAddInput(def, + VIR_DOMAIN_INPUT_TYPE_MOUSE, + VIR_DOMAIN_INPUT_BUS_USB) < 0) + return -1; + return 0; } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml b/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml index 8dde776..64b70f3 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml @@ -30,6 +30,8 @@ <controller type='usb' index='0'/> <controller type='scsi' index='0'/> <controller type='pci' index='0' model='pci-root'/> + <input type='keyboard' bus='usb'/> + <input type='mouse' bus='usb'/> <graphics type='sdl'/> <video> <model type='cirrus' vram='9216' heads='1'/> -- 1.8.2.1

On 02/13/2014 09:48 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
There is no keyboard working on PPC64 and PS2 mouse is only for PPC64 when graphics are enabled. It needs to add a USB keyboard and USB mouse for it.
This patch is to add a USB keyboard and USB mouse when graphics are enabled.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_domain.c | 23 +++++++++++++++++++++- .../qemuxml2argvdata/qemuxml2argv-pseries-disk.xml | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-)
ACK Jan
participants (3)
-
Daniel P. Berrange
-
Ján Tomko
-
Li Zhang