From: Ján Tomko Date: Thu, 14 Sep 2017 07:13:20 +0000 (+0200) Subject: qemu: report a nicer error when USB is disabled X-Git-Tag: v4.2.0-rc1~255 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cdc9ecebd0bf22ea658b84c2466e2ea237f1897;p=thirdparty%2Flibvirt.git qemu: report a nicer error when USB is disabled If the user tries to define a domain that has and also some USB devices, we report an error: error: internal error: No free USB ports Which is technically still correct for a domain with no USB ports. Change it to: USB is disabled for this domain, but USB devices are present in the domain XML https://bugzilla.redhat.com/show_bug.cgi?id=1347550 Signed-off-by: Ján Tomko --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a248d73de3..4b722fbfba 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5225,7 +5225,7 @@ virDomainDiskDefValidate(const virDomainDiskDef *disk) return 0; } -static bool +bool virDomainDefHasUSB(const virDomainDef *def) { size_t i; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a04f96169c..5859c8f4b1 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2700,6 +2700,8 @@ int virDomainDefPostParse(virDomainDefPtr def, unsigned int parseFlags, virDomainXMLOptionPtr xmlopt, void *parseOpaque); +bool +virDomainDefHasUSB(const virDomainDef *def); int virDomainDeviceValidateAliasForHotplug(virDomainObjPtr vm, virDomainDeviceDefPtr dev, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8a62ea159e..3766e20d3b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -276,6 +276,7 @@ virDomainDefGetVcpusTopology; virDomainDefHasDeviceAddress; virDomainDefHasMemballoon; virDomainDefHasMemoryHotplug; +virDomainDefHasUSB; virDomainDefHasVcpusOffline; virDomainDefLifecycleActionAllowed; virDomainDefMaybeAddController; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 1d88ab47a8..3fcb36add4 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2701,6 +2701,13 @@ qemuDomainUSBAddressAddHubs(virDomainDefPtr def) &data, false)); + if (data.count && !virDomainDefHasUSB(def)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("USB is disabled for this domain, but USB devices " + "are present in the domain XML")); + return -1; + } + if (data.count > available_ports) hubs_needed = VIR_DIV_UP(data.count - available_ports + 1, VIR_DOMAIN_USB_HUB_PORTS - 1);