linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] Migrating net/sched to new module interface
@ 2003-01-02 22:50 Kronos
  2003-01-03  5:10 ` Rusty Russell
  0 siblings, 1 reply; 78+ messages in thread
From: Kronos @ 2003-01-02 22:50 UTC (permalink / raw)
  To: linux-kernel; +Cc: kuznet, rusty

Hi,

I'm  working on  net/sched to  convert it  to new  module interface. I'm
going to add a new field  'owner' to struct Qdisc_ops. The init function
of  each module  registers the  callback  functions and  a reference  to
the  module  itself. When a  qdisc  is  created (qdisc_create)  I  check
try_module_get() to see  if I can use the  registered callback functions
and if I can't I return  -ENOSYS. When a qdisc is delete (qdisc_destroy)
I use module_put() to decrement  the refcount. The attacched patch shows
this preliminar work on sch_api.c sch_generic.c.

The   next   step  is   to   update   the  other   schedulers   removing
MOD_{INC,DEC}_USE_COUNT and adding the new 'owner' field.

This work  is based on my  (maybe poor) understanding on  the new module
system, so I'm waiting some feedback before going on.

diff --exclude=diff.exclude -ru linux-2.5.orig/include/net/pkt_sched.h linux-2.5/include/net/pkt_sched.h
--- linux-2.5.orig/include/net/pkt_sched.h	Sun Aug 11 22:07:18 2002
+++ linux-2.5/include/net/pkt_sched.h	Thu Jan  2 22:50:57 2003
@@ -10,6 +10,7 @@
 #include <linux/config.h>
 #include <linux/types.h>
 #include <linux/pkt_sched.h>
+#include <linux/module.h>
 #include <net/pkt_cls.h>
 
 #ifdef CONFIG_X86_TSC
@@ -67,6 +68,8 @@
 	int			(*change)(struct Qdisc *, struct rtattr *arg);
 
 	int			(*dump)(struct Qdisc *, struct sk_buff *);
+	/* Protects callbacks */
+	struct module 		*owner;
 };
 
 extern rwlock_t qdisc_tree_lock;
diff --exclude=diff.exclude -ru linux-2.5.orig/net/sched/sch_api.c linux-2.5/net/sched/sch_api.c
--- linux-2.5.orig/net/sched/sch_api.c	Thu Jan  2 21:55:40 2003
+++ linux-2.5/net/sched/sch_api.c	Thu Jan  2 22:59:26 2003
@@ -409,6 +409,10 @@
 	if (ops == NULL)
 		goto err_out;
 
+	err = -ENOSYS;
+	if (try_module_get(ops->owner) == 0)
+		goto err_module;
+
 	size = sizeof(*sch) + ops->priv_size;
 
 	sch = kmalloc(size, GFP_KERNEL);
@@ -416,12 +420,6 @@
 	if (!sch)
 		goto err_out;
 
-	/* Grrr... Resolve race condition with module unload */
-
-	err = -EINVAL;
-	if (ops != qdisc_lookup_ops(kind))
-		goto err_out;
-
 	memset(sch, 0, size);
 
 	skb_queue_head_init(&sch->q);
@@ -460,6 +458,8 @@
 	}
 
 err_out:
+	module_put(ops->owner);
+err_module:
 	*errp = err;
 	if (sch)
 		kfree(sch);
diff --exclude=diff.exclude -ru linux-2.5.orig/net/sched/sch_generic.c linux-2.5/net/sched/sch_generic.c
--- linux-2.5.orig/net/sched/sch_generic.c	Thu Jan  2 22:41:24 2003
+++ linux-2.5/net/sched/sch_generic.c	Thu Jan  2 23:07:55 2003
@@ -29,6 +29,7 @@
 #include <linux/skbuff.h>
 #include <linux/rtnetlink.h>
 #include <linux/init.h>
+#include <linux/module.h>
 #include <net/sock.h>
 #include <net/pkt_sched.h>
 
@@ -356,6 +357,8 @@
 
 	.init		= pfifo_fast_init,
 	.reset		= pfifo_fast_reset,
+	
+	.owner		= THIS_MODULE,
 };
 
 struct Qdisc * qdisc_create_dflt(struct net_device *dev, struct Qdisc_ops *ops)
@@ -422,6 +425,7 @@
 		ops->reset(qdisc);
 	if (ops->destroy)
 		ops->destroy(qdisc);
+	module_put(ops->owner);
 	if (!(qdisc->flags&TCQ_F_BUILTIN))
 		kfree(qdisc);
 }


ciao,
Luca
-- 
Reply-To: kronos@kronoz.cjb.net
Home: http://kronoz.cjb.net
"Chi parla in tono cortese, ma continua a prepararsi, potra` andare avanti;
 chi parla in tono bellicoso e avanza rapidamente dovra` ritirarsi" 
Sun Tzu -- L'arte della guerra

^ permalink raw reply	[flat|nested] 78+ messages in thread
* Re: [RFC] Is an alternative module interface needed/possible?
@ 2003-02-20 12:09 Adam J. Richter
  2003-02-20 12:46 ` Roman Zippel
  0 siblings, 1 reply; 78+ messages in thread
From: Adam J. Richter @ 2003-02-20 12:09 UTC (permalink / raw)
  To: zippel; +Cc: linux-kernel, rusty, wa

On 2003-02-20, Roman Zippel responded to Werner Almesberger:
>The question is now whether we return an error value or use a callback. 
>When a device is removed, we usually also want to remove all its data 
>structures, on the other hand we can only remove a module when there are 
>no users, so here we return an error value.
>Now I need a bigger example to put this into a context, a nice example is 
>scsi_unregister. It removes among other things procfs entries and these 
>entries have a reference to struct Scsi_Host. As long as scsi_unregister 
>is called from module_exit everything works fine, but a bit searching 
>reveals drivers/usb/storage/usb.c, which create/removes a scsi host when 
>you plug/unplug a storage device (let's ignore other problems here, like 
>it's still mounted).

	The ability to remove a module is generally independent of
whether or not there is any hardware present at that moment for which
the module supplies a driver.  Instead, the determining issue is
whether there are file descriptors open for that driver.

	Of course, if the necessary hardware was never present at any
time when the device driver's module was loaded, then there never will
be any file descriptors open for the device driver.

Adam J. Richter     __     ______________   575 Oroville Road
adam@yggdrasil.com     \ /                  Milpitas, California 95035
+1 408 309-6081         | g g d r a s i l   United States of America
                         "Free Software For The Rest Of Us."

^ permalink raw reply	[flat|nested] 78+ messages in thread
* Re: [RFC] Is an alternative module interface needed/possible?
@ 2003-02-20 13:51 Adam J. Richter
  2003-02-20 14:06 ` Werner Almesberger
  2003-02-20 15:38 ` Roman Zippel
  0 siblings, 2 replies; 78+ messages in thread
From: Adam J. Richter @ 2003-02-20 13:51 UTC (permalink / raw)
  To: zippel; +Cc: linux-kernel, rusty, wa

On Thu, 20 Feb 2003, Roman Zippel wrote:
>On Thu, 20 Feb 2003, Adam J. Richter wrote:

>> 	The ability to remove a module is generally independent of
>> whether or not there is any hardware present at that moment for which
>> the module supplies a driver.  Instead, the determining issue is
>> whether there are file descriptors open for that driver.

>I don't understand, what you're trying to say.
>File descriptors are not the only way to access a driver and the ability 
>to remove a module is only dependent on the number of references to this 
>module.

	You're right.  My second sentence was an oversimplification.
I should have said "software references" rather than file descriptors
to include things like "ifconfig eth0 up" creating a reference,
mounting a block device creating a refernece, etc.  (Perhaps I
should have stated only my first sentence and stopped there.)

	Anyhow, my point is that removing a piece of hardware
does not require that the corresponding module be unloaded
immediately.

Adam J. Richter     __     ______________   575 Oroville Road
adam@yggdrasil.com     \ /                  Milpitas, California 95035
+1 408 309-6081         | g g d r a s i l   United States of America
                         "Free Software For The Rest Of Us."

^ permalink raw reply	[flat|nested] 78+ messages in thread

end of thread, other threads:[~2003-02-27 14:23 UTC | newest]

Thread overview: 78+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-02 22:50 [RFC] Migrating net/sched to new module interface Kronos
2003-01-03  5:10 ` Rusty Russell
2003-01-03  8:37   ` David S. Miller
2003-01-04  6:09     ` Rusty Russell
2003-01-04 16:21       ` Kronos
2003-01-13 22:32   ` kuznet
2003-01-13 23:23     ` Max Krasnyansky
2003-01-14 17:49     ` Kronos
2003-01-15  0:21       ` Roman Zippel
2003-01-15  1:19         ` kuznet
2003-01-15  7:31           ` Werner Almesberger
2003-01-15  8:16             ` Rusty Russell
2003-01-15  9:33               ` Werner Almesberger
2003-01-16  1:12                 ` Rusty Russell
2003-01-16  2:42                   ` Werner Almesberger
2003-01-16  3:31                     ` Rusty Russell
2003-01-16  4:20                       ` Werner Almesberger
2003-01-16  4:25                       ` David S. Miller
2003-01-16  4:49                         ` Werner Almesberger
2003-01-16 16:05                         ` Roman Zippel
2003-01-16 18:15                     ` Roman Zippel
2003-01-16 18:58                       ` Werner Almesberger
2003-01-16 23:53                         ` Roman Zippel
2003-01-17  1:04                           ` Greg KH
2003-01-17  2:27                     ` Rusty Russell
2003-01-17 21:40                       ` Roman Zippel
2003-02-13 23:16                       ` Werner Almesberger
2003-02-14  1:57                         ` Rusty Russell
2003-02-14  3:44                           ` Werner Almesberger
2003-02-14 11:16                           ` Roman Zippel
2003-02-14 12:04                             ` Rusty Russell
2003-02-14 12:49                               ` Roman Zippel
2003-02-17  1:59                                 ` Rusty Russell
2003-02-17 10:53                                   ` Roman Zippel
2003-02-17 23:31                                     ` Rusty Russell
2003-02-18 12:26                                       ` Roman Zippel
2003-02-14 13:21                               ` Roman Zippel
2003-02-14 13:53                                 ` Werner Almesberger
2003-02-14 14:24                                   ` Roman Zippel
2003-02-14 18:30                                     ` Werner Almesberger
2003-02-14 20:09                                       ` Roman Zippel
2003-02-15  0:12                                         ` Werner Almesberger
2003-02-15  0:51                                           ` Roman Zippel
2003-02-15  2:28                                             ` Werner Almesberger
2003-02-15 23:20                                               ` Roman Zippel
2003-02-17 17:04                                                 ` Werner Almesberger
2003-02-17 23:09                                                   ` [RFC] Is an alternative module interface needed/possible? Roman Zippel
2003-02-18  1:18                                                     ` Werner Almesberger
2003-02-18  4:54                                                       ` Rusty Russell
2003-02-18  7:20                                                         ` Werner Almesberger
2003-02-18 12:06                                                           ` Roman Zippel
2003-02-18 14:12                                                             ` Werner Almesberger
2003-02-18 12:45                                                               ` Thomas Molina
2003-02-18 17:22                                                               ` Werner Almesberger
2003-02-19  3:30                                                                 ` Rusty Russell
2003-02-19  4:11                                                                   ` Werner Almesberger
2003-02-19 23:38                                                                     ` Rusty Russell
2003-02-20  9:46                                                                       ` Roman Zippel
2003-02-20  0:40                                                                 ` Roman Zippel
2003-02-20  2:17                                                                   ` Werner Almesberger
2003-02-23 16:02                                                                     ` Roman Zippel
2003-02-26 23:26                                                                       ` Werner Almesberger
2003-02-27 12:34                                                                         ` Roman Zippel
2003-02-27 13:20                                                                           ` Werner Almesberger
2003-02-27 14:33                                                                             ` Roman Zippel
2003-02-23 23:34                                                                 ` Kevin O'Connor
2003-02-24 12:14                                                                   ` Roman Zippel
2003-02-18 12:35                                                           ` Roman Zippel
2003-02-18 14:14                                                             ` Werner Almesberger
2003-02-19  1:48                                                       ` Roman Zippel
2003-02-19  2:27                                                         ` Werner Almesberger
2003-01-16 13:44                   ` [RFC] Migrating net/sched to new module interface Roman Zippel
2003-01-15 17:04               ` Roman Zippel
2003-02-20 12:09 [RFC] Is an alternative module interface needed/possible? Adam J. Richter
2003-02-20 12:46 ` Roman Zippel
2003-02-20 13:51 Adam J. Richter
2003-02-20 14:06 ` Werner Almesberger
2003-02-20 15:38 ` Roman Zippel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).