bonding: convert all_slaves_active to use the new option API
[linux-2.6-block.git] / drivers / net / bonding / bond_sysfs.c
CommitLineData
b76cdba9
MW
1/*
2 * Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
adf8d3ff 15 * with this program; if not, see <http://www.gnu.org/licenses/>.
b76cdba9
MW
16 *
17 * The full GNU General Public License is included in this distribution in the
18 * file called LICENSE.
19 *
b76cdba9 20 */
a4aee5c8
JP
21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
b76cdba9
MW
24#include <linux/kernel.h>
25#include <linux/module.h>
b76cdba9 26#include <linux/device.h>
d43c36dc 27#include <linux/sched.h>
b76cdba9
MW
28#include <linux/fs.h>
29#include <linux/types.h>
30#include <linux/string.h>
31#include <linux/netdevice.h>
32#include <linux/inetdevice.h>
33#include <linux/in.h>
34#include <linux/sysfs.h>
b76cdba9
MW
35#include <linux/ctype.h>
36#include <linux/inet.h>
37#include <linux/rtnetlink.h>
5c5129b5 38#include <linux/etherdevice.h>
881d966b 39#include <net/net_namespace.h>
ec87fd3b
EB
40#include <net/netns/generic.h>
41#include <linux/nsproxy.h>
b76cdba9 42
b76cdba9 43#include "bonding.h"
5a03cdb7 44
3d632c3f 45#define to_dev(obj) container_of(obj, struct device, kobj)
454d7c9b 46#define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
b76cdba9 47
b76cdba9
MW
48/*
49 * "show" function for the bond_masters attribute.
50 * The class parameter is ignored.
51 */
28812fe1
AK
52static ssize_t bonding_show_bonds(struct class *cls,
53 struct class_attribute *attr,
54 char *buf)
b76cdba9 55{
4c22400a
EB
56 struct bond_net *bn =
57 container_of(attr, struct bond_net, class_attr_bonding_masters);
b76cdba9
MW
58 int res = 0;
59 struct bonding *bond;
60
7e083840 61 rtnl_lock();
b76cdba9 62
ec87fd3b 63 list_for_each_entry(bond, &bn->dev_list, bond_list) {
b76cdba9
MW
64 if (res > (PAGE_SIZE - IFNAMSIZ)) {
65 /* not enough space for another interface name */
66 if ((PAGE_SIZE - res) > 10)
67 res = PAGE_SIZE - 10;
b8843665 68 res += sprintf(buf + res, "++more++ ");
b76cdba9
MW
69 break;
70 }
b8843665 71 res += sprintf(buf + res, "%s ", bond->dev->name);
b76cdba9 72 }
1dcdcd69
WF
73 if (res)
74 buf[res-1] = '\n'; /* eat the leftover space */
7e083840
SH
75
76 rtnl_unlock();
b76cdba9
MW
77 return res;
78}
79
4c22400a 80static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname)
373500db
SH
81{
82 struct bonding *bond;
83
ec87fd3b 84 list_for_each_entry(bond, &bn->dev_list, bond_list) {
373500db
SH
85 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
86 return bond->dev;
87 }
88 return NULL;
89}
90
b76cdba9
MW
91/*
92 * "store" function for the bond_masters attribute. This is what
93 * creates and deletes entire bonds.
94 *
95 * The class parameter is ignored.
96 *
97 */
98
3d632c3f 99static ssize_t bonding_store_bonds(struct class *cls,
28812fe1 100 struct class_attribute *attr,
3d632c3f 101 const char *buffer, size_t count)
b76cdba9 102{
4c22400a
EB
103 struct bond_net *bn =
104 container_of(attr, struct bond_net, class_attr_bonding_masters);
b76cdba9
MW
105 char command[IFNAMSIZ + 1] = {0, };
106 char *ifname;
027ea041 107 int rv, res = count;
b76cdba9 108
b76cdba9
MW
109 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
110 ifname = command + 1;
111 if ((strlen(command) <= 1) ||
112 !dev_valid_name(ifname))
113 goto err_no_cmd;
114
115 if (command[0] == '+') {
a4aee5c8 116 pr_info("%s is being created...\n", ifname);
4c22400a 117 rv = bond_create(bn->net, ifname);
027ea041 118 if (rv) {
5f86cad1
PO
119 if (rv == -EEXIST)
120 pr_info("%s already exists.\n", ifname);
121 else
122 pr_info("%s creation failed.\n", ifname);
027ea041 123 res = rv;
b76cdba9 124 }
373500db
SH
125 } else if (command[0] == '-') {
126 struct net_device *bond_dev;
b76cdba9 127
027ea041 128 rtnl_lock();
4c22400a 129 bond_dev = bond_get_by_name(bn, ifname);
373500db 130 if (bond_dev) {
a4aee5c8 131 pr_info("%s is being deleted...\n", ifname);
373500db
SH
132 unregister_netdevice(bond_dev);
133 } else {
a4aee5c8 134 pr_err("unable to delete non-existent %s\n", ifname);
373500db
SH
135 res = -ENODEV;
136 }
137 rtnl_unlock();
138 } else
139 goto err_no_cmd;
027ea041 140
373500db
SH
141 /* Always return either count or an error. If you return 0, you'll
142 * get called forever, which is bad.
143 */
144 return res;
b76cdba9
MW
145
146err_no_cmd:
a4aee5c8 147 pr_err("no command found in bonding_masters. Use +ifname or -ifname.\n");
c4ebc66a 148 return -EPERM;
b76cdba9 149}
373500db 150
b76cdba9 151/* class attribute for bond_masters file. This ends up in /sys/class/net */
4c22400a
EB
152static const struct class_attribute class_attr_bonding_masters = {
153 .attr = {
154 .name = "bonding_masters",
155 .mode = S_IWUSR | S_IRUGO,
156 },
157 .show = bonding_show_bonds,
158 .store = bonding_store_bonds,
4c22400a 159};
b76cdba9 160
b76cdba9
MW
161/*
162 * Show the slaves in the current bond.
163 */
43cb76d9
GKH
164static ssize_t bonding_show_slaves(struct device *d,
165 struct device_attribute *attr, char *buf)
b76cdba9 166{
43cb76d9 167 struct bonding *bond = to_bond(d);
9caff1e7 168 struct list_head *iter;
dec1e90e 169 struct slave *slave;
170 int res = 0;
b76cdba9 171
4d1ae5fb 172 if (!rtnl_trylock())
173 return restart_syscall();
174
9caff1e7 175 bond_for_each_slave(bond, slave, iter) {
b76cdba9
MW
176 if (res > (PAGE_SIZE - IFNAMSIZ)) {
177 /* not enough space for another interface name */
178 if ((PAGE_SIZE - res) > 10)
179 res = PAGE_SIZE - 10;
7bd46508 180 res += sprintf(buf + res, "++more++ ");
b76cdba9
MW
181 break;
182 }
183 res += sprintf(buf + res, "%s ", slave->dev->name);
184 }
4d1ae5fb 185
186 rtnl_unlock();
187
1dcdcd69
WF
188 if (res)
189 buf[res-1] = '\n'; /* eat the leftover space */
dec1e90e 190
b76cdba9
MW
191 return res;
192}
193
194/*
d6641ccf 195 * Set the slaves in the current bond.
f9f3545e
JP
196 * This is supposed to be only thin wrapper for bond_enslave and bond_release.
197 * All hard work should be done there.
b76cdba9 198 */
43cb76d9
GKH
199static ssize_t bonding_store_slaves(struct device *d,
200 struct device_attribute *attr,
201 const char *buffer, size_t count)
b76cdba9
MW
202{
203 char command[IFNAMSIZ + 1] = { 0, };
204 char *ifname;
f9f3545e
JP
205 int res, ret = count;
206 struct net_device *dev;
43cb76d9 207 struct bonding *bond = to_bond(d);
b76cdba9 208
496a60cd
EB
209 if (!rtnl_trylock())
210 return restart_syscall();
027ea041 211
b76cdba9
MW
212 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
213 ifname = command + 1;
214 if ((strlen(command) <= 1) ||
215 !dev_valid_name(ifname))
216 goto err_no_cmd;
217
f9f3545e
JP
218 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
219 if (!dev) {
220 pr_info("%s: Interface %s does not exist!\n",
221 bond->dev->name, ifname);
222 ret = -ENODEV;
223 goto out;
224 }
b76cdba9 225
f9f3545e
JP
226 switch (command[0]) {
227 case '+':
228 pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name);
b76cdba9 229 res = bond_enslave(bond->dev, dev);
f9f3545e 230 break;
3d632c3f 231
f9f3545e
JP
232 case '-':
233 pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name);
234 res = bond_release(bond->dev, dev);
235 break;
b76cdba9 236
f9f3545e
JP
237 default:
238 goto err_no_cmd;
b76cdba9
MW
239 }
240
f9f3545e
JP
241 if (res)
242 ret = res;
243 goto out;
244
b76cdba9 245err_no_cmd:
a4aee5c8
JP
246 pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n",
247 bond->dev->name);
b76cdba9
MW
248 ret = -EPERM;
249
250out:
027ea041 251 rtnl_unlock();
b76cdba9
MW
252 return ret;
253}
254
3d632c3f
SH
255static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
256 bonding_store_slaves);
b76cdba9
MW
257
258/*
259 * Show and set the bonding mode. The bond interface must be down to
260 * change the mode.
261 */
43cb76d9
GKH
262static ssize_t bonding_show_mode(struct device *d,
263 struct device_attribute *attr, char *buf)
b76cdba9 264{
43cb76d9 265 struct bonding *bond = to_bond(d);
2b3798d5 266 struct bond_opt_value *val;
b76cdba9 267
2b3798d5
NA
268 val = bond_opt_get_val(BOND_OPT_MODE, bond->params.mode);
269
270 return sprintf(buf, "%s %d\n", val->string, bond->params.mode);
b76cdba9
MW
271}
272
43cb76d9
GKH
273static ssize_t bonding_store_mode(struct device *d,
274 struct device_attribute *attr,
275 const char *buf, size_t count)
b76cdba9 276{
43cb76d9 277 struct bonding *bond = to_bond(d);
2b3798d5 278 int ret;
b76cdba9 279
2b3798d5
NA
280 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_MODE, (char *)buf);
281 if (!ret)
72be35fe 282 ret = count;
8f903c70 283
b76cdba9
MW
284 return ret;
285}
3d632c3f
SH
286static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
287 bonding_show_mode, bonding_store_mode);
b76cdba9
MW
288
289/*
3d632c3f 290 * Show and set the bonding transmit hash method.
b76cdba9 291 */
43cb76d9
GKH
292static ssize_t bonding_show_xmit_hash(struct device *d,
293 struct device_attribute *attr,
294 char *buf)
b76cdba9 295{
43cb76d9 296 struct bonding *bond = to_bond(d);
a4b32ce7
NA
297 struct bond_opt_value *val;
298
299 val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy);
b76cdba9 300
a4b32ce7 301 return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy);
b76cdba9
MW
302}
303
43cb76d9
GKH
304static ssize_t bonding_store_xmit_hash(struct device *d,
305 struct device_attribute *attr,
306 const char *buf, size_t count)
b76cdba9 307{
43cb76d9 308 struct bonding *bond = to_bond(d);
a4b32ce7 309 int ret;
b76cdba9 310
a4b32ce7 311 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_XMIT_HASH, (char *)buf);
f70161c6 312 if (!ret)
313 ret = count;
314
b76cdba9
MW
315 return ret;
316}
3d632c3f
SH
317static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
318 bonding_show_xmit_hash, bonding_store_xmit_hash);
b76cdba9 319
f5b2b966
JV
320/*
321 * Show and set arp_validate.
322 */
43cb76d9
GKH
323static ssize_t bonding_show_arp_validate(struct device *d,
324 struct device_attribute *attr,
325 char *buf)
f5b2b966 326{
43cb76d9 327 struct bonding *bond = to_bond(d);
16228881
NA
328 struct bond_opt_value *val;
329
330 val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
331 bond->params.arp_validate);
f5b2b966 332
16228881 333 return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate);
f5b2b966
JV
334}
335
43cb76d9
GKH
336static ssize_t bonding_store_arp_validate(struct device *d,
337 struct device_attribute *attr,
338 const char *buf, size_t count)
f5b2b966 339{
43cb76d9 340 struct bonding *bond = to_bond(d);
16228881 341 int ret;
29c49482 342
16228881 343 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_VALIDATE, (char *)buf);
29c49482 344 if (!ret)
345 ret = count;
346
5c5038dc 347 return ret;
f5b2b966
JV
348}
349
3d632c3f
SH
350static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
351 bonding_store_arp_validate);
8599b52e
VF
352/*
353 * Show and set arp_all_targets.
354 */
355static ssize_t bonding_show_arp_all_targets(struct device *d,
356 struct device_attribute *attr,
357 char *buf)
358{
359 struct bonding *bond = to_bond(d);
edf36b24 360 struct bond_opt_value *val;
8599b52e 361
edf36b24
NA
362 val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS,
363 bond->params.arp_all_targets);
364 return sprintf(buf, "%s %d\n",
365 val->string, bond->params.arp_all_targets);
8599b52e
VF
366}
367
368static ssize_t bonding_store_arp_all_targets(struct device *d,
369 struct device_attribute *attr,
370 const char *buf, size_t count)
371{
372 struct bonding *bond = to_bond(d);
edf36b24 373 int ret;
8599b52e 374
edf36b24 375 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_ALL_TARGETS, (char *)buf);
d5c84254 376 if (!ret)
377 ret = count;
378
d5c84254 379 return ret;
8599b52e
VF
380}
381
382static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR,
383 bonding_show_arp_all_targets, bonding_store_arp_all_targets);
f5b2b966 384
dd957c57
JV
385/*
386 * Show and store fail_over_mac. User only allowed to change the
387 * value when there are no slaves.
388 */
3d632c3f
SH
389static ssize_t bonding_show_fail_over_mac(struct device *d,
390 struct device_attribute *attr,
391 char *buf)
dd957c57
JV
392{
393 struct bonding *bond = to_bond(d);
1df6b6aa 394 struct bond_opt_value *val;
dd957c57 395
1df6b6aa
NA
396 val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
397 bond->params.fail_over_mac);
398
399 return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac);
dd957c57
JV
400}
401
3d632c3f
SH
402static ssize_t bonding_store_fail_over_mac(struct device *d,
403 struct device_attribute *attr,
404 const char *buf, size_t count)
dd957c57 405{
dd957c57 406 struct bonding *bond = to_bond(d);
1df6b6aa 407 int ret;
dd957c57 408
1df6b6aa 409 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_FAIL_OVER_MAC, (char *)buf);
89901972 410 if (!ret)
411 ret = count;
3915c1e8 412
9402b746 413 return ret;
dd957c57
JV
414}
415
3d632c3f
SH
416static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
417 bonding_show_fail_over_mac, bonding_store_fail_over_mac);
dd957c57 418
b76cdba9
MW
419/*
420 * Show and set the arp timer interval. There are two tricky bits
421 * here. First, if ARP monitoring is activated, then we must disable
422 * MII monitoring. Second, if the ARP timer isn't running, we must
423 * start it.
424 */
43cb76d9
GKH
425static ssize_t bonding_show_arp_interval(struct device *d,
426 struct device_attribute *attr,
427 char *buf)
b76cdba9 428{
43cb76d9 429 struct bonding *bond = to_bond(d);
b76cdba9 430
7bd46508 431 return sprintf(buf, "%d\n", bond->params.arp_interval);
b76cdba9
MW
432}
433
43cb76d9
GKH
434static ssize_t bonding_store_arp_interval(struct device *d,
435 struct device_attribute *attr,
436 const char *buf, size_t count)
b76cdba9 437{
43cb76d9 438 struct bonding *bond = to_bond(d);
7bdb04ed 439 int ret;
06151dbc 440
7bdb04ed 441 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_INTERVAL, (char *)buf);
06151dbc 442 if (!ret)
443 ret = count;
444
b76cdba9
MW
445 return ret;
446}
3d632c3f
SH
447static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
448 bonding_show_arp_interval, bonding_store_arp_interval);
b76cdba9
MW
449
450/*
451 * Show and set the arp targets.
452 */
43cb76d9
GKH
453static ssize_t bonding_show_arp_targets(struct device *d,
454 struct device_attribute *attr,
455 char *buf)
b76cdba9 456{
43cb76d9 457 struct bonding *bond = to_bond(d);
4fb0ef58 458 int i, res = 0;
b76cdba9
MW
459
460 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
461 if (bond->params.arp_targets[i])
63779436
HH
462 res += sprintf(buf + res, "%pI4 ",
463 &bond->params.arp_targets[i]);
b76cdba9 464 }
1dcdcd69
WF
465 if (res)
466 buf[res-1] = '\n'; /* eat the leftover space */
4fb0ef58 467
b76cdba9
MW
468 return res;
469}
470
43cb76d9
GKH
471static ssize_t bonding_store_arp_targets(struct device *d,
472 struct device_attribute *attr,
473 const char *buf, size_t count)
b76cdba9 474{
43cb76d9 475 struct bonding *bond = to_bond(d);
4fb0ef58 476 int ret;
b76cdba9 477
4fb0ef58 478 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_TARGETS, (char *)buf);
7f28fa10 479 if (!ret)
480 ret = count;
481
b76cdba9
MW
482 return ret;
483}
43cb76d9 484static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
b76cdba9
MW
485
486/*
487 * Show and set the up and down delays. These must be multiples of the
488 * MII monitoring value, and are stored internally as the multiplier.
489 * Thus, we must translate to MS for the real world.
490 */
43cb76d9
GKH
491static ssize_t bonding_show_downdelay(struct device *d,
492 struct device_attribute *attr,
493 char *buf)
b76cdba9 494{
43cb76d9 495 struct bonding *bond = to_bond(d);
b76cdba9 496
7bd46508 497 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
b76cdba9
MW
498}
499
43cb76d9
GKH
500static ssize_t bonding_store_downdelay(struct device *d,
501 struct device_attribute *attr,
502 const char *buf, size_t count)
b76cdba9 503{
43cb76d9 504 struct bonding *bond = to_bond(d);
25a9b54a 505 int ret;
b76cdba9 506
25a9b54a 507 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_DOWNDELAY, (char *)buf);
c7461f9b 508 if (!ret)
509 ret = count;
b76cdba9 510
b76cdba9
MW
511 return ret;
512}
3d632c3f
SH
513static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
514 bonding_show_downdelay, bonding_store_downdelay);
b76cdba9 515
43cb76d9
GKH
516static ssize_t bonding_show_updelay(struct device *d,
517 struct device_attribute *attr,
518 char *buf)
b76cdba9 519{
43cb76d9 520 struct bonding *bond = to_bond(d);
b76cdba9 521
7bd46508 522 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
b76cdba9
MW
523
524}
525
43cb76d9
GKH
526static ssize_t bonding_store_updelay(struct device *d,
527 struct device_attribute *attr,
528 const char *buf, size_t count)
b76cdba9 529{
43cb76d9 530 struct bonding *bond = to_bond(d);
e4994612 531 int ret;
b76cdba9 532
e4994612 533 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_UPDELAY, (char *)buf);
25852e29 534 if (!ret)
535 ret = count;
536
b76cdba9
MW
537 return ret;
538}
3d632c3f
SH
539static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
540 bonding_show_updelay, bonding_store_updelay);
b76cdba9
MW
541
542/*
543 * Show and set the LACP interval. Interface must be down, and the mode
544 * must be set to 802.3ad mode.
545 */
43cb76d9
GKH
546static ssize_t bonding_show_lacp(struct device *d,
547 struct device_attribute *attr,
548 char *buf)
b76cdba9 549{
43cb76d9 550 struct bonding *bond = to_bond(d);
d3131de7 551 struct bond_opt_value *val;
b76cdba9 552
d3131de7
NA
553 val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast);
554
555 return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast);
b76cdba9
MW
556}
557
43cb76d9
GKH
558static ssize_t bonding_store_lacp(struct device *d,
559 struct device_attribute *attr,
560 const char *buf, size_t count)
b76cdba9 561{
43cb76d9 562 struct bonding *bond = to_bond(d);
d3131de7 563 int ret;
998e40bb 564
d3131de7 565 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_LACP_RATE, (char *)buf);
998e40bb 566 if (!ret)
567 ret = count;
568
b76cdba9
MW
569 return ret;
570}
3d632c3f
SH
571static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
572 bonding_show_lacp, bonding_store_lacp);
b76cdba9 573
655f8919 574static ssize_t bonding_show_min_links(struct device *d,
575 struct device_attribute *attr,
576 char *buf)
577{
578 struct bonding *bond = to_bond(d);
579
580 return sprintf(buf, "%d\n", bond->params.min_links);
581}
582
583static ssize_t bonding_store_min_links(struct device *d,
584 struct device_attribute *attr,
585 const char *buf, size_t count)
586{
587 struct bonding *bond = to_bond(d);
588 int ret;
655f8919 589
633ddc9e 590 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_MINLINKS, (char *)buf);
7d101008 591 if (!ret)
592 ret = count;
593
7d101008 594 return ret;
655f8919 595}
596static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR,
597 bonding_show_min_links, bonding_store_min_links);
598
fd989c83
JV
599static ssize_t bonding_show_ad_select(struct device *d,
600 struct device_attribute *attr,
601 char *buf)
602{
603 struct bonding *bond = to_bond(d);
9e5f5eeb 604 struct bond_opt_value *val;
fd989c83 605
9e5f5eeb
NA
606 val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select);
607
608 return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select);
fd989c83
JV
609}
610
611
612static ssize_t bonding_store_ad_select(struct device *d,
613 struct device_attribute *attr,
614 const char *buf, size_t count)
615{
fd989c83 616 struct bonding *bond = to_bond(d);
9e5f5eeb 617 int ret;
fd989c83 618
9e5f5eeb 619 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_AD_SELECT, (char *)buf);
ec029fac 620 if (!ret)
621 ret = count;
622
fd989c83
JV
623 return ret;
624}
3d632c3f
SH
625static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
626 bonding_show_ad_select, bonding_store_ad_select);
fd989c83 627
ad246c99
BH
628/*
629 * Show and set the number of peer notifications to send after a failover event.
630 */
631static ssize_t bonding_show_num_peer_notif(struct device *d,
632 struct device_attribute *attr,
633 char *buf)
634{
635 struct bonding *bond = to_bond(d);
636 return sprintf(buf, "%d\n", bond->params.num_peer_notif);
637}
638
639static ssize_t bonding_store_num_peer_notif(struct device *d,
640 struct device_attribute *attr,
641 const char *buf, size_t count)
642{
643 struct bonding *bond = to_bond(d);
2c9839c1 644 int ret;
645
ef56becb 646 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_NUM_PEER_NOTIF, (char *)buf);
2c9839c1 647 if (!ret)
648 ret = count;
649
2c9839c1 650 return ret;
ad246c99
BH
651}
652static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
653 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
654static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
655 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
656
b76cdba9
MW
657/*
658 * Show and set the MII monitor interval. There are two tricky bits
659 * here. First, if MII monitoring is activated, then we must disable
660 * ARP monitoring. Second, if the timer isn't running, we must
661 * start it.
662 */
43cb76d9
GKH
663static ssize_t bonding_show_miimon(struct device *d,
664 struct device_attribute *attr,
665 char *buf)
b76cdba9 666{
43cb76d9 667 struct bonding *bond = to_bond(d);
b76cdba9 668
7bd46508 669 return sprintf(buf, "%d\n", bond->params.miimon);
b76cdba9
MW
670}
671
43cb76d9
GKH
672static ssize_t bonding_store_miimon(struct device *d,
673 struct device_attribute *attr,
674 const char *buf, size_t count)
b76cdba9 675{
43cb76d9 676 struct bonding *bond = to_bond(d);
b98d9c66 677 int ret;
b76cdba9 678
b98d9c66 679 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_MIIMON, (char *)buf);
eecdaa6e 680 if (!ret)
681 ret = count;
682
b76cdba9
MW
683 return ret;
684}
3d632c3f
SH
685static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
686 bonding_show_miimon, bonding_store_miimon);
b76cdba9
MW
687
688/*
689 * Show and set the primary slave. The store function is much
690 * simpler than bonding_store_slaves function because it only needs to
691 * handle one interface name.
692 * The bond must be a mode that supports a primary for this be
693 * set.
694 */
43cb76d9
GKH
695static ssize_t bonding_show_primary(struct device *d,
696 struct device_attribute *attr,
697 char *buf)
b76cdba9
MW
698{
699 int count = 0;
43cb76d9 700 struct bonding *bond = to_bond(d);
b76cdba9
MW
701
702 if (bond->primary_slave)
7bd46508 703 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
b76cdba9
MW
704
705 return count;
706}
707
43cb76d9
GKH
708static ssize_t bonding_store_primary(struct device *d,
709 struct device_attribute *attr,
710 const char *buf, size_t count)
b76cdba9 711{
43cb76d9 712 struct bonding *bond = to_bond(d);
0a98a0d1 713 int ret;
b76cdba9 714
180222f0 715 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PRIMARY, (char *)buf);
0a98a0d1 716 if (!ret)
717 ret = count;
8a93664d 718
0a98a0d1 719 return ret;
b76cdba9 720}
3d632c3f
SH
721static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
722 bonding_show_primary, bonding_store_primary);
b76cdba9 723
a549952a
JP
724/*
725 * Show and set the primary_reselect flag.
726 */
727static ssize_t bonding_show_primary_reselect(struct device *d,
728 struct device_attribute *attr,
729 char *buf)
730{
731 struct bonding *bond = to_bond(d);
388d3a6d
NA
732 struct bond_opt_value *val;
733
734 val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
735 bond->params.primary_reselect);
a549952a
JP
736
737 return sprintf(buf, "%s %d\n",
388d3a6d 738 val->string, bond->params.primary_reselect);
a549952a
JP
739}
740
741static ssize_t bonding_store_primary_reselect(struct device *d,
742 struct device_attribute *attr,
743 const char *buf, size_t count)
744{
a549952a 745 struct bonding *bond = to_bond(d);
388d3a6d 746 int ret;
a549952a 747
388d3a6d
NA
748 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PRIMARY_RESELECT,
749 (char *)buf);
8a41ae44 750 if (!ret)
751 ret = count;
a549952a 752
a549952a
JP
753 return ret;
754}
755static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
756 bonding_show_primary_reselect,
757 bonding_store_primary_reselect);
758
b76cdba9
MW
759/*
760 * Show and set the use_carrier flag.
761 */
43cb76d9
GKH
762static ssize_t bonding_show_carrier(struct device *d,
763 struct device_attribute *attr,
764 char *buf)
b76cdba9 765{
43cb76d9 766 struct bonding *bond = to_bond(d);
b76cdba9 767
7bd46508 768 return sprintf(buf, "%d\n", bond->params.use_carrier);
b76cdba9
MW
769}
770
43cb76d9
GKH
771static ssize_t bonding_store_carrier(struct device *d,
772 struct device_attribute *attr,
773 const char *buf, size_t count)
b76cdba9 774{
43cb76d9 775 struct bonding *bond = to_bond(d);
0fff0608 776 int ret;
b76cdba9 777
0fff0608 778 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_USE_CARRIER, (char *)buf);
9f53e14e 779 if (!ret)
780 ret = count;
781
672bda33 782 return ret;
b76cdba9 783}
3d632c3f
SH
784static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
785 bonding_show_carrier, bonding_store_carrier);
b76cdba9
MW
786
787
788/*
789 * Show and set currently active_slave.
790 */
43cb76d9
GKH
791static ssize_t bonding_show_active_slave(struct device *d,
792 struct device_attribute *attr,
793 char *buf)
b76cdba9 794{
43cb76d9 795 struct bonding *bond = to_bond(d);
752d48b5 796 struct net_device *slave_dev;
16cd0160 797 int count = 0;
b76cdba9 798
278b2083 799 rcu_read_lock();
752d48b5
JP
800 slave_dev = bond_option_active_slave_get_rcu(bond);
801 if (slave_dev)
802 count = sprintf(buf, "%s\n", slave_dev->name);
278b2083 803 rcu_read_unlock();
804
b76cdba9
MW
805 return count;
806}
807
43cb76d9
GKH
808static ssize_t bonding_store_active_slave(struct device *d,
809 struct device_attribute *attr,
810 const char *buf, size_t count)
b76cdba9 811{
43cb76d9 812 struct bonding *bond = to_bond(d);
d1fbd3ed 813 int ret;
f4bb2e9c 814
d1fbd3ed 815 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ACTIVE_SLAVE, (char *)buf);
d9e32b21
JP
816 if (!ret)
817 ret = count;
e843fa50 818
d9e32b21 819 return ret;
b76cdba9 820}
3d632c3f
SH
821static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
822 bonding_show_active_slave, bonding_store_active_slave);
b76cdba9
MW
823
824
825/*
826 * Show link status of the bond interface.
827 */
43cb76d9
GKH
828static ssize_t bonding_show_mii_status(struct device *d,
829 struct device_attribute *attr,
830 char *buf)
b76cdba9 831{
43cb76d9 832 struct bonding *bond = to_bond(d);
b76cdba9 833
278b2083 834 return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down");
b76cdba9 835}
43cb76d9 836static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
b76cdba9 837
b76cdba9
MW
838/*
839 * Show current 802.3ad aggregator ID.
840 */
43cb76d9
GKH
841static ssize_t bonding_show_ad_aggregator(struct device *d,
842 struct device_attribute *attr,
843 char *buf)
b76cdba9
MW
844{
845 int count = 0;
43cb76d9 846 struct bonding *bond = to_bond(d);
b76cdba9
MW
847
848 if (bond->params.mode == BOND_MODE_8023AD) {
849 struct ad_info ad_info;
3d632c3f 850 count = sprintf(buf, "%d\n",
318debd8 851 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 852 ? 0 : ad_info.aggregator_id);
b76cdba9 853 }
b76cdba9
MW
854
855 return count;
856}
43cb76d9 857static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
b76cdba9
MW
858
859
860/*
861 * Show number of active 802.3ad ports.
862 */
43cb76d9
GKH
863static ssize_t bonding_show_ad_num_ports(struct device *d,
864 struct device_attribute *attr,
865 char *buf)
b76cdba9
MW
866{
867 int count = 0;
43cb76d9 868 struct bonding *bond = to_bond(d);
b76cdba9
MW
869
870 if (bond->params.mode == BOND_MODE_8023AD) {
871 struct ad_info ad_info;
3d632c3f 872 count = sprintf(buf, "%d\n",
318debd8 873 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 874 ? 0 : ad_info.ports);
b76cdba9 875 }
b76cdba9
MW
876
877 return count;
878}
43cb76d9 879static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
b76cdba9
MW
880
881
882/*
883 * Show current 802.3ad actor key.
884 */
43cb76d9
GKH
885static ssize_t bonding_show_ad_actor_key(struct device *d,
886 struct device_attribute *attr,
887 char *buf)
b76cdba9
MW
888{
889 int count = 0;
43cb76d9 890 struct bonding *bond = to_bond(d);
b76cdba9
MW
891
892 if (bond->params.mode == BOND_MODE_8023AD) {
893 struct ad_info ad_info;
3d632c3f 894 count = sprintf(buf, "%d\n",
318debd8 895 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 896 ? 0 : ad_info.actor_key);
b76cdba9 897 }
b76cdba9
MW
898
899 return count;
900}
43cb76d9 901static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
b76cdba9
MW
902
903
904/*
905 * Show current 802.3ad partner key.
906 */
43cb76d9
GKH
907static ssize_t bonding_show_ad_partner_key(struct device *d,
908 struct device_attribute *attr,
909 char *buf)
b76cdba9
MW
910{
911 int count = 0;
43cb76d9 912 struct bonding *bond = to_bond(d);
b76cdba9
MW
913
914 if (bond->params.mode == BOND_MODE_8023AD) {
915 struct ad_info ad_info;
3d632c3f 916 count = sprintf(buf, "%d\n",
318debd8 917 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 918 ? 0 : ad_info.partner_key);
b76cdba9 919 }
b76cdba9
MW
920
921 return count;
922}
43cb76d9 923static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
b76cdba9
MW
924
925
926/*
927 * Show current 802.3ad partner mac.
928 */
43cb76d9
GKH
929static ssize_t bonding_show_ad_partner_mac(struct device *d,
930 struct device_attribute *attr,
931 char *buf)
b76cdba9
MW
932{
933 int count = 0;
43cb76d9 934 struct bonding *bond = to_bond(d);
b76cdba9
MW
935
936 if (bond->params.mode == BOND_MODE_8023AD) {
937 struct ad_info ad_info;
3d632c3f 938 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
e174961c 939 count = sprintf(buf, "%pM\n", ad_info.partner_system);
b76cdba9 940 }
b76cdba9
MW
941
942 return count;
943}
43cb76d9 944static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
b76cdba9 945
bb1d9123
AG
946/*
947 * Show the queue_ids of the slaves in the current bond.
948 */
949static ssize_t bonding_show_queue_id(struct device *d,
950 struct device_attribute *attr,
951 char *buf)
952{
bb1d9123 953 struct bonding *bond = to_bond(d);
9caff1e7 954 struct list_head *iter;
dec1e90e 955 struct slave *slave;
956 int res = 0;
bb1d9123
AG
957
958 if (!rtnl_trylock())
959 return restart_syscall();
960
9caff1e7 961 bond_for_each_slave(bond, slave, iter) {
79236680
NP
962 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
963 /* not enough space for another interface_name:queue_id pair */
bb1d9123
AG
964 if ((PAGE_SIZE - res) > 10)
965 res = PAGE_SIZE - 10;
966 res += sprintf(buf + res, "++more++ ");
967 break;
968 }
969 res += sprintf(buf + res, "%s:%d ",
970 slave->dev->name, slave->queue_id);
971 }
bb1d9123
AG
972 if (res)
973 buf[res-1] = '\n'; /* eat the leftover space */
4d1ae5fb 974
bb1d9123 975 rtnl_unlock();
dec1e90e 976
bb1d9123
AG
977 return res;
978}
979
980/*
981 * Set the queue_ids of the slaves in the current bond. The bond
982 * interface must be enslaved for this to work.
983 */
984static ssize_t bonding_store_queue_id(struct device *d,
985 struct device_attribute *attr,
986 const char *buffer, size_t count)
987{
bb1d9123 988 struct bonding *bond = to_bond(d);
24089ba1 989 int ret;
bb1d9123 990
24089ba1
NA
991 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_QUEUE_ID, (char *)buffer);
992 if (!ret)
993 ret = count;
bb1d9123 994
bb1d9123 995 return ret;
bb1d9123 996}
bb1d9123
AG
997static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
998 bonding_store_queue_id);
999
1000
ebd8e497
AG
1001/*
1002 * Show and set the all_slaves_active flag.
1003 */
1004static ssize_t bonding_show_slaves_active(struct device *d,
1005 struct device_attribute *attr,
1006 char *buf)
1007{
1008 struct bonding *bond = to_bond(d);
1009
1010 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
1011}
1012
1013static ssize_t bonding_store_slaves_active(struct device *d,
1014 struct device_attribute *attr,
1015 const char *buf, size_t count)
1016{
ebd8e497 1017 struct bonding *bond = to_bond(d);
3df01162 1018 int ret;
ebd8e497 1019
3df01162
NA
1020 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ALL_SLAVES_ACTIVE,
1021 (char *)buf);
1cc0b1e3 1022 if (!ret)
1023 ret = count;
b76cdba9 1024
672bda33 1025 return ret;
ebd8e497
AG
1026}
1027static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
1028 bonding_show_slaves_active, bonding_store_slaves_active);
b76cdba9 1029
c2952c31
FL
1030/*
1031 * Show and set the number of IGMP membership reports to send on link failure
1032 */
1033static ssize_t bonding_show_resend_igmp(struct device *d,
94265cf5
FL
1034 struct device_attribute *attr,
1035 char *buf)
c2952c31
FL
1036{
1037 struct bonding *bond = to_bond(d);
1038
1039 return sprintf(buf, "%d\n", bond->params.resend_igmp);
1040}
1041
1042static ssize_t bonding_store_resend_igmp(struct device *d,
94265cf5
FL
1043 struct device_attribute *attr,
1044 const char *buf, size_t count)
c2952c31
FL
1045{
1046 int new_value, ret = count;
1047 struct bonding *bond = to_bond(d);
1048
1049 if (sscanf(buf, "%d", &new_value) != 1) {
1050 pr_err("%s: no resend_igmp value specified.\n",
1051 bond->dev->name);
d8838de7 1052 return -EINVAL;
c2952c31
FL
1053 }
1054
d8838de7 1055 if (!rtnl_trylock())
1056 return restart_syscall();
c2952c31 1057
d8838de7 1058 ret = bond_option_resend_igmp_set(bond, new_value);
1059 if (!ret)
1060 ret = count;
1061
1062 rtnl_unlock();
c2952c31
FL
1063 return ret;
1064}
1065
1066static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1067 bonding_show_resend_igmp, bonding_store_resend_igmp);
1068
7eacd038
NH
1069
1070static ssize_t bonding_show_lp_interval(struct device *d,
1071 struct device_attribute *attr,
1072 char *buf)
1073{
1074 struct bonding *bond = to_bond(d);
1075 return sprintf(buf, "%d\n", bond->params.lp_interval);
1076}
1077
1078static ssize_t bonding_store_lp_interval(struct device *d,
1079 struct device_attribute *attr,
1080 const char *buf, size_t count)
1081{
1082 struct bonding *bond = to_bond(d);
8d836d09 1083 int new_value, ret;
7eacd038
NH
1084
1085 if (sscanf(buf, "%d", &new_value) != 1) {
1086 pr_err("%s: no lp interval value specified.\n",
1087 bond->dev->name);
8d836d09 1088 return -EINVAL;
7eacd038
NH
1089 }
1090
8d836d09 1091 if (!rtnl_trylock())
1092 return restart_syscall();
7eacd038 1093
8d836d09 1094 ret = bond_option_lp_interval_set(bond, new_value);
1095 if (!ret)
1096 ret = count;
1097
1098 rtnl_unlock();
7eacd038
NH
1099 return ret;
1100}
1101
1102static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
1103 bonding_show_lp_interval, bonding_store_lp_interval);
1104
73958329
NA
1105static ssize_t bonding_show_packets_per_slave(struct device *d,
1106 struct device_attribute *attr,
1107 char *buf)
1108{
1109 struct bonding *bond = to_bond(d);
a752a8b9 1110 unsigned int packets_per_slave = bond->params.packets_per_slave;
a752a8b9 1111 return sprintf(buf, "%u\n", packets_per_slave);
73958329
NA
1112}
1113
1114static ssize_t bonding_store_packets_per_slave(struct device *d,
1115 struct device_attribute *attr,
1116 const char *buf, size_t count)
1117{
1118 struct bonding *bond = to_bond(d);
aa59d851 1119 int ret;
c13ab3ff 1120
aa59d851
NA
1121 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PACKETS_PER_SLAVE,
1122 (char *)buf);
c13ab3ff 1123 if (!ret)
1124 ret = count;
1125
73958329
NA
1126 return ret;
1127}
1128
1129static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR,
1130 bonding_show_packets_per_slave,
1131 bonding_store_packets_per_slave);
1132
b76cdba9 1133static struct attribute *per_bond_attrs[] = {
43cb76d9
GKH
1134 &dev_attr_slaves.attr,
1135 &dev_attr_mode.attr,
dd957c57 1136 &dev_attr_fail_over_mac.attr,
43cb76d9 1137 &dev_attr_arp_validate.attr,
8599b52e 1138 &dev_attr_arp_all_targets.attr,
43cb76d9
GKH
1139 &dev_attr_arp_interval.attr,
1140 &dev_attr_arp_ip_target.attr,
1141 &dev_attr_downdelay.attr,
1142 &dev_attr_updelay.attr,
1143 &dev_attr_lacp_rate.attr,
fd989c83 1144 &dev_attr_ad_select.attr,
43cb76d9 1145 &dev_attr_xmit_hash_policy.attr,
ad246c99
BH
1146 &dev_attr_num_grat_arp.attr,
1147 &dev_attr_num_unsol_na.attr,
43cb76d9
GKH
1148 &dev_attr_miimon.attr,
1149 &dev_attr_primary.attr,
a549952a 1150 &dev_attr_primary_reselect.attr,
43cb76d9
GKH
1151 &dev_attr_use_carrier.attr,
1152 &dev_attr_active_slave.attr,
1153 &dev_attr_mii_status.attr,
1154 &dev_attr_ad_aggregator.attr,
1155 &dev_attr_ad_num_ports.attr,
1156 &dev_attr_ad_actor_key.attr,
1157 &dev_attr_ad_partner_key.attr,
1158 &dev_attr_ad_partner_mac.attr,
bb1d9123 1159 &dev_attr_queue_id.attr,
ebd8e497 1160 &dev_attr_all_slaves_active.attr,
c2952c31 1161 &dev_attr_resend_igmp.attr,
655f8919 1162 &dev_attr_min_links.attr,
7eacd038 1163 &dev_attr_lp_interval.attr,
73958329 1164 &dev_attr_packets_per_slave.attr,
b76cdba9
MW
1165 NULL,
1166};
1167
1168static struct attribute_group bonding_group = {
1169 .name = "bonding",
1170 .attrs = per_bond_attrs,
1171};
1172
1173/*
1174 * Initialize sysfs. This sets up the bonding_masters file in
1175 * /sys/class/net.
1176 */
4c22400a 1177int bond_create_sysfs(struct bond_net *bn)
b76cdba9 1178{
b8a9787e 1179 int ret;
b76cdba9 1180
4c22400a 1181 bn->class_attr_bonding_masters = class_attr_bonding_masters;
01718e36 1182 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
4c22400a 1183
58292cbe
TH
1184 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
1185 bn->net);
877cbd36
JV
1186 /*
1187 * Permit multiple loads of the module by ignoring failures to
1188 * create the bonding_masters sysfs file. Bonding devices
1189 * created by second or subsequent loads of the module will
1190 * not be listed in, or controllable by, bonding_masters, but
1191 * will have the usual "bonding" sysfs directory.
1192 *
1193 * This is done to preserve backwards compatibility for
1194 * initscripts/sysconfig, which load bonding multiple times to
1195 * configure multiple bonding devices.
1196 */
1197 if (ret == -EEXIST) {
38d2f38b 1198 /* Is someone being kinky and naming a device bonding_master? */
4c22400a 1199 if (__dev_get_by_name(bn->net,
38d2f38b 1200 class_attr_bonding_masters.attr.name))
a4aee5c8 1201 pr_err("network device named %s already exists in sysfs",
38d2f38b 1202 class_attr_bonding_masters.attr.name);
130aa61a 1203 ret = 0;
877cbd36 1204 }
b76cdba9
MW
1205
1206 return ret;
1207
1208}
1209
1210/*
1211 * Remove /sys/class/net/bonding_masters.
1212 */
4c22400a 1213void bond_destroy_sysfs(struct bond_net *bn)
b76cdba9 1214{
58292cbe 1215 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
b76cdba9
MW
1216}
1217
1218/*
1219 * Initialize sysfs for each bond. This sets up and registers
1220 * the 'bondctl' directory for each individual bond under /sys/class/net.
1221 */
6151b3d4 1222void bond_prepare_sysfs_group(struct bonding *bond)
b76cdba9 1223{
6151b3d4 1224 bond->dev->sysfs_groups[0] = &bonding_group;
b76cdba9
MW
1225}
1226