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

Peter Krempa posted 1 patch 6 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/9054d17a31ececb6122c7829920635fa6b9e80f6.1518099925.git.pkrempa@redhat.com
src/qemu/qemu_command.c | 91 +++++++++++++++++++++++++++++--------------------
1 file changed, 54 insertions(+), 37 deletions(-)
[libvirt] [PATCH] qemu: command: Extract formatting of floppy related stuff into a helper
Posted by Peter Krempa 6 years, 1 month ago
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@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: command: Extract formatting of floppy related stuff into a helper
Posted by Ján Tomko 6 years, 1 month ago
On Thu, Feb 08, 2018 at 03:25:25PM +0100, Peter Krempa wrote:
>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.

Please ask the author of the patch to provide a Signed-off-by line to
conform with our contributor guidelines, point 6:
https://libvirt.org/hacking.html#patches

A sign-off a day keeps lawyers away.

>---
> src/qemu/qemu_command.c | 91 +++++++++++++++++++++++++++++--------------------
> 1 file changed, 54 insertions(+), 37 deletions(-)
>

ACK

Jan
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list