6d3351
From ec733f7eb1f88d9d030952c764c1ee635ab9060b Mon Sep 17 00:00:00 2001
6d3351
Message-Id: <ec733f7eb1f88d9d030952c764c1ee635ab9060b@dist-git>
6d3351
From: Martin Kletzander <mkletzan@redhat.com>
6d3351
Date: Fri, 16 Jun 2017 13:45:30 +0200
6d3351
Subject: [PATCH] qemu: Allow live-updates of coalesce settings
6d3351
6d3351
Change the settings from qemuDomainUpdateDeviceLive() as otherwise the
6d3351
call would succeed even though nothing has changed.
6d3351
6d3351
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1414627
6d3351
6d3351
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
6d3351
(cherry picked from commit 307a205e25ad7db7c895c42ab2e8f59f3839c058)
6d3351
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
6d3351
6d3351
 Conflicts:
6d3351
	src/util/virnetdev.c - non-Linux stubs
6d3351
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6d3351
---
6d3351
 src/qemu/qemu_hotplug.c | 13 +++++++
6d3351
 src/util/virnetdev.c    | 93 ++++++++++++++++++++++++++++++++-----------------
6d3351
 src/util/virnetdev.h    |  3 +-
6d3351
 src/util/virnetdevtap.c |  2 +-
6d3351
 4 files changed, 77 insertions(+), 34 deletions(-)
6d3351
6d3351
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
6d3351
index ab23a575d8..fbc9177669 100644
6d3351
--- a/src/qemu/qemu_hotplug.c
6d3351
+++ b/src/qemu/qemu_hotplug.c
6d3351
@@ -3005,6 +3005,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
6d3351
     bool needLinkStateChange = false;
6d3351
     bool needReplaceDevDef = false;
6d3351
     bool needBandwidthSet = false;
6d3351
+    bool needCoalesceChange = false;
6d3351
     int ret = -1;
6d3351
     int changeidx = -1;
6d3351
 
6d3351
@@ -3293,6 +3294,12 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
6d3351
                                  virDomainNetGetActualBandwidth(newdev)))
6d3351
         needBandwidthSet = true;
6d3351
 
6d3351
+    if (!!olddev->coalesce != !!newdev->coalesce ||
6d3351
+        (olddev->coalesce && newdev->coalesce &&
6d3351
+         !memcmp(olddev->coalesce, newdev->coalesce,
6d3351
+                 sizeof(*olddev->coalesce))))
6d3351
+        needCoalesceChange = true;
6d3351
+
6d3351
     /* FINALLY - actually perform the required actions */
6d3351
 
6d3351
     if (needReconnect) {
6d3351
@@ -3328,6 +3335,12 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
6d3351
         needReplaceDevDef = true;
6d3351
     }
6d3351
 
6d3351
+    if (needCoalesceChange) {
6d3351
+        if (virNetDevSetCoalesce(newdev->ifname, newdev->coalesce, true) < 0)
6d3351
+            goto cleanup;
6d3351
+        needReplaceDevDef = true;
6d3351
+    }
6d3351
+
6d3351
     if (needLinkStateChange &&
6d3351
         qemuDomainChangeNetLinkState(driver, vm, olddev, newdev->linkstate) < 0) {
6d3351
         goto cleanup;
6d3351
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
6d3351
index eb97b705e2..2beb39bb60 100644
6d3351
--- a/src/util/virnetdev.c
6d3351
+++ b/src/util/virnetdev.c
6d3351
@@ -3093,7 +3093,8 @@ virNetDevGetEthtoolGFeatures(virBitmapPtr bitmap ATTRIBUTE_UNUSED,
6d3351
 /**
6d3351
  * virNetDevSetCoalesce:
6d3351
  * @ifname: interface name to modify
6d3351
- * @coalesce: Coalesce settings to set and update
6d3351
+ * @coalesce: Coalesce settings to set or update
6d3351
+ * @update: Whether this is an update for existing settings or not
6d3351
  *
6d3351
  * This function sets the various coalesce settings for a given interface
6d3351
  * @ifname and updates them back into @coalesce.
6d3351
@@ -3101,40 +3102,44 @@ virNetDevGetEthtoolGFeatures(virBitmapPtr bitmap ATTRIBUTE_UNUSED,
6d3351
  * Returns 0 in case of success or -1 on failure
6d3351
  */
6d3351
 int virNetDevSetCoalesce(const char *ifname,
6d3351
-                         virNetDevCoalescePtr coalesce)
6d3351
+                         virNetDevCoalescePtr coalesce,
6d3351
+                         bool update)
6d3351
 {
6d3351
     int fd = -1;
6d3351
     int ret = -1;
6d3351
     struct ifreq ifr;
6d3351
     struct ethtool_coalesce coal = {0};
6d3351
 
6d3351
-    if (!coalesce)
6d3351
+    if (!coalesce && !update)
6d3351
         return 0;
6d3351
 
6d3351
-    coal = (struct ethtool_coalesce) {
6d3351
-        .cmd = ETHTOOL_SCOALESCE,
6d3351
-        .rx_max_coalesced_frames = coalesce->rx_max_coalesced_frames,
6d3351
-        .rx_coalesce_usecs_irq = coalesce->rx_coalesce_usecs_irq,
6d3351
-        .rx_max_coalesced_frames_irq = coalesce->rx_max_coalesced_frames_irq,
6d3351
-        .tx_coalesce_usecs = coalesce->tx_coalesce_usecs,
6d3351
-        .tx_max_coalesced_frames = coalesce->tx_max_coalesced_frames,
6d3351
-        .tx_coalesce_usecs_irq = coalesce->tx_coalesce_usecs_irq,
6d3351
-        .tx_max_coalesced_frames_irq = coalesce->tx_max_coalesced_frames_irq,
6d3351
-        .stats_block_coalesce_usecs = coalesce->stats_block_coalesce_usecs,
6d3351
-        .use_adaptive_rx_coalesce = coalesce->use_adaptive_rx_coalesce,
6d3351
-        .use_adaptive_tx_coalesce = coalesce->use_adaptive_tx_coalesce,
6d3351
-        .pkt_rate_low = coalesce->pkt_rate_low,
6d3351
-        .rx_coalesce_usecs_low = coalesce->rx_coalesce_usecs_low,
6d3351
-        .rx_max_coalesced_frames_low = coalesce->rx_max_coalesced_frames_low,
6d3351
-        .tx_coalesce_usecs_low = coalesce->tx_coalesce_usecs_low,
6d3351
-        .tx_max_coalesced_frames_low = coalesce->tx_max_coalesced_frames_low,
6d3351
-        .pkt_rate_high = coalesce->pkt_rate_high,
6d3351
-        .rx_coalesce_usecs_high = coalesce->rx_coalesce_usecs_high,
6d3351
-        .rx_max_coalesced_frames_high = coalesce->rx_max_coalesced_frames_high,
6d3351
-        .tx_coalesce_usecs_high = coalesce->tx_coalesce_usecs_high,
6d3351
-        .tx_max_coalesced_frames_high = coalesce->tx_max_coalesced_frames_high,
6d3351
-        .rate_sample_interval = coalesce->rate_sample_interval,
6d3351
-    };
6d3351
+    if (coalesce) {
6d3351
+        coal = (struct ethtool_coalesce) {
6d3351
+            .rx_max_coalesced_frames = coalesce->rx_max_coalesced_frames,
6d3351
+            .rx_coalesce_usecs_irq = coalesce->rx_coalesce_usecs_irq,
6d3351
+            .rx_max_coalesced_frames_irq = coalesce->rx_max_coalesced_frames_irq,
6d3351
+            .tx_coalesce_usecs = coalesce->tx_coalesce_usecs,
6d3351
+            .tx_max_coalesced_frames = coalesce->tx_max_coalesced_frames,
6d3351
+            .tx_coalesce_usecs_irq = coalesce->tx_coalesce_usecs_irq,
6d3351
+            .tx_max_coalesced_frames_irq = coalesce->tx_max_coalesced_frames_irq,
6d3351
+            .stats_block_coalesce_usecs = coalesce->stats_block_coalesce_usecs,
6d3351
+            .use_adaptive_rx_coalesce = coalesce->use_adaptive_rx_coalesce,
6d3351
+            .use_adaptive_tx_coalesce = coalesce->use_adaptive_tx_coalesce,
6d3351
+            .pkt_rate_low = coalesce->pkt_rate_low,
6d3351
+            .rx_coalesce_usecs_low = coalesce->rx_coalesce_usecs_low,
6d3351
+            .rx_max_coalesced_frames_low = coalesce->rx_max_coalesced_frames_low,
6d3351
+            .tx_coalesce_usecs_low = coalesce->tx_coalesce_usecs_low,
6d3351
+            .tx_max_coalesced_frames_low = coalesce->tx_max_coalesced_frames_low,
6d3351
+            .pkt_rate_high = coalesce->pkt_rate_high,
6d3351
+            .rx_coalesce_usecs_high = coalesce->rx_coalesce_usecs_high,
6d3351
+            .rx_max_coalesced_frames_high = coalesce->rx_max_coalesced_frames_high,
6d3351
+            .tx_coalesce_usecs_high = coalesce->tx_coalesce_usecs_high,
6d3351
+            .tx_max_coalesced_frames_high = coalesce->tx_max_coalesced_frames_high,
6d3351
+            .rate_sample_interval = coalesce->rate_sample_interval,
6d3351
+        };
6d3351
+    }
6d3351
+
6d3351
+    coal.cmd = ETHTOOL_SCOALESCE;
6d3351
 
6d3351
     if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
6d3351
         return -1;
6d3351
@@ -3148,12 +3153,36 @@ int virNetDevSetCoalesce(const char *ifname,
6d3351
         goto cleanup;
6d3351
     }
6d3351
 
6d3351
-    coal = (struct ethtool_coalesce) {
6d3351
-        .cmd = ETHTOOL_GCOALESCE,
6d3351
-    };
6d3351
+    if (coalesce) {
6d3351
+        coal = (struct ethtool_coalesce) {
6d3351
+            .cmd = ETHTOOL_GCOALESCE,
6d3351
+        };
6d3351
 
6d3351
-    /* Don't fail if the update itself fails */
6d3351
-    virNetDevSendEthtoolIoctl(fd, &ifr);
6d3351
+        /* Don't fail if the update itself fails */
6d3351
+        if (virNetDevSendEthtoolIoctl(fd, &ifr) == 0) {
6d3351
+            coalesce->rx_max_coalesced_frames = coal.rx_max_coalesced_frames;
6d3351
+            coalesce->rx_coalesce_usecs_irq = coal.rx_coalesce_usecs_irq;
6d3351
+            coalesce->rx_max_coalesced_frames_irq = coal.rx_max_coalesced_frames_irq;
6d3351
+            coalesce->tx_coalesce_usecs = coal.tx_coalesce_usecs;
6d3351
+            coalesce->tx_max_coalesced_frames = coal.tx_max_coalesced_frames;
6d3351
+            coalesce->tx_coalesce_usecs_irq = coal.tx_coalesce_usecs_irq;
6d3351
+            coalesce->tx_max_coalesced_frames_irq = coal.tx_max_coalesced_frames_irq;
6d3351
+            coalesce->stats_block_coalesce_usecs = coal.stats_block_coalesce_usecs;
6d3351
+            coalesce->use_adaptive_rx_coalesce = coal.use_adaptive_rx_coalesce;
6d3351
+            coalesce->use_adaptive_tx_coalesce = coal.use_adaptive_tx_coalesce;
6d3351
+            coalesce->pkt_rate_low = coal.pkt_rate_low;
6d3351
+            coalesce->rx_coalesce_usecs_low = coal.rx_coalesce_usecs_low;
6d3351
+            coalesce->rx_max_coalesced_frames_low = coal.rx_max_coalesced_frames_low;
6d3351
+            coalesce->tx_coalesce_usecs_low = coal.tx_coalesce_usecs_low;
6d3351
+            coalesce->tx_max_coalesced_frames_low = coal.tx_max_coalesced_frames_low;
6d3351
+            coalesce->pkt_rate_high = coal.pkt_rate_high;
6d3351
+            coalesce->rx_coalesce_usecs_high = coal.rx_coalesce_usecs_high;
6d3351
+            coalesce->rx_max_coalesced_frames_high = coal.rx_max_coalesced_frames_high;
6d3351
+            coalesce->tx_coalesce_usecs_high = coal.tx_coalesce_usecs_high;
6d3351
+            coalesce->tx_max_coalesced_frames_high = coal.tx_max_coalesced_frames_high;
6d3351
+            coalesce->rate_sample_interval = coal.rate_sample_interval;
6d3351
+        }
6d3351
+    }
6d3351
 
6d3351
     ret = 0;
6d3351
  cleanup:
6d3351
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
6d3351
index 97236c170d..c2c09af636 100644
6d3351
--- a/src/util/virnetdev.h
6d3351
+++ b/src/util/virnetdev.h
6d3351
@@ -180,7 +180,8 @@ int virNetDevRestoreMacAddress(const char *linkdev,
6d3351
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
6d3351
 
6d3351
 int virNetDevSetCoalesce(const char *ifname,
6d3351
-                         virNetDevCoalescePtr coalesce)
6d3351
+                         virNetDevCoalescePtr coalesce,
6d3351
+                         bool update)
6d3351
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
6d3351
 
6d3351
 int virNetDevSetMTU(const char *ifname,
6d3351
diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
6d3351
index c8dacfe27b..175dc2bfaa 100644
6d3351
--- a/src/util/virnetdevtap.c
6d3351
+++ b/src/util/virnetdevtap.c
6d3351
@@ -663,7 +663,7 @@ int virNetDevTapCreateInBridgePort(const char *brname,
6d3351
     if (virNetDevSetOnline(*ifname, !!(flags & VIR_NETDEV_TAP_CREATE_IFUP)) < 0)
6d3351
         goto error;
6d3351
 
6d3351
-    if (virNetDevSetCoalesce(*ifname, coalesce) < 0)
6d3351
+    if (virNetDevSetCoalesce(*ifname, coalesce, false) < 0)
6d3351
         goto error;
6d3351
 
6d3351
     return 0;
6d3351
-- 
6d3351
2.13.1
6d3351