Re: [RFC][PATCH 2.6.19 3/6] add interface for netconsole using sysfs

2006-12-12 Thread Matt Mackall
On Tue, Dec 12, 2006 at 03:34:54PM +0900, Keiichi KII wrote:
> 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
>| |--- remove  [-w---]  if you write something to "remove",
>| | this port is removed.
>| |--- dev_name[r--r--r--]  network interface name
>| |--- local_ip[rw-r--r--]  source IP to use, writable
>| |--- local_port  [rw-r--r--]  source port number for UDP packets, 
> writable
>| |--- local_mac   [r--r--r--]  source MAC address
>| |--- remote_ip   [rw-r--r--]  port number for logging agent, writable
>| |--- remote_port [rw-r--r--]  IP address for logging agent, writable
>|  remote_mac  [rw-r--r--]  MAC address for logging agent, writable
>|--- port2/
>|--- port3/
>...
> 
> Signed-off-by: Keiichi KII <[EMAIL PROTECTED]>
> ---
> --- linux-2.6.19/drivers/net/netconsole.c 2006-12-06 14:37:26.842825500 
> +0900
> +++ enhanced-netconsole/drivers/net/netconsole.c.sysfs2006-12-06
> 13:32:47.488381000 +0900
> @@ -45,6 +45,8 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
> 
>  MODULE_AUTHOR("Maintainer: Matt Mackall <[EMAIL PROTECTED]>");
>  MODULE_DESCRIPTION("Console driver for network interfaces");
> @@ -53,6 +55,7 @@ MODULE_LICENSE("GPL");
>  enum {
>   MAX_PRINT_CHUNK = 1000,
>   MAX_CONFIG_LENGTH = 256,
> + MAC_ADDR_DIGIT = 6,
>  };
> 
>  static char config[MAX_CONFIG_LENGTH];
> @@ -62,19 +65,214 @@ MODULE_PARM_DESC(netconsole, " netconsol
> 
>  struct netconsole_device {
>   struct list_head list;
> + struct kobject obj;
>   spinlock_t netpoll_lock;
>   int id;
>   struct netpoll np;
>  };
> 
> +struct netcon_dev_attr {
> + struct attribute attr;
> + ssize_t (*show)(struct netconsole_device*, char*);
> + ssize_t (*store)(struct netconsole_device*, const char*,
> +  size_t count);
> +};
> +
>  static int add_netcon_dev(const char*);
> +static void setup_netcon_dev_sysfs(struct netconsole_device*);
>  static void cleanup_netconsole(void);
>  static void netcon_dev_cleanup(struct netconsole_device *nd);
> 
> +static int netcon_miscdev_configured = 0;
> +
>  static LIST_HEAD(active_netconsole_dev);
> 
>  static DEFINE_SPINLOCK(netconsole_dev_list_lock);
> 
> +#define SHOW_CLASS_ATTR(field, type, format, ...) \
> +static ssize_t show_##field(type, char *buf) \
> +{ \
> + return sprintf(buf, format, __VA_ARGS__); \
> +} \

I see this sort of thing is pretty common with sysfs stuff.. but yuck.

> +static ssize_t show_netcon_dev_attr(struct kobject *kobj,
> + struct attribute *attr,
> + char *buffer)
> +{
> + struct netcon_dev_attr *na = container_of(attr, struct netcon_dev_attr,
> +   attr);
> + struct netconsole_device * nd =
> + container_of(kobj, struct netconsole_device, obj);
> + if (na->show) {
> + return na->show(nd, buffer);
> + } else {
> + return -EACCES;
> + }

Kernel style is to skip the braces for single statement clauses.

> + if (misc_register(_miscdev)) {
> + printk(KERN_INFO
> +"netconsole: unable netconsole misc device\n");

This error message seems to be missing a word or two.

-- 
Mathematics is the supreme nostalgia of our time.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH 2.6.19 3/6] add interface for netconsole using sysfs

2006-12-12 Thread Matt Mackall
On Tue, Dec 12, 2006 at 03:34:54PM +0900, Keiichi KII wrote:
 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
| |--- remove  [-w---]  if you write something to remove,
| | this port is removed.
| |--- dev_name[r--r--r--]  network interface name
| |--- local_ip[rw-r--r--]  source IP to use, writable
| |--- local_port  [rw-r--r--]  source port number for UDP packets, 
 writable
| |--- local_mac   [r--r--r--]  source MAC address
| |--- remote_ip   [rw-r--r--]  port number for logging agent, writable
| |--- remote_port [rw-r--r--]  IP address for logging agent, writable
|  remote_mac  [rw-r--r--]  MAC address for logging agent, writable
|--- port2/
|--- port3/
...
 
 Signed-off-by: Keiichi KII [EMAIL PROTECTED]
 ---
 --- linux-2.6.19/drivers/net/netconsole.c 2006-12-06 14:37:26.842825500 
 +0900
 +++ enhanced-netconsole/drivers/net/netconsole.c.sysfs2006-12-06
 13:32:47.488381000 +0900
 @@ -45,6 +45,8 @@
  #include linux/sysrq.h
  #include linux/smp.h
  #include linux/netpoll.h
 +#include linux/miscdevice.h
 +#include linux/inet.h
 
  MODULE_AUTHOR(Maintainer: Matt Mackall [EMAIL PROTECTED]);
  MODULE_DESCRIPTION(Console driver for network interfaces);
 @@ -53,6 +55,7 @@ MODULE_LICENSE(GPL);
  enum {
   MAX_PRINT_CHUNK = 1000,
   MAX_CONFIG_LENGTH = 256,
 + MAC_ADDR_DIGIT = 6,
  };
 
  static char config[MAX_CONFIG_LENGTH];
 @@ -62,19 +65,214 @@ MODULE_PARM_DESC(netconsole,  netconsol
 
  struct netconsole_device {
   struct list_head list;
 + struct kobject obj;
   spinlock_t netpoll_lock;
   int id;
   struct netpoll np;
  };
 
 +struct netcon_dev_attr {
 + struct attribute attr;
 + ssize_t (*show)(struct netconsole_device*, char*);
 + ssize_t (*store)(struct netconsole_device*, const char*,
 +  size_t count);
 +};
 +
  static int add_netcon_dev(const char*);
 +static void setup_netcon_dev_sysfs(struct netconsole_device*);
  static void cleanup_netconsole(void);
  static void netcon_dev_cleanup(struct netconsole_device *nd);
 
 +static int netcon_miscdev_configured = 0;
 +
  static LIST_HEAD(active_netconsole_dev);
 
  static DEFINE_SPINLOCK(netconsole_dev_list_lock);
 
 +#define SHOW_CLASS_ATTR(field, type, format, ...) \
 +static ssize_t show_##field(type, char *buf) \
 +{ \
 + return sprintf(buf, format, __VA_ARGS__); \
 +} \

I see this sort of thing is pretty common with sysfs stuff.. but yuck.

 +static ssize_t show_netcon_dev_attr(struct kobject *kobj,
 + struct attribute *attr,
 + char *buffer)
 +{
 + struct netcon_dev_attr *na = container_of(attr, struct netcon_dev_attr,
 +   attr);
 + struct netconsole_device * nd =
 + container_of(kobj, struct netconsole_device, obj);
 + if (na-show) {
 + return na-show(nd, buffer);
 + } else {
 + return -EACCES;
 + }

Kernel style is to skip the braces for single statement clauses.

 + if (misc_register(netcon_miscdev)) {
 + printk(KERN_INFO
 +netconsole: unable netconsole misc device\n);

This error message seems to be missing a word or two.

-- 
Mathematics is the supreme nostalgia of our time.
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC][PATCH 2.6.19 3/6] add interface for netconsole using sysfs

2006-12-11 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
   | |--- remove  [-w---]  if you write something to "remove",
   | | this port is removed.
   | |--- dev_name[r--r--r--]  network interface name
   | |--- local_ip[rw-r--r--]  source IP to use, writable
   | |--- local_port  [rw-r--r--]  source port number for UDP packets, writable
   | |--- local_mac   [r--r--r--]  source MAC address
   | |--- remote_ip   [rw-r--r--]  port number for logging agent, writable
   | |--- remote_port [rw-r--r--]  IP address for logging agent, writable
   |  remote_mac  [rw-r--r--]  MAC address for logging agent, writable
   |--- port2/
   |--- port3/
   ...

Signed-off-by: Keiichi KII <[EMAIL PROTECTED]>
---
--- linux-2.6.19/drivers/net/netconsole.c   2006-12-06 14:37:26.842825500 
+0900
+++ enhanced-netconsole/drivers/net/netconsole.c.sysfs  2006-12-06
13:32:47.488381000 +0900
@@ -45,6 +45,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 

 MODULE_AUTHOR("Maintainer: Matt Mackall <[EMAIL PROTECTED]>");
 MODULE_DESCRIPTION("Console driver for network interfaces");
@@ -53,6 +55,7 @@ MODULE_LICENSE("GPL");
 enum {
MAX_PRINT_CHUNK = 1000,
MAX_CONFIG_LENGTH = 256,
+   MAC_ADDR_DIGIT = 6,
 };

 static char config[MAX_CONFIG_LENGTH];
@@ -62,19 +65,214 @@ MODULE_PARM_DESC(netconsole, " netconsol

 struct netconsole_device {
struct list_head list;
+   struct kobject obj;
spinlock_t netpoll_lock;
int id;
struct netpoll np;
 };

+struct netcon_dev_attr {
+   struct attribute attr;
+   ssize_t (*show)(struct netconsole_device*, char*);
+   ssize_t (*store)(struct netconsole_device*, const char*,
+size_t count);
+};
+
 static int add_netcon_dev(const char*);
+static void setup_netcon_dev_sysfs(struct netconsole_device*);
 static void cleanup_netconsole(void);
 static void netcon_dev_cleanup(struct netconsole_device *nd);

+static int netcon_miscdev_configured = 0;
+
 static LIST_HEAD(active_netconsole_dev);

 static DEFINE_SPINLOCK(netconsole_dev_list_lock);

+#define SHOW_CLASS_ATTR(field, type, format, ...) \
+static ssize_t show_##field(type, char *buf) \
+{ \
+ return sprintf(buf, format, __VA_ARGS__); \
+} \
+
+SHOW_CLASS_ATTR(id, struct netconsole_device *nd, "%d\n", nd->id);
+SHOW_CLASS_ATTR(dev_name, struct netconsole_device *nd,
+   "%s\n", nd->np.dev_name);
+SHOW_CLASS_ATTR(local_port, struct netconsole_device *nd,
+   "%d\n", nd->np.local_port);
+SHOW_CLASS_ATTR(remote_port, struct netconsole_device *nd,
+   "%d\n", nd->np.remote_port);
+SHOW_CLASS_ATTR(local_ip, struct netconsole_device *nd,
+   "%d.%d.%d.%d\n", HIPQUAD(nd->np.local_ip));
+SHOW_CLASS_ATTR(remote_ip, struct netconsole_device *nd,
+   "%d.%d.%d.%d\n", HIPQUAD(nd->np.remote_ip));
+SHOW_CLASS_ATTR(local_mac, struct netconsole_device *nd,
+   "%02x:%02x:%02x:%02x:%02x:%02x\n",
+   nd->np.local_mac[0], nd->np.local_mac[1], nd->np.local_mac[2],
+   nd->np.local_mac[3], nd->np.local_mac[4], nd->np.local_mac[5]);
+SHOW_CLASS_ATTR(remote_mac, struct netconsole_device *nd,
+   "%02x:%02x:%02x:%02x:%02x:%02x\n",
+   nd->np.remote_mac[0], nd->np.remote_mac[1],
+   nd->np.remote_mac[2], nd->np.remote_mac[3],
+   nd->np.remote_mac[4], nd->np.remote_mac[5]);
+
+static ssize_t store_local_port(struct netconsole_device *nd, const char *buf,
+   size_t count)
+{
+   spin_lock(>netpoll_lock);
+   nd->np.local_port = simple_strtol(buf, NULL, 10);
+   spin_unlock(>netpoll_lock);
+
+   return count;
+}
+
+static ssize_t store_remote_port(struct netconsole_device *nd, const char *buf,
+   size_t count)
+{
+   spin_lock(>netpoll_lock);
+   nd->np.remote_port = simple_strtol(buf, NULL, 10);
+   spin_unlock(>netpoll_lock);
+
+   return count;
+}
+
+static ssize_t store_local_ip(struct netconsole_device *nd, const char *buf,
+ size_t count)
+{
+   spin_lock(>netpoll_lock);
+   nd->np.local_ip = ntohl(in_aton(buf));
+   spin_unlock(>netpoll_lock);
+
+   return count;
+}
+
+static ssize_t store_remote_ip(struct netconsole_device *nd, const char *buf,
+  size_t count)
+{
+   spin_lock(>netpoll_lock);
+   nd->np.remote_ip = ntohl(in_aton(buf));
+   spin_unlock(>netpoll_lock);
+
+   return count;
+}
+
+static ssize_t 

[RFC][PATCH 2.6.19 3/6] add interface for netconsole using sysfs

2006-12-11 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
   | |--- remove  [-w---]  if you write something to remove,
   | | this port is removed.
   | |--- dev_name[r--r--r--]  network interface name
   | |--- local_ip[rw-r--r--]  source IP to use, writable
   | |--- local_port  [rw-r--r--]  source port number for UDP packets, writable
   | |--- local_mac   [r--r--r--]  source MAC address
   | |--- remote_ip   [rw-r--r--]  port number for logging agent, writable
   | |--- remote_port [rw-r--r--]  IP address for logging agent, writable
   |  remote_mac  [rw-r--r--]  MAC address for logging agent, writable
   |--- port2/
   |--- port3/
   ...

Signed-off-by: Keiichi KII [EMAIL PROTECTED]
---
--- linux-2.6.19/drivers/net/netconsole.c   2006-12-06 14:37:26.842825500 
+0900
+++ enhanced-netconsole/drivers/net/netconsole.c.sysfs  2006-12-06
13:32:47.488381000 +0900
@@ -45,6 +45,8 @@
 #include linux/sysrq.h
 #include linux/smp.h
 #include linux/netpoll.h
+#include linux/miscdevice.h
+#include linux/inet.h

 MODULE_AUTHOR(Maintainer: Matt Mackall [EMAIL PROTECTED]);
 MODULE_DESCRIPTION(Console driver for network interfaces);
@@ -53,6 +55,7 @@ MODULE_LICENSE(GPL);
 enum {
MAX_PRINT_CHUNK = 1000,
MAX_CONFIG_LENGTH = 256,
+   MAC_ADDR_DIGIT = 6,
 };

 static char config[MAX_CONFIG_LENGTH];
@@ -62,19 +65,214 @@ MODULE_PARM_DESC(netconsole,  netconsol

 struct netconsole_device {
struct list_head list;
+   struct kobject obj;
spinlock_t netpoll_lock;
int id;
struct netpoll np;
 };

+struct netcon_dev_attr {
+   struct attribute attr;
+   ssize_t (*show)(struct netconsole_device*, char*);
+   ssize_t (*store)(struct netconsole_device*, const char*,
+size_t count);
+};
+
 static int add_netcon_dev(const char*);
+static void setup_netcon_dev_sysfs(struct netconsole_device*);
 static void cleanup_netconsole(void);
 static void netcon_dev_cleanup(struct netconsole_device *nd);

+static int netcon_miscdev_configured = 0;
+
 static LIST_HEAD(active_netconsole_dev);

 static DEFINE_SPINLOCK(netconsole_dev_list_lock);

+#define SHOW_CLASS_ATTR(field, type, format, ...) \
+static ssize_t show_##field(type, char *buf) \
+{ \
+ return sprintf(buf, format, __VA_ARGS__); \
+} \
+
+SHOW_CLASS_ATTR(id, struct netconsole_device *nd, %d\n, nd-id);
+SHOW_CLASS_ATTR(dev_name, struct netconsole_device *nd,
+   %s\n, nd-np.dev_name);
+SHOW_CLASS_ATTR(local_port, struct netconsole_device *nd,
+   %d\n, nd-np.local_port);
+SHOW_CLASS_ATTR(remote_port, struct netconsole_device *nd,
+   %d\n, nd-np.remote_port);
+SHOW_CLASS_ATTR(local_ip, struct netconsole_device *nd,
+   %d.%d.%d.%d\n, HIPQUAD(nd-np.local_ip));
+SHOW_CLASS_ATTR(remote_ip, struct netconsole_device *nd,
+   %d.%d.%d.%d\n, HIPQUAD(nd-np.remote_ip));
+SHOW_CLASS_ATTR(local_mac, struct netconsole_device *nd,
+   %02x:%02x:%02x:%02x:%02x:%02x\n,
+   nd-np.local_mac[0], nd-np.local_mac[1], nd-np.local_mac[2],
+   nd-np.local_mac[3], nd-np.local_mac[4], nd-np.local_mac[5]);
+SHOW_CLASS_ATTR(remote_mac, struct netconsole_device *nd,
+   %02x:%02x:%02x:%02x:%02x:%02x\n,
+   nd-np.remote_mac[0], nd-np.remote_mac[1],
+   nd-np.remote_mac[2], nd-np.remote_mac[3],
+   nd-np.remote_mac[4], nd-np.remote_mac[5]);
+
+static ssize_t store_local_port(struct netconsole_device *nd, const char *buf,
+   size_t count)
+{
+   spin_lock(nd-netpoll_lock);
+   nd-np.local_port = simple_strtol(buf, NULL, 10);
+   spin_unlock(nd-netpoll_lock);
+
+   return count;
+}
+
+static ssize_t store_remote_port(struct netconsole_device *nd, const char *buf,
+   size_t count)
+{
+   spin_lock(nd-netpoll_lock);
+   nd-np.remote_port = simple_strtol(buf, NULL, 10);
+   spin_unlock(nd-netpoll_lock);
+
+   return count;
+}
+
+static ssize_t store_local_ip(struct netconsole_device *nd, const char *buf,
+ size_t count)
+{
+   spin_lock(nd-netpoll_lock);
+   nd-np.local_ip = ntohl(in_aton(buf));
+   spin_unlock(nd-netpoll_lock);
+
+   return count;
+}
+
+static ssize_t store_remote_ip(struct netconsole_device *nd, const char *buf,
+  size_t count)
+{
+   spin_lock(nd-netpoll_lock);
+   nd-np.remote_ip = ntohl(in_aton(buf));
+   spin_unlock(nd-netpoll_lock);
+
+   return