From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999631712212.82665193777405; Tue, 19 Mar 2019 05:47: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 C2FAA58E38; Tue, 19 Mar 2019 12:47:09 +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 96CA11001E61; Tue, 19 Mar 2019 12:47: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 4CD493FB14; Tue, 19 Mar 2019 12:47:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCl7M7028714 for ; Tue, 19 Mar 2019 08:47:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id AE26C5D717; Tue, 19 Mar 2019 12:47:07 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AA885D707; Tue, 19 Mar 2019 12:47:06 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:25 +0000 Message-Id: <20190319124700.16722-2-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 01/36] network: restrict usage of port management 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.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.39]); Tue, 19 Mar 2019 12:47:10 +0000 (UTC) The port allocation APIs are currently called unconditionally for all types of NIC, but (mostly) only do anything for NICs with type=3Dnetwork. The exception is the port allocate API which does some validation even for NICs with type!=3Dnetwork. Relying on this validation is flawed, however, since the network driver may not even be installed. IOW virt drivers must not delegate validation to the network driver for NICs with type !=3D network. This change allows us to report errors when the virtual network driver is not registered. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_conf.c | 26 ++++++++------ src/libxl/libxl_domain.c | 6 ++-- src/libxl/libxl_driver.c | 9 +++-- src/lxc/lxc_driver.c | 6 ++-- src/lxc/lxc_process.c | 9 +++-- src/network/bridge_driver.c | 72 +++++++++++++++++++------------------ src/qemu/qemu_driver.c | 6 ++-- src/qemu/qemu_hotplug.c | 17 +++++---- src/qemu/qemu_process.c | 9 +++-- 9 files changed, 94 insertions(+), 66 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 504c24b545..b7bb94b90b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30187,13 +30187,11 @@ int virDomainNetAllocateActualDevice(virDomainDefPtr dom, virDomainNetDefPtr iface) { - /* Just silently ignore if network driver isn't present. If something - * has tried to use a NIC with type=3Dnetwork, other code will already - * cause an error. This ensures type=3Dbridge doesn't break when - * network driver is compiled out. - */ - if (!netAllocate) - return 0; + if (!netAllocate) { + virReportError(VIR_ERR_NO_SUPPORT, "%s", + _("Virtual networking driver is not available")); + return -1; + } =20 return netAllocate(dom, iface); } @@ -30223,8 +30221,11 @@ bool virDomainNetBandwidthChangeAllowed(virDomainNetDefPtr iface, virNetDevBandwidthPtr newBandwidth) { - if (!netBandwidthChangeAllowed) - return 0; + if (!netBandwidthChangeAllowed) { + virReportError(VIR_ERR_NO_SUPPORT, "%s", + _("Virtual networking driver is not available")); + return -1; + } =20 return netBandwidthChangeAllowed(iface, newBandwidth); } @@ -30233,8 +30234,11 @@ int virDomainNetBandwidthUpdate(virDomainNetDefPtr iface, virNetDevBandwidthPtr newBandwidth) { - if (!netBandwidthUpdate) - return 0; + if (!netBandwidthUpdate) { + virReportError(VIR_ERR_NO_SUPPORT, "%s", + _("Virtual networking driver is not available")); + return -1; + } =20 return netBandwidthUpdate(iface, newBandwidth); } diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 287406d323..e2f1b54210 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -903,7 +903,8 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, =20 /* cleanup actual device */ virDomainNetRemoveHostdev(vm->def, net); - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); } } =20 @@ -1060,7 +1061,8 @@ libxlNetworkPrepareDevices(virDomainDefPtr def) * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (virDomainNetAllocateActualDevice(def, net) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(def, net) < 0) return -1; =20 actualType =3D virDomainNetGetActualType(net); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index a9edc8211d..d5cd3fc834 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3390,7 +3390,8 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driv= er, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (virDomainNetAllocateActualDevice(vm->def, net) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(vm->def, net) < 0) goto cleanup; =20 actualType =3D virDomainNetGetActualType(net); @@ -3440,7 +3441,8 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driv= er, vm->def->nets[vm->def->nnets++] =3D net; } else { virDomainNetRemoveHostdev(vm->def, net); - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); } virObjectUnref(cfg); return ret; @@ -3863,7 +3865,8 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driv= er, cleanup: libxl_device_nic_dispose(&nic); if (!ret) { - virDomainNetReleaseActualDevice(vm->def, detach); + if (detach->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, detach); virDomainNetRemove(vm->def, detachidx); } virObjectUnref(cfg); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index e981f8e901..027c4fd990 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3834,7 +3834,8 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (virDomainNetAllocateActualDevice(vm->def, net) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(vm->def, net) < 0) return -1; =20 actualType =3D virDomainNetGetActualType(net); @@ -4388,7 +4389,8 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm, ret =3D 0; cleanup: if (!ret) { - virDomainNetReleaseActualDevice(vm->def, detach); + if (detach->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, detach); virDomainNetRemove(vm->def, detachidx); virDomainNetDefFree(detach); } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index e0729a24bf..7849aaf5b9 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -224,7 +224,8 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, iface->ifname)); ignore_value(virNetDevVethDelete(iface->ifname)); } - virDomainNetReleaseActualDevice(vm->def, iface); + if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, iface); } =20 virDomainConfVMNWFilterTeardown(vm); @@ -558,7 +559,8 @@ static int virLXCProcessSetupInterfaces(virConnectPtr c= onn, if (virLXCProcessValidateInterface(net) < 0) goto cleanup; =20 - if (virDomainNetAllocateActualDevice(def, net) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(def, net) < 0) goto cleanup; =20 type =3D virDomainNetGetActualType(net); @@ -637,7 +639,8 @@ static int virLXCProcessSetupInterfaces(virConnectPtr c= onn, ignore_value(virNetDevOpenvswitchRemovePort( virDomainNetGetActualBridgeName(iface), iface->ifname)); - virDomainNetReleaseActualDevice(def, iface); + if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(def, iface); } } return ret; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 4d4ab0f375..cf37a16c64 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4371,8 +4371,11 @@ networkAllocateActualDevice(virDomainDefPtr dom, size_t i; int ret =3D -1; =20 - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) - goto validate; + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected a interface for a virtual network")); + goto error; + } =20 virDomainActualNetDefFree(iface->data.network.actual); iface->data.network.actual =3D NULL; @@ -4691,7 +4694,6 @@ networkAllocateActualDevice(virDomainDefPtr dom, if (virNetDevVPortProfileCheckComplete(virtport, true) < 0) goto error; =20 - validate: /* 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. @@ -4710,19 +4712,11 @@ networkAllocateActualDevice(virDomainDefPtr dom, (actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && virtport && virtport->virtPortType =3D=3D VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH))) { - if (netdef) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("an interface connecting to network '%s' " - "is requesting a vlan tag, but that is no= t " - "supported for this type of network"), - netdef->name); - } else { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("an interface of type '%s' " - "is requesting a vlan tag, but that is no= t " - "supported for this type of connection"), - virDomainNetTypeToString(iface->type)); - } + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("an interface connecting to network '%s' " + "is requesting a vlan tag, but that is not " + "supported for this type of network"), + netdef->name); goto error; } } @@ -4738,22 +4732,20 @@ networkAllocateActualDevice(virDomainDefPtr dom, } } =20 - if (netdef) { - netdef->connections++; + netdef->connections++; + 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, + VIR_HOOK_SUBOP_BEGIN) < 0) { + /* adjust for failure */ + netdef->connections--; 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, - VIR_HOOK_SUBOP_BEGIN) < 0) { - /* adjust for failure */ - netdef->connections--; - if (dev) - dev->connections--; - goto error; - } - networkLogAllocation(netdef, actualType, dev, iface, true); + dev->connections--; + goto error; } + networkLogAllocation(netdef, actualType, dev, iface, true); =20 ret =3D 0; =20 @@ -4794,8 +4786,11 @@ networkNotifyActualDevice(virDomainDefPtr dom, size_t i; char *master =3D NULL; =20 - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) - return; + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected a interface for a virtual network")); + goto error; + } =20 obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); if (!obj) { @@ -5027,8 +5022,11 @@ networkReleaseActualDevice(virDomainDefPtr dom, size_t i; int ret =3D -1; =20 - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) - return 0; + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected a interface for a virtual network")); + goto error; + } =20 obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); if (!obj) { @@ -5519,6 +5517,12 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, int plug_ret; int ret =3D -1; =20 + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected a interface for a virtual network")); + return -1; + } + if (!networkBandwidthGenericChecks(iface, newBandwidth)) return 0; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a16eab5467..d2ea301981 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11728,12 +11728,14 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, sizeof(*newBandwidth->out)); } =20 - if (!virDomainNetBandwidthChangeAllowed(net, newBandwidth)) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + !virDomainNetBandwidthChangeAllowed(net, newBandwidth)) goto endjob; =20 if (virNetDevBandwidthSet(net->ifname, newBandwidth, false, !virDomainNetTypeSharesHostView(net)) < = 0 || - virDomainNetBandwidthUpdate(net, newBandwidth) < 0) { + (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetBandwidthUpdate(net, newBandwidth) < 0)) { ignore_value(virNetDevBandwidthSet(net->ifname, net->bandwidth, false, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 41d60277d1..97c9de04f0 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1383,7 +1383,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (virDomainNetAllocateActualDevice(vm->def, net) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(vm->def, net) < 0) goto cleanup; =20 actualType =3D virDomainNetGetActualType(net); @@ -1687,7 +1688,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, =20 virDomainNetRemoveHostdev(vm->def, net); =20 - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); } =20 VIR_FREE(nicstr); @@ -4105,7 +4107,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, =20 /* this function doesn't work with HOSTDEV networks yet, thus * no need to change the pointer in the hostdev structure */ - virDomainNetReleaseActualDevice(vm->def, olddev); + if (olddev->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, olddev); virDomainNetDefFree(olddev); /* move newdev into the nets list, and NULL it out from the * virDomainDeviceDef that we were given so that the caller @@ -4136,7 +4139,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, * that the changes were minor enough that we didn't need to * replace the entire device object. */ - if (newdev) + if (newdev && newdev->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) virDomainNetReleaseActualDevice(vm->def, newdev); =20 return ret; @@ -4694,7 +4697,8 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virDomainHostdevDefFree(hostdev); =20 if (net) { - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); virDomainNetDefFree(net); } =20 @@ -4790,7 +4794,8 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver, =20 qemuDomainNetDeviceVportRemove(net); =20 - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); virDomainNetDefFree(net); ret =3D 0; =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d878079eab..6ec69d3c96 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3277,7 +3277,8 @@ qemuProcessNotifyNets(virDomainDefPtr def) if (virDomainNetGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_DIRE= CT) ignore_value(virNetDevMacVLanReserveName(net->ifname, false)); =20 - virDomainNetNotifyActualDevice(def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetNotifyActualDevice(def, net); } } =20 @@ -5463,7 +5464,8 @@ qemuProcessNetworkPrepareDevices(virDomainDefPtr def) * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (virDomainNetAllocateActualDevice(def, net) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(def, net) < 0) goto cleanup; =20 actualType =3D virDomainNetGetActualType(net); @@ -7309,7 +7311,8 @@ void qemuProcessStop(virQEMUDriverPtr driver, =20 /* kick the device out of the hostdev list too */ virDomainNetRemoveHostdev(def, net); - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); } =20 retry: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999635379209.13918710451742; Tue, 19 Mar 2019 05:47:15 -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 3E4B630FE5C9; Tue, 19 Mar 2019 12:47:13 +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 12BFA282F5; Tue, 19 Mar 2019 12:47: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 C350A181A137; Tue, 19 Mar 2019 12:47:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCl9MX028727 for ; Tue, 19 Mar 2019 08:47:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6D44D5D71D; Tue, 19 Mar 2019 12:47:09 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2100F5D707; Tue, 19 Mar 2019 12:47:07 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:26 +0000 Message-Id: <20190319124700.16722-3-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 02/36] network: pass a virNetworkPtr to port management 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.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.47]); Tue, 19 Mar 2019 12:47:13 +0000 (UTC) The APIs for allocating/notifying/removing network ports just take an internal domain interface struct right now. As a step towards turning these into public facing APIs, add a virNetworkPtr argument to all of them. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Cole Robinson --- src/conf/domain_conf.c | 40 ++++++++++++++++++++---- src/conf/domain_conf.h | 18 +++++++---- src/libxl/libxl_domain.c | 30 +++++++++++++----- src/libxl/libxl_driver.c | 26 +++++++++++----- src/lxc/lxc_driver.c | 24 +++++++++++--- src/lxc/lxc_process.c | 24 +++++++++----- src/network/bridge_driver.c | 54 ++++++++++++++++++-------------- src/qemu/qemu_hotplug.c | 62 +++++++++++++++++++++++++++---------- src/qemu/qemu_process.c | 30 +++++++++++++----- 9 files changed, 223 insertions(+), 85 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b7bb94b90b..22c6fe1e38 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30184,37 +30184,65 @@ virDomainNetSetDeviceImpl(virDomainNetAllocateAct= ualDeviceImpl allocate, } =20 int -virDomainNetAllocateActualDevice(virDomainDefPtr dom, +virDomainNetAllocateActualDevice(virConnectPtr conn, + virDomainDefPtr dom, virDomainNetDefPtr iface) { + virNetworkPtr net =3D NULL; + int ret =3D -1; + if (!netAllocate) { virReportError(VIR_ERR_NO_SUPPORT, "%s", _("Virtual networking driver is not available")); return -1; } =20 - return netAllocate(dom, iface); + if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) + return -1; + + ret =3D netAllocate(net, dom, iface); + + virObjectUnref(net); + return ret; } =20 void -virDomainNetNotifyActualDevice(virDomainDefPtr dom, +virDomainNetNotifyActualDevice(virConnectPtr conn, + virDomainDefPtr dom, virDomainNetDefPtr iface) { + virNetworkPtr net =3D NULL; + if (!netNotify) return; =20 - netNotify(dom, iface); + if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) + return; + + netNotify(net, dom, iface); + + virObjectUnref(net); } =20 =20 int -virDomainNetReleaseActualDevice(virDomainDefPtr dom, +virDomainNetReleaseActualDevice(virConnectPtr conn, + virDomainDefPtr dom, virDomainNetDefPtr iface) { + virNetworkPtr net =3D NULL; + int ret; + if (!netRelease) return 0; =20 - return netRelease(dom, iface); + if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) + return -1; + + ret =3D netRelease(net, dom, iface); + + virObjectUnref(net); + return ret; } =20 bool diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 538fb50b9e..e77fdcabf3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3505,15 +3505,18 @@ virDomainDefLifecycleActionAllowed(virDomainLifecyc= le type, virDomainLifecycleAction action); =20 typedef int -(*virDomainNetAllocateActualDeviceImpl)(virDomainDefPtr dom, +(*virDomainNetAllocateActualDeviceImpl)(virNetworkPtr net, + virDomainDefPtr dom, virDomainNetDefPtr iface); =20 typedef void -(*virDomainNetNotifyActualDeviceImpl)(virDomainDefPtr dom, +(*virDomainNetNotifyActualDeviceImpl)(virNetworkPtr net, + virDomainDefPtr dom, virDomainNetDefPtr iface); =20 typedef int -(*virDomainNetReleaseActualDeviceImpl)(virDomainDefPtr dom, +(*virDomainNetReleaseActualDeviceImpl)(virNetworkPtr net, + virDomainDefPtr dom, virDomainNetDefPtr iface); =20 typedef bool @@ -3533,17 +3536,20 @@ virDomainNetSetDeviceImpl(virDomainNetAllocateActua= lDeviceImpl allocate, virDomainNetBandwidthUpdateImpl bandwidthUpdate); =20 int -virDomainNetAllocateActualDevice(virDomainDefPtr dom, +virDomainNetAllocateActualDevice(virConnectPtr conn, + virDomainDefPtr dom, virDomainNetDefPtr iface) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 void -virDomainNetNotifyActualDevice(virDomainDefPtr dom, +virDomainNetNotifyActualDevice(virConnectPtr conn, + virDomainDefPtr dom, virDomainNetDefPtr iface) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 int -virDomainNetReleaseActualDevice(virDomainDefPtr dom, +virDomainNetReleaseActualDevice(virConnectPtr conn, + virDomainDefPtr dom, virDomainNetDefPtr iface) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index e2f1b54210..91b34feca0 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -35,6 +35,7 @@ #include "virtime.h" #include "locking/domain_lock.h" #include "xen_common.h" +#include "driver.h" =20 #define VIR_FROM_THIS VIR_FROM_LIBXL =20 @@ -844,6 +845,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, char *file; virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; unsigned int hostdev_flags =3D VIR_HOSTDEV_SP_PCI; + virConnectPtr conn =3D NULL; =20 #ifdef LIBXL_HAVE_PVUSB hostdev_flags |=3D VIR_HOSTDEV_SP_USB; @@ -903,8 +905,12 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, =20 /* cleanup actual device */ virDomainNetRemoveHostdev(vm->def, net); - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (conn || (conn =3D virGetConnectNetwork())) + virDomainNetReleaseActualDevice(conn, vm->def, net); + else + VIR_WARN("Unable to release network device '%s'", NULL= STR(net->ifname)); + } } } =20 @@ -927,6 +933,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, =20 virDomainObjRemoveTransientDef(vm); virObjectUnref(cfg); + virObjectUnref(conn); } =20 /* @@ -1052,6 +1059,8 @@ static int libxlNetworkPrepareDevices(virDomainDefPtr def) { size_t i; + virConnectPtr conn =3D NULL; + int ret =3D -1; =20 for (i =3D 0; i < def->nnets; i++) { virDomainNetDefPtr net =3D def->nets[i]; @@ -1061,9 +1070,12 @@ libxlNetworkPrepareDevices(virDomainDefPtr def) * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - virDomainNetAllocateActualDevice(def, net) < 0) - return -1; + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (!conn && !(conn =3D virGetConnectNetwork())) + goto cleanup; + if (virDomainNetAllocateActualDevice(conn, def, net) < 0) + goto cleanup; + } =20 actualType =3D virDomainNetGetActualType(net); if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV && @@ -1083,10 +1095,14 @@ libxlNetworkPrepareDevices(virDomainDefPtr def) pcisrc->backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN; =20 if (virDomainHostdevInsert(def, hostdev) < 0) - return -1; + goto cleanup; } } - return 0; + + ret =3D 0; + cleanup: + virObjectUnref(conn); + return ret; } =20 static void diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index d5cd3fc834..506dcdfbeb 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3379,6 +3379,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driv= er, libxl_device_nic nic; int ret =3D -1; char mac[VIR_MAC_STRING_BUFLEN]; + virConnectPtr conn =3D NULL; =20 libxl_device_nic_init(&nic); =20 @@ -3390,9 +3391,12 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr dri= ver, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - virDomainNetAllocateActualDevice(vm->def, net) < 0) - goto cleanup; + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (!(conn =3D virGetConnectNetwork())) + goto cleanup; + if (virDomainNetAllocateActualDevice(conn, vm->def, net) < 0) + goto cleanup; + } =20 actualType =3D virDomainNetGetActualType(net); =20 @@ -3441,9 +3445,10 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr dri= ver, vm->def->nets[vm->def->nnets++] =3D net; } else { virDomainNetRemoveHostdev(vm->def, net); - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && conn) + virDomainNetReleaseActualDevice(conn, vm->def, net); } + virObjectUnref(conn); virObjectUnref(cfg); return ret; } @@ -3865,8 +3870,15 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr dri= ver, cleanup: libxl_device_nic_dispose(&nic); if (!ret) { - if (detach->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(vm->def, detach); + if (detach->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virConnectPtr conn =3D virGetConnectNetwork(); + if (conn) { + virDomainNetReleaseActualDevice(conn, vm->def, detach); + virObjectUnref(conn); + } else { + VIR_WARN("Unable to release network device '%s'", NULLSTR(= detach->ifname)); + } + } virDomainNetRemove(vm->def, detachidx); } virObjectUnref(cfg); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 027c4fd990..a184e67e15 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3834,9 +3834,16 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - virDomainNetAllocateActualDevice(vm->def, net) < 0) - return -1; + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virConnectPtr netconn =3D virGetConnectNetwork(); + if (!netconn) + return -1; + if (virDomainNetAllocateActualDevice(netconn, vm->def, net) < 0) { + virObjectUnref(netconn); + return -1; + } + virObjectUnref(netconn); + } =20 actualType =3D virDomainNetGetActualType(net); =20 @@ -4389,8 +4396,15 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm, ret =3D 0; cleanup: if (!ret) { - if (detach->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(vm->def, detach); + if (detach->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virConnectPtr conn =3D virGetConnectNetwork(); + if (conn) { + virDomainNetReleaseActualDevice(conn, vm->def, detach); + virObjectUnref(conn); + } else { + VIR_WARN("Unable to release network device '%s'", NULLSTR(= detach->ifname)); + } + } virDomainNetRemove(vm->def, detachidx); virDomainNetDefFree(detach); } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 7849aaf5b9..d9362c5ff6 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -165,6 +165,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, virLXCDomainObjPrivatePtr priv =3D vm->privateData; virNetDevVPortProfilePtr vport =3D NULL; virLXCDriverConfigPtr cfg =3D virLXCDriverGetConfig(driver); + virConnectPtr conn =3D NULL; =20 VIR_DEBUG("Cleanup VM name=3D%s pid=3D%d reason=3D%d", vm->def->name, (int)vm->pid, (int)reason); @@ -224,8 +225,12 @@ static void virLXCProcessCleanup(virLXCDriverPtr drive= r, iface->ifname)); ignore_value(virNetDevVethDelete(iface->ifname)); } - if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(vm->def, iface); + if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (conn || (conn =3D virGetConnectNetwork())) + virDomainNetReleaseActualDevice(conn, vm->def, iface); + else + VIR_WARN("Unable to release network device '%s'", NULLSTR(= iface->ifname)); + } } =20 virDomainConfVMNWFilterTeardown(vm); @@ -543,6 +548,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr c= onn, size_t niface =3D 0; virDomainNetDefPtr net; virDomainNetType type; + virConnectPtr netconn =3D NULL; =20 if (VIR_ALLOC_N(*veths, def->nnets + 1) < 0) return -1; @@ -559,9 +565,12 @@ static int virLXCProcessSetupInterfaces(virConnectPtr = conn, if (virLXCProcessValidateInterface(net) < 0) goto cleanup; =20 - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - virDomainNetAllocateActualDevice(def, net) < 0) - goto cleanup; + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (!netconn && !(netconn =3D virGetConnectNetwork())) + goto cleanup; + if (virDomainNetAllocateActualDevice(netconn, def, net) < 0) + goto cleanup; + } =20 type =3D virDomainNetGetActualType(net); switch (type) { @@ -639,10 +648,11 @@ static int virLXCProcessSetupInterfaces(virConnectPtr= conn, ignore_value(virNetDevOpenvswitchRemovePort( virDomainNetGetActualBridgeName(iface), iface->ifname)); - if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(def, iface); + if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && netconn) + virDomainNetReleaseActualDevice(netconn, def, iface); } } + virObjectUnref(netconn); return ret; } =20 diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index cf37a16c64..abeed0a806 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4356,7 +4356,8 @@ networkLogAllocation(virNetworkDefPtr netdef, * Returns 0 on success, -1 on failure. */ static int -networkAllocateActualDevice(virDomainDefPtr dom, +networkAllocateActualDevice(virNetworkPtr net, + virDomainDefPtr dom, virDomainNetDefPtr iface) { virNetworkDriverStatePtr driver =3D networkGetDriver(); @@ -4371,6 +4372,14 @@ networkAllocateActualDevice(virDomainDefPtr dom, 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 a interface for a virtual network")); @@ -4380,13 +4389,6 @@ networkAllocateActualDevice(virDomainDefPtr dom, virDomainActualNetDefFree(iface->data.network.actual); iface->data.network.actual =3D NULL; =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); - goto error; - } netdef =3D virNetworkObjGetDef(obj); =20 if (!virNetworkObjIsActive(obj)) { @@ -4775,7 +4777,8 @@ networkAllocateActualDevice(virDomainDefPtr dom, * No return value (but does log any failures) */ static void -networkNotifyActualDevice(virDomainDefPtr dom, +networkNotifyActualDevice(virNetworkPtr net, + virDomainDefPtr dom, virDomainNetDefPtr iface) { virNetworkDriverStatePtr driver =3D networkGetDriver(); @@ -4786,19 +4789,20 @@ networkNotifyActualDevice(virDomainDefPtr dom, size_t i; char *master =3D NULL; =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 a interface for a virtual network")); goto error; } =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); - goto error; - } netdef =3D virNetworkObjGetDef(obj); =20 if (!virNetworkObjIsActive(obj)) { @@ -5011,7 +5015,8 @@ networkNotifyActualDevice(virDomainDefPtr dom, * Returns 0 on success, -1 on failure. */ static int -networkReleaseActualDevice(virDomainDefPtr dom, +networkReleaseActualDevice(virNetworkPtr net, + virDomainDefPtr dom, virDomainNetDefPtr iface) { virNetworkDriverStatePtr driver =3D networkGetDriver(); @@ -5022,19 +5027,20 @@ networkReleaseActualDevice(virDomainDefPtr dom, 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 a interface for a virtual network")); goto error; } =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); - goto error; - } netdef =3D virNetworkObjGetDef(obj); =20 switch ((virNetworkForwardType) netdef->forward.type) { diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 97c9de04f0..becded57d9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1374,6 +1374,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, bool charDevPlugged =3D false; bool netdevPlugged =3D false; char *netdev_name; + virConnectPtr conn =3D NULL; =20 /* preallocate new slot for device */ if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1) < 0) @@ -1383,9 +1384,12 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - virDomainNetAllocateActualDevice(vm->def, net) < 0) - goto cleanup; + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (!(conn =3D virGetConnectNetwork())) + goto cleanup; + if (virDomainNetAllocateActualDevice(conn, vm->def, net) < 0) + goto cleanup; + } =20 actualType =3D virDomainNetGetActualType(net); =20 @@ -1688,8 +1692,12 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, =20 virDomainNetRemoveHostdev(vm->def, net); =20 - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (conn) + virDomainNetReleaseActualDevice(conn, vm->def, net); + else + VIR_WARN("Unable to release network device '%s'", NULLSTR(= net->ifname)); + } } =20 VIR_FREE(nicstr); @@ -1709,6 +1717,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, VIR_FREE(vhostfd); VIR_FREE(vhostfdName); VIR_FREE(charDevAlias); + virObjectUnref(conn); virObjectUnref(cfg); virDomainCCWAddressSetFree(ccwaddrs); =20 @@ -3719,6 +3728,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, bool needVlanUpdate =3D false; int ret =3D -1; int changeidx =3D -1; + virConnectPtr conn =3D NULL; =20 if ((changeidx =3D virDomainNetFindIdx(vm->def, newdev)) < 0) goto cleanup; @@ -3894,9 +3904,11 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, /* allocate new actual device to compare to old - we will need to * free it if we fail for any reason */ - if (newdev->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - virDomainNetAllocateActualDevice(vm->def, newdev) < 0) { - goto cleanup; + if (newdev->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (!(conn =3D virGetConnectNetwork())) + goto cleanup; + if (virDomainNetAllocateActualDevice(conn, vm->def, newdev) < 0) + goto cleanup; } =20 newType =3D virDomainNetGetActualType(newdev); @@ -4107,8 +4119,12 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, =20 /* this function doesn't work with HOSTDEV networks yet, thus * no need to change the pointer in the hostdev structure */ - if (olddev->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(vm->def, olddev); + if (olddev->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (conn || (conn =3D virGetConnectNetwork())) + virDomainNetReleaseActualDevice(conn, vm->def, olddev); + else + VIR_WARN("Unable to release network device '%s'", NULLSTR(= olddev->ifname)); + } virDomainNetDefFree(olddev); /* move newdev into the nets list, and NULL it out from the * virDomainDeviceDef that we were given so that the caller @@ -4139,8 +4155,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, * that the changes were minor enough that we didn't need to * replace the entire device object. */ - if (newdev && newdev->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(vm->def, newdev); + if (newdev && newdev->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && conn) + virDomainNetReleaseActualDevice(conn, vm->def, newdev); =20 return ret; } @@ -4697,8 +4713,15 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virDomainHostdevDefFree(hostdev); =20 if (net) { - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virConnectPtr conn =3D virGetConnectNetwork(); + if (conn) { + virDomainNetReleaseActualDevice(conn, vm->def, net); + virObjectUnref(conn); + } else { + VIR_WARN("Unable to release network device '%s'", NULLSTR(= net->ifname)); + } + } virDomainNetDefFree(net); } =20 @@ -4794,8 +4817,15 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver, =20 qemuDomainNetDeviceVportRemove(net); =20 - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virConnectPtr conn =3D virGetConnectNetwork(); + if (conn) { + virDomainNetReleaseActualDevice(conn, vm->def, net); + virObjectUnref(conn); + } else { + VIR_WARN("Unable to release network device '%s'", NULLSTR(net-= >ifname)); + } + } virDomainNetDefFree(net); ret =3D 0; =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6ec69d3c96..a8b3ed9099 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3266,6 +3266,7 @@ static void qemuProcessNotifyNets(virDomainDefPtr def) { size_t i; + virConnectPtr conn =3D NULL; =20 for (i =3D 0; i < def->nnets; i++) { virDomainNetDefPtr net =3D def->nets[i]; @@ -3277,9 +3278,14 @@ qemuProcessNotifyNets(virDomainDefPtr def) if (virDomainNetGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_DIRE= CT) ignore_value(virNetDevMacVLanReserveName(net->ifname, false)); =20 - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetNotifyActualDevice(def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (!conn && !(conn =3D virGetConnectNetwork())) + continue; + virDomainNetNotifyActualDevice(conn, def, net); + } } + + virObjectUnref(conn); } =20 /* Attempt to instantiate the filters. Ignore failures because it's @@ -5455,6 +5461,7 @@ qemuProcessNetworkPrepareDevices(virDomainDefPtr def) { int ret =3D -1; size_t i; + virConnectPtr conn =3D NULL; =20 for (i =3D 0; i < def->nnets; i++) { virDomainNetDefPtr net =3D def->nets[i]; @@ -5464,9 +5471,12 @@ qemuProcessNetworkPrepareDevices(virDomainDefPtr def) * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - virDomainNetAllocateActualDevice(def, net) < 0) - goto cleanup; + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (!conn && !(conn =3D virGetConnectNetwork())) + goto cleanup; + if (virDomainNetAllocateActualDevice(conn, def, net) < 0) + goto cleanup; + } =20 actualType =3D virDomainNetGetActualType(net); if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV && @@ -5497,6 +5507,7 @@ qemuProcessNetworkPrepareDevices(virDomainDefPtr def) } ret =3D 0; cleanup: + virObjectUnref(conn); return ret; } =20 @@ -7111,6 +7122,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, size_t i; char *timestamp; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + virConnectPtr conn =3D NULL; =20 VIR_DEBUG("Shutting down vm=3D%p name=3D%s id=3D%d pid=3D%lld, " "reason=3D%s, asyncJob=3D%s, flags=3D0x%x", @@ -7311,8 +7323,12 @@ void qemuProcessStop(virQEMUDriverPtr driver, =20 /* kick the device out of the hostdev list too */ virDomainNetRemoveHostdev(def, net); - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (conn || (conn =3D virGetConnectNetwork())) + virDomainNetReleaseActualDevice(conn, vm->def, net); + else + VIR_WARN("Unable to release network device '%s'", NULLSTR(= net->ifname)); + } } =20 retry: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155299963627123.49861965560865; Tue, 19 Mar 2019 05:47:16 -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 2C206F74AF; Tue, 19 Mar 2019 12:47: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 04A5760260; Tue, 19 Mar 2019 12:47:14 +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 B1D33181A13B; Tue, 19 Mar 2019 12:47:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JClAEe028738 for ; Tue, 19 Mar 2019 08:47:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id A4FCD5D717; Tue, 19 Mar 2019 12:47:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9D465D707; Tue, 19 Mar 2019 12:47:09 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:27 +0000 Message-Id: <20190319124700.16722-4-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 03/36] conf: simplify link from hostdev back to network device 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.38]); Tue, 19 Mar 2019 12:47:14 +0000 (UTC) hostdevs have a link back to the original network device. This is fairly generic accepting any type of device, however, we don't intend to make use of this approach in future. It can thus be specialized to network devices. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Cole Robinson --- src/conf/domain_conf.c | 18 ++++++++---------- src/conf/domain_conf.h | 8 +++++++- src/libxl/libxl_driver.c | 4 ++-- src/network/bridge_driver.c | 3 +-- src/qemu/qemu_command.c | 3 +-- src/qemu/qemu_domain_address.c | 4 ++-- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_hotplug.c | 14 ++++++-------- src/qemu/qemu_hotplug.h | 2 +- src/util/virhostdev.c | 17 ++++++++--------- 10 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 22c6fe1e38..bcd997a705 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2758,7 +2758,7 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr = def) /* If there is a parent device object, it will handle freeing * def->info. */ - if (def->parent.type =3D=3D VIR_DOMAIN_DEVICE_NONE) + if (!def->parent) virDomainDeviceInfoFree(def->info); =20 switch (def->mode) { @@ -2829,7 +2829,7 @@ void virDomainHostdevDefFree(virDomainHostdevDefPtr d= ef) /* If there is a parent device object, it will handle freeing * the memory. */ - if (def->parent.type =3D=3D VIR_DOMAIN_DEVICE_NONE) + if (!def->parent) VIR_FREE(def); } =20 @@ -5396,7 +5396,7 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTR= IBUTE_UNUSED, return 0; =20 if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV && - dev->data.hostdev->parent.type !=3D VIR_DOMAIN_DEVICE_NONE) { + dev->data.hostdev->parent) { /* This hostdev is a child of a higher level device * (e.g. interface), and thus already being counted on the * list for the other device type. @@ -6246,7 +6246,7 @@ virDomainDeviceDefValidateAliasesIterator(virDomainDe= fPtr def, return 0; =20 if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV && - dev->data.hostdev->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET) { + dev->data.hostdev->parent) { /* This hostdev is a copy of some previous interface. * Aliases are duplicated. */ return 0; @@ -11088,8 +11088,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node, } else if (actual->type =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) { virDomainHostdevDefPtr hostdev =3D &actual->data.hostdev.def; =20 - hostdev->parent.type =3D VIR_DOMAIN_DEVICE_NET; - hostdev->parent.data.net =3D parent; + hostdev->parent =3D parent; hostdev->info =3D &parent->info; /* The helper function expects type to already be found and * passed in as a string, since it is in a different place in @@ -11741,8 +11740,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, =20 case VIR_DOMAIN_NET_TYPE_HOSTDEV: hostdev =3D &def->data.hostdev.def; - hostdev->parent.type =3D VIR_DOMAIN_DEVICE_NET; - hostdev->parent.data.net =3D def; + hostdev->parent =3D def; hostdev->info =3D &def->info; /* The helper function expects type to already be found and * passed in as a string, since it is in a different place in @@ -28398,11 +28396,11 @@ virDomainDefFormatInternal(virDomainDefPtr def, } =20 for (n =3D 0; n < def->nhostdevs; n++) { - /* If parent.type !=3D NONE, this is just a pointer to the + /* If parent !=3D NONE, this is just a pointer to the * hostdev in a higher-level device (e.g. virDomainNetDef), * and will have already been formatted there. */ - if (def->hostdevs[n]->parent.type =3D=3D VIR_DOMAIN_DEVICE_NONE && + if (!def->hostdevs[n]->parent && virDomainHostdevDefFormat(buf, def->hostdevs[n], flags) < 0) { goto error; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e77fdcabf3..3db319c23d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -330,7 +330,13 @@ struct _virDomainHostdevCaps { =20 /* basic device for direct passthrough */ struct _virDomainHostdevDef { - virDomainDeviceDef parent; /* higher level Def containing this */ + /* If 'parent' is non-NULL it means this host dev was + * not originally present in the XML. It was copied from + * a network interface for convenience when handling + * hostdevs internally. This hostdev should never be + * visible to the user except as part of the interface + */ + virDomainNetDefPtr parent; =20 int mode; /* enum virDomainHostdevMode */ int startupPolicy; /* enum virDomainStartupPolicy */ diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 506dcdfbeb..3bb93ab5d7 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3915,9 +3915,9 @@ libxlDomainDetachDeviceLive(libxlDriverPrivatePtr dri= ver, /* If this is a network hostdev, we need to use the higher-lev= el * detach function so that mac address / virtualport are reset */ - if (hostdev->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET) + if (hostdev->parent) ret =3D libxlDomainDetachNetDevice(driver, vm, - hostdev->parent.data.net); + hostdev->parent); else ret =3D libxlDomainDetachHostDevice(driver, vm, hostdev); break; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index abeed0a806..1e6d1be32e 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4489,8 +4489,7 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->name); goto error; } - iface->data.network.actual->data.hostdev.def.parent.type =3D VIR_D= OMAIN_DEVICE_NET; - iface->data.network.actual->data.hostdev.def.parent.data.net =3D i= face; + iface->data.network.actual->data.hostdev.def.parent =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; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index bc02362495..022bba0280 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5708,8 +5708,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, /* bootNet will be non-0 if boot order was set and no other * net devices were encountered */ - if (hostdev->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET && - bootIndex =3D=3D 0) { + if (hostdev->parent && bootIndex =3D=3D 0) { bootIndex =3D *bootHostdevNet; *bootHostdevNet =3D 0; } diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 3eccf40eb5..7920f11d13 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1520,7 +1520,7 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def ATTRI= BUTE_UNUSED, =20 if (!virDeviceInfoPCIAddressIsPresent(info) || ((device->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) && - (device->data.hostdev->parent.type !=3D VIR_DOMAIN_DEVICE_NONE)))= { + device->data.hostdev->parent)) { /* If a hostdev has a parent, its info will be a part of the * parent, and will have its address collected during the scan * of the parent's device type. @@ -1615,7 +1615,7 @@ qemuDomainCollectPCIAddressExtension(virDomainDefPtr = def ATTRIBUTE_UNUSED, =20 if (!virDeviceInfoPCIAddressExtensionIsPresent(info) || ((device->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) && - (device->data.hostdev->parent.type !=3D VIR_DOMAIN_DEVICE_NONE)))= { + device->data.hostdev->parent)) { /* If a hostdev has a parent, its info will be a part of the * parent, and will have its address collected during the scan * of the parent's device type. diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d2ea301981..b81c411007 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8044,7 +8044,7 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, ret =3D qemuDomainDetachLease(driver, vm, dev->data.lease); break; case VIR_DOMAIN_DEVICE_NET: - ret =3D qemuDomainDetachNetDevice(driver, vm, dev, async); + ret =3D qemuDomainDetachNetDevice(driver, vm, dev->data.net, async= ); break; case VIR_DOMAIN_DEVICE_HOSTDEV: ret =3D qemuDomainDetachHostDevice(driver, vm, dev, async); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index becded57d9..0e8f082eee 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4656,11 +4656,9 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, event =3D virDomainEventDeviceRemovedNewFromObj(vm, hostdev->info->ali= as); virObjectEventStateQueue(driver->domainEventState, event); =20 - if (hostdev->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET) { - net =3D hostdev->parent.data.net; - + if (hostdev->parent) { for (i =3D 0; i < vm->def->nnets; i++) { - if (vm->def->nets[i] =3D=3D net) { + if (vm->def->nets[i] =3D=3D hostdev->parent) { virDomainNetRemove(vm->def, i); break; } @@ -5782,8 +5780,8 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr drive= r, /* If this is a network hostdev, we need to use the higher-level detach * function so that mac address / virtualport are reset */ - if (detach->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET) - return qemuDomainDetachNetDevice(driver, vm, &detach->parent, asyn= c); + if (detach->parent) + return qemuDomainDetachNetDevice(driver, vm, detach->parent, async= ); else return qemuDomainDetachThisHostDevice(driver, vm, detach, async); } @@ -5945,13 +5943,13 @@ qemuDomainDetachRedirdevDevice(virQEMUDriverPtr dri= ver, int qemuDomainDetachNetDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainDeviceDefPtr dev, + virDomainNetDefPtr net, bool async) { int detachidx, ret =3D -1; virDomainNetDefPtr detach =3D NULL; =20 - if ((detachidx =3D virDomainNetFindIdx(vm->def, dev->data.net)) < 0) + if ((detachidx =3D virDomainNetFindIdx(vm->def, net)) < 0) goto cleanup; =20 detach =3D vm->def->nets[detachidx]; diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 7ac03b7810..d3fa588aac 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -109,7 +109,7 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr d= river, bool async); int qemuDomainDetachNetDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainDeviceDefPtr dev, + virDomainNetDefPtr net, bool async); int qemuDomainDetachHostDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 6be395cdda..7f692a5289 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -333,8 +333,7 @@ virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev) { return hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && - hostdev->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET && - hostdev->parent.data.net; + hostdev->parent !=3D NULL; } =20 =20 @@ -427,7 +426,7 @@ virHostdevSaveNetConfig(virDomainHostdevDefPtr hostdev, int vf =3D -1; =20 if (!virHostdevIsPCINetDevice(hostdev) || - virDomainNetGetActualVirtPortProfile(hostdev->parent.data.net)) + virDomainNetGetActualVirtPortProfile(hostdev->parent)) return 0; =20 if (virHostdevIsVirtualFunction(hostdev) !=3D 1) { @@ -474,8 +473,8 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev, if (virHostdevNetDevice(hostdev, -1, &linkdev, &vf) < 0) return -1; =20 - vlan =3D virDomainNetGetActualVlan(hostdev->parent.data.net); - virtPort =3D virDomainNetGetActualVirtPortProfile(hostdev->parent.data= .net); + vlan =3D virDomainNetGetActualVlan(hostdev->parent); + virtPort =3D virDomainNetGetActualVirtPortProfile(hostdev->parent); if (virtPort) { if (vlan) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -485,11 +484,11 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev, return -1; } if (virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, - &hostdev->parent.data.net->= mac, + &hostdev->parent->mac, uuid, port_profile_associat= e) < 0) return -1; } else { - if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parent.data.net->= mac, + if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parent->mac, vlan, NULL, true) < 0) return -1; } @@ -535,10 +534,10 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hos= tdev, if (virHostdevNetDevice(hostdev, 0, &linkdev, &vf) < 0) return -1; =20 - virtPort =3D virDomainNetGetActualVirtPortProfile(hostdev->parent.data= .net); + virtPort =3D virDomainNetGetActualVirtPortProfile(hostdev->parent); if (virtPort) { return virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, - &hostdev->parent.data.ne= t->mac, + &hostdev->parent->mac, NULL, port_profile_associate); } else { --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999640554864.2876575941726; Tue, 19 Mar 2019 05:47:20 -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 A6898C049E20; Tue, 19 Mar 2019 12:47:18 +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 F20B060C1D; Tue, 19 Mar 2019 12:47:17 +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 9F4F4181A13E; Tue, 19 Mar 2019 12:47:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JClBBi028743 for ; Tue, 19 Mar 2019 08:47:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id DC4EA5D717; Tue, 19 Mar 2019 12:47:11 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 115615D707; Tue, 19 Mar 2019 12:47:10 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:28 +0000 Message-Id: <20190319124700.16722-5-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 04/36] network: add missing bandwidth limits for bridge forward type 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.31]); Tue, 19 Mar 2019 12:47:19 +0000 (UTC) In the case of a network with forward=3Dbridge, which has a bridge device listed, we are capable of setting bandwidth limits but fail to call the function to register them. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Cole Robinson --- src/network/bridge_driver.c | 39 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 1e6d1be32e..4770dd1e4e 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -3229,7 +3229,7 @@ networkValidate(virNetworkDriverStatePtr driver, virPortGroupDefPtr defaultPortGroup =3D NULL; virNetworkIPDefPtr ipdef; bool ipv4def =3D false, ipv6def =3D false; - bool bandwidthAllowed =3D true; + bool bandwidthAllowed =3D false; bool usesInterface =3D false, usesAddress =3D false; =20 if (virXMLCheckIllegalChars("name", def->name, "\n") < 0) @@ -3250,9 +3250,15 @@ networkValidate(virNetworkDriverStatePtr driver, return -1; =20 virNetworkSetBridgeMacAddr(def); + bandwidthAllowed =3D true; break; =20 case VIR_NETWORK_FORWARD_BRIDGE: + if (def->bridge !=3D NULL) + bandwidthAllowed =3D true; + + ATTRIBUTE_FALLTHROUGH; + case VIR_NETWORK_FORWARD_PRIVATE: case VIR_NETWORK_FORWARD_VEPA: case VIR_NETWORK_FORWARD_PASSTHROUGH: @@ -3293,15 +3299,6 @@ networkValidate(virNetworkDriverStatePtr driver, virNetworkForwardTypeToString(def->forward.type= )); return -1; } - if (def->bandwidth) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unsupported network-wide element= " - "in network %s with forward mode=3D'%s'"), - def->name, - virNetworkForwardTypeToString(def->forward.type= )); - return -1; - } - bandwidthAllowed =3D false; break; =20 case VIR_NETWORK_FORWARD_LAST: @@ -3310,6 +3307,16 @@ networkValidate(virNetworkDriverStatePtr driver, return -1; } =20 + if (def->bandwidth && + !bandwidthAllowed) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported network-wide element " + "in network %s with forward mode=3D'%s'"), + def->name, + virNetworkForwardTypeToString(def->forward.type)); + return -1; + } + /* we support configs with a single PF defined: * * or with a list of netdev names: @@ -4578,6 +4585,9 @@ networkAllocateActualDevice(virNetworkPtr net, goto error; } } + + if (networkPlugBandwidth(obj, iface) < 0) + goto error; break; } =20 @@ -5052,6 +5062,11 @@ networkReleaseActualDevice(virNetworkPtr net, break; =20 case VIR_NETWORK_FORWARD_BRIDGE: + if (iface->data.network.actual && + actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && + networkUnplugBandwidth(obj, iface) < 0) + goto error; + break; case VIR_NETWORK_FORWARD_PRIVATE: case VIR_NETWORK_FORWARD_VEPA: case VIR_NETWORK_FORWARD_PASSTHROUGH: @@ -5460,7 +5475,9 @@ networkBandwidthGenericChecks(virDomainNetDefPtr ifac= e, virNetDevBandwidthPtr ifaceBand; unsigned long long old_floor, new_floor; =20 - if (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_NETWORK)= { + 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; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999639823879.9680407931025; Tue, 19 Mar 2019 05:47:19 -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 092602D7E0; Tue, 19 Mar 2019 12:47:18 +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 D57E62967F; Tue, 19 Mar 2019 12:47:17 +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 80BE23FB30; Tue, 19 Mar 2019 12:47:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JClFpX028763 for ; Tue, 19 Mar 2019 08:47:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id C28BC5D707; Tue, 19 Mar 2019 12:47:15 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99D765D75C; Tue, 19 Mar 2019 12:47:12 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:29 +0000 Message-Id: <20190319124700.16722-6-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 05/36] network: use 'bridge' as actual type instead of 'network' 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.30]); Tue, 19 Mar 2019 12:47:18 +0000 (UTC) Ports allocated on virtual networks with type=3Dnat|route|open all get given an actual type of 'network'. Only ports in networks with type=3Dbridge use an actual type of 'bridge'. This distinction makes little sense since the virtualization drivers will treat both actual types in exactly the same way, as they're all just bridge devices a VM needs to be connected to. This doesn't affect user visible XML since the "actual" device XML is internal only, but we need code to convert the data upgrades. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 4770dd1e4e..40122612c8 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4454,11 +4454,7 @@ networkAllocateActualDevice(virNetworkPtr net, case VIR_NETWORK_FORWARD_NAT: case VIR_NETWORK_FORWARD_ROUTE: case VIR_NETWORK_FORWARD_OPEN: - /* for these forward types, the actual net type really *is* - * 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; + iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; =20 /* we also store the bridge device and macTableManager settings * in iface->data.network.actual->data.bridge for later use @@ -4832,6 +4828,15 @@ networkNotifyActualDevice(virNetworkPtr net, netdef->bridge) < 0)) goto error; =20 + /* Older libvirtd uses actualType=3D=3Dnetwork, but we now + * just use actualType=3D=3Dbridge, as nothing needs to + * distinguish the two cases, and this simplifies virt + * drive code */ + if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + actualType =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + } + /* see if we're connected to the correct bridge */ if (netdef->bridge) { bool useOVS =3D false; @@ -5475,9 +5480,8 @@ networkBandwidthGenericChecks(virDomainNetDefPtr ifac= e, virNetDevBandwidthPtr ifaceBand; unsigned long long old_floor, new_floor; =20 - 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)) { + if (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; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999641662849.9845000581212; Tue, 19 Mar 2019 05:47:21 -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 B5393316891A; Tue, 19 Mar 2019 12:47:19 +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 827E85D777; Tue, 19 Mar 2019 12:47: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 3C10F181A263; Tue, 19 Mar 2019 12:47:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JClHgT028773 for ; Tue, 19 Mar 2019 08:47:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id BA57B5D776; Tue, 19 Mar 2019 12:47:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBE5B5D763; Tue, 19 Mar 2019 12:47:15 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:30 +0000 Message-Id: <20190319124700.16722-7-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 06/36] util: add helper method for re-attaching a tap device to a bridge 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.41]); Tue, 19 Mar 2019 12:47:20 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Cole Robinson --- src/libvirt_private.syms | 1 + src/util/virnetdevtap.c | 69 ++++++++++++++++++++++++++++++++++++++++ src/util/virnetdevtap.h | 12 +++++++ 3 files changed, 82 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d9494a04bb..6f5a734fdb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2461,6 +2461,7 @@ virNetDevTapDelete; virNetDevTapGetName; virNetDevTapGetRealDeviceName; virNetDevTapInterfaceStats; +virNetDevTapReattachBridge; =20 =20 # util/virnetdevveth.h diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 972f3405aa..0484c7c5a4 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -553,6 +553,75 @@ virNetDevTapAttachBridge(const char *tapname, } =20 =20 +/** + * virNetDevTapReattachBridge: + * @tapname: the tap interface name (or name template) + * @brname: the bridge name + * @macaddr: desired MAC address + * @virtPortProfile: bridge/port specific configuration + * @virtVlan: vlan tag info + * @mtu: requested MTU for port (or 0 for "default") + * @actualMTU: MTU actually set for port (after accounting for bridge's MT= U) + * + * Ensures that the tap device (@tapname) is connected to the bridge + * (@brname), potentially removing it from any existing bridge that + * does not match. + * + * Returns 0 in case of success or -1 on failure + */ +int +virNetDevTapReattachBridge(const char *tapname, + const char *brname, + const virMacAddr *macaddr, + const unsigned char *vmuuid, + virNetDevVPortProfilePtr virtPortProfile, + virNetDevVlanPtr virtVlan, + unsigned int mtu, + unsigned int *actualMTU) +{ + bool useOVS =3D false; + char *master =3D NULL; + + if (virNetDevGetMaster(tapname, &master) < 0) + return -1; + + /* IFLA_MASTER for a tap on an OVS switch is always "ovs-system" */ + if (STREQ_NULLABLE(master, "ovs-system")) { + useOVS =3D true; + VIR_FREE(master); + if (virNetDevOpenvswitchInterfaceGetMaster(tapname, &master) < 0) + return -1; + } + + /* Nothing more todo if we're on the right bridge already */ + if (STREQ_NULLABLE(brname, master)) + return 0; + + /* disconnect from current (incorrect) bridge, if any */ + if (master) { + int ret; + VIR_INFO("Removing %s from %s", tapname, master); + if (useOVS) + ret =3D virNetDevOpenvswitchRemovePort(master, tapname); + else + ret =3D virNetDevBridgeRemovePort(master, tapname); + VIR_FREE(master); + if (ret < 0) + return -1; + } + + VIR_INFO("Attaching %s to %s", tapname, brname); + if (virNetDevTapAttachBridge(tapname, brname, + macaddr, vmuuid, + virtPortProfile, + virtVlan, + mtu, actualMTU) < 0) + return -1; + + return 0; +} + + /** * virNetDevTapCreateInBridgePort: * @brname: the bridge name diff --git a/src/util/virnetdevtap.h b/src/util/virnetdevtap.h index 226122aa2c..2b3893cd37 100644 --- a/src/util/virnetdevtap.h +++ b/src/util/virnetdevtap.h @@ -71,6 +71,18 @@ virNetDevTapAttachBridge(const char *tapname, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; =20 +int +virNetDevTapReattachBridge(const char *tapname, + const char *brname, + const virMacAddr *macaddr, + const unsigned char *vmuuid, + virNetDevVPortProfilePtr virtPortProfile, + virNetDevVlanPtr virtVlan, + unsigned int mtu, + unsigned int *actualMTU) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) + ATTRIBUTE_RETURN_CHECK; + int virNetDevTapCreateInBridgePort(const char *brname, char **ifname, const virMacAddr *macaddr, --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999648731183.53343982642696; Tue, 19 Mar 2019 05:47:28 -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 1408E83F44; Tue, 19 Mar 2019 12:47:27 +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 DEF2E5D777; Tue, 19 Mar 2019 12:47: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 948F33FA45; Tue, 19 Mar 2019 12:47:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JClPsq028792 for ; Tue, 19 Mar 2019 08:47:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 354E25D78E; Tue, 19 Mar 2019 12:47:25 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA8EA5D777; Tue, 19 Mar 2019 12:47:17 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:31 +0000 Message-Id: <20190319124700.16722-8-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 07/36] network: use virNetDevTapReattachBridge API 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.27]); Tue, 19 Mar 2019 12:47:27 +0000 (UTC) Switch over to use the new API for re-attaching the bridge device Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Cole Robinson --- src/network/bridge_driver.c | 47 ++++++++----------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 40122612c8..7df0c0f67a 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4792,7 +4792,6 @@ networkNotifyActualDevice(virNetworkPtr net, virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev =3D NULL; size_t i; - char *master =3D NULL; =20 obj =3D virNetworkObjFindByName(driver->networks, net->name); if (!obj) { @@ -4839,42 +4838,17 @@ networkNotifyActualDevice(virNetworkPtr net, =20 /* see if we're connected to the correct bridge */ if (netdef->bridge) { - bool useOVS =3D false; - - if (virNetDevGetMaster(iface->ifname, &master) < 0) + /* + * NB: we can't notify the guest of any MTU change anyway, + * so there is no point in trying to learn the actualMTU + * (final arg to virNetDevTapReattachBridge()) + */ + if (virNetDevTapReattachBridge(iface->ifname, netdef->bridge, + &iface->mac, dom->uuid, + virDomainNetGetActualVirtPortProfil= e(iface), + virDomainNetGetActualVlan(iface), + iface->mtu, NULL) < 0) { goto error; - - /* IFLA_MASTER for a tap on an OVS switch is always "ovs-system" */ - if (STREQ_NULLABLE(master, "ovs-system")) { - useOVS =3D true; - VIR_FREE(master); - if (virNetDevOpenvswitchInterfaceGetMaster(iface->ifname, &mas= ter) < 0) - goto error; - } - - if (STRNEQ_NULLABLE(netdef->bridge, master)) { - /* disconnect from current (incorrect) bridge */ - if (master) { - VIR_INFO("Removing %s from %s", iface->ifname, master); - if (useOVS) - ignore_value(virNetDevOpenvswitchRemovePort(master, if= ace->ifname)); - else - ignore_value(virNetDevBridgeRemovePort(master, iface->= ifname)); - } - - /* attach/reattach to correct bridge. - * NB: we can't notify the guest of any MTU change anyway, - * so there is no point in trying to learn the actualMTU - * (final arg to virNetDevTapAttachBridge()) - */ - VIR_INFO("Attaching %s to %s", iface->ifname, netdef->bridge); - if (virNetDevTapAttachBridge(iface->ifname, netdef->bridge, - &iface->mac, dom->uuid, - virDomainNetGetActualVirtPortProf= ile(iface), - virDomainNetGetActualVlan(iface), - iface->mtu, NULL) < 0) { - goto error; - } } } =20 @@ -5009,7 +4983,6 @@ networkNotifyActualDevice(virNetworkPtr net, =20 cleanup: virNetworkObjEndAPI(&obj); - VIR_FREE(master); return; =20 error: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999657738528.3465550994578; Tue, 19 Mar 2019 05:47:37 -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 00E6570D61; Tue, 19 Mar 2019 12:47:36 +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 C2C90600C2; Tue, 19 Mar 2019 12:47:35 +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 6D130181A267; Tue, 19 Mar 2019 12:47:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JClYr5028820 for ; Tue, 19 Mar 2019 08:47:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 830905D75E; Tue, 19 Mar 2019 12:47:34 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 463555D70E; Tue, 19 Mar 2019 12:47:25 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:32 +0000 Message-Id: <20190319124700.16722-9-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 08/36] virt drivers: don't handle type=network after resolving actual network type 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.28]); Tue, 19 Mar 2019 12:47:36 +0000 (UTC) The call to resolve the actual network type will turn any NICs with type=3Dnetwork into one of the other types. Thus there should be no need to handle type=3Dnetwork in later switch() statements jumping off the actual type. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Cole Robinson --- src/libxl/libxl_conf.c | 21 +++------------------ src/lxc/lxc_driver.c | 15 +++++++++++---- src/qemu/qemu_command.c | 8 ++++++-- src/qemu/qemu_hotplug.c | 13 +++++++++++-- src/qemu/qemu_interface.c | 12 ++++++++++-- src/qemu/qemu_process.c | 5 ++++- 6 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index e55a9fe22e..54adfd7379 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1352,25 +1352,10 @@ libxlMakeNic(virDomainDefPtr def, } break; case VIR_DOMAIN_NET_TYPE_NETWORK: - { - if (!(conn =3D virConnectOpen("xen:///system"))) - goto cleanup; - - if (!(network =3D - virNetworkLookupByName(conn, l_nic->data.network.name)))= { - goto cleanup; - } - - if (l_nic->guestIP.nips > 0) { - x_nic->ip =3D xenMakeIPList(&l_nic->guestIP); - if (!x_nic->ip) - goto cleanup; - } + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpectedly found type=3Dnetwork for actual= NIC type")); + goto cleanup; =20 - if (!(x_nic->bridge =3D virNetworkGetBridgeName(network))) - goto cleanup; - break; - } case VIR_DOMAIN_NET_TYPE_VHOSTUSER: case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_SERVER: diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index a184e67e15..37002dbf23 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3848,8 +3848,7 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, actualType =3D virDomainNetGetActualType(net); =20 switch (actualType) { - case VIR_DOMAIN_NET_TYPE_BRIDGE: - case VIR_DOMAIN_NET_TYPE_NETWORK: { + case VIR_DOMAIN_NET_TYPE_BRIDGE: { const char *brname =3D virDomainNetGetActualBridgeName(net); if (!brname) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -3867,6 +3866,10 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, if (!(veth =3D virLXCProcessSetupInterfaceDirect(conn, vm->def, ne= t))) goto cleanup; } break; + case VIR_DOMAIN_NET_TYPE_NETWORK: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpectedly found type=3Dnetwork for actual NIC= type")); + goto cleanup; case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_VHOSTUSER: case VIR_DOMAIN_NET_TYPE_SERVER: @@ -3912,7 +3915,6 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, } else if (veth) { switch (actualType) { case VIR_DOMAIN_NET_TYPE_BRIDGE: - case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_ETHERNET: ignore_value(virNetDevVethDelete(veth)); break; @@ -3921,6 +3923,7 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, ignore_value(virNetDevMacVLanDelete(veth)); break; =20 + case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_VHOSTUSER: case VIR_DOMAIN_NET_TYPE_SERVER: @@ -4352,7 +4355,6 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm, =20 switch (actualType) { case VIR_DOMAIN_NET_TYPE_BRIDGE: - case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_ETHERNET: if (virNetDevVethDelete(detach->ifname) < 0) { virDomainAuditNet(vm, detach, NULL, "detach", false); @@ -4360,6 +4362,11 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm, } break; =20 + case VIR_DOMAIN_NET_TYPE_NETWORK: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpectedly found type=3Dnetwork for actual NIC= type")); + goto cleanup; + /* It'd be nice to support this, but with macvlan * once assigned to a container nothing exists on * the host side. Further the container can change diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 022bba0280..64e47a79f0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8768,7 +8768,6 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, } =20 switch (actualType) { - case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_BRIDGE: tapfdSize =3D net->driver.virtio.queues; if (!tapfdSize) @@ -8846,6 +8845,11 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr drive= r, =20 break; =20 + case VIR_DOMAIN_NET_TYPE_NETWORK: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpectedly found type=3Dnetwork for actual NIC= type")); + goto cleanup; + case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_CLIENT: @@ -8862,7 +8866,6 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, */ switch ((virDomainNetType)actualType) { case VIR_DOMAIN_NET_TYPE_ETHERNET: - case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_BRIDGE: case VIR_DOMAIN_NET_TYPE_DIRECT: { @@ -8880,6 +8883,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, break; } =20 + case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_VHOSTUSER: case VIR_DOMAIN_NET_TYPE_SERVER: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 0e8f082eee..7b16530ab9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1442,7 +1442,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, =20 switch (actualType) { case VIR_DOMAIN_NET_TYPE_BRIDGE: - case VIR_DOMAIN_NET_TYPE_NETWORK: tapfdSize =3D vhostfdSize =3D net->driver.virtio.queues; if (!tapfdSize) tapfdSize =3D vhostfdSize =3D 1; @@ -1534,6 +1533,11 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, /* No preparation needed. */ break; =20 + case VIR_DOMAIN_NET_TYPE_NETWORK: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpectedly found type=3Dnetwork for actual NIC= type")); + goto cleanup; + case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_CLIENT: case VIR_DOMAIN_NET_TYPE_MCAST: @@ -3635,8 +3639,13 @@ qemuDomainChangeNetFilter(virDomainObjPtr vm, switch (virDomainNetGetActualType(newdev)) { case VIR_DOMAIN_NET_TYPE_ETHERNET: case VIR_DOMAIN_NET_TYPE_BRIDGE: - case VIR_DOMAIN_NET_TYPE_NETWORK: break; + + case VIR_DOMAIN_NET_TYPE_NETWORK: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpectedly found type=3Dnetwork for actual NIC= type")); + return -1; + case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_VHOSTUSER: case VIR_DOMAIN_NET_TYPE_SERVER: diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index c8effa68f4..9bb0d70986 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -58,7 +58,6 @@ qemuInterfaceStartDevice(virDomainNetDefPtr net) =20 switch (actualType) { case VIR_DOMAIN_NET_TYPE_BRIDGE: - case VIR_DOMAIN_NET_TYPE_NETWORK: if (virDomainNetGetActualBridgeMACTableManager(net) =3D=3D VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_LIBVIRT) { /* libvirt is managing the FDB of the bridge this device @@ -111,6 +110,11 @@ qemuInterfaceStartDevice(virDomainNetDefPtr net) =20 break; =20 + case VIR_DOMAIN_NET_TYPE_NETWORK: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpectedly found type=3Dnetwork for actual NIC= type")); + goto cleanup; + case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_VHOSTUSER: case VIR_DOMAIN_NET_TYPE_SERVER: @@ -164,7 +168,6 @@ qemuInterfaceStopDevice(virDomainNetDefPtr net) =20 switch (actualType) { case VIR_DOMAIN_NET_TYPE_BRIDGE: - case VIR_DOMAIN_NET_TYPE_NETWORK: if (virDomainNetGetActualBridgeMACTableManager(net) =3D=3D VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_LIBVIRT) { /* remove the FDB entries that were added during @@ -198,6 +201,11 @@ qemuInterfaceStopDevice(virDomainNetDefPtr net) break; } =20 + case VIR_DOMAIN_NET_TYPE_NETWORK: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpectedly found type=3Dnetwork for actual NIC= type")); + goto cleanup; + case VIR_DOMAIN_NET_TYPE_ETHERNET: case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_VHOSTUSER: diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a8b3ed9099..0c53e17dd8 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7290,12 +7290,15 @@ void qemuProcessStop(virQEMUDriverPtr driver, } break; case VIR_DOMAIN_NET_TYPE_BRIDGE: - case VIR_DOMAIN_NET_TYPE_NETWORK: #ifdef VIR_NETDEV_TAP_REQUIRE_MANUAL_CLEANUP if (!(vport && vport->virtPortType =3D=3D VIR_NETDEV_VPORT_PRO= FILE_OPENVSWITCH)) ignore_value(virNetDevTapDelete(net->ifname, net->backend.= tap)); #endif break; + case VIR_DOMAIN_NET_TYPE_NETWORK: + VIR_WARN("Unexpectedly found type=3Dnetwork for actual NIC typ= e"); + break; + case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_VHOSTUSER: case VIR_DOMAIN_NET_TYPE_SERVER: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999674808570.2852722145218; Tue, 19 Mar 2019 05:47:54 -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 983543087933; Tue, 19 Mar 2019 12:47:52 +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 662EC28D08; Tue, 19 Mar 2019 12:47: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 28B1B3FA4C; Tue, 19 Mar 2019 12:47:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JClo89028907 for ; Tue, 19 Mar 2019 08:47:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id CACEA5D717; Tue, 19 Mar 2019 12:47:50 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4243A5EDF4; Tue, 19 Mar 2019 12:47:34 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:33 +0000 Message-Id: <20190319124700.16722-10-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 09/36] network: move re-attach of bridge device out of network driver 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.45]); Tue, 19 Mar 2019 12:47:53 +0000 (UTC) During initial NIC setup the hypervisor drivers are responsible for attaching the TAP device to the bridge device. Any fixup after libvirtd restarts should thus also be their responsibility. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/conf/domain_conf.c | 20 +++++++++++++++++++- src/conf/domain_conf.h | 2 +- src/network/bridge_driver.c | 27 ++++++--------------------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bcd997a705..99b75e26f3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -54,6 +54,7 @@ #include "virsecret.h" #include "virstring.h" #include "virnetdev.h" +#include "virnetdevtap.h" #include "virnetdevmacvlan.h" #include "virhostdev.h" #include "virmdev.h" @@ -30217,8 +30218,25 @@ virDomainNetNotifyActualDevice(virConnectPtr conn, if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) return; =20 - netNotify(net, dom, iface); + if (netNotify(net, dom, iface) < 0) + goto cleanup; + + if (virDomainNetGetActualType(iface) =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE= ) { + /* + * NB: we can't notify the guest of any MTU change anyway, + * 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; + } =20 + cleanup: virObjectUnref(net); } =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3db319c23d..30aa985344 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3515,7 +3515,7 @@ typedef int virDomainDefPtr dom, virDomainNetDefPtr iface); =20 -typedef void +typedef int (*virDomainNetNotifyActualDeviceImpl)(virNetworkPtr net, virDomainDefPtr dom, virDomainNetDefPtr iface); diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 7df0c0f67a..5f3371b150 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4776,12 +4776,11 @@ networkAllocateActualDevice(virNetworkPtr net, * 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, or re-attach the interface's tap device to the network's - * bridge. + * order. * - * No return value (but does log any failures) + * Returns 0 on success, -1 on failure. */ -static void +static int networkNotifyActualDevice(virNetworkPtr net, virDomainDefPtr dom, virDomainNetDefPtr iface) @@ -4792,6 +4791,7 @@ networkNotifyActualDevice(virNetworkPtr net, virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev =3D NULL; size_t i; + int ret =3D -1; =20 obj =3D virNetworkObjFindByName(driver->networks, net->name); if (!obj) { @@ -4836,22 +4836,6 @@ networkNotifyActualDevice(virNetworkPtr net, actualType =3D VIR_DOMAIN_NET_TYPE_BRIDGE; } =20 - /* see if we're connected to the correct bridge */ - if (netdef->bridge) { - /* - * NB: we can't notify the guest of any MTU change anyway, - * so there is no point in trying to learn the actualMTU - * (final arg to virNetDevTapReattachBridge()) - */ - if (virNetDevTapReattachBridge(iface->ifname, netdef->bridge, - &iface->mac, dom->uuid, - virDomainNetGetActualVirtPortProfil= e(iface), - virDomainNetGetActualVlan(iface), - iface->mtu, NULL) < 0) { - goto error; - } - } - if (!iface->data.network.actual || (actualType !=3D VIR_DOMAIN_NET_TYPE_DIRECT && actualType !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV)) { @@ -4980,10 +4964,11 @@ networkNotifyActualDevice(virNetworkPtr net, goto error; } networkLogAllocation(netdef, actualType, dev, iface, true); + ret =3D 0; =20 cleanup: virNetworkObjEndAPI(&obj); - return; + return ret; =20 error: goto cleanup; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999683336323.1880062640204; Tue, 19 Mar 2019 05:48:03 -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 6D5F98123E; Tue, 19 Mar 2019 12:48: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 435D72CFBD; Tue, 19 Mar 2019 12:48: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 F08423FA4A; Tue, 19 Mar 2019 12:48:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JClxd0028938 for ; Tue, 19 Mar 2019 08:47:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 02D225D75C; Tue, 19 Mar 2019 12:47:59 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4ACA5D717; Tue, 19 Mar 2019 12:47:50 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:34 +0000 Message-Id: <20190319124700.16722-11-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 10/36] network: move fixup for domain actual net def out of network driver 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.25]); Tue, 19 Mar 2019 12:48:02 +0000 (UTC) The hypervisor drivers are soon going to communicate with the network driver via public APIs only. As such the network driver will not ever see the domain actual network def. Thus the backwards compatibility fixup logic must be moved out of the network driver. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/conf/domain_conf.c | 25 +++++++++++++++++++++++++ src/network/bridge_driver.c | 20 -------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 99b75e26f3..35d965d2a3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30210,6 +30210,7 @@ virDomainNetNotifyActualDevice(virConnectPtr conn, virDomainDefPtr dom, virDomainNetDefPtr iface) { + virDomainNetType actualType =3D virDomainNetGetActualType(iface); virNetworkPtr net =3D NULL; =20 if (!netNotify) @@ -30218,6 +30219,30 @@ virDomainNetNotifyActualDevice(virConnectPtr conn, if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) return; =20 + /* if we're restarting libvirtd after an upgrade from a version + * that didn't save bridge name in actualNetDef for + * actualType=3D=3Dnetwork, we need to copy it in so that it will be + * available in all cases + */ + if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + !iface->data.network.actual->data.bridge.brname) { + char *bridge =3D virNetworkGetBridgeName(net); + if (!bridge) + goto cleanup; + VIR_FREE(iface->data.network.actual->data.bridge.brname); + iface->data.network.actual->data.bridge.brname =3D bridge; + } + + /* Older libvirtd uses actualType=3D=3Dnetwork, but we now + * just use actualType=3D=3Dbridge, as nothing needs to + * distinguish the two cases, and this simplifies virt + * drive code */ + if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + actualType =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + } + + if (netNotify(net, dom, iface) < 0) goto cleanup; =20 diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 5f3371b150..a1ae90a34c 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4816,26 +4816,6 @@ networkNotifyActualDevice(virNetworkPtr net, goto error; } =20 - /* if we're restarting libvirtd after an upgrade from a version - * that didn't save bridge name in actualNetDef for - * actualType=3D=3Dnetwork, we need to copy it in so that it will be - * available in all cases - */ - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - !iface->data.network.actual->data.bridge.brname && - (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, - netdef->bridge) < 0)) - goto error; - - /* Older libvirtd uses actualType=3D=3Dnetwork, but we now - * just use actualType=3D=3Dbridge, as nothing needs to - * distinguish the two cases, and this simplifies virt - * drive code */ - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - actualType =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - } - if (!iface->data.network.actual || (actualType !=3D VIR_DOMAIN_NET_TYPE_DIRECT && actualType !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV)) { --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999692436340.30194730097367; Tue, 19 Mar 2019 05:48:12 -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 A0333307D963; Tue, 19 Mar 2019 12:48:10 +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 70BE05C219; Tue, 19 Mar 2019 12:48: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 15EF23FA4F; Tue, 19 Mar 2019 12:48:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCm8c5028985 for ; Tue, 19 Mar 2019 08:48:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id B516A5D717; Tue, 19 Mar 2019 12:48:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BCAE5D75C; Tue, 19 Mar 2019 12:47:59 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:35 +0000 Message-Id: <20190319124700.16722-12-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 11/36] network: unconditionally merge port profiles 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, 19 Mar 2019 12:48:11 +0000 (UTC) All but one of the network types supports port profiles. Rather than duplicating the code to merge profiles 3 times, do it once and then later report an error if used from the wrong place. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/network/bridge_driver.c | 54 +++++++++++++++---------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index a1ae90a34c..45a45b95d7 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4449,6 +4449,18 @@ networkAllocateActualDevice(virNetworkPtr net, iface->data.network.actual->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, + netdef->virtPortProfile, + portgroup + ? portgroup->virtPortProfile : NULL) <= 0) { + goto error; + } + virtport =3D iface->data.network.actual->virtPortProfile; + switch ((virNetworkForwardType) netdef->forward.type) { case VIR_NETWORK_FORWARD_NONE: case VIR_NETWORK_FORWARD_NAT: @@ -4467,6 +4479,15 @@ networkAllocateActualDevice(virNetworkPtr net, iface->data.network.actual->data.bridge.macTableManager =3D netdef->macTableManager; =20 + if (virtport) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(" not supported for = network " + "'%s' which uses IP forwarding"), + virNetDevVPortTypeToString(virtport->virtPortTy= pe), + netdef->name); + goto error; + } + if (networkPlugBandwidth(obj, iface) < 0) goto error; break; @@ -4519,17 +4540,6 @@ networkAllocateActualDevice(virNetworkPtr net, iface->data.network.actual->data.hostdev.def.source.subsys.u.pci.b= ackend =3D backend; =20 - /* merge virtualports from interface, network, and portgroup to - * arrive at actual virtualport to use - */ - if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtP= ortProfile, - iface->virtPortProfile, - netdef->virtPortProfile, - portgroup - ? portgroup->virtPortProfile : NUL= L) < 0) { - goto error; - } - virtport =3D iface->data.network.actual->virtPortProfile; if (virtport) { /* make sure type is supported for hostdev connections */ if (virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_8021Q= BG && @@ -4559,17 +4569,6 @@ networkAllocateActualDevice(virNetworkPtr net, iface->data.network.actual->data.bridge.macTableManager =3D netdef->macTableManager; =20 - /* merge virtualports from interface, network, and portgroup to - * arrive at actual virtualport to use - */ - if (virNetDevVPortProfileMerge3(&iface->data.network.actual->v= irtPortProfile, - iface->virtPortProfile, - netdef->virtPortProfile, - portgroup - ? portgroup->virtPortProfile := NULL) < 0) { - goto error; - } - virtport =3D iface->data.network.actual->virtPortProfile; if (virtport) { /* only type=3D'openvswitch' is allowed for bridges */ if (virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_O= PENVSWITCH) { @@ -4608,17 +4607,6 @@ networkAllocateActualDevice(virNetworkPtr net, iface->data.network.actual->data.direct.mode =3D virNetDevMacVLanModeTypeFromString(virNetworkForwardTypeToStri= ng(netdef->forward.type)); =20 - /* merge virtualports from interface, network, and portgroup to - * arrive at actual virtualport to use - */ - if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtP= ortProfile, - iface->virtPortProfile, - netdef->virtPortProfile, - portgroup - ? portgroup->virtPortProfile : NUL= L) < 0) { - goto error; - } - virtport =3D iface->data.network.actual->virtPortProfile; if (virtport) { /* make sure type is supported for macvtap connections */ if (virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_8021Q= BG && --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999697560900.3576798168967; Tue, 19 Mar 2019 05:48:17 -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 A503E36899; Tue, 19 Mar 2019 12:48: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 6CE521001E83; Tue, 19 Mar 2019 12:48: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 215AA3FA4C; Tue, 19 Mar 2019 12:48:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmD6u029024 for ; Tue, 19 Mar 2019 08:48:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 024425D717; Tue, 19 Mar 2019 12:48:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 014A152FC2; Tue, 19 Mar 2019 12:48:08 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:36 +0000 Message-Id: <20190319124700.16722-13-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 12/36] conf: don't pass interface type into virNetDevBandwidthParse 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.30]); Tue, 19 Mar 2019 12:48:16 +0000 (UTC) The virNetDevBandwidthParse method uses the interface type to decide whether to allow use of the "floor" parameter. Using the interface type is not convenient as callers may not have that available, but still wish to allow use of "floor". Switch to an explicit boolean to control its usage. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/conf/domain_conf.c | 4 ++-- src/conf/netdev_bandwidth_conf.c | 22 +++++++--------------- src/conf/netdev_bandwidth_conf.h | 2 +- src/conf/network_conf.c | 4 ++-- tests/virnetdevbandwidthtest.c | 2 +- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 35d965d2a3..d283feaca6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11147,7 +11147,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node, if (bandwidth_node && virNetDevBandwidthParse(&actual->bandwidth, bandwidth_node, - actual->type) < 0) + actual->type =3D=3D VIR_DOMAIN_NET_TYPE_NE= TWORK) < 0) goto error; =20 vlanNode =3D virXPathNode("./vlan", ctxt); @@ -11486,7 +11486,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, } else if (virXMLNodeNameEqual(cur, "bandwidth")) { if (virNetDevBandwidthParse(&def->bandwidth, cur, - def->type) < 0) + def->type =3D=3D VIR_DOMAIN_NE= T_TYPE_NETWORK) < 0) goto error; } else if (virXMLNodeNameEqual(cur, "vlan")) { if (virNetDevVlanParse(cur, ctxt, &def->vlan) < 0) diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_c= onf.c index 3113cde888..014941836d 100644 --- a/src/conf/netdev_bandwidth_conf.c +++ b/src/conf/netdev_bandwidth_conf.c @@ -100,18 +100,18 @@ virNetDevBandwidthParseRate(xmlNodePtr node, virNetDe= vBandwidthRatePtr rate) * virNetDevBandwidthParse: * @bandwidth: parsed bandwidth * @node: XML node - * @net_type: one of virDomainNetType + * @allowFloor: whether "floor" setting is supported * * Parse bandwidth XML and return pointer to structure. - * @net_type tell to which type will/is interface connected to. - * Pass -1 if this is not called on interface. + * The @allowFloor attribute indicates whether the caller + * is able to support use of the "floor" setting. * * Returns !NULL on success, NULL on error. */ int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth, xmlNodePtr node, - int net_type) + bool allowFloor) { int ret =3D -1; virNetDevBandwidthPtr def =3D NULL; @@ -162,17 +162,9 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwid= th, goto cleanup; } =20 - if (def->in->floor && net_type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - if (net_type =3D=3D -1) { - /* 'floor' on network isn't supported */ - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("floor attribute isn't supported for " - "network's bandwidth yet")); - } else { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("floor attribute is supported only for " - "interfaces of type network")); - } + if (def->in->floor && !allowFloor) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("floor attribute is not supported for this co= nfig")); goto cleanup; } } diff --git a/src/conf/netdev_bandwidth_conf.h b/src/conf/netdev_bandwidth_c= onf.h index cb1ffd29e0..7fe750ce27 100644 --- a/src/conf/netdev_bandwidth_conf.h +++ b/src/conf/netdev_bandwidth_conf.h @@ -27,7 +27,7 @@ =20 int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth, xmlNodePtr node, - int net_type) + bool allowFloor) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; int virNetDevBandwidthFormat(virNetDevBandwidthPtr def, virBufferPtr buf); diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 87bf158049..274f482bfc 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1187,7 +1187,7 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def, =20 bandwidth_node =3D virXPathNode("./bandwidth", ctxt); if (bandwidth_node && - virNetDevBandwidthParse(&def->bandwidth, bandwidth_node, -1) < 0) + virNetDevBandwidthParse(&def->bandwidth, bandwidth_node, false) < = 0) goto cleanup; =20 vlanNode =3D virXPathNode("./vlan", ctxt); @@ -1681,7 +1681,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) } =20 if ((bandwidthNode =3D virXPathNode("./bandwidth", ctxt)) && - virNetDevBandwidthParse(&def->bandwidth, bandwidthNode, -1) < 0) + virNetDevBandwidthParse(&def->bandwidth, bandwidthNode, false) < 0) goto error; =20 vlanNode =3D virXPathNode("./vlan", ctxt); diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c index 96776fa033..23788b4164 100644 --- a/tests/virnetdevbandwidthtest.c +++ b/tests/virnetdevbandwidthtest.c @@ -55,7 +55,7 @@ struct testSetStruct { \ rc =3D virNetDevBandwidthParse(&(var), \ ctxt->node, \ - VIR_DOMAIN_NET_TYPE_NETWORK); \ + true); \ xmlFreeDoc(doc); \ xmlXPathFreeContext(ctxt); \ if (rc < 0) \ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999700836992.238273909451; Tue, 19 Mar 2019 05:48:20 -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 DE0D170D6B; Tue, 19 Mar 2019 12:48:18 +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 B20DC1018A02; Tue, 19 Mar 2019 12:48:18 +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 681C5181A13E; Tue, 19 Mar 2019 12:48:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmHLV029048 for ; Tue, 19 Mar 2019 08:48:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 79A4C5D71D; Tue, 19 Mar 2019 12:48:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D7715D707; Tue, 19 Mar 2019 12:48:13 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:37 +0000 Message-Id: <20190319124700.16722-14-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 13/36] 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.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.28]); Tue, 19 Mar 2019 12:48:19 +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 --- src/conf/Makefile.inc.am | 2 + src/conf/virnetworkportdef.c | 514 ++++++++++++++++++ src/conf/virnetworkportdef.h | 112 ++++ src/libvirt_private.syms | 10 + tests/Makefile.am | 7 + .../plug-bridge-mactbl.xml | 9 + .../virnetworkportxml2xmldata/plug-bridge.xml | 12 + .../virnetworkportxml2xmldata/plug-direct.xml | 12 + .../plug-hostdev-pci.xml | 12 + tests/virnetworkportxml2xmldata/plug-none.xml | 8 + tests/virnetworkportxml2xmltest.c | 104 ++++ 11 files changed, 802 insertions(+) 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-none.xml create mode 100644 tests/virnetworkportxml2xmltest.c diff --git a/src/conf/Makefile.inc.am b/src/conf/Makefile.inc.am index 9b4d80485b..388917c5dd 100644 --- a/src/conf/Makefile.inc.am +++ b/src/conf/Makefile.inc.am @@ -5,6 +5,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..7023d9607e --- /dev/null +++ b/src/conf/virnetworkportdef.c @@ -0,0 +1,514 @@ +/* + * 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", "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_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; + } + + class_id =3D virXPathString("string(./class/@id)", ctxt); + if (class_id && + virStrToLong_ui(class_id, NULL, 10, &def->class_id) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse class id '%s'"), + class_id); + 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, 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_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; + virNetDevBandwidthFormat(def->bandwidth, buf); + if (def->class_id) + virBufferAsprintf(buf, "\n", def->class_id); + 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_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..3897013a86 --- /dev/null +++ b/src/conf/virnetworkportdef.h @@ -0,0 +1,112 @@ +/* + * 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_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; + struct { + char *linkdev; + int mode; /* enum virMacvtapMode from util/macvtap.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 6f5a734fdb..0694db7089 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1061,6 +1061,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 29f1fe2d2a..e39e3658a3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -148,6 +148,7 @@ EXTRA_DIST =3D \ virmock.h \ virnetdaemondata \ virnetdevtestdata \ + virnetworkportxml2xmldata \ virnwfilterbindingxml2xmldata \ virpcitestdata \ virscsidata \ @@ -334,6 +335,7 @@ endif WITH_YAJL test_programs +=3D \ networkxml2xmltest \ networkxml2xmlupdatetest \ + virnetworkportxml2xmltest \ $(NULL) =20 if WITH_NETWORK @@ -830,6 +832,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..6dd576e8a1 --- /dev/null +++ b/tests/virnetworkportxml2xmldata/plug-bridge.xml @@ -0,0 +1,12 @@ + + 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-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) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999706803391.45102642683037; Tue, 19 Mar 2019 05:48:26 -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 ABAA861BB4; Tue, 19 Mar 2019 12:48:24 +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 83F86611DC; Tue, 19 Mar 2019 12:48:24 +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 4A0073FA4C; Tue, 19 Mar 2019 12:48:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmMUn029086 for ; Tue, 19 Mar 2019 08:48:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id EF7355D75D; Tue, 19 Mar 2019 12:48:22 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECB8A5D75C; Tue, 19 Mar 2019 12:48:17 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:38 +0000 Message-Id: <20190319124700.16722-15-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 14/36] network: stop passing virDomainNetDefPtr into bandwidth functions 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.39]); Tue, 19 Mar 2019 12:48:25 +0000 (UTC) The networkPlugBandwidth & networkUnplugBandwidth methods currently take a virDomainNetDefPtr. To remove the dependency on the domain config struct, pass individual parameters instead. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/network/bridge_driver.c | 94 ++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 45a45b95d7..d4ca2930cc 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -169,11 +169,14 @@ networkRefreshDaemons(virNetworkDriverStatePtr driver= ); =20 static int networkPlugBandwidth(virNetworkObjPtr obj, - virDomainNetDefPtr iface); + virMacAddrPtr mac, + virNetDevBandwidthPtr ifaceBand, + unsigned int *class_id); =20 static int networkUnplugBandwidth(virNetworkObjPtr obj, - virDomainNetDefPtr iface); + virNetDevBandwidthPtr ifaceBand, + unsigned int *class_id); =20 static void networkNetworkObjTaint(virNetworkObjPtr obj, @@ -4488,7 +4491,9 @@ networkAllocateActualDevice(virNetworkPtr net, goto error; } =20 - if (networkPlugBandwidth(obj, iface) < 0) + if (networkPlugBandwidth(obj, &iface->mac, iface->bandwidth, + iface->data.network.actual ? + &iface->data.network.actual->class_id : N= ULL) < 0) goto error; break; =20 @@ -4581,7 +4586,9 @@ networkAllocateActualDevice(virNetworkPtr net, } } =20 - if (networkPlugBandwidth(obj, iface) < 0) + if (networkPlugBandwidth(obj, &iface->mac, iface->bandwidth, + iface->data.network.actual ? + &iface->data.network.actual->class_id= : NULL) < 0) goto error; break; } @@ -4988,14 +4995,17 @@ networkReleaseActualDevice(virNetworkPtr net, case VIR_NETWORK_FORWARD_NAT: case VIR_NETWORK_FORWARD_ROUTE: case VIR_NETWORK_FORWARD_OPEN: - if (iface->data.network.actual && networkUnplugBandwidth(obj, ifac= e) < 0) + if (iface->data.network.actual && + networkUnplugBandwidth(obj, iface->bandwidth, + &iface->data.network.actual->class_id) = < 0) goto error; break; =20 case VIR_NETWORK_FORWARD_BRIDGE: if (iface->data.network.actual && actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && - networkUnplugBandwidth(obj, iface) < 0) + networkUnplugBandwidth(obj, iface->bandwidth, + &iface->data.network.actual->class_id) = < 0) goto error; break; case VIR_NETWORK_FORWARD_PRIVATE: @@ -5135,7 +5145,7 @@ static int networkCheckBandwidth(virNetworkObjPtr obj, virNetDevBandwidthPtr ifaceBand, virNetDevBandwidthPtr oldBandwidth, - virMacAddr ifaceMac, + virMacAddrPtr ifaceMac, unsigned long long *new_rate) { int ret =3D -1; @@ -5145,7 +5155,7 @@ networkCheckBandwidth(virNetworkObjPtr obj, unsigned long long tmp_new_rate =3D 0; char ifmac[VIR_MAC_STRING_BUFLEN]; =20 - virMacAddrFormat(&ifaceMac, ifmac); + virMacAddrFormat(ifaceMac, ifmac); =20 if (ifaceBand && ifaceBand->in && ifaceBand->in->floor && !(netBand && netBand->in)) { @@ -5230,44 +5240,45 @@ networkNextClassID(virNetworkObjPtr obj) =20 static int networkPlugBandwidthImpl(virNetworkObjPtr obj, - virDomainNetDefPtr iface, + virMacAddrPtr mac, virNetDevBandwidthPtr ifaceBand, + unsigned int *class_id, unsigned long long new_rate) { virNetworkDriverStatePtr driver =3D networkGetDriver(); virNetworkDefPtr def =3D virNetworkObjGetDef(obj); virBitmapPtr classIdMap =3D virNetworkObjGetClassIdMap(obj); unsigned long long tmp_floor_sum =3D virNetworkObjGetFloorSum(obj); - ssize_t class_id =3D 0; + ssize_t next_id =3D 0; int plug_ret; int ret =3D -1; =20 /* generate new class_id */ - if ((class_id =3D networkNextClassID(obj)) < 0) { + if ((next_id =3D networkNextClassID(obj)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not generate next class ID")); goto cleanup; } =20 plug_ret =3D virNetDevBandwidthPlug(def->bridge, def->bandwidth, - &iface->mac, ifaceBand, class_id); + mac, ifaceBand, next_id); if (plug_ret < 0) { - ignore_value(virNetDevBandwidthUnplug(def->bridge, class_id)); + ignore_value(virNetDevBandwidthUnplug(def->bridge, next_id)); goto cleanup; } =20 /* QoS was set, generate new class ID */ - iface->data.network.actual->class_id =3D class_id; + *class_id =3D next_id; /* update sum of 'floor'-s of attached NICs */ tmp_floor_sum +=3D ifaceBand->in->floor; virNetworkObjSetFloorSum(obj, tmp_floor_sum); /* update status file */ if (virNetworkObjSaveStatus(driver->stateDir, obj) < 0) { - ignore_value(virBitmapClearBit(classIdMap, class_id)); + ignore_value(virBitmapClearBit(classIdMap, next_id)); tmp_floor_sum -=3D ifaceBand->in->floor; virNetworkObjSetFloorSum(obj, tmp_floor_sum); - iface->data.network.actual->class_id =3D 0; - ignore_value(virNetDevBandwidthUnplug(def->bridge, class_id)); + *class_id =3D 0; + ignore_value(virNetDevBandwidthUnplug(def->bridge, next_id)); goto cleanup; } /* update rate for non guaranteed NICs */ @@ -5285,16 +5296,17 @@ networkPlugBandwidthImpl(virNetworkObjPtr obj, =20 static int networkPlugBandwidth(virNetworkObjPtr obj, - virDomainNetDefPtr iface) + virMacAddrPtr mac, + virNetDevBandwidthPtr ifaceBand, + unsigned int *class_id) { int ret =3D -1; int plug_ret; unsigned long long new_rate =3D 0; char ifmac[VIR_MAC_STRING_BUFLEN]; - virNetDevBandwidthPtr ifaceBand =3D virDomainNetGetActualBandwidth(ifa= ce); =20 if ((plug_ret =3D networkCheckBandwidth(obj, ifaceBand, NULL, - iface->mac, &new_rate)) < 0) { + mac, &new_rate)) < 0) { /* helper reported error */ goto cleanup; } @@ -5305,16 +5317,9 @@ networkPlugBandwidth(virNetworkObjPtr obj, goto cleanup; } =20 - virMacAddrFormat(&iface->mac, ifmac); - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK || - !iface->data.network.actual) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot set bandwidth on interface '%s' of type %= d"), - ifmac, iface->type); - goto cleanup; - } + virMacAddrFormat(mac, ifmac); =20 - if (networkPlugBandwidthImpl(obj, iface, ifaceBand, new_rate) < 0) + if (networkPlugBandwidthImpl(obj, mac, ifaceBand, class_id, new_rate) = < 0) goto cleanup; =20 ret =3D 0; @@ -5326,7 +5331,8 @@ networkPlugBandwidth(virNetworkObjPtr obj, =20 static int networkUnplugBandwidth(virNetworkObjPtr obj, - virDomainNetDefPtr iface) + virNetDevBandwidthPtr ifaceBand, + unsigned int *class_id) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); virBitmapPtr classIdMap =3D virNetworkObjGetClassIdMap(obj); @@ -5334,10 +5340,8 @@ networkUnplugBandwidth(virNetworkObjPtr obj, virNetworkDriverStatePtr driver =3D networkGetDriver(); int ret =3D 0; unsigned long long new_rate; - virNetDevBandwidthPtr ifaceBand =3D virDomainNetGetActualBandwidth(ifa= ce); =20 - if (iface->data.network.actual && - iface->data.network.actual->class_id) { + if (class_id && *class_id) { if (!def->bandwidth || !def->bandwidth->in) { VIR_WARN("Network %s has no bandwidth but unplug requested", def->name); @@ -5349,8 +5353,7 @@ networkUnplugBandwidth(virNetworkObjPtr obj, if (def->bandwidth->in->peak > 0) new_rate =3D def->bandwidth->in->peak; =20 - ret =3D virNetDevBandwidthUnplug(def->bridge, - iface->data.network.actual->class_i= d); + ret =3D virNetDevBandwidthUnplug(def->bridge, *class_id); if (ret < 0) goto cleanup; /* update sum of 'floor'-s of attached NICs */ @@ -5358,14 +5361,12 @@ networkUnplugBandwidth(virNetworkObjPtr obj, virNetworkObjSetFloorSum(obj, tmp_floor_sum); =20 /* return class ID */ - ignore_value(virBitmapClearBit(classIdMap, - iface->data.network.actual->class_i= d)); + ignore_value(virBitmapClearBit(classIdMap, *class_id)); /* update status file */ if (virNetworkObjSaveStatus(driver->stateDir, obj) < 0) { tmp_floor_sum +=3D ifaceBand->in->floor; virNetworkObjSetFloorSum(obj, tmp_floor_sum); - ignore_value(virBitmapSetBit(classIdMap, - iface->data.network.actual->class= _id)); + ignore_value(virBitmapSetBit(classIdMap, *class_id)); goto cleanup; } /* update rate for non guaranteed NICs */ @@ -5375,7 +5376,7 @@ networkUnplugBandwidth(virNetworkObjPtr obj, VIR_WARN("Unable to update rate for 1:2 class on %s bridge", def->bridge); /* no class is associated any longer */ - iface->data.network.actual->class_id =3D 0; + *class_id =3D 0; } =20 cleanup: @@ -5445,7 +5446,7 @@ networkBandwidthChangeAllowed(virDomainNetDefPtr ifac= e, return false; } =20 - if (networkCheckBandwidth(obj, newBandwidth, ifaceBand, iface->mac, NU= LL) < 0) + if (networkCheckBandwidth(obj, newBandwidth, ifaceBand, &iface->mac, N= ULL) < 0) goto cleanup; =20 ret =3D true; @@ -5488,7 +5489,7 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, def =3D virNetworkObjGetDef(obj); =20 if ((plug_ret =3D networkCheckBandwidth(obj, newBandwidth, ifaceBand, - iface->mac, &new_rate)) < 0) { + &iface->mac, &new_rate)) < 0) { /* helper reported error */ goto cleanup; } @@ -5534,12 +5535,17 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, } else if (newBandwidth->in && newBandwidth->in->floor) { /* .. or we need to plug in new .. */ =20 - if (networkPlugBandwidthImpl(obj, iface, newBandwidth, new_rate) <= 0) + if (networkPlugBandwidthImpl(obj, &iface->mac, newBandwidth, + iface->data.network.actual ? + &iface->data.network.actual->class_id= : NULL, + new_rate) < 0) goto cleanup; } else { /* .. or unplug old. */ =20 - if (networkUnplugBandwidth(obj, iface) < 0) + if (networkUnplugBandwidth(obj, iface->bandwidth, + iface->data.network.actual ? + &iface->data.network.actual->class_id := NULL) < 0) goto cleanup; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155299971126631.731979953097493; Tue, 19 Mar 2019 05:48:31 -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 981453092669; Tue, 19 Mar 2019 12:48:29 +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 67C2C605CA; Tue, 19 Mar 2019 12:48:29 +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 23F4B3FA4C; Tue, 19 Mar 2019 12:48:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmRvd029117 for ; Tue, 19 Mar 2019 08:48:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id E035E5D70E; Tue, 19 Mar 2019 12:48:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1ED05D71D; Tue, 19 Mar 2019 12:48:23 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:39 +0000 Message-Id: <20190319124700.16722-16-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 15/36] 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.43]); Tue, 19 Mar 2019 12:48:30 +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 instad. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- 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 d4ca2930cc..9eda1c62b0 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4313,32 +4313,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); } } @@ -4747,7 +4744,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 @@ -4938,7 +4935,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: @@ -5105,7 +5102,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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999714478193.14419093264075; Tue, 19 Mar 2019 05:48:34 -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 CAF55307C94A; Tue, 19 Mar 2019 12:48:32 +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 9474328545; Tue, 19 Mar 2019 12:48:32 +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 4A452181A137; Tue, 19 Mar 2019 12:48:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmUTp029131 for ; Tue, 19 Mar 2019 08:48:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6DA835D75C; Tue, 19 Mar 2019 12:48:30 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50EEF5D717; Tue, 19 Mar 2019 12:48:28 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:40 +0000 Message-Id: <20190319124700.16722-17-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 16/36] util: add API for copying virtual port profile data 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.46]); Tue, 19 Mar 2019 12:48:33 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/libvirt_private.syms | 1 + src/util/virnetdevvportprofile.c | 16 ++++++++++++++++ src/util/virnetdevvportprofile.h | 2 ++ 3 files changed, 19 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0694db7089..1e405cbe5f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2490,6 +2490,7 @@ virNetDevVlanFree; virNetDevVPortProfileAssociate; virNetDevVPortProfileCheckComplete; virNetDevVPortProfileCheckNoExtras; +virNetDevVPortProfileCopy; virNetDevVPortProfileDisassociate; virNetDevVPortProfileEqual; virNetDevVPortProfileMerge3; diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprof= ile.c index fb05190c02..b6e8365e61 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -125,6 +125,22 @@ virNetDevVPortProfileEqual(virNetDevVPortProfilePtr a,= virNetDevVPortProfilePtr return true; } =20 + +int virNetDevVPortProfileCopy(virNetDevVPortProfilePtr *dst, const virNetD= evVPortProfile *src) +{ + if (!src) { + *dst =3D NULL; + return 0; + } + + if (VIR_ALLOC(*dst) < 0) + return -1; + + memcpy(*dst, src, sizeof(*src)); + return 0; +} + + /* virNetDevVPortProfileCheckComplete() checks that all attributes * required for the type of virtport are specified. When * generateMissing is true, any missing attribute that can be diff --git a/src/util/virnetdevvportprofile.h b/src/util/virnetdevvportprof= ile.h index 65b4779861..503c44e086 100644 --- a/src/util/virnetdevvportprofile.h +++ b/src/util/virnetdevvportprofile.h @@ -79,6 +79,8 @@ struct _virNetDevVPortProfile { =20 bool virNetDevVPortProfileEqual(virNetDevVPortProfilePtr a, virNetDevVPortProfilePtr b); +int virNetDevVPortProfileCopy(virNetDevVPortProfilePtr *dst, + const virNetDevVPortProfile *src); =20 int virNetDevVPortProfileCheckComplete(virNetDevVPortProfilePtr virtport, bool generateMissing); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999717365904.8630594111856; Tue, 19 Mar 2019 05:48:37 -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 8630281105; Tue, 19 Mar 2019 12:48:35 +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 59FD260634; Tue, 19 Mar 2019 12:48:35 +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 0FC033F5CD; Tue, 19 Mar 2019 12:48:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmVQl029137 for ; Tue, 19 Mar 2019 08:48:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id F01725D75E; Tue, 19 Mar 2019 12:48:31 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id C836B5D717; Tue, 19 Mar 2019 12:48:30 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:41 +0000 Message-Id: <20190319124700.16722-18-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 17/36] 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.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.28]); Tue, 19 Mar 2019 12:48:36 +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 | 272 +++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 17 +++ src/libvirt_private.syms | 3 + 3 files changed, 292 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d283feaca6..ee4d586d77 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" @@ -30161,6 +30162,277 @@ 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_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: + 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->data.hostdev.def.parent =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_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_NETWORK: + 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 30aa985344..546ee181b1 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3510,6 +3510,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 1e405cbe5f..b23d3c9891 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -457,9 +457,12 @@ virDomainNetAllocateActualDevice; virDomainNetAppendIPAddress; virDomainNetBandwidthChangeAllowed; virDomainNetBandwidthUpdate; +virDomainNetDefActualFromNetworkPort; +virDomainNetDefActualToNetworkPort; virDomainNetDefClear; virDomainNetDefFormat; virDomainNetDefFree; +virDomainNetDefToNetworkPort; virDomainNetFind; virDomainNetFindByName; virDomainNetFindIdx; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999716853210.9853813355203; Tue, 19 Mar 2019 05:48:36 -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 384913092667; Tue, 19 Mar 2019 12:48:35 +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 0FFA85C641; Tue, 19 Mar 2019 12:48:35 +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 C36023F7D9; Tue, 19 Mar 2019 12:48:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmXcu029155 for ; Tue, 19 Mar 2019 08:48:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 624935D71D; Tue, 19 Mar 2019 12:48:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57E215D75C; Tue, 19 Mar 2019 12:48:32 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:42 +0000 Message-Id: <20190319124700.16722-19-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 18/36] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 19 Mar 2019 12:48:35 +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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- 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 9eda1c62b0..cd53e124c2 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 "conf/virnetworkportdef.h" =20 #define VIR_FROM_THIS VIR_FROM_NETWORK #define MAX_BRIDGE_ID 256 @@ -4368,17 +4369,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, @@ -4393,9 +4393,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)) { @@ -4405,99 +4402,84 @@ 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: case VIR_NETWORK_FORWARD_ROUTE: case VIR_NETWORK_FORWARD_OPEN: - iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE; =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 @@ -4515,42 +4497,19 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->name); goto error; } - iface->data.network.actual->data.hostdev.def.parent =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; } @@ -4564,28 +4523,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; } @@ -4603,22 +4558,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; } @@ -4647,8 +4602,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 */ @@ -4674,7 +4629,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; } @@ -4687,30 +4642,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 " @@ -4719,16 +4674,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++; @@ -4746,9 +4700,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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155299972093133.61405501364061; Tue, 19 Mar 2019 05:48:40 -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 4E39B78EAF; Tue, 19 Mar 2019 12:48:39 +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 1F31D5D723; Tue, 19 Mar 2019 12:48:39 +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 D15713D389; Tue, 19 Mar 2019 12:48:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmZKo029169 for ; Tue, 19 Mar 2019 08:48:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5B3B85D75C; Tue, 19 Mar 2019 12:48:35 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDBEF5D717; Tue, 19 Mar 2019 12:48:33 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:43 +0000 Message-Id: <20190319124700.16722-20-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 19/36] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 19 Mar 2019 12:48:39 +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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/network/bridge_driver.c | 91 ++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index cd53e124c2..158b9ce447 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4738,10 +4738,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 @@ -4768,40 +4768,34 @@ 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_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 plugged into= a 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; } @@ -4810,8 +4804,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 @@ -4822,31 +4817,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; @@ -4856,12 +4846,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 @@ -4874,15 +4864,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++; @@ -4900,6 +4896,7 @@ networkNotifyActualDevice(virNetworkPtr net, =20 cleanup: virNetworkObjEndAPI(&obj); + virNetworkPortDefFree(port); return ret; =20 error: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999724882110.85084639496404; Tue, 19 Mar 2019 05:48:44 -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 3E344C130702; Tue, 19 Mar 2019 12:48:43 +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 18DB95D717; Tue, 19 Mar 2019 12:48:43 +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 C7FB3181A13E; Tue, 19 Mar 2019 12:48:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmaYJ029190 for ; Tue, 19 Mar 2019 08:48:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id A8DF75D75C; Tue, 19 Mar 2019 12:48:36 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5B045D717; Tue, 19 Mar 2019 12:48:35 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:44 +0000 Message-Id: <20190319124700.16722-21-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 20/36] 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.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.31]); Tue, 19 Mar 2019 12:48:43 +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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/network/bridge_driver.c | 137 +++++++++++++++--------------------- 1 file changed, 56 insertions(+), 81 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 158b9ce447..d2bcb81912 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4921,10 +4921,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 @@ -4933,77 +4933,49 @@ 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 a 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_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; } @@ -5013,23 +4985,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; @@ -5041,26 +5014,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); =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); - } + 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, &iface->mac, false); + ret =3D 0; cleanup: virNetworkObjEndAPI(&obj); @@ -5068,10 +5045,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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999723530229.42601380887754; Tue, 19 Mar 2019 05:48:43 -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 D2703C015C2F; Tue, 19 Mar 2019 12:48:41 +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 A4AEF1001E61; Tue, 19 Mar 2019 12:48:41 +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 650A83D38A; Tue, 19 Mar 2019 12:48:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmdOw029215 for ; Tue, 19 Mar 2019 08:48:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id A13B85D71D; Tue, 19 Mar 2019 12:48:39 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1207C5D717; Tue, 19 Mar 2019 12:48:36 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:45 +0000 Message-Id: <20190319124700.16722-22-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 21/36] 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.31]); Tue, 19 Mar 2019 12:48:42 +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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- 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 d2bcb81912..1080684043 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 @@ -2766,7 +2761,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; @@ -2808,7 +2803,7 @@ networkStartNetwork(virNetworkDriverStatePtr driver, } =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; @@ -2892,7 +2887,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); @@ -3868,7 +3863,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 @@ -4689,8 +4684,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--; @@ -4883,7 +4878,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) @@ -5034,7 +5029,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, &iface->mac, false); =20 diff --git a/src/util/virhook.c b/src/util/virhook.c index 37de0cb39e..0322786719 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -95,8 +95,8 @@ VIR_ENUM_IMPL(virHookNetworkOp, VIR_HOOK_NETWORK_OP_LAST, "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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999729179666.7944323344694; Tue, 19 Mar 2019 05:48:49 -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 827D7C057F5C; Tue, 19 Mar 2019 12:48:47 +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 5C00E60C1D; Tue, 19 Mar 2019 12:48:47 +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 192EF3D38E; Tue, 19 Mar 2019 12:48:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmfsC029232 for ; Tue, 19 Mar 2019 08:48:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2FE655D71D; Tue, 19 Mar 2019 12:48:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 090A95D717; Tue, 19 Mar 2019 12:48:39 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:46 +0000 Message-Id: <20190319124700.16722-23-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 22/36] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 19 Mar 2019 12:48:48 +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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/conf/domain_conf.c | 15 -------- src/conf/domain_conf.h | 10 ----- src/libvirt_private.syms | 1 - src/network/bridge_driver.c | 75 ++++++++----------------------------- src/qemu/qemu_driver.c | 8 ++-- 5 files changed, 20 insertions(+), 89 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ee4d586d77..1c0efc018c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30436,7 +30436,6 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr = dom, static virDomainNetAllocateActualDeviceImpl netAllocate; static virDomainNetNotifyActualDeviceImpl netNotify; static virDomainNetReleaseActualDeviceImpl netRelease; -static virDomainNetBandwidthChangeAllowedImpl netBandwidthChangeAllowed; static virDomainNetBandwidthUpdateImpl netBandwidthUpdate; =20 =20 @@ -30444,13 +30443,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 @@ -30558,18 +30555,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 546ee181b1..4c0b3da47d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3542,10 +3542,6 @@ typedef int virDomainDefPtr dom, virDomainNetDefPtr iface); =20 -typedef bool -(*virDomainNetBandwidthChangeAllowedImpl)(virDomainNetDefPtr iface, - virNetDevBandwidthPtr newBandwid= th); - typedef int (*virDomainNetBandwidthUpdateImpl)(virDomainNetDefPtr iface, virNetDevBandwidthPtr newBandwidth); @@ -3555,7 +3551,6 @@ void virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate, virDomainNetNotifyActualDeviceImpl notify, virDomainNetReleaseActualDeviceImpl release, - virDomainNetBandwidthChangeAllowedImpl bandwidth= ChangeAllowed, virDomainNetBandwidthUpdateImpl bandwidthUpdate); =20 int @@ -3576,11 +3571,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 b23d3c9891..43f7f02af3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -455,7 +455,6 @@ virDomainMemorySourceTypeFromString; virDomainMemorySourceTypeToString; virDomainNetAllocateActualDevice; virDomainNetAppendIPAddress; -virDomainNetBandwidthChangeAllowed; virDomainNetBandwidthUpdate; virDomainNetDefActualFromNetworkPort; virDomainNetDefActualToNetworkPort; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 1080684043..534d144464 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -5324,63 +5324,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_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) @@ -5391,6 +5334,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 @@ -5400,7 +5344,21 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, return -1; } =20 - if (!networkBandwidthGenericChecks(iface, newBandwidth)) + if (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 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); @@ -5546,7 +5504,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 b81c411007..baf188ae40 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11729,17 +11729,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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999727963150.69950363451403; Tue, 19 Mar 2019 05:48:47 -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 E558A81E0D; Tue, 19 Mar 2019 12: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 4F59729175; Tue, 19 Mar 2019 12: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 087ED181A265; Tue, 19 Mar 2019 12:48:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmgmI029242 for ; Tue, 19 Mar 2019 08:48:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id B2C2A5D75C; Tue, 19 Mar 2019 12:48:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C3035D717; Tue, 19 Mar 2019 12:48:41 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:47 +0000 Message-Id: <20190319124700.16722-24-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 23/36] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 19 Mar 2019 12:48:46 +0000 (UTC) Separate network port allocation code from the domain driver network callback implementation. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- 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 534d144464..374416e692 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4346,60 +4346,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 a 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 @@ -4411,7 +4389,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) { @@ -4422,7 +4400,7 @@ networkAllocateActualDevice(virNetworkPtr net, vlan =3D &netdef->vlan; =20 if (vlan && virNetDevVlanCopy(&port->vlan, vlan) < 0) - goto error; + goto cleanup; } =20 if (!port->trustGuestRxFilters) { @@ -4440,7 +4418,7 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->virtPortProfile, portgroup ? portgroup->virtPortProfile : NULL) <= 0) { - goto error; + goto cleanup; } if (portprofile) { VIR_FREE(port->virtPortProfile); @@ -4456,7 +4434,7 @@ networkAllocateActualDevice(virNetworkPtr net, port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE; =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) { @@ -4465,18 +4443,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++) { @@ -4490,7 +4468,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; @@ -4506,7 +4484,7 @@ networkAllocateActualDevice(virNetworkPtr net, "via PCI passthrough"), virNetDevVPortTypeToString(port->virtPortPr= ofile->virtPortType), netdef->name); - goto error; + goto cleanup; } } break; @@ -4520,7 +4498,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) { @@ -4531,12 +4509,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 @@ -4570,7 +4548,7 @@ networkAllocateActualDevice(virNetworkPtr net, "'%s' which uses a macvtap device"), virNetDevVPortTypeToString(port->virtPortPr= ofile->virtPortType), netdef->name); - goto error; + goto cleanup; } } =20 @@ -4582,12 +4560,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 @@ -4622,26 +4600,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, @@ -4666,7 +4644,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 @@ -4677,7 +4655,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++; @@ -4691,28 +4669,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 a 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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999730609777.7953510016057; Tue, 19 Mar 2019 05:48:50 -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 DB15C89C42; Tue, 19 Mar 2019 12:48:48 +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 B1B261001E83; Tue, 19 Mar 2019 12:48:48 +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 729D73D396; Tue, 19 Mar 2019 12:48:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCml9m029292 for ; Tue, 19 Mar 2019 08:48:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9E90C5D71D; Tue, 19 Mar 2019 12:48:47 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EEF15D75D; Tue, 19 Mar 2019 12:48:42 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:48 +0000 Message-Id: <20190319124700.16722-25-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 24/36] 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.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.27]); Tue, 19 Mar 2019 12:48:49 +0000 (UTC) Separate network port notification code from the domain driver network callback implementation. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- 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 374416e692..d953215315 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4727,74 +4727,51 @@ 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 a 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_BRIDGE: /* see if we're connected to the correct bridge */ if (!netdef->bridge) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unexpectedly got a network port plugged into= a 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++) { @@ -4813,7 +4790,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 @@ -4829,14 +4806,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++) { @@ -4858,7 +4835,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 @@ -4874,7 +4851,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; @@ -4882,7 +4859,7 @@ networkNotifyActualDevice(virNetworkPtr net, case VIR_NETWORK_PORT_PLUG_TYPE_LAST: default: virReportEnumRangeError(virNetworkPortPlugType, port->plugtype); - goto error; + goto cleanup; } =20 netdef->connections++; @@ -4895,18 +4872,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 a 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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999733160428.0255477642919; Tue, 19 Mar 2019 05:48:53 -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 5BA673092644; Tue, 19 Mar 2019 12:48:51 +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 3404A5D773; Tue, 19 Mar 2019 12:48:51 +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 D4EF7181A266; Tue, 19 Mar 2019 12:48:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmnTw029309 for ; Tue, 19 Mar 2019 08:48:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2CBCE5D763; Tue, 19 Mar 2019 12:48:49 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05CB85D717; Tue, 19 Mar 2019 12:48:47 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:49 +0000 Message-Id: <20190319124700.16722-26-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 25/36] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 19 Mar 2019 12:48:52 +0000 (UTC) Separate network port deletion code from the domain driver network callback implementation. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 91 ++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index d953215315..3c2fcd16e5 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4930,9 +4930,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), @@ -4942,40 +4942,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 a 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) { @@ -5054,7 +5029,7 @@ networkReleaseActualDevice(virNetworkPtr net, goto cleanup; } =20 - virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, dom->name, &iface= ->mac); + virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, port->ownername, = &port->mac); =20 netdef->connections--; if (dev) @@ -5062,7 +5037,59 @@ networkReleaseActualDevice(virNetworkPtr net, /* finally we can call the 'unplugged' hook script if any */ networkRunHook(obj, port, VIR_HOOK_NETWORK_OP_PORT_DELETED, VIR_HOOK_SUBOP_BEGIN); - networkLogAllocation(netdef, dev, &iface->mac, false); + networkLogAllocation(netdef, dev, &port->mac, false); + + 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 a 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; =20 ret =3D 0; cleanup: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999736803378.2560953248976; Tue, 19 Mar 2019 05:48:56 -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 069DB30BC640; Tue, 19 Mar 2019 12:48:55 +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 D412A18BB3; Tue, 19 Mar 2019 12: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 951CE3D399; Tue, 19 Mar 2019 12:48:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmoFm029326 for ; Tue, 19 Mar 2019 08:48:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id B53C25D76B; Tue, 19 Mar 2019 12:48:50 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88C6F5D71D; Tue, 19 Mar 2019 12:48:49 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:50 +0000 Message-Id: <20190319124700.16722-27-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 26/36] 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 19 Mar 2019 12:48:55 +0000 (UTC) Separate network port bandwidth update code from the domain driver network callback implementation. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/network/bridge_driver.c | 115 ++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 50 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 3c2fcd16e5..74dcd0c44a 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -5383,77 +5383,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 a interface for a virtual network")); - return -1; - } - - if (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 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; @@ -5463,34 +5442,70 @@ 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 a interface for a virtual network")); + return -1; + } + + if (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 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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999735378443.28877109499217; Tue, 19 Mar 2019 05: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 AA2563087942; Tue, 19 Mar 2019 12: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 7A0E21001E61; Tue, 19 Mar 2019 12: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 308A3181A26B; Tue, 19 Mar 2019 12:48:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmqR9029342 for ; Tue, 19 Mar 2019 08:48:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 825A45D723; Tue, 19 Mar 2019 12:48:52 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49EDD5D763; Tue, 19 Mar 2019 12:48:50 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:51 +0000 Message-Id: <20190319124700.16722-28-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 27/36] 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 19 Mar 2019 12:48:54 +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 --- 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 | 12 + src/util/virerror.c | 9 + 9 files changed, 734 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 3c19ff5e2e..076903273c 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -322,6 +322,9 @@ typedef enum { VIR_ERR_DEVICE_MISSING =3D 99, /* fail to find the desired devi= ce */ VIR_ERR_INVALID_NWFILTER_BINDING =3D 100, /* invalid nwfilter binding= */ VIR_ERR_NO_NWFILTER_BINDING =3D 101, /* no nwfilter binding */ + VIR_ERR_INVALID_NETWORK_PORT =3D 102, /* invalid network port object */ + VIR_ERR_NETWORK_PORT_EXIST =3D 103, /* the network port already exis= t */ + VIR_ERR_NO_NETWORK_PORT =3D 104, /* network port not found */ =20 # ifdef VIR_ENUM_SENTINELS VIR_ERR_NUMBER_LAST diff --git a/src/datatypes.c b/src/datatypes.c index 9b92d892d5..bd5b1b3e6c 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -39,6 +39,7 @@ virClassPtr virDomainClass; virClassPtr virDomainSnapshotClass; virClassPtr virInterfaceClass; virClassPtr virNetworkClass; +virClassPtr virNetworkPortClass; virClassPtr virNodeDeviceClass; virClassPtr virNWFilterClass; virClassPtr virNWFilterBindingClass; @@ -53,6 +54,7 @@ static void virDomainDispose(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); @@ -89,6 +91,7 @@ virDataTypesOnceInit(void) DECLARE_CLASS(virDomainSnapshot); DECLARE_CLASS(virInterface); DECLARE_CLASS(virNetwork); + DECLARE_CLASS(virNetworkPort); DECLARE_CLASS(virNodeDevice); DECLARE_CLASS(virNWFilter); DECLARE_CLASS(virNWFilterBinding); @@ -385,6 +388,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 12015679f3..3433fe9b60 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -34,6 +34,7 @@ extern virClassPtr virDomainClass; extern virClassPtr virDomainSnapshotClass; extern virClassPtr virInterfaceClass; extern virClassPtr virNetworkClass; +extern virClassPtr virNetworkPortClass; extern virClassPtr virNodeDeviceClass; extern virClassPtr virNWFilterClass; extern virClassPtr virNWFilterBindingClass; @@ -116,6 +117,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); \ @@ -573,6 +601,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: * @@ -717,6 +756,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 43f7f02af3..4017437ab8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1262,6 +1262,7 @@ virGetDomain; virGetDomainSnapshot; virGetInterface; virGetNetwork; +virGetNetworkPort; virGetNodeDevice; virGetNWFilter; virGetNWFilterBinding; @@ -1271,6 +1272,7 @@ virGetStorageVol; virGetStream; virInterfaceClass; virNetworkClass; +virNetworkPortClass; virNewConnectCloseCallbackData; virNodeDeviceClass; virNWFilterClass; diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index dbce3336d5..8fa7c0bf68 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -817,6 +817,18 @@ LIBVIRT_4.10.0 { LIBVIRT_5.2.0 { global: virConnectGetStoragePoolCapabilities; + virNetworkListAllPorts; + virNetworkPortLookupByUUID; + virNetworkPortLookupByUUIDString; + virNetworkPortCreateXML; + virNetworkPortGetNetwork; + virNetworkPortGetParameters; + virNetworkPortGetXMLDesc; + virNetworkPortGetUUID; + virNetworkPortGetUUIDString; + virNetworkPortDelete; + virNetworkPortFree; + virNetworkPortSetParameters; } LIBVIRT_4.10.0; =20 # .... define new API here using predicted next version number .... diff --git a/src/util/virerror.c b/src/util/virerror.c index 91a513160f..ee7ee1c0a6 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -1214,6 +1214,15 @@ const virErrorMsgTuple virErrorMsgStrings[VIR_ERR_NU= MBER_LAST] =3D { [VIR_ERR_NO_NWFILTER_BINDING] =3D { N_("Network filter binding not found"), N_("Network filter binding 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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999737905688.530156156521; Tue, 19 Mar 2019 05:48:57 -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 411C2C057EC5; Tue, 19 Mar 2019 12:48:56 +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 18C67611C2; Tue, 19 Mar 2019 12: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 D14C03D39F; Tue, 19 Mar 2019 12:48:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmsj8029364 for ; Tue, 19 Mar 2019 08:48:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 01E9B5D723; Tue, 19 Mar 2019 12:48:54 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3E685D717; Tue, 19 Mar 2019 12:48:52 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:52 +0000 Message-Id: <20190319124700.16722-29-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 28/36] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 19 Mar 2019 12:48:56 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 --- 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 ce3865b359..c96e4f46e1 100644 --- a/src/access/viraccessperm.h +++ b/src/access/viraccessperm.h @@ -404,6 +404,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 @@ -413,6 +419,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 /** @@ -692,6 +735,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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999739407755.7539587208516; Tue, 19 Mar 2019 05:48:59 -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 997203082E68; Tue, 19 Mar 2019 12: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 6E2C35D76B; Tue, 19 Mar 2019 12: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 263CC2858A; Tue, 19 Mar 2019 12:48:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmuBa029398 for ; Tue, 19 Mar 2019 08:48:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 42F695D717; Tue, 19 Mar 2019 12:48:56 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6995D5D71D; Tue, 19 Mar 2019 12:48:54 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:53 +0000 Message-Id: <20190319124700.16722-30-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 29/36] 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.46]); Tue, 19 Mar 2019 12:48:58 +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..4b23bb10e0 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.2.0 */ + .networkPortLookupByUUID =3D remoteNetworkPortLookupByUUID, /* 5.2.0 */ + .networkPortCreateXML =3D remoteNetworkPortCreateXML, /* 5.2.0 */ + .networkPortGetXMLDesc =3D remoteNetworkPortGetXMLDesc, /* 5.2.0 */ + .networkPortSetParameters =3D remoteNetworkPortSetParameters, /* 5.2.0= */ + .networkPortGetParameters =3D remoteNetworkPortGetParameters, /* 5.2.0= */ + .networkPortDelete =3D remoteNetworkPortDelete, /* 5.2.0 */ }; =20 static virInterfaceDriver interface_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 74be4b37d0..a2eb1cd8c2 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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15529997416841017.9686993864447; Tue, 19 Mar 2019 05:49:01 -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 ED4203087924; Tue, 19 Mar 2019 12:48:59 +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 C8D104D734; Tue, 19 Mar 2019 12:48:59 +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 7B4EA25556; Tue, 19 Mar 2019 12:48:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmv1S029413 for ; Tue, 19 Mar 2019 08:48:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id CBEBF5EE10; Tue, 19 Mar 2019 12:48:57 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id A32B35D717; Tue, 19 Mar 2019 12:48:56 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:54 +0000 Message-Id: <20190319124700.16722-31-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 30/36] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 19 Mar 2019 12:49:00 +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 c4adbb70d0..6ff9e6c5b9 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -442,6 +442,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 2e2e1edafb..991c8ded73 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 9adc63a8fa..6d8ecd5b09 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 @@ -53,6 +53,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) @@ -91,6 +101,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 */ @@ -1434,6 +1473,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, @@ -1525,5 +1898,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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999744126357.2766809793544; Tue, 19 Mar 2019 05:49:04 -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 7F33F308792D; Tue, 19 Mar 2019 12: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 517CB1001E6A; Tue, 19 Mar 2019 12: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 F1D9F181A13C; Tue, 19 Mar 2019 12:49:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCmxHv029435 for ; Tue, 19 Mar 2019 08:48:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 261F45D723; Tue, 19 Mar 2019 12:48:59 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B47C5D75E; Tue, 19 Mar 2019 12:48:57 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:55 +0000 Message-Id: <20190319124700.16722-32-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 31/36] 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.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, 19 Mar 2019 12:49:03 +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 4017437ab8..640ac00d1c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1017,9 +1017,12 @@ virInterfaceObjSetActive; =20 =20 # conf/virnetworkobj.h +virNetworkObjAddPort; virNetworkObjAssignDef; virNetworkObjBridgeInUse; +virNetworkObjDeleteAllPorts; virNetworkObjDeleteConfig; +virNetworkObjDeletePort; virNetworkObjEndAPI; virNetworkObjFindByName; virNetworkObjFindByUUID; @@ -1030,6 +1033,7 @@ virNetworkObjGetFloorSum; virNetworkObjGetMacMap; virNetworkObjGetNewDef; virNetworkObjGetPersistentDef; +virNetworkObjGetPortStatusDir; virNetworkObjGetRadvdPid; virNetworkObjIsActive; virNetworkObjIsAutostart; @@ -1042,9 +1046,11 @@ virNetworkObjListNumOfNetworks; virNetworkObjListPrune; virNetworkObjLoadAllConfigs; virNetworkObjLoadAllState; +virNetworkObjLookupPort; virNetworkObjMacMgrAdd; virNetworkObjMacMgrDel; virNetworkObjNew; +virNetworkObjPortListExport; virNetworkObjRemoveInactive; virNetworkObjReplacePersistentDef; virNetworkObjSaveStatus; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999748021725.2109966194361; Tue, 19 Mar 2019 05:49:08 -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 48AE081106; Tue, 19 Mar 2019 12:49:06 +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 1E3C951F2A; Tue, 19 Mar 2019 12:49:06 +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 C84A3181A26E; Tue, 19 Mar 2019 12:49:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCn0Xm029453 for ; Tue, 19 Mar 2019 08:49:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id D21955D71D; Tue, 19 Mar 2019 12:49:00 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id A57A55D723; Tue, 19 Mar 2019 12:48:59 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:56 +0000 Message-Id: <20190319124700.16722-33-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 32/36] 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 19 Mar 2019 12:49:06 +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 74dcd0c44a..daeedf2995 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2755,6 +2755,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; @@ -3930,6 +3932,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 @@ -5511,6 +5516,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 */ @@ -5535,6 +5928,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.2.0 */ + .networkPortCreateXML =3D networkPortCreateXML, /* 5.2.0 */ + .networkPortGetXMLDesc =3D networkPortGetXMLDesc, /* 5.2.0 */ + .networkPortDelete =3D networkPortDelete, /* 5.2.0 */ + .networkListAllPorts =3D networkListAllPorts, /* 5.2.0 */ + .networkPortGetParameters =3D networkPortGetParameters, /* 5.2.0 */ + .networkPortSetParameters =3D networkPortSetParameters, /* 5.2.0 */ }; =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999747571252.20835965785375; Tue, 19 Mar 2019 05:49:07 -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 D7E0B307D961; Tue, 19 Mar 2019 12:49:05 +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 A3F0A60260; Tue, 19 Mar 2019 12:49:05 +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 509F9181A26B; Tue, 19 Mar 2019 12:49:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCn2qh029473 for ; Tue, 19 Mar 2019 08:49:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C8595D76B; Tue, 19 Mar 2019 12:49:02 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39F725D71D; Tue, 19 Mar 2019 12:49:01 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:57 +0000 Message-Id: <20190319124700.16722-34-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 33/36] 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.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.48]); Tue, 19 Mar 2019 12:49:06 +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 3bb93ab5d7..04f218303a 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 d9362c5ff6..a66bf66839 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1642,6 +1642,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) @@ -1688,6 +1716,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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999749470368.253064077262; Tue, 19 Mar 2019 05: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 B4DD2316891B; Tue, 19 Mar 2019 12:49:07 +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 7E8845ED34; Tue, 19 Mar 2019 12: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 286E924C14; Tue, 19 Mar 2019 12:49:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCn6Pu029529 for ; Tue, 19 Mar 2019 08:49:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2C0DF5D770; Tue, 19 Mar 2019 12:49:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id F34BE5D71D; Tue, 19 Mar 2019 12:49:02 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:58 +0000 Message-Id: <20190319124700.16722-35-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 34/36] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 19 Mar 2019 12:49:08 +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 04f218303a..dbca81e94d 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 a66bf66839..90148ce877 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1676,6 +1676,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, { virLXCDriverPtr driver =3D opaque; virLXCDomainObjPrivatePtr priv; + virLXCDriverConfigPtr cfg =3D virLXCDriverGetConfig(driver); int ret =3D -1; =20 virObjectLock(vm); @@ -1718,6 +1719,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); @@ -1738,6 +1742,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, =20 ret =3D 0; cleanup: + virObjectUnref(cfg); virObjectUnlock(vm); return ret; =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999751860570.1557606846538; Tue, 19 Mar 2019 05:49:11 -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 0FDC3305B887; Tue, 19 Mar 2019 12:49:10 +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 D4FB1291EB; Tue, 19 Mar 2019 12: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 8765024C17; Tue, 19 Mar 2019 12:49:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCn72i029561 for ; Tue, 19 Mar 2019 08:49:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id E1B645D723; Tue, 19 Mar 2019 12:49:07 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87BE55D71D; Tue, 19 Mar 2019 12:49:06 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:59 +0000 Message-Id: <20190319124700.16722-36-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 35/36] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 19 Mar 2019 12:49:10 +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 0e3799061d..192e54764f 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -5299,6 +5299,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 1828e0795b..1e5256332a 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -2586,6 +2586,11 @@ + + + + + =20 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1c0efc018c..fee5df8f40 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11264,6 +11264,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; @@ -11341,6 +11342,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")) { @@ -11564,6 +11567,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); @@ -24806,6 +24816,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) { @@ -25109,6 +25124,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 4c0b3da47d..4df4c51474 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -940,6 +940,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 @@ -947,6 +948,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.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 06:17:48 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999754671909.3687822717346; Tue, 19 Mar 2019 05:49:14 -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 DD2F03007C28; Tue, 19 Mar 2019 12:49:12 +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 B36BA60C1D; Tue, 19 Mar 2019 12:49:12 +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 68E73181A13C; Tue, 19 Mar 2019 12:49:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCnASU029608 for ; Tue, 19 Mar 2019 08:49:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7FFC65D707; Tue, 19 Mar 2019 12:49:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57BB85D71D; Tue, 19 Mar 2019 12:49:08 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:47:00 +0000 Message-Id: <20190319124700.16722-37-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 36/36] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 19 Mar 2019 12:49:13 +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 | 262 ++++++++++++++++++++++++------------ src/conf/domain_conf.h | 26 ---- src/libvirt_private.syms | 1 - src/network/bridge_driver.c | 200 --------------------------- 4 files changed, 178 insertions(+), 311 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fee5df8f40..486638135b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30252,6 +30252,7 @@ virDomainNetDefActualFromNetworkPort(virDomainNetDe= fPtr iface, if (VIR_STRDUP(actual->data.bridge.brname, port->plug.bridge.brname) < 0) goto error; + actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; actual->data.bridge.macTableManager =3D port->plug.bridge.macTable= Manager; break; =20 @@ -30259,10 +30260,12 @@ virDomainNetDefActualFromNetworkPort(virDomainNet= DefPtr iface, if (VIR_STRDUP(actual->data.direct.linkdev, port->plug.direct.linkdev) < 0) goto error; + actual->type =3D VIR_DOMAIN_NET_TYPE_DIRECT; actual->data.direct.mode =3D port->plug.direct.mode; break; =20 case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: + actual->type =3D VIR_DOMAIN_NET_TYPE_HOSTDEV; actual->data.hostdev.def.parent =3D iface; actual->data.hostdev.def.info =3D &iface->info; actual->data.hostdev.def.mode =3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS; @@ -30454,45 +30457,100 @@ virDomainNetDefActualToNetworkPort(virDomainDefP= tr 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) { + virDomainNetType actualType =3D virDomainNetGetActualType(iface); + + /* if we're restarting libvirtd after an upgrade from a version + * that didn't save bridge name in actualNetDef for + * actualType=3D=3Dnetwork, we need to copy it in so that it will = be + * available in all cases + */ + if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + !iface->data.network.actual->data.bridge.brname) { + char *bridge =3D virNetworkGetBridgeName(net); + if (!bridge) + goto cleanup; + VIR_FREE(iface->data.network.actual->data.bridge.brname); + iface->data.network.actual->data.bridge.brname =3D bridge; + } + + /* Older libvirtd uses actualType=3D=3Dnetwork, but we now + * just use actualType=3D=3Dbridge, as nothing needs to + * distinguish the two cases, and this simplifies virt + * drive code */ + if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDG= E; + actualType =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + } + + 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; =20 - ret =3D netAllocate(net, dom, iface); + virNetworkPortDefFree(portdef); + portdef =3D NULL; =20 + if (!(port =3D virNetworkPortCreateXML(net, portxml, flags))) + goto cleanup; + + VIR_FREE(portxml); + + if (!(portxml =3D virNetworkPortGetXMLDesc(port, 0))) + goto deleteport; + + 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 @@ -30500,94 +30558,130 @@ virDomainNetNotifyActualDevice(virConnectPtr con= n, virDomainDefPtr dom, virDomainNetDefPtr iface) { - virDomainNetType actualType =3D virDomainNetGetActualType(iface); - virNetworkPtr net =3D NULL; - - if (!netNotify) - return; - - if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) - return; - - /* if we're restarting libvirtd after an upgrade from a version - * that didn't save bridge name in actualNetDef for - * actualType=3D=3Dnetwork, we need to copy it in so that it will be - * available in all cases - */ - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - !iface->data.network.actual->data.bridge.brname) { - char *bridge =3D virNetworkGetBridgeName(net); - if (!bridge) - goto cleanup; - VIR_FREE(iface->data.network.actual->data.bridge.brname); - iface->data.network.actual->data.bridge.brname =3D bridge; - } - - /* Older libvirtd uses actualType=3D=3Dnetwork, but we now - * just use actualType=3D=3Dbridge, as nothing needs to - * distinguish the two cases, and this simplifies virt - * drive code */ - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - actualType =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + if (!virUUIDIsValid(iface->data.network.portid)) { + if (virDomainNetCreatePort(conn, dom, iface, + VIR_NETWORK_PORT_CREATE_RECLAIM) < 0) + return; } =20 - - if (netNotify(net, dom, iface) < 0) - goto cleanup; - if (virDomainNetGetActualType(iface) =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE= ) { /* * NB: we can't notify the guest of any MTU change anyway, * 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; + + if (virNetworkPortDelete(port, 0) < 0) + goto cleanup; =20 + 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; =20 - return netBandwidthUpdate(iface, newBandwidth); + if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) + goto cleanup; + + if (!(port =3D virNetworkPortLookupByUUID(net, iface->data.network.por= tid))) + goto cleanup; + + 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 4df4c51474..7b1ee33c72 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3531,32 +3531,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 640ac00d1c..3cff1a5c1a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -483,7 +483,6 @@ virDomainNetReleaseActualDevice; virDomainNetRemove; virDomainNetRemoveHostdev; virDomainNetResolveActualType; -virDomainNetSetDeviceImpl; virDomainNetTypeFromString; virDomainNetTypeSharesHostView; virDomainNetTypeToString; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index daeedf2995..5ef5b91581 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4686,52 +4686,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 a 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 @@ -4887,54 +4841,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 a 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 @@ -5050,63 +4956,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 a 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; -} - =20 /** * networkCheckBandwidth: @@ -5474,48 +5323,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 a interface for a virtual network")); - return -1; - } - - if (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 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) @@ -5972,12 +5779,5 @@ networkRegister(void) return -1; if (virRegisterStateDriver(&networkStateDriver) < 0) return -1; - - virDomainNetSetDeviceImpl( - networkAllocateActualDevice, - networkNotifyActualDevice, - networkReleaseActualDevice, - networkBandwidthUpdate); - return 0; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list