]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Use switch statement for address types in qemuBuildControllerDevStr
authorMarc Hartmayer <mhartmay@linux.vnet.ibm.com>
Thu, 4 Jan 2018 11:41:29 +0000 (12:41 +0100)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 2 Feb 2018 19:52:23 +0000 (14:52 -0500)
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@linux.vnet.ibm.com>
src/qemu/qemu_command.c

index 234e2f8e256b8c624f3c76ca698d02479f8b013a..24b434a458993a0bc0f4f4c4fe03bf841a00d82b 100644 (file)
@@ -2608,6 +2608,7 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                           int *nusbcontroller)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
+    int address_type = def->info.type;
     const virDomainPCIControllerOpts *pciopts;
     const char *modelName = NULL;
 
@@ -2617,23 +2618,25 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
     case VIR_DOMAIN_CONTROLLER_TYPE_SCSI:
         switch ((virDomainControllerModelSCSI) def->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;
@@ -2661,18 +2664,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);