]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Move PCI command modelName check to controller def validate
authorJohn Ferlan <jferlan@redhat.com>
Mon, 27 Nov 2017 19:36:22 +0000 (14:36 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 2 Feb 2018 19:35:26 +0000 (14:35 -0500)
Move the various modelName == NAME_NONE from the command line
generation into domain controller validation.  Also rather than
have multiple cases with the same check, let's make the code
more generic, but also note that it was the modelName option
that caused the failure. We also have to be sure not to check
the PCI models that we don't care about.

For the remaining checks in command line building, we can use
the field name in the error message to be more specific about
what causes the failure.

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

index a84cb5839c4c9689dc2637eba3ffef86e3b0cbde..648d361662253cd4f158f8d3f8850ce65cba259f 100644 (file)
@@ -2716,9 +2716,7 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
 
         switch ((virDomainControllerModelPCI) def->model) {
         case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
-            if (pciopts->modelName
-                == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE ||
-                pciopts->chassisNr == -1) {
+            if (pciopts->chassisNr == -1) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("autogenerated pci-bridge options not set"));
                 goto error;
@@ -2750,9 +2748,7 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                               def->info.alias);
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_PCI_EXPANDER_BUS:
-            if (pciopts->modelName
-                == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE ||
-                pciopts->busNr == -1) {
+            if (pciopts->busNr == -1) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("autogenerated pci-expander-bus options not set"));
                 goto error;
@@ -2787,13 +2783,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_NONE) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("autogenerated dmi-to-pci-bridge options not set"));
-                goto error;
-            }
-
             modelName = virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
             if (!modelName) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2818,9 +2807,7 @@ 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_NONE ||
-                pciopts->chassis == -1 || pciopts->port == -1) {
+            if (pciopts->chassis == -1 || pciopts->port == -1) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("autogenerated pcie-root-port options not set"));
                 goto error;
@@ -2864,12 +2851,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_NONE) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("autogenerated pcie-switch-upstream-port options not set"));
-                goto error;
-            }
             modelName = virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
             if (!modelName) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2895,9 +2876,7 @@ 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->modelName
-                == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE ||
-                pciopts->chassis == -1 ||
+            if (pciopts->chassis == -1 ||
                 pciopts->port == -1) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("autogenerated pcie-switch-downstream-port "
@@ -2932,9 +2911,7 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                               pciopts->chassis, def->info.alias);
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_EXPANDER_BUS:
-            if (pciopts->modelName
-                == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE ||
-                pciopts->busNr == -1) {
+            if (pciopts->busNr == -1) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("autogenerated pcie-expander-bus options not set"));
                 goto error;
@@ -2969,8 +2946,7 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                                  pciopts->numaNode);
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT:
-            if (pciopts->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE ||
-                pciopts->targetIndex == -1) {
+            if (pciopts->targetIndex == -1) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("autogenerated pci-root options not set"));
                 goto error;
index 179ff0ec8852c59114de8a50495872dcf394d4cb..a40d5ba55fc4197597759018228254f3d2322c4b 100644 (file)
@@ -4113,6 +4113,7 @@ qemuDomainDeviceDefValidateControllerPCI(const virDomainControllerDef *controlle
                                          const virDomainDef *def)
 {
     virDomainControllerModelPCI model = controller->model;
+    const virDomainPCIControllerOpts *pciopts;
 
     /* skip pcie-root */
     if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT)
@@ -4146,6 +4147,17 @@ qemuDomainDeviceDefValidateControllerPCI(const virDomainControllerDef *controlle
         break;
     }
 
+    pciopts = &controller->opts.pciopts;
+    if (controller->model != VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT &&
+        controller->model != VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST) {
+        if (pciopts->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("autogenerated %s options not set"),
+                           virDomainControllerModelPCITypeToString(controller->model));
+            return -1;
+        }
+    }
+
     return 0;
 }