[PATCH 07/17] qemu: command: drop QEMU_CAPS_DEVICE for PCI address assign

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

 



All the logic was in a QEMU_CAPS_DEVICE conditional. Unindent it
---
 src/qemu/qemu_command.c | 238 ++++++++++++++++++++++++------------------------
 1 file changed, 117 insertions(+), 121 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3ab53be..f2e9f6a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2164,149 +2164,145 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def,
     int ret = -1;
     virDomainPCIAddressSetPtr addrs = NULL;
     qemuDomainObjPrivatePtr priv = NULL;
+    int max_idx = -1;
+    int nbuses = 0;
+    size_t i;
+    int rv;
+    bool buses_reserved = true;
+    virDomainPCIConnectFlags flags = VIR_PCI_CONNECT_TYPE_PCI;
 
-    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
-        int max_idx = -1;
-        int nbuses = 0;
-        size_t i;
-        int rv;
-        bool buses_reserved = true;
+    for (i = 0; i < def->ncontrollers; i++) {
+        if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
+            if ((int) def->controllers[i]->idx > max_idx)
+                max_idx = def->controllers[i]->idx;
+        }
+    }
 
-        virDomainPCIConnectFlags flags = VIR_PCI_CONNECT_TYPE_PCI;
+    nbuses = max_idx + 1;
 
-        for (i = 0; i < def->ncontrollers; i++) {
-            if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
-                if ((int) def->controllers[i]->idx > max_idx)
-                    max_idx = def->controllers[i]->idx;
-            }
-        }
+    if (nbuses > 0 &&
+        virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PCI_BRIDGE)) {
+        virDomainDeviceInfo info;
 
-        nbuses = max_idx + 1;
+        /* 1st pass to figure out how many PCI bridges we need */
+        if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, true)))
+            goto cleanup;
 
-        if (nbuses > 0 &&
-            virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PCI_BRIDGE)) {
-            virDomainDeviceInfo info;
+        if (qemuValidateDevicePCISlotsChipsets(def, qemuCaps, addrs) < 0)
+            goto cleanup;
 
-            /* 1st pass to figure out how many PCI bridges we need */
-            if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, true)))
-                goto cleanup;
+        for (i = 0; i < addrs->nbuses; i++) {
+            if (!qemuDomainPCIBusFullyReserved(&addrs->buses[i]))
+                buses_reserved = false;
+        }
 
-            if (qemuValidateDevicePCISlotsChipsets(def, qemuCaps, addrs) < 0)
-                goto cleanup;
+        /* Reserve 1 extra slot for a (potential) bridge only if buses
+         * are not fully reserved yet
+         */
+        if (!buses_reserved &&
+            virDomainPCIAddressReserveNextSlot(addrs, &info, flags) < 0)
+            goto cleanup;
 
-            for (i = 0; i < addrs->nbuses; i++) {
-                if (!qemuDomainPCIBusFullyReserved(&addrs->buses[i]))
-                    buses_reserved = false;
-            }
+        if (qemuAssignDevicePCISlots(def, qemuCaps, addrs) < 0)
+            goto cleanup;
 
-            /* Reserve 1 extra slot for a (potential) bridge only if buses
-             * are not fully reserved yet
-             */
-            if (!buses_reserved &&
-                virDomainPCIAddressReserveNextSlot(addrs, &info, flags) < 0)
-                goto cleanup;
+        for (i = 1; i < addrs->nbuses; i++) {
+            virDomainPCIAddressBusPtr bus = &addrs->buses[i];
 
-            if (qemuAssignDevicePCISlots(def, qemuCaps, addrs) < 0)
+            if ((rv = virDomainDefMaybeAddController(
+                     def, VIR_DOMAIN_CONTROLLER_TYPE_PCI,
+                     i, bus->model)) < 0)
+                goto cleanup;
+            /* If we added a new bridge, we will need one more address */
+            if (rv > 0 &&
+                virDomainPCIAddressReserveNextSlot(addrs, &info, flags) < 0)
                 goto cleanup;
+        }
+        nbuses = addrs->nbuses;
+        virDomainPCIAddressSetFree(addrs);
+        addrs = NULL;
 
-            for (i = 1; i < addrs->nbuses; i++) {
-                virDomainPCIAddressBusPtr bus = &addrs->buses[i];
+    } else if (max_idx > 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("PCI bridges are not supported "
+                         "by this QEMU binary"));
+        goto cleanup;
+    }
 
-                if ((rv = virDomainDefMaybeAddController(
-                         def, VIR_DOMAIN_CONTROLLER_TYPE_PCI,
-                         i, bus->model)) < 0)
-                    goto cleanup;
-                /* If we added a new bridge, we will need one more address */
-                if (rv > 0 &&
-                    virDomainPCIAddressReserveNextSlot(addrs, &info, flags) < 0)
-                    goto cleanup;
-            }
-            nbuses = addrs->nbuses;
-            virDomainPCIAddressSetFree(addrs);
-            addrs = NULL;
+    if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, false)))
+        goto cleanup;
 
-        } else if (max_idx > 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("PCI bridges are not supported "
-                             "by this QEMU binary"));
+    if (qemuDomainSupportsPCI(def, qemuCaps)) {
+        if (qemuValidateDevicePCISlotsChipsets(def, qemuCaps, addrs) < 0)
             goto cleanup;
-        }
 
-        if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, false)))
+        if (qemuAssignDevicePCISlots(def, qemuCaps, addrs) < 0)
             goto cleanup;
 
-        if (qemuDomainSupportsPCI(def, qemuCaps)) {
-            if (qemuValidateDevicePCISlotsChipsets(def, qemuCaps, addrs) < 0)
-                goto cleanup;
-
-            if (qemuAssignDevicePCISlots(def, qemuCaps, addrs) < 0)
-                goto cleanup;
-
-            for (i = 0; i < def->ncontrollers; i++) {
-                virDomainControllerDefPtr cont = def->controllers[i];
-                int idx = cont->idx;
-                virDevicePCIAddressPtr addr;
-                virDomainPCIControllerOptsPtr options;
+        for (i = 0; i < def->ncontrollers; i++) {
+            virDomainControllerDefPtr cont = def->controllers[i];
+            int idx = cont->idx;
+            virDevicePCIAddressPtr addr;
+            virDomainPCIControllerOptsPtr options;
 
-                if (cont->type != VIR_DOMAIN_CONTROLLER_TYPE_PCI)
-                    continue;
+            if (cont->type != VIR_DOMAIN_CONTROLLER_TYPE_PCI)
+                continue;
 
-                addr = &cont->info.addr.pci;
-                options = &cont->opts.pciopts;
+            addr = &cont->info.addr.pci;
+            options = &cont->opts.pciopts;
 
-                /* set defaults for any other auto-generated config
-                 * options for this controller that haven't been
-                 * specified in config.
-                 */
-                switch ((virDomainControllerModelPCI)cont->model) {
-                case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
-                    if (options->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
-                        options->modelName = VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PCI_BRIDGE;
-                    if (options->chassisNr == -1)
-                        options->chassisNr = cont->idx;
-                    break;
-                case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
-                    if (options->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
-                        options->modelName = VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_I82801B11_BRIDGE;
-                    break;
-                case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT:
-                    if (options->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
-                        options->modelName = VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_IOH3420;
-                    if (options->chassis == -1)
-                       options->chassis = cont->idx;
-                    if (options->port == -1)
-                       options->port = (addr->slot << 3) + addr->function;
-                    break;
-                case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
-                    if (options->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
-                        options->modelName = VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_X3130_UPSTREAM;
-                    break;
-                case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_DOWNSTREAM_PORT:
-                    if (options->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
-                        options->modelName = VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_XIO3130_DOWNSTREAM;
-                    if (options->chassis == -1)
-                       options->chassis = cont->idx;
-                    if (options->port == -1)
-                       options->port = addr->slot;
-                    break;
-                case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT:
-                case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT:
-                case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST:
-                    break;
-                }
+            /* set defaults for any other auto-generated config
+             * options for this controller that haven't been
+             * specified in config.
+             */
+            switch ((virDomainControllerModelPCI)cont->model) {
+            case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
+                if (options->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
+                    options->modelName = VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PCI_BRIDGE;
+                if (options->chassisNr == -1)
+                    options->chassisNr = cont->idx;
+                break;
+            case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
+                if (options->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
+                    options->modelName = VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_I82801B11_BRIDGE;
+                break;
+            case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT:
+                if (options->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
+                    options->modelName = VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_IOH3420;
+                if (options->chassis == -1)
+                   options->chassis = cont->idx;
+                if (options->port == -1)
+                   options->port = (addr->slot << 3) + addr->function;
+                break;
+            case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
+                if (options->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
+                    options->modelName = VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_X3130_UPSTREAM;
+                break;
+            case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_DOWNSTREAM_PORT:
+                if (options->modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
+                    options->modelName = VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_XIO3130_DOWNSTREAM;
+                if (options->chassis == -1)
+                   options->chassis = cont->idx;
+                if (options->port == -1)
+                   options->port = addr->slot;
+                break;
+            case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT:
+            case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT:
+            case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST:
+                break;
+            }
 
-                /* check if every PCI bridge controller's ID is greater than
-                 * the bus it is placed onto
-                 */
-                if (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE &&
-                    idx <= addr->bus) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("failed to create PCI bridge "
-                                     "on bus %d: too many devices with fixed "
-                                     "addresses"),
-                                   addr->bus);
-                    goto cleanup;
-                }
+            /* check if every PCI bridge controller's ID is greater than
+             * the bus it is placed onto
+             */
+            if (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE &&
+                idx <= addr->bus) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("failed to create PCI bridge "
+                                 "on bus %d: too many devices with fixed "
+                                 "addresses"),
+                               addr->bus);
+                goto cleanup;
             }
         }
     }
-- 
2.5.0

--
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]