[PATCH 02/13] qemu: eliminate duplicated code in qemuBuildDriveDevStr()

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

 



The code to add device type to the commandline was identical for lsi
and other models of SCSI controllers, but was duplicated (with the
exception of a minor ordering difference of the if-else clauses) for
the two cases. This patch replaces those two with a single instance of
the code just before the if().
---
 src/qemu/qemu_command.c | 39 +++++++++++++--------------------------
 1 file changed, 13 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 67214e3..620a2a0 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4070,6 +4070,19 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
         if ((qemuSetSCSIControllerModel(def, qemuCaps, &controllerModel)) < 0)
             goto error;
 
+        if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
+            virBufferAddLit(&opt, "scsi-block");
+        } else {
+            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_CD)) {
+                if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
+                    virBufferAddLit(&opt, "scsi-cd");
+                else
+                    virBufferAddLit(&opt, "scsi-hd");
+            } else {
+                virBufferAddLit(&opt, "scsi-disk");
+            }
+        }
+
         if (controllerModel == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
             if (disk->info.addr.drive.target != 0) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -4078,19 +4091,6 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
                 goto error;
             }
 
-            if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
-                virBufferAddLit(&opt, "scsi-block");
-            } else {
-                if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_CD)) {
-                    if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
-                        virBufferAddLit(&opt, "scsi-cd");
-                    else
-                        virBufferAddLit(&opt, "scsi-hd");
-                } else {
-                    virBufferAddLit(&opt, "scsi-disk");
-                }
-            }
-
             virBufferAsprintf(&opt, ",bus=scsi%d.%d,scsi-id=%d",
                               disk->info.addr.drive.controller,
                               disk->info.addr.drive.bus,
@@ -4113,19 +4113,6 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
                 }
             }
 
-            if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN) {
-                if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_CD)) {
-                    if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
-                        virBufferAddLit(&opt, "scsi-cd");
-                    else
-                        virBufferAddLit(&opt, "scsi-hd");
-                } else {
-                    virBufferAddLit(&opt, "scsi-disk");
-                }
-            } else {
-                virBufferAddLit(&opt, "scsi-block");
-            }
-
             virBufferAsprintf(&opt, ",bus=scsi%d.0,channel=%d,scsi-id=%d,lun=%d",
                               disk->info.addr.drive.controller,
                               disk->info.addr.drive.bus,
-- 
2.1.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]