]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virnetdev: move virNetDevSetRootQDisc to virnetdevbandwidth
authorPavel Hrdina <phrdina@redhat.com>
Wed, 14 Apr 2021 22:34:48 +0000 (00:34 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 21 Apr 2021 12:19:34 +0000 (14:19 +0200)
The function in question uses "tc" binary so virnetdevbandwidth feels
like better place for it.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/libvirt_private.syms
src/qemu/qemu_domain.c
src/util/virnetdev.c
src/util/virnetdev.h
src/util/virnetdevbandwidth.c
src/util/virnetdevbandwidth.h
tests/qemuxml2argvmock.c

index 34e22d37d660fe5be8517b00e70e0ad1892d1c31..abd3dc4bd1f2a82b2be42c189e7f39e6d7d46dcb 100644 (file)
@@ -2714,7 +2714,6 @@ virNetDevSetOnline;
 virNetDevSetPromiscuous;
 virNetDevSetRcvAllMulti;
 virNetDevSetRcvMulti;
-virNetDevSetRootQDisc;
 virNetDevSetupControl;
 virNetDevSysfsFile;
 virNetDevValidateConfig;
@@ -2728,6 +2727,7 @@ virNetDevBandwidthEqual;
 virNetDevBandwidthFree;
 virNetDevBandwidthPlug;
 virNetDevBandwidthSet;
+virNetDevBandwidthSetRootQDisc;
 virNetDevBandwidthUnplug;
 virNetDevBandwidthUpdateFilter;
 virNetDevBandwidthUpdateRate;
index 2c8ea398405a2c8f8d8c6a9e2df5b185f3aa5840..6e3e3555c7777724fa3a59cdc7ff7192020628d3 100644 (file)
@@ -50,6 +50,7 @@
 #include "domain_event.h"
 #include "domain_validate.h"
 #include "virtime.h"
+#include "virnetdevbandwidth.h"
 #include "virnetdevopenvswitch.h"
 #include "virstoragefile.h"
 #include "storage_source.h"
@@ -11571,7 +11572,7 @@ qemuDomainInterfaceSetDefaultQDisc(virQEMUDriver *driver,
         actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
         actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
         actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
-        if (virNetDevSetRootQDisc(net->ifname, "noqueue") < 0)
+        if (virNetDevBandwidthSetRootQDisc(net->ifname, "noqueue") < 0)
             return -1;
     }
 
index 86abdc2e5b88cbb59b5c88f223cbdfe209c99756..1870f3f875b18d759ab1967186fd980fd2dc8f92 100644 (file)
@@ -3507,52 +3507,6 @@ virNetDevRunEthernetScript(const char *ifname, const char *script)
 }
 
 
-/**
- * virNetDevSetRootQDisc:
- * @ifname: the interface name
- * @qdisc: queueing discipline to set
- *
- * For given interface @ifname set its root queueing discipline
- * to @qdisc. This can be used to replace the default qdisc
- * (usually pfifo_fast or whatever is set in
- * /proc/sys/net/core/default_qdisc) with different qdisc.
- *
- * Returns: 0 on success,
- *         -1 if failed to exec tc (with error reported)
- *         -2 if tc failed (with no error reported)
- */
-int
-virNetDevSetRootQDisc(const char *ifname,
-                      const char *qdisc)
-{
-    g_autoptr(virCommand) cmd = NULL;
-    g_autofree char *outbuf = NULL;
-    g_autofree char *errbuf = NULL;
-    int status;
-
-    /* Ideally, we would have a netlink implementation and just
-     * call it here.  But honestly, I tried and failed miserably.
-     * Fallback to spawning tc. */
-    cmd = virCommandNewArgList(TC, "qdisc", "add", "dev", ifname,
-                               "root", "handle", "0:", qdisc,
-                               NULL);
-
-    virCommandAddEnvString(cmd, "LC_ALL=C");
-    virCommandSetOutputBuffer(cmd, &outbuf);
-    virCommandSetErrorBuffer(cmd, &errbuf);
-
-    if (virCommandRun(cmd, &status) < 0)
-        return -1;
-
-    if (status != 0) {
-        VIR_DEBUG("Setting qdisc failed: output='%s' err='%s'", outbuf, errbuf);
-        return -2;
-    }
-
-    return 0;
-}
-
-
 /**
  * virNetDevReserveName:
  * @name: name of an existing network device
index 1f03d882930487c22712674bf3bdd4a5381607ae..b694f4ac35515acd996d97d7e7f1a577bde844e7 100644 (file)
@@ -333,10 +333,6 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link,
 int virNetDevRunEthernetScript(const char *ifname, const char *script)
     G_GNUC_NO_INLINE;
 
-int virNetDevSetRootQDisc(const char *ifname,
-                          const char *qdisc)
-    G_GNUC_NO_INLINE;
-
 int virNetDevVFInterfaceStats(virPCIDeviceAddress *vfAddr,
                               virDomainInterfaceStatsPtr stats)
 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
index 0fc802b1748b8c4dabe0d2886361be40c9be0222..75fc5607adededc09d5c8ee58d5d58df947e433e 100644 (file)
 #include "vircommand.h"
 #include "viralloc.h"
 #include "virerror.h"
+#include "virlog.h"
 #include "virstring.h"
 #include "virutil.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
+VIR_LOG_INIT("util.netdevbandwidth");
+
 void
 virNetDevBandwidthFree(virNetDevBandwidth *def)
 {
@@ -749,3 +752,50 @@ virNetDevBandwidthUpdateFilter(const char *ifname,
     VIR_FREE(class_id);
     return ret;
 }
+
+
+
+/**
+ * virNetDevBandwidthSetRootQDisc:
+ * @ifname: the interface name
+ * @qdisc: queueing discipline to set
+ *
+ * For given interface @ifname set its root queueing discipline
+ * to @qdisc. This can be used to replace the default qdisc
+ * (usually pfifo_fast or whatever is set in
+ * /proc/sys/net/core/default_qdisc) with different qdisc.
+ *
+ * Returns: 0 on success,
+ *         -1 if failed to exec tc (with error reported)
+ *         -2 if tc failed (with no error reported)
+ */
+int
+virNetDevBandwidthSetRootQDisc(const char *ifname,
+                               const char *qdisc)
+{
+    g_autoptr(virCommand) cmd = NULL;
+    g_autofree char *outbuf = NULL;
+    g_autofree char *errbuf = NULL;
+    int status;
+
+    /* Ideally, we would have a netlink implementation and just
+     * call it here.  But honestly, I tried and failed miserably.
+     * Fallback to spawning tc. */
+    cmd = virCommandNewArgList(TC, "qdisc", "add", "dev", ifname,
+                               "root", "handle", "0:", qdisc,
+                               NULL);
+
+    virCommandAddEnvString(cmd, "LC_ALL=C");
+    virCommandSetOutputBuffer(cmd, &outbuf);
+    virCommandSetErrorBuffer(cmd, &errbuf);
+
+    if (virCommandRun(cmd, &status) < 0)
+        return -1;
+
+    if (status != 0) {
+        VIR_DEBUG("Setting qdisc failed: output='%s' err='%s'", outbuf, errbuf);
+        return -2;
+    }
+
+    return 0;
+}
index 35e26b66f746bed8cd4997730ac017d5ceff3ca2..3d520721f616022b8ddc32d4fdaa0c3039f7b949 100644 (file)
@@ -74,3 +74,7 @@ int virNetDevBandwidthUpdateFilter(const char *ifname,
                                    unsigned int id)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
     G_GNUC_WARN_UNUSED_RESULT;
+
+int virNetDevBandwidthSetRootQDisc(const char *ifname,
+                                   const char *qdisc)
+    G_GNUC_NO_INLINE;
index 9d812bfc2e63ba190d37c5303b6139f5c1c468fe..77a0814c08b6fc812c7ea0df244b5bd0d88c103a 100644 (file)
@@ -25,6 +25,7 @@
 #include "virmock.h"
 #include "virlog.h"
 #include "virnetdev.h"
+#include "virnetdevbandwidth.h"
 #include "virnetdevip.h"
 #include "virnetdevtap.h"
 #include "virnetdevopenvswitch.h"
@@ -277,8 +278,8 @@ qemuBuildTPMOpenBackendFDs(const char *tpmdev G_GNUC_UNUSED,
 
 
 int
-virNetDevSetRootQDisc(const char *ifname G_GNUC_UNUSED,
-                      const char *qdisc G_GNUC_UNUSED)
+virNetDevBandwidthSetRootQDisc(const char *ifname G_GNUC_UNUSED,
+                               const char *qdisc G_GNUC_UNUSED)
 {
     return 0;
 }