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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]