[libvirt] [PATCH 1/2] qemu: USB keyboard device support

Some guests (like the "pseries" guests) do not implicitly have a virtual keyboard. This patch introduces the proper mechanisms to create an USB keyboard using the existing "input" XML tag. --- src/conf/domain_conf.c | 3 ++- src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 42 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ffdbe95..4938740 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -504,7 +504,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", diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 05c2a84..c659fd0 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1222,6 +1222,7 @@ struct _virDomainTPMDef { enum virDomainInputType { VIR_DOMAIN_INPUT_TYPE_MOUSE, VIR_DOMAIN_INPUT_TYPE_TABLET, + VIR_DOMAIN_INPUT_TYPE_KEYBOARD, VIR_DOMAIN_INPUT_TYPE_LAST }; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 1d693e1..36ca455 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5276,9 +5276,24 @@ qemuBuildUSBInputDevStr(virDomainDefPtr def, { virBuffer buf = VIR_BUFFER_INITIALIZER; + const char * model = NULL; + + switch (dev->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + model = "usb-mouse"; + break; + case VIR_DOMAIN_INPUT_TYPE_TABLET: + model = "usb-tablet"; + break; + case VIR_DOMAIN_INPUT_TYPE_KEYBOARD: + model = "usb-kbd"; + break; + } + virBufferAsprintf(&buf, "%s,id=%s", - dev->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ? - "usb-mouse" : "usb-tablet", dev->info.alias); + model, dev->info.alias); + + if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) goto error; @@ -8959,9 +8974,22 @@ qemuBuildCommandLine(virConnectPtr conn, virCommandAddArg(cmd, optstr); VIR_FREE(optstr); } else { + const char *usbdev = NULL; + + switch (input->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + usbdev = "mouse"; + break; + case VIR_DOMAIN_INPUT_TYPE_TABLET: + usbdev = "tablet"; + break; + case VIR_DOMAIN_INPUT_TYPE_KEYBOARD: + usbdev = "keyboard"; + break; + } + virCommandAddArgList(cmd, "-usbdevice", - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE - ? "mouse" : "tablet", NULL); + usbdev, NULL); } } } @@ -11614,15 +11642,19 @@ 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 if (STREQ(val, "keyboard")) + input->type = VIR_DOMAIN_INPUT_TYPE_KEYBOARD; else input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; + if (VIR_REALLOC_N(def->inputs, def->ninputs+1) < 0) { virDomainInputDefFree(input); goto error; -- 1.8.1.4

This patch fixes the appearance of a PS/2 mouse in the list of input devices of non-x86 guests. --- src/conf/domain_conf.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4938740..fb088d5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12114,14 +12114,16 @@ virDomainDefParseXML(xmlDocPtr xml, /* With QEMU / KVM / Xen graphics, mouse + PS/2 is implicit * with graphics, so don't store it. * 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) || - (STRNEQ(def->os.type, "hvm") && - input->bus == VIR_DOMAIN_INPUT_BUS_XEN && - input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE)) { - virDomainInputDefFree(input); - continue; + if (def->os.arch == VIR_ARCH_I686 || def->os.arch == VIR_ARCH_X86_64) { + if ((STREQ(def->os.type, "hvm") && + input->bus == VIR_DOMAIN_INPUT_BUS_PS2 && + input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE) || + (STRNEQ(def->os.type, "hvm") && + input->bus == VIR_DOMAIN_INPUT_BUS_XEN && + input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE)) { + virDomainInputDefFree(input); + continue; + } } def->inputs[def->ninputs++] = input; @@ -12145,8 +12147,10 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); - /* If graphics are enabled, there's an implicit PS2 mouse */ - if (def->ngraphics > 0) { + /* If graphics are enabled, there's an implicit PS2 mouse + * in the x86 architecture */ + if (def->ngraphics > 0 && (def->os.arch == VIR_ARCH_I686 || + def->os.arch == VIR_ARCH_X86_64)) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) { @@ -17056,16 +17060,20 @@ 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 in the x86 + * architecture */ + + if (def->os.arch == VIR_ARCH_I686 || def->os.arch == VIR_ARCH_X86_64) { + 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) -- 1.8.1.4
participants (1)
-
Vitor de Lima