netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Allow multiple dummy devices again
@ 2003-11-28  0:44 Andi Kleen
  2003-11-28  1:13 ` David S. Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Andi Kleen @ 2003-11-28  0:44 UTC (permalink / raw)
  To: netdev; +Cc: jgarzik


In 2.6 the old trick of copying the dummy module to get multiple dummy
devices doesn't work anymore because the "dummy" device name is embedded
in the module. 

This patch adds a new module option that allows to specify how many
dummy devices you want.

-Andi

diff -u linux/drivers/net/dummy.c-o linux-2.6.0test11-amd64/drivers/net/dummy.c
--- linux/drivers/net/dummy.c-o	2003-09-11 04:12:33.000000000 +0200
+++ linux/drivers/net/dummy.c	2003-11-28 01:40:47.000000000 +0100
@@ -34,6 +34,8 @@
 #include <linux/netdevice.h>
 #include <linux/init.h>
 
+static int numdummies = 1;
+
 static int dummy_xmit(struct sk_buff *skb, struct net_device *dev);
 static struct net_device_stats *dummy_get_stats(struct net_device *dev);
 
@@ -83,10 +85,14 @@
 	return dev->priv;
 }
 
-static struct net_device *dev_dummy;
+static struct net_device **dummies;
 
-static int __init dummy_init_module(void)
+/* Number of dummy devices to be set up by this module. */
+MODULE_PARM(numdummies, "i")
+
+static int __init dummy_init_one(int index)
 {
+	struct net_device *dev_dummy;
 	int err;
 
 	dev_dummy = alloc_netdev(sizeof(struct net_device_stats),
@@ -98,15 +104,40 @@
 	if ((err = register_netdev(dev_dummy))) {
 		kfree(dev_dummy);
 		dev_dummy = NULL;
+	} else {
+		dummies[index] = dev_dummy; 
 	}
+
 	return err;
 }
 
+static void __exit dummy_free_one(int index) 
+{
+	unregister_netdev(dummies[index]);
+	free_netdev(dummies[index]);
+} 
+
+static int __init dummy_init_module(void)
+{ 
+	int i, err = 0;
+	dummies = kmalloc(numdummies * sizeof(void *), GFP_KERNEL); 
+	if (!dummies)
+		return -ENOMEM; 
+	for (i = 0; i < numdummies && !err; i++)
+		err = dummy_init_one(i); 
+	if (err) { 
+		while (--i >= 0)
+			dummy_free_one(i);
+	}
+	return err;
+} 
+
 static void __exit dummy_cleanup_module(void)
 {
-	unregister_netdev(dev_dummy);
-	free_netdev(dev_dummy);
-	dev_dummy = NULL;
+	int i;
+	for (i = 0; i < numdummies; i++) 
+		dummy_free_one(i); 
+	kfree(dummies);	
 }
 
 module_init(dummy_init_module);

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

* Re: [PATCH] Allow multiple dummy devices again
  2003-11-28  0:44 [PATCH] Allow multiple dummy devices again Andi Kleen
@ 2003-11-28  1:13 ` David S. Miller
  2003-11-28  1:33   ` jamal
  0 siblings, 1 reply; 6+ messages in thread
From: David S. Miller @ 2003-11-28  1:13 UTC (permalink / raw)
  To: Andi Kleen; +Cc: netdev, jgarzik

On Fri, 28 Nov 2003 01:44:45 +0100
Andi Kleen <ak@muc.de> wrote:

> In 2.6 the old trick of copying the dummy module to get multiple dummy
> devices doesn't work anymore because the "dummy" device name is embedded
> in the module. 
> 
> This patch adds a new module option that allows to specify how many
> dummy devices you want.

Jeff, FWIW I'm fine with this.

Even though we generally frown upon module options for networking
devices, I think it's wholly appropriate for this case.

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

* Re: [PATCH] Allow multiple dummy devices again
  2003-11-28  1:13 ` David S. Miller
@ 2003-11-28  1:33   ` jamal
  2003-11-28  1:40     ` David S. Miller
  0 siblings, 1 reply; 6+ messages in thread
From: jamal @ 2003-11-28  1:33 UTC (permalink / raw)
  To: David S. Miller; +Cc: Andi Kleen, netdev, jgarzik

On Thu, 2003-11-27 at 20:13, David S. Miller wrote:

> Even though we generally frown upon module options for networking
> devices, I think it's wholly appropriate for this case.

Why not make it also a boot option?

cheers,
jamal

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

* Re: [PATCH] Allow multiple dummy devices again
  2003-11-28  1:33   ` jamal
@ 2003-11-28  1:40     ` David S. Miller
  2003-11-28  7:04       ` Christoph Hellwig
  0 siblings, 1 reply; 6+ messages in thread
From: David S. Miller @ 2003-11-28  1:40 UTC (permalink / raw)
  To: hadi; +Cc: ak, netdev, jgarzik

On 27 Nov 2003 20:33:22 -0500
jamal <hadi@cyberus.ca> wrote:

> On Thu, 2003-11-27 at 20:13, David S. Miller wrote:
> 
> > Even though we generally frown upon module options for networking
> > devices, I think it's wholly appropriate for this case.
> 
> Why not make it also a boot option?

They're one in the same these days.

If the driver is built as a module, you pass the option in with
at modload time, else you pass it in on the kernel command line.

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

* Re: [PATCH] Allow multiple dummy devices again
  2003-11-28  1:40     ` David S. Miller
@ 2003-11-28  7:04       ` Christoph Hellwig
  2003-11-28  8:30         ` David S. Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2003-11-28  7:04 UTC (permalink / raw)
  To: David S. Miller; +Cc: hadi, ak, netdev, jgarzik

On Thu, Nov 27, 2003 at 05:40:12PM -0800, David S. Miller wrote:
> On 27 Nov 2003 20:33:22 -0500
> jamal <hadi@cyberus.ca> wrote:
> 
> > On Thu, 2003-11-27 at 20:13, David S. Miller wrote:
> > 
> > > Even though we generally frown upon module options for networking
> > > devices, I think it's wholly appropriate for this case.
> > 
> > Why not make it also a boot option?
> 
> They're one in the same these days.
> 
> If the driver is built as a module, you pass the option in with
> at modload time, else you pass it in on the kernel command line.

You'd have to use module_param for that, but it appears the driver uses
the deprectated MODULE_PARAM..

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

* Re: [PATCH] Allow multiple dummy devices again
  2003-11-28  7:04       ` Christoph Hellwig
@ 2003-11-28  8:30         ` David S. Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David S. Miller @ 2003-11-28  8:30 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: hadi, ak, netdev, jgarzik

On Fri, 28 Nov 2003 07:04:37 +0000
Christoph Hellwig <hch@infradead.org> wrote:

> You'd have to use module_param for that, but it appears the driver uses
> the deprectated MODULE_PARAM..

Indeed, that should be fixed.  Good catch.

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

end of thread, other threads:[~2003-11-28  8:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-28  0:44 [PATCH] Allow multiple dummy devices again Andi Kleen
2003-11-28  1:13 ` David S. Miller
2003-11-28  1:33   ` jamal
2003-11-28  1:40     ` David S. Miller
2003-11-28  7:04       ` Christoph Hellwig
2003-11-28  8:30         ` David S. Miller

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).