From nobody Sun Feb 8 19:57:11 2026 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 1547747593913330.6229863984612; Thu, 17 Jan 2019 09:53:13 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E5A5C0C4268; Thu, 17 Jan 2019 17:53:11 +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 3C31F5C5BB; Thu, 17 Jan 2019 17:53:11 +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 C8E8B1803391; Thu, 17 Jan 2019 17:53:10 +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 x0HHrAlA005494 for ; Thu, 17 Jan 2019 12:53:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 44D36600C9; Thu, 17 Jan 2019 17:53:10 +0000 (UTC) Received: from worklaptop.redhat.com (ovpn-122-144.rdu2.redhat.com [10.10.122.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8AD1600C6; Thu, 17 Jan 2019 17:53:09 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Thu, 17 Jan 2019 12:52:31 -0500 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/18] conf: Add virDomainNetHasVirtioModel 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: , 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 17 Jan 2019 17:53:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This will be extended in the future, so let's simplify things by centralizing the checks. Signed-off-by: Cole Robinson --- src/conf/domain_conf.c | 47 +++++++++++++++++++--------------- src/conf/domain_conf.h | 1 + src/libvirt_private.syms | 1 + src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_domain_address.c | 3 +-- src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_interface.c | 8 +++--- src/security/virt-aa-helper.c | 2 +- tests/qemuxml2argvmock.c | 2 +- 9 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index facb84a425..4fc33c7e2f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4737,7 +4737,7 @@ virDomainDeviceDefPostParseCommon(virDomainDeviceDefP= tr dev, =20 if (dev->type =3D=3D VIR_DOMAIN_DEVICE_NET) { virDomainNetDefPtr net =3D dev->data.net; - if (STRNEQ_NULLABLE(net->model, "virtio") && + if (!virDomainNetHasVirtioModel(net) && virDomainCheckVirtioOptions(net->virtio) < 0) return -1; } @@ -11329,6 +11329,22 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlo= pt, goto error; } =20 + /* NIC model (see -net nic,model=3D?). We only check that it looks + * reasonable, not that it is a supported NIC type. FWIW kvm + * supports these types as of April 2008: + * i82551 i82557b i82559er ne2k_pci pcnet rtl8139 e1000 virtio + * QEMU PPC64 supports spapr-vlan + */ + if (model !=3D NULL) { + if (strspn(model, NET_MODEL_CHARS) < strlen(model)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Model name contains invalid characters")); + goto error; + } + def->model =3D model; + model =3D NULL; + } + switch (def->type) { case VIR_DOMAIN_NET_TYPE_NETWORK: if (network =3D=3D NULL) { @@ -11346,7 +11362,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, break; =20 case VIR_DOMAIN_NET_TYPE_VHOSTUSER: - if (STRNEQ_NULLABLE(model, "virtio")) { + if (!virDomainNetHasVirtioModel(def)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Wrong or no 'type' attribute " "specified with . " @@ -11574,24 +11590,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlo= pt, ifname_guest_actual =3D NULL; } =20 - /* NIC model (see -net nic,model=3D?). We only check that it looks - * reasonable, not that it is a supported NIC type. FWIW kvm - * supports these types as of April 2008: - * i82551 i82557b i82559er ne2k_pci pcnet rtl8139 e1000 virtio - * QEMU PPC64 supports spapr-vlan - */ - if (model !=3D NULL) { - if (strspn(model, NET_MODEL_CHARS) < strlen(model)) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("Model name contains invalid characters")); - goto error; - } - def->model =3D model; - model =3D NULL; - } - if (def->type !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV && - STREQ_NULLABLE(def->model, "virtio")) { + virDomainNetHasVirtioModel(def)) { if (backend !=3D NULL) { if ((val =3D virDomainNetBackendTypeFromString(backend)) < 0 || val =3D=3D VIR_DOMAIN_NET_BACKEND_TYPE_DEFAULT) { @@ -25478,7 +25478,7 @@ virDomainNetDefFormat(virBufferPtr buf, if (def->model) { virBufferEscapeString(buf, "\n", def->model); - if (STREQ(def->model, "virtio")) { + if (virDomainNetHasVirtioModel(def)) { char *str =3D NULL, *gueststr =3D NULL, *hoststr =3D NULL; int rc =3D 0; =20 @@ -29732,6 +29732,13 @@ virDomainNetGetActualTrustGuestRxFilters(virDomain= NetDefPtr iface) } =20 =20 +bool +virDomainNetHasVirtioModel(const virDomainNetDef *iface) +{ + return STREQ_NULLABLE(iface->model, "virtio"); +} + + /* Return listens[i] from the appropriate union for the graphics * type, or NULL if this is an unsuitable type, or the index is out of * bounds. If force0 is TRUE, i =3D=3D 0, and there is no listen array, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 16c2c6e75b..e3f4273b55 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3222,6 +3222,7 @@ virNetDevBandwidthPtr virDomainNetGetActualBandwidth(virDomainNetDefPtr iface); virNetDevVlanPtr virDomainNetGetActualVlan(virDomainNetDefPtr iface); bool virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface); +bool virDomainNetHasVirtioModel(const virDomainNetDef *iface); int virDomainNetAppendIPAddress(virDomainNetDefPtr def, const char *address, int family, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0d6f054cf2..bd7e896654 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -470,6 +470,7 @@ virDomainNetGetActualTrustGuestRxFilters; virDomainNetGetActualType; virDomainNetGetActualVirtPortProfile; virDomainNetGetActualVlan; +virDomainNetHasVirtioModel; virDomainNetInsert; virDomainNetNotifyActualDevice; virDomainNetReleaseActualDevice; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ec6b340308..08bb2f9ebc 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4573,7 +4573,7 @@ qemuDomainDeviceDefValidateNetwork(const virDomainNet= Def *net) return -1; } =20 - if (STREQ_NULLABLE(net->model, "virtio")) { + if (virDomainNetHasVirtioModel(net)) { if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queu= e_size - 1)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("rx_queue_size has to be a power of two")); diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 4a7c71d76d..0950197a44 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -322,8 +322,7 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr de= f, for (i =3D 0; i < def->nnets; i++) { virDomainNetDefPtr net =3D def->nets[i]; =20 - if (net->model && - STREQ(net->model, "virtio") && + if (virDomainNetHasVirtioModel(net) && net->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { net->info.type =3D type; } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index a1c3ca999b..2fdc71d07b 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3710,7 +3710,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, goto cleanup; } =20 - if (olddev->model && STREQ(olddev->model, "virtio") && + if (virDomainNetHasVirtioModel(olddev) && (olddev->driver.virtio.name !=3D newdev->driver.virtio.name || olddev->driver.virtio.txmode !=3D newdev->driver.virtio.txmode || olddev->driver.virtio.ioeventfd !=3D newdev->driver.virtio.ioeven= tfd || diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index 2607dea1f5..2cbb382b10 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -261,7 +261,7 @@ qemuInterfaceDirectConnect(virDomainDefPtr def, virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); unsigned int macvlan_create_flags =3D VIR_NETDEV_MACVLAN_CREATE_WITH_T= AP; =20 - if (net->model && STREQ(net->model, "virtio")) + if (virDomainNetHasVirtioModel(net)) macvlan_create_flags |=3D VIR_NETDEV_MACVLAN_VNET_HDR; =20 if (virNetDevMacVLanCreateWithVPortProfile(net->ifname, @@ -434,7 +434,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, template_ifname =3D true; } =20 - if (net->model && STREQ(net->model, "virtio")) + if (virDomainNetHasVirtioModel(net)) tap_create_flags |=3D VIR_NETDEV_TAP_CREATE_VNET_HDR; =20 if (virNetDevTapCreate(&net->ifname, tunpath, tapfd, tapfdSize, @@ -533,7 +533,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def, template_ifname =3D true; } =20 - if (net->model && STREQ(net->model, "virtio")) + if (virDomainNetHasVirtioModel(net)) tap_create_flags |=3D VIR_NETDEV_TAP_CREATE_VNET_HDR; =20 if (virQEMUDriverIsPrivileged(driver)) { @@ -653,7 +653,7 @@ qemuInterfaceOpenVhostNet(virDomainDefPtr def, } =20 /* If the nic model isn't virtio, don't try to open. */ - if (!(net->model && STREQ(net->model, "virtio"))) { + if (!virDomainNetHasVirtioModel(net)) { if (net->driver.virtio.name =3D=3D VIR_DOMAIN_NET_BACKEND_TYPE_VHO= ST) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("vhost-net is only supported for " diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 64a425671d..3bd30bb417 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1241,7 +1241,7 @@ get_files(vahControl * ctl) if (net && net->model) { if (net->driver.virtio.name =3D=3D VIR_DOMAIN_NET_BACKEND_= TYPE_QEMU) continue; - if (STRNEQ(net->model, "virtio")) + if (!virDomainNetHasVirtioModel(net)) continue; } needsvhost =3D true; diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index b300793732..729e8146b1 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -228,7 +228,7 @@ qemuInterfaceOpenVhostNet(virDomainDefPtr def ATTRIBUTE= _UNUSED, { size_t i; =20 - if (!(net->model && STREQ(net->model, "virtio"))) { + if (!virDomainNetHasVirtioModel(net)) { *vhostfdSize =3D 0; return 0; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list