Skip to content

Commit b8a9787

Browse files
Jay VosburghJeff Garzik
authored andcommitted
bonding: Allow setting max_bonds to zero
Permit bonding to function rationally if max_bonds is set to zero. This will load the module, but create no master devices (which can be created via sysfs). Requires some change to bond_create_sysfs; currently, the netdev sysfs directory is determined from the first bonding device created, but this is no longer possible. Instead, an interface from net/core is created to create and destroy files in net_class. Based on a patch submitted by Phil Oester <[email protected]>. Modified by Jay Vosburgh to fix the sysfs issue mentioned above and to update the documentation. Signed-off-by: Phil Oester <[email protected]> Signed-off-by: Jay Vosburgh <[email protected]> Signed-off-by: Jeff Garzik <[email protected]>
1 parent b59f9f7 commit b8a9787

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

Documentation/networking/bonding.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ max_bonds
376376
Specifies the number of bonding devices to create for this
377377
instance of the bonding driver. E.g., if max_bonds is 3, and
378378
the bonding driver is not already loaded, then bond0, bond1
379-
and bond2 will be created. The default value is 1.
379+
and bond2 will be created. The default value is 1. Specifying
380+
a value of 0 will load bonding, but will not create any devices.
380381

381382
miimon
382383

drivers/net/bonding/bond_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4750,11 +4750,11 @@ static int bond_check_params(struct bond_params *params)
47504750
}
47514751
}
47524752

4753-
if (max_bonds < 1 || max_bonds > INT_MAX) {
4753+
if (max_bonds < 0 || max_bonds > INT_MAX) {
47544754
printk(KERN_WARNING DRV_NAME
47554755
": Warning: max_bonds (%d) not in range %d-%d, so it "
47564756
"was reset to BOND_DEFAULT_MAX_BONDS (%d)\n",
4757-
max_bonds, 1, INT_MAX, BOND_DEFAULT_MAX_BONDS);
4757+
max_bonds, 0, INT_MAX, BOND_DEFAULT_MAX_BONDS);
47584758
max_bonds = BOND_DEFAULT_MAX_BONDS;
47594759
}
47604760

@@ -4953,7 +4953,7 @@ static int bond_check_params(struct bond_params *params)
49534953

49544954
printk("\n");
49554955

4956-
} else {
4956+
} else if (max_bonds) {
49574957
/* miimon and arp_interval not set, we need one so things
49584958
* work as expected, see bonding.txt for details
49594959
*/

drivers/net/bonding/bond_sysfs.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ extern struct bond_parm_tbl arp_validate_tbl[];
5353
extern struct bond_parm_tbl fail_over_mac_tbl[];
5454

5555
static int expected_refcount = -1;
56-
static struct class *netdev_class;
5756
/*--------------------------- Data Structures -----------------------------*/
5857

5958
/* Bonding sysfs lock. Why can't we just use the subsystem lock?
@@ -1447,19 +1446,9 @@ static struct attribute_group bonding_group = {
14471446
*/
14481447
int bond_create_sysfs(void)
14491448
{
1450-
int ret = 0;
1451-
struct bonding *firstbond;
1452-
1453-
/* get the netdev class pointer */
1454-
firstbond = container_of(bond_dev_list.next, struct bonding, bond_list);
1455-
if (!firstbond)
1456-
return -ENODEV;
1457-
1458-
netdev_class = firstbond->dev->dev.class;
1459-
if (!netdev_class)
1460-
return -ENODEV;
1449+
int ret;
14611450

1462-
ret = class_create_file(netdev_class, &class_attr_bonding_masters);
1451+
ret = netdev_class_create_file(&class_attr_bonding_masters);
14631452
/*
14641453
* Permit multiple loads of the module by ignoring failures to
14651454
* create the bonding_masters sysfs file. Bonding devices
@@ -1478,10 +1467,6 @@ int bond_create_sysfs(void)
14781467
printk(KERN_ERR
14791468
"network device named %s already exists in sysfs",
14801469
class_attr_bonding_masters.attr.name);
1481-
else {
1482-
netdev_class = NULL;
1483-
return 0;
1484-
}
14851470
}
14861471

14871472
return ret;
@@ -1493,8 +1478,7 @@ int bond_create_sysfs(void)
14931478
*/
14941479
void bond_destroy_sysfs(void)
14951480
{
1496-
if (netdev_class)
1497-
class_remove_file(netdev_class, &class_attr_bonding_masters);
1481+
netdev_class_remove_file(&class_attr_bonding_masters);
14981482
}
14991483

15001484
/*

include/linux/netdevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,9 @@ extern void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos);
15061506
extern void dev_seq_stop(struct seq_file *seq, void *v);
15071507
#endif
15081508

1509+
extern int netdev_class_create_file(struct class_attribute *class_attr);
1510+
extern void netdev_class_remove_file(struct class_attribute *class_attr);
1511+
15091512
extern void linkwatch_run_queue(void);
15101513

15111514
extern int netdev_compute_features(unsigned long all, unsigned long one);

net/core/net-sysfs.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,19 @@ int netdev_register_kobject(struct net_device *net)
468468
return device_add(dev);
469469
}
470470

471+
int netdev_class_create_file(struct class_attribute *class_attr)
472+
{
473+
return class_create_file(&net_class, class_attr);
474+
}
475+
476+
void netdev_class_remove_file(struct class_attribute *class_attr)
477+
{
478+
class_remove_file(&net_class, class_attr);
479+
}
480+
481+
EXPORT_SYMBOL(netdev_class_create_file);
482+
EXPORT_SYMBOL(netdev_class_remove_file);
483+
471484
void netdev_initialize_kobject(struct net_device *net)
472485
{
473486
struct device *device = &(net->dev);

0 commit comments

Comments
 (0)