aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorNikolay Aleksandrov <nikolay@redhat.com>2014-01-22 08:53:33 -0500
committerDavid S. Miller <davem@davemloft.net>2014-01-22 18:38:43 -0500
commit388d3a6d4aa356b885bcd023c185060df9ea2484 (patch)
tree4d48b059fc62aac5d47907eca55cc1f10379636c /drivers/net
parent180222f08861d8206b3ff1c6392101e29d4ae161 (diff)
bonding: convert primary_reselect to use the new option API
This patch adds the necessary changes so primary_reselect would use the new bonding option API. Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/bonding/bond_main.c18
-rw-r--r--drivers/net/bonding/bond_netlink.c3
-rw-r--r--drivers/net/bonding/bond_options.c30
-rw-r--r--drivers/net/bonding/bond_options.h3
-rw-r--r--drivers/net/bonding/bond_procfs.c7
-rw-r--r--drivers/net/bonding/bond_sysfs.c24
-rw-r--r--drivers/net/bonding/bonding.h2
7 files changed, 43 insertions, 44 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index f606e2c3724c..59edf18602d9 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -206,13 +206,6 @@ static int bond_mode = BOND_MODE_ROUNDROBIN;
206static int xmit_hashtype = BOND_XMIT_POLICY_LAYER2; 206static int xmit_hashtype = BOND_XMIT_POLICY_LAYER2;
207static int lacp_fast; 207static int lacp_fast;
208 208
209const struct bond_parm_tbl pri_reselect_tbl[] = {
210{ "always", BOND_PRI_RESELECT_ALWAYS},
211{ "better", BOND_PRI_RESELECT_BETTER},
212{ "failure", BOND_PRI_RESELECT_FAILURE},
213{ NULL, -1},
214};
215
216/*-------------------------- Forward declarations ---------------------------*/ 209/*-------------------------- Forward declarations ---------------------------*/
217 210
218static int bond_init(struct net_device *bond_dev); 211static int bond_init(struct net_device *bond_dev);
@@ -4248,14 +4241,15 @@ static int bond_check_params(struct bond_params *params)
4248 } 4241 }
4249 4242
4250 if (primary && primary_reselect) { 4243 if (primary && primary_reselect) {
4251 primary_reselect_value = bond_parse_parm(primary_reselect, 4244 bond_opt_initstr(&newval, primary_reselect);
4252 pri_reselect_tbl); 4245 valptr = bond_opt_parse(bond_opt_get(BOND_OPT_PRIMARY_RESELECT),
4253 if (primary_reselect_value == -1) { 4246 &newval);
4247 if (!valptr) {
4254 pr_err("Error: Invalid primary_reselect \"%s\"\n", 4248 pr_err("Error: Invalid primary_reselect \"%s\"\n",
4255 primary_reselect == 4249 primary_reselect);
4256 NULL ? "NULL" : primary_reselect);
4257 return -EINVAL; 4250 return -EINVAL;
4258 } 4251 }
4252 primary_reselect_value = valptr->value;
4259 } else { 4253 } else {
4260 primary_reselect_value = BOND_PRI_RESELECT_ALWAYS; 4254 primary_reselect_value = BOND_PRI_RESELECT_ALWAYS;
4261 } 4255 }
diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index b27e09d1e2e4..709e93861771 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -236,7 +236,8 @@ static int bond_changelink(struct net_device *bond_dev,
236 int primary_reselect = 236 int primary_reselect =
237 nla_get_u8(data[IFLA_BOND_PRIMARY_RESELECT]); 237 nla_get_u8(data[IFLA_BOND_PRIMARY_RESELECT]);
238 238
239 err = bond_option_primary_reselect_set(bond, primary_reselect); 239 bond_opt_initval(&newval, primary_reselect);
240 err = __bond_opt_set(bond, BOND_OPT_PRIMARY_RESELECT, &newval);
240 if (err) 241 if (err)
241 return err; 242 return err;
242 } 243 }
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index f094a313adb3..eaa3d4057cd3 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -92,6 +92,13 @@ static struct bond_opt_value bond_num_peer_notif_tbl[] = {
92 { NULL, -1, 0} 92 { NULL, -1, 0}
93}; 93};
94 94
95static struct bond_opt_value bond_primary_reselect_tbl[] = {
96 { "always", BOND_PRI_RESELECT_ALWAYS, BOND_VALFLAG_DEFAULT},
97 { "better", BOND_PRI_RESELECT_BETTER, 0},
98 { "failure", BOND_PRI_RESELECT_FAILURE, 0},
99 { NULL, -1},
100};
101
95static struct bond_option bond_opts[] = { 102static struct bond_option bond_opts[] = {
96 [BOND_OPT_MODE] = { 103 [BOND_OPT_MODE] = {
97 .id = BOND_OPT_MODE, 104 .id = BOND_OPT_MODE,
@@ -217,6 +224,13 @@ static struct bond_option bond_opts[] = {
217 BIT(BOND_MODE_ALB)), 224 BIT(BOND_MODE_ALB)),
218 .set = bond_option_primary_set 225 .set = bond_option_primary_set
219 }, 226 },
227 [BOND_OPT_PRIMARY_RESELECT] = {
228 .id = BOND_OPT_PRIMARY_RESELECT,
229 .name = "primary_reselect",
230 .desc = "Reselect primary slave once it comes up",
231 .values = bond_primary_reselect_tbl,
232 .set = bond_option_primary_reselect_set
233 },
220 { } 234 { }
221}; 235};
222 236
@@ -943,18 +957,12 @@ out:
943 return 0; 957 return 0;
944} 958}
945 959
946int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect) 960int bond_option_primary_reselect_set(struct bonding *bond,
961 struct bond_opt_value *newval)
947{ 962{
948 if (bond_parm_tbl_lookup(primary_reselect, pri_reselect_tbl) < 0) { 963 pr_info("%s: setting primary_reselect to %s (%llu).\n",
949 pr_err("%s: Ignoring invalid primary_reselect value %d.\n", 964 bond->dev->name, newval->string, newval->value);
950 bond->dev->name, primary_reselect); 965 bond->params.primary_reselect = newval->value;
951 return -EINVAL;
952 }
953
954 bond->params.primary_reselect = primary_reselect;
955 pr_info("%s: setting primary_reselect to %s (%d).\n",
956 bond->dev->name, pri_reselect_tbl[primary_reselect].modename,
957 primary_reselect);
958 966
959 block_netpoll_tx(); 967 block_netpoll_tx();
960 write_lock_bh(&bond->curr_slave_lock); 968 write_lock_bh(&bond->curr_slave_lock);
diff --git a/drivers/net/bonding/bond_options.h b/drivers/net/bonding/bond_options.h
index 6ff831030545..1de315cd3bb6 100644
--- a/drivers/net/bonding/bond_options.h
+++ b/drivers/net/bonding/bond_options.h
@@ -54,6 +54,7 @@ enum {
54 BOND_OPT_NUM_PEER_NOTIF, 54 BOND_OPT_NUM_PEER_NOTIF,
55 BOND_OPT_MIIMON, 55 BOND_OPT_MIIMON,
56 BOND_OPT_PRIMARY, 56 BOND_OPT_PRIMARY,
57 BOND_OPT_PRIMARY_RESELECT,
57 BOND_OPT_LAST 58 BOND_OPT_LAST
58}; 59};
59 60
@@ -144,4 +145,6 @@ int bond_option_num_peer_notif_set(struct bonding *bond,
144int bond_option_miimon_set(struct bonding *bond, struct bond_opt_value *newval); 145int bond_option_miimon_set(struct bonding *bond, struct bond_opt_value *newval);
145int bond_option_primary_set(struct bonding *bond, 146int bond_option_primary_set(struct bonding *bond,
146 struct bond_opt_value *newval); 147 struct bond_opt_value *newval);
148int bond_option_primary_reselect_set(struct bonding *bond,
149 struct bond_opt_value *newval);
147#endif /* _BOND_OPTIONS_H */ 150#endif /* _BOND_OPTIONS_H */
diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c
index d28c3d7ae029..3ac20e78eafc 100644
--- a/drivers/net/bonding/bond_procfs.c
+++ b/drivers/net/bonding/bond_procfs.c
@@ -97,9 +97,12 @@ static void bond_info_show_master(struct seq_file *seq)
97 seq_printf(seq, "Primary Slave: %s", 97 seq_printf(seq, "Primary Slave: %s",
98 (bond->primary_slave) ? 98 (bond->primary_slave) ?
99 bond->primary_slave->dev->name : "None"); 99 bond->primary_slave->dev->name : "None");
100 if (bond->primary_slave) 100 if (bond->primary_slave) {
101 optval = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
102 bond->params.primary_reselect);
101 seq_printf(seq, " (primary_reselect %s)", 103 seq_printf(seq, " (primary_reselect %s)",
102 pri_reselect_tbl[bond->params.primary_reselect].modename); 104 optval->string);
105 }
103 106
104 seq_printf(seq, "\nCurrently Active Slave: %s\n", 107 seq_printf(seq, "\nCurrently Active Slave: %s\n",
105 (curr) ? curr->dev->name : "None"); 108 (curr) ? curr->dev->name : "None");
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 10c58ef4876d..7f307bf096d1 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -729,35 +729,27 @@ static ssize_t bonding_show_primary_reselect(struct device *d,
729 char *buf) 729 char *buf)
730{ 730{
731 struct bonding *bond = to_bond(d); 731 struct bonding *bond = to_bond(d);
732 struct bond_opt_value *val;
733
734 val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
735 bond->params.primary_reselect);
732 736
733 return sprintf(buf, "%s %d\n", 737 return sprintf(buf, "%s %d\n",
734 pri_reselect_tbl[bond->params.primary_reselect].modename, 738 val->string, bond->params.primary_reselect);
735 bond->params.primary_reselect);
736} 739}
737 740
738static ssize_t bonding_store_primary_reselect(struct device *d, 741static ssize_t bonding_store_primary_reselect(struct device *d,
739 struct device_attribute *attr, 742 struct device_attribute *attr,
740 const char *buf, size_t count) 743 const char *buf, size_t count)
741{ 744{
742 int new_value, ret;
743 struct bonding *bond = to_bond(d); 745 struct bonding *bond = to_bond(d);
746 int ret;
744 747
745 new_value = bond_parse_parm(buf, pri_reselect_tbl); 748 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PRIMARY_RESELECT,
746 if (new_value < 0) { 749 (char *)buf);
747 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
748 bond->dev->name,
749 (int) strlen(buf) - 1, buf);
750 return -EINVAL;
751 }
752
753 if (!rtnl_trylock())
754 return restart_syscall();
755
756 ret = bond_option_primary_reselect_set(bond, new_value);
757 if (!ret) 750 if (!ret)
758 ret = count; 751 ret = count;
759 752
760 rtnl_unlock();
761 return ret; 753 return ret;
762} 754}
763static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, 755static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 891685483034..afa443d29761 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -456,8 +456,6 @@ int bond_option_active_slave_set(struct bonding *bond, struct net_device *slave_
456int bond_option_use_carrier_set(struct bonding *bond, int use_carrier); 456int bond_option_use_carrier_set(struct bonding *bond, int use_carrier);
457int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target); 457int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target);
458int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target); 458int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target);
459int bond_option_primary_reselect_set(struct bonding *bond,
460 int primary_reselect);
461int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp); 459int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp);
462int bond_option_all_slaves_active_set(struct bonding *bond, 460int bond_option_all_slaves_active_set(struct bonding *bond,
463 int all_slaves_active); 461 int all_slaves_active);