]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Add support for "none" USB controller
authorPeter Krempa <pkrempa@redhat.com>
Tue, 3 Jul 2012 13:43:13 +0000 (15:43 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 2 Aug 2012 10:13:48 +0000 (12:13 +0200)
This patch enables the "none" USB controller for qemu guests and adds
valdiation on hot-plugged devices if the guest has USB disabled.

This patch also adds a set of tests to check parsing of domain XMLs that
use the "none" controller and some forbidden situations concerning it.

src/qemu/qemu_command.c
src/qemu/qemu_driver.c
tests/qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-usb-none-other.xml [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-usb-none-usbtablet.xml [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-usb-none.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c

index 0f2adb1a0dc4f0889439ff005ad2a54b2bc1a273..6ad65a6cb88a9ad517e8f197ce2c874c35ffb0ad 100644 (file)
@@ -4787,6 +4787,13 @@ qemuBuildCommandLine(virConnectPtr conn,
                 cont->type == VIR_DOMAIN_CONTROLLER_TYPE_FDC)
                 continue;
 
+             /* Also, skip USB controllers with type none.*/
+            if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
+                cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) {
+                usbcontroller = -1; /* mark we don't want a controller */
+                continue;
+            }
+
             /* Only recent QEMU implements a SATA (AHCI) controller */
             if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_SATA) {
                 if (!qemuCapsGet(qemuCaps, QEMU_CAPS_ICH9_AHCI)) {
index 0da5c5aacf0d9f1a811445cf2cabec9b91ae23f4..b3f946c911f4437ceb7f950e4abc37ca57e71c78 100644 (file)
@@ -5833,6 +5833,9 @@ qemuDomainModifyDeviceFlags(virDomainPtr dom, const char *xml,
     }
 
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+        if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
+            goto endjob;
+
         /* Make a copy for updated domain. */
         vmdef = virDomainObjCopyPersistentDef(driver->caps, vm);
         if (!vmdef)
@@ -5858,6 +5861,9 @@ qemuDomainModifyDeviceFlags(virDomainPtr dom, const char *xml,
     }
 
     if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+        if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0)
+            goto endjob;
+
         switch (action) {
         case QEMU_DEVICE_ATTACH:
             ret = qemuDomainAttachDeviceLive(vm, dev_copy, dom);
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml
new file mode 100644 (file)
index 0000000..9eeb953
--- /dev/null
@@ -0,0 +1,19 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <controller type='usb' model='none' index='0'/>
+    <memballoon model='virtio'/>
+    <hub type='usb'>
+      <address type='usb' bus='0' port='1'/>
+    </hub>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-none-other.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-none-other.xml
new file mode 100644 (file)
index 0000000..64bbba6
--- /dev/null
@@ -0,0 +1,19 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <controller type='usb' index='0' model='none'/>
+    <controller type='usb' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+    </controller>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-none-usbtablet.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-none-usbtablet.xml
new file mode 100644 (file)
index 0000000..9d53cc0
--- /dev/null
@@ -0,0 +1,21 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</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/qemu</emulator>
+    <controller type='usb' model='none' index='0'/>
+    <input type='tablet' bus='usb'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-none.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-none.args
new file mode 100644 (file)
index 0000000..085b66f
--- /dev/null
@@ -0,0 +1,5 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S \
+-M pc -m 214 -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 virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml
new file mode 100644 (file)
index 0000000..69ace41
--- /dev/null
@@ -0,0 +1,16 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <controller type='usb' index='0' model='none'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
index c4aa7c4d604b6db9365424c07603300f17387c4a..39fcd9f7fa6404f32c1aa970e2572c3fb24e54a0 100644 (file)
@@ -683,6 +683,16 @@ mymain(void)
             QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
             QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_PIIX3_USB_UHCI,
             QEMU_CAPS_USB_HUB, QEMU_CAPS_ICH9_USB_EHCI1);
+    DO_TEST("usb-none",
+            QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
+    DO_TEST_PARSE_ERROR("usb-none-other",
+            QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
+    DO_TEST_PARSE_ERROR("usb-none-hub",
+            QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
+            QEMU_CAPS_USB_HUB);
+    DO_TEST_PARSE_ERROR("usb-none-usbtablet",
+            QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
+
 
     DO_TEST("smbios", QEMU_CAPS_SMBIOS_TYPE);