[PATCH] qemu: command: Extract formatting of floppy related stuff into a helper

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

 



The floppy command formatting is special-cased since it does not
directly translate to a single '-device' argument.

Move the code from qemuBuildDiskDriveCommandLine to a new helper
function so that all the related code is together.
---
 src/qemu/qemu_command.c | 91 +++++++++++++++++++++++++++++--------------------
 1 file changed, 54 insertions(+), 37 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 24b434a458..3857a5ef5b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2211,6 +2211,58 @@ qemuBuildDriveDevStr(const virDomainDef *def,
 }


+static int
+qemuBulildFloppyCommandLineOptions(virCommandPtr cmd,
+                                   const virDomainDef *def,
+                                   virDomainDiskDefPtr disk,
+                                   unsigned int bootindex)
+
+{
+    virBuffer fdc_opts = VIR_BUFFER_INITIALIZER;
+    char *fdc_opts_str = NULL;
+    char *optstr;
+
+    if (virAsprintf(&optstr, "drive%c=drive-%s",
+                    disk->info.addr.drive.unit ? 'B' : 'A',
+                    disk->info.alias) < 0)
+        return -1;
+
+    if (!qemuDomainNeedsFDC(def)) {
+        virCommandAddArg(cmd, "-global");
+        virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
+    } else {
+        virBufferAsprintf(&fdc_opts, "%s,", optstr);
+    }
+    VIR_FREE(optstr);
+
+    if (bootindex) {
+        if (virAsprintf(&optstr, "bootindex%c=%u",
+                        disk->info.addr.drive.unit
+                        ? 'B' : 'A',
+                        bootindex) < 0)
+            return -1;
+
+        if (!qemuDomainNeedsFDC(def)) {
+            virCommandAddArg(cmd, "-global");
+            virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
+        } else {
+            virBufferAsprintf(&fdc_opts, "%s,", optstr);
+        }
+        VIR_FREE(optstr);
+    }
+
+    /* Newer Q35 machine types require an explicit FDC controller */
+    virBufferTrim(&fdc_opts, ",", -1);
+    if ((fdc_opts_str = virBufferContentAndReset(&fdc_opts))) {
+        virCommandAddArg(cmd, "-device");
+        virCommandAddArgFormat(cmd, "isa-fdc,%s", fdc_opts_str);
+        VIR_FREE(fdc_opts_str);
+    }
+
+    return 0;
+}
+
+
 static int
 qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
                               const virDomainDef *def,
@@ -2220,8 +2272,6 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
     unsigned int bootCD = 0;
     unsigned int bootFloppy = 0;
     unsigned int bootDisk = 0;
-    virBuffer fdc_opts = VIR_BUFFER_INITIALIZER;
-    char *fdc_opts_str = NULL;

     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_BOOT) ||
         virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX)) {
@@ -2300,34 +2350,9 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,

         if (qemuDiskBusNeedsDeviceArg(disk->bus)) {
             if (disk->bus == VIR_DOMAIN_DISK_BUS_FDC) {
-                if (virAsprintf(&optstr, "drive%c=drive-%s",
-                                disk->info.addr.drive.unit ? 'B' : 'A',
-                                disk->info.alias) < 0)
+                if (qemuBulildFloppyCommandLineOptions(cmd, def, disk,
+                                                       bootindex) < 0)
                     return -1;
-
-                if (!qemuDomainNeedsFDC(def)) {
-                    virCommandAddArg(cmd, "-global");
-                    virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
-                } else {
-                    virBufferAsprintf(&fdc_opts, "%s,", optstr);
-                }
-                VIR_FREE(optstr);
-
-                if (bootindex) {
-                    if (virAsprintf(&optstr, "bootindex%c=%u",
-                                    disk->info.addr.drive.unit
-                                    ? 'B' : 'A',
-                                    bootindex) < 0)
-                        return -1;
-
-                    if (!qemuDomainNeedsFDC(def)) {
-                        virCommandAddArg(cmd, "-global");
-                        virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
-                    } else {
-                        virBufferAsprintf(&fdc_opts, "%s,", optstr);
-                    }
-                    VIR_FREE(optstr);
-                }
             } else {
                 virCommandAddArg(cmd, "-device");

@@ -2339,14 +2364,6 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
             }
         }
     }
-    /* Newer Q35 machine types require an explicit FDC controller */
-    virBufferTrim(&fdc_opts, ",", -1);
-    if ((fdc_opts_str = virBufferContentAndReset(&fdc_opts))) {
-        virCommandAddArg(cmd, "-device");
-        virCommandAddArgFormat(cmd, "isa-fdc,%s", fdc_opts_str);
-        VIR_FREE(fdc_opts_str);
-    }
-
     return 0;
 }

-- 
2.15.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]

  Powered by Linux