Keith Owens wrote: > > On Wed, 18 Oct 2000 00:42:54 -0400, > Paul Gortmaker <p_gortmaker@yahoo.com> wrote: > >As an alternative to sprinkling MOD_DEC_USE_COUNT throughout the failure > >paths of each net driver init sequence, maybe we should get the module use > >counters out of the drivers entirely. The driver source(s) look cleaner > > IOW, exactly what AL Viro did for VFS. erm, guys. We went through all this in June. Please read the 100 posting thread at http://www.wcug.wwu.edu/lists/netdev/200006/threads.html#00254 Subject "modular net drivers" and "modular net drivers take 2". It works just fine and it does not require that the drivers be edited. We can just slot it in and non-edited drivers will show double-inc and double-dec module refcounts. Note that we do _not_ need to do this to fix module removal races - dev_hold() and dev_put() and unregister_netdevice() take care of that. We do need to take care of the 2.2-compatible drivers (acenic, eepro100, others?). Otherwise Jes and Andrey will be after us with a big stick. I covered that at http://www.wcug.wwu.edu/lists/netdev/200006/msg00210.html We also need to work out what's going on with com20020_cs.c, hysdn_net.c, possibly other drivers. I didn't pursue that patch because we ended up working out that Alexey had avoided the module removal race by other means, but it would be a good thing to do. It would be such fun running through drivers/net nailing all those MOD_INC/MOD_DEC things. This is the patch which we ended up with. The open() path logic took a couple of rounds to get right. But it is right. --- linux-2.4.0-test2/include/linux/netdevice.h Sat Jun 24 15:39:47 2000 +++ linux-akpm/include/linux/netdevice.h Thu Jun 29 20:40:25 2000 @@ -136,6 +136,11 @@ struct neigh_parms; struct sk_buff; +/* Centralised module refcounting for netdevices */ +struct module; +#define SET_NETDEVICE_OWNER(dev) \ + do { dev->owner = THIS_MODULE; } while (0) + struct netif_rx_stats { unsigned total; @@ -372,6 +377,9 @@ unsigned char *haddr); int (*neigh_setup)(struct net_device *dev, struct neigh_parms *); int (*accept_fastpath)(struct net_device *, struct dst_entry*); + + /* open/release and usage marking */ + struct module *owner; /* bridge stuff */ struct net_bridge_port *br_port; --- linux-2.4.0-test2/net/core/dev.c Sat Jun 24 15:39:47 2000 +++ linux-akpm/net/core/dev.c Sun Jun 25 20:59:56 2000 @@ -89,6 +89,7 @@ #include <net/profile.h> #include <linux/init.h> #include <linux/kmod.h> +#include <linux/module.h> #if defined(CONFIG_NET_RADIO) || defined(CONFIG_NET_PCMCIA_RADIO) #include <linux/wireless.h> /* Note : will define WIRELESS_EXT */ #endif /* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */ @@ -664,9 +665,19 @@ * Call device private open method */ - if (dev->open) - ret = dev->open(dev); - + if (dev->owner == 0) { + if (dev->open) + ret = dev->open(dev); + } else { + if (try_inc_mod_count(dev->owner)) { + if (dev->open) { + if ((ret = dev->open(dev)) != 0) + __MOD_DEC_USE_COUNT(dev->owner); + } + } else + ret = -ENODEV; + } + /* * If it went open OK then: */ @@ -780,6 +791,13 @@ * Tell people we are down */ notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev); + + /* + * Drop the module refcount + */ + if (dev->owner) { + __MOD_DEC_USE_COUNT(dev->owner); + } return(0); } - : send the line "unsubscribe linux-net" in the body of a message to majordomo@vger.kernel.org