[libvirt] [PATCH 1/4] Add USB Keyboard support in libvirt

Li Zhang zhlcindy at gmail.com
Mon Dec 2 07:27:09 UTC 2013


From: Li Zhang <zhlcindy at linux.vnet.ibm.com>

PS2 devices are not supported for non-x86 platforms. So it needs one USB
keyboard when graphic is enabled.

This patch is to add one kbd input device type for users to add one 
USB keyboard in XML file as the following:
  <input type='kbd' bus='usb'/>


Signed-off-by: Li Zhang <zhlcindy at linux.vnet.ibm.com>
---
 src/conf/domain_conf.c       |  3 ++-
 src/conf/domain_conf.h       |  1 +
 src/qemu/qemu_capabilities.c |  3 +++
 src/qemu/qemu_capabilities.h |  2 ++
 src/qemu/qemu_command.c      | 12 +++++++++---
 5 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7b0e3ea..d90f05c 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",
+              "kbd")
 
 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 4561ccc..c8fecaf 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_KBD,
 
     VIR_DOMAIN_INPUT_TYPE_LAST
 };
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 548b988..89b11ad 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -243,6 +243,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
               "virtio-mmio",
               "ich9-intel-hda",
               "kvm-pit-lost-tick-policy",
+
+              "usb-kbd", /*160*/
     );
 
 struct _virQEMUCaps {
@@ -1394,6 +1396,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = {
     { "usb-storage", QEMU_CAPS_DEVICE_USB_STORAGE },
     { "virtio-mmio", QEMU_CAPS_DEVICE_VIRTIO_MMIO },
     { "ich9-intel-hda", QEMU_CAPS_DEVICE_ICH9_INTEL_HDA },
+    { "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 02d47c6..0b7b5e5 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -198,6 +198,8 @@ enum virQEMUCapsFlags {
     QEMU_CAPS_DEVICE_VIRTIO_MMIO = 157, /* -device virtio-mmio */
     QEMU_CAPS_DEVICE_ICH9_INTEL_HDA = 158, /* -device ich9-intel-hda */
     QEMU_CAPS_KVM_PIT_TICK_POLICY = 159, /* kvm-pit.lost_tick_policy */
+    QEMU_CAPS_DEVICE_USB_KBD = 160, /*-device usb-kbd*/
+
 
     QEMU_CAPS_LAST,                   /* this must always be the last item */
 };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 763417f..318f7a1 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5280,9 +5280,15 @@ 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);
+    if (dev->type == VIR_DOMAIN_INPUT_TYPE_MOUSE) {
+        virBufferAsprintf(&buf, "usb-mouse,id=%s", dev->info.alias);
+    } else if (dev->type == VIR_DOMAIN_INPUT_TYPE_TABLET) {
+        virBufferAsprintf(&buf, "usb-tablet,id=%s", dev->info.alias);
+    } else if (dev->type == VIR_DOMAIN_INPUT_TYPE_KBD) {
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_KBD))
+            goto error;
+        virBufferAsprintf(&buf, "usb-kbd,id=%s", dev->info.alias);
+    }
 
     if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
         goto error;
-- 
1.8.2.1




More information about the libvir-list mailing list