aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Aleksandrov <nikolay@redhat.com>2014-05-08 08:23:54 -0400
committerDavid S. Miller <davem@davemloft.net>2014-05-09 16:12:51 -0400
commitdc3e5d18f2a21f4523f75800f4062348a7e94d14 (patch)
treebc264e7f8164e1c6ca266d90360a2308e24ea564
parentbe7faf7168e831f17b85a96f2f797f504b66cfd7 (diff)
bonding: make a generic sysfs option store and fix comments
Introduce a generic option store function for sysfs and remove the specific ones. The attribute name is used to match against the option which is to be set. Also adjust the "name" of tlb_dynamic_lb option to match the sysfs entry and fix the comments and comment style in bond_sysfs.c The comments which showed obvious behaviour (i.e. behaviour that's seen in the option's entry) are removed, the ones that explained important points about the setting function have been moved above the respective set function in bond_options.c There's only 1 exception: num_unsol_na/num_grat_arp since it has 2 names CC: Jay Vosburgh <j.vosburgh@gmail.com> CC: Veaceslav Falico <vfalico@gmail.com> CC: Andy Gospodarek <andy@greyhouse.net> CC: David S. Miller <davem@davemloft.net> Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/bonding/bond_options.c29
-rw-r--r--drivers/net/bonding/bond_options.h1
-rw-r--r--drivers/net/bonding/bond_sysfs.c568
3 files changed, 107 insertions, 491 deletions
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 9fba7a1e6d51..6dc49da106d6 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -374,7 +374,7 @@ static const struct bond_option bond_opts[] = {
374 }, 374 },
375 [BOND_OPT_TLB_DYNAMIC_LB] = { 375 [BOND_OPT_TLB_DYNAMIC_LB] = {
376 .id = BOND_OPT_TLB_DYNAMIC_LB, 376 .id = BOND_OPT_TLB_DYNAMIC_LB,
377 .name = "dynamic_lb", 377 .name = "tlb_dynamic_lb",
378 .desc = "Enable dynamic flow shuffling", 378 .desc = "Enable dynamic flow shuffling",
379 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_TLB)), 379 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_TLB)),
380 .values = bond_tlb_dynamic_lb_tbl, 380 .values = bond_tlb_dynamic_lb_tbl,
@@ -384,6 +384,21 @@ static const struct bond_option bond_opts[] = {
384 { } 384 { }
385}; 385};
386 386
387/* Searches for an option by name */
388const struct bond_option *bond_opt_get_by_name(const char *name)
389{
390 const struct bond_option *opt;
391 int option;
392
393 for (option = 0; option < BOND_OPT_LAST; option++) {
394 opt = bond_opt_get(option);
395 if (opt && !strcmp(opt->name, name))
396 return opt;
397 }
398
399 return NULL;
400}
401
387/* Searches for a value in opt's values[] table */ 402/* Searches for a value in opt's values[] table */
388const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val) 403const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val)
389{ 404{
@@ -762,6 +777,10 @@ static int bond_option_active_slave_set(struct bonding *bond,
762 return ret; 777 return ret;
763} 778}
764 779
780/* There are two tricky bits here. First, if MII monitoring is activated, then
781 * we must disable ARP monitoring. Second, if the timer isn't running, we must
782 * start it.
783 */
765static int bond_option_miimon_set(struct bonding *bond, 784static int bond_option_miimon_set(struct bonding *bond,
766 const struct bond_opt_value *newval) 785 const struct bond_opt_value *newval)
767{ 786{
@@ -800,6 +819,10 @@ static int bond_option_miimon_set(struct bonding *bond,
800 return 0; 819 return 0;
801} 820}
802 821
822/* Set up and down delays. These must be multiples of the
823 * MII monitoring value, and are stored internally as the multiplier.
824 * Thus, we must translate to MS for the real world.
825 */
803static int bond_option_updelay_set(struct bonding *bond, 826static int bond_option_updelay_set(struct bonding *bond,
804 const struct bond_opt_value *newval) 827 const struct bond_opt_value *newval)
805{ 828{
@@ -858,6 +881,10 @@ static int bond_option_use_carrier_set(struct bonding *bond,
858 return 0; 881 return 0;
859} 882}
860 883
884/* There are two tricky bits here. First, if ARP monitoring is activated, then
885 * we must disable MII monitoring. Second, if the ARP timer isn't running,
886 * we must start it.
887 */
861static int bond_option_arp_interval_set(struct bonding *bond, 888static int bond_option_arp_interval_set(struct bonding *bond,
862 const struct bond_opt_value *newval) 889 const struct bond_opt_value *newval)
863{ 890{
diff --git a/drivers/net/bonding/bond_options.h b/drivers/net/bonding/bond_options.h
index c1860f06145a..17ded5b29176 100644
--- a/drivers/net/bonding/bond_options.h
+++ b/drivers/net/bonding/bond_options.h
@@ -105,6 +105,7 @@ int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf);
105const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt, 105const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
106 struct bond_opt_value *val); 106 struct bond_opt_value *val);
107const struct bond_option *bond_opt_get(unsigned int option); 107const struct bond_option *bond_opt_get(unsigned int option);
108const struct bond_option *bond_opt_get_by_name(const char *name);
108const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val); 109const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val);
109 110
110/* This helper is used to initialize a bond_opt_value structure for parameter 111/* This helper is used to initialize a bond_opt_value structure for parameter
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 431892f1a4ce..5a59b85cdfc2 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -45,8 +45,7 @@
45#define to_dev(obj) container_of(obj, struct device, kobj) 45#define to_dev(obj) container_of(obj, struct device, kobj)
46#define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd)))) 46#define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
47 47
48/* 48/* "show" function for the bond_masters attribute.
49 * "show" function for the bond_masters attribute.
50 * The class parameter is ignored. 49 * The class parameter is ignored.
51 */ 50 */
52static ssize_t bonding_show_bonds(struct class *cls, 51static ssize_t bonding_show_bonds(struct class *cls,
@@ -88,14 +87,12 @@ static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifna
88 return NULL; 87 return NULL;
89} 88}
90 89
91/* 90/* "store" function for the bond_masters attribute. This is what
92 * "store" function for the bond_masters attribute. This is what
93 * creates and deletes entire bonds. 91 * creates and deletes entire bonds.
94 * 92 *
95 * The class parameter is ignored. 93 * The class parameter is ignored.
96 * 94 *
97 */ 95 */
98
99static ssize_t bonding_store_bonds(struct class *cls, 96static ssize_t bonding_store_bonds(struct class *cls,
100 struct class_attribute *attr, 97 struct class_attribute *attr,
101 const char *buffer, size_t count) 98 const char *buffer, size_t count)
@@ -158,9 +155,26 @@ static const struct class_attribute class_attr_bonding_masters = {
158 .store = bonding_store_bonds, 155 .store = bonding_store_bonds,
159}; 156};
160 157
161/* 158/* Generic "store" method for bonding sysfs option setting */
162 * Show the slaves in the current bond. 159static ssize_t bonding_sysfs_store_option(struct device *d,
163 */ 160 struct device_attribute *attr,
161 const char *buffer, size_t count)
162{
163 struct bonding *bond = to_bond(d);
164 const struct bond_option *opt;
165 int ret;
166
167 opt = bond_opt_get_by_name(attr->attr.name);
168 if (WARN_ON(!opt))
169 return -ENOENT;
170 ret = bond_opt_tryset_rtnl(bond, opt->id, (char *)buffer);
171 if (!ret)
172 ret = count;
173
174 return ret;
175}
176
177/* Show the slaves in the current bond. */
164static ssize_t bonding_show_slaves(struct device *d, 178static ssize_t bonding_show_slaves(struct device *d,
165 struct device_attribute *attr, char *buf) 179 struct device_attribute *attr, char *buf)
166{ 180{
@@ -190,32 +204,10 @@ static ssize_t bonding_show_slaves(struct device *d,
190 204
191 return res; 205 return res;
192} 206}
193
194/*
195 * Set the slaves in the current bond.
196 * This is supposed to be only thin wrapper for bond_enslave and bond_release.
197 * All hard work should be done there.
198 */
199static ssize_t bonding_store_slaves(struct device *d,
200 struct device_attribute *attr,
201 const char *buffer, size_t count)
202{
203 struct bonding *bond = to_bond(d);
204 int ret;
205
206 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_SLAVES, (char *)buffer);
207 if (!ret)
208 ret = count;
209
210 return ret;
211}
212static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, 207static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
213 bonding_store_slaves); 208 bonding_sysfs_store_option);
214 209
215/* 210/* Show the bonding mode. */
216 * Show and set the bonding mode. The bond interface must be down to
217 * change the mode.
218 */
219static ssize_t bonding_show_mode(struct device *d, 211static ssize_t bonding_show_mode(struct device *d,
220 struct device_attribute *attr, char *buf) 212 struct device_attribute *attr, char *buf)
221{ 213{
@@ -226,26 +218,10 @@ static ssize_t bonding_show_mode(struct device *d,
226 218
227 return sprintf(buf, "%s %d\n", val->string, bond->params.mode); 219 return sprintf(buf, "%s %d\n", val->string, bond->params.mode);
228} 220}
229
230static ssize_t bonding_store_mode(struct device *d,
231 struct device_attribute *attr,
232 const char *buf, size_t count)
233{
234 struct bonding *bond = to_bond(d);
235 int ret;
236
237 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_MODE, (char *)buf);
238 if (!ret)
239 ret = count;
240
241 return ret;
242}
243static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, 221static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
244 bonding_show_mode, bonding_store_mode); 222 bonding_show_mode, bonding_sysfs_store_option);
245 223
246/* 224/* Show the bonding transmit hash method. */
247 * Show and set the bonding transmit hash method.
248 */
249static ssize_t bonding_show_xmit_hash(struct device *d, 225static ssize_t bonding_show_xmit_hash(struct device *d,
250 struct device_attribute *attr, 226 struct device_attribute *attr,
251 char *buf) 227 char *buf)
@@ -257,26 +233,10 @@ static ssize_t bonding_show_xmit_hash(struct device *d,
257 233
258 return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy); 234 return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy);
259} 235}
260
261static ssize_t bonding_store_xmit_hash(struct device *d,
262 struct device_attribute *attr,
263 const char *buf, size_t count)
264{
265 struct bonding *bond = to_bond(d);
266 int ret;
267
268 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_XMIT_HASH, (char *)buf);
269 if (!ret)
270 ret = count;
271
272 return ret;
273}
274static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, 236static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
275 bonding_show_xmit_hash, bonding_store_xmit_hash); 237 bonding_show_xmit_hash, bonding_sysfs_store_option);
276 238
277/* 239/* Show arp_validate. */
278 * Show and set arp_validate.
279 */
280static ssize_t bonding_show_arp_validate(struct device *d, 240static ssize_t bonding_show_arp_validate(struct device *d,
281 struct device_attribute *attr, 241 struct device_attribute *attr,
282 char *buf) 242 char *buf)
@@ -289,26 +249,10 @@ static ssize_t bonding_show_arp_validate(struct device *d,
289 249
290 return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate); 250 return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate);
291} 251}
292
293static ssize_t bonding_store_arp_validate(struct device *d,
294 struct device_attribute *attr,
295 const char *buf, size_t count)
296{
297 struct bonding *bond = to_bond(d);
298 int ret;
299
300 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_VALIDATE, (char *)buf);
301 if (!ret)
302 ret = count;
303
304 return ret;
305}
306
307static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, 252static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
308 bonding_store_arp_validate); 253 bonding_sysfs_store_option);
309/* 254
310 * Show and set arp_all_targets. 255/* Show arp_all_targets. */
311 */
312static ssize_t bonding_show_arp_all_targets(struct device *d, 256static ssize_t bonding_show_arp_all_targets(struct device *d,
313 struct device_attribute *attr, 257 struct device_attribute *attr,
314 char *buf) 258 char *buf)
@@ -321,28 +265,10 @@ static ssize_t bonding_show_arp_all_targets(struct device *d,
321 return sprintf(buf, "%s %d\n", 265 return sprintf(buf, "%s %d\n",
322 val->string, bond->params.arp_all_targets); 266 val->string, bond->params.arp_all_targets);
323} 267}
324
325static ssize_t bonding_store_arp_all_targets(struct device *d,
326 struct device_attribute *attr,
327 const char *buf, size_t count)
328{
329 struct bonding *bond = to_bond(d);
330 int ret;
331
332 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_ALL_TARGETS, (char *)buf);
333 if (!ret)
334 ret = count;
335
336 return ret;
337}
338
339static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR, 268static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR,
340 bonding_show_arp_all_targets, bonding_store_arp_all_targets); 269 bonding_show_arp_all_targets, bonding_sysfs_store_option);
341 270
342/* 271/* Show fail_over_mac. */
343 * Show and store fail_over_mac. User only allowed to change the
344 * value when there are no slaves.
345 */
346static ssize_t bonding_show_fail_over_mac(struct device *d, 272static ssize_t bonding_show_fail_over_mac(struct device *d,
347 struct device_attribute *attr, 273 struct device_attribute *attr,
348 char *buf) 274 char *buf)
@@ -355,30 +281,10 @@ static ssize_t bonding_show_fail_over_mac(struct device *d,
355 281
356 return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac); 282 return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac);
357} 283}
358
359static ssize_t bonding_store_fail_over_mac(struct device *d,
360 struct device_attribute *attr,
361 const char *buf, size_t count)
362{
363 struct bonding *bond = to_bond(d);
364 int ret;
365
366 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_FAIL_OVER_MAC, (char *)buf);
367 if (!ret)
368 ret = count;
369
370 return ret;
371}
372
373static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, 284static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
374 bonding_show_fail_over_mac, bonding_store_fail_over_mac); 285 bonding_show_fail_over_mac, bonding_sysfs_store_option);
375 286
376/* 287/* Show the arp timer interval. */
377 * Show and set the arp timer interval. There are two tricky bits
378 * here. First, if ARP monitoring is activated, then we must disable
379 * MII monitoring. Second, if the ARP timer isn't running, we must
380 * start it.
381 */
382static ssize_t bonding_show_arp_interval(struct device *d, 288static ssize_t bonding_show_arp_interval(struct device *d,
383 struct device_attribute *attr, 289 struct device_attribute *attr,
384 char *buf) 290 char *buf)
@@ -387,26 +293,10 @@ static ssize_t bonding_show_arp_interval(struct device *d,
387 293
388 return sprintf(buf, "%d\n", bond->params.arp_interval); 294 return sprintf(buf, "%d\n", bond->params.arp_interval);
389} 295}
390
391static ssize_t bonding_store_arp_interval(struct device *d,
392 struct device_attribute *attr,
393 const char *buf, size_t count)
394{
395 struct bonding *bond = to_bond(d);
396 int ret;
397
398 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_INTERVAL, (char *)buf);
399 if (!ret)
400 ret = count;
401
402 return ret;
403}
404static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR, 296static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
405 bonding_show_arp_interval, bonding_store_arp_interval); 297 bonding_show_arp_interval, bonding_sysfs_store_option);
406 298
407/* 299/* Show the arp targets. */
408 * Show and set the arp targets.
409 */
410static ssize_t bonding_show_arp_targets(struct device *d, 300static ssize_t bonding_show_arp_targets(struct device *d,
411 struct device_attribute *attr, 301 struct device_attribute *attr,
412 char *buf) 302 char *buf)
@@ -424,27 +314,10 @@ static ssize_t bonding_show_arp_targets(struct device *d,
424 314
425 return res; 315 return res;
426} 316}
317static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR,
318 bonding_show_arp_targets, bonding_sysfs_store_option);
427 319
428static ssize_t bonding_store_arp_targets(struct device *d, 320/* Show the up and down delays. */
429 struct device_attribute *attr,
430 const char *buf, size_t count)
431{
432 struct bonding *bond = to_bond(d);
433 int ret;
434
435 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_TARGETS, (char *)buf);
436 if (!ret)
437 ret = count;
438
439 return ret;
440}
441static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
442
443/*
444 * Show and set the up and down delays. These must be multiples of the
445 * MII monitoring value, and are stored internally as the multiplier.
446 * Thus, we must translate to MS for the real world.
447 */
448static ssize_t bonding_show_downdelay(struct device *d, 321static ssize_t bonding_show_downdelay(struct device *d,
449 struct device_attribute *attr, 322 struct device_attribute *attr,
450 char *buf) 323 char *buf)
@@ -453,22 +326,8 @@ static ssize_t bonding_show_downdelay(struct device *d,
453 326
454 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); 327 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
455} 328}
456
457static ssize_t bonding_store_downdelay(struct device *d,
458 struct device_attribute *attr,
459 const char *buf, size_t count)
460{
461 struct bonding *bond = to_bond(d);
462 int ret;
463
464 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_DOWNDELAY, (char *)buf);
465 if (!ret)
466 ret = count;
467
468 return ret;
469}
470static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, 329static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
471 bonding_show_downdelay, bonding_store_downdelay); 330 bonding_show_downdelay, bonding_sysfs_store_option);
472 331
473static ssize_t bonding_show_updelay(struct device *d, 332static ssize_t bonding_show_updelay(struct device *d,
474 struct device_attribute *attr, 333 struct device_attribute *attr,
@@ -479,27 +338,10 @@ static ssize_t bonding_show_updelay(struct device *d,
479 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); 338 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
480 339
481} 340}
482
483static ssize_t bonding_store_updelay(struct device *d,
484 struct device_attribute *attr,
485 const char *buf, size_t count)
486{
487 struct bonding *bond = to_bond(d);
488 int ret;
489
490 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_UPDELAY, (char *)buf);
491 if (!ret)
492 ret = count;
493
494 return ret;
495}
496static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR, 341static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
497 bonding_show_updelay, bonding_store_updelay); 342 bonding_show_updelay, bonding_sysfs_store_option);
498 343
499/* 344/* Show the LACP interval. */
500 * Show and set the LACP interval. Interface must be down, and the mode
501 * must be set to 802.3ad mode.
502 */
503static ssize_t bonding_show_lacp(struct device *d, 345static ssize_t bonding_show_lacp(struct device *d,
504 struct device_attribute *attr, 346 struct device_attribute *attr,
505 char *buf) 347 char *buf)
@@ -511,22 +353,8 @@ static ssize_t bonding_show_lacp(struct device *d,
511 353
512 return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast); 354 return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast);
513} 355}
514
515static ssize_t bonding_store_lacp(struct device *d,
516 struct device_attribute *attr,
517 const char *buf, size_t count)
518{
519 struct bonding *bond = to_bond(d);
520 int ret;
521
522 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_LACP_RATE, (char *)buf);
523 if (!ret)
524 ret = count;
525
526 return ret;
527}
528static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, 356static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
529 bonding_show_lacp, bonding_store_lacp); 357 bonding_show_lacp, bonding_sysfs_store_option);
530 358
531static ssize_t bonding_show_min_links(struct device *d, 359static ssize_t bonding_show_min_links(struct device *d,
532 struct device_attribute *attr, 360 struct device_attribute *attr,
@@ -536,22 +364,8 @@ static ssize_t bonding_show_min_links(struct device *d,
536 364
537 return sprintf(buf, "%d\n", bond->params.min_links); 365 return sprintf(buf, "%d\n", bond->params.min_links);
538} 366}
539
540static ssize_t bonding_store_min_links(struct device *d,
541 struct device_attribute *attr,
542 const char *buf, size_t count)
543{
544 struct bonding *bond = to_bond(d);
545 int ret;
546
547 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_MINLINKS, (char *)buf);
548 if (!ret)
549 ret = count;
550
551 return ret;
552}
553static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR, 367static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR,
554 bonding_show_min_links, bonding_store_min_links); 368 bonding_show_min_links, bonding_sysfs_store_option);
555 369
556static ssize_t bonding_show_ad_select(struct device *d, 370static ssize_t bonding_show_ad_select(struct device *d,
557 struct device_attribute *attr, 371 struct device_attribute *attr,
@@ -564,27 +378,10 @@ static ssize_t bonding_show_ad_select(struct device *d,
564 378
565 return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select); 379 return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select);
566} 380}
567
568
569static ssize_t bonding_store_ad_select(struct device *d,
570 struct device_attribute *attr,
571 const char *buf, size_t count)
572{
573 struct bonding *bond = to_bond(d);
574 int ret;
575
576 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_AD_SELECT, (char *)buf);
577 if (!ret)
578 ret = count;
579
580 return ret;
581}
582static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, 381static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
583 bonding_show_ad_select, bonding_store_ad_select); 382 bonding_show_ad_select, bonding_sysfs_store_option);
584 383
585/* 384/* Show and set the number of peer notifications to send after a failover event. */
586 * Show and set the number of peer notifications to send after a failover event.
587 */
588static ssize_t bonding_show_num_peer_notif(struct device *d, 385static ssize_t bonding_show_num_peer_notif(struct device *d,
589 struct device_attribute *attr, 386 struct device_attribute *attr,
590 char *buf) 387 char *buf)
@@ -611,12 +408,7 @@ static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
611static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, 408static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
612 bonding_show_num_peer_notif, bonding_store_num_peer_notif); 409 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
613 410
614/* 411/* Show the MII monitor interval. */
615 * Show and set the MII monitor interval. There are two tricky bits
616 * here. First, if MII monitoring is activated, then we must disable
617 * ARP monitoring. Second, if the timer isn't running, we must
618 * start it.
619 */
620static ssize_t bonding_show_miimon(struct device *d, 412static ssize_t bonding_show_miimon(struct device *d,
621 struct device_attribute *attr, 413 struct device_attribute *attr,
622 char *buf) 414 char *buf)
@@ -625,30 +417,10 @@ static ssize_t bonding_show_miimon(struct device *d,
625 417
626 return sprintf(buf, "%d\n", bond->params.miimon); 418 return sprintf(buf, "%d\n", bond->params.miimon);
627} 419}
628
629static ssize_t bonding_store_miimon(struct device *d,
630 struct device_attribute *attr,
631 const char *buf, size_t count)
632{
633 struct bonding *bond = to_bond(d);
634 int ret;
635
636 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_MIIMON, (char *)buf);
637 if (!ret)
638 ret = count;
639
640 return ret;
641}
642static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, 420static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
643 bonding_show_miimon, bonding_store_miimon); 421 bonding_show_miimon, bonding_sysfs_store_option);
644 422
645/* 423/* Show the primary slave. */
646 * Show and set the primary slave. The store function is much
647 * simpler than bonding_store_slaves function because it only needs to
648 * handle one interface name.
649 * The bond must be a mode that supports a primary for this be
650 * set.
651 */
652static ssize_t bonding_show_primary(struct device *d, 424static ssize_t bonding_show_primary(struct device *d,
653 struct device_attribute *attr, 425 struct device_attribute *attr,
654 char *buf) 426 char *buf)
@@ -661,26 +433,10 @@ static ssize_t bonding_show_primary(struct device *d,
661 433
662 return count; 434 return count;
663} 435}
664
665static ssize_t bonding_store_primary(struct device *d,
666 struct device_attribute *attr,
667 const char *buf, size_t count)
668{
669 struct bonding *bond = to_bond(d);
670 int ret;
671
672 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PRIMARY, (char *)buf);
673 if (!ret)
674 ret = count;
675
676 return ret;
677}
678static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, 436static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
679 bonding_show_primary, bonding_store_primary); 437 bonding_show_primary, bonding_sysfs_store_option);
680 438
681/* 439/* Show the primary_reselect flag. */
682 * Show and set the primary_reselect flag.
683 */
684static ssize_t bonding_show_primary_reselect(struct device *d, 440static ssize_t bonding_show_primary_reselect(struct device *d,
685 struct device_attribute *attr, 441 struct device_attribute *attr,
686 char *buf) 442 char *buf)
@@ -694,28 +450,10 @@ static ssize_t bonding_show_primary_reselect(struct device *d,
694 return sprintf(buf, "%s %d\n", 450 return sprintf(buf, "%s %d\n",
695 val->string, bond->params.primary_reselect); 451 val->string, bond->params.primary_reselect);
696} 452}
697
698static ssize_t bonding_store_primary_reselect(struct device *d,
699 struct device_attribute *attr,
700 const char *buf, size_t count)
701{
702 struct bonding *bond = to_bond(d);
703 int ret;
704
705 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PRIMARY_RESELECT,
706 (char *)buf);
707 if (!ret)
708 ret = count;
709
710 return ret;
711}
712static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, 453static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
713 bonding_show_primary_reselect, 454 bonding_show_primary_reselect, bonding_sysfs_store_option);
714 bonding_store_primary_reselect);
715 455
716/* 456/* Show the use_carrier flag. */
717 * Show and set the use_carrier flag.
718 */
719static ssize_t bonding_show_carrier(struct device *d, 457static ssize_t bonding_show_carrier(struct device *d,
720 struct device_attribute *attr, 458 struct device_attribute *attr,
721 char *buf) 459 char *buf)
@@ -724,27 +462,11 @@ static ssize_t bonding_show_carrier(struct device *d,
724 462
725 return sprintf(buf, "%d\n", bond->params.use_carrier); 463 return sprintf(buf, "%d\n", bond->params.use_carrier);
726} 464}
727
728static ssize_t bonding_store_carrier(struct device *d,
729 struct device_attribute *attr,
730 const char *buf, size_t count)
731{
732 struct bonding *bond = to_bond(d);
733 int ret;
734
735 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_USE_CARRIER, (char *)buf);
736 if (!ret)
737 ret = count;
738
739 return ret;
740}
741static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, 465static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
742 bonding_show_carrier, bonding_store_carrier); 466 bonding_show_carrier, bonding_sysfs_store_option);
743 467
744 468
745/* 469/* Show currently active_slave. */
746 * Show and set currently active_slave.
747 */
748static ssize_t bonding_show_active_slave(struct device *d, 470static ssize_t bonding_show_active_slave(struct device *d,
749 struct device_attribute *attr, 471 struct device_attribute *attr,
750 char *buf) 472 char *buf)
@@ -761,27 +483,10 @@ static ssize_t bonding_show_active_slave(struct device *d,
761 483
762 return count; 484 return count;
763} 485}
764
765static ssize_t bonding_store_active_slave(struct device *d,
766 struct device_attribute *attr,
767 const char *buf, size_t count)
768{
769 struct bonding *bond = to_bond(d);
770 int ret;
771
772 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ACTIVE_SLAVE, (char *)buf);
773 if (!ret)
774 ret = count;
775
776 return ret;
777}
778static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, 486static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
779 bonding_show_active_slave, bonding_store_active_slave); 487 bonding_show_active_slave, bonding_sysfs_store_option);
780 488
781 489/* Show link status of the bond interface. */
782/*
783 * Show link status of the bond interface.
784 */
785static ssize_t bonding_show_mii_status(struct device *d, 490static ssize_t bonding_show_mii_status(struct device *d,
786 struct device_attribute *attr, 491 struct device_attribute *attr,
787 char *buf) 492 char *buf)
@@ -792,9 +497,7 @@ static ssize_t bonding_show_mii_status(struct device *d,
792} 497}
793static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); 498static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
794 499
795/* 500/* Show current 802.3ad aggregator ID. */
796 * Show current 802.3ad aggregator ID.
797 */
798static ssize_t bonding_show_ad_aggregator(struct device *d, 501static ssize_t bonding_show_ad_aggregator(struct device *d,
799 struct device_attribute *attr, 502 struct device_attribute *attr,
800 char *buf) 503 char *buf)
@@ -814,9 +517,7 @@ static ssize_t bonding_show_ad_aggregator(struct device *d,
814static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); 517static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
815 518
816 519
817/* 520/* Show number of active 802.3ad ports. */
818 * Show number of active 802.3ad ports.
819 */
820static ssize_t bonding_show_ad_num_ports(struct device *d, 521static ssize_t bonding_show_ad_num_ports(struct device *d,
821 struct device_attribute *attr, 522 struct device_attribute *attr,
822 char *buf) 523 char *buf)
@@ -836,9 +537,7 @@ static ssize_t bonding_show_ad_num_ports(struct device *d,
836static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL); 537static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
837 538
838 539
839/* 540/* Show current 802.3ad actor key. */
840 * Show current 802.3ad actor key.
841 */
842static ssize_t bonding_show_ad_actor_key(struct device *d, 541static ssize_t bonding_show_ad_actor_key(struct device *d,
843 struct device_attribute *attr, 542 struct device_attribute *attr,
844 char *buf) 543 char *buf)
@@ -858,9 +557,7 @@ static ssize_t bonding_show_ad_actor_key(struct device *d,
858static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL); 557static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
859 558
860 559
861/* 560/* Show current 802.3ad partner key. */
862 * Show current 802.3ad partner key.
863 */
864static ssize_t bonding_show_ad_partner_key(struct device *d, 561static ssize_t bonding_show_ad_partner_key(struct device *d,
865 struct device_attribute *attr, 562 struct device_attribute *attr,
866 char *buf) 563 char *buf)
@@ -880,9 +577,7 @@ static ssize_t bonding_show_ad_partner_key(struct device *d,
880static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL); 577static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
881 578
882 579
883/* 580/* Show current 802.3ad partner mac. */
884 * Show current 802.3ad partner mac.
885 */
886static ssize_t bonding_show_ad_partner_mac(struct device *d, 581static ssize_t bonding_show_ad_partner_mac(struct device *d,
887 struct device_attribute *attr, 582 struct device_attribute *attr,
888 char *buf) 583 char *buf)
@@ -900,9 +595,7 @@ static ssize_t bonding_show_ad_partner_mac(struct device *d,
900} 595}
901static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL); 596static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
902 597
903/* 598/* Show the queue_ids of the slaves in the current bond. */
904 * Show the queue_ids of the slaves in the current bond.
905 */
906static ssize_t bonding_show_queue_id(struct device *d, 599static ssize_t bonding_show_queue_id(struct device *d,
907 struct device_attribute *attr, 600 struct device_attribute *attr,
908 char *buf) 601 char *buf)
@@ -933,31 +626,11 @@ static ssize_t bonding_show_queue_id(struct device *d,
933 626
934 return res; 627 return res;
935} 628}
936
937/*
938 * Set the queue_ids of the slaves in the current bond. The bond
939 * interface must be enslaved for this to work.
940 */
941static ssize_t bonding_store_queue_id(struct device *d,
942 struct device_attribute *attr,
943 const char *buffer, size_t count)
944{
945 struct bonding *bond = to_bond(d);
946 int ret;
947
948 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_QUEUE_ID, (char *)buffer);
949 if (!ret)
950 ret = count;
951
952 return ret;
953}
954static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id, 629static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
955 bonding_store_queue_id); 630 bonding_sysfs_store_option);
956 631
957 632
958/* 633/* Show the all_slaves_active flag. */
959 * Show and set the all_slaves_active flag.
960 */
961static ssize_t bonding_show_slaves_active(struct device *d, 634static ssize_t bonding_show_slaves_active(struct device *d,
962 struct device_attribute *attr, 635 struct device_attribute *attr,
963 char *buf) 636 char *buf)
@@ -966,27 +639,10 @@ static ssize_t bonding_show_slaves_active(struct device *d,
966 639
967 return sprintf(buf, "%d\n", bond->params.all_slaves_active); 640 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
968} 641}
969
970static ssize_t bonding_store_slaves_active(struct device *d,
971 struct device_attribute *attr,
972 const char *buf, size_t count)
973{
974 struct bonding *bond = to_bond(d);
975 int ret;
976
977 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ALL_SLAVES_ACTIVE,
978 (char *)buf);
979 if (!ret)
980 ret = count;
981
982 return ret;
983}
984static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR, 642static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
985 bonding_show_slaves_active, bonding_store_slaves_active); 643 bonding_show_slaves_active, bonding_sysfs_store_option);
986 644
987/* 645/* Show the number of IGMP membership reports to send on link failure */
988 * Show and set the number of IGMP membership reports to send on link failure
989 */
990static ssize_t bonding_show_resend_igmp(struct device *d, 646static ssize_t bonding_show_resend_igmp(struct device *d,
991 struct device_attribute *attr, 647 struct device_attribute *attr,
992 char *buf) 648 char *buf)
@@ -995,23 +651,8 @@ static ssize_t bonding_show_resend_igmp(struct device *d,
995 651
996 return sprintf(buf, "%d\n", bond->params.resend_igmp); 652 return sprintf(buf, "%d\n", bond->params.resend_igmp);
997} 653}
998
999static ssize_t bonding_store_resend_igmp(struct device *d,
1000 struct device_attribute *attr,
1001 const char *buf, size_t count)
1002{
1003 struct bonding *bond = to_bond(d);
1004 int ret;
1005
1006 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_RESEND_IGMP, (char *)buf);
1007 if (!ret)
1008 ret = count;
1009
1010 return ret;
1011}
1012
1013static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR, 654static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1014 bonding_show_resend_igmp, bonding_store_resend_igmp); 655 bonding_show_resend_igmp, bonding_sysfs_store_option);
1015 656
1016 657
1017static ssize_t bonding_show_lp_interval(struct device *d, 658static ssize_t bonding_show_lp_interval(struct device *d,
@@ -1019,25 +660,11 @@ static ssize_t bonding_show_lp_interval(struct device *d,
1019 char *buf) 660 char *buf)
1020{ 661{
1021 struct bonding *bond = to_bond(d); 662 struct bonding *bond = to_bond(d);
1022 return sprintf(buf, "%d\n", bond->params.lp_interval);
1023}
1024
1025static ssize_t bonding_store_lp_interval(struct device *d,
1026 struct device_attribute *attr,
1027 const char *buf, size_t count)
1028{
1029 struct bonding *bond = to_bond(d);
1030 int ret;
1031
1032 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_LP_INTERVAL, (char *)buf);
1033 if (!ret)
1034 ret = count;
1035 663
1036 return ret; 664 return sprintf(buf, "%d\n", bond->params.lp_interval);
1037} 665}
1038
1039static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR, 666static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
1040 bonding_show_lp_interval, bonding_store_lp_interval); 667 bonding_show_lp_interval, bonding_sysfs_store_option);
1041 668
1042static ssize_t bonding_show_tlb_dynamic_lb(struct device *d, 669static ssize_t bonding_show_tlb_dynamic_lb(struct device *d,
1043 struct device_attribute *attr, 670 struct device_attribute *attr,
@@ -1046,26 +673,8 @@ static ssize_t bonding_show_tlb_dynamic_lb(struct device *d,
1046 struct bonding *bond = to_bond(d); 673 struct bonding *bond = to_bond(d);
1047 return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb); 674 return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb);
1048} 675}
1049
1050static ssize_t bonding_store_tlb_dynamic_lb(struct device *d,
1051 struct device_attribute *attr,
1052 const char *buf,
1053 size_t count)
1054{
1055 struct bonding *bond = to_bond(d);
1056 int ret;
1057
1058 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_TLB_DYNAMIC_LB,
1059 (char *)buf);
1060 if (!ret)
1061 ret = count;
1062
1063 return ret;
1064}
1065
1066static DEVICE_ATTR(tlb_dynamic_lb, S_IRUGO | S_IWUSR, 676static DEVICE_ATTR(tlb_dynamic_lb, S_IRUGO | S_IWUSR,
1067 bonding_show_tlb_dynamic_lb, 677 bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option);
1068 bonding_store_tlb_dynamic_lb);
1069 678
1070static ssize_t bonding_show_packets_per_slave(struct device *d, 679static ssize_t bonding_show_packets_per_slave(struct device *d,
1071 struct device_attribute *attr, 680 struct device_attribute *attr,
@@ -1073,27 +682,11 @@ static ssize_t bonding_show_packets_per_slave(struct device *d,
1073{ 682{
1074 struct bonding *bond = to_bond(d); 683 struct bonding *bond = to_bond(d);
1075 unsigned int packets_per_slave = bond->params.packets_per_slave; 684 unsigned int packets_per_slave = bond->params.packets_per_slave;
1076 return sprintf(buf, "%u\n", packets_per_slave);
1077}
1078
1079static ssize_t bonding_store_packets_per_slave(struct device *d,
1080 struct device_attribute *attr,
1081 const char *buf, size_t count)
1082{
1083 struct bonding *bond = to_bond(d);
1084 int ret;
1085 685
1086 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PACKETS_PER_SLAVE, 686 return sprintf(buf, "%u\n", packets_per_slave);
1087 (char *)buf);
1088 if (!ret)
1089 ret = count;
1090
1091 return ret;
1092} 687}
1093
1094static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR, 688static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR,
1095 bonding_show_packets_per_slave, 689 bonding_show_packets_per_slave, bonding_sysfs_store_option);
1096 bonding_store_packets_per_slave);
1097 690
1098static struct attribute *per_bond_attrs[] = { 691static struct attribute *per_bond_attrs[] = {
1099 &dev_attr_slaves.attr, 692 &dev_attr_slaves.attr,
@@ -1136,8 +729,7 @@ static struct attribute_group bonding_group = {
1136 .attrs = per_bond_attrs, 729 .attrs = per_bond_attrs,
1137}; 730};
1138 731
1139/* 732/* Initialize sysfs. This sets up the bonding_masters file in
1140 * Initialize sysfs. This sets up the bonding_masters file in
1141 * /sys/class/net. 733 * /sys/class/net.
1142 */ 734 */
1143int bond_create_sysfs(struct bond_net *bn) 735int bond_create_sysfs(struct bond_net *bn)
@@ -1149,8 +741,7 @@ int bond_create_sysfs(struct bond_net *bn)
1149 741
1150 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters, 742 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
1151 bn->net); 743 bn->net);
1152 /* 744 /* Permit multiple loads of the module by ignoring failures to
1153 * Permit multiple loads of the module by ignoring failures to
1154 * create the bonding_masters sysfs file. Bonding devices 745 * create the bonding_masters sysfs file. Bonding devices
1155 * created by second or subsequent loads of the module will 746 * created by second or subsequent loads of the module will
1156 * not be listed in, or controllable by, bonding_masters, but 747 * not be listed in, or controllable by, bonding_masters, but
@@ -1173,16 +764,13 @@ int bond_create_sysfs(struct bond_net *bn)
1173 764
1174} 765}
1175 766
1176/* 767/* Remove /sys/class/net/bonding_masters. */
1177 * Remove /sys/class/net/bonding_masters.
1178 */
1179void bond_destroy_sysfs(struct bond_net *bn) 768void bond_destroy_sysfs(struct bond_net *bn)
1180{ 769{
1181 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net); 770 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
1182} 771}
1183 772
1184/* 773/* Initialize sysfs for each bond. This sets up and registers
1185 * Initialize sysfs for each bond. This sets up and registers
1186 * the 'bondctl' directory for each individual bond under /sys/class/net. 774 * the 'bondctl' directory for each individual bond under /sys/class/net.
1187 */ 775 */
1188void bond_prepare_sysfs_group(struct bonding *bond) 776void bond_prepare_sysfs_group(struct bonding *bond)