aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Aleksandrov <nikolay@redhat.com>2014-01-22 08:53:18 -0500
committerDavid S. Miller <davem@davemloft.net>2014-01-22 18:38:41 -0500
commitaa59d8517d1017e571b803ba6302c4b693b324ab (patch)
tree7746e9fb5e2d8204fa2777534cf14dfbf265a2a7
parent2b3798d5e1377ce6c67993bb271754c9c5ab4833 (diff)
bonding: convert packets_per_slave to use the new option API
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>
-rw-r--r--drivers/net/bonding/bond_main.c3
-rw-r--r--drivers/net/bonding/bond_netlink.c4
-rw-r--r--drivers/net/bonding/bond_options.c33
-rw-r--r--drivers/net/bonding/bond_options.h2
-rw-r--r--drivers/net/bonding/bond_sysfs.c15
-rw-r--r--drivers/net/bonding/bonding.h2
6 files changed, 27 insertions, 32 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 7a04f0f8449e..a50577bc8bc1 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -4145,7 +4145,8 @@ static int bond_check_params(struct bond_params *params)
4145 resend_igmp = BOND_DEFAULT_RESEND_IGMP; 4145 resend_igmp = BOND_DEFAULT_RESEND_IGMP;
4146 } 4146 }
4147 4147
4148 if (packets_per_slave < 0 || packets_per_slave > USHRT_MAX) { 4148 bond_opt_initval(&newval, packets_per_slave);
4149 if (!bond_opt_parse(bond_opt_get(BOND_OPT_PACKETS_PER_SLAVE), &newval)) {
4149 pr_warn("Warning: packets_per_slave (%d) should be between 0 and %u resetting to 1\n", 4150 pr_warn("Warning: packets_per_slave (%d) should be between 0 and %u resetting to 1\n",
4150 packets_per_slave, USHRT_MAX); 4151 packets_per_slave, USHRT_MAX);
4151 packets_per_slave = 1; 4152 packets_per_slave = 1;
diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index db3f672a5e2a..8936a911ebe2 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -287,8 +287,8 @@ static int bond_changelink(struct net_device *bond_dev,
287 int packets_per_slave = 287 int packets_per_slave =
288 nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]); 288 nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]);
289 289
290 err = bond_option_packets_per_slave_set(bond, 290 bond_opt_initval(&newval, packets_per_slave);
291 packets_per_slave); 291 err = __bond_opt_set(bond, BOND_OPT_PACKETS_PER_SLAVE, &newval);
292 if (err) 292 if (err)
293 return err; 293 return err;
294 } 294 }
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 5696b2fb5cb4..6d2a7d9cee19 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -30,6 +30,12 @@ static struct bond_opt_value bond_mode_tbl[] = {
30 { NULL, -1, 0}, 30 { NULL, -1, 0},
31}; 31};
32 32
33static struct bond_opt_value bond_pps_tbl[] = {
34 { "default", 1, BOND_VALFLAG_DEFAULT},
35 { "maxval", USHRT_MAX, BOND_VALFLAG_MAX},
36 { NULL, -1, 0},
37};
38
33static struct bond_option bond_opts[] = { 39static struct bond_option bond_opts[] = {
34 [BOND_OPT_MODE] = { 40 [BOND_OPT_MODE] = {
35 .id = BOND_OPT_MODE, 41 .id = BOND_OPT_MODE,
@@ -39,6 +45,14 @@ static struct bond_option bond_opts[] = {
39 .values = bond_mode_tbl, 45 .values = bond_mode_tbl,
40 .set = bond_option_mode_set 46 .set = bond_option_mode_set
41 }, 47 },
48 [BOND_OPT_PACKETS_PER_SLAVE] = {
49 .id = BOND_OPT_PACKETS_PER_SLAVE,
50 .name = "packets_per_slave",
51 .desc = "Packets to send per slave in RR mode",
52 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)),
53 .values = bond_pps_tbl,
54 .set = bond_option_pps_set
55 },
42 { } 56 { }
43}; 57};
44 58
@@ -934,23 +948,12 @@ int bond_option_lp_interval_set(struct bonding *bond, int lp_interval)
934 return 0; 948 return 0;
935} 949}
936 950
937int bond_option_packets_per_slave_set(struct bonding *bond, 951int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval)
938 int packets_per_slave)
939{ 952{
940 if (packets_per_slave < 0 || packets_per_slave > USHRT_MAX) { 953 bond->params.packets_per_slave = newval->value;
941 pr_err("%s: packets_per_slave must be between 0 and %u\n", 954 if (newval->value > 0) {
942 bond->dev->name, USHRT_MAX);
943 return -EINVAL;
944 }
945
946 if (bond->params.mode != BOND_MODE_ROUNDROBIN)
947 pr_warn("%s: Warning: packets_per_slave has effect only in balance-rr mode\n",
948 bond->dev->name);
949
950 bond->params.packets_per_slave = packets_per_slave;
951 if (packets_per_slave > 0) {
952 bond->params.reciprocal_packets_per_slave = 955 bond->params.reciprocal_packets_per_slave =
953 reciprocal_value(packets_per_slave); 956 reciprocal_value(newval->value);
954 } else { 957 } else {
955 /* reciprocal_packets_per_slave is unused if 958 /* reciprocal_packets_per_slave is unused if
956 * packets_per_slave is 0 or 1, just initialize it 959 * packets_per_slave is 0 or 1, just initialize it
diff --git a/drivers/net/bonding/bond_options.h b/drivers/net/bonding/bond_options.h
index 11e6c0697aed..f8590767c18e 100644
--- a/drivers/net/bonding/bond_options.h
+++ b/drivers/net/bonding/bond_options.h
@@ -39,6 +39,7 @@ enum {
39/* Option IDs, their bit positions correspond to their IDs */ 39/* Option IDs, their bit positions correspond to their IDs */
40enum { 40enum {
41 BOND_OPT_MODE, 41 BOND_OPT_MODE,
42 BOND_OPT_PACKETS_PER_SLAVE,
42 BOND_OPT_LAST 43 BOND_OPT_LAST
43}; 44};
44 45
@@ -100,4 +101,5 @@ static inline void __bond_opt_init(struct bond_opt_value *optval,
100#define bond_opt_initstr(optval, str) __bond_opt_init(optval, str, ULLONG_MAX) 101#define bond_opt_initstr(optval, str) __bond_opt_init(optval, str, ULLONG_MAX)
101 102
102int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval); 103int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval);
104int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval);
103#endif /* _BOND_OPTIONS_H */ 105#endif /* _BOND_OPTIONS_H */
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 3e537e7b66a5..34815843f6a9 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -1368,22 +1368,13 @@ static ssize_t bonding_store_packets_per_slave(struct device *d,
1368 const char *buf, size_t count) 1368 const char *buf, size_t count)
1369{ 1369{
1370 struct bonding *bond = to_bond(d); 1370 struct bonding *bond = to_bond(d);
1371 int new_value, ret; 1371 int ret;
1372
1373 if (sscanf(buf, "%d", &new_value) != 1) {
1374 pr_err("%s: no packets_per_slave value specified.\n",
1375 bond->dev->name);
1376 return -EINVAL;
1377 }
1378
1379 if (!rtnl_trylock())
1380 return restart_syscall();
1381 1372
1382 ret = bond_option_packets_per_slave_set(bond, new_value); 1373 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PACKETS_PER_SLAVE,
1374 (char *)buf);
1383 if (!ret) 1375 if (!ret)
1384 ret = count; 1376 ret = count;
1385 1377
1386 rtnl_unlock();
1387 return ret; 1378 return ret;
1388} 1379}
1389 1380
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index f8e2cab90020..f9c8a7aff1b4 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -476,8 +476,6 @@ int bond_option_all_slaves_active_set(struct bonding *bond,
476 int all_slaves_active); 476 int all_slaves_active);
477int bond_option_min_links_set(struct bonding *bond, int min_links); 477int bond_option_min_links_set(struct bonding *bond, int min_links);
478int bond_option_lp_interval_set(struct bonding *bond, int min_links); 478int bond_option_lp_interval_set(struct bonding *bond, int min_links);
479int bond_option_packets_per_slave_set(struct bonding *bond,
480 int packets_per_slave);
481int bond_option_lacp_rate_set(struct bonding *bond, int lacp_rate); 479int bond_option_lacp_rate_set(struct bonding *bond, int lacp_rate);
482int bond_option_ad_select_set(struct bonding *bond, int ad_select); 480int bond_option_ad_select_set(struct bonding *bond, int ad_select);
483struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond); 481struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);