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