Re: [PATCH 06/11] netpoll: remove dev_name for npinfo

2007-11-19 Thread Stephen Hemminger
On Mon, 19 Nov 2007 19:47:50 -0800 (PST)
David Miller <[EMAIL PROTECTED]> wrote:

> From: Stephen Hemminger <[EMAIL PROTECTED]>
> Date: Sat, 03 Nov 2007 11:43:20 -0700
> 
> > The device name was only in npinfo for netconsole target
> > configuration, so move it to netconsole.  Netconsole only
> > needs the value during config, so no need to do all
> > the device name tracking etc.. 
> > 
> > Make functions for common code for instantiation and 
> > start up.
> > 
> > Signed-off-by: Stephen Hemminger <[EMAIL PROTECTED]>
> 
> Sigh...
> 
>   return -EUNTESTED;
> 
> In netpoll_parse_options() np->dev isn't setup yet, so if you had
> tested this patch you would have gotten an immediate OOPS.

Sorry, I missed the boot up case, I was testing with modprobe
and dyanmic reconfig stuff.  Places that store the name (and then
get confused by renames) are one of the lingering mis-features of
the whole network device infrastructure. 


-- 
Stephen Hemminger <[EMAIL PROTECTED]>
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 06/11] netpoll: remove dev_name for npinfo

2007-11-19 Thread David Miller
From: Stephen Hemminger <[EMAIL PROTECTED]>
Date: Sat, 03 Nov 2007 11:43:20 -0700

> The device name was only in npinfo for netconsole target
> configuration, so move it to netconsole.  Netconsole only
> needs the value during config, so no need to do all
> the device name tracking etc.. 
> 
> Make functions for common code for instantiation and 
> start up.
> 
> Signed-off-by: Stephen Hemminger <[EMAIL PROTECTED]>

Sigh...

return -EUNTESTED;

In netpoll_parse_options() np->dev isn't setup yet, so if you had
tested this patch you would have gotten an immediate OOPS.

That's why it needs the npinfo->dev_name in the first place, because
it has to be parsed in order to even know what device to attach to.
The np->dev usually isn't setup until netpoll_setup() is called.

I appreciate all the work you are doing trying to clean up this beast
but you have to start testing this stuff and audit the transformations
you are making, instead of always relying on me or someone else to do
it for you.

That's why I let these particular patches sit in my inbox for two
weeks, I knew half of them would have bugs and most if not all of them
were totally untested, so I dreaded reviewing them.

I might have to toss some of the rest of these netconsole things
if there are dependencies on this bogus change.
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/11] netpoll: remove dev_name for npinfo

2007-11-03 Thread Stephen Hemminger
The device name was only in npinfo for netconsole target
configuration, so move it to netconsole.  Netconsole only
needs the value during config, so no need to do all
the device name tracking etc.. 

Make functions for common code for instantiation and 
start up.

Signed-off-by: Stephen Hemminger <[EMAIL PROTECTED]>


--- a/drivers/net/netconsole.c  2007-11-03 09:26:27.0 -0700
+++ b/drivers/net/netconsole.c  2007-11-03 10:02:18.0 -0700
@@ -96,6 +96,7 @@ struct netconsole_target {
struct config_item  item;
 #endif
int enabled;
+   chardev_name[IFNAMSIZ];
struct netpoll  np;
 };
 
@@ -157,39 +158,67 @@ static void netconsole_target_put(struct
 
 #endif /* CONFIG_NETCONSOLE_DYNAMIC */
 
+
+
+/*
+ * Allocate and initialize with defaults.
+ * Note that these targets get their config_item fields zeroed-out.
+ */
+static struct netconsole_target *new_target(void)
+{
+   struct netconsole_target *nt;
+
+   nt = kzalloc(sizeof(*nt), GFP_KERNEL);
+   if (nt) {
+   nt->np.name = "netconsole";
+   strlcpy(nt->dev_name, "eth0", IFNAMSIZ);
+   nt->np.local_port = 6665;
+   nt->np.remote_port = ;
+   memset(nt->np.remote_mac, 0xff, ETH_ALEN);
+   }
+
+   return nt;
+}
+
+static int start_target(struct netconsole_target *nt)
+{
+   struct net_device *dev;
+   int err;
+
+   dev = dev_get_by_name(&init_net, nt->dev_name);
+   if (!dev)
+   return -ENODEV;
+
+   err = netpoll_setup(&nt->np, dev);
+   if (err)
+   dev_put(dev);
+   else
+   nt->enabled = 1;
+   return err;
+}
+
+
 /* Allocate new target (from boot/module param) and setup netpoll for it */
 static struct netconsole_target *alloc_param_target(char *target_config)
 {
int err = -ENOMEM;
struct netconsole_target *nt;
 
-   /*
-* Allocate and initialize with defaults.
-* Note that these targets get their config_item fields zeroed-out.
-*/
-   nt = kzalloc(sizeof(*nt), GFP_KERNEL);
+   nt = new_target();
if (!nt) {
printk(KERN_ERR "netconsole: failed to allocate memory\n");
goto fail;
}
 
-   nt->np.name = "netconsole";
-   strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ);
-   nt->np.local_port = 6665;
-   nt->np.remote_port = ;
-   memset(nt->np.remote_mac, 0xff, ETH_ALEN);
-
/* Parse parameters and setup netpoll */
-   err = netpoll_parse_options(&nt->np, target_config);
+   err = netpoll_parse_options(&nt->np, target_config, nt->dev_name);
if (err)
goto fail;
 
-   err = netpoll_setup(&nt->np);
+
+   err = start_target(nt);
if (err)
goto fail;
-
-   nt->enabled = 1;
-
return nt;
 
 fail:
@@ -279,7 +308,8 @@ static ssize_t show_enabled(struct netco
 
 static ssize_t show_dev_name(struct netconsole_target *nt, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%s\n", nt->np.dev_name);
+   return snprintf(buf, PAGE_SIZE, "%s\n",
+   nt->enabled ? nt->np.dev->name : nt->dev_name);
 }
 
 static ssize_t show_local_port(struct netconsole_target *nt, char *buf)
@@ -339,14 +369,13 @@ static ssize_t store_enabled(struct netc
return enabled;
 
if (enabled) {  /* 1 */
-
/*
 * Skip netpoll_parse_options() -- all the attributes are
 * already configured via configfs. Just print them out.
 */
netpoll_print_options(&nt->np);
 
-   err = netpoll_setup(&nt->np);
+   err = start_target(nt);
if (err)
return err;
 
@@ -365,7 +394,7 @@ static ssize_t store_dev_name(struct net
  const char *buf,
  size_t count)
 {
-   size_t len;
+   char *cp;
 
if (nt->enabled) {
printk(KERN_ERR "netconsole: target (%s) is enabled, "
@@ -374,12 +403,12 @@ static ssize_t store_dev_name(struct net
return -EINVAL;
}
 
-   strlcpy(nt->np.dev_name, buf, IFNAMSIZ);
+   strlcpy(nt->dev_name, buf, IFNAMSIZ);
 
/* Get rid of possible trailing newline from echo(1) */
-   len = strnlen(nt->np.dev_name, IFNAMSIZ);
-   if (nt->np.dev_name[len - 1] == '\n')
-   nt->np.dev_name[len - 1] = '\0';
+   cp = strnchr(nt->dev_name, '\n', IFNAMSIZ);
+   if (cp)
+   *cp = '\0';
 
return strnlen(buf, count);
 }
@@ -591,21 +620,7 @@ static struct config_item *make_netconso
unsigned long flags;
struct netconsole_target *nt;
 
-   /*
-* Allocate and initialize with defaults.
-* Target is disabled at creation (enabled == 0).
-*/
-   nt = kzalloc(sizeof(*nt), GFP_KERNEL);
-