From: Michal Privoznik Date: Fri, 16 Mar 2018 14:53:32 +0000 (+0100) Subject: qemu: Build usb controller command line more wisely X-Git-Tag: v4.2.0-rc1~112 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b133fac356324c3c7992a9cb07c1b5d9eea1e2eb;p=thirdparty%2Flibvirt.git qemu: Build usb controller command line more wisely https://bugzilla.redhat.com/show_bug.cgi?id=1552127 When building command line for USB controllers we have to do more than just put controller's alias onto the command line. QEMU has concept of these joined USB controllers. For instance ehci and uhci controllers need to create the same USB bus. To achieve that the slave controller needs to refer the master controller. This worked until we've introduced user aliases because both master and slave had the same alias. With user aliases slave can have different alias than master. Therefore, when generating command line for slave we need to look up the master's alias. Signed-off-by: Michal Privoznik --- diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index fa0aa5d5c3..a8afbd14fa 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2545,8 +2545,34 @@ qemuControllerModelUSBToCaps(int model) } +static const char * +qemuBuildUSBControllerFindMasterAlias(const virDomainDef *domainDef, + const virDomainControllerDef *def) +{ + size_t i; + + for (i = 0; i < domainDef->ncontrollers; i++) { + const virDomainControllerDef *tmp = domainDef->controllers[i]; + + if (tmp->type != VIR_DOMAIN_CONTROLLER_TYPE_USB) + continue; + + if (tmp->idx != def->idx) + continue; + + if (tmp->info.mastertype == VIR_DOMAIN_CONTROLLER_MASTER_USB) + continue; + + return tmp->info.alias; + } + + return NULL; +} + + static int -qemuBuildUSBControllerDevStr(virDomainControllerDefPtr def, +qemuBuildUSBControllerDevStr(const virDomainDef *domainDef, + virDomainControllerDefPtr def, virQEMUCapsPtr qemuCaps, virBuffer *buf) { @@ -2586,11 +2612,19 @@ qemuBuildUSBControllerDevStr(virDomainControllerDefPtr def, def->opts.usbopts.ports, def->opts.usbopts.ports); } - if (def->info.mastertype == VIR_DOMAIN_CONTROLLER_MASTER_USB) + if (def->info.mastertype == VIR_DOMAIN_CONTROLLER_MASTER_USB) { + const char *masterbus; + + if (!(masterbus = qemuBuildUSBControllerFindMasterAlias(domainDef, def))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("masterbus not found")); + return -1; + } virBufferAsprintf(buf, ",masterbus=%s.0,firstport=%d", - def->info.alias, def->info.master.usb.startport); - else + masterbus, def->info.master.usb.startport); + } else { virBufferAsprintf(buf, ",id=%s", def->info.alias); + } return 0; } @@ -2722,7 +2756,7 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef, break; case VIR_DOMAIN_CONTROLLER_TYPE_USB: - if (qemuBuildUSBControllerDevStr(def, qemuCaps, &buf) == -1) + if (qemuBuildUSBControllerDevStr(domainDef, def, qemuCaps, &buf) == -1) goto error; if (nusbcontroller) diff --git a/tests/qemuxml2argvdata/user-aliases-usb.args b/tests/qemuxml2argvdata/user-aliases-usb.args new file mode 100644 index 0000000000..3dfaadc33b --- /dev/null +++ b/tests/qemuxml2argvdata/user-aliases-usb.args @@ -0,0 +1,38 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-x86_64 \ +-name gentoo \ +-S \ +-M pc-i440fx-1.4 \ +-m 4096 \ +-smp 4,sockets=4,cores=1,threads=1 \ +-uuid a75aca4b-a02f-2bcb-4a91-c93cd848c34b \ +-nographic \ +-nodefaults \ +-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-gentoo/monitor.sock,\ +server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=readline \ +-global PIIX4_PM.disable_s3=0 \ +-global PIIX4_PM.disable_s4=0 \ +-boot cd \ +-device ich9-usb-ehci1,id=ua-myUSB1,bus=pci.0,addr=0x4.0x7 \ +-device ich9-usb-uhci1,masterbus=ua-myUSB1.0,firstport=0,bus=pci.0,\ +multifunction=on,addr=0x4 \ +-device ich9-usb-uhci2,masterbus=ua-myUSB1.0,firstport=2,bus=pci.0,\ +addr=0x4.0x1 \ +-device ich9-usb-uhci3,masterbus=ua-myUSB1.0,firstport=4,bus=pci.0,\ +addr=0x4.0x2 \ +-device ich9-usb-ehci1,id=ua-myUSB5,bus=pci.0,addr=0x5.0x7 \ +-device ich9-usb-uhci1,masterbus=ua-myUSB5.0,firstport=0,bus=pci.0,\ +multifunction=on,addr=0x5 \ +-device ich9-usb-uhci2,masterbus=ua-myUSB5.0,firstport=2,bus=pci.0,\ +addr=0x5.0x1 \ +-device ich9-usb-uhci3,masterbus=ua-myUSB5.0,firstport=4,bus=pci.0,\ +addr=0x5.0x2 \ +-device usb-host,hostbus=14,hostaddr=6,id=hostdev0,bus=ua-myUSB1.0,port=3 \ +-device usb-host,hostbus=15,hostaddr=6,id=hostdev1,bus=ua-myUSB5.0,port=3 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/user-aliases-usb.xml b/tests/qemuxml2argvdata/user-aliases-usb.xml new file mode 100644 index 0000000000..668a9c384b --- /dev/null +++ b/tests/qemuxml2argvdata/user-aliases-usb.xml @@ -0,0 +1,78 @@ + + gentoo + a75aca4b-a02f-2bcb-4a91-c93cd848c34b + 4194304 + 4194304 + 4 + + hvm + + + + + + + + + + destroy + restart + restart + + + + + + /usr/bin/qemu-system-x86_64 + + +
+ + + + +
+ + + + +
+ + + + +
+ + + +
+ + + + +
+ + + + +
+ + + + +
+ + + +
+ +
+ + + +
+ +
+ + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 731db9ed52..f6a90c2814 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2997,6 +2997,9 @@ mymain(void) QEMU_CAPS_DEVICE_ISA_SERIAL, QEMU_CAPS_HDA_DUPLEX); DO_TEST("user-aliases2", QEMU_CAPS_DEVICE_IOH3420, QEMU_CAPS_ICH9_AHCI); + DO_TEST("user-aliases-usb", QEMU_CAPS_KVM, + QEMU_CAPS_PIIX_DISABLE_S3, QEMU_CAPS_PIIX_DISABLE_S4, + QEMU_CAPS_ICH9_USB_EHCI1, QEMU_CAPS_PCI_MULTIFUNCTION); /* Test disks with format probing enabled for legacy reasons. * New tests should not go in this section. */