Cannot delete a bridge using 'ip' netlink interface
Subsystems (3)
On a linux 3.1.0-rc9 system using the latest iproute2, i tried creating a bridge and deleting it with an attached interface.
Here is the sequence of steps i tried
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0
The last command hangs with the following kernel messages kernel:unregister_netdevice: waiting for br0 to become free. Usage count = 1
I see the same behavior even if the bridge is brought down before trying to delete the bridge.
brctl delbr fails with an error message if the bridge is up. But it succeeds if the bridge is brought down before doing a delbr even if it has interfaces attached.
Thanks
Sridhar
PATCH 1/1 bridge: fix hang on removal of bridge via netlink
Need to cleanup bridge device timers and ports when being bridge device is being removed via netlink.
This fixes the problem of observed when doing:
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0
which would cause br0 to hang in unregister_netdev because of leftover reference count.
---
Patch is against net-next but should go to net and stable trees since it is an observable hang on 3.0 and later kernels.
net/bridge/br_if.c +5 -4
@@ -160,9 +160,10 @@ static void del_nbp(struct net_bridge_pocall_rcu (&p->rcu, destroy_nbp_rcu); } -/* called with RTNL */ -static void del_br (struct net_bridge *br,struct list_head *head) +/* Delete bridge device */ +void br_dev_delete (struct net_device *dev,struct list_head *head) { +struct net_bridge *br =netdev_priv (dev);struct net_bridge_port *p, *n;list_for_each_entry_safe (p, n, &br->port_list, list) {
@@ -267,7 +268,7 @@ int br_del_bridge(struct net *net, const }else -del_br (netdev_priv (dev),NULL ); +br_dev_delete (dev,NULL );rtnl_unlock ();return ret;
@@ -446,7 +447,7 @@ void __net_exit br_net_exit(struct net *rtnl_lock ();for_each_netdev (net, dev)if (dev->priv_flags &IFF_EBRIDGE ) -del_br (netdev_priv (dev), &list); +br_dev_delete (dev, &list);unregister_netdevice_many (&list);rtnl_unlock ();
net/bridge/br_netlink.c +1 -0
@@ -210,6 +210,7 @@ static struct rtnl_link_ops br_link_ops .priv_size = sizeof(struct net_bridge), .setup = br_dev_setup, .validate = br_validate, + .dellink = br_dev_delete, };int __init br_netlink_init (void )
net/bridge/br_private.h +1 -0
@@ -301,6 +301,7 @@ static inline int br_is_root_bridge(cons/* br_device.c */ extern void br_dev_setup (struct net_device *dev); +extern void br_dev_delete (struct net_device *dev,struct list_head *list);extern netdev_tx_t br_dev_xmit (struct sk_buff *skb,struct net_device *dev);#ifdef CONFIG_NET_POLL_CONTROLLER
Re: [PATCH] bridge: fix hang on removal of bridge via netlink
Quoted 9 lines · Stephen Hemminger
Need to cleanup bridge device timers and ports when being bridge device is being removed via netlink.
This fixes the problem of observed when doing:
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0
Quoted 5 lines
which would cause br0 to hang in
unregister_netdevbecause of leftover reference count.Reported-by Sridhar Samudrala <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>
Quoted 58 lines
---
Patch is against net-next but should go to net and stable trees since it is an observable hang on 3.0 and later kernels.net/bridge/br_if.c +5
-4@@ -160,9 +160,10 @@ static void del_nbp(struct net_bridge_pocall_rcu (&p->rcu, destroy_nbp_rcu); } -/* called with RTNL */ -static void del_br (struct net_bridge *br,struct list_head *head) +/* Delete bridge device */ +void br_dev_delete (struct net_device *dev,struct list_head *head) { +struct net_bridge *br =netdev_priv (dev);struct net_bridge_port *p, *n;list_for_each_entry_safe (p, n, &br->port_list, list) {@@ -267,7 +268,7 @@ int br_del_bridge(struct net *net, const }else -del_br (netdev_priv (dev),NULL ); +br_dev_delete (dev,NULL );rtnl_unlock ();return ret;@@ -446,7 +447,7 @@ void __net_exit br_net_exit(struct net *rtnl_lock ();for_each_netdev (net, dev)if (dev->priv_flags &IFF_EBRIDGE ) -del_br (netdev_priv (dev), &list); +br_dev_delete (dev, &list);unregister_netdevice_many (&list);rtnl_unlock ();net/bridge/br_netlink.c +1
-0@@ -210,6 +210,7 @@ static struct rtnl_link_ops br_link_ops .priv_size = sizeof(struct net_bridge), .setup = br_dev_setup, .validate = br_validate, + .dellink = br_dev_delete, };int __init br_netlink_init (void )net/bridge/br_private.h +1
-0@@ -301,6 +301,7 @@ static inline int br_is_root_bridge(cons/* br_device.c */ extern void br_dev_setup (struct net_device *dev); +extern void br_dev_delete (struct net_device *dev,struct list_head *list);extern netdev_tx_t br_dev_xmit (struct sk_buff *skb,struct net_device *dev);#ifdef CONFIG_NET_POLL_CONTROLLER
Re: [PATCH] bridge: fix hang on removal of bridge via netlink
From: Sridhar Samudrala <[email protected]>
Date: Thu, 06 Oct 2011 16:02:49 -0700
Quoted 10 lines · Stephen Hemminger
Quoted 9 lines
Need to cleanup bridge device timers and ports when being bridge device is being removed via netlink.
This fixes the problem of observed when doing:
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0
Quoted 7 lines
Quoted 5 lines
which would cause br0 to hang in
unregister_netdevbecause of leftover reference count.Reported-by Sridhar Samudrala <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>
Applied to 'net' and queued up for -stable, thanks.
Quoted 11 lines · Sridhar Samudrala
On a linux 3.1.0-rc9 system using the latest iproute2, i tried creating a bridge and deleting it with an attached interface.
Here is the sequence of steps i tried
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0The last command hangs with the following kernel messages kernel:unregister_netdevice: waiting for br0 to become free. Usage count = 1
Note that the same thing happens when one tries to rmmod bridge while it is in use. I'm trying your patch to see if that helps... ;)
/mjt
Quoted 10 lines · Michael Tokarev
Quoted 9 lines · Sridhar Samudrala
On a linux 3.1.0-rc9 system using the latest iproute2, i tried creating a bridge and deleting it with an attached interface.
Here is the sequence of steps i tried
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0
Quoted 5 lines
Quoted 2 lines
The last command hangs with the following kernel messages kernel:unregister_netdevice: waiting for br0 to become free. Usage count = 1
Note that the same thing happens when one tries to rmmod bridge while it is in use. I'm trying your patch to see if that helps... ;)
..And with the patch sent in this thread, bridge module can be removed and inserted again with proper cleanup.
So you can add my
too, if necessary :)
Thanks,
/mjt