]> xenbits.xensource.com Git - libvirt.git/commitdiff
QoS: Set classes and filters in proper direction
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 2 Oct 2017 12:12:44 +0000 (14:12 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 5 Oct 2017 07:16:05 +0000 (09:16 +0200)
Similarly to previous patch, for some types of interface domain
and host are on the same side of RX/TX barrier. In that case, we
need to set up the QoS differently. Well, swapped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/lxc/lxc_driver.c
src/lxc/lxc_process.c
src/network/bridge_driver.c
src/qemu/qemu_command.c
src/qemu/qemu_driver.c
src/qemu/qemu_hotplug.c
src/util/virnetdevbandwidth.c
src/util/virnetdevbandwidth.h
tests/virnetdevbandwidthtest.c

index f0a22ce3eb50bf7fa7381853bb3ce42e848ea7a8..6ad61bdb767027d62abc829ebfbc54064a37a921 100644 (file)
@@ -3981,7 +3981,8 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn,
     actualBandwidth = virDomainNetGetActualBandwidth(net);
     if (actualBandwidth) {
         if (virNetDevSupportBandwidth(actualType)) {
-            if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false) < 0)
+            if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
+                                      !virDomainNetTypeSharesHostView(net)) < 0)
                 goto cleanup;
         } else {
             VIR_WARN("setting bandwidth on interfaces of "
index 05f1dec4c421d0e99c1bf6666c95dab9ad7c887d..efd8a690009032668842d02d5a58953a68b191e6 100644 (file)
@@ -601,7 +601,8 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
         actualBandwidth = virDomainNetGetActualBandwidth(net);
         if (actualBandwidth) {
             if (virNetDevSupportBandwidth(type)) {
-                if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false) < 0)
+                if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
+                                          !virDomainNetTypeSharesHostView(net)) < 0)
                     goto cleanup;
             } else {
                 VIR_WARN("setting bandwidth on interfaces of "
index e8d093a31491ab634518facdfc20146c2910c82f..530d00ff3689ca255ae0419a8ef1e1c8f16ceeed 100644 (file)
@@ -2445,7 +2445,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
         VIR_FORCE_CLOSE(tapfd);
     }
 
-    if (virNetDevBandwidthSet(def->bridge, def->bandwidth, true) < 0)
+    if (virNetDevBandwidthSet(def->bridge, def->bandwidth, true, true) < 0)
         goto err5;
 
     VIR_FREE(macTapIfName);
index 72318672edd66f251f984d483728d3f5c7ef58fe..c9ba9206899d4faa0c86333536af46eeca26f84b 100644 (file)
@@ -8578,7 +8578,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
     actualBandwidth = virDomainNetGetActualBandwidth(net);
     if (actualBandwidth) {
         if (virNetDevSupportBandwidth(actualType)) {
-            if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false) < 0)
+            if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
+                                      !virDomainNetTypeSharesHostView(net)) < 0)
                 goto cleanup;
         } else {
             VIR_WARN("setting bandwidth on interfaces of "
index dcad01a01debdc2d306c937d00e54e301587f691..fd4075814a5c8ddd62c420c22511e483158a9c44 100644 (file)
@@ -11182,11 +11182,13 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
         if (!networkBandwidthChangeAllowed(net, newBandwidth))
             goto endjob;
 
-        if (virNetDevBandwidthSet(net->ifname, newBandwidth, false) < 0 ||
+        if (virNetDevBandwidthSet(net->ifname, newBandwidth, false,
+                                  !virDomainNetTypeSharesHostView(net)) < 0 ||
             networkBandwidthUpdate(net, newBandwidth) < 0) {
             ignore_value(virNetDevBandwidthSet(net->ifname,
                                                net->bandwidth,
-                                               false));
+                                               false,
+                                               !virDomainNetTypeSharesHostView(net)));
             goto endjob;
         }
 
index b77731df08d601c2b080dabbc1eee78166d9fae0..2b9427df1a32a2f78e04fa7194659f923105e7d7 100644 (file)
@@ -1209,7 +1209,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     actualBandwidth = virDomainNetGetActualBandwidth(net);
     if (actualBandwidth) {
         if (virNetDevSupportBandwidth(actualType)) {
-            if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false) < 0)
+            if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
+                                      !virDomainNetTypeSharesHostView(net)) < 0)
                 goto cleanup;
         } else {
             VIR_WARN("setting bandwidth on interfaces of "
@@ -3362,7 +3363,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
     if (needBandwidthSet) {
         if (virNetDevBandwidthSet(newdev->ifname,
                                   virDomainNetGetActualBandwidth(newdev),
-                                  false) < 0)
+                                  false,
+                                  !virDomainNetTypeSharesHostView(newdev)) < 0)
             goto cleanup;
         needReplaceDevDef = true;
     }
index 4e4ac617beb958a6a9961a8e5207429bb0f91f86..9aebe56f40123bc2190d19f5e4173bd31f06c4ca 100644 (file)
@@ -174,6 +174,7 @@ virNetDevBandwidthManipulateFilter(const char *ifname,
  * @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
  *
  * This function enables QoS on specified interface
  * and set given traffic limits for both, incoming
@@ -182,14 +183,23 @@ virNetDevBandwidthManipulateFilter(const char *ifname,
  * hierarchical class. It is used to guarantee minimal
  * throughput ('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).
+ *
  * Return 0 on success, -1 otherwise.
  */
 int
 virNetDevBandwidthSet(const char *ifname,
                       virNetDevBandwidthPtr bandwidth,
-                      bool hierarchical_class)
+                      bool hierarchical_class,
+                      bool swapped)
 {
     int ret = -1;
+    virNetDevBandwidthRatePtr rx = NULL, tx = NULL; /* From domain POV */
     virCommandPtr cmd = NULL;
     char *average = NULL;
     char *peak = NULL;
@@ -215,16 +225,24 @@ virNetDevBandwidthSet(const char *ifname,
         return -1;
     }
 
+    if (swapped) {
+        rx = bandwidth->out;
+        tx = bandwidth->in;
+    } else {
+        rx = bandwidth->in;
+        tx = bandwidth->out;
+    }
+
     virNetDevBandwidthClear(ifname);
 
-    if (bandwidth->in && bandwidth->in->average) {
-        if (virAsprintf(&average, "%llukbps", bandwidth->in->average) < 0)
+    if (tx && tx->average) {
+        if (virAsprintf(&average, "%llukbps", tx->average) < 0)
             goto cleanup;
-        if (bandwidth->in->peak &&
-            (virAsprintf(&peak, "%llukbps", bandwidth->in->peak) < 0))
+        if (tx->peak &&
+            (virAsprintf(&peak, "%llukbps", tx->peak) < 0))
             goto cleanup;
-        if (bandwidth->in->burst &&
-            (virAsprintf(&burst, "%llukb", bandwidth->in->burst) < 0))
+        if (tx->burst &&
+            (virAsprintf(&burst, "%llukb", tx->burst) < 0))
             goto cleanup;
 
         cmd = virCommandNew(TC);
@@ -303,7 +321,7 @@ virNetDevBandwidthSet(const char *ifname,
             virCommandAddArgList(cmd, "class", "add", "dev", ifname, "parent",
                                  "1:", "classid", "1:1", "htb", "rate", average,
                                  "ceil", peak ? peak : average, NULL);
-            virNetDevBandwidthCmdAddOptimalQuantum(cmd, bandwidth->in);
+            virNetDevBandwidthCmdAddOptimalQuantum(cmd, tx);
             if (virCommandRun(cmd, NULL) < 0)
                 goto cleanup;
         }
@@ -319,7 +337,7 @@ virNetDevBandwidthSet(const char *ifname,
         if (burst)
             virCommandAddArgList(cmd, "burst", burst, NULL);
 
-        virNetDevBandwidthCmdAddOptimalQuantum(cmd, bandwidth->in);
+        virNetDevBandwidthCmdAddOptimalQuantum(cmd, tx);
         if (virCommandRun(cmd, NULL) < 0)
             goto cleanup;
 
@@ -347,11 +365,10 @@ virNetDevBandwidthSet(const char *ifname,
         VIR_FREE(burst);
     }
 
-    if (bandwidth->out) {
-        if (virAsprintf(&average, "%llukbps", bandwidth->out->average) < 0)
+    if (rx) {
+        if (virAsprintf(&average, "%llukbps", rx->average) < 0)
             goto cleanup;
-        if (virAsprintf(&burst, "%llukb", bandwidth->out->burst ?
-                        bandwidth->out->burst : bandwidth->out->average) < 0)
+        if (virAsprintf(&burst, "%llukb", rx->burst ? rx->burst : rx->average) < 0)
             goto cleanup;
 
         virCommandFree(cmd);
index 64f35372e484c48ff1a019182b41420943981663..63ac6089704cb7ef92500efa88cae6787b21d309 100644 (file)
@@ -45,7 +45,8 @@ void virNetDevBandwidthFree(virNetDevBandwidthPtr def);
 
 int virNetDevBandwidthSet(const char *ifname,
                           virNetDevBandwidthPtr bandwidth,
-                          bool hierarchical_class)
+                          bool hierarchical_class,
+                          bool swapped)
     ATTRIBUTE_RETURN_CHECK;
 int virNetDevBandwidthClear(const char *ifname);
 int virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest,
index a8f4ab1966590b16322dbfb607656bdb21f23660..2b031d55e67af933131122d35e908dfd89010376 100644 (file)
@@ -81,7 +81,7 @@ testVirNetDevBandwidthSet(const void *data)
 
     virCommandSetDryRun(&buf, NULL, NULL);
 
-    if (virNetDevBandwidthSet(iface, band, info->hierarchical_class) < 0)
+    if (virNetDevBandwidthSet(iface, band, info->hierarchical_class, true) < 0)
         goto cleanup;
 
     if (!(actual_cmd = virBufferContentAndReset(&buf))) {