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