From nobody Fri Dec 27 00:31:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 173259156287910.021664924110723; Mon, 25 Nov 2024 19:26:02 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2F74C17E8; Mon, 25 Nov 2024 22:26:02 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8061418C8; Mon, 25 Nov 2024 22:25:00 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id A0B5D1364; Mon, 25 Nov 2024 22:24:56 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id B1BC317E1 for ; Mon, 25 Nov 2024 22:24:55 -0500 (EST) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-145-CXB1skarOsmIXnyMphKISg-1; Mon, 25 Nov 2024 22:24:53 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CB5271954128 for ; Tue, 26 Nov 2024 03:24:52 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.88.88]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 96323195DF81; Tue, 26 Nov 2024 03:24:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732591495; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YXnd9gm03MvepqaWvTd649NIaYeeHOnz14nJ/Aum9e8=; b=KgOpOD0MUfDhYMVgf3zaongp0Be9eadtw4g1Gc/iKSwjAA/+HBx13cTdyucCzReXAXPjmn gd5uFkcDdskd1k+hFhO4D0nVBochDtJAtTH29A/b+M1tQzvg+LKJ5zqNERU1H9edKhEOYL g0wWVIbsZP0JVy9wRI7LJzBWZQoP7+k= X-MC-Unique: CXB1skarOsmIXnyMphKISg-1 X-Mimecast-MFC-AGG-ID: CXB1skarOsmIXnyMphKISg From: Laine Stump To: devel@lists.libvirt.org Subject: [PATCH v2 1/6] util: use a single flags arg for virNetDevBandwidthSet(), not multiple bools Date: Mon, 25 Nov 2024 22:24:44 -0500 Message-ID: <20241126032449.912167-2-laine@redhat.com> In-Reply-To: <20241126032449.912167-1-laine@redhat.com> References: <20241126032449.912167-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: wBfsUT6mjhGLjwWjVqz_KdFH8WbM6FZ9rNCIK5Yc69I_1732591492 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 335B3XN3DNRVLCOYLFXMKFJNLXYNCOZE X-Message-ID-Hash: 335B3XN3DNRVLCOYLFXMKFJNLXYNCOZE X-MailFrom: laine@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: egarver@redhat.com, mprivozn@redhat.com, psutter@redhat.com, abologna@redhat.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1732591578778019100 Content-Type: text/plain; charset="utf-8"; x-default="true" Having two bools in the arg list is on the borderline of being confusing to anyone trying to read the code, but we're about to add a 3rd. This patch replaces the two bools with a single flags argument which will instead have one or more bits from virNetDevBandwidthFlags set. Signed-off-by: Laine Stump --- src/lxc/lxc_driver.c | 8 ++++++-- src/lxc/lxc_process.c | 8 ++++++-- src/network/bridge_driver.c | 10 ++++++++-- src/qemu/qemu_command.c | 11 ++++++++--- src/qemu/qemu_driver.c | 29 ++++++++++++++------------- src/qemu/qemu_hotplug.c | 22 +++++++++++++++------ src/util/virnetdevbandwidth.c | 36 ++++++++++++++++++++-------------- src/util/virnetdevbandwidth.h | 11 ++++++++--- tests/virnetdevbandwidthtest.c | 8 +++++++- 9 files changed, 95 insertions(+), 48 deletions(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 0e31e5e4b9..a64cfef1a0 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3570,8 +3570,12 @@ lxcDomainAttachDeviceNetLive(virLXCDriver *driver, actualBandwidth =3D virDomainNetGetActualBandwidth(net); if (actualBandwidth) { if (virNetDevSupportsBandwidth(actualType)) { - if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false, - !virDomainNetTypeSharesHostView(net)= ) < 0) + unsigned int flags =3D 0; + + if (!virDomainNetTypeSharesHostView(net)) + flags |=3D VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED; + + if (virNetDevBandwidthSet(net->ifname, actualBandwidth, flags)= < 0) goto cleanup; } else { VIR_WARN("setting bandwidth on interfaces of " diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 083ab83ec6..7eba7a2c46 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -609,8 +609,12 @@ virLXCProcessSetupInterfaces(virLXCDriver *driver, actualBandwidth =3D virDomainNetGetActualBandwidth(net); if (actualBandwidth) { if (virNetDevSupportsBandwidth(type)) { - if (virNetDevBandwidthSet(net->ifname, actualBandwidth, fa= lse, - !virDomainNetTypeSharesHostView(= net)) < 0) + unsigned int flags =3D 0; + + if (!virDomainNetTypeSharesHostView(net)) + flags |=3D VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED; + + if (virNetDevBandwidthSet(net->ifname, actualBandwidth, fl= ags) < 0) goto cleanup; } else { VIR_WARN("setting bandwidth on interfaces of " diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index d408f17de7..e700a614a9 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2109,8 +2109,11 @@ networkStartNetworkVirtual(virNetworkDriverState *dr= iver, } } =20 - if (virNetDevBandwidthSet(def->bridge, def->bandwidth, true, true) < 0) + if (virNetDevBandwidthSet(def->bridge, def->bandwidth, + VIR_NETDEV_BANDWIDTH_SET_HIERARCHICAL_CLASS + | VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED) < 0)= { goto error; + } =20 return 0; =20 @@ -2190,8 +2193,11 @@ networkStartNetworkBridge(virNetworkObj *obj) * type BRIDGE, is started. On failure, undo anything you've done, * and return -1. On success return 0. */ - if (virNetDevBandwidthSet(def->bridge, def->bandwidth, true, true) < 0) + if (virNetDevBandwidthSet(def->bridge, def->bandwidth, + VIR_NETDEV_BANDWIDTH_SET_HIERARCHICAL_CLASS + | VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED) < 0)= { goto error; + } =20 if (networkStartHandleMACTableManagerMode(obj) < 0) goto error; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f4430275dc..3d0a5dd460 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8694,9 +8694,14 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver, def->uuid, !virDomainNetTypeS= haresHostView(net)) < 0) goto cleanup; - } else if (virNetDevBandwidthSet(net->ifname, actualBandwidth,= false, - !virDomainNetTypeSharesHostVi= ew(net)) < 0) { - goto cleanup; + } else { + unsigned int flags =3D 0; + + if (!virDomainNetTypeSharesHostView(net)) + flags |=3D VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED; + + if (virNetDevBandwidthSet(net->ifname, actualBandwidth, fl= ags) < 0) + goto cleanup; } } else { VIR_WARN("setting bandwidth on interfaces of " diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5b9c55f704..425d583e99 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9938,21 +9938,22 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, virErrorRestore(&orig_err); goto endjob; } - } else if (virNetDevBandwidthSet(net->ifname, newBandwidth, false, - !virDomainNetTypeSharesHostView(n= et)) < 0) { - virErrorPtr orig_err; - - virErrorPreserveLast(&orig_err); - ignore_value(virNetDevBandwidthSet(net->ifname, - net->bandwidth, - false, - !virDomainNetTypeSharesHost= View(net))); - if (net->bandwidth) { - ignore_value(virDomainNetBandwidthUpdate(net, - net->bandwidth)); + } else { + unsigned int bwflags =3D 0; + + if (!virDomainNetTypeSharesHostView(net)) + bwflags |=3D VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED; + + if (virNetDevBandwidthSet(net->ifname, newBandwidth, bwflags) = < 0) { + virErrorPtr orig_err; + + virErrorPreserveLast(&orig_err); + ignore_value(virNetDevBandwidthSet(net->ifname, net->bandw= idth, bwflags)); + if (net->bandwidth) + ignore_value(virDomainNetBandwidthUpdate(net, net->ban= dwidth)); + virErrorRestore(&orig_err); + goto endjob; } - virErrorRestore(&orig_err); - goto endjob; } =20 /* If the old bandwidth was cleared out, restore qdisc. */ diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 55512476e4..b06ae61a44 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1331,9 +1331,14 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver, vm->def->uuid, !virDomainNetTypeS= haresHostView(net)) < 0) goto cleanup; - } else if (virNetDevBandwidthSet(net->ifname, actualBandwidth,= false, - !virDomainNetTypeSharesHostVi= ew(net)) < 0) { - goto cleanup; + } else { + int flags =3D 0; + + if (!virDomainNetTypeSharesHostView(net)) + flags |=3D VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED; + + if (virNetDevBandwidthSet(net->ifname, actualBandwidth, fl= ags) < 0) + goto cleanup; } } else { VIR_WARN("setting bandwidth on interfaces of " @@ -4181,9 +4186,14 @@ qemuDomainChangeNet(virQEMUDriver *driver, vm->def->uuid, !virDomainNetTypeS= haresHostView(newdev)) < 0) goto cleanup; - } else if (virNetDevBandwidthSet(newdev->ifname, newb, false, - !virDomainNetTypeSharesHostVi= ew(newdev)) < 0) { - goto cleanup; + } else { + int flags =3D 0; + + if (!virDomainNetTypeSharesHostView(newdev)) + flags |=3D VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED; + + if (virNetDevBandwidthSet(newdev->ifname, newb, flags) < 0) + goto cleanup; } } else { if (virDomainInterfaceClearQoS(vm->def, olddev) < 0) diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index 2b58c58d3e..1baad849c6 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -173,30 +173,35 @@ virNetDevBandwidthManipulateFilter(const char *ifname, * virNetDevBandwidthSet: * @ifname: on which interface * @bandwidth: rates to set (may be NULL) - * @hierarchical_class: whether to create hierarchical class - * @swapped: true if IN/OUT should be set contrariwise + * @flags: bits indicating certain optional actions * + * This function enables QoS on specified interface * and set given traffic limits for both, incoming - * and outgoing traffic. Any previous setting get - * overwritten. If @hierarchical_class is TRUE, create - * hierarchical class. It is used to guarantee minimal - * throughput ('floor' attribute in NIC). + * and outgoing traffic. + * + * @flags bits and their meanings: + * + * VIR_NETDEV_BANDWIDTH_SET_HIERARCHICAL_CLASS + * whether to create a hierarchical class + * A hiearchical class structure is used to implement a minimal + * throughput guarantee ('floor' attribute in NIC). * - * If @swapped is set, the IN part of @bandwidth is set on - * @ifname's TX, and vice versa. If it is not set, IN is set on - * RX and OUT on TX. This is because for some types of interfaces - * domain and the host live on the same side of the interface (so - * domain's RX/TX is host's RX/TX), and for some it's swapped - * (domain's RX/TX is hosts's TX/RX). + * VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED + * set if IN/OUT should be set backwards from what's indicated in + * the bandwidth, i.e. the IN part of @bandwidth is set on + * @ifname's TX, and the OUT part of @bandwidth is set on + * @ifname's RX. This is needed because for some types of + * interfaces the domain and the host live on the same side of the + * interface (so domain's RX/TX is host's RX/TX), and for some + * it's swapped (domain's RX/TX is hosts's TX/RX). * * Return 0 on success, -1 otherwise. */ int virNetDevBandwidthSet(const char *ifname, const virNetDevBandwidth *bandwidth, - bool hierarchical_class, - bool swapped) + unsigned int flags) { int ret =3D -1; virNetDevBandwidthRate *rx =3D NULL; /* From domain POV */ @@ -205,6 +210,7 @@ virNetDevBandwidthSet(const char *ifname, char *average =3D NULL; char *peak =3D NULL; char *burst =3D NULL; + bool hierarchical_class =3D flags & VIR_NETDEV_BANDWIDTH_SET_HIERARCHI= CAL_CLASS; =20 if (!bandwidth) { /* nothing to be enabled */ @@ -224,7 +230,7 @@ virNetDevBandwidthSet(const char *ifname, return -1; } =20 - if (swapped) { + if (flags & VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED) { rx =3D bandwidth->out; tx =3D bandwidth->in; } else { diff --git a/src/util/virnetdevbandwidth.h b/src/util/virnetdevbandwidth.h index 6d268fb119..414d6c97eb 100644 --- a/src/util/virnetdevbandwidth.h +++ b/src/util/virnetdevbandwidth.h @@ -35,15 +35,20 @@ struct _virNetDevBandwidth { virNetDevBandwidthRate *out; }; =20 -void virNetDevBandwidthFree(virNetDevBandwidth *def); + void virNetDevBandwidthFree(virNetDevBandwidth *def); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetDevBandwidth, virNetDevBandwidthFree); =20 +typedef enum { + VIR_NETDEV_BANDWIDTH_SET_HIERARCHICAL_CLASS =3D (1 << 0), + VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED =3D (1 << 1), +} virNetDevBandwidthSetFlags; + int virNetDevBandwidthSet(const char *ifname, const virNetDevBandwidth *bandwidth, - bool hierarchical_class, - bool swapped) + unsigned int flags) G_GNUC_WARN_UNUSED_RESULT; + int virNetDevBandwidthClear(const char *ifname); int virNetDevBandwidthCopy(virNetDevBandwidth **dest, const virNetDevBandwidth *src) diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c index f7c38faa2e..3a87d876c8 100644 --- a/tests/virnetdevbandwidthtest.c +++ b/tests/virnetdevbandwidthtest.c @@ -82,8 +82,14 @@ testVirNetDevBandwidthSet(const void *data) if (virNetDevOpenvswitchInterfaceSetQos(iface, band, info->uuid, t= rue) < 0) return -1; } else { + int flags =3D (VIR_NETDEV_BANDWIDTH_SET_DIR_SWAPPED); + + if (info->hierarchical_class) + flags |=3D VIR_NETDEV_BANDWIDTH_SET_HIERARCHICAL_CLASS; + exp_cmd =3D info->exp_cmd_tc; - if (virNetDevBandwidthSet(iface, band, info->hierarchical_class, t= rue) < 0) + + if (virNetDevBandwidthSet(iface, band, flags) < 0) return -1; } =20 --=20 2.47.0