提交 4caecbc0 编写于 作者: S Sven Eckelmann 提交者: Greg Kroah-Hartman

Staging: batman-adv: Move tables from sysfs to debugfs

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: NSven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 c4121432
...@@ -31,6 +31,60 @@ ...@@ -31,6 +31,60 @@
static struct dentry *bat_debugfs; 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) void debugfs_init(void)
{ {
bat_debugfs = debugfs_create_dir(DEBUGFS_BAT_SUBDIR, NULL); bat_debugfs = debugfs_create_dir(DEBUGFS_BAT_SUBDIR, NULL);
...@@ -47,6 +101,8 @@ void debugfs_destroy(void) ...@@ -47,6 +101,8 @@ void debugfs_destroy(void)
int debugfs_add_meshif(struct net_device *dev) int debugfs_add_meshif(struct net_device *dev)
{ {
struct bat_priv *bat_priv = netdev_priv(dev); struct bat_priv *bat_priv = netdev_priv(dev);
struct bat_debuginfo **bat_debug;
struct dentry *file;
if (!bat_debugfs) if (!bat_debugfs)
goto out; goto out;
...@@ -57,7 +113,22 @@ int debugfs_add_meshif(struct net_device *dev) ...@@ -57,7 +113,22 @@ int debugfs_add_meshif(struct net_device *dev)
bat_socket_setup(bat_priv); 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; return 0;
rem_attr:
debugfs_remove_recursive(bat_priv->debug_dir);
bat_priv->debug_dir = NULL;
out: out:
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
return -ENOMEM; return -ENOMEM;
......
...@@ -36,14 +36,6 @@ struct bat_attribute bat_attr_##_name = { \ ...@@ -36,14 +36,6 @@ struct bat_attribute bat_attr_##_name = { \
.store = _store, \ .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, static ssize_t show_aggr_ogm(struct kobject *kobj, struct attribute *attr,
char *buff) char *buff)
{ {
...@@ -201,65 +193,11 @@ static struct bat_attribute *mesh_attrs[] = { ...@@ -201,65 +193,11 @@ static struct bat_attribute *mesh_attrs[] = {
NULL, 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) int sysfs_add_meshif(struct net_device *dev)
{ {
struct kobject *batif_kobject = &dev->dev.kobj; struct kobject *batif_kobject = &dev->dev.kobj;
struct bat_priv *bat_priv = netdev_priv(dev); struct bat_priv *bat_priv = netdev_priv(dev);
struct bat_attribute **bat_attr; struct bat_attribute **bat_attr;
struct bin_attribute **bin_attr;
int err; int err;
/* FIXME: should be done in the general mesh setup /* FIXME: should be done in the general mesh setup
...@@ -289,21 +227,8 @@ int sysfs_add_meshif(struct net_device *dev) ...@@ -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; 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: rem_attr:
for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr) for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr)
sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr)); sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
...@@ -318,10 +243,6 @@ void sysfs_del_meshif(struct net_device *dev) ...@@ -318,10 +243,6 @@ void sysfs_del_meshif(struct net_device *dev)
{ {
struct bat_priv *bat_priv = netdev_priv(dev); struct bat_priv *bat_priv = netdev_priv(dev);
struct bat_attribute **bat_attr; 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) for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr)
sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr)); sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
......
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
#define MODULE_ACTIVE 1 #define MODULE_ACTIVE 1
#define MODULE_DEACTIVATING 2 #define MODULE_DEACTIVATING 2
#define BCAST_QUEUE_LEN 256 #define BCAST_QUEUE_LEN 256
#define BATMAN_QUEUE_LEN 256 #define BATMAN_QUEUE_LEN 256
/* /*
...@@ -119,6 +119,7 @@ extern int bat_debug_type(int type); ...@@ -119,6 +119,7 @@ extern int bat_debug_type(int type);
#include <linux/slab.h> #include <linux/slab.h>
#include <net/sock.h> /* struct sock */ #include <net/sock.h> /* struct sock */
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/seq_file.h>
#include "types.h" #include "types.h"
#ifndef REVISION_VERSION #ifndef REVISION_VERSION
......
...@@ -271,39 +271,31 @@ void purge_orig(struct work_struct *work) ...@@ -271,39 +271,31 @@ void purge_orig(struct work_struct *work)
start_purge_timer(); start_purge_timer();
} }
ssize_t orig_fill_buffer_text(struct net_device *net_dev, char *buff, int orig_seq_print_text(struct seq_file *seq, void *offset)
size_t count, loff_t off)
{ {
HASHIT(hashit); HASHIT(hashit);
struct net_device *net_dev = (struct net_device *)seq->private;
struct bat_priv *bat_priv = netdev_priv(net_dev); struct bat_priv *bat_priv = netdev_priv(net_dev);
struct orig_node *orig_node; struct orig_node *orig_node;
struct neigh_node *neigh_node; struct neigh_node *neigh_node;
size_t hdr_len, tmp_len; int batman_count = 0;
int batman_count = 0, bytes_written = 0;
unsigned long flags; unsigned long flags;
char orig_str[ETH_STR_LEN], router_str[ETH_STR_LEN]; char orig_str[ETH_STR_LEN], router_str[ETH_STR_LEN];
if (!bat_priv->primary_if) { if ((!bat_priv->primary_if) ||
if (off == 0) (bat_priv->primary_if->if_status != IF_ACTIVE)) {
return sprintf(buff, if (!bat_priv->primary_if)
"BATMAN mesh %s disabled - " return seq_printf(seq, "BATMAN mesh %s disabled - "
"please specify interfaces to enable it\n", "please specify interfaces to enable it\n",
net_dev->name); 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(); rcu_read_lock();
hdr_len = sprintf(buff, seq_printf(seq, " %-14s (%s/%i) %17s [%10s]: %20s "
" %-14s (%s/%i) %17s [%10s]: %20s "
"... [B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s (%s)]\n", "... [B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s (%s)]\n",
"Originator", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF", "Originator", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF",
"Potential nexthops", SOURCE_VERSION, REVISION_VERSION_STR, "Potential nexthops", SOURCE_VERSION, REVISION_VERSION_STR,
...@@ -311,9 +303,6 @@ ssize_t orig_fill_buffer_text(struct net_device *net_dev, char *buff, ...@@ -311,9 +303,6 @@ ssize_t orig_fill_buffer_text(struct net_device *net_dev, char *buff,
net_dev->name); net_dev->name);
rcu_read_unlock(); rcu_read_unlock();
if (off < hdr_len)
bytes_written = hdr_len;
spin_lock_irqsave(&orig_hash_lock, flags); spin_lock_irqsave(&orig_hash_lock, flags);
while (hash_iterate(orig_hash, &hashit)) { while (hash_iterate(orig_hash, &hashit)) {
...@@ -326,44 +315,29 @@ ssize_t orig_fill_buffer_text(struct net_device *net_dev, char *buff, ...@@ -326,44 +315,29 @@ ssize_t orig_fill_buffer_text(struct net_device *net_dev, char *buff,
if (orig_node->router->tq_avg == 0) if (orig_node->router->tq_avg == 0)
continue; continue;
/* estimated line length */
if (count < bytes_written + 200)
break;
addr_to_string(orig_str, orig_node->orig); addr_to_string(orig_str, orig_node->orig);
addr_to_string(router_str, orig_node->router->addr); addr_to_string(router_str, orig_node->router->addr);
tmp_len = sprintf(buff + bytes_written, seq_printf(seq, "%-17s (%3i) %17s [%10s]:",
"%-17s (%3i) %17s [%10s]:", orig_str, orig_node->router->tq_avg, router_str,
orig_str, orig_node->router->tq_avg, orig_node->router->if_incoming->dev);
router_str,
orig_node->router->if_incoming->dev);
list_for_each_entry(neigh_node, &orig_node->neigh_list, list) { list_for_each_entry(neigh_node, &orig_node->neigh_list, list) {
addr_to_string(orig_str, neigh_node->addr); addr_to_string(orig_str, neigh_node->addr);
tmp_len += sprintf(buff + bytes_written + tmp_len, seq_printf(seq, " %17s (%3i)", orig_str,
" %17s (%3i)", orig_str,
neigh_node->tq_avg); neigh_node->tq_avg);
} }
tmp_len += sprintf(buff + bytes_written + tmp_len, "\n"); seq_printf(seq, "\n");
batman_count++; batman_count++;
hdr_len += tmp_len;
if (off >= hdr_len)
continue;
bytes_written += tmp_len;
} }
spin_unlock_irqrestore(&orig_hash_lock, flags); spin_unlock_irqrestore(&orig_hash_lock, flags);
if ((batman_count == 0) && (off == 0)) if ((batman_count == 0))
bytes_written += sprintf(buff + bytes_written, seq_printf(seq, "No batman nodes in range ...\n");
"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) static int orig_node_add_if(struct orig_node *orig_node, int max_if_num)
......
...@@ -28,7 +28,6 @@ struct orig_node *get_orig_node(uint8_t *addr); ...@@ -28,7 +28,6 @@ struct orig_node *get_orig_node(uint8_t *addr);
struct neigh_node * struct neigh_node *
create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node, create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
uint8_t *neigh, struct batman_if *if_incoming); uint8_t *neigh, struct batman_if *if_incoming);
ssize_t orig_fill_buffer_text(struct net_device *net_dev, char *buff, int orig_seq_print_text(struct seq_file *seq, void *offset);
size_t count, loff_t off);
int orig_hash_add_if(struct batman_if *batman_if, int max_if_num); 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); int orig_hash_del_if(struct batman_if *batman_if, int max_if_num);
...@@ -160,59 +160,59 @@ int hna_local_fill_buffer(unsigned char *buff, int buff_len) ...@@ -160,59 +160,59 @@ int hna_local_fill_buffer(unsigned char *buff, int buff_len)
return i; return i;
} }
int hna_local_fill_buffer_text(struct net_device *net_dev, char *buff, int hna_local_seq_print_text(struct seq_file *seq, void *offset)
size_t count, loff_t off)
{ {
struct net_device *net_dev = (struct net_device *)seq->private;
struct bat_priv *bat_priv = netdev_priv(net_dev); struct bat_priv *bat_priv = netdev_priv(net_dev);
struct hna_local_entry *hna_local_entry; struct hna_local_entry *hna_local_entry;
HASHIT(hashit); HASHIT(hashit);
int bytes_written = 0; HASHIT(hashit_count);
unsigned long flags; unsigned long flags;
size_t hdr_len; size_t buf_size, pos;
char *buff;
if (!bat_priv->primary_if) { if (!bat_priv->primary_if) {
if (off == 0) return seq_printf(seq, "BATMAN mesh %s disabled - "
return sprintf(buff, "please specify interfaces to enable it\n",
"BATMAN mesh %s disabled - " net_dev->name);
"please specify interfaces to enable it\n",
net_dev->name);
return 0;
} }
hdr_len = sprintf(buff, seq_printf(seq, "Locally retrieved addresses (from %s) "
"Locally retrieved addresses (from %s) " "announced via HNA:\n",
"announced via HNA:\n", net_dev->name);
net_dev->name);
if (off < hdr_len)
bytes_written = hdr_len;
spin_lock_irqsave(&hna_local_hash_lock, flags); spin_lock_irqsave(&hna_local_hash_lock, flags);
while (hash_iterate(hna_local_hash, &hashit)) { buf_size = 1;
hdr_len += 21; /* Estimate length for: " * xx:xx:xx:xx:xx:xx\n" */
while (hash_iterate(hna_local_hash, &hashit_count))
if (count < bytes_written + 22) buf_size += 21;
break;
if (off >= hdr_len) buff = kmalloc(buf_size, GFP_ATOMIC);
continue; if (!buff) {
spin_unlock_irqrestore(&hna_local_hash_lock, flags);
return -ENOMEM;
}
buff[0] = '\0';
pos = 0;
while (hash_iterate(hna_local_hash, &hashit)) {
hna_local_entry = hashit.bucket->data; hna_local_entry = hashit.bucket->data;
bytes_written += snprintf(buff + bytes_written, 22, pos += snprintf(buff + pos, 22, " * " MAC_FMT "\n",
" * " MAC_FMT "\n", hna_local_entry->addr[0],
hna_local_entry->addr[0], hna_local_entry->addr[1],
hna_local_entry->addr[1], hna_local_entry->addr[2],
hna_local_entry->addr[2], hna_local_entry->addr[3],
hna_local_entry->addr[3], hna_local_entry->addr[4],
hna_local_entry->addr[4], hna_local_entry->addr[5]);
hna_local_entry->addr[5]);
} }
spin_unlock_irqrestore(&hna_local_hash_lock, flags); spin_unlock_irqrestore(&hna_local_hash_lock, flags);
return bytes_written;
seq_printf(seq, "%s", buff);
kfree(buff);
return 0;
} }
static void _hna_local_del(void *data) static void _hna_local_del(void *data)
...@@ -378,65 +378,66 @@ void hna_global_add_orig(struct orig_node *orig_node, ...@@ -378,65 +378,66 @@ void hna_global_add_orig(struct orig_node *orig_node,
spin_unlock_irqrestore(&hna_global_hash_lock, flags); spin_unlock_irqrestore(&hna_global_hash_lock, flags);
} }
int hna_global_fill_buffer_text(struct net_device *net_dev, char *buff, int hna_global_seq_print_text(struct seq_file *seq, void *offset)
size_t count, loff_t off)
{ {
struct net_device *net_dev = (struct net_device *)seq->private;
struct bat_priv *bat_priv = netdev_priv(net_dev); struct bat_priv *bat_priv = netdev_priv(net_dev);
struct hna_global_entry *hna_global_entry; struct hna_global_entry *hna_global_entry;
HASHIT(hashit); HASHIT(hashit);
int bytes_written = 0; HASHIT(hashit_count);
unsigned long flags; unsigned long flags;
size_t hdr_len; size_t buf_size, pos;
char *buff;
if (!bat_priv->primary_if) { if (!bat_priv->primary_if) {
if (off == 0) return seq_printf(seq, "BATMAN mesh %s disabled - "
return sprintf(buff, "please specify interfaces to enable it\n",
"BATMAN mesh %s disabled - " net_dev->name);
"please specify interfaces to enable it\n",
net_dev->name);
return 0;
} }
hdr_len = sprintf(buff, seq_printf(seq, "Globally announced HNAs received via the mesh %s "
"Globally announced HNAs received via the mesh %s " "(translation table):\n",
"(translation table):\n", net_dev->name);
net_dev->name);
if (off < hdr_len)
bytes_written = hdr_len;
spin_lock_irqsave(&hna_global_hash_lock, flags); spin_lock_irqsave(&hna_global_hash_lock, flags);
while (hash_iterate(hna_global_hash, &hashit)) { buf_size = 1;
hdr_len += 43; /* Estimate length for: " * xx:xx:xx:xx:xx:xx via xx:xx:xx:xx:xx:xx\n"*/
while (hash_iterate(hna_global_hash, &hashit_count))
if (count < bytes_written + 44) buf_size += 43;
break;
if (off >= hdr_len) buff = kmalloc(buf_size, GFP_ATOMIC);
continue; if (!buff) {
spin_unlock_irqrestore(&hna_global_hash_lock, flags);
return -ENOMEM;
}
buff[0] = '\0';
pos = 0;
while (hash_iterate(hna_global_hash, &hashit)) {
hna_global_entry = hashit.bucket->data; hna_global_entry = hashit.bucket->data;
bytes_written += snprintf(buff + bytes_written, 44, pos += snprintf(buff + pos, 44,
" * " MAC_FMT " via " MAC_FMT "\n", " * " MAC_FMT " via " MAC_FMT "\n",
hna_global_entry->addr[0], hna_global_entry->addr[0],
hna_global_entry->addr[1], hna_global_entry->addr[1],
hna_global_entry->addr[2], hna_global_entry->addr[2],
hna_global_entry->addr[3], hna_global_entry->addr[3],
hna_global_entry->addr[4], hna_global_entry->addr[4],
hna_global_entry->addr[5], hna_global_entry->addr[5],
hna_global_entry->orig_node->orig[0], hna_global_entry->orig_node->orig[0],
hna_global_entry->orig_node->orig[1], hna_global_entry->orig_node->orig[1],
hna_global_entry->orig_node->orig[2], hna_global_entry->orig_node->orig[2],
hna_global_entry->orig_node->orig[3], hna_global_entry->orig_node->orig[3],
hna_global_entry->orig_node->orig[4], hna_global_entry->orig_node->orig[4],
hna_global_entry->orig_node->orig[5]); hna_global_entry->orig_node->orig[5]);
} }
spin_unlock_irqrestore(&hna_global_hash_lock, flags); spin_unlock_irqrestore(&hna_global_hash_lock, flags);
return bytes_written;
seq_printf(seq, "%s", buff);
kfree(buff);
return 0;
} }
void _hna_global_del_orig(struct hna_global_entry *hna_global_entry, void _hna_global_del_orig(struct hna_global_entry *hna_global_entry,
......
...@@ -25,15 +25,13 @@ int hna_local_init(void); ...@@ -25,15 +25,13 @@ int hna_local_init(void);
void hna_local_add(uint8_t *addr); void hna_local_add(uint8_t *addr);
void hna_local_remove(uint8_t *addr, char *message); void hna_local_remove(uint8_t *addr, char *message);
int hna_local_fill_buffer(unsigned char *buff, int buff_len); int hna_local_fill_buffer(unsigned char *buff, int buff_len);
int hna_local_fill_buffer_text(struct net_device *net_dev, char *buff, int hna_local_seq_print_text(struct seq_file *seq, void *offset);
size_t count, loff_t off);
void hna_local_purge(struct work_struct *work); void hna_local_purge(struct work_struct *work);
void hna_local_free(void); void hna_local_free(void);
int hna_global_init(void); int hna_global_init(void);
void hna_global_add_orig(struct orig_node *orig_node, unsigned char *hna_buff, void hna_global_add_orig(struct orig_node *orig_node, unsigned char *hna_buff,
int hna_buff_len); int hna_buff_len);
int hna_global_fill_buffer_text(struct net_device *net_dev, char *buff, int hna_global_seq_print_text(struct seq_file *seq, void *offset);
size_t count, loff_t off);
void _hna_global_del_orig(struct hna_global_entry *hna_global_entry, void _hna_global_del_orig(struct hna_global_entry *hna_global_entry,
char *orig_str); char *orig_str);
void hna_global_del_orig(struct orig_node *orig_node, char *message); void hna_global_del_orig(struct orig_node *orig_node, char *message);
......
...@@ -115,7 +115,7 @@ static void vis_data_insert_interface(const uint8_t *interface, ...@@ -115,7 +115,7 @@ static void vis_data_insert_interface(const uint8_t *interface,
} }
/* its a new address, add it to the list */ /* its a new address, add it to the list */
entry = kmalloc(sizeof(*entry), GFP_KERNEL); entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
if (!entry) if (!entry)
return; return;
memcpy(entry->addr, interface, ETH_ALEN); memcpy(entry->addr, interface, ETH_ALEN);
...@@ -142,12 +142,29 @@ static ssize_t vis_data_read_prim_sec(char *buff, struct hlist_head *if_list) ...@@ -142,12 +142,29 @@ static ssize_t vis_data_read_prim_sec(char *buff, struct hlist_head *if_list)
return len; return len;
} }
static size_t vis_data_count_prim_sec(struct hlist_head *if_list)
{
struct if_list_entry *entry;
struct hlist_node *pos;
size_t count = 0;
hlist_for_each_entry(entry, pos, if_list, list) {
if (entry->primary)
count += 9;
else
count += 23;
}
return count;
}
/* read an entry */ /* read an entry */
static ssize_t vis_data_read_entry(char *buff, struct vis_info_entry *entry, static ssize_t vis_data_read_entry(char *buff, struct vis_info_entry *entry,
uint8_t *src, bool primary) uint8_t *src, bool primary)
{ {
char to[40]; char to[18];
/* maximal length: max(4+17+2, 3+17+1+3+2) == 26 */
addr_to_string(to, entry->dest); addr_to_string(to, entry->dest);
if (primary && entry->quality == 0) if (primary && entry->quality == 0)
return sprintf(buff, "HNA %s, ", to); return sprintf(buff, "HNA %s, ", to);
...@@ -157,38 +174,74 @@ static ssize_t vis_data_read_entry(char *buff, struct vis_info_entry *entry, ...@@ -157,38 +174,74 @@ static ssize_t vis_data_read_entry(char *buff, struct vis_info_entry *entry,
return 0; return 0;
} }
ssize_t vis_fill_buffer_text(struct net_device *net_dev, char *buff, int vis_seq_print_text(struct seq_file *seq, void *offset)
size_t count, loff_t off)
{ {
HASHIT(hashit); HASHIT(hashit);
HASHIT(hashit_count);
struct vis_info *info; struct vis_info *info;
struct vis_info_entry *entries; struct vis_info_entry *entries;
struct net_device *net_dev = (struct net_device *)seq->private;
struct bat_priv *bat_priv = netdev_priv(net_dev); struct bat_priv *bat_priv = netdev_priv(net_dev);
HLIST_HEAD(vis_if_list); HLIST_HEAD(vis_if_list);
struct if_list_entry *entry; struct if_list_entry *entry;
struct hlist_node *pos, *n; struct hlist_node *pos, *n;
size_t hdr_len, tmp_len; int i;
int i, bytes_written = 0;
char tmp_addr_str[ETH_STR_LEN]; char tmp_addr_str[ETH_STR_LEN];
unsigned long flags; unsigned long flags;
int vis_server = atomic_read(&bat_priv->vis_mode); int vis_server = atomic_read(&bat_priv->vis_mode);
size_t buff_pos, buf_size;
char *buff;
if ((!bat_priv->primary_if) || if ((!bat_priv->primary_if) ||
(vis_server == VIS_TYPE_CLIENT_UPDATE)) (vis_server == VIS_TYPE_CLIENT_UPDATE))
return 0; return 0;
hdr_len = 0; buf_size = 1;
/* Estimate length */
spin_lock_irqsave(&vis_hash_lock, flags); spin_lock_irqsave(&vis_hash_lock, flags);
while (hash_iterate(vis_hash, &hashit_count)) {
info = hashit_count.bucket->data;
entries = (struct vis_info_entry *)
((char *)info + sizeof(struct vis_info));
for (i = 0; i < info->packet.entries; i++) {
if (entries[i].quality == 0)
continue;
vis_data_insert_interface(entries[i].src, &vis_if_list,
compare_orig(entries[i].src,
info->packet.vis_orig));
}
hlist_for_each_entry(entry, pos, &vis_if_list, list) {
buf_size += 18 + 26 * info->packet.entries;
/* add primary/secondary records */
if (compare_orig(entry->addr, info->packet.vis_orig))
buf_size +=
vis_data_count_prim_sec(&vis_if_list);
buf_size += 1;
}
hlist_for_each_entry_safe(entry, pos, n, &vis_if_list, list) {
hlist_del(&entry->list);
kfree(entry);
}
}
buff = kmalloc(buf_size, GFP_ATOMIC);
if (!buff) {
spin_unlock_irqrestore(&vis_hash_lock, flags);
return -ENOMEM;
}
buff[0] = '\0';
buff_pos = 0;
while (hash_iterate(vis_hash, &hashit)) { while (hash_iterate(vis_hash, &hashit)) {
info = hashit.bucket->data; info = hashit.bucket->data;
entries = (struct vis_info_entry *) entries = (struct vis_info_entry *)
((char *)info + sizeof(struct vis_info)); ((char *)info + sizeof(struct vis_info));
/* estimated line length */
if (count < bytes_written + 200)
break;
for (i = 0; i < info->packet.entries; i++) { for (i = 0; i < info->packet.entries; i++) {
if (entries[i].quality == 0) if (entries[i].quality == 0)
continue; continue;
...@@ -199,30 +252,22 @@ ssize_t vis_fill_buffer_text(struct net_device *net_dev, char *buff, ...@@ -199,30 +252,22 @@ ssize_t vis_fill_buffer_text(struct net_device *net_dev, char *buff,
hlist_for_each_entry(entry, pos, &vis_if_list, list) { hlist_for_each_entry(entry, pos, &vis_if_list, list) {
addr_to_string(tmp_addr_str, entry->addr); addr_to_string(tmp_addr_str, entry->addr);
tmp_len = sprintf(buff + bytes_written, buff_pos += sprintf(buff + buff_pos, "%s,",
"%s,", tmp_addr_str); tmp_addr_str);
for (i = 0; i < info->packet.entries; i++) for (i = 0; i < info->packet.entries; i++)
tmp_len += vis_data_read_entry( buff_pos += vis_data_read_entry(buff + buff_pos,
buff + bytes_written + tmp_len, &entries[i],
&entries[i], entry->addr, entry->addr,
entry->primary); entry->primary);
/* add primary/secondary records */ /* add primary/secondary records */
if (compare_orig(entry->addr, info->packet.vis_orig)) if (compare_orig(entry->addr, info->packet.vis_orig))
tmp_len += vis_data_read_prim_sec( buff_pos +=
buff + bytes_written + tmp_len, vis_data_read_prim_sec(buff + buff_pos,
&vis_if_list); &vis_if_list);
tmp_len += sprintf(buff + bytes_written + tmp_len,
"\n");
hdr_len += tmp_len;
if (off >= hdr_len) buff_pos += sprintf(buff + buff_pos, "\n");
continue;
bytes_written += tmp_len;
} }
hlist_for_each_entry_safe(entry, pos, n, &vis_if_list, list) { hlist_for_each_entry_safe(entry, pos, n, &vis_if_list, list) {
...@@ -230,9 +275,13 @@ ssize_t vis_fill_buffer_text(struct net_device *net_dev, char *buff, ...@@ -230,9 +275,13 @@ ssize_t vis_fill_buffer_text(struct net_device *net_dev, char *buff,
kfree(entry); kfree(entry);
} }
} }
spin_unlock_irqrestore(&vis_hash_lock, flags); spin_unlock_irqrestore(&vis_hash_lock, flags);
return bytes_written; seq_printf(seq, "%s", buff);
kfree(buff);
return 0;
} }
/* add the info packet to the send list, if it was not /* add the info packet to the send list, if it was not
......
...@@ -47,8 +47,7 @@ struct recvlist_node { ...@@ -47,8 +47,7 @@ struct recvlist_node {
extern struct hashtable_t *vis_hash; extern struct hashtable_t *vis_hash;
extern spinlock_t vis_hash_lock; extern spinlock_t vis_hash_lock;
ssize_t vis_fill_buffer_text(struct net_device *net_dev, char *buff, int vis_seq_print_text(struct seq_file *seq, void *offset);
size_t count, loff_t off);
void receive_server_sync_packet(struct bat_priv *bat_priv, void receive_server_sync_packet(struct bat_priv *bat_priv,
struct vis_packet *vis_packet, struct vis_packet *vis_packet,
int vis_info_len); int vis_info_len);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册