Neil Horman 2539fae
commit 7eacd03810960823393521063734fc8188446bca
Neil Horman 2539fae
Author: Neil Horman <nhorman@tuxdriver.com>
Neil Horman 2539fae
Date:   Fri Sep 13 11:05:33 2013 -0400
Neil Horman 2539fae
Neil Horman 2539fae
    bonding: Make alb learning packet interval configurable
Neil Horman 2539fae
    
Neil Horman 2539fae
    running bonding in ALB mode requires that learning packets be sent periodically,
Neil Horman 2539fae
    so that the switch knows where to send responding traffic.  However, depending
Neil Horman 2539fae
    on switch configuration, there may not be any need to send traffic at the
Neil Horman 2539fae
    default rate of 3 packets per second, which represents little more than wasted
Neil Horman 2539fae
    data.  Allow the ALB learning packet interval to be made configurable via sysfs
Neil Horman 2539fae
    
Neil Horman 2539fae
    Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Neil Horman 2539fae
    Acked-by: Acked-by: Veaceslav Falico <vfalico@redhat.com>
Neil Horman 2539fae
    CC: Jay Vosburgh <fubar@us.ibm.com>
Neil Horman 2539fae
    CC: Andy Gospodarek <andy@greyhouse.net>
Neil Horman 2539fae
    CC: "David S. Miller" <davem@davemloft.net>
Neil Horman 2539fae
    Signed-off-by: Andy Gospodarek <andy@greyhouse.net>
Neil Horman 2539fae
    Signed-off-by: David S. Miller <davem@davemloft.net>
Neil Horman 2539fae
Neil Horman 2539fae
diff --git a/Documentation/networking/bonding.txt b/Documentation/networking/bonding.txt
Neil Horman 2539fae
index 87bbcfe..9b28e71 100644
Neil Horman 2539fae
--- a/Documentation/networking/bonding.txt
Neil Horman 2539fae
+++ b/Documentation/networking/bonding.txt
Neil Horman 2539fae
@@ -1362,6 +1362,12 @@ To add ARP targets:
Neil Horman 2539fae
 To remove an ARP target:
Neil Horman 2539fae
 # echo -192.168.0.100 > /sys/class/net/bond0/bonding/arp_ip_target
Neil Horman 2539fae
 
Neil Horman 2539fae
+To configure the interval between learning packet transmits:
Neil Horman 2539fae
+# echo 12 > /sys/class/net/bond0/bonding/lp_interval
Neil Horman 2539fae
+	NOTE: the lp_inteval is the number of seconds between instances where
Neil Horman 2539fae
+the bonding driver sends learning packets to each slaves peer switch.  The
Neil Horman 2539fae
+default interval is 1 second.
Neil Horman 2539fae
+
Neil Horman 2539fae
 Example Configuration
Neil Horman 2539fae
 ---------------------
Neil Horman 2539fae
 	We begin with the same example that is shown in section 3.3,
Neil Horman 2539fae
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
Neil Horman 2539fae
index 91f179d..f428ef57 100644
Neil Horman 2539fae
--- a/drivers/net/bonding/bond_alb.c
Neil Horman 2539fae
+++ b/drivers/net/bonding/bond_alb.c
Neil Horman 2539fae
@@ -1472,7 +1472,7 @@ void bond_alb_monitor(struct work_struct *work)
Neil Horman 2539fae
 	bond_info->lp_counter++;
Neil Horman 2539fae
 
Neil Horman 2539fae
 	/* send learning packets */
Neil Horman 2539fae
-	if (bond_info->lp_counter >= BOND_ALB_LP_TICKS) {
Neil Horman 2539fae
+	if (bond_info->lp_counter >= BOND_ALB_LP_TICKS(bond)) {
Neil Horman 2539fae
 		/* change of curr_active_slave involves swapping of mac addresses.
Neil Horman 2539fae
 		 * in order to avoid this swapping from happening while
Neil Horman 2539fae
 		 * sending the learning packets, the curr_slave_lock must be held for
Neil Horman 2539fae
diff --git a/drivers/net/bonding/bond_alb.h b/drivers/net/bonding/bond_alb.h
Neil Horman 2539fae
index 28d8e4c..c5eff5d 100644
Neil Horman 2539fae
--- a/drivers/net/bonding/bond_alb.h
Neil Horman 2539fae
+++ b/drivers/net/bonding/bond_alb.h
Neil Horman 2539fae
@@ -36,14 +36,15 @@ struct slave;
Neil Horman 2539fae
 					 * Used for division - never set
Neil Horman 2539fae
 					 * to zero !!!
Neil Horman 2539fae
 					 */
Neil Horman 2539fae
-#define BOND_ALB_LP_INTERVAL	    1	/* In seconds, periodic send of
Neil Horman 2539fae
-					 * learning packets to the switch
Neil Horman 2539fae
-					 */
Neil Horman 2539fae
+#define BOND_ALB_DEFAULT_LP_INTERVAL 1
Neil Horman 2539fae
+#define BOND_ALB_LP_INTERVAL(bond) (bond->params.lp_interval)	/* In seconds, periodic send of
Neil Horman 2539fae
+								 * learning packets to the switch
Neil Horman 2539fae
+								 */
Neil Horman 2539fae
 
Neil Horman 2539fae
 #define BOND_TLB_REBALANCE_TICKS (BOND_TLB_REBALANCE_INTERVAL \
Neil Horman 2539fae
 				  * ALB_TIMER_TICKS_PER_SEC)
Neil Horman 2539fae
 
Neil Horman 2539fae
-#define BOND_ALB_LP_TICKS (BOND_ALB_LP_INTERVAL \
Neil Horman 2539fae
+#define BOND_ALB_LP_TICKS(bond) (BOND_ALB_LP_INTERVAL(bond) \
Neil Horman 2539fae
 			   * ALB_TIMER_TICKS_PER_SEC)
Neil Horman 2539fae
 
Neil Horman 2539fae
 #define TLB_HASH_TABLE_SIZE 256	/* The size of the clients hash table.
Neil Horman 2539fae
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
Neil Horman 2539fae
index 72df399..55bbb8b 100644
Neil Horman 2539fae
--- a/drivers/net/bonding/bond_main.c
Neil Horman 2539fae
+++ b/drivers/net/bonding/bond_main.c
Neil Horman 2539fae
@@ -4416,6 +4416,7 @@ static int bond_check_params(struct bond_params *params)
Neil Horman 2539fae
 	params->all_slaves_active = all_slaves_active;
Neil Horman 2539fae
 	params->resend_igmp = resend_igmp;
Neil Horman 2539fae
 	params->min_links = min_links;
Neil Horman 2539fae
+	params->lp_interval = BOND_ALB_DEFAULT_LP_INTERVAL;
Neil Horman 2539fae
 
Neil Horman 2539fae
 	if (primary) {
Neil Horman 2539fae
 		strncpy(params->primary, primary, IFNAMSIZ);
Neil Horman 2539fae
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
Neil Horman 2539fae
index eeab40b..c29b836 100644
Neil Horman 2539fae
--- a/drivers/net/bonding/bond_sysfs.c
Neil Horman 2539fae
+++ b/drivers/net/bonding/bond_sysfs.c
Neil Horman 2539fae
@@ -1699,6 +1699,44 @@ out:
Neil Horman 2539fae
 static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
Neil Horman 2539fae
 		   bonding_show_resend_igmp, bonding_store_resend_igmp);
Neil Horman 2539fae
 
Neil Horman 2539fae
+
Neil Horman 2539fae
+static ssize_t bonding_show_lp_interval(struct device *d,
Neil Horman 2539fae
+					struct device_attribute *attr,
Neil Horman 2539fae
+					char *buf)
Neil Horman 2539fae
+{
Neil Horman 2539fae
+	struct bonding *bond = to_bond(d);
Neil Horman 2539fae
+	return sprintf(buf, "%d\n", bond->params.lp_interval);
Neil Horman 2539fae
+}
Neil Horman 2539fae
+
Neil Horman 2539fae
+static ssize_t bonding_store_lp_interval(struct device *d,
Neil Horman 2539fae
+					 struct device_attribute *attr,
Neil Horman 2539fae
+					 const char *buf, size_t count)
Neil Horman 2539fae
+{
Neil Horman 2539fae
+	struct bonding *bond = to_bond(d);
Neil Horman 2539fae
+	int new_value, ret = count;
Neil Horman 2539fae
+
Neil Horman 2539fae
+	if (sscanf(buf, "%d", &new_value) != 1) {
Neil Horman 2539fae
+		pr_err("%s: no lp interval value specified.\n",
Neil Horman 2539fae
+			bond->dev->name);
Neil Horman 2539fae
+		ret = -EINVAL;
Neil Horman 2539fae
+		goto out;
Neil Horman 2539fae
+	}
Neil Horman 2539fae
+
Neil Horman 2539fae
+	if (new_value <= 0) {
Neil Horman 2539fae
+		pr_err ("%s: lp_interval must be between 1 and %d\n",
Neil Horman 2539fae
+			bond->dev->name, INT_MAX);
Neil Horman 2539fae
+		ret = -EINVAL;
Neil Horman 2539fae
+		goto out;
Neil Horman 2539fae
+	}
Neil Horman 2539fae
+
Neil Horman 2539fae
+	bond->params.lp_interval = new_value;
Neil Horman 2539fae
+out:
Neil Horman 2539fae
+	return ret;
Neil Horman 2539fae
+}
Neil Horman 2539fae
+
Neil Horman 2539fae
+static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
Neil Horman 2539fae
+		   bonding_show_lp_interval, bonding_store_lp_interval);
Neil Horman 2539fae
+
Neil Horman 2539fae
 static struct attribute *per_bond_attrs[] = {
Neil Horman 2539fae
 	&dev_attr_slaves.attr,
Neil Horman 2539fae
 	&dev_attr_mode.attr,
Neil Horman 2539fae
@@ -1729,6 +1767,7 @@ static struct attribute *per_bond_attrs[] = {
Neil Horman 2539fae
 	&dev_attr_all_slaves_active.attr,
Neil Horman 2539fae
 	&dev_attr_resend_igmp.attr,
Neil Horman 2539fae
 	&dev_attr_min_links.attr,
Neil Horman 2539fae
+	&dev_attr_lp_interval.attr,
Neil Horman 2539fae
 	NULL,
Neil Horman 2539fae
 };
Neil Horman 2539fae
 
Neil Horman 2539fae
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
Neil Horman 2539fae
index 7ad8bd5..03cf3fd 100644
Neil Horman 2539fae
--- a/drivers/net/bonding/bonding.h
Neil Horman 2539fae
+++ b/drivers/net/bonding/bonding.h
Neil Horman 2539fae
@@ -176,6 +176,7 @@ struct bond_params {
Neil Horman 2539fae
 	int tx_queues;
Neil Horman 2539fae
 	int all_slaves_active;
Neil Horman 2539fae
 	int resend_igmp;
Neil Horman 2539fae
+	int lp_interval;
Neil Horman 2539fae
 };
Neil Horman 2539fae
 
Neil Horman 2539fae
 struct bond_parm_tbl {