Skip to content

Commit b414ac9

Browse files
committed
Merge branch 'bonding_option_api'
Nikolay Aleksandrov says: ==================== bonding: introduce new option API This patchset's goal is to introduce a new option API which should be used to properly describe the bonding options with their mode dependcies and requirements. With this patchset applied we get centralized option manipulation, automatic RTNL acquire per option setting, automatic option range checking, mode dependcy checking and other various flags which are described in detail in patch 01's commit message and comments. Also the parameter passing is changed to use a specialized structure which is initialized to a value depending on the needs. The main exported functions are: __bond_opt_set() - set an option (RTNL should be acquired prior) bond_opt_init(val|str) - init a bond_opt_value struct for value or string parameter passing bond_opt_tryset_rtnl() - function which tries to acquire rtnl, mainly used for sysfs bond_opt_parse - used to parse or check for valid values bond_opt_get - retrieve a pointer to bond_option struct for some option bond_opt_get_val - retrieve a pointer to a bond_opt_value struct for some value The same functions are used to set an option via sysfs and netlink, just the parameter that's passed is usually initialized in a different way. The converted options have multiple style fixes, there're some longer lines but they looked either ugly or were strings/pr_warnings, if you think some line would be better broken just let me know :-) there're also a few sscanf false-positive warnings. I decided to keep the "unsuppmodes" way of mode dep checking since it's straight forward, if we make a more general way for checking dependencies it'll be easy to change it. Future plans for this work include: - Automatic sysfs generation from the bond_opts[]. - Use of the API in bond_check_params() and thus cleaning it up (this has actually started, I'll take care of the rest in a separate patch) - Clean up all option-unrelated files of option definitions and functions I've tried to leave as much documentation as possible, if there's anything unclear please let me know. One more thing, I haven't moved all option-related functions from bonding.h to the new bond_options.h, this will be done in a separate patch, it's in my todo list. This patchset has been tested by setting each converted option via sysfs and netlink to a couple of wrong values, a couple of correct values and some random values, also for the opts that have flags they have been tested as well. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 374d112 + 0e2e5b6 commit b414ac9

7 files changed

Lines changed: 1217 additions & 883 deletions

File tree

‎drivers/net/bonding/bond_main.c‎

Lines changed: 66 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,11 @@
8686
/*---------------------------- Module parameters ----------------------------*/
8787

8888
/* monitor all links that often (in milliseconds). <=0 disables monitoring */
89-
#define BOND_LINK_MON_INTERV 0
90-
#define BOND_LINK_ARP_INTERV 0
9189

9290
static int max_bonds = BOND_DEFAULT_MAX_BONDS;
9391
static int tx_queues = BOND_DEFAULT_TX_QUEUES;
9492
static int num_peer_notif = 1;
95-
static int miimon = BOND_LINK_MON_INTERV;
93+
static int miimon;
9694
static int updelay;
9795
static int downdelay;
9896
static int use_carrier = 1;
@@ -103,7 +101,7 @@ static char *lacp_rate;
103101
static int min_links;
104102
static char *ad_select;
105103
static char *xmit_hash_policy;
106-
static int arp_interval = BOND_LINK_ARP_INTERV;
104+
static int arp_interval;
107105
static char *arp_ip_target[BOND_MAX_ARP_TARGETS];
108106
static char *arp_validate;
109107
static char *arp_all_targets;
@@ -208,67 +206,6 @@ static int bond_mode = BOND_MODE_ROUNDROBIN;
208206
static int xmit_hashtype = BOND_XMIT_POLICY_LAYER2;
209207
static int lacp_fast;
210208

211-
const struct bond_parm_tbl bond_lacp_tbl[] = {
212-
{ "slow", AD_LACP_SLOW},
213-
{ "fast", AD_LACP_FAST},
214-
{ NULL, -1},
215-
};
216-
217-
const struct bond_parm_tbl bond_mode_tbl[] = {
218-
{ "balance-rr", BOND_MODE_ROUNDROBIN},
219-
{ "active-backup", BOND_MODE_ACTIVEBACKUP},
220-
{ "balance-xor", BOND_MODE_XOR},
221-
{ "broadcast", BOND_MODE_BROADCAST},
222-
{ "802.3ad", BOND_MODE_8023AD},
223-
{ "balance-tlb", BOND_MODE_TLB},
224-
{ "balance-alb", BOND_MODE_ALB},
225-
{ NULL, -1},
226-
};
227-
228-
const struct bond_parm_tbl xmit_hashtype_tbl[] = {
229-
{ "layer2", BOND_XMIT_POLICY_LAYER2},
230-
{ "layer3+4", BOND_XMIT_POLICY_LAYER34},
231-
{ "layer2+3", BOND_XMIT_POLICY_LAYER23},
232-
{ "encap2+3", BOND_XMIT_POLICY_ENCAP23},
233-
{ "encap3+4", BOND_XMIT_POLICY_ENCAP34},
234-
{ NULL, -1},
235-
};
236-
237-
const struct bond_parm_tbl arp_all_targets_tbl[] = {
238-
{ "any", BOND_ARP_TARGETS_ANY},
239-
{ "all", BOND_ARP_TARGETS_ALL},
240-
{ NULL, -1},
241-
};
242-
243-
const struct bond_parm_tbl arp_validate_tbl[] = {
244-
{ "none", BOND_ARP_VALIDATE_NONE},
245-
{ "active", BOND_ARP_VALIDATE_ACTIVE},
246-
{ "backup", BOND_ARP_VALIDATE_BACKUP},
247-
{ "all", BOND_ARP_VALIDATE_ALL},
248-
{ NULL, -1},
249-
};
250-
251-
const struct bond_parm_tbl fail_over_mac_tbl[] = {
252-
{ "none", BOND_FOM_NONE},
253-
{ "active", BOND_FOM_ACTIVE},
254-
{ "follow", BOND_FOM_FOLLOW},
255-
{ NULL, -1},
256-
};
257-
258-
const struct bond_parm_tbl pri_reselect_tbl[] = {
259-
{ "always", BOND_PRI_RESELECT_ALWAYS},
260-
{ "better", BOND_PRI_RESELECT_BETTER},
261-
{ "failure", BOND_PRI_RESELECT_FAILURE},
262-
{ NULL, -1},
263-
};
264-
265-
struct bond_parm_tbl ad_select_tbl[] = {
266-
{ "stable", BOND_AD_STABLE},
267-
{ "bandwidth", BOND_AD_BANDWIDTH},
268-
{ "count", BOND_AD_COUNT},
269-
{ NULL, -1},
270-
};
271-
272209
/*-------------------------- Forward declarations ---------------------------*/
273210

274211
static int bond_init(struct net_device *bond_dev);
@@ -3186,6 +3123,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
31863123
struct ifslave k_sinfo;
31873124
struct ifslave __user *u_sinfo = NULL;
31883125
struct mii_ioctl_data *mii = NULL;
3126+
struct bond_opt_value newval;
31893127
struct net *net;
31903128
int res = 0;
31913129

@@ -3281,7 +3219,8 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
32813219
break;
32823220
case BOND_CHANGE_ACTIVE_OLD:
32833221
case SIOCBONDCHANGEACTIVE:
3284-
res = bond_option_active_slave_set(bond, slave_dev);
3222+
bond_opt_initstr(&newval, slave_dev->name);
3223+
res = __bond_opt_set(bond, BOND_OPT_ACTIVE_SLAVE, &newval);
32853224
break;
32863225
default:
32873226
res = -EOPNOTSUPP;
@@ -4028,18 +3967,20 @@ int bond_parse_parm(const char *buf, const struct bond_parm_tbl *tbl)
40283967
static int bond_check_params(struct bond_params *params)
40293968
{
40303969
int arp_validate_value, fail_over_mac_value, primary_reselect_value, i;
3970+
struct bond_opt_value newval, *valptr;
40313971
int arp_all_targets_value;
40323972

40333973
/*
40343974
* Convert string parameters.
40353975
*/
40363976
if (mode) {
4037-
bond_mode = bond_parse_parm(mode, bond_mode_tbl);
4038-
if (bond_mode == -1) {
4039-
pr_err("Error: Invalid bonding mode \"%s\"\n",
4040-
mode == NULL ? "NULL" : mode);
3977+
bond_opt_initstr(&newval, mode);
3978+
valptr = bond_opt_parse(bond_opt_get(BOND_OPT_MODE), &newval);
3979+
if (!valptr) {
3980+
pr_err("Error: Invalid bonding mode \"%s\"\n", mode);
40413981
return -EINVAL;
40423982
}
3983+
bond_mode = valptr->value;
40433984
}
40443985

40453986
if (xmit_hash_policy) {
@@ -4048,14 +3989,15 @@ static int bond_check_params(struct bond_params *params)
40483989
pr_info("xmit_hash_policy param is irrelevant in mode %s\n",
40493990
bond_mode_name(bond_mode));
40503991
} else {
4051-
xmit_hashtype = bond_parse_parm(xmit_hash_policy,
4052-
xmit_hashtype_tbl);
4053-
if (xmit_hashtype == -1) {
3992+
bond_opt_initstr(&newval, xmit_hash_policy);
3993+
valptr = bond_opt_parse(bond_opt_get(BOND_OPT_XMIT_HASH),
3994+
&newval);
3995+
if (!valptr) {
40543996
pr_err("Error: Invalid xmit_hash_policy \"%s\"\n",
4055-
xmit_hash_policy == NULL ? "NULL" :
40563997
xmit_hash_policy);
40573998
return -EINVAL;
40583999
}
4000+
xmit_hashtype = valptr->value;
40594001
}
40604002
}
40614003

@@ -4064,26 +4006,29 @@ static int bond_check_params(struct bond_params *params)
40644006
pr_info("lacp_rate param is irrelevant in mode %s\n",
40654007
bond_mode_name(bond_mode));
40664008
} else {
4067-
lacp_fast = bond_parse_parm(lacp_rate, bond_lacp_tbl);
4068-
if (lacp_fast == -1) {
4009+
bond_opt_initstr(&newval, lacp_rate);
4010+
valptr = bond_opt_parse(bond_opt_get(BOND_OPT_LACP_RATE),
4011+
&newval);
4012+
if (!valptr) {
40694013
pr_err("Error: Invalid lacp rate \"%s\"\n",
4070-
lacp_rate == NULL ? "NULL" : lacp_rate);
4014+
lacp_rate);
40714015
return -EINVAL;
40724016
}
4017+
lacp_fast = valptr->value;
40734018
}
40744019
}
40754020

40764021
if (ad_select) {
4077-
params->ad_select = bond_parse_parm(ad_select, ad_select_tbl);
4078-
if (params->ad_select == -1) {
4079-
pr_err("Error: Invalid ad_select \"%s\"\n",
4080-
ad_select == NULL ? "NULL" : ad_select);
4022+
bond_opt_initstr(&newval, lacp_rate);
4023+
valptr = bond_opt_parse(bond_opt_get(BOND_OPT_AD_SELECT),
4024+
&newval);
4025+
if (!valptr) {
4026+
pr_err("Error: Invalid ad_select \"%s\"\n", ad_select);
40814027
return -EINVAL;
40824028
}
4083-
4084-
if (bond_mode != BOND_MODE_8023AD) {
4029+
params->ad_select = valptr->value;
4030+
if (bond_mode != BOND_MODE_8023AD)
40854031
pr_warning("ad_select param only affects 802.3ad mode\n");
4086-
}
40874032
} else {
40884033
params->ad_select = BOND_AD_STABLE;
40894034
}
@@ -4095,9 +4040,9 @@ static int bond_check_params(struct bond_params *params)
40954040
}
40964041

40974042
if (miimon < 0) {
4098-
pr_warning("Warning: miimon module parameter (%d), not in range 0-%d, so it was reset to %d\n",
4099-
miimon, INT_MAX, BOND_LINK_MON_INTERV);
4100-
miimon = BOND_LINK_MON_INTERV;
4043+
pr_warning("Warning: miimon module parameter (%d), not in range 0-%d, so it was reset to 0\n",
4044+
miimon, INT_MAX);
4045+
miimon = 0;
41014046
}
41024047

41034048
if (updelay < 0) {
@@ -4154,7 +4099,8 @@ static int bond_check_params(struct bond_params *params)
41544099
resend_igmp = BOND_DEFAULT_RESEND_IGMP;
41554100
}
41564101

4157-
if (packets_per_slave < 0 || packets_per_slave > USHRT_MAX) {
4102+
bond_opt_initval(&newval, packets_per_slave);
4103+
if (!bond_opt_parse(bond_opt_get(BOND_OPT_PACKETS_PER_SLAVE), &newval)) {
41584104
pr_warn("Warning: packets_per_slave (%d) should be between 0 and %u resetting to 1\n",
41594105
packets_per_slave, USHRT_MAX);
41604106
packets_per_slave = 1;
@@ -4199,9 +4145,9 @@ static int bond_check_params(struct bond_params *params)
41994145
}
42004146

42014147
if (arp_interval < 0) {
4202-
pr_warning("Warning: arp_interval module parameter (%d) , not in range 0-%d, so it was reset to %d\n",
4203-
arp_interval, INT_MAX, BOND_LINK_ARP_INTERV);
4204-
arp_interval = BOND_LINK_ARP_INTERV;
4148+
pr_warning("Warning: arp_interval module parameter (%d) , not in range 0-%d, so it was reset to 0\n",
4149+
arp_interval, INT_MAX);
4150+
arp_interval = 0;
42054151
}
42064152

42074153
for (arp_ip_count = 0, i = 0;
@@ -4240,35 +4186,40 @@ static int bond_check_params(struct bond_params *params)
42404186
return -EINVAL;
42414187
}
42424188

4243-
arp_validate_value = bond_parse_parm(arp_validate,
4244-
arp_validate_tbl);
4245-
if (arp_validate_value == -1) {
4189+
bond_opt_initstr(&newval, arp_validate);
4190+
valptr = bond_opt_parse(bond_opt_get(BOND_OPT_ARP_VALIDATE),
4191+
&newval);
4192+
if (!valptr) {
42464193
pr_err("Error: invalid arp_validate \"%s\"\n",
4247-
arp_validate == NULL ? "NULL" : arp_validate);
4194+
arp_validate);
42484195
return -EINVAL;
42494196
}
4250-
} else
4197+
arp_validate_value = valptr->value;
4198+
} else {
42514199
arp_validate_value = 0;
4200+
}
42524201

42534202
arp_all_targets_value = 0;
42544203
if (arp_all_targets) {
4255-
arp_all_targets_value = bond_parse_parm(arp_all_targets,
4256-
arp_all_targets_tbl);
4257-
4258-
if (arp_all_targets_value == -1) {
4204+
bond_opt_initstr(&newval, arp_all_targets);
4205+
valptr = bond_opt_parse(bond_opt_get(BOND_OPT_ARP_ALL_TARGETS),
4206+
&newval);
4207+
if (!valptr) {
42594208
pr_err("Error: invalid arp_all_targets_value \"%s\"\n",
42604209
arp_all_targets);
42614210
arp_all_targets_value = 0;
4211+
} else {
4212+
arp_all_targets_value = valptr->value;
42624213
}
42634214
}
42644215

42654216
if (miimon) {
42664217
pr_info("MII link monitoring set to %d ms\n", miimon);
42674218
} else if (arp_interval) {
4219+
valptr = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
4220+
arp_validate_value);
42684221
pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):",
4269-
arp_interval,
4270-
arp_validate_tbl[arp_validate_value].modename,
4271-
arp_ip_count);
4222+
arp_interval, valptr->string, arp_ip_count);
42724223

42734224
for (i = 0; i < arp_ip_count; i++)
42744225
pr_info(" %s", arp_ip_target[i]);
@@ -4292,27 +4243,29 @@ static int bond_check_params(struct bond_params *params)
42924243
}
42934244

42944245
if (primary && primary_reselect) {
4295-
primary_reselect_value = bond_parse_parm(primary_reselect,
4296-
pri_reselect_tbl);
4297-
if (primary_reselect_value == -1) {
4246+
bond_opt_initstr(&newval, primary_reselect);
4247+
valptr = bond_opt_parse(bond_opt_get(BOND_OPT_PRIMARY_RESELECT),
4248+
&newval);
4249+
if (!valptr) {
42984250
pr_err("Error: Invalid primary_reselect \"%s\"\n",
4299-
primary_reselect ==
4300-
NULL ? "NULL" : primary_reselect);
4251+
primary_reselect);
43014252
return -EINVAL;
43024253
}
4254+
primary_reselect_value = valptr->value;
43034255
} else {
43044256
primary_reselect_value = BOND_PRI_RESELECT_ALWAYS;
43054257
}
43064258

43074259
if (fail_over_mac) {
4308-
fail_over_mac_value = bond_parse_parm(fail_over_mac,
4309-
fail_over_mac_tbl);
4310-
if (fail_over_mac_value == -1) {
4260+
bond_opt_initstr(&newval, fail_over_mac);
4261+
valptr = bond_opt_parse(bond_opt_get(BOND_OPT_FAIL_OVER_MAC),
4262+
&newval);
4263+
if (!valptr) {
43114264
pr_err("Error: invalid fail_over_mac \"%s\"\n",
4312-
arp_validate == NULL ? "NULL" : arp_validate);
4265+
fail_over_mac);
43134266
return -EINVAL;
43144267
}
4315-
4268+
fail_over_mac_value = valptr->value;
43164269
if (bond_mode != BOND_MODE_ACTIVEBACKUP)
43174270
pr_warning("Warning: fail_over_mac only affects active-backup mode.\n");
43184271
} else {

0 commit comments

Comments
 (0)