From nobody Thu May 15 06:28:08 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 151134825521595.48885959499364; Wed, 22 Nov 2017 02:57:35 -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 970EE49036; Wed, 22 Nov 2017 10:57:33 +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 76603614D0; Wed, 22 Nov 2017 10:57:33 +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 436F94A469; Wed, 22 Nov 2017 10:57:33 +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 vAMAvNub013027 for ; Wed, 22 Nov 2017 05:57:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3587F5D971; Wed, 22 Nov 2017 10:57:23 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8734E5D970; Wed, 22 Nov 2017 10:57:22 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 22 Nov 2017 11:56:45 +0100 Message-Id: <28b3b19307f5405bebd34c00366fd24c41389f5d.1511348086.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 02/11] qemu: domain: Despaghetify qemuDomainDeviceDefValidate 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.38]); Wed, 22 Nov 2017 10:57:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move network device validation into a separate function. --- src/qemu/qemu_domain.c | 158 ++++++++++++++++++++++++++-------------------= ---- 1 file changed, 84 insertions(+), 74 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index cc7596bad1..3755a23907 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3589,101 +3589,111 @@ qemuDomainWatchdogDefValidate(const virDomainWatc= hdogDef *dev, static int -qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, - const virDomainDef *def, - void *opaque ATTRIBUTE_UNUSED) +qemuDomainDeviceDefValidateNetwork(const virDomainNetDef *net) { - int ret =3D -1; + bool hasIPv4 =3D false; + bool hasIPv6 =3D false; size_t i; - if (dev->type =3D=3D VIR_DOMAIN_DEVICE_NET) { - const virDomainNetDef *net =3D dev->data.net; - bool hasIPv4 =3D false, hasIPv6 =3D false; + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_USER) { + if (net->guestIP.nroutes) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Invalid attempt to set network interface " + "guest-side IP route, not supported by QEMU")= ); + return -1; + } - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_USER) { - if (net->guestIP.nroutes) { + for (i =3D 0; i < net->guestIP.nips; i++) { + const virNetDevIPAddr *ip =3D net->guestIP.ips[i]; + + if (VIR_SOCKET_ADDR_VALID(&net->guestIP.ips[i]->peer)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Invalid attempt to set network interface= " - "guest-side IP route, not supported by QE= MU")); - goto cleanup; + _("Invalid attempt to set peer IP for guest= ")); + return -1; } - for (i =3D 0; i < net->guestIP.nips; i++) { - const virNetDevIPAddr *ip =3D net->guestIP.ips[i]; - - if (VIR_SOCKET_ADDR_VALID(&net->guestIP.ips[i]->peer)) { + if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) { + if (hasIPv4) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Invalid attempt to set peer IP for g= uest")); - goto cleanup; + _("Only one IPv4 address per " + "interface is allowed")); + return -1; } + hasIPv4 =3D true; - if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) { - if (hasIPv4) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Only one IPv4 address per " - "interface is allowed")); - goto cleanup; - } - hasIPv4 =3D true; - - if (ip->prefix > 27) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("prefix too long")); - goto cleanup; - } + if (ip->prefix > 27) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("prefix too long")); + return -1; } + } - if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6)) { - if (hasIPv6) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Only one IPv6 address per " - "interface is allowed")); - goto cleanup; - } - hasIPv6 =3D true; + if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6)) { + if (hasIPv6) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Only one IPv6 address per " + "interface is allowed")); + return -1; + } + hasIPv6 =3D true; - if (ip->prefix > 120) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("prefix too long")); - goto cleanup; - } + if (ip->prefix > 120) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("prefix too long")); + return -1; } } - } else if (net->guestIP.nroutes || net->guestIP.nips) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Invalid attempt to set network interface " - "guest-side IP route and/or address info, " - "not supported by QEMU")); - goto cleanup; } + } else if (net->guestIP.nroutes || net->guestIP.nips) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Invalid attempt to set network interface " + "guest-side IP route and/or address info, " + "not supported by QEMU")); + return -1; + } - if (STREQ_NULLABLE(net->model, "virtio")) { - if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_= queue_size - 1)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("rx_queue_size has to be a power of two")= ); - goto cleanup; - } - if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_= queue_size - 1)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("tx_queue_size has to be a power of two")= ); - goto cleanup; - } + if (STREQ_NULLABLE(net->model, "virtio")) { + 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")); + return -1; } - - if (net->mtu && - !qemuDomainNetSupportsMTU(net->type)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("setting MTU on interface type %s is not supp= orted yet"), - virDomainNetTypeToString(net->type)); - goto cleanup; + if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_queu= e_size - 1)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("tx_queue_size has to be a power of two")); + return -1; } + } - if (net->coalesce && !qemuDomainNetSupportsCoalesce(net->type)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("coalesce settings on interface type %s are n= ot supported"), - virDomainNetTypeToString(net->type)); + if (net->mtu && + !qemuDomainNetSupportsMTU(net->type)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("setting MTU on interface type %s is not supporte= d yet"), + virDomainNetTypeToString(net->type)); + return -1; + } + + if (net->coalesce && !qemuDomainNetSupportsCoalesce(net->type)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("coalesce settings on interface type %s are not s= upported"), + virDomainNetTypeToString(net->type)); + return -1; + } + + return 0; +} + + +static int +qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, + const virDomainDef *def, + void *opaque ATTRIBUTE_UNUSED) +{ + int ret =3D -1; + + if (dev->type =3D=3D VIR_DOMAIN_DEVICE_NET) { + if (qemuDomainDeviceDefValidateNetwork(dev->data.net) < 0) goto cleanup; - } } else if (dev->type =3D=3D VIR_DOMAIN_DEVICE_CHR) { if (qemuDomainChrDefValidate(dev->data.chr, def) < 0) goto cleanup; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list