]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virnetdevbandwidth: Only clear qdisc for defined directions
authorWesley Hershberger via Devel <devel@lists.libvirt.org>
Thu, 7 May 2026 17:03:15 +0000 (12:03 -0500)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 19 May 2026 11:12:02 +0000 (13:12 +0200)
When virNetDevBandwidthSet is called for a macvtap device in
qemu_command and qemu_hotplug, qemuDomainInterfaceSetDefaultQDisc has
been called already, setting the iface qdisc to 'noqueue'. If the
interface has an inbound-only bandwidth limit, the outgoing qdisc
on the device will be reset to the system default.

<interface type="direct">
  ...
  <bandwidth>
    <inbound average='3125000' peak='3125000'/>
  </bandwidth>
</interface>

This only clears the qdisc on an interface before a bandwidth limit is
actually set.

Closes: https://gitlab.com/libvirt/libvirt/-/work_items/875
Signed-off-by: Wesley Hershberger <wesley.hershberger@canonical.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virnetdevbandwidth.c
tests/virnetdevbandwidthtest.c

index dbceb6293446e2045e79c582a3406fbca8664e2b..81758ecff8c5ba97711b9eef059e6620397a6511 100644 (file)
@@ -287,13 +287,13 @@ virNetDevBandwidthSet(const char *ifname,
         tx = bandwidth->out;
     }
 
-    /* Only if the caller requests, clear everything including root
-     * qdisc and all filters before adding everything.
-     */
-    if (flags & VIR_NETDEV_BANDWIDTH_SET_CLEAR_ALL)
-        virNetDevBandwidthClear(ifname);
-
     if (tx && tx->average) {
+        /* Only if the caller requests, clear the root qdisc and all filters
+         * before adding everything.
+         */
+        if (flags & VIR_NETDEV_BANDWIDTH_SET_CLEAR_ALL)
+            virNetDevBandwidthClearRoot(ifname);
+
         average = g_strdup_printf("%llukbps", tx->average);
         if (tx->peak)
             peak = g_strdup_printf("%llukbps", tx->peak);
@@ -417,6 +417,12 @@ virNetDevBandwidthSet(const char *ifname,
     }
 
     if (rx) {
+        /* Only if the caller requests, clear the ingress qdisc and all
+         * filters before adding everything.
+         */
+        if (flags & VIR_NETDEV_BANDWIDTH_SET_CLEAR_ALL)
+            virNetDevBandwidthClearIngress(ifname);
+
         average = g_strdup_printf("%llukbps", rx->average);
 
         if (rx->burst) {
index 9624da9b96e2b175cccdb07afd508fd6b60fc163..cac7179dc9b896a53b391da6cfcb18d5e8327163 100644 (file)
@@ -146,7 +146,6 @@ mymain(void)
                 "  <inbound average='1024'/>"
                 "</bandwidth>",
                 "tc qdisc del dev eth0 root\n"
-                "tc qdisc del dev eth0 ingress\n"
                 "tc qdisc show dev eth0 handle 1:\n"
                 "tc qdisc add dev eth0 root handle 1: htb default 1\n"
                 "tc class add dev eth0 parent 1: classid 1:1 htb rate 1024kbps quantum 87\n"
@@ -163,7 +162,6 @@ mymain(void)
     DO_TEST_SET("<bandwidth>"
                 "  <outbound average='1024'/>"
                 "</bandwidth>",
-                "tc qdisc del dev eth0 root\n"
                 "tc qdisc del dev eth0 ingress\n"
                 "tc qdisc add dev eth0 ingress\n"
                 "tc filter add dev eth0 parent ffff: protocol all u32 match u32 0 0"
@@ -177,12 +175,12 @@ mymain(void)
                 "  <outbound average='5' peak='6' burst='7'/>"
                 "</bandwidth>",
                 "tc qdisc del dev eth0 root\n"
-                "tc qdisc del dev eth0 ingress\n"
                 "tc qdisc show dev eth0 handle 1:\n"
                 "tc qdisc add dev eth0 root handle 1: htb default 1\n"
                 "tc class add dev eth0 parent 1: classid 1:1 htb rate 1kbps ceil 2kbps burst 4kb quantum 1\n"
                 "tc qdisc add dev eth0 parent 1:1 handle 2: sfq perturb 10\n"
                 "tc filter add dev eth0 parent 1:0 protocol all prio 1 handle 1 fw flowid 1\n"
+                "tc qdisc del dev eth0 ingress\n"
                 "tc qdisc add dev eth0 ingress\n"
                 "tc filter add dev eth0 parent ffff: protocol all u32 match u32 0 0"
                    " police rate 5kbps burst 7kb mtu 64kb drop flowid :1\n",
@@ -200,12 +198,12 @@ mymain(void)
                 "  <outbound average='4294967295'/>"
                 "</bandwidth>",
                 "tc qdisc del dev eth0 root\n"
-                "tc qdisc del dev eth0 ingress\n"
                 "tc qdisc show dev eth0 handle 1:\n"
                 "tc qdisc add dev eth0 root handle 1: htb default 1\n"
                 "tc class add dev eth0 parent 1: classid 1:1 htb rate 4294967295kbps quantum 366503875\n"
                 "tc qdisc add dev eth0 parent 1:1 handle 2: sfq perturb 10\n"
                 "tc filter add dev eth0 parent 1:0 protocol all prio 1 handle 1 fw flowid 1\n"
+                "tc qdisc del dev eth0 ingress\n"
                 "tc qdisc add dev eth0 ingress\n"
                 "tc filter add dev eth0 parent ffff: protocol all u32 match"
                    " u32 0 0 police rate 4294967295kbps burst 4194303kb mtu 64kb"