Re: [RFC][PATCH -mm take4 3/6] add interface for netconsole using sysfs

2007-04-19 Thread Andrew Morton
On Wed, 18 Apr 2007 21:08:45 +0900 Keiichi KII <[EMAIL PROTECTED]> wrote:

> +static ssize_t store_local_port(struct netconsole_target *nt, const char 
> *buf,
> + size_t count)
> +{
> + spin_lock(&target_list_lock);
> + nt->np.local_port = simple_strtol(buf, NULL, 10);
> + spin_unlock(&target_list_lock);
> +
> + return count;
> +}
> +
> +static ssize_t store_remote_port(struct netconsole_target *nt, const char 
> *buf,
> + size_t count)
> +{
> + spin_lock(&target_list_lock);
> + nt->np.remote_port = simple_strtol(buf, NULL, 10);
> + spin_unlock(&target_list_lock);
> +
> + return count;
> +}

I think that you'll find that the locking in here does nothing useful and
can be removed.


Also, write_msg() can be called from IRQ context, so this lock _must_ be
taken with spin_lock_irq[save] basically everywhere - the code as-is can be
deadlocked.


-
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


[RFC][PATCH -mm take4 3/6] add interface for netconsole using sysfs

2007-04-18 Thread Keiichi KII
From: Keiichi KII <[EMAIL PROTECTED]>

This patch contains the following changes.

create a sysfs entry for netconsole in /sys/class/misc.
This entry has elements related to netconsole as follows.
You can change configuration of netconsole(writable attributes such as IP
address, port number and so on) and check current configuration of netconsole.

-+- /sys/class/misc/
 |-+- netconsole/
   |-+- port1/
   | |--- id  [r--r--r--]  unique port id
   | |--- local_ip[rw-r--r--]  source IP to use, writable
   | |--- local_mac   [r--r--r--]  source MAC address
   | |--- local_port  [rw-r--r--]  source port number for UDP packets, writable
   | |--- remote_ip   [rw-r--r--]  port number for logging agent, writable
   | |--- remote_mac  [rw-r--r--]  MAC address for logging agent, writable
   |  remote_port [rw-r--r--]  IP address for logging agent, writable
   |--- port2/
   |--- port3/
   ...

Signed-off-by: Keiichi KII <[EMAIL PROTECTED]>
Signed-off-by: Takayoshi Kochi <[EMAIL PROTECTED]>
---
Index: mm/drivers/net/netconsole.c
===
--- mm.orig/drivers/net/netconsole.c
+++ mm/drivers/net/netconsole.c
@@ -45,6 +45,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 MODULE_AUTHOR("Maintainer: Matt Mackall <[EMAIL PROTECTED]>");
 MODULE_DESCRIPTION("Console driver for network interfaces");
@@ -67,6 +69,7 @@ static struct netpoll np = {
 #ifdef CONFIG_NETCONSOLE_DYNCON
 struct netconsole_target {
struct list_head list;
+   struct kobject obj;
int id;
struct netpoll np;
 };
@@ -77,6 +80,207 @@ static DEFINE_SPINLOCK(target_list_lock)
 static int add_target(char* target_config);
 static void remove_target(struct netconsole_target *nt);
 static void cleanup_netconsole(void);
+static int setup_target_sysfs(struct netconsole_target *nt);
+
+static int miscdev_configured;
+
+static ssize_t show_id(struct netconsole_target *nt, char *buf)
+{
+   return sprintf(buf, "%d\n", nt->id);
+}
+
+static ssize_t show_local_port(struct netconsole_target *nt, char *buf)
+{
+   return sprintf(buf, "%d\n", nt->np.local_port);
+}
+
+static ssize_t show_remote_port(struct netconsole_target *nt, char *buf)
+{
+   return sprintf(buf, "%d\n", nt->np.remote_port);
+}
+
+static ssize_t show_local_ip(struct netconsole_target *nt, char *buf)
+{
+   return sprintf(buf, "%d.%d.%d.%d\n", HIPQUAD(nt->np.local_ip));
+}
+
+static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf)
+{
+   return sprintf(buf, "%d.%d.%d.%d\n", HIPQUAD(nt->np.remote_ip));
+}
+
+static ssize_t show_local_mac(struct netconsole_target *nt, char *buf)
+{
+   return sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
+  nt->np.local_mac[0], nt->np.local_mac[1],
+  nt->np.local_mac[2], nt->np.local_mac[3],
+  nt->np.local_mac[4], nt->np.local_mac[5]);
+}
+
+static ssize_t show_remote_mac(struct netconsole_target *nt, char *buf)
+{
+   return sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
+  nt->np.remote_mac[0], nt->np.remote_mac[1],
+  nt->np.remote_mac[2], nt->np.remote_mac[3],
+  nt->np.remote_mac[4], nt->np.remote_mac[5]);
+}
+
+static ssize_t store_local_port(struct netconsole_target *nt, const char *buf,
+   size_t count)
+{
+   spin_lock(&target_list_lock);
+   nt->np.local_port = simple_strtol(buf, NULL, 10);
+   spin_unlock(&target_list_lock);
+
+   return count;
+}
+
+static ssize_t store_remote_port(struct netconsole_target *nt, const char *buf,
+   size_t count)
+{
+   spin_lock(&target_list_lock);
+   nt->np.remote_port = simple_strtol(buf, NULL, 10);
+   spin_unlock(&target_list_lock);
+
+   return count;
+}
+
+static ssize_t store_local_ip(struct netconsole_target *nt, const char *buf,
+ size_t count)
+{
+   spin_lock(&target_list_lock);
+   nt->np.local_ip = ntohl(in_aton(buf));
+   spin_unlock(&target_list_lock);
+
+   return count;
+}
+
+static ssize_t store_remote_ip(struct netconsole_target *nt, const char *buf,
+  size_t count)
+{
+   spin_lock(&target_list_lock);
+   nt->np.remote_ip = ntohl(in_aton(buf));
+   spin_unlock(&target_list_lock);
+
+   return count;
+}
+
+static ssize_t store_remote_mac(struct netconsole_target *nt, const char *buf,
+  size_t count)
+{
+   unsigned char input_mac[ETH_ALEN] =
+   {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+   const char *cur = buf;
+   int i = 0;
+
+   input_mac[i++] = simple_strtol(cur, NULL, 16);
+   while ((cur = strchr(cur, ':')) != NULL) {
+   cur++;
+   input_mac[i++] = simple_strtol(cur, NULL, 16);
+   }
+   if (i != ETH_ALEN)
+   return -EINVAL;
+   spin_lock(&targ