[PATCH v8 6/7] xen: format xen 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 xen command line for USB keyboard

Signed-off-by: Li Zhang <zhlcindy@xxxxxxxxxxxxxxxxxx>
---
 src/xenxs/xen_sxpr.c | 27 +++++++++++++++++++--------
 src/xenxs/xen_xm.c   | 30 ++++++++++++++++++++++--------
 2 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index d514725..d366b1b 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..3a57547 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 if (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;
             }
         }
-- 
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]