From 1cdc9ecebd0bf22ea658b84c2466e2ea237f1897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Thu, 14 Sep 2017 09:13:20 +0200 Subject: [PATCH] qemu: report a nicer error when USB is disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + src/qemu/qemu_domain_address.c | 7 +++++++ 4 files changed, 11 insertions(+), 1 deletion(-) 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);