Skip to content

Commit

Permalink
Staging: batman-adv: Move tables from sysfs to debugfs
Browse files Browse the repository at this point in the history
Files which represent more than a single attribute aren't allowed in
sysfs. As we have some files which aren't essential and are lists or
tables aggregated from data from different places inside batman-adv, we
must place them in a filesystem without such a restriction.

Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Sven Eckelmann authored and Greg Kroah-Hartman committed Jun 22, 2010
1 parent c412143 commit 4caecbc
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 238 deletions.
71 changes: 71 additions & 0 deletions drivers/staging/batman-adv/bat_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,60 @@

static struct dentry *bat_debugfs;

static int originators_open(struct inode *inode, struct file *file)
{
struct net_device *net_dev = (struct net_device *)inode->i_private;
return single_open(file, orig_seq_print_text, net_dev);
}

static int transtable_global_open(struct inode *inode, struct file *file)
{
struct net_device *net_dev = (struct net_device *)inode->i_private;
return single_open(file, hna_global_seq_print_text, net_dev);
}

static int transtable_local_open(struct inode *inode, struct file *file)
{
struct net_device *net_dev = (struct net_device *)inode->i_private;
return single_open(file, hna_local_seq_print_text, net_dev);
}

static int vis_data_open(struct inode *inode, struct file *file)
{
struct net_device *net_dev = (struct net_device *)inode->i_private;
return single_open(file, vis_seq_print_text, net_dev);
}

struct bat_debuginfo {
struct attribute attr;
const struct file_operations fops;
};

#define BAT_DEBUGINFO(_name, _mode, _open) \
struct bat_debuginfo bat_debuginfo_##_name = { \
.attr = { .name = __stringify(_name), \
.mode = _mode, }, \
.fops = { .owner = THIS_MODULE, \
.open = _open, \
.read = seq_read, \
.llseek = seq_lseek, \
.release = single_release, \
} \
};

static BAT_DEBUGINFO(originators, S_IRUGO, originators_open);
static BAT_DEBUGINFO(transtable_global, S_IRUGO, transtable_global_open);
static BAT_DEBUGINFO(transtable_local, S_IRUGO, transtable_local_open);
static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open);

static struct bat_debuginfo *mesh_debuginfos[] = {
&bat_debuginfo_originators,
&bat_debuginfo_transtable_global,
&bat_debuginfo_transtable_local,
&bat_debuginfo_vis_data,
NULL,
};

void debugfs_init(void)
{
bat_debugfs = debugfs_create_dir(DEBUGFS_BAT_SUBDIR, NULL);
Expand All @@ -47,6 +101,8 @@ void debugfs_destroy(void)
int debugfs_add_meshif(struct net_device *dev)
{
struct bat_priv *bat_priv = netdev_priv(dev);
struct bat_debuginfo **bat_debug;
struct dentry *file;

if (!bat_debugfs)
goto out;
Expand All @@ -57,7 +113,22 @@ int debugfs_add_meshif(struct net_device *dev)

bat_socket_setup(bat_priv);

for (bat_debug = mesh_debuginfos; *bat_debug; ++bat_debug) {
file = debugfs_create_file(((*bat_debug)->attr).name,
S_IFREG | ((*bat_debug)->attr).mode,
bat_priv->debug_dir,
dev, &(*bat_debug)->fops);
if (!file) {
printk(KERN_ERR "batman-adv:Can't add debugfs file: "
"%s/%s\n", dev->name, ((*bat_debug)->attr).name);
goto rem_attr;
}
}

return 0;
rem_attr:
debugfs_remove_recursive(bat_priv->debug_dir);
bat_priv->debug_dir = NULL;
out:
#ifdef CONFIG_DEBUG_FS
return -ENOMEM;
Expand Down
79 changes: 0 additions & 79 deletions drivers/staging/batman-adv/bat_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ struct bat_attribute bat_attr_##_name = { \
.store = _store, \
};

#define BAT_BIN_ATTR(_name, _mode, _read, _write) \
struct bin_attribute bat_attr_##_name = { \
.attr = { .name = __stringify(_name), \
.mode = _mode, }, \
.read = _read, \
.write = _write, \
};

static ssize_t show_aggr_ogm(struct kobject *kobj, struct attribute *attr,
char *buff)
{
Expand Down Expand Up @@ -201,65 +193,11 @@ static struct bat_attribute *mesh_attrs[] = {
NULL,
};

static ssize_t transtable_local_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buff, loff_t off, size_t count)
{
struct device *dev = to_dev(kobj->parent);
struct net_device *net_dev = to_net_dev(dev);

return hna_local_fill_buffer_text(net_dev, buff, count, off);
}

static ssize_t transtable_global_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buff, loff_t off, size_t count)
{
struct device *dev = to_dev(kobj->parent);
struct net_device *net_dev = to_net_dev(dev);

return hna_global_fill_buffer_text(net_dev, buff, count, off);
}

static ssize_t originators_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buff, loff_t off, size_t count)
{
struct device *dev = to_dev(kobj->parent);
struct net_device *net_dev = to_net_dev(dev);

return orig_fill_buffer_text(net_dev, buff, count, off);
}

static ssize_t vis_data_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buff, loff_t off, size_t count)
{
struct device *dev = to_dev(kobj->parent);
struct net_device *net_dev = to_net_dev(dev);

return vis_fill_buffer_text(net_dev, buff, count, off);
}

static BAT_BIN_ATTR(transtable_local, S_IRUGO, transtable_local_read, NULL);
static BAT_BIN_ATTR(transtable_global, S_IRUGO, transtable_global_read, NULL);
static BAT_BIN_ATTR(originators, S_IRUGO, originators_read, NULL);
static BAT_BIN_ATTR(vis_data, S_IRUGO, vis_data_read, NULL);

static struct bin_attribute *mesh_bin_attrs[] = {
&bat_attr_transtable_local,
&bat_attr_transtable_global,
&bat_attr_originators,
&bat_attr_vis_data,
NULL,
};

int sysfs_add_meshif(struct net_device *dev)
{
struct kobject *batif_kobject = &dev->dev.kobj;
struct bat_priv *bat_priv = netdev_priv(dev);
struct bat_attribute **bat_attr;
struct bin_attribute **bin_attr;
int err;

/* FIXME: should be done in the general mesh setup
Expand Down Expand Up @@ -289,21 +227,8 @@ int sysfs_add_meshif(struct net_device *dev)
}
}

for (bin_attr = mesh_bin_attrs; *bin_attr; ++bin_attr) {
err = sysfs_create_bin_file(bat_priv->mesh_obj, (*bin_attr));
if (err) {
printk(KERN_ERR "batman-adv:Can't add sysfs file: %s/%s/%s\n",
dev->name, SYSFS_IF_MESH_SUBDIR,
((*bin_attr)->attr).name);
goto rem_bin_attr;
}
}

return 0;

rem_bin_attr:
for (bin_attr = mesh_bin_attrs; *bin_attr; ++bin_attr)
sysfs_remove_bin_file(bat_priv->mesh_obj, (*bin_attr));
rem_attr:
for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr)
sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
Expand All @@ -318,10 +243,6 @@ void sysfs_del_meshif(struct net_device *dev)
{
struct bat_priv *bat_priv = netdev_priv(dev);
struct bat_attribute **bat_attr;
struct bin_attribute **bin_attr;

for (bin_attr = mesh_bin_attrs; *bin_attr; ++bin_attr)
sysfs_remove_bin_file(bat_priv->mesh_obj, (*bin_attr));

for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr)
sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
Expand Down
3 changes: 2 additions & 1 deletion drivers/staging/batman-adv/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
#define MODULE_ACTIVE 1
#define MODULE_DEACTIVATING 2

#define BCAST_QUEUE_LEN 256
#define BCAST_QUEUE_LEN 256
#define BATMAN_QUEUE_LEN 256

/*
Expand Down Expand Up @@ -119,6 +119,7 @@ extern int bat_debug_type(int type);
#include <linux/slab.h>
#include <net/sock.h> /* struct sock */
#include <linux/jiffies.h>
#include <linux/seq_file.h>
#include "types.h"

#ifndef REVISION_VERSION
Expand Down
64 changes: 19 additions & 45 deletions drivers/staging/batman-adv/originator.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,49 +271,38 @@ void purge_orig(struct work_struct *work)
start_purge_timer();
}

ssize_t orig_fill_buffer_text(struct net_device *net_dev, char *buff,
size_t count, loff_t off)
int orig_seq_print_text(struct seq_file *seq, void *offset)
{
HASHIT(hashit);
struct net_device *net_dev = (struct net_device *)seq->private;
struct bat_priv *bat_priv = netdev_priv(net_dev);
struct orig_node *orig_node;
struct neigh_node *neigh_node;
size_t hdr_len, tmp_len;
int batman_count = 0, bytes_written = 0;
int batman_count = 0;
unsigned long flags;
char orig_str[ETH_STR_LEN], router_str[ETH_STR_LEN];

if (!bat_priv->primary_if) {
if (off == 0)
return sprintf(buff,
"BATMAN mesh %s disabled - "
if ((!bat_priv->primary_if) ||
(bat_priv->primary_if->if_status != IF_ACTIVE)) {
if (!bat_priv->primary_if)
return seq_printf(seq, "BATMAN mesh %s disabled - "
"please specify interfaces to enable it\n",
net_dev->name);

return 0;
return seq_printf(seq, "BATMAN mesh %s "
"disabled - primary interface not active\n",
net_dev->name);
}

if (bat_priv->primary_if->if_status != IF_ACTIVE && off == 0)
return sprintf(buff,
"BATMAN mesh %s "
"disabled - primary interface not active\n",
net_dev->name);
else if (bat_priv->primary_if->if_status != IF_ACTIVE)
return 0;

rcu_read_lock();
hdr_len = sprintf(buff,
" %-14s (%s/%i) %17s [%10s]: %20s "
seq_printf(seq, " %-14s (%s/%i) %17s [%10s]: %20s "
"... [B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s (%s)]\n",
"Originator", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF",
"Potential nexthops", SOURCE_VERSION, REVISION_VERSION_STR,
bat_priv->primary_if->dev, bat_priv->primary_if->addr_str,
net_dev->name);
rcu_read_unlock();

if (off < hdr_len)
bytes_written = hdr_len;

spin_lock_irqsave(&orig_hash_lock, flags);

while (hash_iterate(orig_hash, &hashit)) {
Expand All @@ -326,44 +315,29 @@ ssize_t orig_fill_buffer_text(struct net_device *net_dev, char *buff,
if (orig_node->router->tq_avg == 0)
continue;

/* estimated line length */
if (count < bytes_written + 200)
break;

addr_to_string(orig_str, orig_node->orig);
addr_to_string(router_str, orig_node->router->addr);

tmp_len = sprintf(buff + bytes_written,
"%-17s (%3i) %17s [%10s]:",
orig_str, orig_node->router->tq_avg,
router_str,
orig_node->router->if_incoming->dev);
seq_printf(seq, "%-17s (%3i) %17s [%10s]:",
orig_str, orig_node->router->tq_avg, router_str,
orig_node->router->if_incoming->dev);

list_for_each_entry(neigh_node, &orig_node->neigh_list, list) {
addr_to_string(orig_str, neigh_node->addr);
tmp_len += sprintf(buff + bytes_written + tmp_len,
" %17s (%3i)", orig_str,
seq_printf(seq, " %17s (%3i)", orig_str,
neigh_node->tq_avg);
}

tmp_len += sprintf(buff + bytes_written + tmp_len, "\n");

seq_printf(seq, "\n");
batman_count++;
hdr_len += tmp_len;

if (off >= hdr_len)
continue;

bytes_written += tmp_len;
}

spin_unlock_irqrestore(&orig_hash_lock, flags);

if ((batman_count == 0) && (off == 0))
bytes_written += sprintf(buff + bytes_written,
"No batman nodes in range ...\n");
if ((batman_count == 0))
seq_printf(seq, "No batman nodes in range ...\n");

return bytes_written;
return 0;
}

static int orig_node_add_if(struct orig_node *orig_node, int max_if_num)
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/batman-adv/originator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct orig_node *get_orig_node(uint8_t *addr);
struct neigh_node *
create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
uint8_t *neigh, struct batman_if *if_incoming);
ssize_t orig_fill_buffer_text(struct net_device *net_dev, char *buff,
size_t count, loff_t off);
int orig_seq_print_text(struct seq_file *seq, void *offset);
int orig_hash_add_if(struct batman_if *batman_if, int max_if_num);
int orig_hash_del_if(struct batman_if *batman_if, int max_if_num);
Loading

0 comments on commit 4caecbc

Please sign in to comment.