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 ccd141c55..9a4ad0531 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2713,6 +2713,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:
@@ -2722,13 +2725,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,
@@ -2754,13 +2750,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
goto error;
}
- 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,
@@ -2783,13 +2772,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,
_("autogenerated pcie-root-port options not
set"));
goto error;
}
- 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,
@@ -2884,13 +2852,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,
@@ -2917,13 +2878,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,
@@ -2956,13 +2910,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 a40d5ba55..302e3ee49 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4114,6 +4114,7 @@ qemuDomainDeviceDefValidateControllerPCI(const
virDomainControllerDef *controlle
{
virDomainControllerModelPCI model = controller->model;
const virDomainPCIControllerOpts *pciopts;
+ const char *modelName = NULL;
/* skip pcie-root */
if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT)
@@ -4156,6 +4157,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