From nobody Sun Apr 28 00:36:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1518100046348571.6567591529964; Thu, 8 Feb 2018 06:27:26 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 667C2C0567A3; Thu, 8 Feb 2018 14:27:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D6186018D; Thu, 8 Feb 2018 14:27:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2B6EF4A46E; Thu, 8 Feb 2018 14:27:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w18EQBx6023620 for ; Thu, 8 Feb 2018 09:26:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8F0E910073C2; Thu, 8 Feb 2018 14:26:11 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 181E410073BE; Thu, 8 Feb 2018 14:26:08 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 8 Feb 2018 15:25:25 +0100 Message-Id: <9054d17a31ececb6122c7829920635fa6b9e80f6.1518099925.git.pkrempa@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH] qemu: command: Extract formatting of floppy related stuff into a helper X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 08 Feb 2018 14:27:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 =3D VIR_BUFFER_INITIALIZER; + char *fdc_opts_str =3D NULL; + char *optstr; + + if (virAsprintf(&optstr, "drive%c=3Ddrive-%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=3D%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 =3D 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 =3D 0; unsigned int bootFloppy =3D 0; unsigned int bootDisk =3D 0; - virBuffer fdc_opts =3D VIR_BUFFER_INITIALIZER; - char *fdc_opts_str =3D 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 =3D=3D VIR_DOMAIN_DISK_BUS_FDC) { - if (virAsprintf(&optstr, "drive%c=3Ddrive-%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=3D%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 =3D virBufferContentAndReset(&fdc_opts))) { - virCommandAddArg(cmd, "-device"); - virCommandAddArgFormat(cmd, "isa-fdc,%s", fdc_opts_str); - VIR_FREE(fdc_opts_str); - } - return 0; } --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list