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@xxxxxxxxx> --- src/qemu/qemu_domain.c | 74 +--------------------------------------- src/qemu/qemu_validate.c | 72 ++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_validate.h | 2 ++ 3 files changed, 75 insertions(+), 73 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 84212f7441..7cab3e370c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7721,78 +7721,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, @@ -7813,7 +7741,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) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 27e0558770..1bcc0c5da2 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -942,3 +942,75 @@ qemuValidateDomainDef(const virDomainDef *def, void *opaque) 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; +} diff --git a/src/qemu/qemu_validate.h b/src/qemu/qemu_validate.h index b6a6466a24..440b63333c 100644 --- a/src/qemu/qemu_validate.h +++ b/src/qemu/qemu_validate.h @@ -26,3 +26,5 @@ #include "qemu_capabilities.h" int qemuValidateDomainDef(const virDomainDef *def, void *opaque); +int qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev, + virQEMUCapsPtr qemuCaps); -- 2.25.1