aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding/bond_options.c
diff options
context:
space:
mode:
authorNikolay Aleksandrov <nikolay@redhat.com>2014-01-22 08:53:17 -0500
committerDavid S. Miller <davem@davemloft.net>2014-01-22 18:38:41 -0500
commit2b3798d5e1377ce6c67993bb271754c9c5ab4833 (patch)
tree29e37d916f2312c62d9e2f46a6cbe54125e1f3bb /drivers/net/bonding/bond_options.c
parent0911736245df19b423a3b156f6709e7bba48b18a (diff)
bonding: convert mode setting to use the new option API
This patch makes the bond's mode setting use the new option API and adds support for dependency printing which relies on having an entry for the mode option in the bond_opts[] array. Also add the ability to print the mode name when mode dependency fails and fix some trivial/style errors. Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/bonding/bond_options.c')
-rw-r--r--drivers/net/bonding/bond_options.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 3ad140bfed1a..5696b2fb5cb4 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -19,7 +19,26 @@
19#include <linux/ctype.h> 19#include <linux/ctype.h>
20#include "bonding.h" 20#include "bonding.h"
21 21
22static struct bond_opt_value bond_mode_tbl[] = {
23 { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT},
24 { "active-backup", BOND_MODE_ACTIVEBACKUP, 0},
25 { "balance-xor", BOND_MODE_XOR, 0},
26 { "broadcast", BOND_MODE_BROADCAST, 0},
27 { "802.3ad", BOND_MODE_8023AD, 0},
28 { "balance-tlb", BOND_MODE_TLB, 0},
29 { "balance-alb", BOND_MODE_ALB, 0},
30 { NULL, -1, 0},
31};
32
22static struct bond_option bond_opts[] = { 33static struct bond_option bond_opts[] = {
34 [BOND_OPT_MODE] = {
35 .id = BOND_OPT_MODE,
36 .name = "mode",
37 .desc = "bond device mode",
38 .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN,
39 .values = bond_mode_tbl,
40 .set = bond_option_mode_set
41 },
23 { } 42 { }
24}; 43};
25 44
@@ -160,12 +179,15 @@ static int bond_opt_check_deps(struct bonding *bond,
160static void bond_opt_dep_print(struct bonding *bond, 179static void bond_opt_dep_print(struct bonding *bond,
161 const struct bond_option *opt) 180 const struct bond_option *opt)
162{ 181{
182 struct bond_opt_value *modeval;
163 struct bond_params *params; 183 struct bond_params *params;
164 184
165 params = &bond->params; 185 params = &bond->params;
186 modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode);
166 if (test_bit(params->mode, &opt->unsuppmodes)) 187 if (test_bit(params->mode, &opt->unsuppmodes))
167 pr_err("%s: option %s: mode dependency failed\n", 188 pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n",
168 bond->dev->name, opt->name); 189 bond->dev->name, opt->name,
190 modeval->string, modeval->value);
169} 191}
170 192
171static void bond_opt_error_interpret(struct bonding *bond, 193static void bond_opt_error_interpret(struct bonding *bond,
@@ -290,29 +312,11 @@ struct bond_option *bond_opt_get(unsigned int option)
290 return &bond_opts[option]; 312 return &bond_opts[option];
291} 313}
292 314
293int bond_option_mode_set(struct bonding *bond, int mode) 315int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval)
294{ 316{
295 if (bond_parm_tbl_lookup(mode, bond_mode_tbl) < 0) { 317 if (BOND_NO_USES_ARP(newval->value) && bond->params.arp_interval) {
296 pr_err("%s: Ignoring invalid mode value %d.\n",
297 bond->dev->name, mode);
298 return -EINVAL;
299 }
300
301 if (bond->dev->flags & IFF_UP) {
302 pr_err("%s: unable to update mode because interface is up.\n",
303 bond->dev->name);
304 return -EPERM;
305 }
306
307 if (bond_has_slaves(bond)) {
308 pr_err("%s: unable to update mode because bond has slaves.\n",
309 bond->dev->name);
310 return -EPERM;
311 }
312
313 if (BOND_NO_USES_ARP(mode) && bond->params.arp_interval) {
314 pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n", 318 pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n",
315 bond->dev->name, bond_mode_tbl[mode].modename); 319 bond->dev->name, newval->string);
316 /* disable arp monitoring */ 320 /* disable arp monitoring */
317 bond->params.arp_interval = 0; 321 bond->params.arp_interval = 0;
318 /* set miimon to default value */ 322 /* set miimon to default value */
@@ -323,7 +327,8 @@ int bond_option_mode_set(struct bonding *bond, int mode)
323 327
324 /* don't cache arp_validate between modes */ 328 /* don't cache arp_validate between modes */
325 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; 329 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
326 bond->params.mode = mode; 330 bond->params.mode = newval->value;
331
327 return 0; 332 return 0;
328} 333}
329 334