From nobody Sat Feb 7 15:15:33 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 ARC-Seal: i=1; a=rsa-sha256; t=1558625694; cv=none; d=zoho.com; s=zohoarc; b=PRqdXmeiJrX3altwB+RyYSjTSrGRwmyi7N2ofsVwlw5DR8SRuwKS8ccD87oZTYaOMrGidpKastCwOTJI2zqJ4DkxYlsUEg7yMzLvQZXwU7RAA/9NCeT+fGGjIlXJNO5Pfjy3YBnrN7V0CspaYazfYNsJKk+m7dDqL7C7afpufPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558625694; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=LPCFsqg9u2fI0rPevPQGK8cK8io47IRvG8ZdYVk069s=; b=FEY5HcD56D7GSqTq3/5wJsDWde1O2g3CVGSc/9W9bD4cP0h9KfcsXGcAK2L5e/TiPavUt5CuGfowyvJIThVTSRfLx65a3fdwec8b2dIW5GAhPUrl1F+saO39BHbSTXxYW1dv+QGDVAEvBrMvVhklNwIoEkc7QsbRQozhS3i3D3I= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1558625694725258.3548134835769; Thu, 23 May 2019 08:34:54 -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 CA5878830E; Thu, 23 May 2019 15:34:49 +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 9ECD95B683; Thu, 23 May 2019 15:34: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 4761B1806B1C; Thu, 23 May 2019 15:34:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4NFXZkS006822 for ; Thu, 23 May 2019 11:33:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id A29DD7BE87; Thu, 23 May 2019 15:33:35 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-64.ams2.redhat.com [10.36.112.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8569D6134C; Thu, 23 May 2019 15:33:34 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 23 May 2019 16:32:52 +0100 Message-Id: <20190523153302.28526-14-berrange@redhat.com> In-Reply-To: <20190523153302.28526-1-berrange@redhat.com> References: <20190523153302.28526-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v6 13/23] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 23 May 2019 15:34:50 +0000 (UTC) Separate network port bandwidth update code from the domain driver network callback implementation. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 117 ++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 51 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 41934762d0..3cff96ac2c 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -5409,78 +5409,56 @@ networkNetworkObjTaint(virNetworkObjPtr obj, =20 =20 static int -networkBandwidthUpdate(virDomainNetDefPtr iface, - virNetDevBandwidthPtr newBandwidth) +networkUpdatePortBandwidth(virNetworkObjPtr obj, + virMacAddrPtr mac, + unsigned int *class_id, + virNetDevBandwidthPtr oldBandwidth, + virNetDevBandwidthPtr newBandwidth) { virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj =3D NULL; virNetworkDefPtr def; unsigned long long tmp_floor_sum; - virNetDevBandwidthPtr ifaceBand =3D virDomainNetGetActualBandwidth(ifa= ce); unsigned long long new_rate =3D 0; unsigned long long old_floor, new_floor; int plug_ret; - int ret =3D -1; - - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - return -1; - } - - if (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_NETWORK = && - (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_BRIDGE = || - iface->data.network.actual->data.bridge.brname !=3D NULL)) { - /* This is not an interface that's plugged into a bridge. - * We don't care. Thus from our POV bandwidth change is allowed. */ - return 0; - } =20 old_floor =3D new_floor =3D 0; =20 - if (ifaceBand && ifaceBand->in) - old_floor =3D ifaceBand->in->floor; + if (oldBandwidth && oldBandwidth->in) + old_floor =3D oldBandwidth->in->floor; if (newBandwidth && newBandwidth->in) new_floor =3D newBandwidth->in->floor; =20 if (new_floor =3D=3D old_floor) return 0; =20 - obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - iface->data.network.name); - return ret; - } def =3D virNetworkObjGetDef(obj); =20 - if ((plug_ret =3D networkCheckBandwidth(obj, newBandwidth, ifaceBand, - &iface->mac, &new_rate)) < 0) { + if ((plug_ret =3D networkCheckBandwidth(obj, newBandwidth, oldBandwidt= h, + mac, &new_rate)) < 0) { /* helper reported error */ - goto cleanup; + return -1; } =20 if (plug_ret > 0) { /* no QoS needs to be set; claim success */ - ret =3D 0; - goto cleanup; + return 0; } =20 /* Okay, there are three possible scenarios: */ =20 - if (ifaceBand && ifaceBand->in && ifaceBand->in->floor && + if (oldBandwidth && oldBandwidth->in && oldBandwidth->in->floor && newBandwidth->in && newBandwidth->in->floor) { /* Either we just need to update @floor .. */ =20 if (virNetDevBandwidthUpdateRate(def->bridge, - iface->data.network.actual->class= _id, + *class_id, def->bandwidth, newBandwidth->in->floor) < 0) - goto cleanup; + return -1; =20 tmp_floor_sum =3D virNetworkObjGetFloorSum(obj); - tmp_floor_sum -=3D ifaceBand->in->floor; + tmp_floor_sum -=3D oldBandwidth->in->floor; tmp_floor_sum +=3D newBandwidth->in->floor; virNetworkObjSetFloorSum(obj, tmp_floor_sum); new_rate -=3D tmp_floor_sum; @@ -5490,34 +5468,71 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, virNetworkObjSaveStatus(driver->stateDir, obj) < 0) { /* Ouch, rollback */ tmp_floor_sum -=3D newBandwidth->in->floor; - tmp_floor_sum +=3D ifaceBand->in->floor; + tmp_floor_sum +=3D oldBandwidth->in->floor; virNetworkObjSetFloorSum(obj, tmp_floor_sum); =20 ignore_value(virNetDevBandwidthUpdateRate(def->bridge, - iface->data.network.= actual->class_id, + *class_id, def->bandwidth, - ifaceBand->in->floor= )); - goto cleanup; + oldBandwidth->in->fl= oor)); + return -1; } } else if (newBandwidth->in && newBandwidth->in->floor) { /* .. or we need to plug in new .. */ =20 - if (networkPlugBandwidthImpl(obj, &iface->mac, newBandwidth, - iface->data.network.actual ? - &iface->data.network.actual->class_id= : NULL, + if (networkPlugBandwidthImpl(obj, mac, newBandwidth, + class_id, new_rate) < 0) - goto cleanup; + return -1; } else { /* .. or unplug old. */ =20 - if (networkUnplugBandwidth(obj, iface->bandwidth, - iface->data.network.actual ? - &iface->data.network.actual->class_id := NULL) < 0) - goto cleanup; + if (networkUnplugBandwidth(obj, oldBandwidth, class_id) < 0) + return -1; } =20 - ret =3D 0; - cleanup: + return 0; +} + + +static int +networkBandwidthUpdate(virDomainNetDefPtr iface, + virNetDevBandwidthPtr newBandwidth) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virNetworkObjPtr obj =3D NULL; + virNetDevBandwidthPtr oldBandwidth =3D virDomainNetGetActualBandwidth(= iface); + int ret =3D -1; + + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected an interface for a virtual network")); + return -1; + } + + if (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_NETWORK = && + (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_BRIDGE = || + iface->data.network.actual->data.bridge.brname !=3D NULL)) { + /* This is not an interface that's plugged into a bridge. + * We don't care. Thus from our POV bandwidth change is allowed. */ + return 0; + } + + obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); + if (!obj) { + virReportError(VIR_ERR_NO_NETWORK, + _("no network with matching name '%s'"), + iface->data.network.name); + return ret; + } + + ret =3D networkUpdatePortBandwidth(obj, + &iface->mac, + iface->data.network.actual ? + &iface->data.network.actual->class_id= : NULL, + newBandwidth, + oldBandwidth); + virNetworkObjEndAPI(&obj); return ret; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list