Stephen Hemminger
2007-Sep-26 08:37 UTC
[Bridge] Re: [PATCH] Module use count must be updated as bridges are created/destroyed
On Wed, 26 Sep 2007 08:53:27 +0100 "Jan Beulich" <jbeulich@novell.com> wrote:> Otherwise 'modprobe -r' on a module having a dependency on bridge will > implicitly unload bridge, bringing down all connectivity that was > using bridges. > > Signed-off-by: Jan Beulich <jbeulich@novell.com> >No, network devices don't do reference counting. What is the dependency? Where is the source of the module interacting with the bridge?
Jan Beulich
2007-Sep-26 13:00 UTC
[Bridge] [PATCH] Module use count must be updated as bridges are created/destroyed
Otherwise 'modprobe -r' on a module having a dependency on bridge will implicitly unload bridge, bringing down all connectivity that was using bridges. Signed-off-by: Jan Beulich <jbeulich@novell.com> net/bridge/br_if.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- linux-2.6.23-rc8/net/bridge/br_if.c 2007-09-26 09:23:54.000000000 +0200 +++ 2.6.23-rc8-bridge-module-get-put/net/bridge/br_if.c 2007-09-25 14:31:01.000000000 +0200 @@ -276,6 +276,11 @@ int br_add_bridge(const char *name) if (!dev) return -ENOMEM; + if (!try_module_get(THIS_MODULE)) { + free_netdev(dev); + return -ENOENT; + } + rtnl_lock(); if (strchr(dev->name, '%')) { ret = dev_alloc_name(dev, dev->name); @@ -294,6 +299,8 @@ int br_add_bridge(const char *name) unregister_netdevice(dev); out: rtnl_unlock(); + if (ret) + module_put(THIS_MODULE); return ret; } @@ -321,6 +328,8 @@ int br_del_bridge(const char *name) del_br(netdev_priv(dev)); rtnl_unlock(); + if (ret == 0) + module_put(THIS_MODULE); return ret; }
Jan Beulich
2007-Sep-27 00:39 UTC
[Bridge] Re: [PATCH] Module use count must be updated as bridges are created/destroyed
>>> Stephen Hemminger <shemminger@linux-foundation.org> 26.09.07 19:12 >>> >On Wed, 26 Sep 2007 17:08:19 +0100 >"Jan Beulich" <jbeulich@novell.com> wrote: > >> >>> Stephen Hemminger <shemminger@linux-foundation.org> 26.09.07 17:37 >>> >> >On Wed, 26 Sep 2007 08:53:27 +0100 >> >"Jan Beulich" <jbeulich@novell.com> wrote: >> > >> >> Otherwise 'modprobe -r' on a module having a dependency on bridge will >> >> implicitly unload bridge, bringing down all connectivity that was >> >> using bridges. >> >> >> >> Signed-off-by: Jan Beulich <jbeulich@novell.com> >> >> >> > >> >No, network devices don't do reference counting. >> >What is the dependency? Where is the source of the module interacting >> >with the bridge? >> >> On a Xen system, I loaded and then unloaded ebtable_broute. The unload >> implicitly unloaded bridge, destroying the network. The only way I could see >> to avoid the implicit unload was to bump the reference count on bridge >> creation. Otherwise I would have to ask why bridge has a zero reference >> count despite a bridge being configured. >> >> Jan > >Sounds like a module utilities problem since unloading one module doesn't >normally unload others.I have to disagree here - 'modprobe -r' is specifically unloading all modules the specified one references as long as they have a use count of zero. The difference to other networking modules is that the latter normally don't export symbols, and hence don't have dependent modules (and thus cannot be subject of implicit unloading). Bridge does have dependents, and hence must avoid implicit unloading by managing its use count. Jan