qemu: report a nicer error when USB is disabled

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>
This commit is contained in:
Ján Tomko 2017-09-14 09:13:20 +02:00
parent c17666419b
commit 1cdc9ecebd
4 changed files with 11 additions and 1 deletions

View File

@ -5225,7 +5225,7 @@ virDomainDiskDefValidate(const virDomainDiskDef *disk)
return 0;
}
static bool
bool
virDomainDefHasUSB(const virDomainDef *def)
{
size_t i;

View 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,

View File

@ -276,6 +276,7 @@ virDomainDefGetVcpusTopology;
virDomainDefHasDeviceAddress;
virDomainDefHasMemballoon;
virDomainDefHasMemoryHotplug;
virDomainDefHasUSB;
virDomainDefHasVcpusOffline;
virDomainDefLifecycleActionAllowed;
virDomainDefMaybeAddController;

View 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);