aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2011-09-02 22:49:42 +0800
committerDaniel Veillard <veillard@redhat.com>2011-09-02 23:39:03 +0800
commitfdd14a9d056a363373baf224056612fbf7467b20 (patch)
treeb6d909ff265b60330203c5861b84433294b8c3ea
parentqemu: don't reserve slot 1 if a PIIX3 USB controller is defined there (diff)
downloadlibvirt-fdd14a9d056a363373baf224056612fbf7467b20.tar.gz
libvirt-fdd14a9d056a363373baf224056612fbf7467b20.tar.bz2
libvirt-fdd14a9d056a363373baf224056612fbf7467b20.zip
qemu: Don't append 0 at usb id, so that it is compatible with legacy -usb
QEMU uses USB bus name "usb.0" when using the legacy -usb argument. If we want to allow USB devices to specify their addresses with legacy -usb, we should either in case of legacy bus name drop the 0 from the address bus, or just drop the 0 from device id. This patch does the later. Another solution would be to permit addressing on non-legacy USB controllers only.
-rw-r--r--src/qemu/qemu_command.c46
-rw-r--r--tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse-addr.args2
-rw-r--r--tests/qemuxml2argvdata/qemuxml2argv-usb-hub.args2
-rw-r--r--tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-companion.args8
-rw-r--r--tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-ehci-addr.args2
-rw-r--r--tests/qemuxml2argvdata/qemuxml2argv-usb-piix3-controller.args2
-rw-r--r--tests/qemuxml2argvdata/qemuxml2argv-usb-ports.args2
-rw-r--r--tests/qemuxml2argvtest.c2
8 files changed, 45 insertions, 21 deletions
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ff8a8313f..5cb62e6f7 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1099,7 +1099,7 @@ qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs)
if (qemuDomainPCIAddressReserveSlot(addrs, 0) < 0)
goto error;
- /* Verify that first IDE controller (if any) is on the PIIX3, fn 1 */
+ /* Verify that first IDE and USB controllers (if any) is on the PIIX3, fn 1 */
for (i = 0; i < def->ncontrollers ; i++) {
/* First IDE controller lives on the PIIX3 at slot=1, function=1 */
if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE &&
@@ -1125,11 +1125,24 @@ qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs)
}
} else if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
def->controllers[i]->idx == 0 &&
- def->controllers[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI &&
- def->controllers[i]->info.addr.pci.domain == 0 &&
- def->controllers[i]->info.addr.pci.bus == 0 &&
- def->controllers[i]->info.addr.pci.slot == 1) {
- reservedUSB = true;
+ def->controllers[i]->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI) {
+ if (def->controllers[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+ if (def->controllers[i]->info.addr.pci.domain != 0 ||
+ def->controllers[i]->info.addr.pci.bus != 0 ||
+ def->controllers[i]->info.addr.pci.slot != 1 ||
+ def->controllers[i]->info.addr.pci.function != 2) {
+ qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("PIIX3 USB controller must have PCI address 0:0:1.2"));
+ goto error;
+ }
+ reservedUSB = true;
+ } else {
+ def->controllers[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+ def->controllers[i]->info.addr.pci.domain = 0;
+ def->controllers[i]->info.addr.pci.bus = 0;
+ def->controllers[i]->info.addr.pci.slot = 1;
+ def->controllers[i]->info.addr.pci.function = 2;
+ }
}
}
@@ -1292,6 +1305,14 @@ error:
return -1;
}
+static void
+qemuUsbId(virBufferPtr buf, int idx)
+{
+ if (idx == 0)
+ virBufferAsprintf(buf, "usb");
+ else
+ virBufferAsprintf(buf, "usb%d", idx);
+}
static int
qemuBuildDeviceAddressStr(virBufferPtr buf,
@@ -1341,8 +1362,9 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
else
virBufferAsprintf(buf, ",addr=0x%x", info->addr.pci.slot);
} else if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
- virBufferAsprintf(buf, ",bus=usb%d.0", info->addr.usb.bus);
- virBufferAsprintf(buf, ",port=%s", info->addr.usb.port);
+ virBufferAsprintf(buf, ",bus=");
+ qemuUsbId(buf, info->addr.usb.bus);
+ virBufferAsprintf(buf, ".0,port=%s", info->addr.usb.port);
}
return 0;
@@ -1785,10 +1807,12 @@ qemuBuildUSBControllerDevStr(virDomainControllerDefPtr def,
virBufferAsprintf(buf, "%s", smodel);
if (def->info.mastertype == VIR_DOMAIN_CONTROLLER_MASTER_USB) {
- virBufferAsprintf(buf, ",masterbus=usb%d.0", def->idx);
- virBufferAsprintf(buf, ",firstport=%d", def->info.master.usb.startport);
+ virBufferAsprintf(buf, ",masterbus=");
+ qemuUsbId(buf, def->idx);
+ virBufferAsprintf(buf, ".0,firstport=%d", def->info.master.usb.startport);
} else {
- virBufferAsprintf(buf, ",id=usb%d", def->idx);
+ virBufferAsprintf(buf, ",id=");
+ qemuUsbId(buf, def->idx);
}
return 0;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse-addr.args b/tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse-addr.args
index d7849609d..b6dc0d357 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse-addr.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse-addr.args
@@ -1 +1 @@
-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 -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -usb -device usb-mouse,id=input0,bus=usb0.0,port=4 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
+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 -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -usb -device usb-mouse,id=input0,bus=usb.0,port=4 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-hub.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-hub.args
index 3d32e416b..4911dd429 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-usb-hub.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-hub.args
@@ -1 +1 @@
-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 -usb -device usb-hub,id=hub0,bus=usb0.0,port=1 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
+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 -usb -device usb-hub,id=hub0,bus=usb.0,port=1 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-companion.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-companion.args
index b37dbf6b7..100754483 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-companion.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-companion.args
@@ -1,6 +1,6 @@
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 ich9-usb-ehci1,id=usb0,bus=pci.0,multifunction=on,addr=0x4.0x7 \
--device ich9-usb-uhci1,masterbus=usb0.0,firstport=0,bus=pci.0,multifunction=on,addr=0x4.0x0 \
--device ich9-usb-uhci2,masterbus=usb0.0,firstport=2,bus=pci.0,multifunction=on,addr=0x4.0x1 \
--device ich9-usb-uhci3,masterbus=usb0.0,firstport=4,bus=pci.0,multifunction=on,addr=0x4.0x2 \
+-device ich9-usb-ehci1,id=usb,bus=pci.0,multifunction=on,addr=0x4.0x7 \
+-device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x4.0x0 \
+-device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,multifunction=on,addr=0x4.0x1 \
+-device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,multifunction=on,addr=0x4.0x2 \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,multifunction=on,addr=0x3.0x0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-ehci-addr.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-ehci-addr.args
index 502244dd6..0059ab590 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-ehci-addr.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-ehci-addr.args
@@ -1 +1 @@
-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 ich9-usb-ehci1,id=usb0,bus=pci.0,multifunction=on,addr=0x4.0x7 -device virtio-balloon-pci,id=balloon0,bus=pci.0,multifunction=on,addr=0x3.0x0
+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 ich9-usb-ehci1,id=usb,bus=pci.0,multifunction=on,addr=0x4.0x7 -device virtio-balloon-pci,id=balloon0,bus=pci.0,multifunction=on,addr=0x3.0x0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-piix3-controller.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-piix3-controller.args
index 799b75f45..06863bbde 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-usb-piix3-controller.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-piix3-controller.args
@@ -1 +1 @@
-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 piix3-usb-uhci,id=usb0,bus=pci.0,addr=0x3 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
+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 piix3-usb-uhci,id=usb,bus=pci.0,multifunction=on,addr=0x1.0x2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,multifunction=on,addr=0x3.0x0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-ports.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-ports.args
index 8ba5b7cf0..556eb4cf8 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-usb-ports.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-ports.args
@@ -1 +1 @@
-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 -usb -device usb-hub,id=hub0,bus=usb0.0,port=1 -device usb-hub,id=hub1,bus=usb0.0,port=1.2 -device usb-mouse,id=input0,bus=usb0.0,port=1.1 -device usb-mouse,id=input1,bus=usb0.0,port=1.2.1 -device usb-mouse,id=input2,bus=usb0.0,port=1.2.2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
+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 -usb -device usb-hub,id=hub0,bus=usb.0,port=1 -device usb-hub,id=hub1,bus=usb.0,port=1.2 -device usb-mouse,id=input0,bus=usb.0,port=1.1 -device usb-mouse,id=input1,bus=usb.0,port=1.2.1 -device usb-mouse,id=input2,bus=usb.0,port=1.2.2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 99d8711af..fcd52d21b 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -492,7 +492,7 @@ mymain(void)
QEMU_CAPS_NODEFCONFIG);
DO_TEST("usb-piix3-controller", false,
QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_PIIX3_USB_UHCI,
- QEMU_CAPS_NODEFCONFIG);
+ QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_NODEFCONFIG);
DO_TEST("usb-ich9-ehci-addr", false,
QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_ICH9_USB_EHCI1);