Merge branch 'for-3.11' of git://linux-nfs.org/~bfields/linux
[linux-2.6.git] / drivers / net / bonding / bond_debugfs.c
blob5fc4c2351478b21f98ba8ed2d2c329275e30ed39
1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/device.h>
4 #include <linux/netdevice.h>
6 #include "bonding.h"
7 #include "bond_alb.h"
9 #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_NET_NS)
11 #include <linux/debugfs.h>
12 #include <linux/seq_file.h>
14 static struct dentry *bonding_debug_root;
17 * Show RLB hash table
19 static int bond_debug_rlb_hash_show(struct seq_file *m, void *v)
21 struct bonding *bond = m->private;
22 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
23 struct rlb_client_info *client_info;
24 u32 hash_index;
26 if (bond->params.mode != BOND_MODE_ALB)
27 return 0;
29 seq_printf(m, "SourceIP DestinationIP "
30 "Destination MAC DEV\n");
32 spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
34 hash_index = bond_info->rx_hashtbl_used_head;
35 for (; hash_index != RLB_NULL_INDEX;
36 hash_index = client_info->used_next) {
37 client_info = &(bond_info->rx_hashtbl[hash_index]);
38 seq_printf(m, "%-15pI4 %-15pI4 %-17pM %s\n",
39 &client_info->ip_src,
40 &client_info->ip_dst,
41 &client_info->mac_dst,
42 client_info->slave->dev->name);
45 spin_unlock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
47 return 0;
50 static int bond_debug_rlb_hash_open(struct inode *inode, struct file *file)
52 return single_open(file, bond_debug_rlb_hash_show, inode->i_private);
55 static const struct file_operations bond_debug_rlb_hash_fops = {
56 .owner = THIS_MODULE,
57 .open = bond_debug_rlb_hash_open,
58 .read = seq_read,
59 .llseek = seq_lseek,
60 .release = single_release,
63 void bond_debug_register(struct bonding *bond)
65 if (!bonding_debug_root)
66 return;
68 bond->debug_dir =
69 debugfs_create_dir(bond->dev->name, bonding_debug_root);
71 if (!bond->debug_dir) {
72 pr_warning("%s: Warning: failed to register to debugfs\n",
73 bond->dev->name);
74 return;
77 debugfs_create_file("rlb_hash_table", 0400, bond->debug_dir,
78 bond, &bond_debug_rlb_hash_fops);
81 void bond_debug_unregister(struct bonding *bond)
83 if (!bonding_debug_root)
84 return;
86 debugfs_remove_recursive(bond->debug_dir);
89 void bond_debug_reregister(struct bonding *bond)
91 struct dentry *d;
93 if (!bonding_debug_root)
94 return;
96 d = debugfs_rename(bonding_debug_root, bond->debug_dir,
97 bonding_debug_root, bond->dev->name);
98 if (d) {
99 bond->debug_dir = d;
100 } else {
101 pr_warning("%s: Warning: failed to reregister, "
102 "so just unregister old one\n",
103 bond->dev->name);
104 bond_debug_unregister(bond);
108 void bond_create_debugfs(void)
110 bonding_debug_root = debugfs_create_dir("bonding", NULL);
112 if (!bonding_debug_root) {
113 pr_warning("Warning: Cannot create bonding directory"
114 " in debugfs\n");
118 void bond_destroy_debugfs(void)
120 debugfs_remove_recursive(bonding_debug_root);
121 bonding_debug_root = NULL;
125 #else /* !CONFIG_DEBUG_FS */
127 void bond_debug_register(struct bonding *bond)
131 void bond_debug_unregister(struct bonding *bond)
135 void bond_debug_reregister(struct bonding *bond)
139 void bond_create_debugfs(void)
143 void bond_destroy_debugfs(void)
147 #endif /* CONFIG_DEBUG_FS */