From nobody Thu May 15 09:16:34 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 1511869741898246.84710453920593; Tue, 28 Nov 2017 03:49:01 -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 E325913A5D; Tue, 28 Nov 2017 11:49:00 +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 BDBF360605; Tue, 28 Nov 2017 11:49:00 +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 6C4F8180212A; Tue, 28 Nov 2017 11:49:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vASBmxSZ008808 for ; Tue, 28 Nov 2017 06:48:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6963A60175; Tue, 28 Nov 2017 11:48:59 +0000 (UTC) Received: from inaba.usersys.redhat.com (ovpn-204-77.brq.redhat.com [10.40.204.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7376D60479 for ; Tue, 28 Nov 2017 11:48:55 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 28 Nov 2017 12:48:00 +0100 Message-Id: <20171128114813.28509-18-abologna@redhat.com> In-Reply-To: <20171128114813.28509-1-abologna@redhat.com> References: <20171128114813.28509-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 17/30] 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.29]); Tue, 28 Nov 2017 11:49:01 +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 | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 718dfb15f..8249c6237 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9222,6 +9222,25 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManage= r, return 0; } =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; +} + + static int qemuBuildChrDeviceCommandLine(virCommandPtr cmd, const virDomainDef *def, @@ -10351,6 +10370,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, return NULL; } =20 + /* This function generates the correct '-device' string for character * devices of each architecture. */ @@ -10361,6 +10381,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 +10398,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 (caps && !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 +10413,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