Skip to contentSkip to conversation

bonding: set primary param via sysfs

PATCH Applied Jiri Pirko 4 participants 4 messages Sep 18, 2009 – Oct 1, 2009

Subsystems (3)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

PATCH 1/1 bonding: set primary param via sysfs

Primary module parameter passed to bonding is pernament. That means if you release the primary slave and enslave it again, it becomes the primary slave again. But if you set primary slave via sysfs, the primary slave is only set once and it's not remembered in bond->params structure. Therefore the setting is lost after releasing the primary slave. This simple one-liner fixes this.

drivers/net/bonding/bond_sysfs.c +1 -0
index 6044e12..ff449de 100644
@@ -1182,6 +1182,7 @@ static ssize_t bonding_store_primary(struct device *d,
 				       ": %s: Setting %s as primary slave.\n",
 				       bond->dev->name, slave->dev->name);
 				bond->primary_slave = slave;
+				strcpy(bond->params.primary, slave->dev->name);
 				bond_select_active_slave(bond);
 				goto out;
 			}
#1 lore raw
Quoted 1 line · Jiri Pirko

Primary module parameter passed to bonding is pernament. That means if you

typo in "permanent".

Quoted 4 lines

release the primary slave and enslave it again, it becomes the primary slave again. But if you set primary slave via sysfs, the primary slave is only set once and it's not remembered in bond->params structure. Therefore the setting is lost after releasing the primary slave. This simple one-liner fixes this.

You patch also has the side effect of fixing this strange behavior:

If you move the primary slave from one bond device to another one, it becomes the primary for this other bond device, ignoring what you might have set as the primary for this other bond device.

#modprobe bonding mode=active-backup primary=eth0
#echo +eth0 > /sys/class/net/bond0/bonding/slaves
#cat /sys/class/net/bond0/bonding/primary
eth0
#echo -eth0 > /sys/class/net/bond0/bonding/slaves

#echo +eth1 > /sys/class/net/bond1/bonding/slaves
#echo eth1 > /sys/class/net/bond1/bonding/primary
#cat /sys/class/net/bond1/bonding/primary
eth1
#echo +eth0 > /sys/class/net/bond1/bonding/slaves
#cat /sys/class/net/bond1/bonding/primary
eth0

=> Primary just changed, for no good reason.

Can someone imagine that some current configurations rely on this incredible side effect ?

Nicolas.

Quoted 14 lines
drivers/net/bonding/bond_sysfs.c +1 -0
index 6044e12..ff449de 100644
@@ -1182,6 +1182,7 @@ static ssize_t bonding_store_primary(struct device *d,
 				       ": %s: Setting %s as primary slave.\n",
 				       bond->dev->name, slave->dev->name);
 				bond->primary_slave = slave;
+				strcpy(bond->params.primary, slave->dev->name);
 				bond_select_active_slave(bond);
 				goto out;
 			}
#2 lore raw
In reply to Jiri Pirko
Quoted 13 lines · Jiri Pirko

Primary module parameter passed to bonding is pernament. That means if you release the primary slave and enslave it again, it becomes the primary slave again. But if you set primary slave via sysfs, the primary slave is only set once and it's not remembered in bond->params structure. Therefore the setting is lost after releasing the primary slave. This simple one-liner fixes this.

drivers/net/bonding/bond_sysfs.c +0 -0
index 6044e12..ff449de 100644

drivers/net/bonding/bond_sysfs.c static ssize_t bonding_store_primary(struct device *d, · line 1188

Quoted 7 lines
drivers/net/bonding/bond_sysfs.c +1 -0
@@ -1182,6 +1182,7 @@ static ssize_t bonding_store_primary(struct device *d,
 				       ": %s: Setting %s as primary slave.\n",
 				       bond->dev->name, slave->dev->name);
 				bond->primary_slave = slave;
+				strcpy(bond->params.primary, slave->dev->name);
 				bond_select_active_slave(bond);
 				goto out;
 			}

Looks good, fixes another bug I'd not heard of previously.

maintainer Applied
#3 lore raw
In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>
Date: Fri, 18 Sep 2009 14:13:22 +0200

Quoted 7 lines

Primary module parameter passed to bonding is pernament. That means if you release the primary slave and enslave it again, it becomes the primary slave again. But if you set primary slave via sysfs, the primary slave is only set once and it's not remembered in bond->params structure. Therefore the setting is lost after releasing the primary slave. This simple one-liner fixes this.

Applied, thanks Jiri.