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

[libvirt] PATCH: Allow Xen bus type for input devices in QEMU driver



The Xenner virtual machine supportes a bus type of 'xen' for input devices,
corresponding to the paravirtualized mouse device. QEMU currently rejects
any bus type which isn't ps2 or usb. This patch makes it allow 'xen' as a
valid bus type for Xenner guests.

 b/tests/qemuxml2argvdata/qemuxml2argv-input-xen.args |    1 
 b/tests/qemuxml2argvdata/qemuxml2argv-input-xen.xml  |   24 ++++++
 src/qemu_conf.c                                      |   72 ++++++++++++-------
 src/qemu_conf.h                                      |    3 
 src/qemu_driver.c                                    |    2 
 tests/qemuxml2argvtest.c                             |    2 
 tests/qemuxml2xmltest.c                              |    1 
 7 files changed, 78 insertions(+), 27 deletions(-)


Dan.

diff -r f00771a60241 src/qemu_conf.c
--- a/src/qemu_conf.c	Sat May 10 12:57:47 2008 -0400
+++ b/src/qemu_conf.c	Sat May 10 13:00:01 2008 -0400
@@ -1365,6 +1365,7 @@
 
 /* Parse the XML definition for a network interface */
 static int qemudParseInputXML(virConnectPtr conn,
+                              struct qemud_vm_def *vm,
                               struct qemud_vm_input_def *input,
                               xmlNodePtr node) {
     xmlChar *type = NULL;
@@ -1391,26 +1392,46 @@
     }
 
     if (bus) {
-        if (STREQ((const char*)bus, "ps2")) { /* Only allow mouse */
-            if (input->type == QEMU_INPUT_TYPE_TABLET) {
-                qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
-                                 _("ps2 bus does not support %s input device"),
-                                 (const char*)type);
-                goto error;
-            }
-            input->bus = QEMU_INPUT_BUS_PS2;
-        } else if (STREQ((const char *)bus, "usb")) { /* Allow mouse & keyboard */
-            input->bus = QEMU_INPUT_BUS_USB;
-        } else {
-            qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
-                             _("unsupported input bus %s"), (const char*)bus);
-            goto error;
-        }
-    } else {
-        if (input->type == QEMU_INPUT_TYPE_MOUSE)
-            input->bus = QEMU_INPUT_BUS_PS2;
-        else
-            input->bus = QEMU_INPUT_BUS_USB;
+        if (STREQ(vm->os.type, "hvm")) {
+            if (STREQ((const char*)bus, "ps2")) { /* Only allow mouse */
+                if (input->type == QEMU_INPUT_TYPE_TABLET) {
+                    qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                                     _("ps2 bus does not support %s input device"),
+                                     (const char*)type);
+                    goto error;
+                }
+                input->bus = QEMU_INPUT_BUS_PS2;
+            } else if (STREQ((const char *)bus, "usb")) { /* Allow mouse & tablet */
+                input->bus = QEMU_INPUT_BUS_USB;
+            } else {
+                qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                                 _("unsupported input bus %s"), (const char*)bus);
+                goto error;
+            }
+        } else {
+            if (STREQ((const char *)bus, "xen")) { /* Allow mouse only */
+                input->bus = QEMU_INPUT_BUS_XEN;
+                if (input->type == QEMU_INPUT_TYPE_TABLET) {
+                    qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                                     _("xen bus does not support %s input device"),
+                                     (const char*)type);
+                    goto error;
+                }
+            } else {
+                qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                                 _("unsupported input bus %s"), (const char*)bus);
+                goto error;
+            }
+        }
+    } else {
+        if (!strcmp(vm->os.type, "hvm")) {
+            if (input->type == QEMU_INPUT_TYPE_MOUSE)
+                input->bus = QEMU_INPUT_BUS_PS2;
+            else
+                input->bus = QEMU_INPUT_BUS_USB;
+        } else {
+            input->bus = QEMU_INPUT_BUS_XEN;
+        }
     }
 
     xmlFree(type);
@@ -1998,7 +2019,7 @@
                          "%s", _("failed to allocate space for input string"));
                 goto error;
             }
-            if (qemudParseInputXML(conn, input, obj->nodesetval->nodeTab[i]) < 0) {
+            if (qemudParseInputXML(conn, def, input, obj->nodesetval->nodeTab[i]) < 0) {
                 free(input);
                 goto error;
             }
@@ -2852,7 +2873,7 @@
 
 struct qemud_vm_device_def *
 qemudParseVMDeviceDef(virConnectPtr conn,
-                      struct qemud_driver *driver ATTRIBUTE_UNUSED,
+                      struct qemud_vm_def *def,
                       const char *xmlStr)
 {
     xmlDocPtr xml;
@@ -2880,7 +2901,7 @@
         qemudParseInterfaceXML(conn, &(dev->data.net), node);
     } else if (xmlStrEqual(node->name, BAD_CAST "input")) {
         dev->type = QEMUD_DEVICE_DISK;
-        qemudParseInputXML(conn, &(dev->data.input), node);
+        qemudParseInputXML(conn, def, &(dev->data.input), node);
     } else if (xmlStrEqual(node->name, BAD_CAST "sound")) {
         dev->type = QEMUD_DEVICE_SOUND;
         qemudParseSoundXML(conn, &(dev->data.sound), node);
@@ -3950,14 +3971,15 @@
 
     input = def->inputs;
     while (input) {
-        if (input->bus != QEMU_INPUT_BUS_PS2)
+        if (input->bus == QEMU_INPUT_BUS_USB)
             virBufferVSprintf(&buf, "    <input type='%s' bus='usb'/>\n",
                               input->type == QEMU_INPUT_TYPE_MOUSE ? "mouse" : "tablet");
         input = input->next;
     }
     /* If graphics is enable, add implicit mouse */
     if (def->graphicsType != QEMUD_GRAPHICS_NONE)
-        virBufferAddLit(&buf, "    <input type='mouse' bus='ps2'/>\n");
+        virBufferVSprintf(&buf, "    <input type='mouse' bus='%s'/>\n",
+                          STREQ(def->os.type, "hvm") ? "ps2" : "xen");
 
     switch (def->graphicsType) {
     case QEMUD_GRAPHICS_VNC:
diff -r f00771a60241 src/qemu_conf.h
--- a/src/qemu_conf.h	Sat May 10 12:57:47 2008 -0400
+++ b/src/qemu_conf.h	Sat May 10 13:00:01 2008 -0400
@@ -189,6 +189,7 @@
 enum qemu_vm_input_bus {
     QEMU_INPUT_BUS_PS2,
     QEMU_INPUT_BUS_USB,
+    QEMU_INPUT_BUS_XEN,
 };
 
 struct qemud_vm_input_def {
@@ -474,7 +475,7 @@
 
 struct qemud_vm_device_def *
             qemudParseVMDeviceDef       (virConnectPtr conn,
-                                         struct qemud_driver *driver,
+                                         struct qemud_vm_def *def,
                                          const char *xmlStr);
 
 struct qemud_vm_def *
diff -r f00771a60241 src/qemu_driver.c
--- a/src/qemu_driver.c	Sat May 10 12:57:47 2008 -0400
+++ b/src/qemu_driver.c	Sat May 10 13:00:01 2008 -0400
@@ -2516,7 +2516,7 @@
         return -1;
     }
 
-    dev = qemudParseVMDeviceDef(dom->conn, driver, xml);
+    dev = qemudParseVMDeviceDef(dom->conn, vm->def, xml);
     if (dev == NULL) {
         return -1;
     }
diff -r f00771a60241 tests/qemuxml2argvdata/qemuxml2argv-input-xen.args
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/qemuxml2argvdata/qemuxml2argv-input-xen.args	Sat May 10 13:00:01 2008 -0400
@@ -0,0 +1,1 @@
+/usr/bin/xenner -M xenner -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -vnc :-5901
\ No newline at end of file
diff -r f00771a60241 tests/qemuxml2argvdata/qemuxml2argv-input-xen.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/qemuxml2argvdata/qemuxml2argv-input-xen.xml	Sat May 10 13:00:01 2008 -0400
@@ -0,0 +1,24 @@
+<domain type='kvm'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219200</memory>
+  <currentMemory>219200</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>xen</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/xenner</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+    </disk>
+    <input type='mouse' bus='xen'/>
+    <graphics type='vnc' port='-1'/>
+  </devices>
+</domain>
diff -r f00771a60241 tests/qemuxml2argvtest.c
--- a/tests/qemuxml2argvtest.c	Sat May 10 12:57:47 2008 -0400
+++ b/tests/qemuxml2argvtest.c	Sat May 10 13:00:01 2008 -0400
@@ -153,10 +153,12 @@
     DO_TEST("disk-floppy", 0);
     DO_TEST("disk-many", 0);
     DO_TEST("disk-virtio", 1);
+    DO_TEST("disk-xenvbd", 1);
     DO_TEST("graphics-vnc", 0);
     DO_TEST("graphics-sdl", 0);
     DO_TEST("input-usbmouse", 0);
     DO_TEST("input-usbtablet", 0);
+    DO_TEST("input-xen", 0);
     DO_TEST("misc-acpi", 0);
     DO_TEST("misc-no-reboot", 0);
     DO_TEST("net-user", 0);
diff -r f00771a60241 tests/qemuxml2xmltest.c
--- a/tests/qemuxml2xmltest.c	Sat May 10 12:57:47 2008 -0400
+++ b/tests/qemuxml2xmltest.c	Sat May 10 13:00:01 2008 -0400
@@ -107,6 +107,7 @@
     DO_TEST("graphics-sdl");
     DO_TEST("input-usbmouse");
     DO_TEST("input-usbtablet");
+    DO_TEST("input-xen");
     DO_TEST("misc-acpi");
     DO_TEST("misc-no-reboot");
     DO_TEST("net-user");


-- 
|: Red Hat, Engineering, Boston   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


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