Loading...
1#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/device.h>
4#include <linux/netdevice.h>
5
6#include "bonding.h"
7#include "bond_alb.h"
8
9#if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_NET_NS)
10
11#include <linux/debugfs.h>
12#include <linux/seq_file.h>
13
14static struct dentry *bonding_debug_root;
15
16/*
17 * Show RLB hash table
18 */
19static int bond_debug_rlb_hash_show(struct seq_file *m, void *v)
20{
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;
25
26 if (bond->params.mode != BOND_MODE_ALB)
27 return 0;
28
29 seq_printf(m, "SourceIP DestinationIP "
30 "Destination MAC DEV\n");
31
32 spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
33
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);
43 }
44
45 spin_unlock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
46
47 return 0;
48}
49
50static int bond_debug_rlb_hash_open(struct inode *inode, struct file *file)
51{
52 return single_open(file, bond_debug_rlb_hash_show, inode->i_private);
53}
54
55static 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,
61};
62
63void bond_debug_register(struct bonding *bond)
64{
65 if (!bonding_debug_root)
66 return;
67
68 bond->debug_dir =
69 debugfs_create_dir(bond->dev->name, bonding_debug_root);
70
71 if (!bond->debug_dir) {
72 pr_warn("%s: Warning: failed to register to debugfs\n",
73 bond->dev->name);
74 return;
75 }
76
77 debugfs_create_file("rlb_hash_table", 0400, bond->debug_dir,
78 bond, &bond_debug_rlb_hash_fops);
79}
80
81void bond_debug_unregister(struct bonding *bond)
82{
83 if (!bonding_debug_root)
84 return;
85
86 debugfs_remove_recursive(bond->debug_dir);
87}
88
89void bond_debug_reregister(struct bonding *bond)
90{
91 struct dentry *d;
92
93 if (!bonding_debug_root)
94 return;
95
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_warn("%s: Warning: failed to reregister, so just unregister old one\n",
102 bond->dev->name);
103 bond_debug_unregister(bond);
104 }
105}
106
107void bond_create_debugfs(void)
108{
109 bonding_debug_root = debugfs_create_dir("bonding", NULL);
110
111 if (!bonding_debug_root) {
112 pr_warn("Warning: Cannot create bonding directory in debugfs\n");
113 }
114}
115
116void bond_destroy_debugfs(void)
117{
118 debugfs_remove_recursive(bonding_debug_root);
119 bonding_debug_root = NULL;
120}
121
122
123#else /* !CONFIG_DEBUG_FS */
124
125void bond_debug_register(struct bonding *bond)
126{
127}
128
129void bond_debug_unregister(struct bonding *bond)
130{
131}
132
133void bond_debug_reregister(struct bonding *bond)
134{
135}
136
137void bond_create_debugfs(void)
138{
139}
140
141void bond_destroy_debugfs(void)
142{
143}
144
145#endif /* CONFIG_DEBUG_FS */
1#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/device.h>
4#include <linux/netdevice.h>
5
6#include <net/bonding.h>
7#include <net/bond_alb.h>
8
9#if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_NET_NS)
10
11#include <linux/debugfs.h>
12#include <linux/seq_file.h>
13
14static struct dentry *bonding_debug_root;
15
16/* Show RLB hash table */
17static int bond_debug_rlb_hash_show(struct seq_file *m, void *v)
18{
19 struct bonding *bond = m->private;
20 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
21 struct rlb_client_info *client_info;
22 u32 hash_index;
23
24 if (BOND_MODE(bond) != BOND_MODE_ALB)
25 return 0;
26
27 seq_printf(m, "SourceIP DestinationIP "
28 "Destination MAC DEV\n");
29
30 spin_lock_bh(&bond->mode_lock);
31
32 hash_index = bond_info->rx_hashtbl_used_head;
33 for (; hash_index != RLB_NULL_INDEX;
34 hash_index = client_info->used_next) {
35 client_info = &(bond_info->rx_hashtbl[hash_index]);
36 seq_printf(m, "%-15pI4 %-15pI4 %-17pM %s\n",
37 &client_info->ip_src,
38 &client_info->ip_dst,
39 &client_info->mac_dst,
40 client_info->slave->dev->name);
41 }
42
43 spin_unlock_bh(&bond->mode_lock);
44
45 return 0;
46}
47
48static int bond_debug_rlb_hash_open(struct inode *inode, struct file *file)
49{
50 return single_open(file, bond_debug_rlb_hash_show, inode->i_private);
51}
52
53static const struct file_operations bond_debug_rlb_hash_fops = {
54 .owner = THIS_MODULE,
55 .open = bond_debug_rlb_hash_open,
56 .read = seq_read,
57 .llseek = seq_lseek,
58 .release = single_release,
59};
60
61void bond_debug_register(struct bonding *bond)
62{
63 if (!bonding_debug_root)
64 return;
65
66 bond->debug_dir =
67 debugfs_create_dir(bond->dev->name, bonding_debug_root);
68
69 if (!bond->debug_dir) {
70 netdev_warn(bond->dev, "failed to register to debugfs\n");
71 return;
72 }
73
74 debugfs_create_file("rlb_hash_table", 0400, bond->debug_dir,
75 bond, &bond_debug_rlb_hash_fops);
76}
77
78void bond_debug_unregister(struct bonding *bond)
79{
80 if (!bonding_debug_root)
81 return;
82
83 debugfs_remove_recursive(bond->debug_dir);
84}
85
86void bond_debug_reregister(struct bonding *bond)
87{
88 struct dentry *d;
89
90 if (!bonding_debug_root)
91 return;
92
93 d = debugfs_rename(bonding_debug_root, bond->debug_dir,
94 bonding_debug_root, bond->dev->name);
95 if (d) {
96 bond->debug_dir = d;
97 } else {
98 netdev_warn(bond->dev, "failed to reregister, so just unregister old one\n");
99 bond_debug_unregister(bond);
100 }
101}
102
103void bond_create_debugfs(void)
104{
105 bonding_debug_root = debugfs_create_dir("bonding", NULL);
106
107 if (!bonding_debug_root) {
108 pr_warn("Warning: Cannot create bonding directory in debugfs\n");
109 }
110}
111
112void bond_destroy_debugfs(void)
113{
114 debugfs_remove_recursive(bonding_debug_root);
115 bonding_debug_root = NULL;
116}
117
118
119#else /* !CONFIG_DEBUG_FS */
120
121void bond_debug_register(struct bonding *bond)
122{
123}
124
125void bond_debug_unregister(struct bonding *bond)
126{
127}
128
129void bond_debug_reregister(struct bonding *bond)
130{
131}
132
133void bond_create_debugfs(void)
134{
135}
136
137void bond_destroy_debugfs(void)
138{
139}
140
141#endif /* CONFIG_DEBUG_FS */