[PATCH v5 16/16] qemu: Use switch statement for address types in qemuBuildControllerDevStr

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

 



From: Marc Hartmayer <mhartmay@xxxxxxxxxxxxxxxxxx>

Use a switch statement instead of if-else-if statements. Move the
command line building of the iothread attribute into the common path
as the SCSI controller attributes are already validated.

Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxxxxxxx>
Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8c728c654..2523127cc 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2612,6 +2612,7 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     int model = def->model;
+    int address_type = def->info.type;
     const virDomainPCIControllerOpts *pciopts;
     const char *modelName = NULL;
 
@@ -2624,23 +2625,25 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
 
         switch ((virDomainControllerModelSCSI) model) {
         case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI:
-            if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) {
+            switch ((virDomainDeviceAddressType) address_type) {
+            case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
                 virBufferAddLit(&buf, "virtio-scsi-ccw");
-                if (def->iothread)
-                    virBufferAsprintf(&buf, ",iothread=iothread%u",
-                                      def->iothread);
-            } else if (def->info.type ==
-                       VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390) {
+                break;
+            case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
                 virBufferAddLit(&buf, "virtio-scsi-s390");
-            } else if (def->info.type ==
-                       VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO) {
+                break;
+            case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
                 virBufferAddLit(&buf, "virtio-scsi-device");
-            } else {
+                break;
+            default:
                 virBufferAddLit(&buf, "virtio-scsi-pci");
-                if (def->iothread)
-                    virBufferAsprintf(&buf, ",iothread=iothread%u",
-                                      def->iothread);
             }
+
+            if (def->iothread) {
+                virBufferAsprintf(&buf, ",iothread=iothread%u",
+                                  def->iothread);
+            }
+
             if (qemuBuildVirtioOptionsStr(&buf, def->virtio, qemuCaps) < 0)
                 goto error;
             break;
@@ -2668,18 +2671,20 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
         break;
 
     case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL:
-        if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+        switch ((virDomainDeviceAddressType) address_type) {
+        case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
             virBufferAddLit(&buf, "virtio-serial-pci");
-        } else if (def->info.type ==
-                   VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) {
+            break;
+        case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
             virBufferAddLit(&buf, "virtio-serial-ccw");
-        } else if (def->info.type ==
-                   VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390) {
+            break;
+        case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
             virBufferAddLit(&buf, "virtio-serial-s390");
-        } else if (def->info.type ==
-                   VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO) {
+            break;
+        case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
             virBufferAddLit(&buf, "virtio-serial-device");
-        } else {
+            break;
+        default:
             virBufferAddLit(&buf, "virtio-serial");
         }
         virBufferAsprintf(&buf, ",id=%s", def->info.alias);
-- 
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