]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: report a nicer error when USB is disabled
authorJán Tomko <jtomko@redhat.com>
Thu, 14 Sep 2017 07:13:20 +0000 (09:13 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 7 Mar 2018 13:10:46 +0000 (14:10 +0100)
If the user tries to define a domain that has

  <controller type='usb' model='none'/>

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 <jtomko@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/qemu/qemu_domain_address.c

index a248d73de3736064456f169d1db3e6389b23fa7b..4b722fbfbae24a05d30f8e02d13bc82879b69e11 100644 (file)
@@ -5225,7 +5225,7 @@ virDomainDiskDefValidate(const virDomainDiskDef *disk)
     return 0;
 }
 
-static bool
+bool
 virDomainDefHasUSB(const virDomainDef *def)
 {
     size_t i;
index a04f96169cbfeec3a5ad47687894c5d86ab89adb..5859c8f4b18653f42ca12135928a597c635aea84 100644 (file)
@@ -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,
index 8a62ea159e81d7d15deacffc11d3df4404d2ac40..3766e20d3b301528f0ed6a5f7594b2351f070b73 100644 (file)
@@ -276,6 +276,7 @@ virDomainDefGetVcpusTopology;
 virDomainDefHasDeviceAddress;
 virDomainDefHasMemballoon;
 virDomainDefHasMemoryHotplug;
+virDomainDefHasUSB;
 virDomainDefHasVcpusOffline;
 virDomainDefLifecycleActionAllowed;
 virDomainDefMaybeAddController;
index 1d88ab47a87c776e42e9156fc1ad393faa913f86..3fcb36add4e8585159214af25222dbc61558f0a7 100644 (file)
@@ -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);