Rusty Russell wrote:
>
> Adding a field to every registerable structure is gross. The
> responsibility for getting modules right should be with the person
> writing the modules. The rules are simple; and people w/o module
> support don't pay the penalty for the extra field everywhere...
I don't think it's _that_ bad, Rusty. And some sort of linkage between
module identity and the drivers which the module offers will, I believe,
need to be provided to unbreak PCMCIA.
I've attached here the current netdevice patch which allows the
MOD_INC/MOD_DEC stuff to be hoisted out of the drivers up into the
calling layer. As we've seen, it's only a partial fix to the race
problems.
To use this, net drivers will have to add a single line
SET_NETDEVICE_OWNER(dev);
within their probe() function, and remove all the current
MOD_INC/MOD_DEC calls. This is an aggregate unbloat.
--- linux-2.4.0-test2/include/linux/netdevice.h Sat Jun 24 15:39:47 2000
+++ linux-akpm/include/linux/netdevice.h Sun Jun 25 21:00:26 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);
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Mon Jun 26 2000 - 21:00:06 EST