aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding
diff options
context:
space:
mode:
authorNikolay Aleksandrov <nikolay@redhat.com>2014-01-22 08:53:22 -0500
committerDavid S. Miller <davem@davemloft.net>2014-01-22 18:38:42 -0500
commit1df6b6aa334c99b39f9366f4199b7f5e479a8899 (patch)
treedb9fc82c70ba94d02bd646650b914cb910ff8f80 /drivers/net/bonding
parentedf36b24c58dbbd5f2e708096537bf0a88ffa477 (diff)
bonding: convert fail_over_mac to use the new option API
This patch adds the necessary changes so fail_over_mac would use the new bonding option API. Also fixes a trivial copy/paste error in bond_check_params where the wrong variable was used for the error msg. Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/bonding')
-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.c37
-rw-r--r--drivers/net/bonding/bond_options.h3
-rw-r--r--drivers/net/bonding/bond_procfs.c8
-rw-r--r--drivers/net/bonding/bond_sysfs.c23
-rw-r--r--drivers/net/bonding/bonding.h1
7 files changed, 43 insertions, 50 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 103b6af30474..4fe3634a77d3 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -214,13 +214,6 @@ const struct bond_parm_tbl bond_lacp_tbl[] = {
214{ NULL, -1}, 214{ NULL, -1},
215}; 215};
216 216
217const struct bond_parm_tbl fail_over_mac_tbl[] = {
218{ "none", BOND_FOM_NONE},
219{ "active", BOND_FOM_ACTIVE},
220{ "follow", BOND_FOM_FOLLOW},
221{ NULL, -1},
222};
223
224const struct bond_parm_tbl pri_reselect_tbl[] = { 217const struct bond_parm_tbl pri_reselect_tbl[] = {
225{ "always", BOND_PRI_RESELECT_ALWAYS}, 218{ "always", BOND_PRI_RESELECT_ALWAYS},
226{ "better", BOND_PRI_RESELECT_BETTER}, 219{ "better", BOND_PRI_RESELECT_BETTER},
@@ -4280,14 +4273,15 @@ static int bond_check_params(struct bond_params *params)
4280 } 4273 }
4281 4274
4282 if (fail_over_mac) { 4275 if (fail_over_mac) {
4283 fail_over_mac_value = bond_parse_parm(fail_over_mac, 4276 bond_opt_initstr(&newval, fail_over_mac);
4284 fail_over_mac_tbl); 4277 valptr = bond_opt_parse(bond_opt_get(BOND_OPT_FAIL_OVER_MAC),
4285 if (fail_over_mac_value == -1) { 4278 &newval);
4279 if (!valptr) {
4286 pr_err("Error: invalid fail_over_mac \"%s\"\n", 4280 pr_err("Error: invalid fail_over_mac \"%s\"\n",
4287 arp_validate == NULL ? "NULL" : arp_validate); 4281 fail_over_mac);
4288 return -EINVAL; 4282 return -EINVAL;
4289 } 4283 }
4290 4284 fail_over_mac_value = valptr->value;
4291 if (bond_mode != BOND_MODE_ACTIVEBACKUP) 4285 if (bond_mode != BOND_MODE_ACTIVEBACKUP)
4292 pr_warning("Warning: fail_over_mac only affects active-backup mode.\n"); 4286 pr_warning("Warning: fail_over_mac only affects active-backup mode.\n");
4293 } else { 4287 } else {
diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index ff1e3d3282e3..efdff6cb19a9 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -232,7 +232,8 @@ static int bond_changelink(struct net_device *bond_dev,
232 int fail_over_mac = 232 int fail_over_mac =
233 nla_get_u8(data[IFLA_BOND_FAIL_OVER_MAC]); 233 nla_get_u8(data[IFLA_BOND_FAIL_OVER_MAC]);
234 234
235 err = bond_option_fail_over_mac_set(bond, fail_over_mac); 235 bond_opt_initval(&newval, fail_over_mac);
236 err = __bond_opt_set(bond, BOND_OPT_FAIL_OVER_MAC, &newval);
236 if (err) 237 if (err)
237 return err; 238 return err;
238 } 239 }
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index e136e7525a02..c73d3acbdd37 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -59,6 +59,13 @@ static struct bond_opt_value bond_arp_all_targets_tbl[] = {
59 { NULL, -1, 0}, 59 { NULL, -1, 0},
60}; 60};
61 61
62static struct bond_opt_value bond_fail_over_mac_tbl[] = {
63 { "none", BOND_FOM_NONE, BOND_VALFLAG_DEFAULT},
64 { "active", BOND_FOM_ACTIVE, 0},
65 { "follow", BOND_FOM_FOLLOW, 0},
66 { NULL, -1, 0},
67};
68
62static struct bond_option bond_opts[] = { 69static struct bond_option bond_opts[] = {
63 [BOND_OPT_MODE] = { 70 [BOND_OPT_MODE] = {
64 .id = BOND_OPT_MODE, 71 .id = BOND_OPT_MODE,
@@ -98,6 +105,14 @@ static struct bond_option bond_opts[] = {
98 .values = bond_arp_all_targets_tbl, 105 .values = bond_arp_all_targets_tbl,
99 .set = bond_option_arp_all_targets_set 106 .set = bond_option_arp_all_targets_set
100 }, 107 },
108 [BOND_OPT_FAIL_OVER_MAC] = {
109 .id = BOND_OPT_FAIL_OVER_MAC,
110 .name = "fail_over_mac",
111 .desc = "For active-backup, do not set all slaves to the same MAC",
112 .flags = BOND_OPTFLAG_NOSLAVES,
113 .values = bond_fail_over_mac_tbl,
114 .set = bond_option_fail_over_mac_set
115 },
101 { } 116 { }
102}; 117};
103 118
@@ -864,24 +879,12 @@ int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect)
864 return 0; 879 return 0;
865} 880}
866 881
867int bond_option_fail_over_mac_set(struct bonding *bond, int fail_over_mac) 882int bond_option_fail_over_mac_set(struct bonding *bond,
883 struct bond_opt_value *newval)
868{ 884{
869 if (bond_parm_tbl_lookup(fail_over_mac, fail_over_mac_tbl) < 0) { 885 pr_info("%s: Setting fail_over_mac to %s (%llu).\n",
870 pr_err("%s: Ignoring invalid fail_over_mac value %d.\n", 886 bond->dev->name, newval->string, newval->value);
871 bond->dev->name, fail_over_mac); 887 bond->params.fail_over_mac = newval->value;
872 return -EINVAL;
873 }
874
875 if (bond_has_slaves(bond)) {
876 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
877 bond->dev->name);
878 return -EPERM;
879 }
880
881 bond->params.fail_over_mac = fail_over_mac;
882 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
883 bond->dev->name, fail_over_mac_tbl[fail_over_mac].modename,
884 fail_over_mac);
885 888
886 return 0; 889 return 0;
887} 890}
diff --git a/drivers/net/bonding/bond_options.h b/drivers/net/bonding/bond_options.h
index 88f8c178b233..e80a0310d7af 100644
--- a/drivers/net/bonding/bond_options.h
+++ b/drivers/net/bonding/bond_options.h
@@ -43,6 +43,7 @@ enum {
43 BOND_OPT_XMIT_HASH, 43 BOND_OPT_XMIT_HASH,
44 BOND_OPT_ARP_VALIDATE, 44 BOND_OPT_ARP_VALIDATE,
45 BOND_OPT_ARP_ALL_TARGETS, 45 BOND_OPT_ARP_ALL_TARGETS,
46 BOND_OPT_FAIL_OVER_MAC,
46 BOND_OPT_LAST 47 BOND_OPT_LAST
47}; 48};
48 49
@@ -111,4 +112,6 @@ int bond_option_arp_validate_set(struct bonding *bond,
111 struct bond_opt_value *newval); 112 struct bond_opt_value *newval);
112int bond_option_arp_all_targets_set(struct bonding *bond, 113int bond_option_arp_all_targets_set(struct bonding *bond,
113 struct bond_opt_value *newval); 114 struct bond_opt_value *newval);
115int bond_option_fail_over_mac_set(struct bonding *bond,
116 struct bond_opt_value *newval);
114#endif /* _BOND_OPTIONS_H */ 117#endif /* _BOND_OPTIONS_H */
diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c
index edb7c184de39..1a6631032f58 100644
--- a/drivers/net/bonding/bond_procfs.c
+++ b/drivers/net/bonding/bond_procfs.c
@@ -77,9 +77,11 @@ static void bond_info_show_master(struct seq_file *seq)
77 bond_mode_name(bond->params.mode)); 77 bond_mode_name(bond->params.mode));
78 78
79 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP && 79 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP &&
80 bond->params.fail_over_mac) 80 bond->params.fail_over_mac) {
81 seq_printf(seq, " (fail_over_mac %s)", 81 optval = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
82 fail_over_mac_tbl[bond->params.fail_over_mac].modename); 82 bond->params.fail_over_mac);
83 seq_printf(seq, " (fail_over_mac %s)", optval->string);
84 }
83 85
84 seq_printf(seq, "\n"); 86 seq_printf(seq, "\n");
85 87
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 83463fc7622b..968c099945b2 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -391,34 +391,25 @@ static ssize_t bonding_show_fail_over_mac(struct device *d,
391 char *buf) 391 char *buf)
392{ 392{
393 struct bonding *bond = to_bond(d); 393 struct bonding *bond = to_bond(d);
394 struct bond_opt_value *val;
394 395
395 return sprintf(buf, "%s %d\n", 396 val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
396 fail_over_mac_tbl[bond->params.fail_over_mac].modename, 397 bond->params.fail_over_mac);
397 bond->params.fail_over_mac); 398
399 return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac);
398} 400}
399 401
400static ssize_t bonding_store_fail_over_mac(struct device *d, 402static ssize_t bonding_store_fail_over_mac(struct device *d,
401 struct device_attribute *attr, 403 struct device_attribute *attr,
402 const char *buf, size_t count) 404 const char *buf, size_t count)
403{ 405{
404 int new_value, ret;
405 struct bonding *bond = to_bond(d); 406 struct bonding *bond = to_bond(d);
407 int ret;
406 408
407 new_value = bond_parse_parm(buf, fail_over_mac_tbl); 409 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_FAIL_OVER_MAC, (char *)buf);
408 if (new_value < 0) {
409 pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
410 bond->dev->name, buf);
411 return -EINVAL;
412 }
413
414 if (!rtnl_trylock())
415 return restart_syscall();
416
417 ret = bond_option_fail_over_mac_set(bond, new_value);
418 if (!ret) 410 if (!ret)
419 ret = count; 411 ret = count;
420 412
421 rtnl_unlock();
422 return ret; 413 return ret;
423} 414}
424 415
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 18b948ad28d3..86d464db2631 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -465,7 +465,6 @@ int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target);
465int bond_option_primary_set(struct bonding *bond, const char *primary); 465int bond_option_primary_set(struct bonding *bond, const char *primary);
466int bond_option_primary_reselect_set(struct bonding *bond, 466int bond_option_primary_reselect_set(struct bonding *bond,
467 int primary_reselect); 467 int primary_reselect);
468int bond_option_fail_over_mac_set(struct bonding *bond, int fail_over_mac);
469int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp); 468int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp);
470int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif); 469int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif);
471int bond_option_all_slaves_active_set(struct bonding *bond, 470int bond_option_all_slaves_active_set(struct bonding *bond,