[Devel] [PATCH rh7 v2 2/2] ms/net: use net->count to check whether a netns is alive or not

Konstantin Khorenko khorenko at virtuozzo.com
Wed May 27 19:11:52 MSK 2020


From: Andrey Vagin <avagin at openvz.org>

The previous idea was to check whether a net namespace is in
net_exit_list or not. It doesn't work, because net->exit_list is used in
__register_pernet_operations and __unregister_pernet_operations where
all namespaces are added to a temporary list to make cleanup in a error
case, so list_empty(&net->exit_list) always returns false.

Reported-by: Mantas Mikulėnas <grawity at gmail.com>
Fixes: 002d8a1a6c11 ("net: skip genenerating uevents for network namespaces that are exiting")
Signed-off-by: Andrei Vagin <avagin at openvz.org>
Signed-off-by: David S. Miller <davem at davemloft.net>

(cherry picked from commit 91864f5852f9996210fad400cf70fb85af091243)
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 net/core/net-sysfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 52199cb62bd22..18463b0a4a1e4 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -920,7 +920,7 @@ net_rx_queue_update_kobjects(struct net_device *net, int old_num, int new_num)
 	while (--i >= new_num) {
 		struct kobject *kobj = &net->_rx[i].kobj;
 
-		if (!list_empty(&dev_net(net)->exit_list))
+		if (!atomic_read(&dev_net(net)->count))
 			kobj->uevent_suppress = 1;
 
 		kobject_put(kobj);
@@ -1337,7 +1337,7 @@ netdev_queue_update_kobjects(struct net_device *net, int old_num, int new_num)
 	while (--i >= new_num) {
 		struct netdev_queue *queue = net->_tx + i;
 
-		if (!list_empty(&dev_net(net)->exit_list))
+		if (!atomic_read(&dev_net(net)->count))
 			queue->kobj.uevent_suppress = 1;
 #ifdef CONFIG_BQL
 		sysfs_remove_group(&queue->kobj, &dql_group);
@@ -1497,7 +1497,7 @@ void netdev_unregister_kobject(struct net_device * net)
 {
 	struct device *dev = &(net->dev);
 
-	if (!list_empty(&dev_net(net)->exit_list))
+	if (!atomic_read(&dev_net(net)->count))
 		dev_set_uevent_suppress(dev, 1);
 
 	kobject_get(&dev->kobj);
-- 
2.15.1



More information about the Devel mailing list