From nobody Thu May 15 08:42:44 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 1510746632003262.49537480317497; Wed, 15 Nov 2017 03:50:32 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 507E68B125; Wed, 15 Nov 2017 11:50:30 +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 19C0F11E7D5; Wed, 15 Nov 2017 11:50:30 +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 CB8AC1800C87; Wed, 15 Nov 2017 11:50:29 +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 vAFBoRk5022418 for ; Wed, 15 Nov 2017 06:50:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4515A121E50; Wed, 15 Nov 2017 11:50:27 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.219]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB512121F2E for ; Wed, 15 Nov 2017 11:50:26 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Wed, 15 Nov 2017 12:50:05 +0100 Message-Id: <20171115115017.10092-3-abologna@redhat.com> In-Reply-To: <20171115115017.10092-1-abologna@redhat.com> References: <20171115115017.10092-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/14] conf, qemu: Use type-aware switches where possible 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 15 Nov 2017 11:50:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The compiler can warn us if we add a value to the virDomainChrSerialTargetType enumeration but forget to handle it properly in the code. Let's take advantage of that. This commit is best viewed with 'git diff -w'. Signed-off-by: Andrea Bolognani Reviewed-by: Pavel Hrdina --- src/conf/domain_conf.c | 47 ++++++++++++++++++++++++++++++---------------= -- src/qemu/qemu_command.c | 7 ++++++- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 62d0a1683..9da8dd646 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4035,26 +4035,39 @@ virDomainDefAddConsoleCompat(virDomainDefPtr def) def->consoles[0]->targetType =3D VIR_DOMAIN_CHR_CONSOLE_TARGET= _TYPE_SERIAL; } } else if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM && def->nserials = > 0 && - def->serials[0]->deviceType =3D=3D VIR_DOMAIN_CHR_DEVICE_TY= PE_SERIAL && - def->serials[0]->targetType =3D=3D VIR_DOMAIN_CHR_SERIAL_TA= RGET_TYPE_ISA) { - /* Create a stub console to match the serial port. - * console[0] either does not exist - * or has a different type than SERIAL or NONE. - */ - virDomainChrDefPtr chr; - if (!(chr =3D virDomainChrDefNew(NULL))) - return -1; + def->serials[0]->deviceType =3D=3D VIR_DOMAIN_CHR_DEVICE_TY= PE_SERIAL) { =20 - if (VIR_INSERT_ELEMENT(def->consoles, - 0, - def->nconsoles, - chr) < 0) { - virDomainChrDefFree(chr); - return -1; + switch ((virDomainChrSerialTargetType) def->serials[0]->targetType= ) { + case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA: { + + /* Create a stub console to match the serial port. + * console[0] either does not exist + * or has a different type than SERIAL or NONE. + */ + virDomainChrDefPtr chr; + if (!(chr =3D virDomainChrDefNew(NULL))) + return -1; + + if (VIR_INSERT_ELEMENT(def->consoles, + 0, + def->nconsoles, + chr) < 0) { + virDomainChrDefFree(chr); + return -1; + } + + def->consoles[0]->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_CO= NSOLE; + def->consoles[0]->targetType =3D VIR_DOMAIN_CHR_CONSOLE_TARGET= _TYPE_SERIAL; + + break; } =20 - def->consoles[0]->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOL= E; - def->consoles[0]->targetType =3D VIR_DOMAIN_CHR_CONSOLE_TARGET_TYP= E_SERIAL; + case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI: + case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB: + case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST: + /* Nothing to do */ + break; + } } =20 return 0; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 4c05a5f66..010c2992f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10206,7 +10206,7 @@ qemuBuildSerialChrDeviceStr(char **deviceStr, serial->info.alias); } } else { - switch (serial->targetType) { + switch ((virDomainChrSerialTargetType) serial->targetType) { case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB: if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_SERIAL)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -10245,6 +10245,11 @@ qemuBuildSerialChrDeviceStr(char **deviceStr, goto error; } break; + + case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Invalid target type for serial device")); + goto error; } =20 virBufferAsprintf(&cmd, "%s,chardev=3Dchar%s,id=3D%s", --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list