From nobody Mon Feb 9 01:06:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1634037262; cv=none; d=zohomail.com; s=zohoarc; b=nOR2ZPAjlO8fTZWS2dtRvkeWP4hhpAGLftbDUKxURJEfLXHDKo+HW1OH0V7WPLQzfU3b+i+XUaftqPCkjOh9+G75sHtH5+eNY6uOSx+ZlcKiO+fLzz0GazXkSyRxrPkygt7z5mqrtl4uX23jwbIoJkATQV4+L85/ViB/eQhe7Bk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634037262; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FtfDZnXkUKCWsxokMB9RpODMorx+62rIV3HvMcHeOh4=; b=aKjiprd9/VZS0AnMY0obhQCWBUTouaOhFsLs/jVOfZa5laduIHCu2VmVt30qo/ypFIo5O5NUlZiUJYnn8XA7Jj9cjN7tG9skiuQSYWFuFeuneTR/6J6Om6UYDdd0q3pSYLZQGSl3LTWHXVpNEQpS8lJR0Ggyqw+qZcWY/hoqGWQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1634037262836586.2284526497579; Tue, 12 Oct 2021 04:14:22 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-151-lgg6fDLvO9O1fc7BK5loOA-1; Tue, 12 Oct 2021 07:14:18 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9BF10100A647; Tue, 12 Oct 2021 11:14:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7EA8110016F4; Tue, 12 Oct 2021 11:14:13 +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 4B86A1806D01; Tue, 12 Oct 2021 11:14:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19CBEAYS008912 for ; Tue, 12 Oct 2021 07:14:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id D1BFB5D9F0; Tue, 12 Oct 2021 11:14:10 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3634A5D9D5 for ; Tue, 12 Oct 2021 11:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634037261; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FtfDZnXkUKCWsxokMB9RpODMorx+62rIV3HvMcHeOh4=; b=jR6j8aT5kMQoFbv5W6oKY7hhHxzZoPMS3oQZzyMeiiP1iY7PFyI9JKp5Wbh7sp2LddBeni 0c9iIcfun+Z7Aku0uaQrZeOR/e6NGlAegqKAtrceuIKN3CS9mSzSBE/Kz4FSMHIwJGv3NU G6inyRtj6284ZXBik99QlWPZtbMpHDE= X-MC-Unique: lgg6fDLvO9O1fc7BK5loOA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/14] qemuBuildFloppyCommandLineControllerOptions: Extract formatting of implicit/explicit fdc Date: Tue, 12 Oct 2021 13:12:19 +0200 Message-Id: <075d8dc0f0b2e733791df84498a234208af56b6d.1634037046.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1634037264897100005 Content-Type: text/plain; charset="utf-8" qemuBuildFloppyCommandLineControllerOptions was generating config for both the implicit and explicit fdc. The explicit FDC is using '-device' and thus will need to be converted to JSON. Split up the lookup of the floppy drive configs from the actuall command generation. Signed-off-by: Peter Krempa --- src/qemu/qemu_command.c | 126 +++++++++++++++++++++++++++------------- 1 file changed, 86 insertions(+), 40 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 1d5986b85a..665cd739ec 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2153,23 +2153,79 @@ qemuCommandAddExtDevice(virCommand *cmd, return 0; } + +static void +qemuBuildFloppyCommandLineControllerOptionsImplicit(virCommand *cmd, + unsigned int bootindex= A, + unsigned int bootindex= B, + const char *backendA, + const char *backendB) +{ + if (backendA) { + virCommandAddArg(cmd, "-global"); + virCommandAddArgFormat(cmd, "isa-fdc.driveA=3D%s", backendA); + } + + if (bootindexA > 0) { + virCommandAddArg(cmd, "-global"); + virCommandAddArgFormat(cmd, "isa-fdc.bootindexA=3D%u", bootindexA); + } + + if (backendB) { + virCommandAddArg(cmd, "-global"); + virCommandAddArgFormat(cmd, "isa-fdc.driveB=3D%s", backendB); + } + + if (bootindexB > 0) { + virCommandAddArg(cmd, "-global"); + virCommandAddArgFormat(cmd, "isa-fdc.bootindexB=3D%u", bootindexB); + } +} + + +static void +qemuBuildFloppyCommandLineControllerOptionsExplicit(virCommand *cmd, + unsigned int bootindex= A, + unsigned int bootindex= B, + const char *backendA, + const char *backendB) +{ + g_auto(virBuffer) fdc_opts =3D VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&fdc_opts, "isa-fdc,"); + + if (backendA) + virBufferAsprintf(&fdc_opts, "driveA=3D%s,", backendA); + + if (bootindexA > 0) + virBufferAsprintf(&fdc_opts, "bootindexA=3D%u,", bootindexA); + + if (backendB) + virBufferAsprintf(&fdc_opts, "driveB=3D%s,", backendB); + + if (bootindexB > 0) + virBufferAsprintf(&fdc_opts, "bootindexB=3D%u,", bootindexB); + + virBufferTrim(&fdc_opts, ","); + virCommandAddArg(cmd, "-device"); + virCommandAddArgBuffer(cmd, &fdc_opts); +} + + static int qemuBuildFloppyCommandLineControllerOptions(virCommand *cmd, const virDomainDef *def, virQEMUCaps *qemuCaps) { - g_auto(virBuffer) fdc_opts =3D VIR_BUFFER_INITIALIZER; - bool explicitfdc =3D qemuDomainNeedsFDC(def); + unsigned int bootindexA =3D 0; + unsigned int bootindexB =3D 0; + g_autofree char *backendA =3D NULL; + g_autofree char *backendB =3D NULL; bool hasfloppy =3D false; - char driveLetter; size_t i; - virBufferAddLit(&fdc_opts, "isa-fdc,"); - for (i =3D 0; i < def->ndisks; i++) { g_autofree char *backendAlias =3D NULL; - g_autofree char *backendStr =3D NULL; - g_autofree char *bootindexStr =3D NULL; virDomainDiskDef *disk =3D def->disks[i]; if (disk->bus !=3D VIR_DOMAIN_DISK_BUS_FDC) @@ -2177,45 +2233,35 @@ qemuBuildFloppyCommandLineControllerOptions(virComm= and *cmd, hasfloppy =3D true; - if (disk->info.addr.drive.unit) - driveLetter =3D 'B'; - else - driveLetter =3D 'A'; - - if (disk->info.effectiveBootIndex > 0) - bootindexStr =3D g_strdup_printf("bootindex%c=3D%u", driveLett= er, - disk->info.effectiveBootIndex); - /* with -blockdev we setup the floppy device and it's backend with= -device */ - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { - if (qemuDomainDiskGetBackendAlias(disk, qemuCaps, &backendAlia= s) < 0) - return -1; - - if (backendAlias) - backendStr =3D g_strdup_printf("drive%c=3D%s", driveLetter= , backendAlias); - } - - if (!explicitfdc) { - if (backendStr) { - virCommandAddArg(cmd, "-global"); - virCommandAddArgFormat(cmd, "isa-fdc.%s", backendStr); - } + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV) && + qemuDomainDiskGetBackendAlias(disk, qemuCaps, &backendAlias) <= 0) + return -1; - if (bootindexStr) { - virCommandAddArg(cmd, "-global"); - virCommandAddArgFormat(cmd, "isa-fdc.%s", bootindexStr); - } + if (disk->info.addr.drive.unit) { + bootindexB =3D disk->info.effectiveBootIndex; + backendB =3D g_steal_pointer(&backendAlias); } else { - virBufferStrcat(&fdc_opts, backendStr, ",", NULL); - virBufferStrcat(&fdc_opts, bootindexStr, ",", NULL); + bootindexA =3D disk->info.effectiveBootIndex; + backendA =3D g_steal_pointer(&backendAlias); } } - if (explicitfdc && hasfloppy) { - /* Newer Q35 machine types require an explicit FDC controller */ - virBufferTrim(&fdc_opts, ","); - virCommandAddArg(cmd, "-device"); - virCommandAddArgBuffer(cmd, &fdc_opts); + if (!hasfloppy) + return 0; + + if (qemuDomainNeedsFDC(def)) { + qemuBuildFloppyCommandLineControllerOptionsExplicit(cmd, + bootindexA, + bootindexB, + backendA, + backendB); + } else { + qemuBuildFloppyCommandLineControllerOptionsImplicit(cmd, + bootindexA, + bootindexB, + backendA, + backendB); } return 0; --=20 2.31.1