]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Move PCI command modelName TypeToString to controller def validate
authorJohn Ferlan <jferlan@redhat.com>
Mon, 27 Nov 2017 20:05:49 +0000 (15:05 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 2 Feb 2018 19:35:26 +0000 (14:35 -0500)
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.

src/qemu/qemu_command.c
src/qemu/qemu_domain.c

index 648d361662253cd4f158f8d3f8850ce65cba259f..72b85ae00080b0da12b4e7bb27d98150b450fa82 100644 (file)
@@ -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"),
index a40d5ba55fc4197597759018228254f3d2322c4b..302e3ee4974a67da8ebfb6f97a59a5a373491e6e 100644 (file)
@@ -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;