hook into netif_set_real_num_tx_queues() to cleanup any shaper
configured on top of the to-be-destroyed TX queues.
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
net/core/dev.c | 2 ++
net/core/dev.h | 4 ++++
net/shaper/shaper.c | 31 +++++++++++++++++++++++++++++++
3 files changed, 37 insertions(+)
diff --git a/net/core/dev.c b/net/core/dev.c
index 8615f16e8456..33629a9d0661 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2948,6 +2948,8 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq)
if (dev->num_tc)
netif_setup_tc(dev, txq);
+ net_shaper_set_real_num_tx_queues(dev, txq);
+
dev_qdisc_change_real_num_tx(dev, txq);
dev->real_num_tx_queues = txq;
diff --git a/net/core/dev.h b/net/core/dev.h
index 13c558874af3..d3ea92949ff3 100644
--- a/net/core/dev.h
+++ b/net/core/dev.h
@@ -37,8 +37,12 @@ void dev_addr_check(struct net_device *dev);
#if IS_ENABLED(CONFIG_NET_SHAPER)
void net_shaper_flush_netdev(struct net_device *dev);
+void net_shaper_set_real_num_tx_queues(struct net_device *dev,
+ unsigned int txq);
#else
static inline void net_shaper_flush_netdev(struct net_device *dev) {}
+static inline void net_shaper_set_real_num_tx_queues(struct net_device *dev,
+ unsigned int txq) {}
#endif
/* sysctls not referred to from outside net/core/ */diff --git a/net/shaper/shaper.c b/net/shaper/shaper.c
index 1255d532b36a..f6f5712d7b3c 100644
--- a/net/shaper/shaper.c
+++ b/net/shaper/shaper.c
@@ -1201,6 +1201,37 @@ void net_shaper_flush_netdev(struct net_device *dev)
net_shaper_flush(&binding);
}
+void net_shaper_set_real_num_tx_queues(struct net_device *dev,
+ unsigned int txq)
+{
+ struct net_shaper_hierarchy *hierarchy;
+ struct net_shaper_binding binding;
+ int i;
+
+ binding.type = NET_SHAPER_BINDING_TYPE_NETDEV;
+ binding.netdev = dev;
+ hierarchy = net_shaper_hierarchy(&binding);
+ if (!hierarchy)
+ return;
+
+ net_shaper_lock(&binding);
+
+ /* Take action only when decreasing the tx queue number. */
+ for (i = txq; i < dev->real_num_tx_queues; ++i) {
+ struct net_shaper_handle handle;
+ struct net_shaper *shaper;
+
+ handle.scope = NET_SHAPER_SCOPE_QUEUE;
+ handle.id = i;
+ shaper = net_shaper_lookup(&binding, &handle);
+ if (!shaper)
+ continue;
+
+ __net_shaper_delete(&binding, shaper, NULL);
+ }
+ net_shaper_unlock(&binding);
+}
+
static int __init shaper_init(void)
{
return genl_register_family(&net_shaper_nl_family);--
2.45.2