Re: [PATCH] net: use net->count to check whether a netns is alive or not

2017-03-13 Thread David Miller
From: Andrei Vagin 
Date: Sun, 12 Mar 2017 21:36:18 -0700

> 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(>exit_list) always returns false.
> 
> Reported-by: Mantas Mikulėnas 
> Fixes: 002d8a1a6c11 ("net: skip genenerating uevents for network namespaces 
> that are exiting")
> Signed-off-by: Andrei Vagin 

Applied and queued up for -stable, thanks.


[PATCH] net: use net->count to check whether a netns is alive or not

2017-03-12 Thread Andrei Vagin
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(>exit_list) always returns false.

Reported-by: Mantas Mikulėnas 
Fixes: 002d8a1a6c11 ("net: skip genenerating uevents for network namespaces 
that are exiting")
Signed-off-by: Andrei Vagin 
---
 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 b0c04cf..1004418 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -952,7 +952,7 @@ net_rx_queue_update_kobjects(struct net_device *dev, int 
old_num, int new_num)
while (--i >= new_num) {
struct kobject *kobj = >_rx[i].kobj;
 
-   if (!list_empty(_net(dev)->exit_list))
+   if (!atomic_read(_net(dev)->count))
kobj->uevent_suppress = 1;
if (dev->sysfs_rx_queue_group)
sysfs_remove_group(kobj, dev->sysfs_rx_queue_group);
@@ -1370,7 +1370,7 @@ netdev_queue_update_kobjects(struct net_device *dev, int 
old_num, int new_num)
while (--i >= new_num) {
struct netdev_queue *queue = dev->_tx + i;
 
-   if (!list_empty(_net(dev)->exit_list))
+   if (!atomic_read(_net(dev)->count))
queue->kobj.uevent_suppress = 1;
 #ifdef CONFIG_BQL
sysfs_remove_group(>kobj, _group);
@@ -1557,7 +1557,7 @@ void netdev_unregister_kobject(struct net_device *ndev)
 {
struct device *dev = &(ndev->dev);
 
-   if (!list_empty(_net(ndev)->exit_list))
+   if (!atomic_read(_net(ndev)->count))
dev_set_uevent_suppress(dev, 1);
 
kobject_get(>kobj);
-- 
2.9.3