]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: command: Extract formatting of floppy related stuff into a helper
authorPeter Krempa <pkrempa@redhat.com>
Thu, 8 Feb 2018 11:23:50 +0000 (12:23 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 12 Feb 2018 09:03:29 +0000 (10:03 +0100)
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.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_command.c

index 040ea65b62dc493b8ce612592043aaa7c20f8d02..2bcaa5fc22530c00f8bea40c7530268db5ded56c 100644 (file)
@@ -2210,6 +2210,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,
@@ -2219,8 +2271,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)) {
@@ -2299,34 +2349,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");
 
@@ -2338,14 +2363,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;
 }