bonding: Allow userspace to set actors' system_priority in AD system
authorMahesh Bandewar <maheshb@google.com>
Sat, 9 May 2015 07:01:55 +0000 (00:01 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 11 May 2015 14:59:31 +0000 (10:59 -0400)
This patch allows user to randomize the system-priority in an ad-system.
The allowed range is 1 - 0xFFFF while default value is 0xFFFF. If user
does not specify this value, the system defaults to 0xFFFF, which is
what it was before this patch.

Following example code could set the value -
    # modprobe bonding mode=4
    # sys_prio=$(( 1 + RANDOM + RANDOM ))
    # echo $sys_prio > /sys/class/net/bond0/bonding/ad_actor_sys_prio
    # echo +eth1 > /sys/class/net/bond0/bonding/slaves
    ...
    # ip link set bond0 up

Signed-off-by: Mahesh Bandewar <maheshb@google.com>
Reviewed-by: Nikolay Aleksandrov <nikolay@redhat.com>
[jt: * fixed up style issues reported by checkpatch
     * changed how the default value is set in bond_check_params(), this
       makes the default consistent between what gets set for a new bond
       and what the default is claimed to be in the bonding options.]
Signed-off-by: Jonathan Toppins <jtoppins@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Documentation/networking/bonding.txt
drivers/net/bonding/bond_3ad.c
drivers/net/bonding/bond_main.c
drivers/net/bonding/bond_options.c
drivers/net/bonding/bond_procfs.c
drivers/net/bonding/bond_sysfs.c
include/net/bond_options.h
include/net/bonding.h

index 83bf4986baeabbcc75e03abd5e3d50edd3e97962..34946115acec45d510eac470d8e35053948d4533 100644 (file)
@@ -178,6 +178,15 @@ active_slave
        active slave, or the empty string if there is no active slave or
        the current mode does not use an active slave.
 
+ad_actor_sys_prio
+
+       In an AD system, this specifies the system priority. The allowed range
+       is 1 - 65535. If the value is not specified, it takes 65535 as the
+       default value.
+
+       This parameter has effect only in 802.3ad mode and is available through
+       SysFs interface.
+
 ad_select
 
        Specifies the 802.3ad aggregation selection logic to use.  The
index fbd54f0e32e8d7baf7e1f2de3c5155201aeccfea..4c003bc87d4b03ff0e23e4d452b2e4836570a4e4 100644 (file)
@@ -1908,7 +1908,8 @@ void bond_3ad_initialize(struct bonding *bond, u16 tick_resolution)
 
                BOND_AD_INFO(bond).aggregator_identifier = 0;
 
-               BOND_AD_INFO(bond).system.sys_priority = 0xFFFF;
+               BOND_AD_INFO(bond).system.sys_priority =
+                       bond->params.ad_actor_sys_prio;
                BOND_AD_INFO(bond).system.sys_mac_addr = *((struct mac_addr *)bond->dev->dev_addr);
 
                /* initialize how many times this module is called in one
@@ -1959,6 +1960,8 @@ void bond_3ad_bind_slave(struct slave *slave)
                        port->sm_vars &= ~AD_PORT_LACP_ENABLED;
                /* actor system is the bond's system */
                port->actor_system = BOND_AD_INFO(bond).system.sys_mac_addr;
+               port->actor_system_priority =
+                   BOND_AD_INFO(bond).system.sys_priority;
                /* tx timer(to verify that no more than MAX_TX_IN_SECOND
                 * lacpdu's are sent in one second)
                 */
index d5fe5d5f490f3efa70e022fdac9b64bd89311e22..5f2f28f0e927f83ece002185658a73e10fb7159d 100644 (file)
@@ -4140,6 +4140,7 @@ static int bond_check_params(struct bond_params *params)
        struct bond_opt_value newval;
        const struct bond_opt_value *valptr;
        int arp_all_targets_value;
+       u16 ad_actor_sys_prio = 0;
 
        /* Convert string parameters. */
        if (mode) {
@@ -4434,6 +4435,16 @@ static int bond_check_params(struct bond_params *params)
                fail_over_mac_value = BOND_FOM_NONE;
        }
 
+       bond_opt_initstr(&newval, "default");
+       valptr = bond_opt_parse(
+                       bond_opt_get(BOND_OPT_AD_ACTOR_SYS_PRIO),
+                                    &newval);
+       if (!valptr) {
+               pr_err("Error: No ad_actor_sys_prio default value");
+               return -EINVAL;
+       }
+       ad_actor_sys_prio = valptr->value;
+
        if (lp_interval == 0) {
                pr_warn("Warning: ip_interval must be between 1 and %d, so it was reset to %d\n",
                        INT_MAX, BOND_ALB_DEFAULT_LP_INTERVAL);
@@ -4462,6 +4473,7 @@ static int bond_check_params(struct bond_params *params)
        params->lp_interval = lp_interval;
        params->packets_per_slave = packets_per_slave;
        params->tlb_dynamic_lb = 1; /* Default value */
+       params->ad_actor_sys_prio = ad_actor_sys_prio;
        if (packets_per_slave > 0) {
                params->reciprocal_packets_per_slave =
                        reciprocal_value(packets_per_slave);
index 4df28943d2229035166d2bb4a72ec11c8f9671c5..d2b47e5e99f7b7a0ee05b5ec15c81ae0c2092e62 100644 (file)
@@ -70,6 +70,8 @@ static int bond_option_slaves_set(struct bonding *bond,
                                  const struct bond_opt_value *newval);
 static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
                                  const struct bond_opt_value *newval);
+static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
+                                            const struct bond_opt_value *newval);
 
 
 static const struct bond_opt_value bond_mode_tbl[] = {
@@ -186,6 +188,12 @@ static const struct bond_opt_value bond_tlb_dynamic_lb_tbl[] = {
        { NULL,  -1, 0}
 };
 
+static const struct bond_opt_value bond_ad_actor_sys_prio_tbl[] = {
+       { "minval",  1,     BOND_VALFLAG_MIN},
+       { "maxval",  65535, BOND_VALFLAG_MAX | BOND_VALFLAG_DEFAULT},
+       { NULL,      -1,    0},
+};
+
 static const struct bond_option bond_opts[BOND_OPT_LAST] = {
        [BOND_OPT_MODE] = {
                .id = BOND_OPT_MODE,
@@ -379,7 +387,15 @@ static const struct bond_option bond_opts[BOND_OPT_LAST] = {
                .values = bond_tlb_dynamic_lb_tbl,
                .flags = BOND_OPTFLAG_IFDOWN,
                .set = bond_option_tlb_dynamic_lb_set,
-       }
+       },
+       [BOND_OPT_AD_ACTOR_SYS_PRIO] = {
+               .id = BOND_OPT_AD_ACTOR_SYS_PRIO,
+               .name = "ad_actor_sys_prio",
+               .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
+               .flags = BOND_OPTFLAG_IFDOWN,
+               .values = bond_ad_actor_sys_prio_tbl,
+               .set = bond_option_ad_actor_sys_prio_set,
+       },
 };
 
 /* Searches for an option by name */
@@ -1349,3 +1365,13 @@ static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
 
        return 0;
 }
+
+static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
+                                            const struct bond_opt_value *newval)
+{
+       netdev_info(bond->dev, "Setting ad_actor_sys_prio to (%llu)\n",
+                   newval->value);
+
+       bond->params.ad_actor_sys_prio = newval->value;
+       return 0;
+}
index b20b35acb47d3465063cdde30a1018321b344b56..11369299e7e582912d7ef03c575815efd207f5cc 100644 (file)
@@ -135,6 +135,8 @@ static void bond_info_show_master(struct seq_file *seq)
                                          bond->params.ad_select);
                seq_printf(seq, "Aggregator selection policy (ad_select): %s\n",
                           optval->string);
+               seq_printf(seq, "System priority: %d\n",
+                          BOND_AD_INFO(bond).system.sys_priority);
 
                if (__bond_3ad_get_active_agg_info(bond, &ad_info)) {
                        seq_printf(seq, "bond %s has no active aggregator\n",
index 7e9e151d4d6168821e28ef82e8c197b2c4666b87..4a7626611ca64b1b023c6253912b29c9a281ee77 100644 (file)
@@ -692,6 +692,20 @@ static ssize_t bonding_show_packets_per_slave(struct device *d,
 static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR,
                   bonding_show_packets_per_slave, bonding_sysfs_store_option);
 
+static ssize_t bonding_show_ad_actor_sys_prio(struct device *d,
+                                             struct device_attribute *attr,
+                                             char *buf)
+{
+       struct bonding *bond = to_bond(d);
+
+       if (BOND_MODE(bond) == BOND_MODE_8023AD)
+               return sprintf(buf, "%hu\n", bond->params.ad_actor_sys_prio);
+
+       return 0;
+}
+static DEVICE_ATTR(ad_actor_sys_prio, S_IRUGO | S_IWUSR,
+                  bonding_show_ad_actor_sys_prio, bonding_sysfs_store_option);
+
 static struct attribute *per_bond_attrs[] = {
        &dev_attr_slaves.attr,
        &dev_attr_mode.attr,
@@ -725,6 +739,7 @@ static struct attribute *per_bond_attrs[] = {
        &dev_attr_lp_interval.attr,
        &dev_attr_packets_per_slave.attr,
        &dev_attr_tlb_dynamic_lb.attr,
+       &dev_attr_ad_actor_sys_prio.attr,
        NULL,
 };
 
index ea6546d2c946aa1caeabcb071a368e07cf89c3a3..894002a2620f362bcb02095b7f140cc9bcbaeaaa 100644 (file)
@@ -63,6 +63,7 @@ enum {
        BOND_OPT_LP_INTERVAL,
        BOND_OPT_SLAVES,
        BOND_OPT_TLB_DYNAMIC_LB,
+       BOND_OPT_AD_ACTOR_SYS_PRIO,
        BOND_OPT_LAST
 };
 
index 78ed135e9dea6a9971d15e3b786a64de170b310c..405cf87a450a35a62e1a53310df63670933d988b 100644 (file)
@@ -136,6 +136,7 @@ struct bond_params {
        int packets_per_slave;
        int tlb_dynamic_lb;
        struct reciprocal_value reciprocal_packets_per_slave;
+       u16 ad_actor_sys_prio;
 };
 
 struct bond_parm_tbl {