[PATCH v5 5/6] qemu: parse qemu command line for USB keyboard

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

 



From: Li Zhang <zhlcindy@xxxxxxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxxxxx>
---
 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 a80559e..00072aa 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5307,9 +5307,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;
@@ -8996,9 +9006,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", "kbd", NULL);
+                        break;
+                }
             }
         }
     }
@@ -11684,20 +11702,23 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
         } else if (STREQ(arg, "-usbdevice")) {
             WANT_VALUE();
             if (STREQ(val, "tablet") ||
-                STREQ(val, "mouse")) {
+                STREQ(val, "mouse") ||
+                STREQ(val, "kbd")) {
                 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..a02f999 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, "kbd")) {
                     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)","kbd")
+            break;
+    }
 
     return 0;
 }
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 5e89876..9e19bb7 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, "kbd"))) {
             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, "kbd"))
+                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", "kbd") < 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..c512584
--- /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='kbd' bus='usb'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 847e96f..4abb821 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1177,6 +1177,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

--
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]