From nobody Sun Feb 8 16:50:06 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=1557848946; cv=none; d=zoho.com; s=zohoarc; b=gMeAK11gpFSusCm519SlGqzyRQzThlWJC+jWoAgdjmxR50u1gvW85zoRAGqwNeatFQ5bNI9OWmvq2tGR++QNucrrNFRb8lu/KEsg88p3p2aeO5z6iiACSxgRulZaB51v5ZxF5JBTFqYJR0uOUy9bLixSiaALB0a3ATo/Oq002IU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848946; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=S+4FMeINAQOyPBppIGAheh9D5E2sUq8gGDH0VhPVRjs=; b=cv1MfMlEKnaSWQveZGwfgAUNzDOo7b59oh+r8O4m4MbElOEpLjefhsTlHFJuK5UkOtCRf4uJ2Ium+p4BWfY33Dmq/O049kULtkitU2e9XQSZgYQAy8Okp3cxtnRDuza1Mt7gfhCJ0/UW5iWgvdtoJKKjGVY35nO13OlaqBFWHnw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557848946789526.247372995612; Tue, 14 May 2019 08:49:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E929AA404E; Tue, 14 May 2019 15:49:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C451C5D725; Tue, 14 May 2019 15:49:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 81D893FA4C; Tue, 14 May 2019 15:49:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4EFmsWg031850 for ; Tue, 14 May 2019 11:48:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 73FF02B9E4; Tue, 14 May 2019 15:48:54 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id B00B8600C5; Tue, 14 May 2019 15:48:53 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:25 +0100 Message-Id: <20190514154836.6427-14-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v5 13/24] network: introduce networkUpdatePortBandwidth X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 14 May 2019 15:49:05 +0000 (UTC) Separate network port bandwidth update code from the domain driver network callback implementation. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 117 ++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 51 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 8025c4c984..aada1e0316 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -5416,78 +5416,56 @@ networkNetworkObjTaint(virNetworkObjPtr obj, =20 =20 static int -networkBandwidthUpdate(virDomainNetDefPtr iface, - virNetDevBandwidthPtr newBandwidth) +networkUpdatePortBandwidth(virNetworkObjPtr obj, + virMacAddrPtr mac, + unsigned int *class_id, + virNetDevBandwidthPtr oldBandwidth, + virNetDevBandwidthPtr newBandwidth) { virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj =3D NULL; virNetworkDefPtr def; unsigned long long tmp_floor_sum; - virNetDevBandwidthPtr ifaceBand =3D virDomainNetGetActualBandwidth(ifa= ce); unsigned long long new_rate =3D 0; unsigned long long old_floor, new_floor; int plug_ret; - int ret =3D -1; - - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - return -1; - } - - if (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_NETWORK = && - (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_BRIDGE = || - iface->data.network.actual->data.bridge.brname !=3D NULL)) { - /* This is not an interface that's plugged into a bridge. - * We don't care. Thus from our POV bandwidth change is allowed. */ - return 0; - } =20 old_floor =3D new_floor =3D 0; =20 - if (ifaceBand && ifaceBand->in) - old_floor =3D ifaceBand->in->floor; + if (oldBandwidth && oldBandwidth->in) + old_floor =3D oldBandwidth->in->floor; if (newBandwidth && newBandwidth->in) new_floor =3D newBandwidth->in->floor; =20 if (new_floor =3D=3D old_floor) return 0; =20 - obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - iface->data.network.name); - return ret; - } def =3D virNetworkObjGetDef(obj); =20 - if ((plug_ret =3D networkCheckBandwidth(obj, newBandwidth, ifaceBand, - &iface->mac, &new_rate)) < 0) { + if ((plug_ret =3D networkCheckBandwidth(obj, newBandwidth, oldBandwidt= h, + mac, &new_rate)) < 0) { /* helper reported error */ - goto cleanup; + return -1; } =20 if (plug_ret > 0) { /* no QoS needs to be set; claim success */ - ret =3D 0; - goto cleanup; + return 0; } =20 /* Okay, there are three possible scenarios: */ =20 - if (ifaceBand && ifaceBand->in && ifaceBand->in->floor && + if (oldBandwidth && oldBandwidth->in && oldBandwidth->in->floor && newBandwidth->in && newBandwidth->in->floor) { /* Either we just need to update @floor .. */ =20 if (virNetDevBandwidthUpdateRate(def->bridge, - iface->data.network.actual->class= _id, + *class_id, def->bandwidth, newBandwidth->in->floor) < 0) - goto cleanup; + return -1; =20 tmp_floor_sum =3D virNetworkObjGetFloorSum(obj); - tmp_floor_sum -=3D ifaceBand->in->floor; + tmp_floor_sum -=3D oldBandwidth->in->floor; tmp_floor_sum +=3D newBandwidth->in->floor; virNetworkObjSetFloorSum(obj, tmp_floor_sum); new_rate -=3D tmp_floor_sum; @@ -5497,34 +5475,71 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, virNetworkObjSaveStatus(driver->stateDir, obj) < 0) { /* Ouch, rollback */ tmp_floor_sum -=3D newBandwidth->in->floor; - tmp_floor_sum +=3D ifaceBand->in->floor; + tmp_floor_sum +=3D oldBandwidth->in->floor; virNetworkObjSetFloorSum(obj, tmp_floor_sum); =20 ignore_value(virNetDevBandwidthUpdateRate(def->bridge, - iface->data.network.= actual->class_id, + *class_id, def->bandwidth, - ifaceBand->in->floor= )); - goto cleanup; + oldBandwidth->in->fl= oor)); + return -1; } } else if (newBandwidth->in && newBandwidth->in->floor) { /* .. or we need to plug in new .. */ =20 - if (networkPlugBandwidthImpl(obj, &iface->mac, newBandwidth, - iface->data.network.actual ? - &iface->data.network.actual->class_id= : NULL, + if (networkPlugBandwidthImpl(obj, mac, newBandwidth, + class_id, new_rate) < 0) - goto cleanup; + return -1; } else { /* .. or unplug old. */ =20 - if (networkUnplugBandwidth(obj, iface->bandwidth, - iface->data.network.actual ? - &iface->data.network.actual->class_id := NULL) < 0) - goto cleanup; + if (networkUnplugBandwidth(obj, oldBandwidth, class_id) < 0) + return -1; } =20 - ret =3D 0; - cleanup: + return 0; +} + + +static int +networkBandwidthUpdate(virDomainNetDefPtr iface, + virNetDevBandwidthPtr newBandwidth) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virNetworkObjPtr obj =3D NULL; + virNetDevBandwidthPtr oldBandwidth =3D virDomainNetGetActualBandwidth(= iface); + int ret =3D -1; + + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected an interface for a virtual network")); + return -1; + } + + if (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_NETWORK = && + (virDomainNetGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_BRIDGE = || + iface->data.network.actual->data.bridge.brname !=3D NULL)) { + /* This is not an interface that's plugged into a bridge. + * We don't care. Thus from our POV bandwidth change is allowed. */ + return 0; + } + + obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); + if (!obj) { + virReportError(VIR_ERR_NO_NETWORK, + _("no network with matching name '%s'"), + iface->data.network.name); + return ret; + } + + ret =3D networkUpdatePortBandwidth(obj, + &iface->mac, + iface->data.network.actual ? + &iface->data.network.actual->class_id= : NULL, + newBandwidth, + oldBandwidth); + virNetworkObjEndAPI(&obj); return ret; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list