[PATCH v5 13/16] qemu: Move PCI more command checks to controller def validate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 101 -----------------------------------
 src/qemu/qemu_domain.c  | 139 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+), 101 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 4a5d37f5d..0dbc73399 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2726,20 +2726,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 options 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 "
@@ -2751,20 +2737,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 options not set"));
-                goto error;
-            }
-
-            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 "
@@ -2779,14 +2751,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) "
@@ -2796,21 +2760,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->chassis == -1 || pciopts->port == -1) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("autogenerated pcie-root-port options not set"));
-                goto error;
-            }
-            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)) {
@@ -2833,14 +2782,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) "
@@ -2851,22 +2792,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, "%s",
-                               _("autogenerated pcie-switch-downstream-port "
-                                 "options not set"));
-                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 "
@@ -2879,20 +2804,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 options 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 "
@@ -2907,22 +2818,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 options 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 082f1124c..8cbb29e40 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4135,6 +4135,8 @@ qemuDomainDeviceDefValidateControllerPCI(const virDomainControllerDef *controlle
         controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT)
         return 0;
 
+    /* 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:
@@ -4177,6 +4179,143 @@ 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 options 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 options 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->chassis == -1 || pciopts->port == -1) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("autogenerated pcie-root-port options not set"));
+            return -1;
+        }
+
+        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, "%s",
+                           _("autogenerated pcie-switch-downstream-port "
+                             "options not set"));
+            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 options 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 options 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

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux