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 <jfer...@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 cc8cc1afe..18ede87d6 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2720,6 +2720,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:
@@ -2729,13 +2732,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,
@@ -2761,13 +2757,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,
@@ -2790,13 +2779,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,
@@ -2819,13 +2801,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 !=
@@ -2858,13 +2833,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,
@@ -2891,13 +2859,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,
@@ -2924,13 +2885,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,
@@ -2963,13 +2917,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 9c843d8b5..376ad63fc 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4024,6 +4024,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)
@@ -4066,6 +4067,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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to