[PATCH 20/23] netconsole: use per-attribute show and store methods

2015-10-03 Thread Christoph Hellwig
Note that the old code actually used the store_attributes method to do
locking, this is moved into the individual methods.

Signed-off-by: Christoph Hellwig 
---
 drivers/net/netconsole.c | 271 +++
 1 file changed, 132 insertions(+), 139 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 97f3acd..06ee639 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -244,15 +244,6 @@ static void free_param_target(struct netconsole_target *nt)
  * /...
  */
 
-struct netconsole_target_attr {
-   struct configfs_attribute   attr;
-   ssize_t (*show)(struct netconsole_target *nt,
-   char *buf);
-   ssize_t (*store)(struct netconsole_target *nt,
-const char *buf,
-size_t count);
-};
-
 static struct netconsole_target *to_target(struct config_item *item)
 {
return item ?
@@ -264,58 +255,62 @@ static struct netconsole_target *to_target(struct 
config_item *item)
  * Attribute operations for netconsole_target.
  */
 
-static ssize_t show_enabled(struct netconsole_target *nt, char *buf)
+static ssize_t enabled_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%d\n", nt->enabled);
+   return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->enabled);
 }
 
-static ssize_t show_extended(struct netconsole_target *nt, char *buf)
+static ssize_t extended_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%d\n", nt->extended);
+   return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->extended);
 }
 
-static ssize_t show_dev_name(struct netconsole_target *nt, char *buf)
+static ssize_t dev_name_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%s\n", nt->np.dev_name);
+   return snprintf(buf, PAGE_SIZE, "%s\n", to_target(item)->np.dev_name);
 }
 
-static ssize_t show_local_port(struct netconsole_target *nt, char *buf)
+static ssize_t local_port_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%d\n", nt->np.local_port);
+   return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->np.local_port);
 }
 
-static ssize_t show_remote_port(struct netconsole_target *nt, char *buf)
+static ssize_t remote_port_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%d\n", nt->np.remote_port);
+   return snprintf(buf, PAGE_SIZE, "%d\n", 
to_target(item)->np.remote_port);
 }
 
-static ssize_t show_local_ip(struct netconsole_target *nt, char *buf)
+static ssize_t local_ip_show(struct config_item *item, char *buf)
 {
+   struct netconsole_target *nt = to_target(item);
+
if (nt->np.ipv6)
return snprintf(buf, PAGE_SIZE, "%pI6c\n", 
&nt->np.local_ip.in6);
else
return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip);
 }
 
-static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf)
+static ssize_t remote_ip_show(struct config_item *item, char *buf)
 {
+   struct netconsole_target *nt = to_target(item);
+
if (nt->np.ipv6)
return snprintf(buf, PAGE_SIZE, "%pI6c\n", 
&nt->np.remote_ip.in6);
else
return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip);
 }
 
-static ssize_t show_local_mac(struct netconsole_target *nt, char *buf)
+static ssize_t local_mac_show(struct config_item *item, char *buf)
 {
-   struct net_device *dev = nt->np.dev;
+   struct net_device *dev = to_target(item)->np.dev;
static const u8 bcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 
};
 
return snprintf(buf, PAGE_SIZE, "%pM\n", dev ? dev->dev_addr : bcast);
 }
 
-static ssize_t show_remote_mac(struct netconsole_target *nt, char *buf)
+static ssize_t remote_mac_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%pM\n", nt->np.remote_mac);
+   return snprintf(buf, PAGE_SIZE, "%pM\n", 
to_target(item)->np.remote_mac);
 }
 
 /*
@@ -325,23 +320,26 @@ static ssize_t show_remote_mac(struct netconsole_target 
*nt, char *buf)
  * would enable him to dynamically add new netpoll targets for new
  * network interfaces as and when they come up).
  */
-static ssize_t store_enabled(struct netconsole_target *nt,
-const char *buf,
-size_t count)
+static ssize_t enabled_store(struct config_item *item,
+   const char *buf, size_t count)
 {
+   struct netconsole_target *nt = to_target(item);
unsigned long flags;
int enabled;
int err;
 
+   mutex_lock(&dynamic_netconsole_mutex);
err = kstrtoint(buf, 10, &enabled);
if (err < 0)
-   return err;
+   goto

[PATCH 20/23] netconsole: use per-attribute show and store methods

2015-09-25 Thread Christoph Hellwig
Note that the old code actually used the store_attributes method to do
locking, this is moved into the individual methods.

Signed-off-by: Christoph Hellwig 
---
 drivers/net/netconsole.c | 269 +++
 1 file changed, 131 insertions(+), 138 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 97f3acd..8783169 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -244,15 +244,6 @@ static void free_param_target(struct netconsole_target *nt)
  * /...
  */
 
-struct netconsole_target_attr {
-   struct configfs_attribute   attr;
-   ssize_t (*show)(struct netconsole_target *nt,
-   char *buf);
-   ssize_t (*store)(struct netconsole_target *nt,
-const char *buf,
-size_t count);
-};
-
 static struct netconsole_target *to_target(struct config_item *item)
 {
return item ?
@@ -264,58 +255,62 @@ static struct netconsole_target *to_target(struct 
config_item *item)
  * Attribute operations for netconsole_target.
  */
 
-static ssize_t show_enabled(struct netconsole_target *nt, char *buf)
+static ssize_t enabled_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%d\n", nt->enabled);
+   return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->enabled);
 }
 
-static ssize_t show_extended(struct netconsole_target *nt, char *buf)
+static ssize_t extended_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%d\n", nt->extended);
+   return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->extended);
 }
 
-static ssize_t show_dev_name(struct netconsole_target *nt, char *buf)
+static ssize_t dev_name_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%s\n", nt->np.dev_name);
+   return snprintf(buf, PAGE_SIZE, "%s\n", to_target(item)->np.dev_name);
 }
 
-static ssize_t show_local_port(struct netconsole_target *nt, char *buf)
+static ssize_t local_port_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%d\n", nt->np.local_port);
+   return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->np.local_port);
 }
 
-static ssize_t show_remote_port(struct netconsole_target *nt, char *buf)
+static ssize_t remote_port_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%d\n", nt->np.remote_port);
+   return snprintf(buf, PAGE_SIZE, "%d\n", 
to_target(item)->np.remote_port);
 }
 
-static ssize_t show_local_ip(struct netconsole_target *nt, char *buf)
+static ssize_t local_ip_show(struct config_item *item, char *buf)
 {
+   struct netconsole_target *nt = to_target(item);
+
if (nt->np.ipv6)
return snprintf(buf, PAGE_SIZE, "%pI6c\n", 
&nt->np.local_ip.in6);
else
return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip);
 }
 
-static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf)
+static ssize_t remote_ip_show(struct config_item *item, char *buf)
 {
+   struct netconsole_target *nt = to_target(item);
+
if (nt->np.ipv6)
return snprintf(buf, PAGE_SIZE, "%pI6c\n", 
&nt->np.remote_ip.in6);
else
return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip);
 }
 
-static ssize_t show_local_mac(struct netconsole_target *nt, char *buf)
+static ssize_t local_mac_show(struct config_item *item, char *buf)
 {
-   struct net_device *dev = nt->np.dev;
+   struct net_device *dev = to_target(item)->np.dev;
static const u8 bcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 
};
 
return snprintf(buf, PAGE_SIZE, "%pM\n", dev ? dev->dev_addr : bcast);
 }
 
-static ssize_t show_remote_mac(struct netconsole_target *nt, char *buf)
+static ssize_t remote_mac_show(struct config_item *item, char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, "%pM\n", nt->np.remote_mac);
+   return snprintf(buf, PAGE_SIZE, "%pM\n", 
to_target(item)->np.remote_mac);
 }
 
 /*
@@ -325,23 +320,26 @@ static ssize_t show_remote_mac(struct netconsole_target 
*nt, char *buf)
  * would enable him to dynamically add new netpoll targets for new
  * network interfaces as and when they come up).
  */
-static ssize_t store_enabled(struct netconsole_target *nt,
-const char *buf,
-size_t count)
+static ssize_t enabled_store(struct config_item *item,
+   const char *buf, size_t count)
 {
+   struct netconsole_target *nt = to_target(item);
unsigned long flags;
int enabled;
int err;
 
+   mutex_lock(&dynamic_netconsole_mutex);
err = kstrtoint(buf, 10, &enabled);
if (err < 0)
-   return err;
+   goto