render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 7d759a3c11fad02795b6ef9cdc091356353d8492 Mon Sep 17 00:00:00 2001
Message-Id: <7d759a3c11fad02795b6ef9cdc091356353d8492.1380703761.git.jdenemar@redhat.com>
From: Laine Stump <laine@laine.org>
Date: Fri, 27 Sep 2013 05:19:40 -0600
Subject: [PATCH] qemu: eliminate redundant if clauses in qemuCollectPCIAddress

Replace them with switch cases. This will make it more efficient when
we add exceptions for more controller types, and other device types.

This is a prerequisite for patches to resolve:

   https://bugzilla.redhat.com/show_bug.cgi?id=1003983

(cherry picked from commit fbd9be484c3b1891412e9409d0133a07bbc3fc2b)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_command.c | 57 +++++++++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d596f09..85eedd5 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1689,37 +1689,44 @@ qemuCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED,
     /* Change flags according to differing requirements of different
      * devices.
      */
-    if (device->type == VIR_DOMAIN_DEVICE_CONTROLLER &&
-        device->data.controller->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
-        switch (device->data.controller->model) {
-        case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
-            /* pci-bridge needs a PCI slot, but it isn't
-             * hot-pluggable, so it doesn't need a hot-pluggable slot.
-             */
-            flags = QEMU_PCI_CONNECT_TYPE_PCI;
+    switch (device->type) {
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
+        switch (device->data.controller->type) {
+        case  VIR_DOMAIN_CONTROLLER_TYPE_PCI:
+            switch (device->data.controller->model) {
+            case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
+                /* pci-bridge needs a PCI slot, but it isn't
+                 * hot-pluggable, so it doesn't need a hot-pluggable slot.
+                 */
+                flags = QEMU_PCI_CONNECT_TYPE_PCI;
+                break;
+            case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
+                /* pci-bridge needs a PCIe slot, but it isn't
+                 * hot-pluggable, so it doesn't need a hot-pluggable slot.
+                 */
+                flags = QEMU_PCI_CONNECT_TYPE_PCIE;
+                break;
+            default:
+                break;
+            }
             break;
-        case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
-            /* pci-bridge needs a PCIe slot, but it isn't
-             * hot-pluggable, so it doesn't need a hot-pluggable slot.
+
+        case VIR_DOMAIN_CONTROLLER_TYPE_SATA:
+            /* SATA controllers aren't hot-plugged, and can be put in
+             * either a PCI or PCIe slot
              */
-            flags = QEMU_PCI_CONNECT_TYPE_PCIE;
-            break;
-        default:
+            flags = QEMU_PCI_CONNECT_TYPE_PCI | QEMU_PCI_CONNECT_TYPE_PCIE;
             break;
         }
-    }
-    /* SATA controllers aren't hot-plugged, and can be put in either a
-     * PCI or PCIe slot
-     */
-    if (device->type == VIR_DOMAIN_DEVICE_CONTROLLER &&
-        device->data.controller->type == VIR_DOMAIN_CONTROLLER_TYPE_SATA)
-        flags = QEMU_PCI_CONNECT_TYPE_PCI | QEMU_PCI_CONNECT_TYPE_PCIE;
+        break;
 
-    /* video cards aren't hot-plugged, and can be put in either a PCI
-     * or PCIe slot
-     */
-    if (device->type == VIR_DOMAIN_DEVICE_VIDEO)
+    case VIR_DOMAIN_DEVICE_VIDEO:
+        /* video cards aren't hot-plugged, and can be put in either a
+         * PCI or PCIe slot
+         */
         flags = QEMU_PCI_CONNECT_TYPE_PCI | QEMU_PCI_CONNECT_TYPE_PCIE;
+        break;
+    }
 
     /* Ignore implicit controllers on slot 0:0:1.0:
      * implicit IDE controller on 0:0:1.1 (no qemu command line)
-- 
1.8.3.2