Skip to contentSkip to conversation

bonding: add the sysfs interface to see RLB hash table

PATCH In review Taku Izumi 4 participants 6 messages Nov 30, 2010 – Dec 1, 2010

Subsystems (3)
lore
Share & tools
lore

Taku Izumi

author
#0 lore raw

PATCH 1/1 bonding: add the sysfs interface to see RLB hash table

This patch provides the sysfs interface to see RLB hash table like the following:

# cat /sys/class/net/bond0/bonding/rlb_hash_table

SourceIP DestinationIP Destination MAC DEV

 10.124.196.205  10.124.196. 81 00:19:99:XX:XX:XX eth3
 10.124.196.205  10.124.196.222 00:0a:79:XX:XX:XX eth0
 10.124.196.205  10.124.196. 75 00:15:17:XX:XX:XX eth4
 10.124.196.205  10.124.196.  1 00:21:d8:XX:XX:XX eth3
 10.124.196.205  10.124.196.205 ff:ff:ff:ff:ff:ff eth0

This is helpful to check if the receive load balancing works as expected.

---
 drivers/net/bonding/bond_sysfs.c |   56 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
drivers/net/bonding/bond_sysfs.c +56 -0
Index: net-next/drivers/net/bonding/bond_sysfs.c
===================================================================
@@ -43,6 +43,7 @@
 #include <linux/nsproxy.h>
 
 #include "bonding.h"
+#include "bond_alb.h"
 
 #define to_dev(obj)	container_of(obj, struct device, kobj)
 #define to_bond(cd)	((struct bonding *)(netdev_priv(to_net_dev(cd))))
@@ -1643,6 +1644,60 @@ out:
 static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
 		   bonding_show_resend_igmp, bonding_store_resend_igmp);
 
+/*
+ *  Show RLB hash table
+ */
+#define RLB_NULL_INDEX  0xffffffff
+static ssize_t bonding_show_rlb_hashtable(struct device *d,
+					  struct device_attribute *attr,
+					  char *buf)
+{
+	int count = 0;
+	struct bonding *bond = to_bond(d);
+	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
+	struct rlb_client_info *client_info;
+	u32 hash_index;
+
+	if (bond->params.mode != BOND_MODE_ALB)
+		return count;
+
+	count += sprintf(buf + count, "SourceIP        "
+		"DestinationIP   Destination MAC   DEV\n");
+
+	spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
+
+	hash_index = bond_info->rx_hashtbl_head;
+	for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
+		client_info = &(bond_info->rx_hashtbl[hash_index]);
+
+		count += sprintf(buf + count,
+			"%3d.%3d.%3d.%3d %3d.%3d.%3d.%3d "
+			"%02x:%02x:%02x:%02x:%02x:%02x %s\n",
+			client_info->ip_src & 0xff,
+			(client_info->ip_src >> 8) & 0xff,
+			(client_info->ip_src >> 16) & 0xff,
+			(client_info->ip_src >> 24) & 0xff,
+			client_info->ip_dst & 0xff,
+			(client_info->ip_dst >> 8) & 0xff,
+			(client_info->ip_dst >> 16) & 0xff,
+			(client_info->ip_dst >> 24) & 0xff,
+			client_info->mac_dst[0],
+			client_info->mac_dst[1],
+			client_info->mac_dst[2],
+			client_info->mac_dst[3],
+			client_info->mac_dst[4],
+			client_info->mac_dst[5],
+			client_info->slave->dev->name);
+	}
+
+	spin_unlock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
+
+	return count;
+
+}
+static DEVICE_ATTR(rlb_hash_table, S_IRUGO, bonding_show_rlb_hashtable, NULL);
+
+
 static struct attribute *per_bond_attrs[] = {
 	&dev_attr_slaves.attr,
 	&dev_attr_mode.attr,
@@ -1671,6 +1726,7 @@ static struct attribute *per_bond_attrs[
 	&dev_attr_queue_id.attr,
 	&dev_attr_all_slaves_active.attr,
 	&dev_attr_resend_igmp.attr,
+	&dev_attr_rlb_hash_table.attr,
 	NULL,
 };
 
#1 lore raw
Quoted 12 lines · Taku Izumi

This patch provides the sysfs interface to see RLB hash table like the following:

# cat /sys/class/net/bond0/bonding/rlb_hash_table

SourceIP DestinationIP Destination MAC DEV

 10.124.196.205  10.124.196. 81 00:19:99:XX:XX:XX eth3
 10.124.196.205  10.124.196.222 00:0a:79:XX:XX:XX eth0
 10.124.196.205  10.124.196. 75 00:15:17:XX:XX:XX eth4
 10.124.196.205  10.124.196.  1 00:21:d8:XX:XX:XX eth3
 10.124.196.205  10.124.196.205 ff:ff:ff:ff:ff:ff eth0

why spaces in IP addresses ?

Quoted 44 lines

This is helpful to check if the receive load balancing works as expected.

---
 drivers/net/bonding/bond_sysfs.c |   56 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

Index: net-next/drivers/net/bonding/bond_sysfs.c
===================================================================

drivers/net/bonding/bond_sysfs.c +20 -0
@@ -43,6 +43,7 @@
 #include <linux/nsproxy.h>
 
 #include "bonding.h"
+#include "bond_alb.h"
 
 #define to_dev(obj)	container_of(obj, struct device, kobj)
 #define to_bond(cd)	((struct bonding *)(netdev_priv(to_net_dev(cd))))
@@ -1643,6 +1644,60 @@ out:
 static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
 		   bonding_show_resend_igmp, bonding_store_resend_igmp);
 
+/*
+ *  Show RLB hash table
+ */
+#define RLB_NULL_INDEX  0xffffffff
+static ssize_t bonding_show_rlb_hashtable(struct device *d,
+					  struct device_attribute *attr,
+					  char *buf)
+{
+	int count = 0;
+	struct bonding *bond = to_bond(d);
+	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
+	struct rlb_client_info *client_info;
+	u32 hash_index;
+
+	if (bond->params.mode != BOND_MODE_ALB)
+		return count;
+
+	count += sprintf(buf + count, "SourceIP        "
+		"DestinationIP   Destination MAC   DEV\n");

drivers/net/bonding/bond_sysfs.c out: · line 1675

Quoted 10 lines
drivers/net/bonding/bond_sysfs.c +10 -0
+
+	spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
+
+	hash_index = bond_info->rx_hashtbl_head;
+	for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
+		client_info = &(bond_info->rx_hashtbl[hash_index]);
+
+		count += sprintf(buf + count,
+			"%3d.%3d.%3d.%3d %3d.%3d.%3d.%3d "
+			"%02x:%02x:%02x:%02x:%02x:%02x %s\n",

Oh well, I guess you dont read Joe patches on netdev ;)

Please take a look at %pI4 and %pM

sprintf(buf + count, "%pI4 %pI4 %pM %s\n", ...)

Quoted 17 lines
drivers/net/bonding/bond_sysfs.c +17 -0
+			client_info->ip_src & 0xff,
+			(client_info->ip_src >> 8) & 0xff,
+			(client_info->ip_src >> 16) & 0xff,
+			(client_info->ip_src >> 24) & 0xff,
+			client_info->ip_dst & 0xff,
+			(client_info->ip_dst >> 8) & 0xff,
+			(client_info->ip_dst >> 16) & 0xff,
+			(client_info->ip_dst >> 24) & 0xff,
+			client_info->mac_dst[0],
+			client_info->mac_dst[1],
+			client_info->mac_dst[2],
+			client_info->mac_dst[3],
+			client_info->mac_dst[4],
+			client_info->mac_dst[5],
+			client_info->slave->dev->name);
+	}
+
#2 lore raw
Quoted 4 lines · Eric Dumazet
Quoted 3 lines · Taku Izumi

This patch provides the sysfs interface to see RLB hash table like the following:

Quoted 8 lines
Quoted 8 lines
# cat /sys/class/net/bond0/bonding/rlb_hash_table

SourceIP DestinationIP Destination MAC DEV

 10.124.196.205  10.124.196. 81 00:19:99:XX:XX:XX eth3
 10.124.196.205  10.124.196.222 00:0a:79:XX:XX:XX eth0
 10.124.196.205  10.124.196. 75 00:15:17:XX:XX:XX eth4
 10.124.196.205  10.124.196.  1 00:21:d8:XX:XX:XX eth3
 10.124.196.205  10.124.196.205 ff:ff:ff:ff:ff:ff eth0

I'm reasonably sure something like this isn't going to be
acceptable in sysfs (it's much too large).

In the proc file that bonding already uses, this type of
information isn't unreasonable, but I don't think that is the best place for this, for two reasons.

First, the table may have up to 256 entries. Therefore, a
sufficiently populated table will easily overrun the one page of space available to a sysfs show function or a proc seq_printf (per iteration), so it will have to handle that. The current code in bonding to do its proc file already iterates over the slaves; adding another iteration loop to handle this table seems overly complicated. A well populated table would also make the current proc file's output rather verbose, particularly if the TLB table is added later.

Second, it would have to hold the hash table spin lock, which
may provide an easy way to mess with bonding (user space doing "while 1 cat rlb_hash_table > /dev/null").

Therefore, I'd suggest this go into debugfs somewhere, perhaps a
/sys/kernel/debug/bonding/rlb_hash_table (perhaps with a tlb_hash_table as the logical pairing for the TX side), readable only by root.

Alternatively, if there are objections to using debufs, a new
file in /proc/net/bonding could be used, although that seems cumbersome (because it would have to be named to avoid conflicts, e.g., /proc/net/bonding/bond0_rlb_hash_table).

Quoted 62 lines

why spaces in IP addresses ?

Quoted 46 lines

This is helpful to check if the receive load balancing works as expected.

---
 drivers/net/bonding/bond_sysfs.c |   56 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

Index: net-next/drivers/net/bonding/bond_sysfs.c
===================================================================

drivers/net/bonding/bond_sysfs.c +20 -0
@@ -43,6 +43,7 @@
 #include <linux/nsproxy.h>
 
 #include "bonding.h"
+#include "bond_alb.h"
 
 #define to_dev(obj)	container_of(obj, struct device, kobj)
 #define to_bond(cd)	((struct bonding *)(netdev_priv(to_net_dev(cd))))
@@ -1643,6 +1644,60 @@ out:
 static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
 		   bonding_show_resend_igmp, bonding_store_resend_igmp);
 
+/*
+ *  Show RLB hash table
+ */
+#define RLB_NULL_INDEX  0xffffffff
 
 
+static ssize_t bonding_show_rlb_hashtable(struct device *d,
+					  struct device_attribute *attr,
+					  char *buf)
+{
+	int count = 0;
+	struct bonding *bond = to_bond(d);
+	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
+	struct rlb_client_info *client_info;
+	u32 hash_index;
+
+	if (bond->params.mode != BOND_MODE_ALB)
+		return count;
+
+	count += sprintf(buf + count, "SourceIP        "
+		"DestinationIP   Destination MAC   DEV\n");

drivers/net/bonding/bond_sysfs.c out: · line 1677

Quoted 10 lines
drivers/net/bonding/bond_sysfs.c +10 -0
+
+	spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
+
+	hash_index = bond_info->rx_hashtbl_head;
+	for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
+		client_info = &(bond_info->rx_hashtbl[hash_index]);
+
+		count += sprintf(buf + count,
+			"%3d.%3d.%3d.%3d %3d.%3d.%3d.%3d "
+			"%02x:%02x:%02x:%02x:%02x:%02x %s\n",

Oh well, I guess you dont read Joe patches on netdev ;)

Quoted 1 line

Please take a look at %pI4 and %pM

	Agreed.

	-J
Quoted 12 lines

sprintf(buf + count, "%pI4 %pI4 %pM %s\n", ...)

Quoted 9 lines
drivers/net/bonding/bond_sysfs.c +9 -0
+			client_info->ip_src & 0xff,
+			(client_info->ip_src >> 8) & 0xff,
+			(client_info->ip_src >> 16) & 0xff,
+			(client_info->ip_src >> 24) & 0xff,
+			client_info->ip_dst & 0xff,
+			(client_info->ip_dst >> 8) & 0xff,
+			(client_info->ip_dst >> 16) & 0xff,
+			(client_info->ip_dst >> 24) & 0xff,
+			client_info->mac_dst[0],
Quoted 9 lines

drivers/net/bonding/bond_sysfs.c out: · line 1692

Quoted 8 lines
drivers/net/bonding/bond_sysfs.c +8 -0
+			client_info->mac_dst[1],
+			client_info->mac_dst[2],
+			client_info->mac_dst[3],
+			client_info->mac_dst[4],
+			client_info->mac_dst[5],
+			client_info->slave->dev->name);
+	}
+

---
-Jay Vosburgh, IBM Linux Technology Center, [email protected]

author
#3 lore raw

Dear Jay Volburgh and Stephen Hemminger:

Quoted 35 lines · Jay Vosburgh
Quoted 4 lines · Eric Dumazet
Quoted 3 lines · Taku Izumi

This patch provides the sysfs interface to see RLB hash table like the following:

Quoted 8 lines
Quoted 8 lines
# cat /sys/class/net/bond0/bonding/rlb_hash_table

SourceIP DestinationIP Destination MAC DEV

  10.124.196.205  10.124.196. 81 00:19:99:XX:XX:XX eth3
  10.124.196.205  10.124.196.222 00:0a:79:XX:XX:XX eth0
  10.124.196.205  10.124.196. 75 00:15:17:XX:XX:XX eth4
  10.124.196.205  10.124.196.  1 00:21:d8:XX:XX:XX eth3
  10.124.196.205  10.124.196.205 ff:ff:ff:ff:ff:ff eth0

I'm reasonably sure something like this isn't going to be
acceptable in sysfs (it's much too large).

In the proc file that bonding already uses, this type of
information isn't unreasonable, but I don't think that is the best place for this, for two reasons.

First, the table may have up to 256 entries. Therefore, a
sufficiently populated table will easily overrun the one page of space available to a sysfs show function or a proc seq_printf (per iteration), so it will have to handle that. The current code in bonding to do its proc file already iterates over the slaves; adding another iteration loop to handle this table seems overly complicated. A well populated table would also make the current proc file's output rather verbose, particularly if the TLB table is added later.

Second, it would have to hold the hash table spin lock, which
may provide an easy way to mess with bonding (user space doing "while 1 cat rlb_hash_table> /dev/null").

Quoted 9 lines

Therefore, I'd suggest this go into debugfs somewhere, perhaps a
/sys/kernel/debug/bonding/rlb_hash_table (perhaps with a tlb_hash_table as the logical pairing for the TX side), readable only by root.

Alternatively, if there are objections to using debufs, a new
file in /proc/net/bonding could be used, although that seems cumbersome (because it would have to be named to avoid conflicts, e.g., /proc/net/bonding/bond0_rlb_hash_table).

I understand the sysfs is not the proper place. I have no objection to using debugfs. I'll try to rewrite my patch.

Taku Izumi <[email protected]>

author
#4 lore raw
In reply to Eric Dumazet
Quoted 13 lines · Eric Dumazet

drivers/net/bonding/bond_sysfs.c out: · line 1675

Quoted 7 lines · Taku Izumi
drivers/net/bonding/bond_sysfs.c +7 -0
+	hash_index = bond_info->rx_hashtbl_head;
+	for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
+		client_info =&(bond_info->rx_hashtbl[hash_index]);
+
+		count += sprintf(buf + count,
+			"%3d.%3d.%3d.%3d %3d.%3d.%3d.%3d "
+			"%02x:%02x:%02x:%02x:%02x:%02x %s\n",

Oh well, I guess you dont read Joe patches on netdev ;)

Quoted 3 lines

Please take a look at %pI4 and %pM

sprintf(buf + count, "%pI4 %pI4 %pM %s\n", ...)

Thank you for your advice. I've become a little wiser..

Taku Izumi <[email protected]>

#5 lore raw
In reply to Taku Izumi
Quoted 8 lines · On Tue, 30 Nov 2010 19:01:41 +0900 Taku Izumi <[email protected]> wrote:
# cat /sys/class/net/bond0/bonding/rlb_hash_table

SourceIP DestinationIP Destination MAC DEV

 10.124.196.205  10.124.196. 81 00:19:99:XX:XX:XX eth3
 10.124.196.205  10.124.196.222 00:0a:79:XX:XX:XX eth0
 10.124.196.205  10.124.196. 75 00:15:17:XX:XX:XX eth4
 10.124.196.205  10.124.196.  1 00:21:d8:XX:XX:XX eth3
 10.124.196.205  10.124.196.205 ff:ff:ff:ff:ff:ff eth0

This violates the one value per file convention of sysfs.
It belongs in /proc. Unfortunately there already is a /proc/net/bonding/bond0 but it is a file not a directory.