From nobody Thu May 15 08:53:28 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1511735266231154.26727599326443; Sun, 26 Nov 2017 14:27:46 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04798C119CAB; Sun, 26 Nov 2017 22:27:45 +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 C9F01648C1; Sun, 26 Nov 2017 22:27:44 +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 952AC3D399; Sun, 26 Nov 2017 22:27:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vAQMQRPM028401 for ; Sun, 26 Nov 2017 17:26:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id CFC4D18EDA; Sun, 26 Nov 2017 22:26:27 +0000 (UTC) Received: from inaba.usersys.redhat.com (ovpn-204-63.brq.redhat.com [10.40.204.63]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E165760BE9 for ; Sun, 26 Nov 2017 22:26:26 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Sun, 26 Nov 2017 23:25:38 +0100 Message-Id: <20171126222549.13681-18-abologna@redhat.com> In-Reply-To: <20171126222549.13681-1-abologna@redhat.com> References: <20171126222549.13681-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 17/28] qemu: Remove redundancy in qemuBuildSerialChrDeviceStr() 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sun, 26 Nov 2017 22:27:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Instead duplicating the capability check for each possible target model, introduce a small helper that matches the target model with the corresponding capability and collapse all existing checks into a single one. Signed-off-by: Andrea Bolognani Reviewed-by: Pavel Hrdina --- src/qemu/qemu_command.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 718dfb15f..53b0e6841 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10351,6 +10351,25 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, return NULL; } =20 + +static virQEMUCapsFlags +qemuChrSerialTargetModelToCaps(virDomainChrSerialTargetModel targetModel) +{ + switch (targetModel) { + case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL: + return QEMU_CAPS_DEVICE_USB_SERIAL; + case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL: + return QEMU_CAPS_DEVICE_PCI_SERIAL; + case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL: + case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE: + case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST: + break; + } + + return 0; +} + + /* This function generates the correct '-device' string for character * devices of each architecture. */ @@ -10361,6 +10380,7 @@ qemuBuildSerialChrDeviceStr(char **deviceStr, virQEMUCapsPtr qemuCaps) { virBuffer cmd =3D VIR_BUFFER_INITIALIZER; + virQEMUCapsFlags caps; =20 if (qemuDomainIsPSeries(def)) { if (serial->deviceType =3D=3D VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL && @@ -10377,9 +10397,14 @@ qemuBuildSerialChrDeviceStr(char **deviceStr, } else { switch ((virDomainChrSerialTargetModel) serial->targetModel) { case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL: - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_SERIAL)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("usb-serial is not supported in this QEMU= binary")); + case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL: + + caps =3D qemuChrSerialTargetModelToCaps(serial->targetModel); + + if (!virQEMUCapsGet(qemuCaps, caps)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("'%s' is not supported in this QEMU binar= y"), + virDomainChrSerialTargetModelTypeToString(s= erial->targetModel)); goto error; } break; @@ -10387,14 +10412,6 @@ qemuBuildSerialChrDeviceStr(char **deviceStr, case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL: break; =20 - case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL: - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PCI_SERIAL)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("pci-serial is not supported with this QE= MU binary")); - goto error; - } - break; - case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE: case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST: /* Except from _LAST, which is just a guard value and will nev= er --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list