render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
43fe83
From 7d759a3c11fad02795b6ef9cdc091356353d8492 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <7d759a3c11fad02795b6ef9cdc091356353d8492.1380703761.git.jdenemar@redhat.com>
43fe83
From: Laine Stump <laine@laine.org>
43fe83
Date: Fri, 27 Sep 2013 05:19:40 -0600
43fe83
Subject: [PATCH] qemu: eliminate redundant if clauses in qemuCollectPCIAddress
43fe83
43fe83
Replace them with switch cases. This will make it more efficient when
43fe83
we add exceptions for more controller types, and other device types.
43fe83
43fe83
This is a prerequisite for patches to resolve:
43fe83
43fe83
   https://bugzilla.redhat.com/show_bug.cgi?id=1003983
43fe83
43fe83
(cherry picked from commit fbd9be484c3b1891412e9409d0133a07bbc3fc2b)
43fe83
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 src/qemu/qemu_command.c | 57 +++++++++++++++++++++++++++----------------------
43fe83
 1 file changed, 32 insertions(+), 25 deletions(-)
43fe83
43fe83
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
43fe83
index d596f09..85eedd5 100644
43fe83
--- a/src/qemu/qemu_command.c
43fe83
+++ b/src/qemu/qemu_command.c
43fe83
@@ -1689,37 +1689,44 @@ qemuCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED,
43fe83
     /* Change flags according to differing requirements of different
43fe83
      * devices.
43fe83
      */
43fe83
-    if (device->type == VIR_DOMAIN_DEVICE_CONTROLLER &&
43fe83
-        device->data.controller->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
43fe83
-        switch (device->data.controller->model) {
43fe83
-        case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
43fe83
-            /* pci-bridge needs a PCI slot, but it isn't
43fe83
-             * hot-pluggable, so it doesn't need a hot-pluggable slot.
43fe83
-             */
43fe83
-            flags = QEMU_PCI_CONNECT_TYPE_PCI;
43fe83
+    switch (device->type) {
43fe83
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
43fe83
+        switch (device->data.controller->type) {
43fe83
+        case  VIR_DOMAIN_CONTROLLER_TYPE_PCI:
43fe83
+            switch (device->data.controller->model) {
43fe83
+            case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
43fe83
+                /* pci-bridge needs a PCI slot, but it isn't
43fe83
+                 * hot-pluggable, so it doesn't need a hot-pluggable slot.
43fe83
+                 */
43fe83
+                flags = QEMU_PCI_CONNECT_TYPE_PCI;
43fe83
+                break;
43fe83
+            case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
43fe83
+                /* pci-bridge needs a PCIe slot, but it isn't
43fe83
+                 * hot-pluggable, so it doesn't need a hot-pluggable slot.
43fe83
+                 */
43fe83
+                flags = QEMU_PCI_CONNECT_TYPE_PCIE;
43fe83
+                break;
43fe83
+            default:
43fe83
+                break;
43fe83
+            }
43fe83
             break;
43fe83
-        case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
43fe83
-            /* pci-bridge needs a PCIe slot, but it isn't
43fe83
-             * hot-pluggable, so it doesn't need a hot-pluggable slot.
43fe83
+
43fe83
+        case VIR_DOMAIN_CONTROLLER_TYPE_SATA:
43fe83
+            /* SATA controllers aren't hot-plugged, and can be put in
43fe83
+             * either a PCI or PCIe slot
43fe83
              */
43fe83
-            flags = QEMU_PCI_CONNECT_TYPE_PCIE;
43fe83
-            break;
43fe83
-        default:
43fe83
+            flags = QEMU_PCI_CONNECT_TYPE_PCI | QEMU_PCI_CONNECT_TYPE_PCIE;
43fe83
             break;
43fe83
         }
43fe83
-    }
43fe83
-    /* SATA controllers aren't hot-plugged, and can be put in either a
43fe83
-     * PCI or PCIe slot
43fe83
-     */
43fe83
-    if (device->type == VIR_DOMAIN_DEVICE_CONTROLLER &&
43fe83
-        device->data.controller->type == VIR_DOMAIN_CONTROLLER_TYPE_SATA)
43fe83
-        flags = QEMU_PCI_CONNECT_TYPE_PCI | QEMU_PCI_CONNECT_TYPE_PCIE;
43fe83
+        break;
43fe83
 
43fe83
-    /* video cards aren't hot-plugged, and can be put in either a PCI
43fe83
-     * or PCIe slot
43fe83
-     */
43fe83
-    if (device->type == VIR_DOMAIN_DEVICE_VIDEO)
43fe83
+    case VIR_DOMAIN_DEVICE_VIDEO:
43fe83
+        /* video cards aren't hot-plugged, and can be put in either a
43fe83
+         * PCI or PCIe slot
43fe83
+         */
43fe83
         flags = QEMU_PCI_CONNECT_TYPE_PCI | QEMU_PCI_CONNECT_TYPE_PCIE;
43fe83
+        break;
43fe83
+    }
43fe83
 
43fe83
     /* Ignore implicit controllers on slot 0:0:1.0:
43fe83
      * implicit IDE controller on 0:0:1.1 (no qemu command line)
43fe83
-- 
43fe83
1.8.3.2
43fe83