Similar to the checking the modelName vs. NAME_NONE, let's make the
ModelNameTypeToString check more generic too within the checking done
in controller validation (with the same ignore certain models.
NB: We need to keep the ModelNameTypeToString fetch in command line
validation since we use it, but at least we can assume it returns
something valid now.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_command.c | 59 +++----------------------------------------------
src/qemu/qemu_domain.c | 10 +++++++++
2 files changed, 13 insertions(+), 56 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 9a885bb1c..7f2102644 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2719,6 +2719,9 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
case VIR_DOMAIN_CONTROLLER_TYPE_PCI:
pciopts = &def->opts.pciopts;
+ if (def->model != VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT &&
+ def->model != VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST)
+ modelName =
virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
switch ((virDomainControllerModelPCI) def->model) {
case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
@@ -2728,13 +2731,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
goto error;
}
- modelName =
virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
- if (!modelName) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown pci-bridge model name value %d"),
- pciopts->modelName);
- goto error;
- }
if (pciopts->modelName
!= VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PCI_BRIDGE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -2759,13 +2755,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
_("autogenerated pci-expander-bus option busNr not
set"));
}
- modelName =
virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
- if (!modelName) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown pci-expander-bus model name value
%d"),
- pciopts->modelName);
- goto error;
- }
if (pciopts->modelName
!= VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PXB) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -2788,13 +2777,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
pciopts->numaNode);
break;
case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
- modelName =
virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
- if (!modelName) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown dmi-to-pci-bridge model name value
%d"),
- pciopts->modelName);
- goto error;
- }
if (pciopts->modelName
!= VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_I82801B11_BRIDGE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -2812,13 +2794,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
virBufferAsprintf(&buf, "%s,id=%s", modelName,
def->info.alias);
break;
case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT:
- modelName =
virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
- if (!modelName) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown pcie-root-port model name value
%d"),
- pciopts->modelName);
- goto error;
- }
if ((pciopts->modelName !=
VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_IOH3420) &&
(pciopts->modelName !=
@@ -2851,13 +2826,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
pciopts->chassis, def->info.alias);
break;
case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
- modelName =
virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
- if (!modelName) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown pcie-switch-upstream-port model name value
%d"),
- pciopts->modelName);
- goto error;
- }
if (pciopts->modelName
!= VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_X3130_UPSTREAM) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -2885,13 +2853,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
goto error;
}
- modelName =
virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
- if (!modelName) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown pcie-switch-downstream-port model name
value %d"),
- pciopts->modelName);
- goto error;
- }
if (pciopts->modelName
!= VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_XIO3130_DOWNSTREAM) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -2918,13 +2879,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
goto error;
}
- modelName =
virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
- if (!modelName) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown pcie-expander-bus model name value
%d"),
- pciopts->modelName);
- goto error;
- }
if (pciopts->modelName
!= VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PXB_PCIE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -2957,13 +2911,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
if (pciopts->targetIndex == 0)
goto done;
- modelName =
virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
- if (!modelName) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown pci-root model name value %d"),
- pciopts->modelName);
- goto error;
- }
if (pciopts->modelName !=
VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_SPAPR_PCI_HOST_BRIDGE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("PCI controller model name '%s' is not
valid for a pci-root"),
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 013266383..5f417d5d7 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4047,6 +4047,7 @@ qemuDomainDeviceDefValidateControllerPCI(const
virDomainControllerDef *controlle
{
virDomainControllerModelPCI model = controller->model;
const virDomainPCIControllerOpts *pciopts;
+ const char *modelName = NULL;
switch (model) {
case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
@@ -4079,6 +4080,15 @@ qemuDomainDeviceDefValidateControllerPCI(const
virDomainControllerDef *controlle
virDomainControllerModelPCITypeToString(controller->model));
return -1;
}
+
+ modelName = virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
+ if (!modelName) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unknown %s modelName value %d"),
+
virDomainControllerModelPCITypeToString(controller->model),
+ pciopts->modelName);
+ return -1;
+ }
}
return 0;
--
2.13.6