From nobody Sun Feb 8 19:02:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 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