[PATCH 1/1] virsh: inherit qos from network definition when attaching an interface

jx8zjs jx8zjs at 126.com
Mon Nov 1 07:52:02 UTC 2021


Fix bug 1826168: bridge type network with ovs bridge can start with Qos
setting which do not take any effect

Resolves:https://bugzilla.redhat.com/show_bug.cgi?id=1826168
Signed-off-by: jx8zjs <jx8zjs at 126.com>
---
 tools/virsh-domain.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 7f3356a536..b809a0e30f 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -32,6 +32,7 @@
 #include "virbitmap.h"
 #include "virbuffer.h"
 #include "conf/domain_conf.h"
+#include "conf/network_conf.h"
 #include "viralloc.h"
 #include "vircommand.h"
 #include "virfile.h"
@@ -907,6 +908,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     g_autofree char *xml = NULL;
     unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+    bool sourceQos = false;
     bool current = vshCommandOptBool(cmd, "current");
     bool config = vshCommandOptBool(cmd, "config");
     bool live = vshCommandOptBool(cmd, "live");
@@ -971,6 +973,32 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
         }
     }
 
+    if (!inboundStr && !outboundStr) {
+        virNetworkPtr network = NULL;
+        virshControl *priv = ctl->privData;
+        g_autofree char *networkDump = NULL;
+        g_autoptr(virNetworkDef) netdef = NULL;
+
+        network = virNetworkLookupByName(priv->conn, source);
+
+        if (network) {
+            networkDump = virNetworkGetXMLDesc(network, VIR_NETWORK_XML_INACTIVE);
+            netdef = virNetworkDefParseString(networkDump, NULL, false);
+            if (netdef->bandwidth) {
+                sourceQos = true;
+                memset(&inbound, 0, sizeof(inbound));
+                inbound = *netdef->bandwidth->in;
+                memset(&outbound, 0, sizeof(outbound));
+                outbound = *netdef->bandwidth->out;
+            }
+        } else {
+            vshDebug(ctl, VSH_ERR_DEBUG, "failed to get network '%s'", source);
+        }
+
+        virObjectUnref(network);
+        virObjectUnref(priv);
+    }
+
     /* Make XML of interface */
     virBufferAsprintf(&buf, "<interface type='%s'", type);
 
@@ -1045,10 +1073,10 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     if (alias != NULL)
         virBufferAsprintf(&buf, "<alias name='%s'/>\n", alias);
 
-    if (inboundStr || outboundStr) {
+    if (inboundStr || outboundStr || sourceQos) {
         virBufferAddLit(&buf, "<bandwidth>\n");
         virBufferAdjustIndent(&buf, 2);
-        if (inboundStr && (inbound.average || inbound.floor)) {
+        if ((inboundStr || sourceQos) && (inbound.average || inbound.floor)) {
             virBufferAddLit(&buf, "<inbound");
             if (inbound.average > 0)
                 virBufferAsprintf(&buf, " average='%llu'", inbound.average);
@@ -1060,7 +1088,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
                 virBufferAsprintf(&buf, " floor='%llu'", inbound.floor);
             virBufferAddLit(&buf, "/>\n");
         }
-        if (outboundStr && outbound.average > 0) {
+        if ((outboundStr || sourceQos) && outbound.average > 0) {
             virBufferAsprintf(&buf, "<outbound average='%llu'", outbound.average);
             if (outbound.peak > 0)
                 virBufferAsprintf(&buf, " peak='%llu'", outbound.peak);
-- 
2.30.2.windows.1




More information about the libvir-list mailing list