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

[libvirt] [PATCH v7 3/7] conf: Remove the implicit PS2 mouse for non-X86 and platforms and add an implicit PS2 keyboard device for X86 platforms.



From: Li Zhang <zhlcindy linux vnet ibm com>

PS2 device only works for X86 platform, other platforms may need
USB mouse. Athough it doesn't influence the QEMU command line, but
it's not right to add one PS2 mouse for non-X86 platform.

What's more, PS2 keyboard can be supported for X86.

So, this patch is to remove PS2 mouse for non-x86 platforms and also add
an implicit PS2 keyboard device for X86.

Signed-off-by: Li Zhang <zhlcindy linux vnet ibm com>
---
 src/conf/domain_conf.c                             | 69 +++++++++++-----------
 src/util/virarch.h                                 |  2 +
 .../qemuxml2argvdata/qemuxml2argv-pseries-disk.xml |  1 -
 3 files changed, 37 insertions(+), 35 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3cb4fc1..87f5fea 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7763,7 +7763,7 @@ error:
 
 /* Parse the XML definition for an input device */
 static virDomainInputDefPtr
-virDomainInputDefParseXML(const char *ostype,
+virDomainInputDefParseXML(const virDomainDef *dom,
                           xmlNodePtr node,
                           unsigned int flags)
 {
@@ -7796,7 +7796,7 @@ virDomainInputDefParseXML(const char *ostype,
             goto error;
         }
 
-        if (STREQ(ostype, "hvm")) {
+        if (STREQ(dom->os.type, "hvm")) {
             if (def->bus == VIR_DOMAIN_INPUT_BUS_PS2 && /* PS2 can be mouse or keyboard */
                 !(def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ||
                 def->type == VIR_DOMAIN_INPUT_TYPE_KBD)) {
@@ -7826,9 +7826,10 @@ virDomainInputDefParseXML(const char *ostype,
             }
         }
     } else {
-        if (STREQ(ostype, "hvm")) {
-            if (def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ||
-                def->type == VIR_DOMAIN_INPUT_TYPE_KBD)
+        if (STREQ(dom->os.type, "hvm")) {
+            if ((def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ||
+                def->type == VIR_DOMAIN_INPUT_TYPE_KBD) &&
+                ARCH_IS_X86(dom->os.arch))
                 def->bus = VIR_DOMAIN_INPUT_BUS_PS2;
             else
                 def->bus = VIR_DOMAIN_INPUT_BUS_USB;
@@ -9850,7 +9851,7 @@ virDomainDeviceDefParse(const char *xmlStr,
             goto error;
         break;
     case VIR_DOMAIN_DEVICE_INPUT:
-        if (!(dev->data.input = virDomainInputDefParseXML(def->os.type,
+        if (!(dev->data.input = virDomainInputDefParseXML(def,
                                                           node, flags)))
             goto error;
         break;
@@ -12433,7 +12434,7 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;
 
     for (i = 0; i < n; i++) {
-        virDomainInputDefPtr input = virDomainInputDefParseXML(def->os.type,
+        virDomainInputDefPtr input = virDomainInputDefParseXML(def,
                                                                nodes[i],
                                                                flags);
         if (!input)
@@ -12485,29 +12486,28 @@ virDomainDefParseXML(xmlDocPtr xml,
     VIR_FREE(nodes);
 
     /* If graphics are enabled, there's an implicit PS2 mouse */
-    if (def->ngraphics > 0) {
-        virDomainInputDefPtr input;
+    if (def->ngraphics > 0 &&
+        (ARCH_IS_X86(def->os.arch) ||
+         def->os.arch == VIR_ARCH_NONE)) {
+        int input_bus = VIR_DOMAIN_INPUT_BUS_XEN;
 
-        if (VIR_ALLOC(input) < 0) {
-            goto error;
-        }
-        if (STREQ(def->os.type, "hvm")) {
-            input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE;
-            input->bus = VIR_DOMAIN_INPUT_BUS_PS2;
-        } else {
-            input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE;
-            input->bus = VIR_DOMAIN_INPUT_BUS_XEN;
-        }
+        if (STREQ(def->os.type, "hvm"))
+            input_bus = VIR_DOMAIN_INPUT_BUS_PS2;
 
-        if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) {
-            virDomainInputDefFree(input);
+        if (virDomainDefMaybeAddInput(def,
+                                      VIR_DOMAIN_INPUT_TYPE_MOUSE,
+                                      input_bus) < 0)
             goto error;
+
+        /*Ignore keyboard for XEN, only add a PS2 keyboard device for hvm*/
+        if (STREQ(def->os.type, "hvm")) {
+            if (virDomainDefMaybeAddInput(def,
+                                          VIR_DOMAIN_INPUT_TYPE_KBD,
+                                          input_bus) < 0)
+                goto error;
         }
-        def->inputs[def->ninputs] = input;
-        def->ninputs++;
     }
 
-
     /* analysis of the sound devices */
     if ((n = virXPathNodeSet("./devices/sound", ctxt, &nodes)) < 0) {
         goto error;
@@ -17523,16 +17523,17 @@ 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 */
+        if (ARCH_IS_X86(def->os.arch)) {
+            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)
diff --git a/src/util/virarch.h b/src/util/virarch.h
index b180400..d6a4413 100644
--- a/src/util/virarch.h
+++ b/src/util/virarch.h
@@ -70,6 +70,8 @@ typedef enum {
     VIR_ARCH_LAST,
 } virArch;
 
+# define ARCH_IS_X86(arch)  ((arch) == VIR_ARCH_X86_64 ||\
+                            (arch) == VIR_ARCH_I686)
 
 typedef enum {
     VIR_ARCH_LITTLE_ENDIAN,
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml b/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml
index dbbd6aa..8dde776 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-disk.xml
@@ -30,7 +30,6 @@
     <controller type='usb' index='0'/>
     <controller type='scsi' index='0'/>
     <controller type='pci' index='0' model='pci-root'/>
-    <input type='mouse' bus='ps2'/>
     <graphics type='sdl'/>
     <video>
       <model type='cirrus' vram='9216' heads='1'/>
-- 
1.8.2.1


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