bonding: convert packets_per_slave to use the new option API
authorNikolay Aleksandrov <nikolay@redhat.com>
Wed, 22 Jan 2014 13:53:18 +0000 (14:53 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 22 Jan 2014 23:38:41 +0000 (15:38 -0800)
This patch adds the necessary changes so packets_per_slave would use the
new bonding option API.

Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/bond_main.c
drivers/net/bonding/bond_netlink.c
drivers/net/bonding/bond_options.c
drivers/net/bonding/bond_options.h
drivers/net/bonding/bond_sysfs.c
drivers/net/bonding/bonding.h

index 7a04f0f8449e239ec8888c37c746b745821b13d3..a50577bc8bc16b97043c0662dbd4187201164de4 100644 (file)
@@ -4145,7 +4145,8 @@ static int bond_check_params(struct bond_params *params)
                resend_igmp = BOND_DEFAULT_RESEND_IGMP;
        }
 
-       if (packets_per_slave < 0 || packets_per_slave > USHRT_MAX) {
+       bond_opt_initval(&newval, packets_per_slave);
+       if (!bond_opt_parse(bond_opt_get(BOND_OPT_PACKETS_PER_SLAVE), &newval)) {
                pr_warn("Warning: packets_per_slave (%d) should be between 0 and %u resetting to 1\n",
                        packets_per_slave, USHRT_MAX);
                packets_per_slave = 1;
index db3f672a5e2a578f3f166ba1c619cc92f81a825e..8936a911ebe2b46c78849081666026ad5848803a 100644 (file)
@@ -287,8 +287,8 @@ static int bond_changelink(struct net_device *bond_dev,
                int packets_per_slave =
                        nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]);
 
-               err = bond_option_packets_per_slave_set(bond,
-                                                       packets_per_slave);
+               bond_opt_initval(&newval, packets_per_slave);
+               err = __bond_opt_set(bond, BOND_OPT_PACKETS_PER_SLAVE, &newval);
                if (err)
                        return err;
        }
index 5696b2fb5cb451db563e546411fd2610d1f5be06..6d2a7d9cee19b219915af1acfb321338a8b2f0ec 100644 (file)
@@ -30,6 +30,12 @@ static struct bond_opt_value bond_mode_tbl[] = {
        { NULL,            -1,                     0},
 };
 
+static struct bond_opt_value bond_pps_tbl[] = {
+       { "default", 1,         BOND_VALFLAG_DEFAULT},
+       { "maxval",  USHRT_MAX, BOND_VALFLAG_MAX},
+       { NULL,      -1,        0},
+};
+
 static struct bond_option bond_opts[] = {
        [BOND_OPT_MODE] = {
                .id = BOND_OPT_MODE,
@@ -39,6 +45,14 @@ static struct bond_option bond_opts[] = {
                .values = bond_mode_tbl,
                .set = bond_option_mode_set
        },
+       [BOND_OPT_PACKETS_PER_SLAVE] = {
+               .id = BOND_OPT_PACKETS_PER_SLAVE,
+               .name = "packets_per_slave",
+               .desc = "Packets to send per slave in RR mode",
+               .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)),
+               .values = bond_pps_tbl,
+               .set = bond_option_pps_set
+       },
        { }
 };
 
@@ -934,23 +948,12 @@ int bond_option_lp_interval_set(struct bonding *bond, int lp_interval)
        return 0;
 }
 
-int bond_option_packets_per_slave_set(struct bonding *bond,
-                                     int packets_per_slave)
+int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval)
 {
-       if (packets_per_slave < 0 || packets_per_slave > USHRT_MAX) {
-               pr_err("%s: packets_per_slave must be between 0 and %u\n",
-                      bond->dev->name, USHRT_MAX);
-               return -EINVAL;
-       }
-
-       if (bond->params.mode != BOND_MODE_ROUNDROBIN)
-               pr_warn("%s: Warning: packets_per_slave has effect only in balance-rr mode\n",
-                       bond->dev->name);
-
-       bond->params.packets_per_slave = packets_per_slave;
-       if (packets_per_slave > 0) {
+       bond->params.packets_per_slave = newval->value;
+       if (newval->value > 0) {
                bond->params.reciprocal_packets_per_slave =
-                       reciprocal_value(packets_per_slave);
+                       reciprocal_value(newval->value);
        } else {
                /* reciprocal_packets_per_slave is unused if
                 * packets_per_slave is 0 or 1, just initialize it
index 11e6c0697aed630f35842085200bc504476b4ee3..f8590767c18e1738d02b471ab1d3e18f234c512b 100644 (file)
@@ -39,6 +39,7 @@ enum {
 /* Option IDs, their bit positions correspond to their IDs */
 enum {
        BOND_OPT_MODE,
+       BOND_OPT_PACKETS_PER_SLAVE,
        BOND_OPT_LAST
 };
 
@@ -100,4 +101,5 @@ static inline void __bond_opt_init(struct bond_opt_value *optval,
 #define bond_opt_initstr(optval, str) __bond_opt_init(optval, str, ULLONG_MAX)
 
 int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval);
+int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval);
 #endif /* _BOND_OPTIONS_H */
index 3e537e7b66a5ccb2046959d8a9f164015ccba695..34815843f6a98a84542b1f7bf64f9bac3b92e09c 100644 (file)
@@ -1368,22 +1368,13 @@ static ssize_t bonding_store_packets_per_slave(struct device *d,
                                               const char *buf, size_t count)
 {
        struct bonding *bond = to_bond(d);
-       int new_value, ret;
-
-       if (sscanf(buf, "%d", &new_value) != 1) {
-               pr_err("%s: no packets_per_slave value specified.\n",
-                      bond->dev->name);
-               return -EINVAL;
-       }
-
-       if (!rtnl_trylock())
-               return restart_syscall();
+       int ret;
 
-       ret = bond_option_packets_per_slave_set(bond, new_value);
+       ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PACKETS_PER_SLAVE,
+                                  (char *)buf);
        if (!ret)
                ret = count;
 
-       rtnl_unlock();
        return ret;
 }
 
index f8e2cab90020802647261eac01aca67207a51a1a..f9c8a7aff1b4c15e9336e9b238ca551542636100 100644 (file)
@@ -476,8 +476,6 @@ int bond_option_all_slaves_active_set(struct bonding *bond,
                                      int all_slaves_active);
 int bond_option_min_links_set(struct bonding *bond, int min_links);
 int bond_option_lp_interval_set(struct bonding *bond, int min_links);
-int bond_option_packets_per_slave_set(struct bonding *bond,
-                                     int packets_per_slave);
 int bond_option_lacp_rate_set(struct bonding *bond, int lacp_rate);
 int bond_option_ad_select_set(struct bonding *bond, int ad_select);
 struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);