[libvirt] [PATCH v2 13/15] qemu: Move PCI more command checks to controller def validate

John Ferlan jferlan at redhat.com
Wed Dec 6 15:27:45 UTC 2017


Excluding the qemuCaps checks, move the remainder of the checks
that validate whether the PCI definition is valid or not into
qemuDomainControllerDefValidatePCI.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/qemu/qemu_command.c |  96 ----------------------------------
 src/qemu/qemu_domain.c  | 134 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 134 insertions(+), 96 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7f2102644..95a6f56e7 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2725,20 +2725,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
 
         switch ((virDomainControllerModelPCI) def->model) {
         case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
-            if (pciopts->chassisNr == -1) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("autogenerated pci-bridge option chassisNr not set"));
-                goto error;
-            }
-
-            if (pciopts->modelName
-                != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PCI_BRIDGE) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("PCI controller model name '%s' "
-                                 "is not valid for a pci-bridge"),
-                               modelName);
-                goto error;
-            }
             if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PCI_BRIDGE)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                _("the pci-bridge controller "
@@ -2750,19 +2736,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                               def->info.alias);
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_PCI_EXPANDER_BUS:
-            if (pciopts->busNr == -1) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("autogenerated pci-expander-bus option busNr not set"));
-            }
-
-            if (pciopts->modelName
-                != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PXB) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("PCI controller model name '%s' "
-                                 "is not valid for a pci-expander-bus"),
-                               modelName);
-                goto error;
-            }
             if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PXB)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                _("the pxb controller "
@@ -2777,14 +2750,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                                  pciopts->numaNode);
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
-            if (pciopts->modelName
-                != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_I82801B11_BRIDGE) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("PCI controller model name '%s' "
-                                 "is not valid for a dmi-to-pci-bridge"),
-                               modelName);
-                goto error;
-            }
             if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                _("the dmi-to-pci-bridge (i82801b11-bridge) "
@@ -2794,16 +2759,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
             virBufferAsprintf(&buf, "%s,id=%s", modelName, def->info.alias);
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT:
-            if ((pciopts->modelName !=
-                 VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_IOH3420) &&
-                (pciopts->modelName !=
-                 VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PCIE_ROOT_PORT)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("PCI controller model name '%s' "
-                                 "is not valid for a pcie-root-port"),
-                               modelName);
-                goto error;
-            }
             if ((pciopts->modelName ==
                  VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_IOH3420) &&
                 !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_IOH3420)) {
@@ -2826,14 +2781,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                               pciopts->chassis, def->info.alias);
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
-            if (pciopts->modelName
-                != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_X3130_UPSTREAM) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("PCI controller model name '%s' "
-                                 "is not valid for a pcie-switch-upstream-port"),
-                               modelName);
-                goto error;
-            }
             if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_X3130_UPSTREAM)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                _("the pcie-switch-upstream-port (x3130-upstream) "
@@ -2844,23 +2791,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
             virBufferAsprintf(&buf, "%s,id=%s", modelName, def->info.alias);
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_DOWNSTREAM_PORT:
-            if (pciopts->chassis == -1 ||
-                pciopts->port == -1) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("autogenerated pcie-switch-downstream-port "
-                                 "options chassis=%d or port=%d not set"),
-                               pciopts->chassis, pciopts->port);
-                goto error;
-            }
-
-            if (pciopts->modelName
-                != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_XIO3130_DOWNSTREAM) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("PCI controller model name '%s' "
-                                 "is not valid for a pcie-switch-downstream-port"),
-                               modelName);
-                goto error;
-            }
             if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                _("The pcie-switch-downstream-port "
@@ -2873,20 +2803,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                               pciopts->chassis, def->info.alias);
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_EXPANDER_BUS:
-            if (pciopts->busNr == -1) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("autogenerated pcie-expander-bus option busNr not set"));
-                goto error;
-            }
-
-            if (pciopts->modelName
-                != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PXB_PCIE) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("PCI controller model name '%s' "
-                                 "is not valid for a pcie-expander-bus"),
-                               modelName);
-                goto error;
-            }
             if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PXB_PCIE)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                _("the pxb-pcie controller "
@@ -2901,22 +2817,10 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                                  pciopts->numaNode);
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT:
-            if (pciopts->targetIndex == -1) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("autogenerated pci-root option targetIndex not set"));
-                goto error;
-            }
-
             /* Skip the implicit one */
             if (pciopts->targetIndex == 0)
                 goto done;
 
-            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"),
-                               modelName);
-                goto error;
-            }
             if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                _("the spapr-pci-host-bridge controller "
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 5f417d5d7..54cc6ac9c 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4049,6 +4049,8 @@ qemuDomainDeviceDefValidateControllerPCI(const virDomainControllerDef *controlle
     const virDomainPCIControllerOpts *pciopts;
     const char *modelName = NULL;
 
+    /* First pass - just check the controller index for the model's
+     * that we care to check... */
     switch (model) {
     case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
     case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
@@ -4091,6 +4093,138 @@ qemuDomainDeviceDefValidateControllerPCI(const virDomainControllerDef *controlle
         }
     }
 
+    /* Second pass - now the model specific checks */
+    switch (model) {
+    case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
+        if (pciopts->chassisNr == -1) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("autogenerated pci-bridge option chassisNr not set"));
+            return -1;
+        }
+
+        if (pciopts->modelName != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PCI_BRIDGE) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("PCI controller model name '%s' is not valid "
+                             "for a pci-bridge"),
+                           modelName);
+            return -1;
+        }
+
+        break;
+
+    case VIR_DOMAIN_CONTROLLER_MODEL_PCI_EXPANDER_BUS:
+        if (pciopts->busNr == -1) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("autogenerated pci-expander-bus option busNr not set"));
+            return -1;
+        }
+
+        if (pciopts->modelName != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PXB) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("PCI controller model name '%s' is not valid "
+                             "for a pci-expander-bus"),
+                           modelName);
+            return -1;
+        }
+
+        break;
+
+    case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
+        if (pciopts->modelName != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_I82801B11_BRIDGE) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("PCI controller model name '%s' is not valid "
+                             "for a dmi-to-pci-bridge"),
+                           modelName);
+            return -1;
+        }
+
+        break;
+
+    case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT:
+        if ((pciopts->modelName != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_IOH3420) &&
+            (pciopts->modelName != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PCIE_ROOT_PORT)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("PCI controller model name '%s' is not valid "
+                             "for a pcie-root-port"),
+                           modelName);
+            return -1;
+        }
+
+        break;
+
+    case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
+        if (pciopts->modelName != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_X3130_UPSTREAM) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("PCI controller model name '%s' is not valid "
+                             "for a pcie-switch-upstream-port"),
+                           modelName);
+            return -1;
+        }
+
+        break;
+
+    case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_DOWNSTREAM_PORT:
+        if (pciopts->chassis == -1 || pciopts->port == -1) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("autogenerated pcie-switch-downstream-port "
+                             "options chassis=%d or port=%d not set"),
+                           pciopts->chassis, pciopts->port);
+            return -1;
+        }
+
+        if (pciopts->modelName != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_XIO3130_DOWNSTREAM) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("PCI controller model name '%s' is not valid "
+                             "for a pcie-switch-downstream-port"),
+                           modelName);
+            return -1;
+        }
+
+        break;
+
+    case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_EXPANDER_BUS:
+        if (pciopts->busNr == -1) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("autogenerated pcie-expander-bus option busNr not set"));
+            return -1;
+        }
+
+        if (pciopts->modelName != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PXB_PCIE) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("PCI controller model name '%s' is not valid "
+                             "for a pcie-expander-bus"),
+                            modelName);
+             return -1;
+        }
+
+        break;
+
+    case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT:
+        if (pciopts->targetIndex == -1) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("autogenerated pci-root option targetIndex not set"));
+            return -1;
+        }
+
+        /* Skip the implicit one */
+        if (pciopts->targetIndex == 0)
+            return 0;
+
+        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"),
+                           modelName);
+            return 0;
+        }
+
+        break;
+
+    case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT:
+    case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST:
+        break;
+    }
+
     return 0;
 }
 
-- 
2.13.6




More information about the libvir-list mailing list