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

2018-02-09 Thread Ján Tomko

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


signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

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

2018-02-08 Thread Peter Krempa
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(, "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(_opts, "%s,", optstr);
+}
+VIR_FREE(optstr);
+
+if (bootindex) {
+if (virAsprintf(, "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(_opts, "%s,", optstr);
+}
+VIR_FREE(optstr);
+}
+
+/* Newer Q35 machine types require an explicit FDC controller */
+virBufferTrim(_opts, ",", -1);
+if ((fdc_opts_str = virBufferContentAndReset(_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(, "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(_opts, "%s,", optstr);
-}
-VIR_FREE(optstr);
-
-if (bootindex) {
-if (virAsprintf(, "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(_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(_opts, ",", -1);
-if ((fdc_opts_str = virBufferContentAndReset(_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