From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848927; cv=none; d=zoho.com; s=zohoarc; b=S9wEkmNJdf4IF7Ng7rny1MzSSoP8qvc92cJMznp2H/DhaW3ZR/NbPERboG4KLFIBPnyOId5NyQnmkyj/EhehWLArlRBrJq0f/4NvgFMruLubH9djza4M2Y9xfKMEc02r/zuthGFXHR67EBNaGslXoU4h+hGy2ty+hnk1SjPaSO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848927; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=B3MK90//GpxFC5ZyPmkjoT0/AIn1mpHkK2htW6/KHLU=; b=cswooyD8W/BLZFURK8usb4zmEDckeF2RVFUMXZnrAlKi+g50RBi2B2yTjeDmB1XKibbf5zGBUwW9nIvnZ30q15f77k3KSyqiTL4vkJ6y9lYIexbBPMTpRdfi71QF+daLchphHASmH4TMOwipYzaD7Mwzj8Ae8jHr4wpM2HevHpw= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155784892771839.67466922507219; Tue, 14 May 2019 08:48:47 -0700 (PDT) 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 B857E5277B; Tue, 14 May 2019 15:48:45 +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 91E1E608A6; Tue, 14 May 2019 15:48:45 +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 DF1D518089D3; Tue, 14 May 2019 15:48:43 +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 x4EFmeHK031719 for ; Tue, 14 May 2019 11:48:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id C82BF600CD; Tue, 14 May 2019 15:48:40 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FFD2600C5; Tue, 14 May 2019 15:48:39 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:13 +0100 Message-Id: <20190514154836.6427-2-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 01/24] conf: allow bandwidth parsing / formatting to include class ID 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-Type: text/plain; charset="utf-8" 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, 14 May 2019 15:48:46 +0000 (UTC) The domain conf actual network def stores a element separately from the . The class ID should really just be an attribute on the element. We can't change existing XML, and this isn't visible to users since it is internal XML only. When we expose the new network port XML to users though, we should get the design right. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/conf/domain_conf.c | 6 ++++-- src/conf/netdev_bandwidth_conf.c | 30 ++++++++++++++++++++++++++++-- src/conf/netdev_bandwidth_conf.h | 2 ++ src/conf/network_conf.c | 8 ++++---- tests/virnetdevbandwidthtest.c | 1 + 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a3a514136b..011d789feb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11270,6 +11270,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node, bandwidth_node =3D virXPathNode("./bandwidth", ctxt); if (bandwidth_node && virNetDevBandwidthParse(&actual->bandwidth, + NULL, bandwidth_node, actual->type =3D=3D VIR_DOMAIN_NET_TYPE_NE= TWORK) < 0) goto error; @@ -11609,6 +11610,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, } } else if (virXMLNodeNameEqual(cur, "bandwidth")) { if (virNetDevBandwidthParse(&def->bandwidth, + NULL, cur, def->type =3D=3D VIR_DOMAIN_NE= T_TYPE_NETWORK) < 0) goto error; @@ -25006,7 +25008,7 @@ virDomainActualNetDefContentsFormat(virBufferPtr bu= f, return -1; if (virNetDevVPortProfileFormat(virDomainNetGetActualVirtPortProfile(d= ef), buf) < 0) return -1; - if (virNetDevBandwidthFormat(virDomainNetGetActualBandwidth(def), buf)= < 0) + if (virNetDevBandwidthFormat(virDomainNetGetActualBandwidth(def), 0, b= uf) < 0) return -1; return 0; } @@ -25383,7 +25385,7 @@ virDomainNetDefFormat(virBufferPtr buf, return -1; if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0) return -1; - if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0) + if (virNetDevBandwidthFormat(def->bandwidth, 0, buf) < 0) return -1; =20 /* ONLY for internal status storage - format the ActualNetDef diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_c= onf.c index 014941836d..9af2173b7b 100644 --- a/src/conf/netdev_bandwidth_conf.c +++ b/src/conf/netdev_bandwidth_conf.c @@ -99,6 +99,7 @@ virNetDevBandwidthParseRate(xmlNodePtr node, virNetDevBan= dwidthRatePtr rate) /** * virNetDevBandwidthParse: * @bandwidth: parsed bandwidth + * @class_id: parsed class ID * @node: XML node * @allowFloor: whether "floor" setting is supported * @@ -110,6 +111,7 @@ virNetDevBandwidthParseRate(xmlNodePtr node, virNetDevB= andwidthRatePtr rate) */ int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth, + unsigned int *class_id, xmlNodePtr node, bool allowFloor) { @@ -117,6 +119,7 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidt= h, virNetDevBandwidthPtr def =3D NULL; xmlNodePtr cur; xmlNodePtr in =3D NULL, out =3D NULL; + char *class_id_prop =3D NULL; =20 if (VIR_ALLOC(def) < 0) return ret; @@ -127,6 +130,22 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwid= th, goto cleanup; } =20 + class_id_prop =3D virXMLPropString(node, "classID"); + if (class_id_prop) { + if (!class_id) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("classID attribute not supported on " + "in this usage context")); + goto cleanup; + } + if (virStrToLong_ui(class_id_prop, NULL, 10, class_id) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse class id '%s'"), + class_id_prop); + goto cleanup; + } + } + cur =3D node->children; =20 while (cur) { @@ -194,6 +213,7 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidt= h, ret =3D 0; =20 cleanup: + VIR_FREE(class_id_prop); virNetDevBandwidthFree(def); return ret; } @@ -231,6 +251,7 @@ virNetDevBandwidthRateFormat(virNetDevBandwidthRatePtr = def, /** * virNetDevBandwidthFormat: * @def: Data source + * @class_id: the class ID to format, 0 to skip * @buf: Buffer to print to * * Formats bandwidth and prepend each line with @indent. @@ -239,7 +260,9 @@ virNetDevBandwidthRateFormat(virNetDevBandwidthRatePtr = def, * Returns 0 on success, else -1. */ int -virNetDevBandwidthFormat(virNetDevBandwidthPtr def, virBufferPtr buf) +virNetDevBandwidthFormat(virNetDevBandwidthPtr def, + unsigned int class_id, + virBufferPtr buf) { int ret =3D -1; =20 @@ -251,7 +274,10 @@ virNetDevBandwidthFormat(virNetDevBandwidthPtr def, vi= rBufferPtr buf) goto cleanup; } =20 - virBufferAddLit(buf, "\n"); + virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); if (virNetDevBandwidthRateFormat(def->in, buf, "inbound") < 0 || virNetDevBandwidthRateFormat(def->out, buf, "outbound") < 0) diff --git a/src/conf/netdev_bandwidth_conf.h b/src/conf/netdev_bandwidth_c= onf.h index 7fe750ce27..b91222321a 100644 --- a/src/conf/netdev_bandwidth_conf.h +++ b/src/conf/netdev_bandwidth_conf.h @@ -26,10 +26,12 @@ # include "domain_conf.h" =20 int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth, + unsigned int *class_id, xmlNodePtr node, bool allowFloor) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; int virNetDevBandwidthFormat(virNetDevBandwidthPtr def, + unsigned int class_id, virBufferPtr buf); =20 void virDomainClearNetBandwidth(virDomainObjPtr vm) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 91562de269..09e379ae9a 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1188,7 +1188,7 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def, =20 bandwidth_node =3D virXPathNode("./bandwidth", ctxt); if (bandwidth_node && - virNetDevBandwidthParse(&def->bandwidth, bandwidth_node, false) < = 0) + virNetDevBandwidthParse(&def->bandwidth, NULL, bandwidth_node, fal= se) < 0) goto cleanup; =20 vlanNode =3D virXPathNode("./vlan", ctxt); @@ -1682,7 +1682,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) } =20 if ((bandwidthNode =3D virXPathNode("./bandwidth", ctxt)) && - virNetDevBandwidthParse(&def->bandwidth, bandwidthNode, false) < 0) + virNetDevBandwidthParse(&def->bandwidth, NULL, bandwidthNode, fals= e) < 0) goto error; =20 vlanNode =3D virXPathNode("./vlan", ctxt); @@ -2311,7 +2311,7 @@ virPortGroupDefFormat(virBufferPtr buf, return -1; if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0) return -1; - virNetDevBandwidthFormat(def->bandwidth, buf); + virNetDevBandwidthFormat(def->bandwidth, 0, buf); virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); return 0; @@ -2566,7 +2566,7 @@ virNetworkDefFormatBuf(virBufferPtr buf, =20 if (virNetDevVlanFormat(&def->vlan, buf) < 0) goto error; - if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0) + if (virNetDevBandwidthFormat(def->bandwidth, 0, buf) < 0) goto error; =20 for (i =3D 0; i < def->nips; i++) { diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c index 23788b4164..2c0b6a6713 100644 --- a/tests/virnetdevbandwidthtest.c +++ b/tests/virnetdevbandwidthtest.c @@ -54,6 +54,7 @@ struct testSetStruct { goto cleanup; \ \ rc =3D virNetDevBandwidthParse(&(var), \ + NULL, \ ctxt->node, \ true); \ xmlFreeDoc(doc); \ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848935; cv=none; d=zoho.com; s=zohoarc; b=oYvkBhnsU/KYeKXA2LfEw7/nJmCPmh4mnzLDKYqXuNiq9qs2a/1z+t+FqSFEzTRsK88WKE/xfOrKfmSBzc9UrRJHjoWy/FhJCEWjMgM8OYms/DBYxI0ON8aD0fNfSLUaAHx44MNLG7CeT8cUedNe/y5Vhjgc7DxyTJiSlsimkBI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848935; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=e42ZdY/IVOmV0GmCp131jyEmBZTGlkzZHTWAbSeN8Tc=; b=hLno3Mmldn36Vh7yjB4l0If1hOBWpu8gyniSEl9HLsexBbLEpMgZ8leXhF/7HB4CYffAHWAY57MtPLpBFPPL5vai13kUHfiliBLTfW3xPyJXC45AywKEryEdoRDo9AvY6kbITTRkwnZoCTlFW/wiMR0TXgu+XfmI9eudRESbvjI= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848935180479.85408222037177; Tue, 14 May 2019 08:48:55 -0700 (PDT) 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 40B7059479; Tue, 14 May 2019 15:48:53 +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 E44135D730; Tue, 14 May 2019 15:48:52 +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 84CDF3FB10; Tue, 14 May 2019 15:48:52 +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 x4EFmhwB031732 for ; Tue, 14 May 2019 11:48:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id C6B912B9E3; Tue, 14 May 2019 15:48:43 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0FE363B86; Tue, 14 May 2019 15:48:40 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:14 +0100 Message-Id: <20190514154836.6427-3-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 02/24] conf: introduce virNetworkPortDefPtr struct and XML support 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-Type: text/plain; charset="utf-8" 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.39]); Tue, 14 May 2019 15:48:53 +0000 (UTC) Introduce a virNetworkPortDefPtr struct to represent the data associated with a virtual network port. Add APIs for parsing/formatting XML docs with the data. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- docs/docs.html.in | 1 + docs/formatnetworkport.html.in | 212 ++++++++ docs/schemas/networkport.rng | 165 ++++++ src/conf/Makefile.inc.am | 2 + src/conf/virnetworkportdef.c | 509 ++++++++++++++++++ src/conf/virnetworkportdef.h | 113 ++++ src/libvirt_private.syms | 10 + tests/Makefile.am | 7 + .../plug-bridge-mactbl.xml | 9 + .../virnetworkportxml2xmldata/plug-bridge.xml | 15 + .../virnetworkportxml2xmldata/plug-direct.xml | 12 + .../plug-hostdev-pci.xml | 12 + .../plug-network.xml | 16 + tests/virnetworkportxml2xmldata/plug-none.xml | 8 + tests/virnetworkportxml2xmltest.c | 104 ++++ tests/virschematest.c | 1 + 16 files changed, 1196 insertions(+) create mode 100644 docs/formatnetworkport.html.in create mode 100644 docs/schemas/networkport.rng create mode 100644 src/conf/virnetworkportdef.c create mode 100644 src/conf/virnetworkportdef.h create mode 100644 tests/virnetworkportxml2xmldata/plug-bridge-mactbl.xml create mode 100644 tests/virnetworkportxml2xmldata/plug-bridge.xml create mode 100644 tests/virnetworkportxml2xmldata/plug-direct.xml create mode 100644 tests/virnetworkportxml2xmldata/plug-hostdev-pci.xml create mode 100644 tests/virnetworkportxml2xmldata/plug-network.xml create mode 100644 tests/virnetworkportxml2xmldata/plug-none.xml create mode 100644 tests/virnetworkportxml2xmltest.c diff --git a/docs/docs.html.in b/docs/docs.html.in index d0ff844d0c..c8674e1457 100644 --- a/docs/docs.html.in +++ b/docs/docs.html.in @@ -72,6 +72,7 @@
Description of the XML schemas for domains, networks, + network ports, network filtering, storage, storage encryption, diff --git a/docs/formatnetworkport.html.in b/docs/formatnetworkport.html.in new file mode 100644 index 0000000000..0211518a6a --- /dev/null +++ b/docs/formatnetworkport.html.in @@ -0,0 +1,212 @@ + + + + +

Network XML format

+ +
    +
+ +

+ This page provides an introduction to the network port XML format. + This stores information about the connection between an virtual + interface on a virtual domain's, and the virtual network it is + attached to. +

+ +

Element and attribute overview

+ +

+ The root element required for all virtual network ports is + named networkport and has no configurable attributes + The network port XML format is available since + 5.4.0 +

+ +

General metadata

+ +

+ The first elements provide basic metadata about the virtual + network port. +

+ +
+<networkport
+  <uuid>7ae63b5f-fe96-4af0-a7c3-da04ba1b3f54</uuid>
+  <owner>
+    <uuid>06578fc1-c686-46fa-bc2c-220893b466a6</uuid>
+    <name>myguest<name>
+  </owner>
+  <group>webfront<group>
+  <mac address=3D'52:54:0:7b:35:93'/>
+  ...
+ +
+
uuid
+
The content of the uuid element provides + a globally unique identifier for the virtual network port. + The format must be RFC 4122 compliant, eg 3e3fce45-4f53-4fa7= -bb32-11f34168b82b. + If omitted when defining/creating a new network port, a random + UUID is generated.
+
The owner node records the domain object that + is the owner of the network port. It contains two child nodes: +
+
uuid
+
The content of the uuid element provides + a globally unique identifier for the virtual domain.
+
name
+
The unique name of the virtual domain
+
+
+
group
+
The port group in the virtual network to which the + port belongs. Can be omitted if no port groups are + defined on the network.
+
mac
+
The address attribute provides the MAC + address of the virtual port that will be see by the + guest. The MAC address must not start with 0xFE as this + byte is reserved for use on the host side of the port. +
+
+ +

Common elements

+ +

+ The following elements are common to one of more of the plug + types listed later +

+ +
+  ...
+  <bandwidth>
+    <inbound average=3D'1000' peak=3D'5000' floor=3D'200' burst=3D'1024=
'/>
+    <outbound average=3D'128' peak=3D'256' burst=3D'256'/>
+  </bandwidth>
+  <rxfilters trustGuest=3D'yes'/>
+  <virtualport type=3D'802.1Qbg'>
+    <parameters managerid=3D'11' typeid=3D'1193047' typeidversion=3D'2'=
/>
+  </virtualport>
+  ...
+ +
+
bandwidth
+
This part of the network port XML provides setting quality of se= rvice. + Incoming and outgoing traffic can be shaped independently. + The bandwidth element and its child elements are desc= ribed + in the QoS section of + the Network XML. In addition the classID attribute may + exist provide the ID of the traffic shaping class that is active. +
+
rxfilters
+
The rxfilters element property + trustGuestRxFilters provides the + capability for the host to detect and trust reports from the + guest regarding changes to the interface mac address and receive + filters by setting the attribute to yes. The default + setting for the attribute is no for security + reasons and support depends on the guest network device model as + well as the type of connection on the host - currently it is + only supported for the virtio device model and for macvtap + connections on the host. +
+
virtualport
+
The virtualport element describes metadata that + needs to be provided to the underlying network subsystem. It + is described in the domain XML + interface documentation= . +
+
+ + +

Plugs

+ +

+ The plug element has varying content depending + on the value of the type attribute. +

+ +

Network

+ +

+ The network plug type refers to a managed virtual + network plug that is based on a traditional software bridge + device privately managed by libvirt. +

+ +
+  ...
+  <plug type=3D'network' bridge=3D'virbr0'>
+  ...
+ +

+ The bridge attribute provides the name of the + privately managed bridge device associated with the virtual + network. +

+ +

Bridge

+ +

+ The bridge plug type refers to an externally + managed traditional software bridge. +

+ +
+  ...
+  <plug type=3D'bridge' bridge=3D'br2'>
+  ...
+ +

+ The bridge attribute provides the name of the + externally managed bridge device associated with the virtual + network. +

+ +

Direct

+ +

+ The direct plug type refers to an connection + directly to a physical network interface. +

+ +
+  ...
+  <plug type=3D'direct' dev=3D'ens3' mode=3D'vepa'/>
+  ...
+ +

+ The dev attribute provides the name of the + physical network interface to which the port will be + connected. The mode attribute describes + how the connection will be setup and takes the same + values described in the + domain XML. +

+ +

Host PCI

+ +

+ The hostdev-pci plug type refers to the + passthrough of a physical PCI device rather than emulation. +

+ +
+  ...
+  <plug type=3D'hostdev-pci' managed=3D'yes'>
+    <driver name=3D'vfio'/>
+    <address domain=3D'0x0001' bus=3D'0x02' slot=3D'0x03' function=3D'0=
x4'/>
+  </plug>
+  ...
+ +

+ The managed attribute indicates who is responsible for + managing the PCI device in the host. When set to the value yes= + libvirt is responsible for automatically detaching the device from h= ost + drivers and resetting it if needed. If the value is no, + some other party must ensure the device is not attached to any + host drivers. +

+ + + diff --git a/docs/schemas/networkport.rng b/docs/schemas/networkport.rng new file mode 100644 index 0000000000..8192f6efc4 --- /dev/null +++ b/docs/schemas/networkport.rng @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + network + + + + + + + + + + + + + + bridge + + + + + + + + + + + + + + direct + + + + + + + bridge + passthrough + private + vepa + + + + + + + hostdev-pci + + + + + + + + + + + kvm + vfio + + + + + + + + + + + diff --git a/src/conf/Makefile.inc.am b/src/conf/Makefile.inc.am index 3e9fdd1aea..6b52ba674b 100644 --- a/src/conf/Makefile.inc.am +++ b/src/conf/Makefile.inc.am @@ -7,6 +7,8 @@ NETDEV_CONF_SOURCES =3D \ conf/netdev_vport_profile_conf.c \ conf/netdev_vlan_conf.h \ conf/netdev_vlan_conf.c \ + conf/virnetworkportdef.h \ + conf/virnetworkportdef.c \ $(NULL) =20 DOMAIN_CONF_SOURCES =3D \ diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c new file mode 100644 index 0000000000..6c896968ce --- /dev/null +++ b/src/conf/virnetworkportdef.c @@ -0,0 +1,509 @@ +/* + * virnetworkportdef.c: network port XML processing + * + * Copyright (C) 2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "viralloc.h" +#include "virerror.h" +#include "virstring.h" +#include "virfile.h" +#include "virnetworkportdef.h" +#include "network_conf.h" + +#define VIR_FROM_THIS VIR_FROM_NETWORK + +VIR_ENUM_IMPL(virNetworkPortPlug, + VIR_NETWORK_PORT_PLUG_TYPE_LAST, + "none", "network", "bridge", "direct", "hostdev-pci"); + +void +virNetworkPortDefFree(virNetworkPortDefPtr def) +{ + if (!def) + return; + + VIR_FREE(def->ownername); + VIR_FREE(def->group); + + virNetDevBandwidthFree(def->bandwidth); + virNetDevVlanClear(&def->vlan); + VIR_FREE(def->virtPortProfile); + + switch ((virNetworkPortPlugType)def->plugtype) { + case VIR_NETWORK_PORT_PLUG_TYPE_NONE: + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK: + case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE: + VIR_FREE(def->plug.bridge.brname); + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT: + VIR_FREE(def->plug.direct.linkdev); + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_LAST: + default: + break; + } + + VIR_FREE(def); +} + + + +static virNetworkPortDefPtr +virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) +{ + virNetworkPortDefPtr def; + char *uuid =3D NULL; + xmlNodePtr virtPortNode; + xmlNodePtr vlanNode; + xmlNodePtr bandwidthNode; + xmlNodePtr addressNode; + char *trustGuestRxFilters =3D NULL; + char *mac =3D NULL; + char *macmgr =3D NULL; + char *mode =3D NULL; + char *plugtype =3D NULL; + char *managed =3D NULL; + char *driver =3D NULL; + char *class_id =3D NULL; + + if (VIR_ALLOC(def) < 0) + return NULL; + + uuid =3D virXPathString("string(./uuid)", ctxt); + if (!uuid) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("network port has no uuid")); + goto error; + } + if (virUUIDParse(uuid, def->uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse UUID '%s'"), uuid); + goto error; + } + + def->ownername =3D virXPathString("string(./owner/name)", ctxt); + if (!def->ownername) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("network port has no owner name")); + goto error; + } + + VIR_FREE(uuid); + uuid =3D virXPathString("string(./owner/uuid)", ctxt); + if (!uuid) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("network port has no owner UUID")); + goto error; + } + + if (virUUIDParse(uuid, def->owneruuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse UUID '%s'"), uuid); + goto error; + } + + def->group =3D virXPathString("string(./group)", ctxt); + + virtPortNode =3D virXPathNode("./virtualport", ctxt); + if (virtPortNode && + (!(def->virtPortProfile =3D virNetDevVPortProfileParse(virtPortNod= e, 0)))) { + goto error; + } + + mac =3D virXPathString("string(./mac/@address)", ctxt); + if (!mac) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("network port has no mac")); + goto error; + } + if (virMacAddrParse(mac, &def->mac) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse MAC '%s'"), mac); + goto error; + } + + bandwidthNode =3D virXPathNode("./bandwidth", ctxt); + /* + * We don't know if the port will allow the "floor" param or + * not at this stage, so we must just tell virNetDevBandwidthParse + * to allow it regardless. Any bad config must be reported at + * time of use instead. + */ + if (bandwidthNode && + virNetDevBandwidthParse(&def->bandwidth, &def->class_id, + bandwidthNode, true) < 0) + goto error; + + vlanNode =3D virXPathNode("./vlan", ctxt); + if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &def->vlan) < 0) + goto error; + + + trustGuestRxFilters + =3D virXPathString("string(./rxfilters/@trustGuest)", ctxt); + if (trustGuestRxFilters) { + if ((def->trustGuestRxFilters + =3D virTristateBoolTypeFromString(trustGuestRxFilters)) <=3D = 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid guest rx filters trust setting '%s' = "), + trustGuestRxFilters); + goto error; + } + } + + plugtype =3D virXPathString("string(./plug/@type)", ctxt); + + if (plugtype && + (def->plugtype =3D virNetworkPortPlugTypeFromString(plugtype)) < 0= ) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid network prt plug type '%s'"), plugtype); + } + + switch (def->plugtype) { + case VIR_NETWORK_PORT_PLUG_TYPE_NONE: + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK: + case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE: + if (!(def->plug.bridge.brname =3D virXPathString("string(./plug/@b= ridge)", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Missing network port bridge name")); + goto error; + } + macmgr =3D virXPathString("string(./plug/@macTableManager)", ctxt); + if (macmgr && + (def->plug.bridge.macTableManager =3D + virNetworkBridgeMACTableManagerTypeFromString(macmgr)) <=3D 0= ) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid macTableManager setting '%s' " + "in network port"), macmgr); + goto error; + } + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT: + if (!(def->plug.direct.linkdev =3D virXPathString("string(./plug/@= dev)", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Missing network port link device name")); + goto error; + } + mode =3D virXPathString("string(./plug/@mode)", ctxt); + if (mode && + (def->plug.direct.mode =3D + virNetDevMacVLanModeTypeFromString(mode)) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid mode setting '%s' in network port"),= mode); + goto error; + } + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: + managed =3D virXPathString("string(./plug/@managed)", ctxt); + if (managed && + (def->plug.hostdevpci.managed =3D + virTristateBoolTypeFromString(managed)) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid managed setting '%s' in network port= "), mode); + goto error; + } + driver =3D virXPathString("string(./plug/driver/@name)", ctxt); + if (driver && + (def->plug.hostdevpci.driver =3D + virNetworkForwardDriverNameTypeFromString(driver)) <=3D 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Missing network port driver name")); + goto error; + } + if (!(addressNode =3D virXPathNode("./plug/address", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Missing network port PCI address")); + goto error; + } + + if (virPCIDeviceAddressParseXML(addressNode, &def->plug.hostdevpci= .addr) < 0) + goto error; + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_LAST: + default: + virReportEnumRangeError(virNetworkPortPlugType, def->plugtype); + goto error; + } + + cleanup: + VIR_FREE(class_id); + VIR_FREE(uuid); + VIR_FREE(plugtype); + VIR_FREE(mac); + VIR_FREE(mode); + VIR_FREE(macmgr); + VIR_FREE(driver); + VIR_FREE(managed); + return def; + + error: + virNetworkPortDefFree(def); + def =3D NULL; + goto cleanup; +} + + +virNetworkPortDefPtr +virNetworkPortDefParseNode(xmlDocPtr xml, + xmlNodePtr root) +{ + xmlXPathContextPtr ctxt =3D NULL; + virNetworkPortDefPtr def =3D NULL; + + if (STRNEQ((const char *)root->name, "networkport")) { + virReportError(VIR_ERR_XML_ERROR, + "%s", + _("unknown root element for network port")); + goto cleanup; + } + + ctxt =3D xmlXPathNewContext(xml); + if (ctxt =3D=3D NULL) { + virReportOOMError(); + goto cleanup; + } + + ctxt->node =3D root; + def =3D virNetworkPortDefParseXML(ctxt); + + cleanup: + xmlXPathFreeContext(ctxt); + return def; +} + + +static virNetworkPortDefPtr +virNetworkPortDefParse(const char *xmlStr, + const char *filename) +{ + virNetworkPortDefPtr def =3D NULL; + xmlDocPtr xml; + + if ((xml =3D virXMLParse(filename, xmlStr, _("(networkport_definition)= ")))) { + def =3D virNetworkPortDefParseNode(xml, xmlDocGetRootElement(xml)); + xmlFreeDoc(xml); + } + + return def; +} + + +virNetworkPortDefPtr +virNetworkPortDefParseString(const char *xmlStr) +{ + return virNetworkPortDefParse(xmlStr, NULL); +} + + +virNetworkPortDefPtr +virNetworkPortDefParseFile(const char *filename) +{ + return virNetworkPortDefParse(NULL, filename); +} + + +char * +virNetworkPortDefFormat(const virNetworkPortDef *def) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + if (virNetworkPortDefFormatBuf(&buf, def) < 0) { + virBufferFreeAndReset(&buf); + return NULL; + } + + if (virBufferCheckError(&buf) < 0) + return NULL; + + return virBufferContentAndReset(&buf); +} + + +int +virNetworkPortDefFormatBuf(virBufferPtr buf, + const virNetworkPortDef *def) +{ + char uuid[VIR_UUID_STRING_BUFLEN]; + char macaddr[VIR_MAC_STRING_BUFLEN]; + + virBufferAddLit(buf, "\n"); + + virBufferAdjustIndent(buf, 2); + + virUUIDFormat(def->uuid, uuid); + virBufferAsprintf(buf, "%s\n", uuid); + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferEscapeString(buf, "%s\n", def->ownername); + virUUIDFormat(def->owneruuid, uuid); + virBufferAsprintf(buf, "%s\n", uuid); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + if (def->group) + virBufferEscapeString(buf, "%s\n", def->group); + + virMacAddrFormat(&def->mac, macaddr); + virBufferAsprintf(buf, "\n", macaddr); + + if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0) + return -1; + if (def->bandwidth) + virNetDevBandwidthFormat(def->bandwidth, def->class_id, buf); + if (virNetDevVlanFormat(&def->vlan, buf) < 0) + return -1; + if (def->trustGuestRxFilters) + virBufferAsprintf(buf, "\n", + virTristateBoolTypeToString(def->trustGuestRxFil= ters)); + + if (def->plugtype !=3D VIR_NETWORK_PORT_PLUG_TYPE_NONE) { + virBufferAsprintf(buf, "plugtype)); + + switch (def->plugtype) { + case VIR_NETWORK_PORT_PLUG_TYPE_NONE: + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK: + case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE: + virBufferEscapeString(buf, " bridge=3D'%s'", def->plug.bridge.= brname); + if (def->plug.bridge.macTableManager) + virBufferAsprintf(buf, " macTableManager=3D'%s'", + virNetworkBridgeMACTableManagerTypeToStr= ing( + def->plug.bridge.macTableManager)); + virBufferAddLit(buf, "/>\n"); + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT: + virBufferEscapeString(buf, " dev=3D'%s'", def->plug.direct.lin= kdev); + virBufferAsprintf(buf, " mode=3D'%s'", + virNetDevMacVLanModeTypeToString( + def->plug.direct.mode)); + virBufferAddLit(buf, "/>\n"); + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: + virBufferAsprintf(buf, " managed=3D'%s'>\n", + def->plug.hostdevpci.managed ? "yes" : "no"); + virBufferAdjustIndent(buf, 2); + if (def->plug.hostdevpci.driver) + virBufferEscapeString(buf, "\n", + virNetworkForwardDriverNameTypeToStr= ing( + def->plug.hostdevpci.driver)); + + virPCIDeviceAddressFormat(buf, def->plug.hostdevpci.addr, fals= e); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_LAST: + default: + virReportEnumRangeError(virNetworkPortPlugType, def->plugtype); + return -1; + } + } + + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + return 0; +} + + +static char * +virNetworkPortDefConfigFile(const char *dir, + const char *name) +{ + char *ret =3D NULL; + + ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name)); + return ret; +} + + +int +virNetworkPortDefSaveStatus(virNetworkPortDef *def, + const char *dir) +{ + char uuidstr[VIR_UUID_STRING_BUFLEN]; + char *path; + char *xml =3D NULL; + int ret =3D -1; + + virUUIDFormat(def->uuid, uuidstr); + + if (virFileMakePath(dir) < 0) + goto cleanup; + + if (!(path =3D virNetworkPortDefConfigFile(dir, uuidstr))) + goto cleanup; + + if (!(xml =3D virNetworkPortDefFormat(def))) + goto cleanup; + + if (virXMLSaveFile(path, uuidstr, "net-port-create", xml) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + VIR_FREE(xml); + VIR_FREE(path); + return ret; +} + + +int +virNetworkPortDefDeleteStatus(virNetworkPortDef *def, + const char *dir) +{ + char uuidstr[VIR_UUID_STRING_BUFLEN]; + char *path; + int ret =3D -1; + + virUUIDFormat(def->uuid, uuidstr); + + if (!(path =3D virNetworkPortDefConfigFile(dir, uuidstr))) + goto cleanup; + + if (unlink(path) < 0 && errno !=3D ENOENT) { + virReportSystemError(errno, + _("Unable to delete %s"), path); + goto cleanup; + } + + ret =3D 0; + cleanup: + VIR_FREE(path); + return ret; +} diff --git a/src/conf/virnetworkportdef.h b/src/conf/virnetworkportdef.h new file mode 100644 index 0000000000..94b2fabf6b --- /dev/null +++ b/src/conf/virnetworkportdef.h @@ -0,0 +1,113 @@ +/* + * virnetworkportdef.h: network port XML processing + * + * Copyright (C) 2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#ifndef LIBVIRT_VIRNETWORKPORTDEF_H +# define LIBVIRT_VIRNETWORKPORTDEF_H + +# include "internal.h" +# include "viruuid.h" +# include "virnetdevvlan.h" +# include "virnetdevvportprofile.h" +# include "virnetdevbandwidth.h" +# include "virpci.h" +# include "virxml.h" +# include "netdev_vport_profile_conf.h" +# include "netdev_bandwidth_conf.h" +# include "netdev_vlan_conf.h" + +typedef struct _virNetworkPortDef virNetworkPortDef; +typedef virNetworkPortDef *virNetworkPortDefPtr; + +typedef enum { + VIR_NETWORK_PORT_PLUG_TYPE_NONE, + VIR_NETWORK_PORT_PLUG_TYPE_NETWORK, + VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE, + VIR_NETWORK_PORT_PLUG_TYPE_DIRECT, + VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI, + + VIR_NETWORK_PORT_PLUG_TYPE_LAST, +} virNetworkPortPlugType; + +VIR_ENUM_DECL(virNetworkPortPlug); + +struct _virNetworkPortDef { + unsigned char uuid[VIR_UUID_BUFLEN]; + char *ownername; + unsigned char owneruuid[VIR_UUID_BUFLEN]; + + char *group; + virMacAddr mac; + + virNetDevVPortProfilePtr virtPortProfile; + virNetDevBandwidthPtr bandwidth; + unsigned int class_id; /* class ID for bandwidth 'floor' */ + virNetDevVlan vlan; + int trustGuestRxFilters; /* enum virTristateBool */ + + int plugtype; /* virNetworkPortPlugType */ + union { + struct { + char *brname; + int macTableManager; /* enum virNetworkBridgeMACTableManagerTy= pe */ + } bridge; /* For TYPE_NETWORK & TYPE_BRIDGE */ + struct { + char *linkdev; + int mode; /* enum virNetDevMacVLanMode from util/virnetdevmacv= lan.h */ + } direct; + struct { + virPCIDeviceAddress addr; /* PCI Address of device */ + int driver; /* virNetworkForwardDriverNameType */ + int managed; + } hostdevpci; + } plug; +}; + + +void +virNetworkPortDefFree(virNetworkPortDefPtr port); + +virNetworkPortDefPtr +virNetworkPortDefParseNode(xmlDocPtr xml, + xmlNodePtr root); + +virNetworkPortDefPtr +virNetworkPortDefParseString(const char *xml); + +virNetworkPortDefPtr +virNetworkPortDefParseFile(const char *filename); + +char * +virNetworkPortDefFormat(const virNetworkPortDef *def); + +int +virNetworkPortDefFormatBuf(virBufferPtr buf, + const virNetworkPortDef *def); + +int +virNetworkPortDefSaveStatus(virNetworkPortDef *def, + const char *dir); + +int +virNetworkPortDefDeleteStatus(virNetworkPortDef *def, + const char *dir); + + +#endif /* LIBVIRT_VIRNETWORKPORTDEF_H */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 909975750c..62a07c094e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1075,6 +1075,16 @@ virNetworkObjUpdate; virNetworkObjUpdateAssignDef; =20 =20 +# conf/virnetworkportdef.h +virNetworkPortDefFormat; +virNetworkPortDefFormatBuf; +virNetworkPortDefFree; +virNetworkPortDefParseFile; +virNetworkPortDefParseNode; +virNetworkPortDefParseString; +virNetworkPortDefSaveStatus; + + # conf/virnodedeviceobj.h virNodeDeviceObjEndAPI; virNodeDeviceObjGetDef; diff --git a/tests/Makefile.am b/tests/Makefile.am index 46d94d2236..6865ee946e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -149,6 +149,7 @@ EXTRA_DIST =3D \ virmockstathelpers.c \ virnetdaemondata \ virnetdevtestdata \ + virnetworkportxml2xmldata \ virnwfilterbindingxml2xmldata \ virpcitestdata \ virscsidata \ @@ -335,6 +336,7 @@ endif WITH_YAJL test_programs +=3D \ networkxml2xmltest \ networkxml2xmlupdatetest \ + virnetworkportxml2xmltest \ $(NULL) =20 if WITH_NETWORK @@ -832,6 +834,11 @@ networkxml2xmlupdatetest_SOURCES =3D \ testutils.c testutils.h networkxml2xmlupdatetest_LDADD =3D $(LDADDS) =20 +virnetworkportxml2xmltest_SOURCES =3D \ + virnetworkportxml2xmltest.c \ + testutils.c testutils.h +virnetworkportxml2xmltest_LDADD =3D $(LDADDS) + if WITH_NETWORK networkxml2conftest_SOURCES =3D \ networkxml2conftest.c \ diff --git a/tests/virnetworkportxml2xmldata/plug-bridge-mactbl.xml b/tests= /virnetworkportxml2xmldata/plug-bridge-mactbl.xml new file mode 100644 index 0000000000..8036bc2e1c --- /dev/null +++ b/tests/virnetworkportxml2xmldata/plug-bridge-mactbl.xml @@ -0,0 +1,9 @@ + + 5d744f21-ba4a-4d6e-bdb2-30a35ff3207d + + memtest + d54df46f-1ab5-4a22-8618-4560ef5fac2c + + + + diff --git a/tests/virnetworkportxml2xmldata/plug-bridge.xml b/tests/virnet= workportxml2xmldata/plug-bridge.xml new file mode 100644 index 0000000000..e09fc45a9d --- /dev/null +++ b/tests/virnetworkportxml2xmldata/plug-bridge.xml @@ -0,0 +1,15 @@ + + 5d744f21-ba4a-4d6e-bdb2-30a35ff3207d + + memtest + d54df46f-1ab5-4a22-8618-4560ef5fac2c + + web1 + + + + + + + + diff --git a/tests/virnetworkportxml2xmldata/plug-direct.xml b/tests/virnet= workportxml2xmldata/plug-direct.xml new file mode 100644 index 0000000000..81554b4579 --- /dev/null +++ b/tests/virnetworkportxml2xmldata/plug-direct.xml @@ -0,0 +1,12 @@ + + 5d744f21-ba4a-4d6e-bdb2-30a35ff3207d + + memtest + d54df46f-1ab5-4a22-8618-4560ef5fac2c + + + + + + + diff --git a/tests/virnetworkportxml2xmldata/plug-hostdev-pci.xml b/tests/v= irnetworkportxml2xmldata/plug-hostdev-pci.xml new file mode 100644 index 0000000000..cc4419f3fd --- /dev/null +++ b/tests/virnetworkportxml2xmldata/plug-hostdev-pci.xml @@ -0,0 +1,12 @@ + + 5d744f21-ba4a-4d6e-bdb2-30a35ff3207d + + memtest + d54df46f-1ab5-4a22-8618-4560ef5fac2c + + + + +
+ + diff --git a/tests/virnetworkportxml2xmldata/plug-network.xml b/tests/virne= tworkportxml2xmldata/plug-network.xml new file mode 100644 index 0000000000..7b08ca295a --- /dev/null +++ b/tests/virnetworkportxml2xmldata/plug-network.xml @@ -0,0 +1,16 @@ + + 5d744f21-ba4a-4d6e-bdb2-30a35ff3207d + + memtest + d54df46f-1ab5-4a22-8618-4560ef5fac2c + + web1 + + + + + + + + + diff --git a/tests/virnetworkportxml2xmldata/plug-none.xml b/tests/virnetwo= rkportxml2xmldata/plug-none.xml new file mode 100644 index 0000000000..ed7199ec8c --- /dev/null +++ b/tests/virnetworkportxml2xmldata/plug-none.xml @@ -0,0 +1,8 @@ + + 5d744f21-ba4a-4d6e-bdb2-30a35ff3207d + + memtest + d54df46f-1ab5-4a22-8618-4560ef5fac2c + + + diff --git a/tests/virnetworkportxml2xmltest.c b/tests/virnetworkportxml2xm= ltest.c new file mode 100644 index 0000000000..bb0ae8a8d5 --- /dev/null +++ b/tests/virnetworkportxml2xmltest.c @@ -0,0 +1,104 @@ +/* + * virnetworkportxml2xmltest.c: network port XML processing test suite + * + * Copyright (C) 2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include + +#include +#include + +#include "internal.h" +#include "testutils.h" +#include "virnetworkportdef.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + + +static int +testCompareXMLToXMLFiles(const char *expected) +{ + char *actual =3D NULL; + int ret =3D -1; + virNetworkPortDefPtr dev =3D NULL; + + if (!(dev =3D virNetworkPortDefParseFile(expected))) + goto cleanup; + + if (!(actual =3D virNetworkPortDefFormat(dev))) + goto cleanup; + + if (virTestCompareToFile(actual, expected) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + VIR_FREE(actual); + virNetworkPortDefFree(dev); + return ret; +} + +struct testInfo { + const char *name; +}; + +static int +testCompareXMLToXMLHelper(const void *data) +{ + const struct testInfo *info =3D data; + int ret =3D -1; + char *xml =3D NULL; + + if (virAsprintf(&xml, "%s/virnetworkportxml2xmldata/%s.xml", + abs_srcdir, info->name) < 0) + goto cleanup; + + ret =3D testCompareXMLToXMLFiles(xml); + + cleanup: + VIR_FREE(xml); + + return ret; +} + +static int +mymain(void) +{ + int ret =3D 0; + +#define DO_TEST(name) \ + do { \ + const struct testInfo info =3D {name}; \ + if (virTestRun("virnetworkportdeftest " name, \ + testCompareXMLToXMLHelper, &info) < 0) \ + ret =3D -1; \ + } while (0) + + DO_TEST("plug-none"); + DO_TEST("plug-bridge"); + DO_TEST("plug-bridge-mactbl"); + DO_TEST("plug-direct"); + DO_TEST("plug-hostdev-pci"); + + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(mymain) diff --git a/tests/virschematest.c b/tests/virschematest.c index 56bdcb2f88..13c30acc30 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -227,6 +227,7 @@ mymain(void) DO_TEST_DIR("interface.rng", "interfaceschemadata"); DO_TEST_DIR("network.rng", "../src/network", "networkxml2xmlin", "networkxml2xmlout", "networkxml2confdata"); + DO_TEST_DIR("networkport.rng", "virnetworkportxml2xmldata"); DO_TEST_DIR("nodedev.rng", "nodedevschemadata"); DO_TEST_DIR("nwfilter.rng", "nwfilterxml2xmlout", "../examples/xml/nwf= ilter"); DO_TEST_DIR("nwfilterbinding.rng", "virnwfilterbindingxml2xmldata"); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848927; cv=none; d=zoho.com; s=zohoarc; b=oYD48NBMUjm0QUtp67Rqzm5SLYCJxtoptBnMcSX+lGQZab9jsLBjAPz2JREuUS9J9tuFMV9+Pnt/tCHCmXTAWXUlr6pcSjyOblOafI38Z+2Vb48gJXI71IagY9FQnOdPLLA8iY2vXK8fhZGGb11pae+/OkDKHroiALOZ3y0t1EA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848927; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=LLVvk7YKEjqmR5FKTbtyag/UqMoy6txwX/RavJ0+Sl0=; b=PjVpJjHT0MISxCVd42Fx5xKn8IBIhpAEgoPl9C7vq2oQYCyR4Wqp9UHkW7a1A1V4QR+UKqZYzYzcGXEItsz1PQWAGTUWiNYyo9NHL0eFzUl/R8gErZ5FWf/pB9m6djzufx2f8StYKZIlrw+1aSaOdYRsTwoXKrGZ3HMfv357hwE= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848927645890.1920056771105; Tue, 14 May 2019 08:48:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B21773680A; Tue, 14 May 2019 15:48: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 8413260BCF; Tue, 14 May 2019 15:48:45 +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 41C4841F5A; Tue, 14 May 2019 15:48:45 +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 x4EFmifp031739 for ; Tue, 14 May 2019 11:48:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id BD51360BCF; Tue, 14 May 2019 15:48:44 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1360A600CD; Tue, 14 May 2019 15:48:43 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:15 +0100 Message-Id: <20190514154836.6427-4-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 03/24] network: make networkLogAllocation independent of domain conf 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-Type: text/plain; charset="utf-8" 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 14 May 2019 15:48:46 +0000 (UTC) Stop passing a virDomainNetDefPtr parameter to networkLogAllocation, instead just pass in the MAC address. The actual device type is also not required, since virNetworkForwardIfDefPtr has a type field that can be used instead. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 26f7f80418..fbd8909009 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4333,32 +4333,29 @@ networkGetDHCPLeases(virNetworkPtr net, =20 static void networkLogAllocation(virNetworkDefPtr netdef, - virDomainNetType actualType, virNetworkForwardIfDefPtr dev, - virDomainNetDefPtr iface, + virMacAddrPtr mac, bool inUse) { char macStr[VIR_MAC_STRING_BUFLEN]; const char *verb =3D inUse ? "using" : "releasing"; =20 + virMacAddrFormat(mac, macStr); if (!dev) { VIR_INFO("MAC %s %s network %s (%d connections)", - virMacAddrFormat(&iface->mac, macStr), verb, - netdef->name, netdef->connections); + macStr, verb, netdef->name, netdef->connections); } else { - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) { + if (dev->type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_PCI) { VIR_INFO("MAC %s %s network %s (%d connections) " "physical device %04x:%02x:%02x.%x (%d connections)", - virMacAddrFormat(&iface->mac, macStr), verb, - netdef->name, netdef->connections, + macStr, verb, netdef->name, netdef->connections, dev->device.pci.domain, dev->device.pci.bus, dev->device.pci.slot, dev->device.pci.function, dev->connections); } else { VIR_INFO("MAC %s %s network %s (%d connections) " "physical device %s (%d connections)", - virMacAddrFormat(&iface->mac, macStr), verb, - netdef->name, netdef->connections, + macStr, verb, netdef->name, netdef->connections, dev->device.dev, dev->connections); } } @@ -4771,7 +4768,7 @@ networkAllocateActualDevice(virNetworkPtr net, dev->connections--; goto error; } - networkLogAllocation(netdef, actualType, dev, iface, true); + networkLogAllocation(netdef, dev, &iface->mac, true); =20 ret =3D 0; =20 @@ -4962,7 +4959,7 @@ networkNotifyActualDevice(virNetworkPtr net, netdef->connections--; goto error; } - networkLogAllocation(netdef, actualType, dev, iface, true); + networkLogAllocation(netdef, dev, &iface->mac, true); ret =3D 0; =20 cleanup: @@ -5129,7 +5126,7 @@ networkReleaseActualDevice(virNetworkPtr net, /* finally we can call the 'unplugged' hook script if any */ networkRunHook(obj, dom, iface, VIR_HOOK_NETWORK_OP_IFACE_UNPLUGGE= D, VIR_HOOK_SUBOP_BEGIN); - networkLogAllocation(netdef, actualType, dev, iface, false); + networkLogAllocation(netdef, dev, &iface->mac, false); } ret =3D 0; cleanup: --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848935; cv=none; d=zoho.com; s=zohoarc; b=fZFQdB+v5wo/0h74lMwukfAadxg3tnLa2dLnAp06m0rvBri8XjhHWAJciLdy8qB/6g26lWB6522UEQ3MhpJA6y371jvsSY1qbm2WLPJjnwvj36NWeEs4ACMHXLMJu1p6X9XMAAYCC1isca9n1hTuitVandSxcbRy2oqEo6l/2wg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848935; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=zRM0PPqdWVLvk9vVDnlXctZ98S0FtGYKDu+h+hLEJj0=; b=f5Btz3pBYUyuFuOb+ebDIAcBvk8Q0ebKL1KNWk6aMwv+xcnWhP69nuPudbooVWTuJ6jAaKIjQ2XDxeO7rmgWDkJkh1uB4hkh9gydMwMrayqHikS0CZHVkmhA5/EOpiAx6/kpsSmplrg+1duTupMpsXfTReuMWsgDENOro1wWVeI= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848935815758.6530844783449; Tue, 14 May 2019 08:48:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE61D300183E; Tue, 14 May 2019 15:48:53 +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 C85E61001E91; Tue, 14 May 2019 15:48:53 +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 66ACA18089D4; Tue, 14 May 2019 15:48:53 +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 x4EFmjAU031744 for ; Tue, 14 May 2019 11:48:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id B37726135A; Tue, 14 May 2019 15:48:45 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0ABF5600CD; Tue, 14 May 2019 15:48:44 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:16 +0100 Message-Id: <20190514154836.6427-5-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 04/24] conf: add APIs to convert virDomainNetDef to virNetworkPortDef 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 14 May 2019 15:48:54 +0000 (UTC) Helper APIs are needed to - Populate basic virNetworkPortDef from virDomainNetDef - Set a virDomainActualNetDef from virNetworkPortDef - Populate a full virNetworkPortDef from virDomainActualNetDef Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/conf/domain_conf.c | 290 +++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 17 +++ src/libvirt_private.syms | 3 + 3 files changed, 310 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 011d789feb..7569b1b580 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -39,6 +39,7 @@ #include "virbuffer.h" #include "virlog.h" #include "nwfilter_conf.h" +#include "virnetworkportdef.h" #include "storage_conf.h" #include "virstoragefile.h" #include "virfile.h" @@ -30367,6 +30368,295 @@ virDomainNetTypeSharesHostView(const virDomainNet= Def *net) return false; } =20 +virNetworkPortDefPtr +virDomainNetDefToNetworkPort(virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + virNetworkPortDefPtr port; + + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Expected an interface of type 'network' not '%s'= "), + virDomainNetTypeToString(iface->type)); + return NULL; + } + + if (VIR_ALLOC(port) < 0) + return NULL; + + virUUIDGenerate(port->uuid); + + memcpy(port->owneruuid, dom->uuid, VIR_UUID_BUFLEN); + if (VIR_STRDUP(port->ownername, dom->name) < 0) + goto error; + + if (VIR_STRDUP(port->group, iface->data.network.portgroup) < 0) + goto error; + + memcpy(&port->mac, &iface->mac, VIR_MAC_BUFLEN); + + if (virNetDevVPortProfileCopy(&port->virtPortProfile, iface->virtPortP= rofile) < 0) + goto error; + + if (virNetDevBandwidthCopy(&port->bandwidth, iface->bandwidth) < 0) + goto error; + + if (virNetDevVlanCopy(&port->vlan, &iface->vlan) < 0) + goto error; + + port->trustGuestRxFilters =3D iface->trustGuestRxFilters; + + return port; + + error: + virNetworkPortDefFree(port); + return NULL; +} + +int +virDomainNetDefActualFromNetworkPort(virDomainNetDefPtr iface, + virNetworkPortDefPtr port) +{ + virDomainActualNetDefPtr actual =3D NULL; + + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Expected an interface of type 'network' not '%s'= "), + virDomainNetTypeToString(iface->type)); + return -1; + } + + if (VIR_ALLOC(actual) < 0) + return -1; + + switch ((virNetworkPortPlugType)port->plugtype) { + case VIR_NETWORK_PORT_PLUG_TYPE_NONE: + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK: + actual->type =3D VIR_DOMAIN_NET_TYPE_NETWORK; + if (VIR_STRDUP(actual->data.bridge.brname, + port->plug.bridge.brname) < 0) + goto error; + actual->data.bridge.macTableManager =3D port->plug.bridge.macTable= Manager; + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE: + actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + if (VIR_STRDUP(actual->data.bridge.brname, + port->plug.bridge.brname) < 0) + goto error; + actual->data.bridge.macTableManager =3D port->plug.bridge.macTable= Manager; + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT: + actual->type =3D VIR_DOMAIN_NET_TYPE_DIRECT; + if (VIR_STRDUP(actual->data.direct.linkdev, + port->plug.direct.linkdev) < 0) + goto error; + actual->data.direct.mode =3D port->plug.direct.mode; + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: + actual->type =3D VIR_DOMAIN_NET_TYPE_HOSTDEV; + actual->data.hostdev.def.parentnet =3D iface; + actual->data.hostdev.def.info =3D &iface->info; + actual->data.hostdev.def.mode =3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS; + actual->data.hostdev.def.managed =3D port->plug.hostdevpci.managed; + actual->data.hostdev.def.source.subsys.type =3D VIR_DOMAIN_HOSTDEV= _SUBSYS_TYPE_PCI; + actual->data.hostdev.def.source.subsys.u.pci.addr =3D port->plug.h= ostdevpci.addr; + switch ((virNetworkForwardDriverNameType)port->plug.hostdevpci.dri= ver) { + case VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT: + actual->data.hostdev.def.source.subsys.u.pci.backend =3D + VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT; + break; + + case VIR_NETWORK_FORWARD_DRIVER_NAME_KVM: + actual->data.hostdev.def.source.subsys.u.pci.backend =3D + VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM; + break; + + case VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO: + actual->data.hostdev.def.source.subsys.u.pci.backend =3D + VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; + break; + + case VIR_NETWORK_FORWARD_DRIVER_NAME_LAST: + default: + virReportEnumRangeError(virNetworkForwardDriverNameType, + port->plug.hostdevpci.driver); + goto error; + } + + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_LAST: + default: + virReportEnumRangeError(virNetworkPortPlugType, port->plugtype); + goto error; + } + + if (virNetDevVPortProfileCopy(&actual->virtPortProfile, port->virtPort= Profile) < 0) + goto error; + + if (virNetDevBandwidthCopy(&actual->bandwidth, port->bandwidth) < 0) + goto error; + + if (virNetDevVlanCopy(&actual->vlan, &port->vlan) < 0) + goto error; + + actual->class_id =3D port->class_id; + actual->trustGuestRxFilters =3D port->trustGuestRxFilters; + + virDomainActualNetDefFree(iface->data.network.actual); + iface->data.network.actual =3D actual; + + return 0; + + error: + virDomainActualNetDefFree(actual); + return -1; +} + +virNetworkPortDefPtr +virDomainNetDefActualToNetworkPort(virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + virDomainActualNetDefPtr actual; + virNetworkPortDefPtr port; + + if (!iface->data.network.actual) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing actual data for interface '%s'"), + iface->ifname); + return NULL; + } + + actual =3D iface->data.network.actual; + + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Expected an interface of type 'network' not '%s'= "), + virDomainNetTypeToString(iface->type)); + return NULL; + } + + if (VIR_ALLOC(port) < 0) + return NULL; + + /* Bad - we need to preserve original port uuid */ + virUUIDGenerate(port->uuid); + + memcpy(port->owneruuid, dom->uuid, VIR_UUID_BUFLEN); + if (VIR_STRDUP(port->ownername, dom->name) < 0) + goto error; + + if (VIR_STRDUP(port->group, iface->data.network.portgroup) < 0) + goto error; + + memcpy(&port->mac, &iface->mac, VIR_MAC_BUFLEN); + + switch (virDomainNetGetActualType(iface)) { + case VIR_DOMAIN_NET_TYPE_NETWORK: + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_NETWORK; + if (VIR_STRDUP(port->plug.bridge.brname, + actual->data.bridge.brname) < 0) + goto error; + port->plug.bridge.macTableManager =3D actual->data.bridge.macTable= Manager; + break; + + case VIR_DOMAIN_NET_TYPE_BRIDGE: + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE; + if (VIR_STRDUP(port->plug.bridge.brname, + actual->data.bridge.brname) < 0) + goto error; + port->plug.bridge.macTableManager =3D actual->data.bridge.macTable= Manager; + break; + + case VIR_DOMAIN_NET_TYPE_DIRECT: + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_DIRECT; + if (VIR_STRDUP(port->plug.direct.linkdev, + actual->data.direct.linkdev) < 0) + goto error; + port->plug.direct.mode =3D actual->data.direct.mode; + break; + + case VIR_DOMAIN_NET_TYPE_HOSTDEV: + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI; + if (actual->data.hostdev.def.mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUB= SYS || + actual->data.hostdev.def.source.subsys.type !=3D VIR_DOMAIN_HO= STDEV_SUBSYS_TYPE_PCI) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Actual interface '%s' hostdev was not a PCI = device"), + iface->ifname); + goto error; + } + port->plug.hostdevpci.managed =3D actual->data.hostdev.def.managed; + port->plug.hostdevpci.addr =3D actual->data.hostdev.def.source.sub= sys.u.pci.addr; + switch ((virDomainHostdevSubsysPCIBackendType)actual->data.hostdev= .def.source.subsys.u.pci.backend) { + case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT: + port->plug.hostdevpci.driver =3D VIR_NETWORK_FORWARD_DRIVER_NA= ME_DEFAULT; + break; + + case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM: + port->plug.hostdevpci.driver =3D VIR_NETWORK_FORWARD_DRIVER_NA= ME_KVM; + break; + + case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO: + port->plug.hostdevpci.driver =3D VIR_NETWORK_FORWARD_DRIVER_NA= ME_VFIO; + break; + + case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unexpected PCI backend 'xen'")); + break; + + case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST: + default: + virReportEnumRangeError(virDomainHostdevSubsysPCIBackendType, + actual->data.hostdev.def.source.subsys= .u.pci.backend); + goto error; + } + + break; + + case VIR_DOMAIN_NET_TYPE_CLIENT: + case VIR_DOMAIN_NET_TYPE_ETHERNET: + case VIR_DOMAIN_NET_TYPE_INTERNAL: + case VIR_DOMAIN_NET_TYPE_MCAST: + case VIR_DOMAIN_NET_TYPE_SERVER: + case VIR_DOMAIN_NET_TYPE_UDP: + case VIR_DOMAIN_NET_TYPE_USER: + case VIR_DOMAIN_NET_TYPE_VHOSTUSER: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unexpected network port type %s"), + virDomainNetTypeToString(virDomainNetGetActualType(= iface))); + goto error; + + case VIR_DOMAIN_NET_TYPE_LAST: + default: + virReportEnumRangeError(virNetworkPortPlugType, port->plugtype); + goto error; + } + + if (virNetDevVPortProfileCopy(&port->virtPortProfile, actual->virtPort= Profile) < 0) + goto error; + + if (virNetDevBandwidthCopy(&port->bandwidth, actual->bandwidth) < 0) + goto error; + + if (virNetDevVlanCopy(&port->vlan, &actual->vlan) < 0) + goto error; + + port->class_id =3D actual->class_id; + port->trustGuestRxFilters =3D actual->trustGuestRxFilters; + + return port; + + error: + virNetworkPortDefFree(port); + return NULL; +} + static virDomainNetAllocateActualDeviceImpl netAllocate; static virDomainNetNotifyActualDeviceImpl netNotify; static virDomainNetReleaseActualDeviceImpl netRelease; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index fa0756b634..c0a94e3b5a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3552,6 +3552,23 @@ bool virDomainDefLifecycleActionAllowed(virDomainLifecycle type, virDomainLifecycleAction action); =20 +// Forward decl to avoid pulling in virnetworkportdef.h because +// that pulls in virhostdev.h which pulls in domain_conf.h (evil) +typedef struct _virNetworkPortDef virNetworkPortDef; +typedef virNetworkPortDef *virNetworkPortDefPtr; + +virNetworkPortDefPtr +virDomainNetDefToNetworkPort(virDomainDefPtr dom, + virDomainNetDefPtr iface); + +int +virDomainNetDefActualFromNetworkPort(virDomainNetDefPtr iface, + virNetworkPortDefPtr port); + +virNetworkPortDefPtr +virDomainNetDefActualToNetworkPort(virDomainDefPtr dom, + virDomainNetDefPtr iface); + typedef int (*virDomainNetAllocateActualDeviceImpl)(virNetworkPtr net, virDomainDefPtr dom, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 62a07c094e..6646fc5039 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -458,9 +458,12 @@ virDomainNetAllocateActualDevice; virDomainNetAppendIPAddress; virDomainNetBandwidthChangeAllowed; virDomainNetBandwidthUpdate; +virDomainNetDefActualFromNetworkPort; +virDomainNetDefActualToNetworkPort; virDomainNetDefClear; virDomainNetDefFormat; virDomainNetDefFree; +virDomainNetDefToNetworkPort; virDomainNetFind; virDomainNetFindByName; virDomainNetFindIdx; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848939; cv=none; d=zoho.com; s=zohoarc; b=Wd3iL6iyt8ruj6qHxHfk62NyRHuKT15iP8YZxVmXRQTccLEbPe25hbBPC4g0lTplbn/goC7AJMXvSClBBKjy0t54eddZne6pHp14iOaj/noJb9ZcgGMY6sDmxNKIjCEOEc1HaO74lbIyT6iADNlwcaG8w8biOlT47N3Q6lYpFss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848939; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=lAzqwbuySQkyKAoiy40U4RMGdxirWppVgEd1TTDm3RE=; b=ExAauhyTBm+EQnBRS+ANSaDbaqwTPEBe9Vi9phGs6R0zSR2CxV1fkVmAvwcBbgVvVrhGah9hmPMFAHYkBLTwsUP9iYqwIkPCN08urjWAKHgWHRXIOwV9yPCaN8FGmEqSbMI0nc/1WE+kIxCwGQ3oO5XkgzaPJ3R788HCFDuuxxM= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848939441999.0777243797618; Tue, 14 May 2019 08:48:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D9773092675; Tue, 14 May 2019 15:48:57 +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 3340563B86; Tue, 14 May 2019 15:48:57 +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 E971318052E6; Tue, 14 May 2019 15:48:56 +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 x4EFmknd031752 for ; Tue, 14 May 2019 11:48:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id A97342B9E3; Tue, 14 May 2019 15:48:46 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id F4081600CD; Tue, 14 May 2019 15:48:45 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:17 +0100 Message-Id: <20190514154836.6427-6-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 05/24] network: convert networkAllocateActualDevice to virNetworkPortDef 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-Type: text/plain; charset="utf-8" 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 14 May 2019 15:48:58 +0000 (UTC) Convert the virDomainNetDef object into a virNetworkPortDef object at the start of networkAllocateActualDevice. This largely decouples the method impl from the domain object type. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 222 +++++++++++++++--------------------- 1 file changed, 91 insertions(+), 131 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index fbd8909009..e5a42d7a7f 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -67,6 +67,7 @@ #include "network_event.h" #include "virhook.h" #include "virjson.h" +#include "virnetworkportdef.h" =20 #define VIR_FROM_THIS VIR_FROM_NETWORK #define MAX_BRIDGE_ID 256 @@ -4388,17 +4389,16 @@ networkAllocateActualDevice(virNetworkPtr net, virDomainNetDefPtr iface) { virNetworkDriverStatePtr driver =3D networkGetDriver(); - virDomainNetType actualType =3D iface->type; virNetworkObjPtr obj =3D NULL; virNetworkDefPtr netdef =3D NULL; - virNetDevBandwidthPtr bandwidth =3D NULL; virPortGroupDefPtr portgroup =3D NULL; - virNetDevVPortProfilePtr virtport =3D iface->virtPortProfile; - virNetDevVlanPtr vlan =3D NULL; virNetworkForwardIfDefPtr dev =3D NULL; size_t i; int ret =3D -1; + virNetDevVPortProfilePtr portprofile =3D NULL; + virNetworkPortDefPtr port =3D NULL; =20 + VIR_DEBUG("Allocating port from net %s", net->name); obj =3D virNetworkObjFindByName(driver->networks, net->name); if (!obj) { virReportError(VIR_ERR_NO_NETWORK, @@ -4413,9 +4413,6 @@ networkAllocateActualDevice(virNetworkPtr net, goto error; } =20 - virDomainActualNetDefFree(iface->data.network.actual); - iface->data.network.actual =3D NULL; - netdef =3D virNetworkObjGetDef(obj); =20 if (!virNetworkObjIsActive(obj)) { @@ -4425,62 +4422,57 @@ networkAllocateActualDevice(virNetworkPtr net, goto error; } =20 - if (VIR_ALLOC(iface->data.network.actual) < 0) + if (!(port =3D virDomainNetDefToNetworkPort(dom, iface))) goto error; =20 + VIR_DEBUG("Interface port group %s", port->group); /* portgroup can be present for any type of network, in particular * for bandwidth information, so we need to check for that and * fill it in appropriately for all forward types. */ - portgroup =3D virPortGroupFindByName(netdef, iface->data.network.portg= roup); - - /* If there is already interface-specific bandwidth, just use that - * (already in NetDef). Otherwise, if there is bandwidth info in - * the portgroup, fill that into the ActualDef. - */ - - if (iface->bandwidth) - bandwidth =3D iface->bandwidth; - else if (portgroup && portgroup->bandwidth) - bandwidth =3D portgroup->bandwidth; + portgroup =3D virPortGroupFindByName(netdef, port->group); =20 - if (bandwidth && virNetDevBandwidthCopy(&iface->data.network.actual->b= andwidth, - bandwidth) < 0) - goto error; + if (!port->bandwidth) { + if (portgroup && portgroup->bandwidth && + virNetDevBandwidthCopy(&port->bandwidth, + portgroup->bandwidth) < 0) + goto error; + } =20 - /* copy appropriate vlan info to actualNet */ - if (iface->vlan.nTags > 0) - vlan =3D &iface->vlan; - else if (portgroup && portgroup->vlan.nTags > 0) - vlan =3D &portgroup->vlan; - else if (netdef->vlan.nTags > 0) - vlan =3D &netdef->vlan; + if (port->vlan.nTags =3D=3D 0) { + virNetDevVlanPtr vlan =3D NULL; + if (portgroup && portgroup->vlan.nTags > 0) + vlan =3D &portgroup->vlan; + else if (netdef->vlan.nTags > 0) + vlan =3D &netdef->vlan; =20 - if (vlan && virNetDevVlanCopy(&iface->data.network.actual->vlan, vlan)= < 0) - goto error; + if (vlan && virNetDevVlanCopy(&port->vlan, vlan) < 0) + goto error; + } =20 - if (iface->trustGuestRxFilters) - iface->data.network.actual->trustGuestRxFilters - =3D iface->trustGuestRxFilters; - else if (portgroup && portgroup->trustGuestRxFilters) - iface->data.network.actual->trustGuestRxFilters - =3D portgroup->trustGuestRxFilters; - else if (netdef->trustGuestRxFilters) - iface->data.network.actual->trustGuestRxFilters - =3D netdef->trustGuestRxFilters; + if (!port->trustGuestRxFilters) { + if (portgroup && portgroup->trustGuestRxFilters) + port->trustGuestRxFilters =3D portgroup->trustGuestRxFilters; + else if (netdef->trustGuestRxFilters) + port->trustGuestRxFilters =3D netdef->trustGuestRxFilters; + } =20 /* merge virtualports from interface, network, and portgroup to * arrive at actual virtualport to use */ - if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtPortP= rofile, - iface->virtPortProfile, + if (virNetDevVPortProfileMerge3(&portprofile, + port->virtPortProfile, netdef->virtPortProfile, portgroup ? portgroup->virtPortProfile : NULL) <= 0) { - goto error; + goto error; + } + if (portprofile) { + VIR_FREE(port->virtPortProfile); + port->virtPortProfile =3D portprofile; } - virtport =3D iface->data.network.actual->virtPortProfile; =20 + VIR_DEBUG("Processing forward type %d", netdef->forward.type); switch ((virNetworkForwardType) netdef->forward.type) { case VIR_NETWORK_FORWARD_NONE: case VIR_NETWORK_FORWARD_NAT: @@ -4490,38 +4482,28 @@ networkAllocateActualDevice(virNetworkPtr net, * NETWORK; we just keep the info from the portgroup in * iface->data.network.actual */ - iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_NETWORK; + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_NETWORK; =20 - /* we also store the bridge device and macTableManager settings - * in iface->data.network.actual->data.bridge for later use - * after the domain's tap device is created (to attach to the - * bridge and set flood/learning mode on the tap device) - */ - if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, - netdef->bridge) < 0) + if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0) goto error; - iface->data.network.actual->data.bridge.macTableManager - =3D netdef->macTableManager; + port->plug.bridge.macTableManager =3D netdef->macTableManager; =20 - if (virtport) { + if (port->virtPortProfile) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(" not supported for = network " "'%s' which uses IP forwarding"), - virNetDevVPortTypeToString(virtport->virtPortTy= pe), + virNetDevVPortTypeToString(port->virtPortProfil= e->virtPortType), netdef->name); goto error; } =20 - if (networkPlugBandwidth(obj, &iface->mac, iface->bandwidth, - iface->data.network.actual ? - &iface->data.network.actual->class_id : N= ULL) < 0) + if (networkPlugBandwidth(obj, &port->mac, port->bandwidth, &port->= class_id) < 0) goto error; break; =20 case VIR_NETWORK_FORWARD_HOSTDEV: { - virDomainHostdevSubsysPCIBackendType backend; + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI; =20 - iface->data.network.actual->type =3D actualType =3D VIR_DOMAIN_NET= _TYPE_HOSTDEV; if (networkCreateInterfacePool(netdef) < 0) goto error; =20 @@ -4539,42 +4521,19 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->name); goto error; } - iface->data.network.actual->data.hostdev.def.parentnet =3D iface; - iface->data.network.actual->data.hostdev.def.info =3D &iface->info; - iface->data.network.actual->data.hostdev.def.mode =3D VIR_DOMAIN_H= OSTDEV_MODE_SUBSYS; - iface->data.network.actual->data.hostdev.def.managed =3D netdef->f= orward.managed ? 1 : 0; - iface->data.network.actual->data.hostdev.def.source.subsys.type = =3D dev->type; - iface->data.network.actual->data.hostdev.def.source.subsys.u.pci.a= ddr =3D dev->device.pci; - - switch (netdef->forward.driverName) { - case VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT: - backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT; - break; - case VIR_NETWORK_FORWARD_DRIVER_NAME_KVM: - backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM; - break; - case VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO: - backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; - break; - default: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unrecognized driver name value %d " - " in network '%s'"), - netdef->forward.driverName, netdef->name); - goto error; - } - iface->data.network.actual->data.hostdev.def.source.subsys.u.pci.b= ackend - =3D backend; + port->plug.hostdevpci.addr =3D dev->device.pci; + port->plug.hostdevpci.driver =3D netdef->forward.driverName; + port->plug.hostdevpci.managed =3D netdef->forward.managed; =20 - if (virtport) { + if (port->virtPortProfile) { /* make sure type is supported for hostdev connections */ - if (virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_8021Q= BG && - virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_8021Q= BH) { + if (port->virtPortProfile->virtPortType !=3D VIR_NETDEV_VPORT_= PROFILE_8021QBG && + port->virtPortProfile->virtPortType !=3D VIR_NETDEV_VPORT_= PROFILE_8021QBH) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(" not supported = for network " "'%s' which uses an SR-IOV Virtual Functi= on " "via PCI passthrough"), - virNetDevVPortTypeToString(virtport->virtPo= rtType), + virNetDevVPortTypeToString(port->virtPortPr= ofile->virtPortType), netdef->name); goto error; } @@ -4588,28 +4547,24 @@ networkAllocateActualDevice(virNetworkPtr net, * is VIR_DOMAIN_NET_TYPE_BRIDGE */ =20 - iface->data.network.actual->type =3D actualType =3D VIR_DOMAIN= _NET_TYPE_BRIDGE; - if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, - netdef->bridge) < 0) + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE; + if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0) goto error; - iface->data.network.actual->data.bridge.macTableManager - =3D netdef->macTableManager; + port->plug.bridge.macTableManager =3D netdef->macTableManager; =20 - if (virtport) { + if (port->virtPortProfile) { /* only type=3D'openvswitch' is allowed for bridges */ - if (virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_O= PENVSWITCH) { + if (port->virtPortProfile->virtPortType !=3D VIR_NETDEV_VP= ORT_PROFILE_OPENVSWITCH) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(" not suppor= ted for network " "'%s' which uses a bridge device"), - virNetDevVPortTypeToString(virtport->vi= rtPortType), + virNetDevVPortTypeToString(port->virtPo= rtProfile->virtPortType), netdef->name); goto error; } } =20 - if (networkPlugBandwidth(obj, &iface->mac, iface->bandwidth, - iface->data.network.actual ? - &iface->data.network.actual->class_id= : NULL) < 0) + if (networkPlugBandwidth(obj, &port->mac, port->bandwidth, &po= rt->class_id) < 0) goto error; break; } @@ -4627,22 +4582,22 @@ networkAllocateActualDevice(virNetworkPtr net, */ =20 /* Set type=3Ddirect and appropriate */ - iface->data.network.actual->type =3D actualType =3D VIR_DOMAIN_NET= _TYPE_DIRECT; + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_DIRECT; =20 /* NO need to check the value returned from virNetDevMacVLanModeTy= peFromString * it must be valid for these forward type(bridge|private|vepa|pas= sthrough) */ - iface->data.network.actual->data.direct.mode =3D + port->plug.direct.mode =3D virNetDevMacVLanModeTypeFromString(virNetworkForwardTypeToStri= ng(netdef->forward.type)); =20 - if (virtport) { + if (port->virtPortProfile) { /* make sure type is supported for macvtap connections */ - if (virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_8021Q= BG && - virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_8021Q= BH) { + if (port->virtPortProfile->virtPortType !=3D VIR_NETDEV_VPORT_= PROFILE_8021QBG && + port->virtPortProfile->virtPortType !=3D VIR_NETDEV_VPORT_= PROFILE_8021QBH) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(" not supported = for network " "'%s' which uses a macvtap device"), - virNetDevVPortTypeToString(virtport->virtPo= rtType), + virNetDevVPortTypeToString(port->virtPortPr= ofile->virtPortType), netdef->name); goto error; } @@ -4671,8 +4626,8 @@ networkAllocateActualDevice(virNetworkPtr net, */ if ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PASSTHROU= GH) || ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PRIVATE)= && - iface->data.network.actual->virtPortProfile && - (iface->data.network.actual->virtPortProfile->virtPortType + port->virtPortProfile && + (port->virtPortProfile->virtPortType =3D=3D VIR_NETDEV_VPORT_PROFILE_8021QBH))) { =20 /* pick first dev with 0 connections */ @@ -4698,7 +4653,7 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->name); goto error; } - if (VIR_STRDUP(iface->data.network.actual->data.direct.linkdev, + if (VIR_STRDUP(port->plug.direct.linkdev, dev->device.dev) < 0) goto error; } @@ -4711,30 +4666,30 @@ networkAllocateActualDevice(virNetworkPtr net, } =20 if (virNetworkObjMacMgrAdd(obj, driver->dnsmasqStateDir, - dom->name, &iface->mac) < 0) + dom->name, &port->mac) < 0) goto error; =20 - if (virNetDevVPortProfileCheckComplete(virtport, true) < 0) + if (virNetDevVPortProfileCheckComplete(port->virtPortProfile, true) < = 0) goto error; =20 /* make sure that everything now specified for the device is * actually supported on this type of network. NB: network, * netdev, and iface->data.network.actual may all be NULL. */ + VIR_DEBUG("Sanity check port config"); =20 - if (virDomainNetGetActualVlan(iface)) { + if (port->vlan.nTags) { /* vlan configuration via libvirt is only supported for PCI * Passthrough SR-IOV devices (hostdev or macvtap passthru * mode) and openvswitch bridges. Otherwise log an error and * fail */ - if (!(actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV || - (actualType =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT && - virDomainNetGetActualDirectMode(iface) - =3D=3D VIR_NETDEV_MACVLAN_MODE_PASSTHRU) || - (actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && - virtport && virtport->virtPortType - =3D=3D VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH))) { + if (!(port->plugtype =3D=3D VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI= || + (port->plugtype =3D=3D VIR_NETWORK_PORT_PLUG_TYPE_DIRECT && + port->plug.direct.mode =3D=3D VIR_NETDEV_MACVLAN_MODE_PASST= HRU) || + (port->plugtype =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && + port->virtPortProfile && + port->virtPortProfile->virtPortType =3D=3D VIR_NETDEV_VPORT= _PROFILE_OPENVSWITCH))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("an interface connecting to network '%s' " "is requesting a vlan tag, but that is not " @@ -4743,16 +4698,15 @@ networkAllocateActualDevice(virNetworkPtr net, goto error; } } - if (virDomainNetGetActualBandwidth(iface)) { - /* bandwidth configuration via libvirt is not supported for - * hostdev network devices - */ - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("bandwidth settings are not supported " - "for hostdev interfaces")); - goto error; - } + + /* bandwidth configuration via libvirt is not supported for + * hostdev network devices + */ + if (port->bandwidth && port->plugtype =3D=3D VIR_NETWORK_PORT_PLUG_TYP= E_HOSTDEV_PCI) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("bandwidth settings are not supported " + "for hostdev interfaces")); + goto error; } =20 netdef->connections++; @@ -4770,9 +4724,15 @@ networkAllocateActualDevice(virNetworkPtr net, } networkLogAllocation(netdef, dev, &iface->mac, true); =20 + VIR_DEBUG("Populating net def"); + if (virDomainNetDefActualFromNetworkPort(iface, port) < 0) + goto error; + + VIR_DEBUG("Port allocated"); ret =3D 0; =20 cleanup: + virNetworkPortDefFree(port); virNetworkObjEndAPI(&obj); return ret; =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848944; cv=none; d=zoho.com; s=zohoarc; b=XPBkqqdfjyug5Qgub/372fYEwfM/rasIvlZpD5DgrHVHL5pWaHD+NXjBJvN6hHxVp+3Y/J2JYDdYRVo/bbLOveUY3mW1QZj+P+TZsRYUHm+eOZLL84llLgLFZDxftsb3CZx04/5aheIsE2xL9ms8s6l/IUSa+pkVeT2q9+015DA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848944; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Equfr8gVvzXn0lyi5AZKgR66ElS0fsF5ze0UfgxrAvs=; b=jisCvVLuo+emQ6SJbXOztNx0PA6T/OWbhlqzxjwrjnDj+Kcid7iOn18ubLvvF0X/WpAEtAjO0qqEFocPpMvopOeO9BVVRwNwl9ozBuVN4ebCbl50fX/blAR9TU1/lW7L+fvvjNmiyxs1iyIyz4oO9/CF8IqKF5tiP4VgTfU9Ovc= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848944525496.05612993092325; Tue, 14 May 2019 08:49:04 -0700 (PDT) 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 C095E89C40; Tue, 14 May 2019 15:49:02 +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 99351608BC; Tue, 14 May 2019 15:49:02 +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 4CF291803507; Tue, 14 May 2019 15:49:02 +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 x4EFmlMg031769 for ; Tue, 14 May 2019 11:48:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9F11A60BCF; Tue, 14 May 2019 15:48:47 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA2CA600CD; Tue, 14 May 2019 15:48:46 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:18 +0100 Message-Id: <20190514154836.6427-7-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 06/24] network: convert networkNotifyActualDevice to virNetworkPortDef 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-Type: text/plain; charset="utf-8" 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.27]); Tue, 14 May 2019 15:49:03 +0000 (UTC) Convert the virDomainNetDef object into a virNetworkPortDef object at the start of networkNotifyActualDevice. This largely decouples the method impl from the domain object type. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 92 ++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index e5a42d7a7f..75f42155ee 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4762,10 +4762,10 @@ networkNotifyActualDevice(virNetworkPtr net, virDomainNetDefPtr iface) { virNetworkDriverStatePtr driver =3D networkGetDriver(); - virDomainNetType actualType =3D virDomainNetGetActualType(iface); virNetworkObjPtr obj; virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev =3D NULL; + virNetworkPortDefPtr port =3D NULL; size_t i; int ret =3D -1; =20 @@ -4792,40 +4792,35 @@ networkNotifyActualDevice(virNetworkPtr net, goto error; } =20 - if (!iface->data.network.actual || - (actualType !=3D VIR_DOMAIN_NET_TYPE_DIRECT && - actualType !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV)) { - VIR_DEBUG("Nothing to claim from network %s", iface->data.network.= name); - goto success; - } - - if (networkCreateInterfacePool(netdef) < 0) - goto error; + if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) + goto cleanup; =20 - if (netdef->forward.nifs =3D=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("network '%s' uses a direct or hostdev mode, " - "but has no forward dev and no interface pool"), - netdef->name); + switch (port->plugtype) { + case VIR_NETWORK_PORT_PLUG_TYPE_NONE: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpectedly got a network port without a plug")= ); goto error; - } =20 - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT) { - const char *actualDev; - - actualDev =3D virDomainNetGetActualDirectDev(iface); - if (!actualDev) { + case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK: + case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE: + /* see if we're connected to the correct bridge */ + if (!netdef->bridge) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("the interface uses a direct mode, " - "but has no source dev")); + _("Unexpectedly got a network port without a ne= twork bridge")); goto error; } + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT: + if (networkCreateInterfacePool(netdef) < 0) + goto error; =20 /* find the matching interface and increment its connections */ for (i =3D 0; i < netdef->forward.nifs; i++) { if (netdef->forward.ifs[i].type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV && - STREQ(actualDev, netdef->forward.ifs[i].device.dev)) { + STREQ(port->plug.direct.linkdev, + netdef->forward.ifs[i].device.dev)) { dev =3D &netdef->forward.ifs[i]; break; } @@ -4834,8 +4829,9 @@ networkNotifyActualDevice(virNetworkPtr net, if (!dev) { virReportError(VIR_ERR_INTERNAL_ERROR, _("network '%s' doesn't have dev=3D'%s' " - "in use by domain"), - netdef->name, actualDev); + "in use by network port '%s'"), + netdef->name, port->plug.direct.linkdev, + port->uuid); goto error; } =20 @@ -4846,31 +4842,26 @@ networkNotifyActualDevice(virNetworkPtr net, if ((dev->connections > 0) && ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PASSTHROUGH)= || ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PRIVATE) && - iface->data.network.actual->virtPortProfile && - (iface->data.network.actual->virtPortProfile->virtPortType - =3D=3D VIR_NETDEV_VPORT_PROFILE_8021QBH)))) { + port->virtPortProfile && + (port->virtPortProfile->virtPortType =3D=3D VIR_NETDEV_VPORT= _PROFILE_8021QBH)))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("network '%s' claims dev=3D'%s' is already in= " - "use by a different domain"), - netdef->name, actualDev); + "use by a different port"), + netdef->name, port->plug.direct.linkdev); goto error; } - } else /* if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) */ { - virDomainHostdevDefPtr hostdev; + break; =20 - hostdev =3D virDomainNetGetActualHostdev(iface); - if (!hostdev) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("the interface uses a hostdev mode, " - "but has no hostdev")); + case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: + + if (networkCreateInterfacePool(netdef) < 0) goto error; - } =20 /* find the matching interface and increment its connections */ for (i =3D 0; i < netdef->forward.nifs; i++) { if (netdef->forward.ifs[i].type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_PCI && - virPCIDeviceAddressEqual(&hostdev->source.subsys.u.pci.add= r, + virPCIDeviceAddressEqual(&port->plug.hostdevpci.addr, &netdef->forward.ifs[i].device.pc= i)) { dev =3D &netdef->forward.ifs[i]; break; @@ -4880,12 +4871,12 @@ networkNotifyActualDevice(virNetworkPtr net, if (!dev) { virReportError(VIR_ERR_INTERNAL_ERROR, _("network '%s' doesn't have " - "PCI device %04x:%02x:%02x.%x in use by domai= n"), + "PCI device %04x:%02x:%02x.%x in use by netwo= rk port"), netdef->name, - hostdev->source.subsys.u.pci.addr.domain, - hostdev->source.subsys.u.pci.addr.bus, - hostdev->source.subsys.u.pci.addr.slot, - hostdev->source.subsys.u.pci.addr.function); + port->plug.hostdevpci.addr.domain, + port->plug.hostdevpci.addr.bus, + port->plug.hostdevpci.addr.slot, + port->plug.hostdevpci.addr.function); goto error; } =20 @@ -4898,15 +4889,21 @@ networkNotifyActualDevice(virNetworkPtr net, virReportError(VIR_ERR_INTERNAL_ERROR, _("network '%s' claims the PCI device at " "domain=3D%d bus=3D%d slot=3D%d function=3D%d= " - "is already in use by a different domain"), + "is already in use by a different network por= t"), netdef->name, dev->device.pci.domain, dev->device.pci.bus, dev->device.pci.slot, dev->device.pci.function); goto error; } + + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_LAST: + default: + virReportEnumRangeError(virNetworkPortPlugType, port->plugtype); + goto error; } =20 - success: netdef->connections++; if (dev) dev->connections++; @@ -4924,6 +4921,7 @@ networkNotifyActualDevice(virNetworkPtr net, =20 cleanup: virNetworkObjEndAPI(&obj); + virNetworkPortDefFree(port); return ret; =20 error: --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848939; cv=none; d=zoho.com; s=zohoarc; b=e5En0qDBcUKKOuj5fFk1fG6bCLy0vYO1WIEibh4LVhUx5N+66oeqAYGxIXLvYy68fqLLWeqBXKzUDlsM9VAEaB1+YbjYPYXZ+AZLLES4d9HkY3cpj0e2H2ba85P732afeKqSFtcCmZx2m+y1fyYbdMYhvGBpnC0gVlFs45mbn6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848939; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=fRWErftu3tlApBJZHqX37XE00xudTehYFfYbr98eabA=; b=Ol4laQ3CUT5E1sj9TJ2gxNaN+7Ib6iJEDncV5LUVMGM07kkYp0Dn56DmpsS++Zk39azLjScd6eAUgHESJYRBDjLoXyWZvKmUg4QIs8ZahmArmerr6lR0HJWpua5DvvldmfF5Hd2iZ7p5+Cc4yAcIU1Qf7AZ8pANIrMNgAEHZ1m4= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15578489393162.180660990298179; Tue, 14 May 2019 08:48:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 704E23004158; Tue, 14 May 2019 15:48:57 +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 00D111001E91; Tue, 14 May 2019 15:48:56 +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 AF4233FB12; Tue, 14 May 2019 15:48:56 +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 x4EFmm2J031774 for ; Tue, 14 May 2019 11:48:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9503C2B9E3; Tue, 14 May 2019 15:48:48 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id E02FC600CD; Tue, 14 May 2019 15:48:47 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:19 +0100 Message-Id: <20190514154836.6427-8-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 07/24] network: convert networkReleaseActualDevice to virNetworkPortDef 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 14 May 2019 15:48:58 +0000 (UTC) Convert the virDomainNetDef object into a virNetworkPortDef object at the start of networkReleaseActualDevice. This largely decouples the method impl from the domain object type. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 140 +++++++++++++++--------------------- 1 file changed, 58 insertions(+), 82 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 75f42155ee..0b5073b7ab 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4946,10 +4946,10 @@ networkReleaseActualDevice(virNetworkPtr net, virDomainNetDefPtr iface) { virNetworkDriverStatePtr driver =3D networkGetDriver(); - virDomainNetType actualType =3D virDomainNetGetActualType(iface); virNetworkObjPtr obj; virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev =3D NULL; + virNetworkPortDefPtr port =3D NULL; size_t i; int ret =3D -1; =20 @@ -4958,77 +4958,50 @@ networkReleaseActualDevice(virNetworkPtr net, virReportError(VIR_ERR_NO_NETWORK, _("no network with matching name '%s'"), net->name); - goto error; + goto cleanup; } =20 if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Expected an interface for a virtual network")); - goto error; + goto cleanup; } =20 + if (iface->data.network.actual =3D=3D NULL) { + ret =3D 0; + goto cleanup; + } + + if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) + goto cleanup; + netdef =3D virNetworkObjGetDef(obj); =20 - switch ((virNetworkForwardType) netdef->forward.type) { - case VIR_NETWORK_FORWARD_NONE: - case VIR_NETWORK_FORWARD_NAT: - case VIR_NETWORK_FORWARD_ROUTE: - case VIR_NETWORK_FORWARD_OPEN: - if (iface->data.network.actual && - networkUnplugBandwidth(obj, iface->bandwidth, - &iface->data.network.actual->class_id) = < 0) - goto error; + switch ((virNetworkPortPlugType)port->plugtype) { + case VIR_NETWORK_PORT_PLUG_TYPE_NONE: + VIR_DEBUG("Releasing network device with no plug type"); break; =20 - case VIR_NETWORK_FORWARD_BRIDGE: - if (iface->data.network.actual && - actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && - networkUnplugBandwidth(obj, iface->bandwidth, - &iface->data.network.actual->class_id) = < 0) - goto error; - break; - case VIR_NETWORK_FORWARD_PRIVATE: - case VIR_NETWORK_FORWARD_VEPA: - case VIR_NETWORK_FORWARD_PASSTHROUGH: - case VIR_NETWORK_FORWARD_HOSTDEV: + case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK: + case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE: + if (networkUnplugBandwidth(obj, port->bandwidth, + &port->class_id) < 0) + goto cleanup; break; =20 - case VIR_NETWORK_FORWARD_LAST: - default: - virReportEnumRangeError(virNetworkForwardType, netdef->forward.typ= e); - goto error; - } - - if ((!iface->data.network.actual) || - ((actualType !=3D VIR_DOMAIN_NET_TYPE_DIRECT) && - (actualType !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV))) { - VIR_DEBUG("Nothing to release to network %s", iface->data.network.= name); - goto success; - } - - if (netdef->forward.nifs =3D=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("network '%s' uses a direct/hostdev mode, but " - "has no forward dev and no interface pool"), - netdef->name); - goto error; - } - - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT) { - const char *actualDev; - - actualDev =3D virDomainNetGetActualDirectDev(iface); - if (!actualDev) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("the interface uses a direct mode, " - "but has no source dev")); - goto error; + case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT: + if (netdef->forward.nifs =3D=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("network '%s' uses a direct mode, but " + "has no forward dev and no interface pool"), + netdef->name); + goto cleanup; } =20 for (i =3D 0; i < netdef->forward.nifs; i++) { if (netdef->forward.ifs[i].type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV && - STREQ(actualDev, netdef->forward.ifs[i].device.dev)) { + STREQ(port->plug.direct.linkdev, netdef->forward.ifs[i].de= vice.dev)) { dev =3D &netdef->forward.ifs[i]; break; } @@ -5038,23 +5011,24 @@ networkReleaseActualDevice(virNetworkPtr net, virReportError(VIR_ERR_INTERNAL_ERROR, _("network '%s' doesn't have dev=3D'%s' " "in use by domain"), - netdef->name, actualDev); - goto error; + netdef->name, port->plug.direct.linkdev); + goto cleanup; } - } else /* if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) */ { - virDomainHostdevDefPtr hostdev; + break; =20 - hostdev =3D virDomainNetGetActualHostdev(iface); - if (!hostdev) { + case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: + if (netdef->forward.nifs =3D=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("the interface uses a hostdev mode, but= has no hostdev")); - goto error; + _("network '%s' uses a hostdev mode, but " + "has no forward dev and no interface pool"), + netdef->name); + goto cleanup; } =20 for (i =3D 0; i < netdef->forward.nifs; i++) { if (netdef->forward.ifs[i].type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_PCI && - virPCIDeviceAddressEqual(&hostdev->source.subsys.u.pci.add= r, + virPCIDeviceAddressEqual(&port->plug.hostdevpci.addr, &netdef->forward.ifs[i].device.pc= i)) { dev =3D &netdef->forward.ifs[i]; break; @@ -5066,26 +5040,30 @@ networkReleaseActualDevice(virNetworkPtr net, _("network '%s' doesn't have " "PCI device %04x:%02x:%02x.%x in use by domai= n"), netdef->name, - hostdev->source.subsys.u.pci.addr.domain, - hostdev->source.subsys.u.pci.addr.bus, - hostdev->source.subsys.u.pci.addr.slot, - hostdev->source.subsys.u.pci.addr.function); - goto error; + port->plug.hostdevpci.addr.domain, + port->plug.hostdevpci.addr.bus, + port->plug.hostdevpci.addr.slot, + port->plug.hostdevpci.addr.function); + goto cleanup; } + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_LAST: + default: + virReportEnumRangeError(virNetworkPortPlugType, port->plugtype); + goto cleanup; } =20 - success: - virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, dom->name, &iface= ->mac); + virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, dom->name, &port-= >mac); + + netdef->connections--; + if (dev) + dev->connections--; + /* finally we can call the 'unplugged' hook script if any */ + networkRunHook(obj, dom, iface, VIR_HOOK_NETWORK_OP_IFACE_UNPLUGGED, + VIR_HOOK_SUBOP_BEGIN); + networkLogAllocation(netdef, dev, &port->mac, false); =20 - if (iface->data.network.actual) { - netdef->connections--; - if (dev) - dev->connections--; - /* finally we can call the 'unplugged' hook script if any */ - networkRunHook(obj, dom, iface, VIR_HOOK_NETWORK_OP_IFACE_UNPLUGGE= D, - VIR_HOOK_SUBOP_BEGIN); - networkLogAllocation(netdef, dev, &iface->mac, false); - } ret =3D 0; cleanup: virNetworkObjEndAPI(&obj); @@ -5093,10 +5071,8 @@ networkReleaseActualDevice(virNetworkPtr net, virDomainActualNetDefFree(iface->data.network.actual); iface->data.network.actual =3D NULL; } + virNetworkPortDefFree(port); return ret; - - error: - goto cleanup; } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848942; cv=none; d=zoho.com; s=zohoarc; b=UQbh65Gjzeo6tk1HAaiArh3xIjpJ4Z/ai+eGYft54AxxNenLFnRX1nvzT+qKdNzGTmsgdYjLdAvqgUu5SKdhxj4KoeErs3v6Uk1gaPU3beO62mBJ13Xm/K9oTBHDyWebNzaQ+V6xWymWRPojBTvRYvg81bCYvQypDgPG8PweDwQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848942; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=2zZA/pPmQJjLyJmprAXhg6v9ELtwxCOV5yIU6GN+aA0=; b=K+ZwBgVr67bxVf1ed+z9GXNv/2f8BlmOEZ+5O9/rVlacnCsLoWpibH28s+QOx0wPI4PkqWUg6EAFhvjnPZ74Lgzt8FeWWlltBa8q2WFG+D+2xPNamuarxKFD5aKv9HxU1s+n3ttgpXfInh1MjNGrwsQpfcXXH8MMgm6Av3srR7c= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848942461787.4767860205975; Tue, 14 May 2019 08:49:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92A27308795B; Tue, 14 May 2019 15: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 682741001943; Tue, 14 May 2019 15: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 2658918052ED; Tue, 14 May 2019 15: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 x4EFmnPQ031790 for ; Tue, 14 May 2019 11:48:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8C3C560BCF; Tue, 14 May 2019 15:48:49 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7309600C5; Tue, 14 May 2019 15:48:48 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:20 +0100 Message-Id: <20190514154836.6427-9-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 08/24] network: convert hook script to take a network port XML 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 14 May 2019 15:49:01 +0000 (UTC) When (un)plugging an interface into a network, the 'plugged' and 'unplugged' operations are invoked in the hook script. The data provided to the script contains the network XML, the domain XML and the domain interface XML. When we strictly split the drivers up this will no longer be possible and thus breakage is unavoidable. The hook scripts are not considered to be covered by the API guarantee so this is OK. To avoid existing scripts taking the wrong action, the existing operations are changed to 'port-created' and 'port-deleted' instead. These will receive the network XML and the network port XML. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- docs/hooks.html.in | 24 +++++++++++------------- src/network/bridge_driver.c | 27 +++++++++++---------------- src/util/virhook.c | 4 ++-- src/util/virhook.h | 4 ++-- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/docs/hooks.html.in b/docs/hooks.html.in index 2c4c39b771..7c9d3ef7f3 100644 --- a/docs/hooks.html.in +++ b/docs/hooks.html.in @@ -91,10 +91,8 @@ </network> </hookData> =20 -

In the case of an interface - being plugged/unplugged to/from the network, the network XML will be - followed with the full XML description of the domain containing the - interface that is being plugged/unplugged:

+

In the case of an network port being created / deleted, the network + XML will be followed with the full XML description of the port:

=20
<hookData>
   <network>
@@ -102,11 +100,11 @@
      <uuid>afca425a-2c3a-420c-b2fb-dd7b4950d722</uuid>
      ...
   </network>
-  <domain type=3D'$domain_type' id=3D'$domain_id'>
-     <name>$domain_name</name>
-     <uuid>afca425a-2c3a-420c-b2fb-dd7b4950d722</uuid>
-     ...
-  </domain>
+  <networkport>
+    <uuid>5d744f21-ba4a-4d6e-bdb2-30a35ff3207d</uuid>
+    ...
+    <plug type=3D'direct' dev=3D'ens3' mode=3D'vepa'/>
+  </networkport>
 </hookData>
=20

Please note that this approach is different from other cases such as @@ -296,15 +294,15 @@

/etc/libvirt/hooks/network network_name stopped end -
=
  • Later, when network is started and there's an interface from a domain to be plugged into the network, the hook script is called a= s:
    -
    /etc/libvirt/hooks/network network_name plugged begin -
    +          
    /etc/libvirt/hooks/network network_name port-created begin =
    -
    Please note, that in this case, the script is passed both network = and - domain XMLs on its stdin.
  • + port XMLs on its stdin.
  • When network is updated, the hook script is called as:
    /etc/libvirt/hooks/network network_name updated begin -
  • When the domain from previous case is shutting down, the interfa= ce is unplugged. This leads to another script invocation:
    -
    /etc/libvirt/hooks/network network_name unplugged begin -
    -        And again, as in previous case, both network and domain XMLs are p=
    assed
    +          
    /etc/libvirt/hooks/network network_name port-deleted begin =
    -
    + And again, as in previous case, both network and port XMLs are pas= sed onto script's stdin.
  • =20 diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 0b5073b7ab..88cd3e8c15 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -205,14 +205,13 @@ networkObjFromNetwork(virNetworkPtr net) =20 static int networkRunHook(virNetworkObjPtr obj, - virDomainDefPtr dom, - virDomainNetDefPtr iface, + virNetworkPortDefPtr port, int op, int sub_op) { virNetworkDefPtr def; virBuffer buf =3D VIR_BUFFER_INITIALIZER; - char *xml =3D NULL, *net_xml =3D NULL, *dom_xml =3D NULL; + char *xml =3D NULL; int hookret; int ret =3D -1; =20 @@ -226,11 +225,9 @@ networkRunHook(virNetworkObjPtr obj, =20 virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); - if (iface && virDomainNetDefFormat(&buf, iface, NULL, 0) < 0) - goto cleanup; if (virNetworkDefFormatBuf(&buf, def, 0) < 0) goto cleanup; - if (dom && virDomainDefFormatInternal(dom, NULL, 0, &buf, NULL) < = 0) + if (port && virNetworkPortDefFormatBuf(&buf, port) < 0) goto cleanup; =20 virBufferAdjustIndent(&buf, -2); @@ -256,8 +253,6 @@ networkRunHook(virNetworkObjPtr obj, cleanup: virBufferFreeAndReset(&buf); VIR_FREE(xml); - VIR_FREE(net_xml); - VIR_FREE(dom_xml); return ret; } =20 @@ -2784,7 +2779,7 @@ networkStartNetwork(virNetworkDriverStatePtr driver, =20 /* Run an early hook to set-up missing devices. * If the script raised an error abort the launch. */ - if (networkRunHook(obj, NULL, NULL, + if (networkRunHook(obj, NULL, VIR_HOOK_NETWORK_OP_START, VIR_HOOK_SUBOP_BEGIN) < 0) goto cleanup; @@ -2828,7 +2823,7 @@ networkStartNetwork(virNetworkDriverStatePtr driver, virNetworkObjSetFloorSum(obj, 0); =20 /* finally we can call the 'started' hook script if any */ - if (networkRunHook(obj, NULL, NULL, + if (networkRunHook(obj, NULL, VIR_HOOK_NETWORK_OP_STARTED, VIR_HOOK_SUBOP_BEGIN) < 0) goto cleanup; @@ -2912,7 +2907,7 @@ networkShutdownNetwork(virNetworkDriverStatePtr drive= r, } =20 /* now that we know it's stopped call the hook if present */ - networkRunHook(obj, NULL, NULL, VIR_HOOK_NETWORK_OP_STOPPED, + networkRunHook(obj, NULL, VIR_HOOK_NETWORK_OP_STOPPED, VIR_HOOK_SUBOP_END); =20 virNetworkObjSetActive(obj, false); @@ -3888,7 +3883,7 @@ networkUpdate(virNetworkPtr net, } =20 /* call the 'updated' network hook script */ - if (networkRunHook(obj, NULL, NULL, VIR_HOOK_NETWORK_OP_UPDATED, + if (networkRunHook(obj, NULL, VIR_HOOK_NETWORK_OP_UPDATED, VIR_HOOK_SUBOP_BEGIN) < 0) goto cleanup; =20 @@ -4713,8 +4708,8 @@ networkAllocateActualDevice(virNetworkPtr net, if (dev) dev->connections++; /* finally we can call the 'plugged' hook script if any */ - if (networkRunHook(obj, dom, iface, - VIR_HOOK_NETWORK_OP_IFACE_PLUGGED, + if (networkRunHook(obj, port, + VIR_HOOK_NETWORK_OP_PORT_CREATED, VIR_HOOK_SUBOP_BEGIN) < 0) { /* adjust for failure */ netdef->connections--; @@ -4908,7 +4903,7 @@ networkNotifyActualDevice(virNetworkPtr net, if (dev) dev->connections++; /* finally we can call the 'plugged' hook script if any */ - if (networkRunHook(obj, dom, iface, VIR_HOOK_NETWORK_OP_IFACE_PLUGGED, + if (networkRunHook(obj, port, VIR_HOOK_NETWORK_OP_PORT_CREATED, VIR_HOOK_SUBOP_BEGIN) < 0) { /* adjust for failure */ if (dev) @@ -5060,7 +5055,7 @@ networkReleaseActualDevice(virNetworkPtr net, if (dev) dev->connections--; /* finally we can call the 'unplugged' hook script if any */ - networkRunHook(obj, dom, iface, VIR_HOOK_NETWORK_OP_IFACE_UNPLUGGED, + networkRunHook(obj, port, VIR_HOOK_NETWORK_OP_PORT_DELETED, VIR_HOOK_SUBOP_BEGIN); networkLogAllocation(netdef, dev, &port->mac, false); =20 diff --git a/src/util/virhook.c b/src/util/virhook.c index 57549ef8e5..84b3954872 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -100,8 +100,8 @@ VIR_ENUM_IMPL(virHookNetworkOp, "start", "started", "stopped", - "plugged", - "unplugged", + "port-created", + "port-deleted", "updated", ); =20 diff --git a/src/util/virhook.h b/src/util/virhook.h index 034fb8f263..fa188c89e3 100644 --- a/src/util/virhook.h +++ b/src/util/virhook.h @@ -79,8 +79,8 @@ typedef enum { VIR_HOOK_NETWORK_OP_START, /* network is about to start */ VIR_HOOK_NETWORK_OP_STARTED, /* network has start */ VIR_HOOK_NETWORK_OP_STOPPED, /* network has stopped */ - VIR_HOOK_NETWORK_OP_IFACE_PLUGGED, /* an interface has been plugged i= nto the network */ - VIR_HOOK_NETWORK_OP_IFACE_UNPLUGGED, /* an interface was unplugged = from the network */ + VIR_HOOK_NETWORK_OP_PORT_CREATED, /* port has been created in the ne= twork */ + VIR_HOOK_NETWORK_OP_PORT_DELETED, /* port has been deleted in the ne= twork */ VIR_HOOK_NETWORK_OP_UPDATED, /* network has been updated */ =20 VIR_HOOK_NETWORK_OP_LAST, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848936; cv=none; d=zoho.com; s=zohoarc; b=W0I07UfBTZ9tysno0J4TlCU9YFAwpMCH8gRFP3dzd4lvfPq/jfrOAOkqtsIXCAEAQK90UA2I5z6i13YzK/GpVS3E0gmS/lC4sJSnE2bLV+2ql0Xj8kBRInxlTzUoJn7wL+YbU8W86+NnsFExXGYEC4TU6R25LRdq4yGli950OvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848936; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=nZqNDcq7418erjw6qgD40vbpMi7drov11jASzN2wxJM=; b=OCozYluSCibfwqdxUrO4sjZw1MEPK/tAtA5uVsYIAM0wkiqurrKJ6zPWWslNaKUAbm85K2pbgclJj7xsqQl2UNszR7cIME9eSMtWuJDOrjNBOmSghcskYugQDD2udzPrTWXT4c41KCvjEg3jnXFn/WNP9ZKjwh8jRixghi8mqLE= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848936226407.483315569057; Tue, 14 May 2019 08:48:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3085B301EA82; Tue, 14 May 2019 15:48:54 +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 0A3405D729; Tue, 14 May 2019 15:48:54 +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 C351B18089D9; Tue, 14 May 2019 15:48:53 +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 x4EFmoMp031799 for ; Tue, 14 May 2019 11:48:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8359C60BCF; Tue, 14 May 2019 15:48:50 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDEFF600C5; Tue, 14 May 2019 15:48:49 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:21 +0100 Message-Id: <20190514154836.6427-10-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 09/24] network: remove the virDomainNetBandwidthChangeAllowed callback 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-Type: text/plain; charset="utf-8" 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 14 May 2019 15:48:54 +0000 (UTC) The current qemu driver code for changing bandwidth on a NIC first asks the network driver if the change is supported, then changes the bandwidth on the VIF, and then tells the network driver to update the bandwidth on the bridge. This is potentially racing if a parallel API call causes the network driver to allocate bandwidth on the bridge between the check and the update phases. Change the code to just try to apply the network bridge update immediately and rollback at the end if something failed. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_conf.c | 15 -------- src/conf/domain_conf.h | 10 ----- src/libvirt_private.syms | 1 - src/network/bridge_driver.c | 77 ++++++++----------------------------- src/qemu/qemu_driver.c | 8 ++-- 5 files changed, 21 insertions(+), 90 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7569b1b580..1d2ad0fa92 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30660,7 +30660,6 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr = dom, static virDomainNetAllocateActualDeviceImpl netAllocate; static virDomainNetNotifyActualDeviceImpl netNotify; static virDomainNetReleaseActualDeviceImpl netRelease; -static virDomainNetBandwidthChangeAllowedImpl netBandwidthChangeAllowed; static virDomainNetBandwidthUpdateImpl netBandwidthUpdate; =20 =20 @@ -30668,13 +30667,11 @@ void virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate, virDomainNetNotifyActualDeviceImpl notify, virDomainNetReleaseActualDeviceImpl release, - virDomainNetBandwidthChangeAllowedImpl bandwidth= ChangeAllowed, virDomainNetBandwidthUpdateImpl bandwidthUpdate) { netAllocate =3D allocate; netNotify =3D notify; netRelease =3D release; - netBandwidthChangeAllowed =3D bandwidthChangeAllowed; netBandwidthUpdate =3D bandwidthUpdate; } =20 @@ -30757,18 +30754,6 @@ virDomainNetReleaseActualDevice(virConnectPtr conn, return ret; } =20 -bool -virDomainNetBandwidthChangeAllowed(virDomainNetDefPtr iface, - virNetDevBandwidthPtr newBandwidth) -{ - if (!netBandwidthChangeAllowed) { - virReportError(VIR_ERR_NO_SUPPORT, "%s", - _("Virtual networking driver is not available")); - return -1; - } - - return netBandwidthChangeAllowed(iface, newBandwidth); -} =20 int virDomainNetBandwidthUpdate(virDomainNetDefPtr iface, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c0a94e3b5a..a584925fc7 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3584,10 +3584,6 @@ typedef int virDomainDefPtr dom, virDomainNetDefPtr iface); =20 -typedef bool -(*virDomainNetBandwidthChangeAllowedImpl)(virDomainNetDefPtr iface, - virNetDevBandwidthPtr newBandwid= th); - typedef int (*virDomainNetBandwidthUpdateImpl)(virDomainNetDefPtr iface, virNetDevBandwidthPtr newBandwidth); @@ -3597,7 +3593,6 @@ void virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate, virDomainNetNotifyActualDeviceImpl notify, virDomainNetReleaseActualDeviceImpl release, - virDomainNetBandwidthChangeAllowedImpl bandwidth= ChangeAllowed, virDomainNetBandwidthUpdateImpl bandwidthUpdate); =20 int @@ -3618,11 +3613,6 @@ virDomainNetReleaseActualDevice(virConnectPtr conn, virDomainNetDefPtr iface) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 -bool -virDomainNetBandwidthChangeAllowed(virDomainNetDefPtr iface, - virNetDevBandwidthPtr newBandwidth) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); - int virDomainNetBandwidthUpdate(virDomainNetDefPtr iface, virNetDevBandwidthPtr newBandwidth) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6646fc5039..c5e5c2d144 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -456,7 +456,6 @@ virDomainMemorySourceTypeFromString; virDomainMemorySourceTypeToString; virDomainNetAllocateActualDevice; virDomainNetAppendIPAddress; -virDomainNetBandwidthChangeAllowed; virDomainNetBandwidthUpdate; virDomainNetDefActualFromNetworkPort; virDomainNetDefActualToNetworkPort; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 88cd3e8c15..ec2f5e92ee 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -5356,64 +5356,6 @@ networkNetworkObjTaint(virNetworkObjPtr obj, } =20 =20 -static bool -networkBandwidthGenericChecks(virDomainNetDefPtr iface, - virNetDevBandwidthPtr newBandwidth) -{ - virNetDevBandwidthPtr ifaceBand; - unsigned long long old_floor, new_floor; - - if (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_NETWORK = && - (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_BRIDGE = || - iface->data.network.actual->data.bridge.brname =3D=3D NULL)) { - /* This is not an interface that's plugged into a network. - * We don't care. Thus from our POV bandwidth change is allowed. */ - return false; - } - - ifaceBand =3D virDomainNetGetActualBandwidth(iface); - old_floor =3D new_floor =3D 0; - - if (ifaceBand && ifaceBand->in) - old_floor =3D ifaceBand->in->floor; - if (newBandwidth && newBandwidth->in) - new_floor =3D newBandwidth->in->floor; - - return new_floor !=3D old_floor; -} - - -static bool -networkBandwidthChangeAllowed(virDomainNetDefPtr iface, - virNetDevBandwidthPtr newBandwidth) -{ - virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj =3D NULL; - virNetDevBandwidthPtr ifaceBand =3D virDomainNetGetActualBandwidth(ifa= ce); - bool ret =3D false; - - if (!networkBandwidthGenericChecks(iface, newBandwidth)) - return true; - - obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - iface->data.network.name); - return false; - } - - if (networkCheckBandwidth(obj, newBandwidth, ifaceBand, &iface->mac, N= ULL) < 0) - goto cleanup; - - ret =3D true; - - cleanup: - virNetworkObjEndAPI(&obj); - return ret; -} - - static int networkBandwidthUpdate(virDomainNetDefPtr iface, virNetDevBandwidthPtr newBandwidth) @@ -5424,6 +5366,7 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, unsigned long long tmp_floor_sum; virNetDevBandwidthPtr ifaceBand =3D virDomainNetGetActualBandwidth(ifa= ce); unsigned long long new_rate =3D 0; + unsigned long long old_floor, new_floor; int plug_ret; int ret =3D -1; =20 @@ -5433,7 +5376,22 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, return -1; } =20 - if (!networkBandwidthGenericChecks(iface, newBandwidth)) + if (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_NETWORK = && + (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_BRIDGE = || + iface->data.network.actual->data.bridge.brname !=3D NULL)) { + /* This is not an interface that's plugged into a bridge. + * We don't care. Thus from our POV bandwidth change is allowed. */ + return 0; + } + + old_floor =3D new_floor =3D 0; + + if (ifaceBand && ifaceBand->in) + old_floor =3D ifaceBand->in->floor; + if (newBandwidth && newBandwidth->in) + new_floor =3D newBandwidth->in->floor; + + if (new_floor =3D=3D old_floor) return 0; =20 obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); @@ -5579,7 +5537,6 @@ networkRegister(void) networkAllocateActualDevice, networkNotifyActualDevice, networkReleaseActualDevice, - networkBandwidthChangeAllowed, networkBandwidthUpdate); =20 return 0; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f01282a037..08995c1c0e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11625,17 +11625,17 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, } =20 if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - !virDomainNetBandwidthChangeAllowed(net, newBandwidth)) + virDomainNetBandwidthUpdate(net, newBandwidth) < 0) goto endjob; =20 if (virNetDevBandwidthSet(net->ifname, newBandwidth, false, - !virDomainNetTypeSharesHostView(net)) < = 0 || - (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - virDomainNetBandwidthUpdate(net, newBandwidth) < 0)) { + !virDomainNetTypeSharesHostView(net)) < = 0) { ignore_value(virNetDevBandwidthSet(net->ifname, net->bandwidth, false, !virDomainNetTypeSharesHost= View(net))); + ignore_value(virDomainNetBandwidthUpdate(net, + net->bandwidth)); goto endjob; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848939; cv=none; d=zoho.com; s=zohoarc; b=K616frMq2IEE7wugOy37XMZw/RO93qaE5FqCaaC8uOBJI+j+vg1LvU9KzhTIWu9BAXL+PBUdYEBnzXFaKiCaP82oEvBVOMPbpEyjMIovX+aSjaNFikjRkF9r9x15bn9Yn3qoYWHQHPSoLATLSqO0FpFnJsYrU7NKJjAUUWaSpwc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848939; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ne5H8aeGNxW5pgBbs+u/0JJ/stYyv4qTIuN7G7J0GxY=; b=hAtDcoQeD6efO1zdQM2Y3FADA0C542mniHUXN13qSxVTBd8a2UQHymcxaFMrHrOQh9f1eM6QwDC7kK0Jfoo6wBzsh89btBCNk2W8dmU13/DVugX5knJN3b0vvpNVDY+Q6OEJ+n7dMhUCujeJkSgqFNtH7WcCg2LLoqREIcbTZ+w= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848939367590.3196855323065; Tue, 14 May 2019 08:48:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F93D30198AF; Tue, 14 May 2019 15:48:57 +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 74E0B9F7F; Tue, 14 May 2019 15:48:57 +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 322A33FB16; Tue, 14 May 2019 15:48:57 +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 x4EFmpEp031811 for ; Tue, 14 May 2019 11:48:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 78E2360BCF; Tue, 14 May 2019 15:48:51 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4901600C5; Tue, 14 May 2019 15:48:50 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:22 +0100 Message-Id: <20190514154836.6427-11-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 10/24] network: introduce networkAllocatePort 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-Type: text/plain; charset="utf-8" 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 14 May 2019 15:48:58 +0000 (UTC) Separate network port allocation code from the domain driver network callback implementation. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 143 +++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 66 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index ec2f5e92ee..0954b5515b 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4366,60 +4366,38 @@ networkLogAllocation(virNetworkDefPtr netdef, * "backend" function table. */ =20 -/* networkAllocateActualDevice: - * @dom: domain definition that @iface belongs to - * @iface: the original NetDef from the domain +/* networkAllocatePort: + * @obj: the network to allocate from + * @port: the port definition to allocate * - * Looks up the network reference by iface, allocates a physical + * Looks up the network reference by port, allocates a physical * device from that network (if appropriate), and returns with the - * virDomainActualNetDef filled in accordingly. If there are no - * changes to be made in the netdef, then just leave the actualdef - * empty. + * port configuration filled in accordingly. * * Returns 0 on success, -1 on failure. */ static int -networkAllocateActualDevice(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface) +networkAllocatePort(virNetworkObjPtr obj, + virNetworkPortDefPtr port) { virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj =3D NULL; virNetworkDefPtr netdef =3D NULL; virPortGroupDefPtr portgroup =3D NULL; virNetworkForwardIfDefPtr dev =3D NULL; size_t i; int ret =3D -1; virNetDevVPortProfilePtr portprofile =3D NULL; - virNetworkPortDefPtr port =3D NULL; - - VIR_DEBUG("Allocating port from net %s", net->name); - obj =3D virNetworkObjFindByName(driver->networks, net->name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - net->name); - goto error; - } - - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - goto error; - } =20 netdef =3D virNetworkObjGetDef(obj); + VIR_DEBUG("Allocating port from net %s", netdef->name); =20 if (!virNetworkObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("network '%s' is not active"), netdef->name); - goto error; + goto cleanup; } =20 - if (!(port =3D virDomainNetDefToNetworkPort(dom, iface))) - goto error; - VIR_DEBUG("Interface port group %s", port->group); /* portgroup can be present for any type of network, in particular * for bandwidth information, so we need to check for that and @@ -4431,7 +4409,7 @@ networkAllocateActualDevice(virNetworkPtr net, if (portgroup && portgroup->bandwidth && virNetDevBandwidthCopy(&port->bandwidth, portgroup->bandwidth) < 0) - goto error; + goto cleanup; } =20 if (port->vlan.nTags =3D=3D 0) { @@ -4442,7 +4420,7 @@ networkAllocateActualDevice(virNetworkPtr net, vlan =3D &netdef->vlan; =20 if (vlan && virNetDevVlanCopy(&port->vlan, vlan) < 0) - goto error; + goto cleanup; } =20 if (!port->trustGuestRxFilters) { @@ -4460,7 +4438,7 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->virtPortProfile, portgroup ? portgroup->virtPortProfile : NULL) <= 0) { - goto error; + goto cleanup; } if (portprofile) { VIR_FREE(port->virtPortProfile); @@ -4480,7 +4458,7 @@ networkAllocateActualDevice(virNetworkPtr net, port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_NETWORK; =20 if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0) - goto error; + goto cleanup; port->plug.bridge.macTableManager =3D netdef->macTableManager; =20 if (port->virtPortProfile) { @@ -4489,18 +4467,18 @@ networkAllocateActualDevice(virNetworkPtr net, "'%s' which uses IP forwarding"), virNetDevVPortTypeToString(port->virtPortProfil= e->virtPortType), netdef->name); - goto error; + goto cleanup; } =20 if (networkPlugBandwidth(obj, &port->mac, port->bandwidth, &port->= class_id) < 0) - goto error; + goto cleanup; break; =20 case VIR_NETWORK_FORWARD_HOSTDEV: { port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI; =20 if (networkCreateInterfacePool(netdef) < 0) - goto error; + goto cleanup; =20 /* pick first dev with 0 connections */ for (i =3D 0; i < netdef->forward.nifs; i++) { @@ -4514,7 +4492,7 @@ networkAllocateActualDevice(virNetworkPtr net, _("network '%s' requires exclusive access " "to interfaces, but none are available"), netdef->name); - goto error; + goto cleanup; } port->plug.hostdevpci.addr =3D dev->device.pci; port->plug.hostdevpci.driver =3D netdef->forward.driverName; @@ -4530,7 +4508,7 @@ networkAllocateActualDevice(virNetworkPtr net, "via PCI passthrough"), virNetDevVPortTypeToString(port->virtPortPr= ofile->virtPortType), netdef->name); - goto error; + goto cleanup; } } break; @@ -4544,7 +4522,7 @@ networkAllocateActualDevice(virNetworkPtr net, =20 port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE; if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0) - goto error; + goto cleanup; port->plug.bridge.macTableManager =3D netdef->macTableManager; =20 if (port->virtPortProfile) { @@ -4555,12 +4533,12 @@ networkAllocateActualDevice(virNetworkPtr net, "'%s' which uses a bridge device"), virNetDevVPortTypeToString(port->virtPo= rtProfile->virtPortType), netdef->name); - goto error; + goto cleanup; } } =20 if (networkPlugBandwidth(obj, &port->mac, port->bandwidth, &po= rt->class_id) < 0) - goto error; + goto cleanup; break; } =20 @@ -4594,7 +4572,7 @@ networkAllocateActualDevice(virNetworkPtr net, "'%s' which uses a macvtap device"), virNetDevVPortTypeToString(port->virtPortPr= ofile->virtPortType), netdef->name); - goto error; + goto cleanup; } } =20 @@ -4606,12 +4584,12 @@ networkAllocateActualDevice(virNetworkPtr net, _("network '%s' uses a direct mode, but " "has no forward dev and no interface pool"), netdef->name); - goto error; + goto cleanup; } else { /* pick an interface from the pool */ =20 if (networkCreateInterfacePool(netdef) < 0) - goto error; + goto cleanup; =20 /* PASSTHROUGH mode, and PRIVATE Mode + 802.1Qbh both * require exclusive access to a device, so current @@ -4646,26 +4624,26 @@ networkAllocateActualDevice(virNetworkPtr net, _("network '%s' requires exclusive access " "to interfaces, but none are available"), netdef->name); - goto error; + goto cleanup; } if (VIR_STRDUP(port->plug.direct.linkdev, dev->device.dev) < 0) - goto error; + goto cleanup; } break; =20 case VIR_NETWORK_FORWARD_LAST: default: virReportEnumRangeError(virNetworkForwardType, netdef->forward.typ= e); - goto error; + goto cleanup; } =20 if (virNetworkObjMacMgrAdd(obj, driver->dnsmasqStateDir, - dom->name, &port->mac) < 0) - goto error; + port->ownername, &port->mac) < 0) + goto cleanup; =20 if (virNetDevVPortProfileCheckComplete(port->virtPortProfile, true) < = 0) - goto error; + goto cleanup; =20 /* make sure that everything now specified for the device is * actually supported on this type of network. NB: network, @@ -4690,7 +4668,7 @@ networkAllocateActualDevice(virNetworkPtr net, "is requesting a vlan tag, but that is not " "supported for this type of network"), netdef->name); - goto error; + goto cleanup; } } =20 @@ -4701,7 +4679,7 @@ networkAllocateActualDevice(virNetworkPtr net, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("bandwidth settings are not supported " "for hostdev interfaces")); - goto error; + goto cleanup; } =20 netdef->connections++; @@ -4715,28 +4693,61 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->connections--; if (dev) dev->connections--; - goto error; + goto cleanup; } - networkLogAllocation(netdef, dev, &iface->mac, true); - - VIR_DEBUG("Populating net def"); - if (virDomainNetDefActualFromNetworkPort(iface, port) < 0) - goto error; + networkLogAllocation(netdef, dev, &port->mac, true); =20 VIR_DEBUG("Port allocated"); - ret =3D 0; =20 + ret =3D 0; cleanup: - virNetworkPortDefFree(port); - virNetworkObjEndAPI(&obj); return ret; +} =20 - error: - if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + +static int +networkAllocateActualDevice(virNetworkPtr net, + virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virNetworkPortDefPtr port =3D NULL; + virNetworkObjPtr obj; + int ret =3D -1; + + obj =3D virNetworkObjFindByName(driver->networks, net->name); + if (!obj) { + virReportError(VIR_ERR_NO_NETWORK, + _("no network with matching name '%s'"), + net->name); + return -1; + } + + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected an interface for a virtual network")); + goto cleanup; + } + + if (!(port =3D virDomainNetDefToNetworkPort(dom, iface))) + goto cleanup; + + if (networkAllocatePort(obj, port) < 0) + goto cleanup; + + VIR_DEBUG("Populating net def"); + if (virDomainNetDefActualFromNetworkPort(iface, port) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + if (ret < 0) { virDomainActualNetDefFree(iface->data.network.actual); iface->data.network.actual =3D NULL; } - goto cleanup; + virNetworkPortDefFree(port); + virNetworkObjEndAPI(&obj); + return ret; } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848942; cv=none; d=zoho.com; s=zohoarc; b=XoZfvalk4QFztbU4b0Pf8LACkQZ+dVUUX9obWn7sWuD3LjJKtxep55noqoilv5C5xf84zgIsJ00NnWnxuIdyb7hLYz0TZTsCeSmKqXPUA4kc4c30GyfBtv8cTmQEpIP8fLOKhuldj2EbeOCLhnx0inLzek+pokdLYOKwtEvvebY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848942; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=1xOnmvsDkUNoDeg2+h4BlzP2QM0omChjAtD27jGmUmc=; b=YhHo3MRjpVIXIkWgJMhO9j9g3CUPo7esdWVUt4Q/dawNC3WRKgGzkpciGTmLySg7ArhVF/K6aa1m7fl/w+AkF49GAb4aHB+kAW5OoHcQtEx647PL63fv7fgju0hsdfnEtOAPvwFKphRPKsmvo5nKAfaLNYOyAjXfz1sRmFmndM4= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155784894282474.99123567641914; Tue, 14 May 2019 08:49:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4196C301BE65; Tue, 14 May 2019 15:49:01 +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 0C75F2B9E3; Tue, 14 May 2019 15:49:01 +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 BF5A53FAF5; Tue, 14 May 2019 15: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 x4EFmqON031816 for ; Tue, 14 May 2019 11:48:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E16319808; Tue, 14 May 2019 15:48:52 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA106600C5; Tue, 14 May 2019 15:48:51 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:23 +0100 Message-Id: <20190514154836.6427-12-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 11/24] network: introduce networkNotifyPort 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-Type: text/plain; charset="utf-8" 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 14 May 2019 15:49:01 +0000 (UTC) Separate network port notification code from the domain driver network callback implementation. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 106 +++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 43 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 0954b5515b..7446978be4 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4751,61 +4751,38 @@ networkAllocateActualDevice(virNetworkPtr net, } =20 =20 -/* networkNotifyActualDevice: - * @dom: domain definition that @iface belongs to - * @iface: the domain's NetDef with an "actual" device already filled in. +/* networkNotifyPort: + * @obj: the network to notify + * @port: the port definition to notify * * Called to notify the network driver when libvirtd is restarted and * finds an already running domain. If appropriate it will force an * allocation of the actual->direct.linkdev to get everything back in * order. - * - * Returns 0 on success, -1 on failure. */ static int -networkNotifyActualDevice(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface) +networkNotifyPort(virNetworkObjPtr obj, + virNetworkPortDefPtr port) { - virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj; virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev =3D NULL; - virNetworkPortDefPtr port =3D NULL; size_t i; int ret =3D -1; =20 - obj =3D virNetworkObjFindByName(driver->networks, net->name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - net->name); - goto error; - } - - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - goto error; - } - netdef =3D virNetworkObjGetDef(obj); =20 if (!virNetworkObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("network '%s' is not active"), netdef->name); - goto error; - } - - if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) goto cleanup; + } =20 switch (port->plugtype) { case VIR_NETWORK_PORT_PLUG_TYPE_NONE: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unexpectedly got a network port without a plug")= ); - goto error; + goto cleanup; =20 case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK: case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE: @@ -4813,13 +4790,13 @@ networkNotifyActualDevice(virNetworkPtr net, if (!netdef->bridge) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unexpectedly got a network port without a ne= twork bridge")); - goto error; + goto cleanup; } break; =20 case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT: if (networkCreateInterfacePool(netdef) < 0) - goto error; + goto cleanup; =20 /* find the matching interface and increment its connections */ for (i =3D 0; i < netdef->forward.nifs; i++) { @@ -4838,7 +4815,7 @@ networkNotifyActualDevice(virNetworkPtr net, "in use by network port '%s'"), netdef->name, port->plug.direct.linkdev, port->uuid); - goto error; + goto cleanup; } =20 /* PASSTHROUGH mode and PRIVATE Mode + 802.1Qbh both require @@ -4854,14 +4831,14 @@ networkNotifyActualDevice(virNetworkPtr net, _("network '%s' claims dev=3D'%s' is already in= " "use by a different port"), netdef->name, port->plug.direct.linkdev); - goto error; + goto cleanup; } break; =20 case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: =20 if (networkCreateInterfacePool(netdef) < 0) - goto error; + goto cleanup; =20 /* find the matching interface and increment its connections */ for (i =3D 0; i < netdef->forward.nifs; i++) { @@ -4883,7 +4860,7 @@ networkNotifyActualDevice(virNetworkPtr net, port->plug.hostdevpci.addr.bus, port->plug.hostdevpci.addr.slot, port->plug.hostdevpci.addr.function); - goto error; + goto cleanup; } =20 /* PASSTHROUGH mode, PRIVATE Mode + 802.1Qbh, and hostdev (PCI @@ -4899,7 +4876,7 @@ networkNotifyActualDevice(virNetworkPtr net, netdef->name, dev->device.pci.domain, dev->device.pci.bus, dev->device.pci.slot, dev->device.pci.function); - goto error; + goto cleanup; } =20 break; @@ -4907,7 +4884,7 @@ networkNotifyActualDevice(virNetworkPtr net, case VIR_NETWORK_PORT_PLUG_TYPE_LAST: default: virReportEnumRangeError(virNetworkPortPlugType, port->plugtype); - goto error; + goto cleanup; } =20 netdef->connections++; @@ -4920,18 +4897,61 @@ networkNotifyActualDevice(virNetworkPtr net, if (dev) dev->connections--; netdef->connections--; - goto error; + goto cleanup; } - networkLogAllocation(netdef, dev, &iface->mac, true); + networkLogAllocation(netdef, dev, &port->mac, true); + ret =3D 0; + cleanup: + return ret; +} + + +static int +networkNotifyActualDevice(virNetworkPtr net, + virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virNetworkObjPtr obj; + virNetworkDefPtr netdef; + virNetworkPortDefPtr port =3D NULL; + int ret =3D -1; + + obj =3D virNetworkObjFindByName(driver->networks, net->name); + if (!obj) { + virReportError(VIR_ERR_NO_NETWORK, + _("no network with matching name '%s'"), + net->name); + goto cleanup; + } =20 + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected an interface for a virtual network")); + goto cleanup; + } + + netdef =3D virNetworkObjGetDef(obj); + + if (!virNetworkObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("network '%s' is not active"), + netdef->name); + goto cleanup; + } + + if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) + goto cleanup; + + if (networkNotifyPort(obj, port) < 0) + goto cleanup; + + ret =3D 0; cleanup: virNetworkObjEndAPI(&obj); virNetworkPortDefFree(port); return ret; - - error: - goto cleanup; } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848949; cv=none; d=zoho.com; s=zohoarc; b=BtUipMa7BPOJw+QnjDupdDzGGly5Hy2CtQsKpowILUzbUi9sNUaTEMRIYebiTcwRO6y4pFA7uzqqCAjHPvcJnsegWsR3vBlHlu99FUrA9ry7NU66L6zToaSDfvcfVSEk5Yx9zD3HvxMQP3IYCUrMXje+gKaBPwGiMb2fnDLREvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848949; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=mPqpNlRqyiUcjj/+3tyYejddkfUHe3KUJE9vDugqQ44=; b=jinBKm9V70yEIUL+Ub4fJ7W2pUdAH2m2AxAe3KO7x2k9mwtAgKkJ0rViZS6w8xPkKj7Kr7iet9HCG5Fthj5cyGODf1yhKDQ2kVv9YqKOgHhDnThCRtRFTnJjlUCOaaXuyGnFNx1Kgg49QoInFUBYh9EtR2BT9M/fFNsuqkT/JYY= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848949133832.1562255822234; Tue, 14 May 2019 08:49:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3F440C4EAC; Tue, 14 May 2019 15:49:07 +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 168F95D723; Tue, 14 May 2019 15:49:07 +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 C81AE1803510; Tue, 14 May 2019 15:49:06 +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 x4EFmrP5031824 for ; Tue, 14 May 2019 11:48:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 689631981E; Tue, 14 May 2019 15:48:53 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFE6760BCF; Tue, 14 May 2019 15:48:52 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:24 +0100 Message-Id: <20190514154836.6427-13-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 12/24] network: introduce networkReleasePort 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-Type: text/plain; charset="utf-8" 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 14 May 2019 15:49:07 +0000 (UTC) Separate network port deletion code from the domain driver network callback implementation. Reivewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 90 ++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 31 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 7446978be4..8025c4c984 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4955,9 +4955,9 @@ networkNotifyActualDevice(virNetworkPtr net, } =20 =20 -/* networkReleaseActualDevice: - * @dom: domain definition that @iface belongs to - * @iface: a domain's NetDef (interface definition) +/* networkReleasePort: + * @obj: the network to release from + * @port: the port definition to release * * Given a domain element that previously had its * element filled in (and possibly a physical device allocated to it), @@ -4967,40 +4967,15 @@ networkNotifyActualDevice(virNetworkPtr net, * Returns 0 on success, -1 on failure. */ static int -networkReleaseActualDevice(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface) +networkReleasePort(virNetworkObjPtr obj, + virNetworkPortDefPtr port) { virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj; virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev =3D NULL; - virNetworkPortDefPtr port =3D NULL; size_t i; int ret =3D -1; =20 - obj =3D virNetworkObjFindByName(driver->networks, net->name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - net->name); - goto cleanup; - } - - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - goto cleanup; - } - - if (iface->data.network.actual =3D=3D NULL) { - ret =3D 0; - goto cleanup; - } - - if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) - goto cleanup; - netdef =3D virNetworkObjGetDef(obj); =20 switch ((virNetworkPortPlugType)port->plugtype) { @@ -5080,7 +5055,7 @@ networkReleaseActualDevice(virNetworkPtr net, goto cleanup; } =20 - virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, dom->name, &port-= >mac); + virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, port->ownername, = &port->mac); =20 netdef->connections--; if (dev) @@ -5090,6 +5065,59 @@ networkReleaseActualDevice(virNetworkPtr net, VIR_HOOK_SUBOP_BEGIN); networkLogAllocation(netdef, dev, &port->mac, false); =20 + ret =3D 0; + cleanup: + return ret; +} + + +/* networkReleaseActualDevice: + * @dom: domain definition that @iface belongs to + * @iface: a domain's NetDef (interface definition) + * + * Given a domain element that previously had its + * element filled in (and possibly a physical device allocated to it), + * free up the physical device for use by someone else, and free the + * virDomainActualNetDef. + * + * Returns 0 on success, -1 on failure. + */ +static int +networkReleaseActualDevice(virNetworkPtr net, + virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virNetworkObjPtr obj; + virNetworkPortDefPtr port =3D NULL; + int ret =3D -1; + + obj =3D virNetworkObjFindByName(driver->networks, net->name); + if (!obj) { + virReportError(VIR_ERR_NO_NETWORK, + _("no network with matching name '%s'"), + net->name); + goto cleanup; + } + + + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected an interface for a virtual network")); + goto cleanup; + } + + if (iface->data.network.actual =3D=3D NULL) { + ret =3D 0; + goto cleanup; + } + + if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) + goto cleanup; + + if (networkReleasePort(obj, port) < 0) + goto cleanup; + ret =3D 0; cleanup: virNetworkObjEndAPI(&obj); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848946; cv=none; d=zoho.com; s=zohoarc; b=gMeAK11gpFSusCm519SlGqzyRQzThlWJC+jWoAgdjmxR50u1gvW85zoRAGqwNeatFQ5bNI9OWmvq2tGR++QNucrrNFRb8lu/KEsg88p3p2aeO5z6iiACSxgRulZaB51v5ZxF5JBTFqYJR0uOUy9bLixSiaALB0a3ATo/Oq002IU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848946; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=S+4FMeINAQOyPBppIGAheh9D5E2sUq8gGDH0VhPVRjs=; b=cv1MfMlEKnaSWQveZGwfgAUNzDOo7b59oh+r8O4m4MbElOEpLjefhsTlHFJuK5UkOtCRf4uJ2Ium+p4BWfY33Dmq/O049kULtkitU2e9XQSZgYQAy8Okp3cxtnRDuza1Mt7gfhCJ0/UW5iWgvdtoJKKjGVY35nO13OlaqBFWHnw= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848946789526.247372995612; Tue, 14 May 2019 08:49:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E929AA404E; Tue, 14 May 2019 15:49:04 +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 C451C5D725; Tue, 14 May 2019 15:49:04 +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 81D893FA4C; Tue, 14 May 2019 15:49:04 +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 x4EFmsWg031850 for ; Tue, 14 May 2019 11:48:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 73FF02B9E4; Tue, 14 May 2019 15:48:54 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id B00B8600C5; Tue, 14 May 2019 15:48:53 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:25 +0100 Message-Id: <20190514154836.6427-14-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 13/24] network: introduce networkUpdatePortBandwidth 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-Type: text/plain; charset="utf-8" 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 14 May 2019 15:49:05 +0000 (UTC) Separate network port bandwidth update code from the domain driver network callback implementation. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 117 ++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 51 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 8025c4c984..aada1e0316 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -5416,78 +5416,56 @@ networkNetworkObjTaint(virNetworkObjPtr obj, =20 =20 static int -networkBandwidthUpdate(virDomainNetDefPtr iface, - virNetDevBandwidthPtr newBandwidth) +networkUpdatePortBandwidth(virNetworkObjPtr obj, + virMacAddrPtr mac, + unsigned int *class_id, + virNetDevBandwidthPtr oldBandwidth, + virNetDevBandwidthPtr newBandwidth) { virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj =3D NULL; virNetworkDefPtr def; unsigned long long tmp_floor_sum; - virNetDevBandwidthPtr ifaceBand =3D virDomainNetGetActualBandwidth(ifa= ce); unsigned long long new_rate =3D 0; unsigned long long old_floor, new_floor; int plug_ret; - int ret =3D -1; - - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - return -1; - } - - if (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_NETWORK = && - (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_BRIDGE = || - iface->data.network.actual->data.bridge.brname !=3D NULL)) { - /* This is not an interface that's plugged into a bridge. - * We don't care. Thus from our POV bandwidth change is allowed. */ - return 0; - } =20 old_floor =3D new_floor =3D 0; =20 - if (ifaceBand && ifaceBand->in) - old_floor =3D ifaceBand->in->floor; + if (oldBandwidth && oldBandwidth->in) + old_floor =3D oldBandwidth->in->floor; if (newBandwidth && newBandwidth->in) new_floor =3D newBandwidth->in->floor; =20 if (new_floor =3D=3D old_floor) return 0; =20 - obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - iface->data.network.name); - return ret; - } def =3D virNetworkObjGetDef(obj); =20 - if ((plug_ret =3D networkCheckBandwidth(obj, newBandwidth, ifaceBand, - &iface->mac, &new_rate)) < 0) { + if ((plug_ret =3D networkCheckBandwidth(obj, newBandwidth, oldBandwidt= h, + mac, &new_rate)) < 0) { /* helper reported error */ - goto cleanup; + return -1; } =20 if (plug_ret > 0) { /* no QoS needs to be set; claim success */ - ret =3D 0; - goto cleanup; + return 0; } =20 /* Okay, there are three possible scenarios: */ =20 - if (ifaceBand && ifaceBand->in && ifaceBand->in->floor && + if (oldBandwidth && oldBandwidth->in && oldBandwidth->in->floor && newBandwidth->in && newBandwidth->in->floor) { /* Either we just need to update @floor .. */ =20 if (virNetDevBandwidthUpdateRate(def->bridge, - iface->data.network.actual->class= _id, + *class_id, def->bandwidth, newBandwidth->in->floor) < 0) - goto cleanup; + return -1; =20 tmp_floor_sum =3D virNetworkObjGetFloorSum(obj); - tmp_floor_sum -=3D ifaceBand->in->floor; + tmp_floor_sum -=3D oldBandwidth->in->floor; tmp_floor_sum +=3D newBandwidth->in->floor; virNetworkObjSetFloorSum(obj, tmp_floor_sum); new_rate -=3D tmp_floor_sum; @@ -5497,34 +5475,71 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, virNetworkObjSaveStatus(driver->stateDir, obj) < 0) { /* Ouch, rollback */ tmp_floor_sum -=3D newBandwidth->in->floor; - tmp_floor_sum +=3D ifaceBand->in->floor; + tmp_floor_sum +=3D oldBandwidth->in->floor; virNetworkObjSetFloorSum(obj, tmp_floor_sum); =20 ignore_value(virNetDevBandwidthUpdateRate(def->bridge, - iface->data.network.= actual->class_id, + *class_id, def->bandwidth, - ifaceBand->in->floor= )); - goto cleanup; + oldBandwidth->in->fl= oor)); + return -1; } } else if (newBandwidth->in && newBandwidth->in->floor) { /* .. or we need to plug in new .. */ =20 - if (networkPlugBandwidthImpl(obj, &iface->mac, newBandwidth, - iface->data.network.actual ? - &iface->data.network.actual->class_id= : NULL, + if (networkPlugBandwidthImpl(obj, mac, newBandwidth, + class_id, new_rate) < 0) - goto cleanup; + return -1; } else { /* .. or unplug old. */ =20 - if (networkUnplugBandwidth(obj, iface->bandwidth, - iface->data.network.actual ? - &iface->data.network.actual->class_id := NULL) < 0) - goto cleanup; + if (networkUnplugBandwidth(obj, oldBandwidth, class_id) < 0) + return -1; } =20 - ret =3D 0; - cleanup: + return 0; +} + + +static int +networkBandwidthUpdate(virDomainNetDefPtr iface, + virNetDevBandwidthPtr newBandwidth) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virNetworkObjPtr obj =3D NULL; + virNetDevBandwidthPtr oldBandwidth =3D virDomainNetGetActualBandwidth(= iface); + int ret =3D -1; + + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected an interface for a virtual network")); + return -1; + } + + if (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_NETWORK = && + (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_BRIDGE = || + iface->data.network.actual->data.bridge.brname !=3D NULL)) { + /* This is not an interface that's plugged into a bridge. + * We don't care. Thus from our POV bandwidth change is allowed. */ + return 0; + } + + obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); + if (!obj) { + virReportError(VIR_ERR_NO_NETWORK, + _("no network with matching name '%s'"), + iface->data.network.name); + return ret; + } + + ret =3D networkUpdatePortBandwidth(obj, + &iface->mac, + iface->data.network.actual ? + &iface->data.network.actual->class_id= : NULL, + newBandwidth, + oldBandwidth); + virNetworkObjEndAPI(&obj); return ret; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848952; cv=none; d=zoho.com; s=zohoarc; b=SKhFLWB3ztyT1ZyAcR68Wo2sdpZwkVqXxGalHw2hwJXhCLo0g7QV0Xcg+e7yh4hF0HnEQzcO0FOZtvd/LeTE03NIs08wc18dWNwNg9LAZ18lL9jOEWhBfg/lvl7rferxLVMUMGam1DXDg6Zp0S8mRCT86OsI1PY7pOKdO4tCnO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848952; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=4bVnsZfYZKSxlRQ2es72Qs11JPqMhFmJZJ6PjYBU82Y=; b=VybnmQSrI3IVRHIVWm2AP8m4guiLqEtGEciN2e2EDUUmkKvQho3OLw0LTmq7jsOCNGX7hZCgJPMick7+Fv4Qn98CyLLZei8kYLhuhX6OitVIeTcuQ9O+qTQGgv+K+SidOBE8412kIWoWqfUixvoJYnvWVLv/B4p/qwkf9Dypv5s= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848952718350.60355230820755; Tue, 14 May 2019 08:49:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11F0C8110D; Tue, 14 May 2019 15:49:11 +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 DDD141A265; Tue, 14 May 2019 15:49:10 +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 9FE1C3FA50; Tue, 14 May 2019 15:49: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 x4EFmtKp031856 for ; Tue, 14 May 2019 11:48:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6A78560BCF; Tue, 14 May 2019 15:48:55 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5E23600C5; Tue, 14 May 2019 15:48:54 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:26 +0100 Message-Id: <20190514154836.6427-15-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 14/24] network: add public APIs for network port object 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 14 May 2019 15:49:11 +0000 (UTC) Introduce a new virNetworPort object that will present an attachment to a virtual network from a VM. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- include/libvirt/libvirt-network.h | 122 ++++++++ include/libvirt/virterror.h | 3 + src/datatypes.c | 60 ++++ src/datatypes.h | 41 +++ src/driver-network.h | 41 +++ src/libvirt-network.c | 444 ++++++++++++++++++++++++++++++ src/libvirt_private.syms | 2 + src/libvirt_public.syms | 15 + src/util/virerror.c | 9 + 9 files changed, 737 insertions(+) diff --git a/include/libvirt/libvirt-network.h b/include/libvirt/libvirt-ne= twork.h index 5115251fbe..97eceef754 100644 --- a/include/libvirt/libvirt-network.h +++ b/include/libvirt/libvirt-network.h @@ -46,6 +46,22 @@ typedef struct _virNetwork virNetwork; */ typedef virNetwork *virNetworkPtr; =20 +/** + * virNetworkPort: + * + * a virNetworkPort is a private structure representing a virtual network + * port + */ +typedef struct _virNetworkPort virNetworkPort; + +/** + * virNetworkPortPtr: + * + * a virNetworkPortPtr is pointer to a virNetworkPort private structure, + * this is the type used to reference a virtual network port in the API. + */ +typedef virNetworkPort *virNetworkPortPtr; + /* * Get connection from network. */ @@ -333,4 +349,110 @@ int virConnectNetworkEventRegisterAny(virConnectPtr c= onn, int virConnectNetworkEventDeregisterAny(virConnectPtr conn, int callbackID); =20 + +virNetworkPortPtr +virNetworkPortLookupByUUID(virNetworkPtr net, + const unsigned char *uuid); + +virNetworkPortPtr +virNetworkPortLookupByUUIDString(virNetworkPtr net, + const char *uuidstr); + +typedef enum { + VIR_NETWORK_PORT_CREATE_RECLAIM =3D (1 << 0), /* reclaim existing used= resources */ +} virNetworkPortCreateFlags; + +virNetworkPortPtr +virNetworkPortCreateXML(virNetworkPtr net, + const char *xmldesc, + unsigned int flags); + +virNetworkPtr +virNetworkPortGetNetwork(virNetworkPortPtr port); + +char * +virNetworkPortGetXMLDesc(virNetworkPortPtr port, + unsigned int flags); + +int +virNetworkPortGetUUID(virNetworkPortPtr port, + unsigned char *uuid); +int +virNetworkPortGetUUIDString(virNetworkPortPtr port, + char *buf); + +/* Management of interface parameters */ + +/** + * VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE: + * + * Macro represents the inbound average of NIC bandwidth, as a uint. + */ +# define VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE "inbound.average" + +/** + * VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK: + * + * Macro represents the inbound peak of NIC bandwidth, as a uint. + */ +# define VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK "inbound.peak" + +/** + * VIR_NETWORK_PORT_BANDWIDTH_IN_BURST: + * + * Macro represents the inbound burst of NIC bandwidth, as a uint. + */ +# define VIR_NETWORK_PORT_BANDWIDTH_IN_BURST "inbound.burst" + +/** + * VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR: + * + * Macro represents the inbound floor of NIC bandwidth, as a uint. + */ +# define VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR "inbound.floor" + +/** + * VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE: + * + * Macro represents the outbound average of NIC bandwidth, as a uint. + */ +# define VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE "outbound.average" + +/** + * VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK: + * + * Macro represents the outbound peak of NIC bandwidth, as a uint. + */ +# define VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK "outbound.peak" + +/** + * VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST: + * + * Macro represents the outbound burst of NIC bandwidth, as a uint. + */ +# define VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST "outbound.burst" + +int +virNetworkPortSetParameters(virNetworkPortPtr port, + virTypedParameterPtr params, + int nparams, + unsigned int flags); +int +virNetworkPortGetParameters(virNetworkPortPtr port, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags); + +int +virNetworkPortDelete(virNetworkPortPtr port, + unsigned int flags); + +int +virNetworkListAllPorts(virNetworkPtr network, + virNetworkPortPtr **ports, + unsigned int flags); + +int +virNetworkPortFree(virNetworkPortPtr port); + #endif /* LIBVIRT_NETWORK_H */ diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 6dc83a17cc..102a2573bf 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -326,6 +326,9 @@ typedef enum { VIR_ERR_INVALID_DOMAIN_CHECKPOINT =3D 102, /* invalid domain checkpoin= t */ VIR_ERR_NO_DOMAIN_CHECKPOINT =3D 103, /* domain checkpoint not found */ VIR_ERR_NO_DOMAIN_BACKUP =3D 104, /* domain backup job id not foun= d */ + VIR_ERR_INVALID_NETWORK_PORT =3D 105, /* invalid network port object */ + VIR_ERR_NETWORK_PORT_EXIST =3D 106, /* the network port already exis= t */ + VIR_ERR_NO_NETWORK_PORT =3D 107, /* network port not found */ =20 # ifdef VIR_ENUM_SENTINELS VIR_ERR_NUMBER_LAST diff --git a/src/datatypes.c b/src/datatypes.c index 14ad5442fd..33c3f6be88 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -40,6 +40,7 @@ virClassPtr virDomainCheckpointClass; virClassPtr virDomainSnapshotClass; virClassPtr virInterfaceClass; virClassPtr virNetworkClass; +virClassPtr virNetworkPortClass; virClassPtr virNodeDeviceClass; virClassPtr virNWFilterClass; virClassPtr virNWFilterBindingClass; @@ -55,6 +56,7 @@ static void virDomainCheckpointDispose(void *obj); static void virDomainSnapshotDispose(void *obj); static void virInterfaceDispose(void *obj); static void virNetworkDispose(void *obj); +static void virNetworkPortDispose(void *obj); static void virNodeDeviceDispose(void *obj); static void virNWFilterDispose(void *obj); static void virNWFilterBindingDispose(void *obj); @@ -92,6 +94,7 @@ virDataTypesOnceInit(void) DECLARE_CLASS(virDomainSnapshot); DECLARE_CLASS(virInterface); DECLARE_CLASS(virNetwork); + DECLARE_CLASS(virNetworkPort); DECLARE_CLASS(virNodeDevice); DECLARE_CLASS(virNWFilter); DECLARE_CLASS(virNWFilterBinding); @@ -388,6 +391,63 @@ virNetworkDispose(void *obj) } =20 =20 +/** + * virGetNetworkPort: + * @net: the network object + * @uuid: pointer to the uuid + * + * Allocates a new network port object. When the object is no longer neede= d, + * virObjectUnref() must be called in order to not leak data. + * + * Returns a pointer to the network port object, or NULL on error. + */ +virNetworkPortPtr +virGetNetworkPort(virNetworkPtr net, const unsigned char *uuid) +{ + virNetworkPortPtr ret =3D NULL; + + if (virDataTypesInitialize() < 0) + return NULL; + + virCheckNetworkGoto(net, error); + virCheckNonNullArgGoto(uuid, error); + + if (!(ret =3D virObjectNew(virNetworkPortClass))) + goto error; + + ret->net =3D virObjectRef(net); + memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN); + + return ret; + + error: + virObjectUnref(ret); + return NULL; +} + +/** + * virNetworkPortDispose: + * @obj: the network port to release + * + * Unconditionally release all memory associated with a network port. + * The network port object must not be used once this method returns. + * + * It will also unreference the associated network object, + * which may also be released if its ref count hits zero. + */ +static void +virNetworkPortDispose(void *obj) +{ + virNetworkPortPtr port =3D obj; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(port->uuid, uuidstr); + VIR_DEBUG("release network port %p %s", port, uuidstr); + + virObjectUnref(port->net); +} + + /** * virGetInterface: * @conn: the hypervisor connection diff --git a/src/datatypes.h b/src/datatypes.h index 87f3d5e095..428b166b2b 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -35,6 +35,7 @@ extern virClassPtr virDomainCheckpointClass; extern virClassPtr virDomainSnapshotClass; extern virClassPtr virInterfaceClass; extern virClassPtr virNetworkClass; +extern virClassPtr virNetworkPortClass; extern virClassPtr virNodeDeviceClass; extern virClassPtr virNWFilterClass; extern virClassPtr virNWFilterBindingClass; @@ -117,6 +118,33 @@ extern virClassPtr virAdmClientClass; } \ } while (0) =20 +# define virCheckNetworkPortReturn(obj, retval) \ + do { \ + virNetworkPortPtr _port =3D (obj); \ + if (!virObjectIsClass(_port, virNetworkPortClass) || \ + !virObjectIsClass(_port->net, virNetworkClass)) { \ + virReportErrorHelper(VIR_FROM_NETWORK, \ + VIR_ERR_INVALID_NETWORK_PORT, \ + __FILE__, __FUNCTION__, __LINE__, \ + __FUNCTION__); \ + virDispatchError(NULL); \ + return retval; \ + } \ + } while (0) + +# define virCheckNetworkPortGoto(obj, label) \ + do { \ + virNetworkPortPtr _port =3D (obj); \ + if (!virObjectIsClass(_port, virNetworkPortClass) || \ + !virObjectIsClass(_port->net, virNetworkClass)) { \ + virReportErrorHelper(VIR_FROM_NETWORK, \ + VIR_ERR_INVALID_NETWORK_PORT, \ + __FILE__, __FUNCTION__, __LINE__, \ + __FUNCTION__); \ + goto label; \ + } \ + } while (0) + # define virCheckInterfaceReturn(obj, retval) \ do { \ virInterfacePtr _iface =3D (obj); \ @@ -589,6 +617,17 @@ struct _virNetwork { unsigned char uuid[VIR_UUID_BUFLEN]; /* the network unique identifier = */ }; =20 +/** +* _virNetworkPort: +* +* Internal structure associated to a network port +*/ +struct _virNetworkPort { + virObject parent; + virNetworkPtr net; /* pointer back to the connection= */ + unsigned char uuid[VIR_UUID_BUFLEN]; /* the network unique identifier = */ +}; + /** * _virInterface: * @@ -746,6 +785,8 @@ virDomainPtr virGetDomain(virConnectPtr conn, virNetworkPtr virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid); +virNetworkPortPtr virGetNetworkPort(virNetworkPtr net, + const unsigned char *uuid); virInterfacePtr virGetInterface(virConnectPtr conn, const char *name, const char *mac); diff --git a/src/driver-network.h b/src/driver-network.h index 2715c7bfec..a33407436f 100644 --- a/src/driver-network.h +++ b/src/driver-network.h @@ -118,6 +118,40 @@ typedef int virNetworkDHCPLeasePtr **leases, unsigned int flags); =20 +typedef virNetworkPortPtr +(*virDrvNetworkPortLookupByUUID)(virNetworkPtr net, + const unsigned char *uuid); + +typedef virNetworkPortPtr +(*virDrvNetworkPortCreateXML)(virNetworkPtr net, + const char *xmldesc, + unsigned int flags); + +typedef int +(*virDrvNetworkPortSetParameters)(virNetworkPortPtr port, + virTypedParameterPtr params, + int nparams, + unsigned int flags); + +typedef int +(*virDrvNetworkPortGetParameters)(virNetworkPortPtr port, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags); + +typedef char * +(*virDrvNetworkPortGetXMLDesc)(virNetworkPortPtr port, + unsigned int flags); + +typedef int +(*virDrvNetworkPortDelete)(virNetworkPortPtr port, + unsigned int flags); + +typedef int +(*virDrvNetworkListAllPorts)(virNetworkPtr network, + virNetworkPortPtr **ports, + unsigned int flags); + typedef struct _virNetworkDriver virNetworkDriver; typedef virNetworkDriver *virNetworkDriverPtr; =20 @@ -151,6 +185,13 @@ struct _virNetworkDriver { virDrvNetworkIsActive networkIsActive; virDrvNetworkIsPersistent networkIsPersistent; virDrvNetworkGetDHCPLeases networkGetDHCPLeases; + virDrvNetworkPortLookupByUUID networkPortLookupByUUID; + virDrvNetworkPortCreateXML networkPortCreateXML; + virDrvNetworkPortGetXMLDesc networkPortGetXMLDesc; + virDrvNetworkPortSetParameters networkPortSetParameters; + virDrvNetworkPortGetParameters networkPortGetParameters; + virDrvNetworkPortDelete networkPortDelete; + virDrvNetworkListAllPorts networkListAllPorts; }; =20 =20 diff --git a/src/libvirt-network.c b/src/libvirt-network.c index d46a7d5c47..6ed32c8ba2 100644 --- a/src/libvirt-network.c +++ b/src/libvirt-network.c @@ -23,6 +23,7 @@ #include "datatypes.h" #include "viralloc.h" #include "virlog.h" +#include "virtypedparam.h" =20 VIR_LOG_INIT("libvirt.network"); =20 @@ -1246,3 +1247,446 @@ virNetworkDHCPLeaseFree(virNetworkDHCPLeasePtr leas= e) VIR_FREE(lease->clientid); VIR_FREE(lease); } + + +/** + * virNetworkPortLookupByUUID: + * @net: pointer to the network object + * @uuid: the raw UUID for the network port + * + * Try to lookup a port on the given network based on its UUID. + * + * virNetworkPortFree should be used to free the resources after the + * network port object is no longer needed. + * + * Returns a new network port object or NULL in case of failure. If the + * network port cannot be found, then VIR_ERR_NO_NETWORK_PORT error is rai= sed. + */ +virNetworkPortPtr +virNetworkPortLookupByUUID(virNetworkPtr net, + const unsigned char *uuid) +{ + VIR_UUID_DEBUG(net, uuid); + + virResetLastError(); + + virCheckNetworkReturn(net, NULL); + virCheckNonNullArgGoto(uuid, error); + + if (net->conn->networkDriver && net->conn->networkDriver->networkPortL= ookupByUUID) { + virNetworkPortPtr ret; + ret =3D net->conn->networkDriver->networkPortLookupByUUID(net, uui= d); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(net->conn); + return NULL; +} + + +/** + * virNetworkPortLookupByUUIDString: + * @net: pointer to the network object + * @uuidstr: the string UUID for the port + * + * Try to lookup a port on the given network based on its UUID. + * + * Returns a new network port object or NULL in case of failure. If the + * network port cannot be found, then VIR_ERR_NO_NETWORK_PORT error is rai= sed. + */ +virNetworkPortPtr +virNetworkPortLookupByUUIDString(virNetworkPtr net, + const char *uuidstr) +{ + unsigned char uuid[VIR_UUID_BUFLEN]; + VIR_DEBUG("net=3D%p, uuidstr=3D%s", net, NULLSTR(uuidstr)); + + virResetLastError(); + + virCheckNetworkReturn(net, NULL); + virCheckNonNullArgGoto(uuidstr, error); + + if (virUUIDParse(uuidstr, uuid) < 0) { + virReportInvalidArg(uuidstr, + _("uuidstr in %s must be a valid UUID"), + __FUNCTION__); + goto error; + } + + return virNetworkPortLookupByUUID(net, &uuid[0]); + + error: + virDispatchError(net->conn); + return NULL; +} + + +/** + * virNetworkPortSetParameters: + * @port: a network port object + * @params: pointer to interface parameter objects + * @nparams: number of interface parameter (this value can be the same or + * less than the number of parameters supported) + * @flags: currently unused, pass 0 + * + * Change a subset or all parameters of the network port; currently this + * includes bandwidth parameters. + * + * Returns -1 in case of error, 0 in case of success. + */ +int +virNetworkPortSetParameters(virNetworkPortPtr port, + virTypedParameterPtr params, + int nparams, + unsigned int flags) +{ + virConnectPtr conn; + VIR_DEBUG("port=3D%p, params=3D%p, nparams=3D%d, flags=3D0x%x", port, = params, nparams, flags); + VIR_TYPED_PARAMS_DEBUG(params, nparams); + + virResetLastError(); + + virCheckNetworkPortReturn(port, -1); + conn =3D port->net->conn; + + virCheckReadOnlyGoto(conn->flags, error); + + if (conn->networkDriver && conn->networkDriver->networkPortSetParamete= rs) { + int ret; + ret =3D conn->networkDriver->networkPortSetParameters(port, params= , nparams, flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return -1; +} + + +/** + * virNetworkPortGetParameters: + * @port: a network port object + * @params: pointer to pointer of interface parameter objects + * @nparams: pointer to received number of interface parameter + * @flags: currently unused, pass 0 + * + * Get all interface parameters. On input, @params should be initialized + * to NULL. On return @params will be allocated with the size large + * enough to hold all parameters, and @nparams will be updated to say + * how many parameters are present. @params should be freed by the caller + * on success. + * + * Returns -1 in case of error, 0 in case of success. + */ +int +virNetworkPortGetParameters(virNetworkPortPtr port, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags) +{ + virConnectPtr conn; + VIR_DEBUG("port=3D%p, params=3D%p, nparams=3D%p, flags=3D0x%x", port, = params, nparams, flags); + + virResetLastError(); + + virCheckNetworkPortReturn(port, -1); + conn =3D port->net->conn; + + if (conn->networkDriver && conn->networkDriver->networkPortGetParamete= rs) { + int ret; + ret =3D conn->networkDriver->networkPortGetParameters(port, params= , nparams, flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return -1; +} + + +/** + * virNetworkPortCreateXML: + * @net: pointer to the network object + * @xmldesc: an XML description of the port + * @flags: currently unused, pass 0 + * + * Create a new network port, based on an XML description + * similar to the one returned by virNetworkPortGetXMLDesc() + * + * virNetworkPortFree should be used to free the resources after the + * network port object is no longer needed. + * + * Returns a new network port object or NULL in case of failure + */ +virNetworkPortPtr +virNetworkPortCreateXML(virNetworkPtr net, + const char *xmldesc, + unsigned int flags) +{ + VIR_DEBUG("net=3D%p, xmldesc=3D%s, flags=3D0x%x", net, NULLSTR(xmldesc= ), flags); + + virResetLastError(); + + virCheckNetworkReturn(net, NULL); + virCheckNonNullArgGoto(xmldesc, error); + virCheckReadOnlyGoto(net->conn->flags, error); + + if (net->conn->networkDriver && net->conn->networkDriver->networkPortC= reateXML) { + virNetworkPortPtr ret; + ret =3D net->conn->networkDriver->networkPortCreateXML(net, xmldes= c, flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(net->conn); + return NULL; +} + +/** + * virNetworkPortGetNetwork: + * @port: pointer to a network port + * + * Provides the network pointer associated with a port. The + * reference counter on the connection is not increased by this + * call. + * + * Returns the virNetworkPtr or NULL in case of failure. + */ +virNetworkPtr +virNetworkPortGetNetwork(virNetworkPortPtr port) +{ + VIR_DEBUG("port=3D%p", port); + + virResetLastError(); + + virCheckNetworkPortReturn(port, NULL); + + return port->net; +} + + +/** + * virNetworkPortGetXMLDesc: + * @port: a network port object + * @flags: currently unused, pass 0 + * + * Provide an XML description of the network port. The description may be = reused + * later to recreate the port with virNetworkPortCreateXML(). + * + * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of e= rror. + * the caller must free() the returned value. + */ +char * +virNetworkPortGetXMLDesc(virNetworkPortPtr port, + unsigned int flags) +{ + virConnectPtr conn; + VIR_DEBUG("port=3D%p, flags=3D0x%x", port, flags); + + virResetLastError(); + + virCheckNetworkPortReturn(port, NULL); + conn =3D port->net->conn; + + if (conn->networkDriver && conn->networkDriver->networkPortGetXMLDesc)= { + char *ret; + ret =3D conn->networkDriver->networkPortGetXMLDesc(port, flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virNetworkPortGetUUID: + * @port: a network port object + * @uuid: pointer to a VIR_UUID_BUFLEN bytes array + * + * Get the UUID for a network port + * + * Returns -1 in case of error, 0 in case of success + */ +int +virNetworkPortGetUUID(virNetworkPortPtr port, + unsigned char *uuid) +{ + VIR_DEBUG("port=3D%p, uuid=3D%p", port, uuid); + + virResetLastError(); + + virCheckNetworkPortReturn(port, -1); + virCheckNonNullArgGoto(uuid, error); + + memcpy(uuid, &port->uuid[0], VIR_UUID_BUFLEN); + + return 0; + + error: + virDispatchError(port->net->conn); + return -1; +} + + +/** + * virNetworkPortGetUUIDString: + * @port: a network port object + * @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array + * + * Get the UUID for a network as string. For more information about + * UUID see RFC4122. + * + * Returns -1 in case of error, 0 in case of success + */ +int +virNetworkPortGetUUIDString(virNetworkPortPtr port, + char *buf) +{ + VIR_DEBUG("port=3D%p, buf=3D%p", port, buf); + + virResetLastError(); + + virCheckNetworkPortReturn(port, -1); + virCheckNonNullArgGoto(buf, error); + + virUUIDFormat(port->uuid, buf); + return 0; + + error: + virDispatchError(port->net->conn); + return -1; +} + +/** + * virNetworkPortDelete: + * @port: a port object + * @flags: currently unused, pass 0 + * + * Delete the network port. This does not free the + * associated virNetworkPortPtr object. It is the + * caller's responsibility to ensure the port is not + * still in use by a virtual machine before deleting + * port. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virNetworkPortDelete(virNetworkPortPtr port, + unsigned int flags) +{ + virConnectPtr conn; + VIR_DEBUG("port=3D%p, flags=3D0x%x", port, flags); + + virResetLastError(); + + virCheckNetworkPortReturn(port, -1); + conn =3D port->net->conn; + + virCheckReadOnlyGoto(conn->flags, error); + + if (conn->networkDriver && conn->networkDriver->networkPortDelete) { + int ret; + ret =3D conn->networkDriver->networkPortDelete(port, flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return -1; +} + + +/** + * virNetworkListAllPorts: + * @network: pointer to a network object + * @ports: Pointer to a variable to store the array containing network port + * objects or NULL if the list is not required (just returns number + * of ports). + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Collect the list of network ports, and allocate an array to store those + * objects. + * + * Returns the number of network ports found or -1 and sets @ports to + * NULL in case of error. On success, the array stored into @ports is + * guaranteed to have an extra allocated element set to NULL but not inclu= ded + * in the return count, to make iteration easier. The caller is responsib= le + * for calling virNetworkPortFree() on each array element, then calling + * free() on @ports. + */ +int +virNetworkListAllPorts(virNetworkPtr network, + virNetworkPortPtr **ports, + unsigned int flags) +{ + VIR_DEBUG("network=3D%p, ports=3D%p, flags=3D0x%x", network, ports, fl= ags); + + virResetLastError(); + + virCheckNetworkReturn(network, -1); + + if (network->conn->networkDriver && + network->conn->networkDriver->networkListAllPorts) { + int ret; + ret =3D network->conn->networkDriver->networkListAllPorts(network,= ports, flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(network->conn); + return -1; +} + + +/** + * virNetworkPortFree: + * @port: a network port object + * + * Free the network port object. + * The data structure is freed and should not be used thereafter. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virNetworkPortFree(virNetworkPortPtr port) +{ + VIR_DEBUG("port=3D%p", port); + + virResetLastError(); + + virCheckNetworkPortReturn(port, -1); + + virObjectUnref(port); + return 0; +} diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c5e5c2d144..a88917c957 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1279,6 +1279,7 @@ virGetDomainCheckpoint; virGetDomainSnapshot; virGetInterface; virGetNetwork; +virGetNetworkPort; virGetNodeDevice; virGetNWFilter; virGetNWFilterBinding; @@ -1288,6 +1289,7 @@ virGetStorageVol; virGetStream; virInterfaceClass; virNetworkClass; +virNetworkPortClass; virNewConnectCloseCallbackData; virNodeDeviceClass; virNWFilterClass; diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index dbce3336d5..c629528fbd 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -819,4 +819,19 @@ LIBVIRT_5.2.0 { virConnectGetStoragePoolCapabilities; } LIBVIRT_4.10.0; =20 +LIBVIRT_5.3.0 { + virNetworkListAllPorts; + virNetworkPortLookupByUUID; + virNetworkPortLookupByUUIDString; + virNetworkPortCreateXML; + virNetworkPortGetNetwork; + virNetworkPortGetParameters; + virNetworkPortGetXMLDesc; + virNetworkPortGetUUID; + virNetworkPortGetUUIDString; + virNetworkPortDelete; + virNetworkPortFree; + virNetworkPortSetParameters; +} LIBVIRT_5.2.0; + # .... define new API here using predicted next version number .... diff --git a/src/util/virerror.c b/src/util/virerror.c index 37b5b2f3f9..67e2bc984e 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -1226,6 +1226,15 @@ const virErrorMsgTuple virErrorMsgStrings[VIR_ERR_NU= MBER_LAST] =3D { [VIR_ERR_NO_DOMAIN_BACKUP] =3D { N_("Domain backup job id not found"), N_("Domain backup job id not found: %s") }, + [VIR_ERR_INVALID_NETWORK_PORT] =3D { + N_("Invalid network port pointer"), + N_("Invalid network port pointer: %s") }, + [VIR_ERR_NETWORK_PORT_EXIST] =3D { + N_("this network port exists already"), + N_("network port %s exists already") }, + [VIR_ERR_NO_NETWORK_PORT] =3D { + N_("network port not found"), + N_("network port not found: %s") }, }; =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848957; cv=none; d=zoho.com; s=zohoarc; b=PEj4kXBa3K/ZXOhg42XgiiPwthYsKdHGxeO+I6PBrSQum9cSjQ/YmraTScCLL+j6SSP8yP+A869es9124cvPQ+Cte/x6dKOOdPe7gra3o11bYNCkaXY2O0P9nZrqLjW2zewNlplWvVL9EEFKL8R1GV28eCrhMIFCZslpnWApvR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848957; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=vYCwy8VLh/nMsiiJBgG4V43SQWQi+2P2hK2+7ZMcbNs=; b=lAgDEDRVm11tJA1XxWi1w2E51OcAns7YQt81Y4CD8Gw2lp9fimNzKXsOFC4+HrZecMh/a0Pxdocj+fNAP0gO+Pi1UnGgirB3EplR+BL5YZ325xfyts/iq4TU5AQuCx0S1/SeFzJZHxYGbg36lXsd/oTH8Qt2ikL+jBw2I4mbtvI= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848957298669.5567654734482; Tue, 14 May 2019 08:49:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D9FB7DCCA; Tue, 14 May 2019 15:49:15 +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 75FB95D720; Tue, 14 May 2019 15:49:15 +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 2D9803D88; Tue, 14 May 2019 15:49:15 +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 x4EFmwUV031887 for ; Tue, 14 May 2019 11:48:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id A6E8B2B9E3; Tue, 14 May 2019 15:48:58 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id F16751981E; Tue, 14 May 2019 15:48:55 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:27 +0100 Message-Id: <20190514154836.6427-16-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 15/24] access: add permissions for network port objects 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-Type: text/plain; charset="utf-8" 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 14 May 2019 15:49:16 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/access/genpolkit.pl | 2 +- src/access/viraccessdriver.h | 6 ++++ src/access/viraccessdrivernop.c | 11 ++++++++ src/access/viraccessdriverpolkit.c | 26 ++++++++++++++++++ src/access/viraccessdriverstack.c | 25 +++++++++++++++++ src/access/viraccessmanager.c | 16 +++++++++++ src/access/viraccessmanager.h | 6 ++++ src/access/viraccessperm.c | 6 ++++ src/access/viraccessperm.h | 44 ++++++++++++++++++++++++++++++ 9 files changed, 141 insertions(+), 1 deletion(-) diff --git a/src/access/genpolkit.pl b/src/access/genpolkit.pl index e074c90eb6..f8f20caf65 100755 --- a/src/access/genpolkit.pl +++ b/src/access/genpolkit.pl @@ -21,7 +21,7 @@ use strict; use warnings; =20 my @objects =3D ( - "CONNECT", "DOMAIN", "INTERFACE", + "CONNECT", "DOMAIN", "INTERFACE", "NETWORK_PORT", "NETWORK","NODE_DEVICE", "NWFILTER_BINDING", "NWFILTER", "SECRET", "STORAGE_POOL", "STORAGE_VOL", ); diff --git a/src/access/viraccessdriver.h b/src/access/viraccessdriver.h index 2cc3950f60..590d86fdf0 100644 --- a/src/access/viraccessdriver.h +++ b/src/access/viraccessdriver.h @@ -39,6 +39,11 @@ typedef int (*virAccessDriverCheckNetworkDrv)(virAccessM= anagerPtr manager, const char *driverName, virNetworkDefPtr network, virAccessPermNetwork av); +typedef int (*virAccessDriverCheckNetworkPortDrv)(virAccessManagerPtr mana= ger, + const char *driverName, + virNetworkDefPtr network, + virNetworkPortDefPtr por= t, + virAccessPermNetworkPort= av); typedef int (*virAccessDriverCheckNodeDeviceDrv)(virAccessManagerPtr manag= er, const char *driverName, virNodeDeviceDefPtr noded= ev, @@ -82,6 +87,7 @@ struct _virAccessDriver { virAccessDriverCheckDomainDrv checkDomain; virAccessDriverCheckInterfaceDrv checkInterface; virAccessDriverCheckNetworkDrv checkNetwork; + virAccessDriverCheckNetworkPortDrv checkNetworkPort; virAccessDriverCheckNodeDeviceDrv checkNodeDevice; virAccessDriverCheckNWFilterDrv checkNWFilter; virAccessDriverCheckNWFilterBindingDrv checkNWFilterBinding; diff --git a/src/access/viraccessdrivernop.c b/src/access/viraccessdriverno= p.c index 98ef9206c5..5e9d9db759 100644 --- a/src/access/viraccessdrivernop.c +++ b/src/access/viraccessdrivernop.c @@ -57,6 +57,16 @@ virAccessDriverNopCheckNetwork(virAccessManagerPtr manag= er ATTRIBUTE_UNUSED, return 1; /* Allow */ } =20 +static int +virAccessDriverNopCheckNetworkPort(virAccessManagerPtr manager ATTRIBUTE_U= NUSED, + const char *driverName ATTRIBUTE_UNUSED, + virNetworkDefPtr network ATTRIBUTE_UNUS= ED, + virNetworkPortDefPtr port ATTRIBUTE_UNU= SED, + virAccessPermNetworkPort perm ATTRIBUTE= _UNUSED) +{ + return 1; /* Allow */ +} + static int virAccessDriverNopCheckNodeDevice(virAccessManagerPtr manager ATTRIBUTE_UN= USED, const char *driverName ATTRIBUTE_UNUSED, @@ -119,6 +129,7 @@ virAccessDriver accessDriverNop =3D { .checkDomain =3D virAccessDriverNopCheckDomain, .checkInterface =3D virAccessDriverNopCheckInterface, .checkNetwork =3D virAccessDriverNopCheckNetwork, + .checkNetworkPort =3D virAccessDriverNopCheckNetworkPort, .checkNodeDevice =3D virAccessDriverNopCheckNodeDevice, .checkNWFilter =3D virAccessDriverNopCheckNWFilter, .checkNWFilterBinding =3D virAccessDriverNopCheckNWFilterBinding, diff --git a/src/access/viraccessdriverpolkit.c b/src/access/viraccessdrive= rpolkit.c index 6954d74a15..b1473cd0a4 100644 --- a/src/access/viraccessdriverpolkit.c +++ b/src/access/viraccessdriverpolkit.c @@ -237,6 +237,31 @@ virAccessDriverPolkitCheckNetwork(virAccessManagerPtr = manager, attrs); } =20 +static int +virAccessDriverPolkitCheckNetworkPort(virAccessManagerPtr manager, + const char *driverName, + virNetworkDefPtr network, + virNetworkPortDefPtr port, + virAccessPermNetworkPort perm) +{ + char uuidstr1[VIR_UUID_STRING_BUFLEN]; + char uuidstr2[VIR_UUID_STRING_BUFLEN]; + const char *attrs[] =3D { + "connect_driver", driverName, + "network_name", network->name, + "network_uuid", uuidstr1, + "port_uuid", uuidstr2, + NULL, + }; + virUUIDFormat(network->uuid, uuidstr1); + virUUIDFormat(port->uuid, uuidstr2); + + return virAccessDriverPolkitCheck(manager, + "network-port", + virAccessPermNetworkPortTypeToString= (perm), + attrs); +} + static int virAccessDriverPolkitCheckNodeDevice(virAccessManagerPtr manager, const char *driverName, @@ -427,6 +452,7 @@ virAccessDriver accessDriverPolkit =3D { .checkDomain =3D virAccessDriverPolkitCheckDomain, .checkInterface =3D virAccessDriverPolkitCheckInterface, .checkNetwork =3D virAccessDriverPolkitCheckNetwork, + .checkNetworkPort =3D virAccessDriverPolkitCheckNetworkPort, .checkNodeDevice =3D virAccessDriverPolkitCheckNodeDevice, .checkNWFilter =3D virAccessDriverPolkitCheckNWFilter, .checkNWFilterBinding =3D virAccessDriverPolkitCheckNWFilterBinding, diff --git a/src/access/viraccessdriverstack.c b/src/access/viraccessdriver= stack.c index 0ffc6abaf3..238caef115 100644 --- a/src/access/viraccessdriverstack.c +++ b/src/access/viraccessdriverstack.c @@ -151,6 +151,30 @@ virAccessDriverStackCheckNetwork(virAccessManagerPtr m= anager, return ret; } =20 +static int +virAccessDriverStackCheckNetworkPort(virAccessManagerPtr manager, + const char *driverName, + virNetworkDefPtr network, + virNetworkPortDefPtr port, + virAccessPermNetworkPort perm) +{ + virAccessDriverStackPrivatePtr priv =3D virAccessManagerGetPrivateData= (manager); + int ret =3D 1; + size_t i; + + for (i =3D 0; i < priv->managersLen; i++) { + int rv; + /* We do not short-circuit on first denial - always check all driv= ers */ + rv =3D virAccessManagerCheckNetworkPort(priv->managers[i], driverN= ame, network, port, perm); + if (rv =3D=3D 0 && ret !=3D -1) + ret =3D 0; + else if (rv < 0) + ret =3D -1; + } + + return ret; +} + static int virAccessDriverStackCheckNodeDevice(virAccessManagerPtr manager, const char *driverName, @@ -298,6 +322,7 @@ virAccessDriver accessDriverStack =3D { .checkDomain =3D virAccessDriverStackCheckDomain, .checkInterface =3D virAccessDriverStackCheckInterface, .checkNetwork =3D virAccessDriverStackCheckNetwork, + .checkNetworkPort =3D virAccessDriverStackCheckNetworkPort, .checkNodeDevice =3D virAccessDriverStackCheckNodeDevice, .checkNWFilter =3D virAccessDriverStackCheckNWFilter, .checkNWFilterBinding =3D virAccessDriverStackCheckNWFilterBinding, diff --git a/src/access/viraccessmanager.c b/src/access/viraccessmanager.c index f5d62604cf..24d9713cfd 100644 --- a/src/access/viraccessmanager.c +++ b/src/access/viraccessmanager.c @@ -268,6 +268,22 @@ int virAccessManagerCheckNetwork(virAccessManagerPtr m= anager, return virAccessManagerSanitizeError(ret, driverName); } =20 +int virAccessManagerCheckNetworkPort(virAccessManagerPtr manager, + const char *driverName, + virNetworkDefPtr network, + virNetworkPortDefPtr port, + virAccessPermNetworkPort perm) +{ + int ret =3D 0; + VIR_DEBUG("manager=3D%p(name=3D%s) driver=3D%s network=3D%p port=3D%p = perm=3D%d", + manager, manager->drv->name, driverName, network, port, perm= ); + + if (manager->drv->checkNetworkPort) + ret =3D manager->drv->checkNetworkPort(manager, driverName, networ= k, port, perm); + + return virAccessManagerSanitizeError(ret, driverName); +} + int virAccessManagerCheckNodeDevice(virAccessManagerPtr manager, const char *driverName, virNodeDeviceDefPtr nodedev, diff --git a/src/access/viraccessmanager.h b/src/access/viraccessmanager.h index ab5ef87585..bedd6ba475 100644 --- a/src/access/viraccessmanager.h +++ b/src/access/viraccessmanager.h @@ -30,6 +30,7 @@ # include "conf/secret_conf.h" # include "conf/interface_conf.h" # include "conf/virnwfilterbindingdef.h" +# include "conf/virnetworkportdef.h" # include "access/viraccessperm.h" =20 typedef struct _virAccessManager virAccessManager; @@ -66,6 +67,11 @@ int virAccessManagerCheckNetwork(virAccessManagerPtr man= ager, const char *driverName, virNetworkDefPtr network, virAccessPermNetwork perm); +int virAccessManagerCheckNetworkPort(virAccessManagerPtr manager, + const char *driverName, + virNetworkDefPtr network, + virNetworkPortDefPtr port, + virAccessPermNetworkPort perm); int virAccessManagerCheckNodeDevice(virAccessManagerPtr manager, const char *driverName, virNodeDeviceDefPtr nodedev, diff --git a/src/access/viraccessperm.c b/src/access/viraccessperm.c index 67f751ef9c..74993e9f29 100644 --- a/src/access/viraccessperm.c +++ b/src/access/viraccessperm.c @@ -57,6 +57,12 @@ VIR_ENUM_IMPL(virAccessPermNetwork, VIR_ACCESS_PERM_NETWORK_LAST, "getattr", "read", "write", "save", "delete", "start", "stop", + "search_ports", +); + +VIR_ENUM_IMPL(virAccessPermNetworkPort, + VIR_ACCESS_PERM_NETWORK_PORT_LAST, + "getattr", "read", "write", "create", "delete", ); =20 VIR_ENUM_IMPL(virAccessPermNodeDevice, diff --git a/src/access/viraccessperm.h b/src/access/viraccessperm.h index ed1f7168ca..0fe618328b 100644 --- a/src/access/viraccessperm.h +++ b/src/access/viraccessperm.h @@ -405,6 +405,12 @@ typedef enum { */ VIR_ACCESS_PERM_NETWORK_START, =20 + /** + * @desc: List network ports + * @message: Listing network ports requires authorization + */ + VIR_ACCESS_PERM_NETWORK_SEARCH_PORTS, + /** * @desc: Stop network * @message: Stopping network requires authorization @@ -414,6 +420,43 @@ typedef enum { VIR_ACCESS_PERM_NETWORK_LAST } virAccessPermNetwork; =20 +typedef enum { + + /** + * @desc: Access network port + * @message: Accessing network port requires authorization + * @anonymous: 1 + */ + VIR_ACCESS_PERM_NETWORK_PORT_GETATTR, + + /** + * @desc: Read network port + * @message: Reading network port configuration requires authorization + * @anonymous: 1 + */ + VIR_ACCESS_PERM_NETWORK_PORT_READ, + + /** + * @desc: Read network port + * @message: Writing network port configuration requires authorization + */ + VIR_ACCESS_PERM_NETWORK_PORT_WRITE, + + /** + * @desc: Create network port + * @message: Creating network port configuration requires authorization + */ + VIR_ACCESS_PERM_NETWORK_PORT_CREATE, + + /** + * @desc: Delete network port + * @message: Deleting network port configuration requires authorization + */ + VIR_ACCESS_PERM_NETWORK_PORT_DELETE, + + VIR_ACCESS_PERM_NETWORK_PORT_LAST +} virAccessPermNetworkPort; + typedef enum { =20 /** @@ -693,6 +736,7 @@ VIR_ENUM_DECL(virAccessPermConnect); VIR_ENUM_DECL(virAccessPermDomain); VIR_ENUM_DECL(virAccessPermInterface); VIR_ENUM_DECL(virAccessPermNetwork); +VIR_ENUM_DECL(virAccessPermNetworkPort); VIR_ENUM_DECL(virAccessPermNodeDevice); VIR_ENUM_DECL(virAccessPermNWFilter); VIR_ENUM_DECL(virAccessPermNWFilterBinding); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848946; cv=none; d=zoho.com; s=zohoarc; b=DSsOly/fCixJ2c171vXMbqlSbzlQcwq0B02WcSaodI9nhwMJ0MohQ+6f4BZiTHk4VvtYP+NLi2Q7zfVjcB46LpKhiWfSN/+mZs7JXypJvgtZXkH+TU1rNEgh8oE5kOyxsMb4kht18kwgNOyiNqjEIUcXAEFEa1eI+tBu2DhgNCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848946; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=v3F33wJBB4ZpNAEygC0VtQXNRBSlfmGl1Br3s8UmZ/o=; b=AynQ6j/G42NKX30zg+4ww1wnmDC8CC4C3zHXehw9n0Ulys0c23zKP1pp7gXsWRMcEMwWtrEBknCyqrZgDak5QBVI3/qUOd3Vw79QHL/Z2P55035w3GAUiQcTMtUfKH8cY2KWPu0tVa7bBToBVN6b/6OFilDRznr4MKvj5VnMTRw= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848946593366.12560451310856; Tue, 14 May 2019 08:49:06 -0700 (PDT) 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 ECEF919CBC4; Tue, 14 May 2019 15:49:04 +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 C04BA5D72E; Tue, 14 May 2019 15:49:04 +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 7E126180350E; Tue, 14 May 2019 15:49:04 +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 x4EFn0UP031904 for ; Tue, 14 May 2019 11:49:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id A23162B9E7; Tue, 14 May 2019 15:49:00 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id E87F51981E; Tue, 14 May 2019 15:48:58 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:28 +0100 Message-Id: <20190514154836.6427-17-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 16/24] remote: add support for new network port APIs 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-Type: text/plain; charset="utf-8" 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.29]); Tue, 14 May 2019 15:49:05 +0000 (UTC) Define the wire protocol for the virNetworkPort APIs and enable the client/server RPC dispatch. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/remote_daemon_dispatch.c | 73 ++++++++++++++++ src/remote/remote_driver.c | 69 ++++++++++++++++ src/remote/remote_protocol.x | 124 +++++++++++++++++++++++++++- src/remote_protocol-structs | 69 ++++++++++++++++ src/rpc/gendispatch.pl | 18 ++-- 5 files changed, 346 insertions(+), 7 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index df28259042..856c5e48e7 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -83,6 +83,7 @@ struct daemonClientEventCallback { =20 static virDomainPtr get_nonnull_domain(virConnectPtr conn, remote_nonnull_= domain domain); static virNetworkPtr get_nonnull_network(virConnectPtr conn, remote_nonnul= l_network network); +static virNetworkPortPtr get_nonnull_network_port(virConnectPtr conn, remo= te_nonnull_network_port port); static virInterfacePtr get_nonnull_interface(virConnectPtr conn, remote_no= nnull_interface iface); static virStoragePoolPtr get_nonnull_storage_pool(virConnectPtr conn, remo= te_nonnull_storage_pool pool); static virStorageVolPtr get_nonnull_storage_vol(virConnectPtr conn, remote= _nonnull_storage_vol vol); @@ -93,6 +94,7 @@ static virDomainSnapshotPtr get_nonnull_domain_snapshot(v= irDomainPtr dom, remote static virNodeDevicePtr get_nonnull_node_device(virConnectPtr conn, remote= _nonnull_node_device dev); static int make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPt= r dom_src) ATTRIBUTE_RETURN_CHECK; static int make_nonnull_network(remote_nonnull_network *net_dst, virNetwor= kPtr net_src) ATTRIBUTE_RETURN_CHECK; +static int make_nonnull_network_port(remote_nonnull_network_port *port_dst= , virNetworkPortPtr port_src) ATTRIBUTE_RETURN_CHECK; static int make_nonnull_interface(remote_nonnull_interface *interface_dst,= virInterfacePtr interface_src) ATTRIBUTE_RETURN_CHECK; static int make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_dst= , virStoragePoolPtr pool_src) ATTRIBUTE_RETURN_CHECK; static int make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, v= irStorageVolPtr vol_src) ATTRIBUTE_RETURN_CHECK; @@ -7175,6 +7177,54 @@ remoteDispatchStorageVolGetInfoFlags(virNetServerPtr= server ATTRIBUTE_UNUSED, } =20 =20 +static int +remoteDispatchNetworkPortGetParameters(virNetServerPtr server ATTRIBUTE_UN= USED, + virNetServerClientPtr client ATTRIB= UTE_UNUSED, + virNetMessagePtr msg ATTRIBUTE_UNUS= ED, + virNetMessageErrorPtr rerr, + remote_network_port_get_parameters_= args *args, + remote_network_port_get_parameters_= ret *ret) +{ + int rv =3D -1; + virNetworkPortPtr port =3D NULL; + virTypedParameterPtr params =3D NULL; + int nparams =3D 0; + struct daemonClientPrivate *priv =3D + virNetServerClientGetPrivateData(client); + + if (!priv->networkConn) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not ope= n")); + goto cleanup; + } + + if (!(port =3D get_nonnull_network_port(priv->networkConn, args->port)= )) + goto cleanup; + + if (virNetworkPortGetParameters(port, ¶ms, &nparams, args->flags) = < 0) + goto cleanup; + + if (nparams > REMOTE_NETWORK_PORT_PARAMETERS_MAX) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); + goto cleanup; + } + + if (virTypedParamsSerialize(params, nparams, + (virTypedParameterRemotePtr *) &ret->param= s.params_val, + &ret->params.params_len, + args->flags) < 0) + goto cleanup; + + rv =3D 0; + + cleanup: + if (rv < 0) + virNetMessageSaveError(rerr); + virObjectUnref(port); + virTypedParamsFree(params, nparams); + return rv; +} + + /*----- Helpers. -----*/ =20 /* get_nonnull_domain and get_nonnull_network turn an on-wire @@ -7198,6 +7248,19 @@ get_nonnull_network(virConnectPtr conn, remote_nonnu= ll_network network) return virGetNetwork(conn, network.name, BAD_CAST network.uuid); } =20 +static virNetworkPortPtr +get_nonnull_network_port(virConnectPtr conn, remote_nonnull_network_port p= ort) +{ + virNetworkPortPtr ret; + virNetworkPtr net; + net =3D virGetNetwork(conn, port.net.name, BAD_CAST port.net.uuid); + if (!net) + return NULL; + ret =3D virGetNetworkPort(net, BAD_CAST port.uuid); + virObjectUnref(net); + return ret; +} + static virInterfacePtr get_nonnull_interface(virConnectPtr conn, remote_nonnull_interface iface) { @@ -7270,6 +7333,16 @@ make_nonnull_network(remote_nonnull_network *net_dst= , virNetworkPtr net_src) return 0; } =20 +static int +make_nonnull_network_port(remote_nonnull_network_port *port_dst, virNetwor= kPortPtr port_src) +{ + if (VIR_STRDUP(port_dst->net.name, port_src->net->name) < 0) + return -1; + memcpy(port_dst->net.uuid, port_src->net->uuid, VIR_UUID_BUFLEN); + memcpy(port_dst->uuid, port_src->uuid, VIR_UUID_BUFLEN); + return 0; +} + static int make_nonnull_interface(remote_nonnull_interface *interface_dst, virInterfacePtr interface_src) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 5c4dd41227..560174be4f 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -138,6 +138,7 @@ static int remoteAuthPolkit(virConnectPtr conn, struct = private_data *priv, =20 static virDomainPtr get_nonnull_domain(virConnectPtr conn, remote_nonnull_= domain domain); static virNetworkPtr get_nonnull_network(virConnectPtr conn, remote_nonnul= l_network network); +static virNetworkPortPtr get_nonnull_network_port(virConnectPtr conn, remo= te_nonnull_network_port port); static virNWFilterPtr get_nonnull_nwfilter(virConnectPtr conn, remote_nonn= ull_nwfilter nwfilter); static virNWFilterBindingPtr get_nonnull_nwfilter_binding(virConnectPtr co= nn, remote_nonnull_nwfilter_binding binding); static virInterfacePtr get_nonnull_interface(virConnectPtr conn, remote_no= nnull_interface iface); @@ -148,6 +149,7 @@ static virSecretPtr get_nonnull_secret(virConnectPtr co= nn, remote_nonnull_secret static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr domai= n, remote_nonnull_domain_snapshot snapshot); static void make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainP= tr dom_src); static void make_nonnull_network(remote_nonnull_network *net_dst, virNetwo= rkPtr net_src); +static void make_nonnull_network_port(remote_nonnull_network_port *port_ds= t, virNetworkPortPtr port_src); static void make_nonnull_interface(remote_nonnull_interface *interface_dst= , virInterfacePtr interface_src); static void make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_ds= t, virStoragePoolPtr vol_src); static void make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, = virStorageVolPtr vol_src); @@ -8132,6 +8134,45 @@ remoteStorageVolGetInfoFlags(virStorageVolPtr vol, } =20 =20 +static int +remoteNetworkPortGetParameters(virNetworkPortPtr port, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags) +{ + int rv =3D -1; + struct private_data *priv =3D port->net->conn->privateData; + remote_network_port_get_parameters_args args; + remote_network_port_get_parameters_ret ret; + + remoteDriverLock(priv); + + make_nonnull_network_port(&args.port, port); + args.flags =3D flags; + + memset(&ret, 0, sizeof(ret)); + if (call(port->net->conn, priv, 0, REMOTE_PROC_NETWORK_PORT_GET_PARAME= TERS, + (xdrproc_t) xdr_remote_network_port_get_parameters_args, (cha= r *) &args, + (xdrproc_t) xdr_remote_network_port_get_parameters_ret, (char= *) &ret) =3D=3D -1) + goto done; + + if (virTypedParamsDeserialize((virTypedParameterRemotePtr) ret.params.= params_val, + ret.params.params_len, + REMOTE_NETWORK_PORT_PARAMETERS_MAX, + params, + nparams) < 0) + goto cleanup; + + rv =3D 0; + + cleanup: + xdr_free((xdrproc_t) xdr_remote_network_port_get_parameters_ret, (char= *) &ret); + done: + remoteDriverUnlock(priv); + return rv; +} + + /* get_nonnull_domain and get_nonnull_network turn an on-wire * (name, uuid) pair into virDomainPtr or virNetworkPtr object. * These can return NULL if underlying memory allocations fail, @@ -8149,6 +8190,19 @@ get_nonnull_network(virConnectPtr conn, remote_nonnu= ll_network network) return virGetNetwork(conn, network.name, BAD_CAST network.uuid); } =20 +static virNetworkPortPtr +get_nonnull_network_port(virConnectPtr conn, remote_nonnull_network_port p= ort) +{ + virNetworkPortPtr ret; + virNetworkPtr net; + net =3D virGetNetwork(conn, port.net.name, BAD_CAST port.net.uuid); + if (!net) + return NULL; + ret =3D virGetNetworkPort(net, BAD_CAST port.uuid); + virObjectUnref(net); + return ret; +} + static virInterfacePtr get_nonnull_interface(virConnectPtr conn, remote_nonnull_interface iface) { @@ -8216,6 +8270,14 @@ make_nonnull_network(remote_nonnull_network *net_dst= , virNetworkPtr net_src) memcpy(net_dst->uuid, net_src->uuid, VIR_UUID_BUFLEN); } =20 +static void +make_nonnull_network_port(remote_nonnull_network_port *port_dst, virNetwor= kPortPtr port_src) +{ + port_dst->net.name =3D port_src->net->name; + memcpy(port_dst->net.uuid, port_src->net->uuid, VIR_UUID_BUFLEN); + memcpy(port_dst->uuid, port_src->uuid, VIR_UUID_BUFLEN); +} + static void make_nonnull_interface(remote_nonnull_interface *interface_dst, virInterfacePtr interface_src) @@ -8542,6 +8604,13 @@ static virNetworkDriver network_driver =3D { .networkIsActive =3D remoteNetworkIsActive, /* 0.7.3 */ .networkIsPersistent =3D remoteNetworkIsPersistent, /* 0.7.3 */ .networkGetDHCPLeases =3D remoteNetworkGetDHCPLeases, /* 1.2.6 */ + .networkListAllPorts =3D remoteNetworkListAllPorts, /* 5.3.0 */ + .networkPortLookupByUUID =3D remoteNetworkPortLookupByUUID, /* 5.3.0 */ + .networkPortCreateXML =3D remoteNetworkPortCreateXML, /* 5.3.0 */ + .networkPortGetXMLDesc =3D remoteNetworkPortGetXMLDesc, /* 5.3.0 */ + .networkPortSetParameters =3D remoteNetworkPortSetParameters, /* 5.3.0= */ + .networkPortGetParameters =3D remoteNetworkPortGetParameters, /* 5.3.0= */ + .networkPortDelete =3D remoteNetworkPortDelete, /* 5.3.0 */ }; =20 static virInterfaceDriver interface_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 11f44ee267..d64b494cef 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -74,6 +74,9 @@ const REMOTE_MIGRATE_COOKIE_MAX =3D 4194304; /* Upper limit on lists of networks. */ const REMOTE_NETWORK_LIST_MAX =3D 16384; =20 +/* Upper limit on lists of network ports. */ +const REMOTE_NETWORK_PORT_LIST_MAX =3D 16384; + /* Upper limit on lists of interfaces. */ const REMOTE_INTERFACE_LIST_MAX =3D 16384; =20 @@ -263,6 +266,12 @@ const REMOTE_NODE_SEV_INFO_MAX =3D 64; /* Upper limit on number of launch security information entries */ const REMOTE_DOMAIN_LAUNCH_SECURITY_INFO_PARAMS_MAX =3D 64; =20 +/* + * Upper limit on list of network port parameters + */ +const REMOTE_NETWORK_PORT_PARAMETERS_MAX =3D 16; + + /* UUID. VIR_UUID_BUFLEN definition comes from libvirt.h */ typedef opaque remote_uuid[VIR_UUID_BUFLEN]; =20 @@ -279,6 +288,11 @@ struct remote_nonnull_network { remote_uuid uuid; }; =20 +struct remote_nonnull_network_port { + remote_nonnull_network net; + remote_uuid uuid; +}; + /* A network filter which may not be NULL. */ struct remote_nonnull_nwfilter { remote_nonnull_string name; @@ -331,6 +345,7 @@ struct remote_nonnull_domain_snapshot { /* A domain or network which may be NULL. */ typedef remote_nonnull_domain *remote_domain; typedef remote_nonnull_network *remote_network; +typedef remote_nonnull_network_port *remote_network_port; typedef remote_nonnull_nwfilter *remote_nwfilter; typedef remote_nonnull_nwfilter_binding *remote_nwfilter_binding; typedef remote_nonnull_storage_pool *remote_storage_pool; @@ -3573,6 +3588,68 @@ struct remote_connect_get_storage_pool_capabilities_= ret { remote_nonnull_string capabilities; }; =20 +struct remote_network_list_all_ports_args { + remote_nonnull_network network; + int need_results; + unsigned int flags; +}; + +struct remote_network_list_all_ports_ret { /* insert@1 */ + remote_nonnull_network_port ports; + unsigned int ret; +}; + +struct remote_network_port_lookup_by_uuid_args { + remote_nonnull_network network; + remote_uuid uuid; +}; + +struct remote_network_port_lookup_by_uuid_ret { + remote_nonnull_network_port port; +}; + +struct remote_network_port_create_xml_args { + remote_nonnull_network network; + remote_nonnull_string xml; + unsigned int flags; +}; + +struct remote_network_port_create_xml_ret { + remote_nonnull_network_port port; +}; + +struct remote_network_port_set_parameters_args { + remote_nonnull_network_port port; + remote_typed_param params; + unsigned int flags; +}; + +struct remote_network_port_get_parameters_args { + remote_nonnull_network_port port; + int nparams; + unsigned int flags; +}; + +struct remote_network_port_get_parameters_ret { + remote_typed_param params; + int nparams; +}; + +struct remote_network_port_get_xml_desc_args { + remote_nonnull_network_port port; + unsigned int flags; +}; + +struct remote_network_port_get_xml_desc_ret { + remote_nonnull_string xml; +}; + +struct remote_network_port_delete_args { + remote_nonnull_network_port port; + unsigned int flags; +}; + + /*----- Protocol. -----*/ =20 /* Define the program number, protocol version and procedure numbers here.= */ @@ -6342,5 +6419,50 @@ enum remote_procedure { * @generate: both * @acl: connect:read */ - REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403 + REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403, + + /** + * @generate: both + * @priority: high + * @acl: network:search_ports + * @aclfilter: network_port:getattr + */ + REMOTE_PROC_NETWORK_LIST_ALL_PORTS =3D 404, + + /** + * @generate: both + * @priority: high + * @acl: network_port:getattr + */ + REMOTE_PROC_NETWORK_PORT_LOOKUP_BY_UUID =3D 405, + + /** + * @generate: both + * @acl: network_port:create + */ + REMOTE_PROC_NETWORK_PORT_CREATE_XML =3D 406, + + /** + * @generate: none + * @acl: network_port:read + */ + REMOTE_PROC_NETWORK_PORT_GET_PARAMETERS =3D 407, + + /** + * @generate: both + * @acl: network_port:write + */ + REMOTE_PROC_NETWORK_PORT_SET_PARAMETERS =3D 408, + + /** + * @generate: both + * @acl: network_port:read + */ + REMOTE_PROC_NETWORK_PORT_GET_XML_DESC =3D 409, + + /** + * @generate: both + * @acl: network_port:delete + */ + REMOTE_PROC_NETWORK_PORT_DELETE =3D 410 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 768189c573..2398494520 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -17,6 +17,10 @@ struct remote_nonnull_network { remote_nonnull_string name; remote_uuid uuid; }; +struct remote_nonnull_network_port { + remote_nonnull_network net; + remote_uuid uuid; +}; struct remote_nonnull_nwfilter { remote_nonnull_string name; remote_uuid uuid; @@ -2981,6 +2985,64 @@ struct remote_connect_get_storage_pool_capabilities_= args { struct remote_connect_get_storage_pool_capabilities_ret { remote_nonnull_string capabilities; }; +struct remote_network_list_all_ports_args { + remote_nonnull_network network; + int need_results; + u_int flags; +}; +struct remote_network_list_all_ports_ret { + struct { + u_int ports_len; + remote_nonnull_network_port * ports_val; + } ports; + u_int ret; +}; +struct remote_network_port_lookup_by_uuid_args { + remote_nonnull_network network; + remote_uuid uuid; +}; +struct remote_network_port_lookup_by_uuid_ret { + remote_nonnull_network_port port; +}; +struct remote_network_port_create_xml_args { + remote_nonnull_network network; + remote_nonnull_string xml; + u_int flags; +}; +struct remote_network_port_create_xml_ret { + remote_nonnull_network_port port; +}; +struct remote_network_port_set_parameters_args { + remote_nonnull_network_port port; + struct { + u_int params_len; + remote_typed_param * params_val; + } params; + u_int flags; +}; +struct remote_network_port_get_parameters_args { + remote_nonnull_network_port port; + int nparams; + u_int flags; +}; +struct remote_network_port_get_parameters_ret { + struct { + u_int params_len; + remote_typed_param * params_val; + } params; + int nparams; +}; +struct remote_network_port_get_xml_desc_args { + remote_nonnull_network_port port; + u_int flags; +}; +struct remote_network_port_get_xml_desc_ret { + remote_nonnull_string xml; +}; +struct remote_network_port_delete_args { + remote_nonnull_network_port port; + u_int flags; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3385,4 +3447,11 @@ enum remote_procedure { REMOTE_PROC_CONNECT_LIST_ALL_NWFILTER_BINDINGS =3D 401, REMOTE_PROC_DOMAIN_SET_IOTHREAD_PARAMS =3D 402, REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403, + REMOTE_PROC_NETWORK_LIST_ALL_PORTS =3D 404, + REMOTE_PROC_NETWORK_PORT_LOOKUP_BY_UUID =3D 405, + REMOTE_PROC_NETWORK_PORT_CREATE_XML =3D 406, + REMOTE_PROC_NETWORK_PORT_GET_PARAMETERS =3D 407, + REMOTE_PROC_NETWORK_PORT_SET_PARAMETERS =3D 408, + REMOTE_PROC_NETWORK_PORT_GET_XML_DESC =3D 409, + REMOTE_PROC_NETWORK_PORT_DELETE =3D 410, }; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index ae3a42c4c1..f683e711ce 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -557,7 +557,7 @@ elsif ($mode eq "server") { if ($args_member =3D~ m/^remote_nonnull_string name;/ and = $has_node_device) { # ignore the name arg for node devices next - } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter_binding) (\S= +);/) { + } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|network_port|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter= _binding) (\S+);/) { my $type_name =3D name_to_TypeName($1); =20 push(@vars_list, "vir${type_name}Ptr $2 =3D NULL"); @@ -722,7 +722,7 @@ elsif ($mode eq "server") { if (!$modern_ret_as_list) { push(@ret_list, "ret->$3 =3D tmp.$3;"); } - } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|storage_vol|= storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)>;/) { + } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|network_port= |storage_vol|storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)= >;/) { $modern_ret_struct_name =3D $1; $single_ret_list_error_msg_type =3D $1; $single_ret_list_name =3D $2; @@ -780,7 +780,7 @@ elsif ($mode eq "server") { $single_ret_var =3D $1; $single_ret_by_ref =3D 0; $single_ret_check =3D " =3D=3D NULL"; - } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|interface|node_device|secret|nwfilter|nwfilter_b= inding|domain_snapshot) (\S+);/) { + } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|network_port|storage_pool|storage_vol|interface|node_device|secret|nwfilt= er|nwfilter_binding|domain_snapshot) (\S+);/) { my $type_name =3D name_to_TypeName($1); =20 if ($call->{ProcName} eq "DomainCreateWithFlags") { @@ -1328,7 +1328,7 @@ elsif ($mode eq "client") { $priv_src =3D "dev->conn"; push(@args_list, "virNodeDevicePtr dev"); push(@setters_list, "args.name =3D dev->name;"); - } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter_binding|doma= in_snapshot) (\S+);/) { + } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|network_port|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter= _binding|domain_snapshot) (\S+);/) { my $name =3D $1; my $arg_name =3D $2; my $type_name =3D name_to_TypeName($name); @@ -1336,6 +1336,8 @@ elsif ($mode eq "client") { if ($is_first_arg) { if ($name eq "domain_snapshot") { $priv_src =3D "$arg_name->domain->conn"; + } elsif ($name eq "network_port") { + $priv_src =3D "$arg_name->net->conn"; } else { $priv_src =3D "$arg_name->conn"; } @@ -1521,7 +1523,7 @@ elsif ($mode eq "client") { } =20 push(@ret_list, "memcpy(result->$3, ret.$3, sizeof= (result->$3));"); - } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|storage_vol|= storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)>;/) { + } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|network_port= |storage_vol|storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)= >;/) { my $proc_name =3D name_to_TypeName($1); =20 if ($structprefix eq "admin") { @@ -1574,7 +1576,7 @@ elsif ($mode eq "client") { push(@ret_list, "VIR_FREE(ret.$1);"); $single_ret_var =3D "char *rv =3D NULL"; $single_ret_type =3D "char *"; - } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|node_device|interface|secret|nwfilter|nwfilter_b= inding|domain_snapshot) (\S+);/) { + } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|network_port|storage_pool|storage_vol|node_device|interface|secret|nwfilt= er|nwfilter_binding|domain_snapshot) (\S+);/) { my $name =3D $1; my $arg_name =3D $2; my $type_name =3D name_to_TypeName($name); @@ -2135,6 +2137,8 @@ elsif ($mode eq "client") { if ($object ne "Connect") { if ($object eq "StorageVol") { push @argdecls, "virStoragePoolDefPtr pool"; + } elsif ($object eq "NetworkPort") { + push @argdecls, "virNetworkDefPtr net"; } push @argdecls, "$objecttype $arg"; } @@ -2164,6 +2168,8 @@ elsif ($mode eq "client") { if ($object ne "Connect") { if ($object eq "StorageVol") { push @argvars, "pool"; + } elsif ($object eq "NetworkPort") { + push @argvars, "net"; } push @argvars, $arg; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848950; cv=none; d=zoho.com; s=zohoarc; b=EJE+Nj6axT3PsACSSFJn2+iknSvnc3F1CddtCgC2zWLt86AppkN0K8e+HRIo7G/yBicjcVvqwfXFnzAugPlNqfO1KRO7Ps1IXn0CPgpbY4b0kwL1qAGdrA12AosKqqAs701RZiHF7Pm8E1fiYbw/Fkl2D4kl2RN//XkcbyqaE14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848950; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=wNLuvi+DzTAmxclnY6waRpJwLBvHhA3wAyx2OpE7mKs=; b=THPe3sQg6rJUJ8D4z54f5uE364JQpfk70VzLGFUPZPuVX9ewrcSXE36jzNAlI4TyWDUUie1taasA+naT3s1JfQVsmk//YzNR7G/GuYS7Mi04Rf6WUvVJmbVKOeDyZ61UZ1RAPeZSgzGwKFXaNScxj3B7owP0vO+w6IQOlEzbgn0= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848950314538.0590433883489; Tue, 14 May 2019 08:49:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C3C1C821CC; Tue, 14 May 2019 15:49:08 +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 9386E61995; Tue, 14 May 2019 15:49:08 +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 5736F3FA4F; Tue, 14 May 2019 15:49:08 +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 x4EFn1jf031909 for ; Tue, 14 May 2019 11:49:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9AE251981E; Tue, 14 May 2019 15:49:01 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id E360C2B9F0; Tue, 14 May 2019 15:49:00 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:29 +0100 Message-Id: <20190514154836.6427-18-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 17/24] virsh: add support for network port APIs 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-Type: text/plain; charset="utf-8" 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 14 May 2019 15:49:09 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 --- tools/virsh-completer.c | 50 +++++ tools/virsh-completer.h | 4 + tools/virsh-network.c | 399 +++++++++++++++++++++++++++++++++++++++- tools/virsh-network.h | 5 + 4 files changed, 457 insertions(+), 1 deletion(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 918e409890..7d5cf8cb90 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -408,6 +408,56 @@ virshNetworkEventNameCompleter(vshControl *ctl ATTRIBU= TE_UNUSED, } =20 =20 +char ** +virshNetworkPortUUIDCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virNetworkPtr net =3D NULL; + virNetworkPortPtr *ports =3D NULL; + int nports =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (!(net =3D virshCommandOptNetwork(ctl, cmd, NULL))) + return false; + + if ((nports =3D virNetworkListAllPorts(net, &ports, flags)) < 0) + return NULL; + + if (VIR_ALLOC_N(ret, nports + 1) < 0) + goto error; + + for (i =3D 0; i < nports; i++) { + char uuid[VIR_UUID_STRING_BUFLEN]; + + if (virNetworkPortGetUUIDString(ports[i], uuid) < 0 || + VIR_STRDUP(ret[i], uuid) < 0) + goto error; + + virNetworkPortFree(ports[i]); + } + VIR_FREE(ports); + + return ret; + + error: + for (; i < nports; i++) + virNetworkPortFree(ports[i]); + VIR_FREE(ports); + for (i =3D 0; i < nports; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + return NULL; +} + + char ** virshNodeDeviceNameCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index ed37a26cc9..cd3cc9ecae 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -59,6 +59,10 @@ char ** virshNetworkEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** virshNetworkPortUUIDCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + char ** virshNodeDeviceNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 14bf9a144f..af08441842 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -1,7 +1,7 @@ /* * virsh-network.c: Commands to manage network * - * Copyright (C) 2005, 2007-2016 Red Hat, Inc. + * Copyright (C) 2005, 2007-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -54,6 +54,16 @@ #define VIRSH_COMMON_OPT_NETWORK_OT_STRING_FULL(cflags) \ VIRSH_COMMON_OPT_NETWORK_OT_STRING(N_("network name or uuid"), cflags) =20 +#define VIRSH_COMMON_OPT_NETWORK_PORT(cflags) \ + {.name =3D "port", \ + .type =3D VSH_OT_DATA, \ + .flags =3D VSH_OFLAG_REQ, \ + .help =3D N_("port UUID"), \ + .completer =3D virshNetworkPortUUIDCompleter, \ + .completer_flags =3D cflags, \ + } + + virNetworkPtr virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, const char **name, unsigned int flags) @@ -92,6 +102,35 @@ virshCommandOptNetworkBy(vshControl *ctl, const vshCmd = *cmd, return network; } =20 + +virNetworkPortPtr +virshCommandOptNetworkPort(vshControl *ctl, const vshCmd *cmd, + virNetworkPtr net, + const char **name) +{ + virNetworkPortPtr port =3D NULL; + const char *n =3D NULL; + const char *optname =3D "port"; + + if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0) + return NULL; + + vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n", + cmd->def->name, optname, n); + + if (name) + *name =3D n; + + vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network UUID\n", + cmd->def->name, optname); + port =3D virNetworkPortLookupByUUIDString(net, n); + + if (!port) + vshError(ctl, _("failed to get network port '%s'"), n); + + return port; +} + /* * "net-autostart" command */ @@ -1437,6 +1476,340 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd = *cmd) return ret; } =20 +/* + * "net-port-create" command + */ +static const vshCmdInfo info_network_port_create[] =3D { + {.name =3D "help", + .data =3D N_("create a network port from an XML file") + }, + {.name =3D "desc", + .data =3D N_("Create a network port.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_network_port_create[] =3D { + VIRSH_COMMON_OPT_NETWORK_FULL(0), + VIRSH_COMMON_OPT_FILE(N_("file containing an XML network port descript= ion")), + {.name =3D NULL} +}; + +static bool +cmdNetworkPortCreate(vshControl *ctl, const vshCmd *cmd) +{ + virNetworkPortPtr port =3D NULL; + const char *from =3D NULL; + bool ret =3D false; + char *buffer =3D NULL; + virNetworkPtr network =3D NULL; + + network =3D virshCommandOptNetwork(ctl, cmd, NULL); + if (network =3D=3D NULL) + goto cleanup; + + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) + goto cleanup; + + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) + goto cleanup; + + port =3D virNetworkPortCreateXML(network, buffer, 0); + + if (port !=3D NULL) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virNetworkPortGetUUIDString(port, uuidstr); + vshPrintExtra(ctl, _("Network port %s created from %s\n"), + uuidstr, from); + } else { + vshError(ctl, _("Failed to create network from %s"), from); + goto cleanup; + } + + ret =3D true; + cleanup: + VIR_FREE(buffer); + if (port) + virNetworkPortFree(port); + if (network) + virNetworkFree(network); + return ret; +} + +/* + * "net-port-dumpxml" command + */ +static const vshCmdInfo info_network_port_dumpxml[] =3D { + {.name =3D "help", + .data =3D N_("network port information in XML") + }, + {.name =3D "desc", + .data =3D N_("Output the network port information as an XML dump to s= tdout.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_network_port_dumpxml[] =3D { + VIRSH_COMMON_OPT_NETWORK_FULL(0), + VIRSH_COMMON_OPT_NETWORK_PORT(0), + {.name =3D NULL} +}; + +static bool +cmdNetworkPortDumpXML(vshControl *ctl, const vshCmd *cmd) +{ + virNetworkPtr network; + virNetworkPortPtr port =3D NULL; + bool ret =3D true; + char *dump; + unsigned int flags =3D 0; + + if (!(network =3D virshCommandOptNetwork(ctl, cmd, NULL))) + goto cleanup; + + if (!(port =3D virshCommandOptNetworkPort(ctl, cmd, network, NULL))) + goto cleanup; + + dump =3D virNetworkPortGetXMLDesc(port, flags); + + if (dump !=3D NULL) { + vshPrint(ctl, "%s", dump); + VIR_FREE(dump); + } else { + ret =3D false; + } + + cleanup: + if (port) + virNetworkPortFree(port); + if (network) + virNetworkFree(network); + return ret; +} + + +/* + * "net-port-delete" command + */ +static const vshCmdInfo info_network_port_delete[] =3D { + {.name =3D "help", + .data =3D N_("network port information in XML") + }, + {.name =3D "desc", + .data =3D N_("Output the network port information as an XML dump to s= tdout.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_network_port_delete[] =3D { + VIRSH_COMMON_OPT_NETWORK_FULL(0), + VIRSH_COMMON_OPT_NETWORK_PORT(0), + {.name =3D NULL} +}; + +static bool +cmdNetworkPortDelete(vshControl *ctl, const vshCmd *cmd) +{ + virNetworkPtr network =3D NULL; + virNetworkPortPtr port =3D NULL; + bool ret =3D true; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + if (!(network =3D virshCommandOptNetwork(ctl, cmd, NULL))) + goto cleanup; + + if (!(port =3D virshCommandOptNetworkPort(ctl, cmd, network, NULL))) + goto cleanup; + + if (virNetworkPortGetUUIDString(port, uuidstr) < 0) + goto cleanup; + + if (virNetworkPortDelete(port, 0) < 0) { + vshError(ctl, _("Failed to delete network port %s"), uuidstr); + goto cleanup; + } else { + vshPrintExtra(ctl, _("Network port %s deleted\n"), uuidstr); + } + + ret =3D true; + cleanup: + if (port) + virNetworkPortFree(port); + if (network) + virNetworkFree(network); + return ret; +} + + +static int +virshNetworkPortSorter(const void *a, const void *b) +{ + virNetworkPortPtr *na =3D (virNetworkPortPtr *) a; + virNetworkPortPtr *nb =3D (virNetworkPortPtr *) b; + unsigned char uuida[VIR_UUID_BUFLEN]; + unsigned char uuidb[VIR_UUID_BUFLEN]; + + if (*na && !*nb) + return -1; + + if (!*na) + return *nb !=3D NULL; + + if (virNetworkPortGetUUID(*na, uuida) < 0 || + virNetworkPortGetUUID(*nb, uuidb) < 0) + return -1; + + return memcmp(uuida, uuidb, VIR_UUID_BUFLEN); +} + +struct virshNetworkPortList { + virNetworkPortPtr *ports; + size_t nports; +}; +typedef struct virshNetworkPortList *virshNetworkPortListPtr; + +static void +virshNetworkPortListFree(virshNetworkPortListPtr list) +{ + size_t i; + + if (list && list->ports) { + for (i =3D 0; i < list->nports; i++) { + if (list->ports[i]) + virNetworkPortFree(list->ports[i]); + } + VIR_FREE(list->ports); + } + VIR_FREE(list); +} + +static virshNetworkPortListPtr +virshNetworkPortListCollect(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshNetworkPortListPtr list =3D vshMalloc(ctl, sizeof(*list)); + int ret; + virNetworkPtr network =3D NULL; + bool success =3D false; + + if (!(network =3D virshCommandOptNetwork(ctl, cmd, NULL))) + goto cleanup; + + /* try the list with flags support (0.10.2 and later) */ + if ((ret =3D virNetworkListAllPorts(network, + &list->ports, + flags)) < 0) + goto cleanup; + + list->nports =3D ret; + + /* sort the list */ + if (list->ports && list->nports) + qsort(list->ports, list->nports, + sizeof(*list->ports), virshNetworkPortSorter); + + success =3D true; + + cleanup: + if (!success) { + virshNetworkPortListFree(list); + list =3D NULL; + } + + if (network) + virNetworkFree(network); + + return list; +} + +/* + * "net-list" command + */ +static const vshCmdInfo info_network_port_list[] =3D { + {.name =3D "help", + .data =3D N_("list network ports") + }, + {.name =3D "desc", + .data =3D N_("Returns list of network ports.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_network_port_list[] =3D { + VIRSH_COMMON_OPT_NETWORK_FULL(0), + {.name =3D "uuid", + .type =3D VSH_OT_BOOL, + .help =3D N_("list uuid's only") + }, + {.name =3D "table", + .type =3D VSH_OT_BOOL, + .help =3D N_("list table (default)") + }, + {.name =3D NULL} +}; + +#define FILTER(NAME, FLAG) \ + if (vshCommandOptBool(cmd, NAME)) \ + flags |=3D (FLAG) +static bool +cmdNetworkPortList(vshControl *ctl, const vshCmd *cmd) +{ + virshNetworkPortListPtr list =3D NULL; + size_t i; + bool ret =3D false; + bool optTable =3D vshCommandOptBool(cmd, "table"); + bool optUUID =3D vshCommandOptBool(cmd, "uuid"); + char uuid[VIR_UUID_STRING_BUFLEN]; + unsigned int flags =3D 0; + vshTablePtr table =3D NULL; + + if (optTable + optUUID > 1) { + vshError(ctl, "%s", + _("Only one argument from --table and --uuid " + "may be specified.")); + return false; + } + + if (!optUUID) + optTable =3D true; + + if (!(list =3D virshNetworkPortListCollect(ctl, cmd, flags))) + return false; + + if (optTable) { + table =3D vshTableNew(_("UUID"), NULL); + if (!table) + goto cleanup; + } + + for (i =3D 0; i < list->nports; i++) { + virNetworkPortPtr port =3D list->ports[i]; + + if (virNetworkPortGetUUIDString(port, uuid) < 0) { + vshError(ctl, "%s", _("Failed to get network's UUID")); + goto cleanup; + } + if (optTable) { + if (vshTableRowAppend(table, uuid, NULL) < 0) + goto cleanup; + } else if (optUUID) { + vshPrint(ctl, "%s\n", uuid); + } + } + + if (optTable) + vshTablePrintToStdout(table, ctl); + + ret =3D true; + cleanup: + vshTableFree(table); + virshNetworkPortListFree(list); + return ret; +} +#undef FILTER + + const vshCmdDef networkCmds[] =3D { {.name =3D "net-autostart", .handler =3D cmdNetworkAutostart, @@ -1528,5 +1901,29 @@ const vshCmdDef networkCmds[] =3D { .info =3D info_network_uuid, .flags =3D 0 }, + {.name =3D "net-port-list", + .handler =3D cmdNetworkPortList, + .opts =3D opts_network_port_list, + .info =3D info_network_port_list, + .flags =3D 0 + }, + {.name =3D "net-port-create", + .handler =3D cmdNetworkPortCreate, + .opts =3D opts_network_port_create, + .info =3D info_network_port_create, + .flags =3D 0 + }, + {.name =3D "net-port-dumpxml", + .handler =3D cmdNetworkPortDumpXML, + .opts =3D opts_network_port_dumpxml, + .info =3D info_network_port_dumpxml, + .flags =3D 0 + }, + {.name =3D "net-port-delete", + .handler =3D cmdNetworkPortDelete, + .opts =3D opts_network_port_delete, + .info =3D info_network_port_delete, + .flags =3D 0 + }, {.name =3D NULL} }; diff --git a/tools/virsh-network.h b/tools/virsh-network.h index 9c86eb5bc9..18b8e4365f 100644 --- a/tools/virsh-network.h +++ b/tools/virsh-network.h @@ -27,6 +27,11 @@ virNetworkPtr virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, const char **name, unsigned int flags); =20 +virNetworkPortPtr +virshCommandOptNetworkPort(vshControl *ctl, const vshCmd *cmd, + virNetworkPtr net, + const char **name); + /* default is lookup by Name and UUID */ # define virshCommandOptNetwork(_ctl, _cmd, _name) \ virshCommandOptNetworkBy(_ctl, _cmd, _name, \ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848961; cv=none; d=zoho.com; s=zohoarc; b=EdkrZFrhu3PSV1bjzl5I4j0dxAS9EiY4WrhovSGqjBMlQZwlXpkgM16lFxP/p0dtII70bPStCrOECkeRdQ8re2BPt3EKDYLh+5UyGgO4cYM8wr0qgGk1exDDwk/4aKxgXRqwPqo8t0Lpizc4LNkK2l76eewHPx6ix1HBqchWZi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848961; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=dgcNzhzH3P5I5W/OQbhixJTUzMZrW8Z4OYVgYvUX9so=; b=Z3K2cSf7sZ1erwKEZiDpANmN53DC3eQhVAHUVuANlzXvgPGi8Xb9SXQJRHDylrUCoaddESGJKPQCgzALCbrd/vZg0OI5PZYf+9DfQLk/XsLX2ISl4Ya5Doo4tmm8cF49gPF6duEhAN/OBU7USk7pbAFGkZdhsg761fyUwA1W8v4= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848961381589.2478234865943; Tue, 14 May 2019 08:49:21 -0700 (PDT) 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 C0A993082133; Tue, 14 May 2019 15:49:19 +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 92DCE5C644; Tue, 14 May 2019 15:49:19 +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 539063FA4C; Tue, 14 May 2019 15:49:19 +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 x4EFn4XW031933 for ; Tue, 14 May 2019 11:49:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id D1BF82B9EE; Tue, 14 May 2019 15:49:04 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE6172B9EF; Tue, 14 May 2019 15:49:01 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:30 +0100 Message-Id: <20190514154836.6427-19-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 18/24] conf: support recording ports against virNetworkObjPtr 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-Type: text/plain; charset="utf-8" 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.42]); Tue, 14 May 2019 15:49:20 +0000 (UTC) The virNetworkObjPtr state will need to maintain a record of all virNetworkPortDefPtr objects associated with the network. Record these in a hash and add APIs for manipulating them. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/virnetworkobj.c | 303 +++++++++++++++++++++++++++++++++++++++ src/conf/virnetworkobj.h | 34 +++++ src/libvirt_private.syms | 6 + 3 files changed, 343 insertions(+) diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index c9336e0472..47c142998e 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -58,6 +58,8 @@ struct _virNetworkObj { =20 /* Immutable pointer, self locking APIs */ virMacMapPtr macmap; + + virHashTablePtr ports; /* uuid -> virNetworkPortDefPtr */ }; =20 struct _virNetworkObjList { @@ -86,6 +88,17 @@ virNetworkObjOnceInit(void) =20 VIR_ONCE_GLOBAL_INIT(virNetworkObj); =20 +static int +virNetworkObjLoadAllPorts(virNetworkObjPtr net, + const char *stateDir); + + +static void +virNetworkObjPortFree(void *val, const void *key ATTRIBUTE_UNUSED) +{ + virNetworkPortDefFree(val); +} + virNetworkObjPtr virNetworkObjNew(void) { @@ -106,6 +119,10 @@ virNetworkObjNew(void) virBitmapSetBitExpand(obj->classIdMap, 2) < 0) goto error; =20 + if (!(obj->ports =3D virHashCreate(10, + virNetworkObjPortFree))) + goto error; + virObjectLock(obj); =20 return obj; @@ -458,6 +475,7 @@ virNetworkObjDispose(void *opaque) { virNetworkObjPtr obj =3D opaque; =20 + virHashFree(obj->ports); virNetworkDefFree(obj->def); virNetworkDefFree(obj->newDef); virBitmapFree(obj->classIdMap); @@ -1072,9 +1090,16 @@ virNetworkObjLoadAllState(virNetworkObjListPtr nets, continue; =20 obj =3D virNetworkLoadState(nets, stateDir, entry->d_name); + + if (obj && + virNetworkObjLoadAllPorts(obj, stateDir) < 0) { + virNetworkObjEndAPI(&obj); + goto cleanup; + } virNetworkObjEndAPI(&obj); } =20 + cleanup: VIR_DIR_CLOSE(dir); return ret; } @@ -1584,3 +1609,281 @@ virNetworkObjListPrune(virNetworkObjListPtr nets, virHashRemoveSet(nets->objs, virNetworkObjListPruneHelper, &data); virObjectRWUnlock(nets); } + + +char * +virNetworkObjGetPortStatusDir(virNetworkObjPtr net, + const char *stateDir) +{ + char *ret; + ignore_value(virAsprintf(&ret, "%s/%s/ports", stateDir, net->def->name= )); + return ret; +} + +int +virNetworkObjAddPort(virNetworkObjPtr net, + virNetworkPortDefPtr portdef, + const char *stateDir) +{ + int ret =3D -1; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + char *dir =3D NULL; + + virUUIDFormat(portdef->uuid, uuidstr); + + if (virHashLookup(net->ports, uuidstr)) { + virReportError(VIR_ERR_NETWORK_PORT_EXIST, + _("Network port with UUID %s already exists"), + uuidstr); + goto cleanup; + } + + if (!(dir =3D virNetworkObjGetPortStatusDir(net, stateDir))) + goto cleanup; + + if (virHashAddEntry(net->ports, uuidstr, portdef) < 0) + goto cleanup; + + if (virNetworkPortDefSaveStatus(portdef, dir) < 0) { + virHashRemoveEntry(net->ports, uuidstr); + goto cleanup; + } + + ret =3D 0; + + cleanup: + return ret; +} + + +virNetworkPortDefPtr +virNetworkObjLookupPort(virNetworkObjPtr net, + const unsigned char *uuid) +{ + virNetworkPortDefPtr ret =3D NULL; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(uuid, uuidstr); + + if (!(ret =3D virHashLookup(net->ports, uuidstr))) { + virReportError(VIR_ERR_NO_NETWORK_PORT, + _("Network port with UUID %s does not exist"), + uuidstr); + goto cleanup; + } + + cleanup: + return ret; +} + + +int +virNetworkObjDeletePort(virNetworkObjPtr net, + const unsigned char *uuid, + const char *stateDir) +{ + int ret =3D -1; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + char *dir =3D NULL; + virNetworkPortDefPtr portdef; + + virUUIDFormat(uuid, uuidstr); + + if (!(portdef =3D virHashLookup(net->ports, uuidstr))) { + virReportError(VIR_ERR_NO_NETWORK_PORT, + _("Network port with UUID %s does not exist"), + uuidstr); + goto cleanup; + } + + if (!(dir =3D virNetworkObjGetPortStatusDir(net, stateDir))) + goto cleanup; + + if (virNetworkPortDefDeleteStatus(portdef, dir) < 0) + goto cleanup; + + if (virHashRemoveEntry(net->ports, uuidstr) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(dir); + return ret; +} + + +int +virNetworkObjDeleteAllPorts(virNetworkObjPtr net, + const char *stateDir) +{ + char *dir; + DIR *dh; + struct dirent *de; + int rc; + int ret =3D -1; + + if (!(dir =3D virNetworkObjGetPortStatusDir(net, stateDir))) + goto cleanup; + + if ((rc =3D virDirOpenIfExists(&dh, dir)) <=3D 0) { + ret =3D rc; + goto cleanup; + } + + while ((rc =3D virDirRead(dh, &de, dir)) > 0) { + char *file =3D NULL; + + if (!virStringStripSuffix(de->d_name, ".xml")) + continue; + + if (virAsprintf(&file, "%s/%s.xml", dir, de->d_name) < 0) + goto cleanup; + + if (unlink(file) < 0 && errno !=3D ENOENT) + VIR_WARN("Unable to delete %s", file); + + VIR_FREE(file); + } + + virHashRemoveAll(net->ports); + + ret =3D 0; + cleanup: + return ret; +} + + +typedef struct _virNetworkObjPortListExportData virNetworkObjPortListExpor= tData; +typedef virNetworkObjPortListExportData *virNetworkObjPortListExportDataPt= r; +struct _virNetworkObjPortListExportData { + virNetworkPtr net; + virNetworkDefPtr def; + virNetworkPortPtr *ports; + virNetworkPortListFilter filter; + int nports; + bool error; +}; + +static int +virNetworkObjPortListExportCallback(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + virNetworkObjPortListExportDataPtr data =3D opaque; + virNetworkPortDefPtr def =3D payload; + virNetworkPortPtr port; + + if (data->error) + return 0; + + if (data->filter && + !data->filter(data->net->conn, data->def, def)) + goto cleanup; + + if (!data->ports) { + data->nports++; + goto cleanup; + } + + if (!(port =3D virGetNetworkPort(data->net, def->uuid))) { + data->error =3D true; + goto cleanup; + } + + data->ports[data->nports++] =3D port; + + cleanup: + return 0; +} + + +int +virNetworkObjPortListExport(virNetworkPtr net, + virNetworkObjPtr obj, + virNetworkPortPtr **ports, + virNetworkPortListFilter filter) +{ + virNetworkObjPortListExportData data =3D { + net, obj->def, NULL, filter, 0, false, + }; + int ret =3D -1; + + *ports =3D NULL; + + if (ports && VIR_ALLOC_N(data.ports, virHashSize(obj->ports) + 1) < 0) + goto cleanup; + + virHashForEach(obj->ports, virNetworkObjPortListExportCallback, &data); + + if (data.error) + goto cleanup; + + if (data.ports) { + /* trim the array to the final size */ + ignore_value(VIR_REALLOC_N(data.ports, data.nports + 1)); + *ports =3D data.ports; + data.ports =3D NULL; + } + + ret =3D data.nports; + cleanup: + while (data.ports && data.nports) + virObjectUnref(data.ports[--data.nports]); + + VIR_FREE(data.ports); + return ret; +} + + +static int +virNetworkObjLoadAllPorts(virNetworkObjPtr net, + const char *stateDir) +{ + char *dir; + DIR *dh =3D NULL; + struct dirent *de; + int ret =3D -1; + int rc; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virNetworkPortDefPtr portdef =3D NULL; + + if (!(dir =3D virNetworkObjGetPortStatusDir(net, stateDir))) + goto cleanup; + + if ((rc =3D virDirOpenIfExists(&dh, dir)) <=3D 0) { + ret =3D rc; + goto cleanup; + } + + while ((rc =3D virDirRead(dh, &de, dir)) > 0) { + char *file =3D NULL; + + if (!virStringStripSuffix(de->d_name, ".xml")) + continue; + + if (virAsprintf(&file, "%s/%s.xml", dir, de->d_name) < 0) + goto cleanup; + + portdef =3D virNetworkPortDefParseFile(file); + VIR_FREE(file); + file =3D NULL; + + if (!portdef) { + VIR_WARN("Cannot parse port %s", file); + continue; + } + + virUUIDFormat(portdef->uuid, uuidstr); + if (virHashAddEntry(net->ports, uuidstr, portdef) < 0) + goto cleanup; + + portdef =3D NULL; + } + + ret =3D 0; + cleanup: + VIR_DIR_CLOSE(dh); + virNetworkPortDefFree(portdef); + return ret; +} diff --git a/src/conf/virnetworkobj.h b/src/conf/virnetworkobj.h index 9c8f141cd9..9d9b29fc25 100644 --- a/src/conf/virnetworkobj.h +++ b/src/conf/virnetworkobj.h @@ -23,6 +23,7 @@ # include "internal.h" =20 # include "network_conf.h" +# include "virnetworkportdef.h" =20 typedef struct _virNetworkObj virNetworkObj; typedef virNetworkObj *virNetworkObjPtr; @@ -156,6 +157,39 @@ void virNetworkObjRemoveInactive(virNetworkObjListPtr nets, virNetworkObjPtr net); =20 +int +virNetworkObjAddPort(virNetworkObjPtr net, + virNetworkPortDefPtr portdef, + const char *stateDir); + +char * +virNetworkObjGetPortStatusDir(virNetworkObjPtr net, + const char *stateDir); + +virNetworkPortDefPtr +virNetworkObjLookupPort(virNetworkObjPtr net, + const unsigned char *uuid); + +int +virNetworkObjDeletePort(virNetworkObjPtr net, + const unsigned char *uuid, + const char *stateDir); + +int +virNetworkObjDeleteAllPorts(virNetworkObjPtr net, + const char *stateDir); + +typedef bool +(*virNetworkPortListFilter)(virConnectPtr conn, + virNetworkDefPtr def, + virNetworkPortDefPtr portdef); + +int +virNetworkObjPortListExport(virNetworkPtr net, + virNetworkObjPtr obj, + virNetworkPortPtr **ports, + virNetworkPortListFilter filter); + int virNetworkObjSaveStatus(const char *statusDir, virNetworkObjPtr net) ATTRIBUTE_RETURN_CHECK; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a88917c957..0c357f72a3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1031,9 +1031,12 @@ virInterfaceObjSetActive; =20 =20 # conf/virnetworkobj.h +virNetworkObjAddPort; virNetworkObjAssignDef; virNetworkObjBridgeInUse; +virNetworkObjDeleteAllPorts; virNetworkObjDeleteConfig; +virNetworkObjDeletePort; virNetworkObjEndAPI; virNetworkObjFindByName; virNetworkObjFindByUUID; @@ -1044,6 +1047,7 @@ virNetworkObjGetFloorSum; virNetworkObjGetMacMap; virNetworkObjGetNewDef; virNetworkObjGetPersistentDef; +virNetworkObjGetPortStatusDir; virNetworkObjGetRadvdPid; virNetworkObjIsActive; virNetworkObjIsAutostart; @@ -1056,9 +1060,11 @@ virNetworkObjListNumOfNetworks; virNetworkObjListPrune; virNetworkObjLoadAllConfigs; virNetworkObjLoadAllState; +virNetworkObjLookupPort; virNetworkObjMacMgrAdd; virNetworkObjMacMgrDel; virNetworkObjNew; +virNetworkObjPortListExport; virNetworkObjRemoveInactive; virNetworkObjReplacePersistentDef; virNetworkObjSaveStatus; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848965; cv=none; d=zoho.com; s=zohoarc; b=GIqQb0oqBQ/ebGDTlV8OqAPJ/GlfWa5ewJIJQ0Tu0VbIsuRlYlVByHo+akKRftEQtSPj3PIyLWxVcQMdD2DurVybNNc43DbxbXCImglce09jE4fqZkjk7fdgPW4UK91O3q7T7Rni3ejcYstz1yQ2PVjR5KfarIS74puK6Jdb38U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848965; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=VaBFjEEvvj/VUIQD+sVz9/8VVaNrNmK5DM5ej6p65JA=; b=SlsmtEctzOOxTQXP7siKpQxhkhbrxcAvjUMI+1AEZUi+x1UUrhoXNjCab/6cj5cY9EDHv1/mvHOAxROMyK4NAXI1lDtCnknpzRWC1gaL/p9w/OxB7p16t/7bQ2bYSL7SX4DyYaIUEoFn8AqiywvdlzQ6Qsr+ifRX769g05EYDjI= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848965038344.4260012545112; Tue, 14 May 2019 08:49:25 -0700 (PDT) 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 6500418DF7A; Tue, 14 May 2019 15:49:23 +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 31FD2608CC; Tue, 14 May 2019 15:49:23 +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 DB1AF180599C; Tue, 14 May 2019 15:49:22 +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 x4EFn6lX031945 for ; Tue, 14 May 2019 11:49:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2954D60BCF; Tue, 14 May 2019 15:49:06 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 702EF2B9F0; Tue, 14 May 2019 15:49:04 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:31 +0100 Message-Id: <20190514154836.6427-20-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 19/24] network: add implementation of network port APIs 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-Type: text/plain; charset="utf-8" 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, 14 May 2019 15:49:23 +0000 (UTC) This initial implementation just wires up the APIs and does tracking of the port XML definitions. It is not yet integrated into the resource allocation logic. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 400 ++++++++++++++++++++++++++++++++++++ 1 file changed, 400 insertions(+) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index aada1e0316..0b9d440d42 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2773,6 +2773,8 @@ networkStartNetwork(virNetworkDriverStatePtr driver, =20 VIR_DEBUG("Beginning network startup process"); =20 + virNetworkObjDeleteAllPorts(obj, driver->stateDir); + VIR_DEBUG("Setting current network def as transient"); if (virNetworkObjSetDefTransient(obj, true) < 0) goto cleanup; @@ -3950,6 +3952,9 @@ networkDestroy(virNetworkPtr net) =20 if ((ret =3D networkShutdownNetwork(driver, obj)) < 0) goto cleanup; + + virNetworkObjDeleteAllPorts(obj, driver->stateDir); + /* @def replaced in virNetworkObjUnsetDefTransient*/ def =3D virNetworkObjGetDef(obj); =20 @@ -5545,6 +5550,394 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, } =20 =20 +static virNetworkPortPtr +networkPortLookupByUUID(virNetworkPtr net, + const unsigned char *uuid) +{ + virNetworkObjPtr obj; + virNetworkDefPtr def; + virNetworkPortDefPtr portdef =3D NULL; + virNetworkPortPtr ret =3D NULL; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virUUIDFormat(uuid, uuidstr); + + if (!(obj =3D networkObjFromNetwork(net))) + return ret; + + def =3D virNetworkObjGetDef(obj); + + if (!(portdef =3D virNetworkObjLookupPort(obj, uuid))) + goto cleanup; + + if (virNetworkPortLookupByUUIDEnsureACL(net->conn, def, portdef) < 0) + goto cleanup; + + if (!virNetworkObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("network '%s' is not active"), + def->name); + goto cleanup; + } + + ret =3D virGetNetworkPort(net, uuid); + + cleanup: + virNetworkObjEndAPI(&obj); + return ret; +} + + +static virNetworkPortPtr +networkPortCreateXML(virNetworkPtr net, + const char *xmldesc, + unsigned int flags) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virNetworkObjPtr obj; + virNetworkDefPtr def; + virNetworkPortDefPtr portdef =3D NULL; + virNetworkPortPtr ret =3D NULL; + int rc; + + virCheckFlags(VIR_NETWORK_PORT_CREATE_RECLAIM, NULL); + + if (!(obj =3D networkObjFromNetwork(net))) + return ret; + + def =3D virNetworkObjGetDef(obj); + + if (!(portdef =3D virNetworkPortDefParseString(xmldesc))) + goto cleanup; + + if (virNetworkPortCreateXMLEnsureACL(net->conn, def, portdef) < 0) + goto cleanup; + + if (!virNetworkObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("network '%s' is not active"), + def->name); + goto cleanup; + } + + if (portdef->plugtype =3D=3D VIR_NETWORK_PORT_PLUG_TYPE_NONE) { + if (flags & VIR_NETWORK_PORT_CREATE_RECLAIM) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Port reclaim requested but plug type is none= ")); + goto cleanup; + } + } else { + if (!(flags & VIR_NETWORK_PORT_CREATE_RECLAIM)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Port reclaim not requested but plug type is = not none")); + goto cleanup; + } + } + + if (flags & VIR_NETWORK_PORT_CREATE_RECLAIM) + rc =3D networkNotifyPort(obj, portdef); + else + rc =3D networkAllocatePort(obj, portdef); + if (rc < 0) { + virErrorPtr saved; + saved =3D virSaveLastError(); + ignore_value(networkReleasePort(obj, portdef)); + virSetError(saved); + virFreeError(saved); + goto cleanup; + } + + if (virNetworkObjAddPort(obj, portdef, driver->stateDir) < 0) { + virNetworkPortDefFree(portdef); + goto cleanup; + } + + ret =3D virGetNetworkPort(net, portdef->uuid); + cleanup: + virNetworkObjEndAPI(&obj); + return ret; +} + + +static char * +networkPortGetXMLDesc(virNetworkPortPtr port, + unsigned int flags) +{ + virNetworkObjPtr obj; + virNetworkDefPtr def; + virNetworkPortDefPtr portdef =3D NULL; + char *ret =3D NULL; + + virCheckFlags(0, NULL); + + if (!(obj =3D networkObjFromNetwork(port->net))) + return ret; + + def =3D virNetworkObjGetDef(obj); + + if (!(portdef =3D virNetworkObjLookupPort(obj, port->uuid))) + goto cleanup; + + if (virNetworkPortGetXMLDescEnsureACL(port->net->conn, def, portdef) <= 0) + goto cleanup; + + if (!virNetworkObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("network '%s' is not active"), + def->name); + goto cleanup; + } + + if (!(ret =3D virNetworkPortDefFormat(portdef))) + goto cleanup; + + cleanup: + virNetworkObjEndAPI(&obj); + return ret; +} + + +static int +networkPortDelete(virNetworkPortPtr port, + unsigned int flags) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virNetworkObjPtr obj; + virNetworkDefPtr def; + virNetworkPortDefPtr portdef; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (!(obj =3D networkObjFromNetwork(port->net))) + return ret; + + def =3D virNetworkObjGetDef(obj); + + if (!(portdef =3D virNetworkObjLookupPort(obj, port->uuid))) + goto cleanup; + + if (virNetworkPortDeleteEnsureACL(port->net->conn, def, portdef) < 0) + goto cleanup; + + if (!virNetworkObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("network '%s' is not active"), + def->name); + goto cleanup; + } + + if (networkReleasePort(obj, portdef) < 0) + goto cleanup; + + virNetworkObjDeletePort(obj, port->uuid, driver->stateDir); + + ret =3D 0; + cleanup: + virNetworkObjEndAPI(&obj); + return ret; +} + + +static int +networkPortSetParameters(virNetworkPortPtr port, + virTypedParameterPtr params, + int nparams, + unsigned int flags) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virNetworkObjPtr obj; + virNetworkDefPtr def; + virNetworkPortDefPtr portdef; + virNetDevBandwidthPtr bandwidth =3D NULL; + char *dir =3D NULL; + int ret =3D -1; + size_t i; + + virCheckFlags(0, -1); + + if (!(obj =3D networkObjFromNetwork(port->net))) + return ret; + + def =3D virNetworkObjGetDef(obj); + + if (!(portdef =3D virNetworkObjLookupPort(obj, port->uuid))) + goto cleanup; + + if (virNetworkPortSetParametersEnsureACL(port->net->conn, def, portdef= ) < 0) + goto cleanup; + + if (!virNetworkObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("network '%s' is not active"), + def->name); + goto cleanup; + } + + if (!(dir =3D virNetworkObjGetPortStatusDir(obj, driver->stateDir))) + goto cleanup; + + if ((VIR_ALLOC(bandwidth) < 0) || + (VIR_ALLOC(bandwidth->in) < 0) || + (VIR_ALLOC(bandwidth->out) < 0)) + goto cleanup; + + for (i =3D 0; i < nparams; i++) { + virTypedParameterPtr param =3D ¶ms[i]; + + if (STREQ(param->field, VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE)) { + bandwidth->in->average =3D param->value.ui; + } else if (STREQ(param->field, VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK)= ) { + bandwidth->in->peak =3D param->value.ui; + } else if (STREQ(param->field, VIR_NETWORK_PORT_BANDWIDTH_IN_BURST= )) { + bandwidth->in->burst =3D param->value.ui; + } else if (STREQ(param->field, VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR= )) { + bandwidth->in->floor =3D param->value.ui; + } else if (STREQ(param->field, VIR_NETWORK_PORT_BANDWIDTH_OUT_AVER= AGE)) { + bandwidth->out->average =3D param->value.ui; + } else if (STREQ(param->field, VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK= )) { + bandwidth->out->peak =3D param->value.ui; + } else if (STREQ(param->field, VIR_NETWORK_PORT_BANDWIDTH_OUT_BURS= T)) { + bandwidth->out->burst =3D param->value.ui; + } + } + + /* average or floor are mandatory, peak and burst are optional. + * So if no average or floor is given, we free inbound/outbound + * here which causes inbound/outbound to not be set. */ + if (!bandwidth->in->average && !bandwidth->in->floor) + VIR_FREE(bandwidth->in); + if (!bandwidth->out->average) + VIR_FREE(bandwidth->out); + + if (networkUpdatePortBandwidth(obj, + &portdef->mac, + &portdef->class_id, + portdef->bandwidth, + bandwidth) < 0) + goto cleanup; + + virNetDevBandwidthFree(portdef->bandwidth); + portdef->bandwidth =3D bandwidth; + bandwidth =3D NULL; + + if (virNetworkPortDefSaveStatus(portdef, dir) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virNetDevBandwidthFree(bandwidth); + virNetworkObjEndAPI(&obj); + VIR_FREE(dir); + return ret; +} + + +static int +networkPortGetParameters(virNetworkPortPtr port, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags) +{ + virNetworkObjPtr obj; + virNetworkDefPtr def; + virNetworkPortDefPtr portdef; + int maxparams =3D 0; + int ret =3D -1; + + virCheckFlags(0, -1); + + *params =3D NULL; + *nparams =3D 0; + + if (!(obj =3D networkObjFromNetwork(port->net))) + return ret; + + def =3D virNetworkObjGetDef(obj); + + if (!(portdef =3D virNetworkObjLookupPort(obj, port->uuid))) + goto cleanup; + + if (virNetworkPortGetParametersEnsureACL(port->net->conn, def, portdef= ) < 0) + goto cleanup; + + if (!virNetworkObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("network '%s' is not active"), + def->name); + goto cleanup; + } + + if (portdef->bandwidth) { + if ((portdef->bandwidth->in !=3D NULL) && + (virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE, + portdef->bandwidth->in->average) < 0 || + virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK, + portdef->bandwidth->in->peak) < 0 || + virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR, + portdef->bandwidth->in->floor) < 0 || + virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_IN_BURST, + portdef->bandwidth->in->burst) < 0)) + goto cleanup; + + if ((portdef->bandwidth->out !=3D NULL) && + (virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE, + portdef->bandwidth->out->average) < 0 || + virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK, + portdef->bandwidth->out->peak) < 0 || + virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST, + portdef->bandwidth->out->burst) < 0)) + goto cleanup; + } + + ret =3D 0; + cleanup: + virNetworkObjEndAPI(&obj); + return ret; +} + + +static int +networkListAllPorts(virNetworkPtr net, + virNetworkPortPtr **ports, + unsigned int flags) +{ + virNetworkObjPtr obj; + virNetworkDefPtr def; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (!(obj =3D networkObjFromNetwork(net))) + return ret; + + def =3D virNetworkObjGetDef(obj); + + if (virNetworkListAllPortsEnsureACL(net->conn, def) < 0) + goto cleanup; + + if (!virNetworkObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("network '%s' is not active"), + def->name); + goto cleanup; + } + + ret =3D virNetworkObjPortListExport(net, obj, ports, + virNetworkListAllPortsCheckACL); + + cleanup: + virNetworkObjEndAPI(&obj); + return ret; +} + + static virNetworkDriver networkDriver =3D { .name =3D "bridge", .connectNumOfNetworks =3D networkConnectNumOfNetworks, /* 0.2.0 */ @@ -5569,6 +5962,13 @@ static virNetworkDriver networkDriver =3D { .networkIsActive =3D networkIsActive, /* 0.7.3 */ .networkIsPersistent =3D networkIsPersistent, /* 0.7.3 */ .networkGetDHCPLeases =3D networkGetDHCPLeases, /* 1.2.6 */ + .networkPortLookupByUUID =3D networkPortLookupByUUID, /* 5.3.0 */ + .networkPortCreateXML =3D networkPortCreateXML, /* 5.3.0 */ + .networkPortGetXMLDesc =3D networkPortGetXMLDesc, /* 5.3.0 */ + .networkPortDelete =3D networkPortDelete, /* 5.3.0 */ + .networkListAllPorts =3D networkListAllPorts, /* 5.3.0 */ + .networkPortGetParameters =3D networkPortGetParameters, /* 5.3.0 */ + .networkPortSetParameters =3D networkPortSetParameters, /* 5.3.0 */ }; =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848951; cv=none; d=zoho.com; s=zohoarc; b=jPNHGSJ2fhYGJGIShBz7sIqTt6ZSkVsnND6XUTCJZqRmtqEgjbanVdCB/clU/5jvnjGh94bkVDwpN4inMtAbXkHV+FgwfmX8Zce8xjLRivJ9AUsg3hT1BMlHumhxZPy4eRssyTyvfUTLiCFBQn24ZzRSuhS/r9YvIOTVV8qL1f8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848951; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KIrhaaHrYhmHNi9TCSTe+1JMgFPbKUsucialBBOZ7lA=; b=FbbRv148QtBAw9XUhoZmKwiYdSVvUkeXKo9wLExyV4xGKQfZTkmQTcpSCiXqCj4AOXdr8FAmKeCwhm4ea38MJd2BTKD0lTUQ8/semC+h6mp0VXWTjnoVJRwqft1+YI1YjlurjOQL4qkOhZxDaN0YKgBNTQknwagzlWdkw7DYFNU= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848951447468.32020013605404; Tue, 14 May 2019 08:49:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C713D3099FCB; Tue, 14 May 2019 15:49:09 +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 7F18310027C1; Tue, 14 May 2019 15:49:09 +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 3BE6518033DF; Tue, 14 May 2019 15:49:09 +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 x4EFn7hu031958 for ; Tue, 14 May 2019 11:49:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1DD8C2B9E4; Tue, 14 May 2019 15:49:07 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6ACB21981E; Tue, 14 May 2019 15:49:06 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:32 +0100 Message-Id: <20190514154836.6427-21-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 20/24] lxc, libxl: notify network driver of NICs during reconnect 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 14 May 2019 15:49:10 +0000 (UTC) When starting up it is important to notify the network driver of any NICs which are used by running guests so that it can account for any resources they are using. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libxl/libxl_driver.c | 30 ++++++++++++++++++++++++++++++ src/lxc/lxc_process.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 2b9c6f1866..e2819eb0cc 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -352,6 +352,34 @@ libxlAutostartDomain(virDomainObjPtr vm, return ret; } =20 + +static void +libxlReconnectNotifyNets(virDomainDefPtr def) +{ + size_t i; + virConnectPtr conn =3D NULL; + + for (i =3D 0; i < def->nnets; i++) { + virDomainNetDefPtr net =3D def->nets[i]; + /* keep others from trying to use the macvtap device name, but + * don't return error if this happens, since that causes the + * domain to be unceremoniously killed, which would be *very* + * impolite. + */ + if (virDomainNetGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_DIRE= CT) + ignore_value(virNetDevMacVLanReserveName(net->ifname, false)); + + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (!conn && !(conn =3D virGetConnectNetwork())) + continue; + virDomainNetNotifyActualDevice(conn, def, net); + } + } + + virObjectUnref(conn); +} + + /* * Reconnect to running domains that were previously started/created * with libxenlight driver. @@ -424,6 +452,8 @@ libxlReconnectDomain(virDomainObjPtr vm, /* Enable domain death events */ libxl_evenable_domain_death(cfg->ctx, vm->def->id, 0, &priv->deathW); =20 + libxlReconnectNotifyNets(vm->def); + /* now that we know it's reconnected call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL) && STRNEQ("Domain-0", vm->def->name)) { diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index de4d7c73fb..b59cbbaba5 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1646,6 +1646,34 @@ virLXCProcessAutostartAll(virLXCDriverPtr driver) virObjectUnref(conn); } =20 + +static void +virLXCProcessReconnectNotifyNets(virDomainDefPtr def) +{ + size_t i; + virConnectPtr conn =3D NULL; + + for (i =3D 0; i < def->nnets; i++) { + virDomainNetDefPtr net =3D def->nets[i]; + /* keep others from trying to use the macvtap device name, but + * don't return error if this happens, since that causes the + * domain to be unceremoniously killed, which would be *very* + * impolite. + */ + if (virDomainNetGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_DIRE= CT) + ignore_value(virNetDevMacVLanReserveName(net->ifname, false)); + + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (!conn && !(conn =3D virGetConnectNetwork())) + continue; + virDomainNetNotifyActualDevice(conn, def, net); + } + } + + virObjectUnref(conn); +} + + static int virLXCProcessReconnectDomain(virDomainObjPtr vm, void *opaque) @@ -1692,6 +1720,8 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, vm->def, vm->pid) < 0) goto error; =20 + virLXCProcessReconnectNotifyNets(vm->def); + /* now that we know it's reconnected call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { char *xml =3D virDomainDefFormat(vm->def, driver->caps, 0); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848968; cv=none; d=zoho.com; s=zohoarc; b=XHjZIbtz7rG4Ak/orSne7wOo/URxW7bKjZP+5Pj+5ksPfexUu/DK294yl0JTqa7cnNuJMrZFSL0dvo1RyKbNf6Mi5B5HeQ0FtOGU4WXU1FHOTt6ij0JlVo4lRRHxC0RYZo33vKKn3TgzhK4WTSgFiMYk7+nSOZN8XmwzZwfHNjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848968; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=cQJNgsa54eZ7XAfOFcQCqFdcWS+4YCTJJlQTz/KJoTI=; b=N8wht9UP0yD69w32JYAZvCk44QDF5HiX9NycEvcZgGhBffl/Oc7+SqlDM8IBjGuPyVUMRR1QGBp1INVHuGkPw2/es297j9wyzkBfDPHsQK3UpeOpScTRxphiXn8H9YGqsqjk0zqNjo1x/SFEjVBJTCI1C1UhWoYKtf6BiIbIwKk= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848968643166.29998677052868; Tue, 14 May 2019 08:49:28 -0700 (PDT) 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 0106A30089B9; Tue, 14 May 2019 15:49:27 +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 CCB8F4C5; Tue, 14 May 2019 15:49:26 +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 807DE1803507; Tue, 14 May 2019 15:49:26 +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 x4EFn88g032005 for ; Tue, 14 May 2019 11:49:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id DD8471981E; Tue, 14 May 2019 15:49:08 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61F6763B86; Tue, 14 May 2019 15:49:07 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:33 +0100 Message-Id: <20190514154836.6427-22-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 21/24] lxc, libxl: save domain status after reconnect 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-Type: text/plain; charset="utf-8" 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.46]); Tue, 14 May 2019 15:49:27 +0000 (UTC) The various steps involved in reconnecting to a domain may cause updates to the virDomainObj struct that need to be reflected in the saved status file. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libxl/libxl_driver.c | 3 +++ src/lxc/lxc_process.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index e2819eb0cc..2adb604f0f 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -454,6 +454,9 @@ libxlReconnectDomain(virDomainObjPtr vm, =20 libxlReconnectNotifyNets(vm->def); =20 + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps) = < 0) + VIR_WARN("Cannot update XML for running Xen guest %s", vm->def->na= me); + /* now that we know it's reconnected call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL) && STRNEQ("Domain-0", vm->def->name)) { diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index b59cbbaba5..714eef20c8 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1680,6 +1680,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, { virLXCDriverPtr driver =3D opaque; virLXCDomainObjPrivatePtr priv; + virLXCDriverConfigPtr cfg =3D virLXCDriverGetConfig(driver); int ret =3D -1; =20 virObjectLock(vm); @@ -1722,6 +1723,9 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, =20 virLXCProcessReconnectNotifyNets(vm->def); =20 + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver-= >caps) < 0) + VIR_WARN("Cannot update XML for running LXC guest %s", vm->def= ->name); + /* now that we know it's reconnected call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { char *xml =3D virDomainDefFormat(vm->def, driver->caps, 0); @@ -1742,6 +1746,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, =20 ret =3D 0; cleanup: + virObjectUnref(cfg); virObjectUnlock(vm); return ret; =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848955; cv=none; d=zoho.com; s=zohoarc; b=TuetOEc9H6PCkMzGZ7CimfXIpNtftJ1Rm+XPar3G9/oEW/8XX/GBExdA4ec2QeeNce/Gy0huwyP8r5iy9upa1MqxnEP/pUrT99dc8Xl/jvG+JKG5K0W/gM+WxkXwumnisMr9+gX/ViVS+11Kr3ddZQ7SRAqaJsgBps4kvKf3wlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848955; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=geWw4CPMeIxihO8c6FXUObHnEoT+EmT1gwZ9byqEPvE=; b=GdZPq3T+jeLgzv7MGn3cEmCoxGZ5IzVLAmhGb6yZF5yyRNFS9QG84LMKPzUmYGkywDvwgLPnvdCesHEcAqavyfUN5TYCVd2EgJLQhyQejFK+aVWaaHcuBcGEkH7ZArbjem0PUwR8bGt2IXUT803xP+o9EmFu0PUBD9XW24sCEFo= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848955699900.1385015452707; Tue, 14 May 2019 08:49:15 -0700 (PDT) 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 1CF92307D978; Tue, 14 May 2019 15:49:14 +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 E76B9608BC; Tue, 14 May 2019 15:49:13 +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 9589D1803384; Tue, 14 May 2019 15:49:13 +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 x4EFnCpN032052 for ; Tue, 14 May 2019 11:49:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 220B22B9F0; Tue, 14 May 2019 15:49:12 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A6D463B86; Tue, 14 May 2019 15:49:09 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:34 +0100 Message-Id: <20190514154836.6427-23-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 22/24] conf: record a portid against the domain conf 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-Type: text/plain; charset="utf-8" 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.48]); Tue, 14 May 2019 15:49:14 +0000 (UTC) The portid will be the UUID of the virNetworkPort object associated with the network interface when a guest is running. Signed-off-by: Daniel P. Berrang=C3=A9 --- docs/formatdomain.html.in | 8 +++++++ docs/schemas/domaincommon.rng | 5 +++++ src/conf/domain_conf.c | 21 +++++++++++++++++++ src/conf/domain_conf.h | 4 ++++ .../net-virtio-network-portgroup.xml | 6 +++--- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index e1da878fcc..e25126b315 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -5309,6 +5309,14 @@ information for different classes of network connections. Since 0.9.4.

    +

    + When a guest is running and interface of type network + may include a portid attribute. This provides the UUID + of an associated virNetworkPortPtr object that records the associati= on + between the domain interface and the network. This attribute is + read-only since port objects are create and deleted automatically + during startup and shutdown. Since 5.1.0/ +

    Also, similar to direct network connections (described below), a connection of type network may diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 111b85c36f..ecdde43c3a 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -2591,6 +2591,11 @@ + + + + + =20 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1d2ad0fa92..f43426f9a2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11389,6 +11389,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, VIR_AUTOFREE(char *) type =3D NULL; VIR_AUTOFREE(char *) network =3D NULL; VIR_AUTOFREE(char *) portgroup =3D NULL; + VIR_AUTOFREE(char *) portid =3D NULL; VIR_AUTOFREE(char *) bridge =3D NULL; VIR_AUTOFREE(char *) dev =3D NULL; VIR_AUTOFREE(char *) ifname =3D NULL; @@ -11466,6 +11467,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, virXMLNodeNameEqual(cur, "source")) { network =3D virXMLPropString(cur, "network"); portgroup =3D virXMLPropString(cur, "portgroup"); + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) + portid =3D virXMLPropString(cur, "portid"); } else if (!internal && def->type =3D=3D VIR_DOMAIN_NET_TYPE_INTERNAL && virXMLNodeNameEqual(cur, "source")) { @@ -11679,6 +11682,13 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlo= pt, "specified with = ")); goto error; } + if (portid && + virUUIDParse(portid, def->data.network.portid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse port id '%s'"), portid); + goto error; + } + VIR_STEAL_PTR(def->data.network.name, network); VIR_STEAL_PTR(def->data.network.portgroup, portgroup); VIR_STEAL_PTR(def->data.network.actual, actual); @@ -24967,6 +24977,11 @@ virDomainActualNetDefContentsFormat(virBufferPtr b= uf, def->data.network.name); virBufferEscapeString(buf, " portgroup=3D'%s'", def->data.network.portgroup); + if (virUUIDIsValid(def->data.network.portid)) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virUUIDFormat(def->data.network.portid, uuidstr); + virBufferAsprintf(buf, " portid=3D'%s'", uuidstr); + } } if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE || actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { @@ -25270,6 +25285,12 @@ virDomainNetDefFormat(virBufferPtr buf, def->data.network.name); virBufferEscapeString(buf, " portgroup=3D'%s'", def->data.network.portgroup); + if (virUUIDIsValid(def->data.network.portid) && + !(flags & (VIR_DOMAIN_DEF_FORMAT_INACTIVE))) { + char portidstr[VIR_UUID_STRING_BUFLEN]; + virUUIDFormat(def->data.network.portid, portidstr); + virBufferEscapeString(buf, " portid=3D'%s'", portidstr); + } sourceLines++; break; =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a584925fc7..41fadbeb49 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -969,6 +969,7 @@ struct _virDomainNetDef { struct { char *name; char *portgroup; + unsigned char portid[VIR_UUID_BUFLEN]; /* actual has info about the currently used physical * device (if the network is of type * bridge/private/vepa/passthrough). This is saved in the @@ -976,6 +977,9 @@ struct _virDomainNetDef { * since it needs to be re-allocated whenever the domain * is restarted. It is also never shown to the user, and * the user cannot specify it in XML documents. + * + * This information is populated from the virNetworkPort + * object associated with the portid UUID above. */ virDomainActualNetDefPtr actual; } network; diff --git a/tests/qemuxml2argvdata/net-virtio-network-portgroup.xml b/test= s/qemuxml2argvdata/net-virtio-network-portgroup.xml index 54a0eb7229..3d6cd02a73 100644 --- a/tests/qemuxml2argvdata/net-virtio-network-portgroup.xml +++ b/tests/qemuxml2argvdata/net-virtio-network-portgroup.xml @@ -24,7 +24,7 @@ - + @@ -35,7 +35,7 @@ - + @@ -43,7 +43,7 @@ - + --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848972; cv=none; d=zoho.com; s=zohoarc; b=HR7NeORRqOOxqku+YGejYRCVxWm0P2UatVCPxU+T0cmWJI/BK1K6EbJCfm0JSHVimUUdeEcxKx0x1AEPDOSyyA8aiaBjaK0r+eREsyqk9JaThwNmvt2twiVEXyQCI4FdtC+pCxYRL6NlUKf9ILIw9/YW9WRgb5vaV8vntwJBBmw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848972; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ItdT1mXIZrDIts5vpeMWuWBnjRF7i79N/3CM7/ZRDkk=; b=OaHYuIl610qhCsEku/lUjSvcSlHF4jKeXvqigruF7GkFJVGfLmRTd0QczCMF4cx15bJsGzznZuMm/pPRFUFrbmKFIQ7vqhLEato0G+ca9nDZAp0QXXMPCD16IptExcZtbGNr77uht7hMKViPun3ZVu1M5fbcOE9+6XEn5XAUR+Q= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848972071355.5460681874447; Tue, 14 May 2019 08:49:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 61DB43079B87; Tue, 14 May 2019 15:49:30 +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 35373BAAD; Tue, 14 May 2019 15:49: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 E48723FB13; Tue, 14 May 2019 15:49:29 +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 x4EFnJLW032123 for ; Tue, 14 May 2019 11:49:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2E4772B9F0; Tue, 14 May 2019 15:49:19 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C32063B86; Tue, 14 May 2019 15:49:12 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:35 +0100 Message-Id: <20190514154836.6427-24-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 23/24] conf: switch over to use network port APIs for virt drivers 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-Type: text/plain; charset="utf-8" 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 14 May 2019 15:49:31 +0000 (UTC) Change the domain conf so invoke the new network port public APIs instead of the network callbacks. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_conf.c | 211 ++++++++++++++++++++++++++---------- src/conf/domain_conf.h | 26 ----- src/libvirt_private.syms | 1 - src/network/bridge_driver.c | 203 ---------------------------------- 4 files changed, 151 insertions(+), 290 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f43426f9a2..2a9528c0ea 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30678,45 +30678,75 @@ virDomainNetDefActualToNetworkPort(virDomainDefPt= r dom, return NULL; } =20 -static virDomainNetAllocateActualDeviceImpl netAllocate; -static virDomainNetNotifyActualDeviceImpl netNotify; -static virDomainNetReleaseActualDeviceImpl netRelease; -static virDomainNetBandwidthUpdateImpl netBandwidthUpdate; =20 - -void -virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate, - virDomainNetNotifyActualDeviceImpl notify, - virDomainNetReleaseActualDeviceImpl release, - virDomainNetBandwidthUpdateImpl bandwidthUpdate) -{ - netAllocate =3D allocate; - netNotify =3D notify; - netRelease =3D release; - netBandwidthUpdate =3D bandwidthUpdate; -} - -int -virDomainNetAllocateActualDevice(virConnectPtr conn, - virDomainDefPtr dom, - virDomainNetDefPtr iface) +static int +virDomainNetCreatePort(virConnectPtr conn, + virDomainDefPtr dom, + virDomainNetDefPtr iface, + unsigned int flags) { virNetworkPtr net =3D NULL; int ret =3D -1; + virNetworkPortDefPtr portdef =3D NULL; + virNetworkPortPtr port =3D NULL; + char *portxml =3D NULL; + virErrorPtr saved; =20 - if (!netAllocate) { - virReportError(VIR_ERR_NO_SUPPORT, "%s", - _("Virtual networking driver is not available")); + if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) return -1; + + if (flags & VIR_NETWORK_PORT_CREATE_RECLAIM) { + if (!(portdef =3D virDomainNetDefActualToNetworkPort(dom, iface))) + goto cleanup; + } else { + if (!(portdef =3D virDomainNetDefToNetworkPort(dom, iface))) + goto cleanup; } =20 - if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) - return -1; + if (!(portxml =3D virNetworkPortDefFormat(portdef))) + goto cleanup; + + virNetworkPortDefFree(portdef); + portdef =3D NULL; + + if (!(port =3D virNetworkPortCreateXML(net, portxml, flags))) + goto cleanup; + + VIR_FREE(portxml); =20 - ret =3D netAllocate(net, dom, iface); + if (!(portxml =3D virNetworkPortGetXMLDesc(port, 0))) + goto deleteport; =20 + if (!(portdef =3D virNetworkPortDefParseString(portxml))) + goto deleteport; + + if (virDomainNetDefActualFromNetworkPort(iface, portdef) < 0) + goto deleteport; + + virNetworkPortGetUUID(port, iface->data.network.portid); + + ret =3D 0; + cleanup: + virNetworkPortDefFree(portdef); + VIR_FREE(portxml); + virObjectUnref(port); virObjectUnref(net); return ret; + + deleteport: + saved =3D virSaveLastError(); + virNetworkPortDelete(port, 0); + virSetError(saved); + virFreeError(saved); + goto cleanup; +} + +int +virDomainNetAllocateActualDevice(virConnectPtr conn, + virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + return virDomainNetCreatePort(conn, dom, iface, 0); } =20 void @@ -30724,16 +30754,11 @@ virDomainNetNotifyActualDevice(virConnectPtr conn, virDomainDefPtr dom, virDomainNetDefPtr iface) { - virNetworkPtr net =3D NULL; - - if (!netNotify) - return; - - if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) - return; - - if (netNotify(net, dom, iface) < 0) - goto cleanup; + if (!virUUIDIsValid(iface->data.network.portid)) { + if (virDomainNetCreatePort(conn, dom, iface, + VIR_NETWORK_PORT_CREATE_RECLAIM) < 0) + return; + } =20 if (virDomainNetGetActualType(iface) =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE= ) { /* @@ -30741,52 +30766,118 @@ virDomainNetNotifyActualDevice(virConnectPtr con= n, * so there is no point in trying to learn the actualMTU * (final arg to virNetDevTapReattachBridge()) */ - if (virNetDevTapReattachBridge(iface->ifname, - iface->data.network.actual->data.br= idge.brname, - &iface->mac, dom->uuid, - virDomainNetGetActualVirtPortProfil= e(iface), - virDomainNetGetActualVlan(iface), - iface->mtu, NULL) < 0) - goto cleanup; + ignore_value(virNetDevTapReattachBridge(iface->ifname, + iface->data.network.actual= ->data.bridge.brname, + &iface->mac, dom->uuid, + virDomainNetGetActualVirtP= ortProfile(iface), + virDomainNetGetActualVlan(= iface), + iface->mtu, NULL)); } - - cleanup: - virObjectUnref(net); } =20 =20 int virDomainNetReleaseActualDevice(virConnectPtr conn, - virDomainDefPtr dom, + virDomainDefPtr dom ATTRIBUTE_UNUSED, virDomainNetDefPtr iface) { virNetworkPtr net =3D NULL; - int ret; - - if (!netRelease) - return 0; + virNetworkPortPtr port =3D NULL; + int ret =3D -1; =20 if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) - return -1; + goto cleanup; =20 - ret =3D netRelease(net, dom, iface); + if (!(port =3D virNetworkPortLookupByUUID(net, iface->data.network.por= tid))) + goto cleanup; =20 + if (virNetworkPortDelete(port, 0) < 0) + goto cleanup; + + cleanup: + virObjectUnref(port); virObjectUnref(net); return ret; } =20 =20 +static int +virDomainNetBandwidthToTypedParams(virNetDevBandwidthPtr bandwidth, + virTypedParameterPtr *params, + int *nparams) +{ + int maxparams =3D 0; + + if ((bandwidth->in !=3D NULL) && + (virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE, + bandwidth->in->average) < 0 || + virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK, + bandwidth->in->peak) < 0 || + virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR, + bandwidth->in->floor) < 0 || + virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_IN_BURST, + bandwidth->in->burst) < 0)) + goto error; + + if ((bandwidth->out !=3D NULL) && + (virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE, + bandwidth->out->average) < 0 || + virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK, + bandwidth->out->peak) < 0 || + virTypedParamsAddUInt(params, nparams, &maxparams, + VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST, + bandwidth->out->burst) < 0)) + goto error; + + return 0; + + error: + virTypedParamsFree(*params, *nparams); + *params =3D NULL; + *nparams =3D 0; + return -1; +} + + int virDomainNetBandwidthUpdate(virDomainNetDefPtr iface, virNetDevBandwidthPtr newBandwidth) { - if (!netBandwidthUpdate) { - virReportError(VIR_ERR_NO_SUPPORT, "%s", - _("Virtual networking driver is not available")); - return -1; - } + virNetworkPtr net =3D NULL; + virNetworkPortPtr port =3D NULL; + virTypedParameterPtr params =3D NULL; + int nparams =3D 0; + virConnectPtr conn =3D NULL; + int ret =3D -1; + + if (!(conn =3D virGetConnectNetwork())) + goto cleanup; + + if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) + goto cleanup; + + if (!(port =3D virNetworkPortLookupByUUID(net, iface->data.network.por= tid))) + goto cleanup; =20 - return netBandwidthUpdate(iface, newBandwidth); + if (virDomainNetBandwidthToTypedParams(newBandwidth, ¶ms, &nparams= ) < 0) + goto cleanup; + + if (virNetworkPortSetParameters(port, params, nparams, 0) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virObjectUnref(conn); + virTypedParamsFree(params, nparams); + virObjectUnref(port); + virObjectUnref(net); + return ret; } =20 /* virDomainNetResolveActualType: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 41fadbeb49..cdc341952c 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3573,32 +3573,6 @@ virNetworkPortDefPtr virDomainNetDefActualToNetworkPort(virDomainDefPtr dom, virDomainNetDefPtr iface); =20 -typedef int -(*virDomainNetAllocateActualDeviceImpl)(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface); - -typedef int -(*virDomainNetNotifyActualDeviceImpl)(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface); - -typedef int -(*virDomainNetReleaseActualDeviceImpl)(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface); - -typedef int -(*virDomainNetBandwidthUpdateImpl)(virDomainNetDefPtr iface, - virNetDevBandwidthPtr newBandwidth); - - -void -virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate, - virDomainNetNotifyActualDeviceImpl notify, - virDomainNetReleaseActualDeviceImpl release, - virDomainNetBandwidthUpdateImpl bandwidthUpdate); - int virDomainNetAllocateActualDevice(virConnectPtr conn, virDomainDefPtr dom, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0c357f72a3..0172b0d3ea 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -487,7 +487,6 @@ virDomainNetReleaseActualDevice; virDomainNetRemove; virDomainNetRemoveHostdev; virDomainNetResolveActualType; -virDomainNetSetDeviceImpl; virDomainNetSetModelString; virDomainNetTypeFromString; virDomainNetTypeSharesHostView; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 0b9d440d42..6f5d2c6cf6 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4710,52 +4710,6 @@ networkAllocatePort(virNetworkObjPtr obj, } =20 =20 -static int -networkAllocateActualDevice(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface) -{ - virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkPortDefPtr port =3D NULL; - virNetworkObjPtr obj; - int ret =3D -1; - - obj =3D virNetworkObjFindByName(driver->networks, net->name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - net->name); - return -1; - } - - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - goto cleanup; - } - - if (!(port =3D virDomainNetDefToNetworkPort(dom, iface))) - goto cleanup; - - if (networkAllocatePort(obj, port) < 0) - goto cleanup; - - VIR_DEBUG("Populating net def"); - if (virDomainNetDefActualFromNetworkPort(iface, port) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - if (ret < 0) { - virDomainActualNetDefFree(iface->data.network.actual); - iface->data.network.actual =3D NULL; - } - virNetworkPortDefFree(port); - virNetworkObjEndAPI(&obj); - return ret; -} - - /* networkNotifyPort: * @obj: the network to notify * @port: the port definition to notify @@ -4912,54 +4866,6 @@ networkNotifyPort(virNetworkObjPtr obj, } =20 =20 -static int -networkNotifyActualDevice(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface) -{ - virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj; - virNetworkDefPtr netdef; - virNetworkPortDefPtr port =3D NULL; - int ret =3D -1; - - obj =3D virNetworkObjFindByName(driver->networks, net->name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - net->name); - goto cleanup; - } - - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - goto cleanup; - } - - netdef =3D virNetworkObjGetDef(obj); - - if (!virNetworkObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("network '%s' is not active"), - netdef->name); - goto cleanup; - } - - if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) - goto cleanup; - - if (networkNotifyPort(obj, port) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - virNetworkObjEndAPI(&obj); - virNetworkPortDefFree(port); - return ret; -} - - /* networkReleasePort: * @obj: the network to release from * @port: the port definition to release @@ -5076,65 +4982,6 @@ networkReleasePort(virNetworkObjPtr obj, } =20 =20 -/* networkReleaseActualDevice: - * @dom: domain definition that @iface belongs to - * @iface: a domain's NetDef (interface definition) - * - * Given a domain element that previously had its - * element filled in (and possibly a physical device allocated to it), - * free up the physical device for use by someone else, and free the - * virDomainActualNetDef. - * - * Returns 0 on success, -1 on failure. - */ -static int -networkReleaseActualDevice(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface) -{ - virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj; - virNetworkPortDefPtr port =3D NULL; - int ret =3D -1; - - obj =3D virNetworkObjFindByName(driver->networks, net->name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - net->name); - goto cleanup; - } - - - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - goto cleanup; - } - - if (iface->data.network.actual =3D=3D NULL) { - ret =3D 0; - goto cleanup; - } - - if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) - goto cleanup; - - if (networkReleasePort(obj, port) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - virNetworkObjEndAPI(&obj); - if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virDomainActualNetDefFree(iface->data.network.actual); - iface->data.network.actual =3D NULL; - } - virNetworkPortDefFree(port); - return ret; -} - - /** * networkCheckBandwidth: * @net: network QoS @@ -5507,49 +5354,6 @@ networkUpdatePortBandwidth(virNetworkObjPtr obj, } =20 =20 -static int -networkBandwidthUpdate(virDomainNetDefPtr iface, - virNetDevBandwidthPtr newBandwidth) -{ - virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj =3D NULL; - virNetDevBandwidthPtr oldBandwidth =3D virDomainNetGetActualBandwidth(= iface); - int ret =3D -1; - - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - return -1; - } - - if (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_NETWORK = && - (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_BRIDGE = || - iface->data.network.actual->data.bridge.brname !=3D NULL)) { - /* This is not an interface that's plugged into a bridge. - * We don't care. Thus from our POV bandwidth change is allowed. */ - return 0; - } - - obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - iface->data.network.name); - return ret; - } - - ret =3D networkUpdatePortBandwidth(obj, - &iface->mac, - iface->data.network.actual ? - &iface->data.network.actual->class_id= : NULL, - newBandwidth, - oldBandwidth); - - virNetworkObjEndAPI(&obj); - return ret; -} - - static virNetworkPortPtr networkPortLookupByUUID(virNetworkPtr net, const unsigned char *uuid) @@ -6006,12 +5810,5 @@ networkRegister(void) return -1; if (virRegisterStateDriver(&networkStateDriver) < 0) return -1; - - virDomainNetSetDeviceImpl( - networkAllocateActualDevice, - networkNotifyActualDevice, - networkReleaseActualDevice, - networkBandwidthUpdate); - return 0; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 23:59:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1557848975; cv=none; d=zoho.com; s=zohoarc; b=oOhf451yNJyZ4LrHULCFqGQtzofSBz5xrlbwG1vIl490gSSnWAwxw2UIMhpB3fTyNlsE/inLHNll2b9dd5AzgVeWNZ7mKx0orBNOrJz8Z/SrS0M1vKgRBaD/7mHOfaKLzCGMA3oE9EXeqH4VyTdV1OChYuVo60BuTVqMJDTkBcA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848975; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=OrI3fY2rqLSt2Q6kBw9DQ+J8Qw17k6pkctuakVYoIp8=; b=Pv3ot2SAoY9n7kAIQX+SZTALPLnNgKDkChq8U6Pq2QawZUp/wTSqr0nQjvxfQHVwy8CGfY9K8AtZy3rfur53hBVzNeDlgZ9ijKHwcvrWnHb2aoKy2ab1l3qXUsn8LuEZhduI3AEBpjIWjXGgyg81z2oDOGKkq90QRcnzHgRhqgk= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155784897579512.485899972101151; Tue, 14 May 2019 08:49:35 -0700 (PDT) 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 2ABEF307D970; Tue, 14 May 2019 15:49:34 +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 011BB5C664; Tue, 14 May 2019 15:49:34 +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 AEB9D41F3C; Tue, 14 May 2019 15:49:33 +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 x4EFnP1F032200 for ; Tue, 14 May 2019 11:49:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id C32752B9F7; Tue, 14 May 2019 15:49:25 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36E192B9F8; Tue, 14 May 2019 15:49:19 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:36 +0100 Message-Id: <20190514154836.6427-25-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 24/24] rpm: remove dependancy from qemu to network/storage drivers 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-Type: text/plain; charset="utf-8" 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.48]); Tue, 14 May 2019 15:49:34 +0000 (UTC) The libvirt-daemon-driver-qemu RPM has historically had a hard dependency on the libvirt-daemon-driver-network and libvirt-daemon-driver-storage-core packages. This was because the QEMU driver would directly call into APIs that were part of these drivers. The dependency to the storage driver was eliminated in commit 064fec69be4a4673e0df17b007bf781026c3b4b2 Author: Daniel P. Berrang=C3=A9 Date: Thu Jan 25 09:35:46 2018 +0000 storage: move storage file backend framework into util directory The dependency to the network driver was eliminated in commit 5b13570ab8b43ec3c590399ec5a7644d91082149 Author: Daniel P. Berrang=C3=A9 Date: Thu Jan 25 09:35:47 2018 +0000 conf: introduce callback registration for domain net device allocation Signed-off-by: Daniel P. Berrang=C3=A9 --- libvirt.spec.in | 3 --- 1 file changed, 3 deletions(-) diff --git a/libvirt.spec.in b/libvirt.spec.in index 5c27a44fc5..b159c50d8f 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -720,9 +720,6 @@ parted and more. Summary: QEMU driver plugin for the libvirtd daemon Requires: libvirt-daemon =3D %{version}-%{release} Requires: libvirt-libs =3D %{version}-%{release} -# There really is a hard cross-driver dependency here -Requires: libvirt-daemon-driver-network =3D %{version}-%{release} -Requires: libvirt-daemon-driver-storage-core =3D %{version}-%{release} Requires: /usr/bin/qemu-img # For image compression Requires: gzip --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list