bond_debugfs.c 3.0 KB

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