qemu: move qemuDomainDeviceDefValidateAddress() to qemu_validate.c

The next big task is to move qemuDomainDeviceDefValidate() to
qemu_validation.c, which is a function that calls a lot of
other static helper functions. This patch starts it by moving
qemuDomainDeviceDefValidateAddress().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Daniel Henrique Barboza 2020-03-26 18:31:14 -03:00 committed by Ján Tomko
parent 07cfccc53a
commit 2a8168c99b
3 changed files with 75 additions and 73 deletions

View File

@ -7730,78 +7730,6 @@ qemuDomainDeviceDefValidateFS(virDomainFSDefPtr fs,
}
static int
qemuDomainDeviceDefValidateZPCIAddress(virDomainDeviceInfoPtr info,
virQEMUCapsPtr qemuCaps)
{
if (!virZPCIDeviceAddressIsEmpty(&info->addr.pci.zpci) &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_ZPCI)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s",
_("This QEMU binary doesn't support zPCI"));
return -1;
}
return 0;
}
static int
qemuDomainDeviceDefValidateAddress(const virDomainDeviceDef *dev,
virQEMUCapsPtr qemuCaps)
{
virDomainDeviceInfoPtr info;
if (!(info = virDomainDeviceGetInfo((virDomainDeviceDef *)dev)))
return 0;
switch ((virDomainDeviceAddressType) info->type) {
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
return qemuDomainDeviceDefValidateZPCIAddress(info, qemuCaps);
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
/* Address validation might happen before we have had a chance to
* automatically assign addresses to devices for which the user
* didn't specify one themselves */
break;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO: {
virDomainDeviceSpaprVioAddressPtr addr = &(info->addr.spaprvio);
if (addr->has_reg && addr->reg > 0xffffffff) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("spapr-vio reg='0x%llx' exceeds maximum "
"possible value (0xffffffff)"),
addr->reg);
return -1;
}
break;
}
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
/* No validation for these address types yet */
break;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
default:
virReportEnumRangeError(virDomainDeviceAddressType, info->type);
return -1;
}
return 0;
}
static int
qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
const virDomainDef *def,
@ -7822,7 +7750,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
def->virtType)))
return -1;
if ((ret = qemuDomainDeviceDefValidateAddress(dev, qemuCaps)) < 0)
if ((ret = qemuValidateDomainDeviceDefAddress(dev, qemuCaps)) < 0)
return ret;
if ((ret = virDomainCapsDeviceDefValidate(domCaps, dev, def)) < 0)

View File

@ -943,3 +943,75 @@ qemuValidateDomainDef(const virDomainDef *def,
return 0;
}
static int
qemuValidateDomainDeviceDefZPCIAddress(virDomainDeviceInfoPtr info,
virQEMUCapsPtr qemuCaps)
{
if (!virZPCIDeviceAddressIsEmpty(&info->addr.pci.zpci) &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_ZPCI)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s",
_("This QEMU binary doesn't support zPCI"));
return -1;
}
return 0;
}
int
qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev,
virQEMUCapsPtr qemuCaps)
{
virDomainDeviceInfoPtr info;
if (!(info = virDomainDeviceGetInfo((virDomainDeviceDef *)dev)))
return 0;
switch ((virDomainDeviceAddressType) info->type) {
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
return qemuValidateDomainDeviceDefZPCIAddress(info, qemuCaps);
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
/* Address validation might happen before we have had a chance to
* automatically assign addresses to devices for which the user
* didn't specify one themselves */
break;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO: {
virDomainDeviceSpaprVioAddressPtr addr = &(info->addr.spaprvio);
if (addr->has_reg && addr->reg > 0xffffffff) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("spapr-vio reg='0x%llx' exceeds maximum "
"possible value (0xffffffff)"),
addr->reg);
return -1;
}
break;
}
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
/* No validation for these address types yet */
break;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
default:
virReportEnumRangeError(virDomainDeviceAddressType, info->type);
return -1;
}
return 0;
}

View File

@ -26,3 +26,5 @@
#include "qemu_capabilities.h"
int qemuValidateDomainDef(const virDomainDef *def, void *opaque);
int qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev,
virQEMUCapsPtr qemuCaps);