Skip to contentSkip to conversation

bonding: handle slave's name change with primary_slave logic

PATCH Applied Veaceslav Falico 3 participants 4 messages Jan 16, 2014 – Jan 17, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 bonding: handle slave's name change with primary_slave logic

Currently, if a slave's name change, we just pass it by. However, if the slave is a current primary_slave, then we end up with using a slave, whose name != params.primary, for primary_slave. And vice-versa, if we don't have a primary_slave but have params.primary set - we will not detected a new primary_slave.

Fix this by catching the NETDEV_CHANGENAME event and setting primary_slave accordingly. Also, if the primary_slave was changed, issue a reselection of the active slave, cause the priorities have changed.

CC Ding Tianhong <[email protected]>
CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>

---

Notes:

    v3->v4:
    Fix style issue.
    
    v2->v3:
    Reword the info message, per Jay's comment.
    
    v1->v2:
    Proper patch
 drivers/net/bonding/bond_main.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/net/bonding/bond_main.c +21 -3
index f2fe6cb..f00dd45 100644
@@ -2860,9 +2860,27 @@ static int bond_slave_netdev_event(unsigned long event,
 		 */
 		break;
 	case NETDEV_CHANGENAME:
-		/*
-		 * TODO: handle changing the primary's name
-		 */
+		/* we don't care if we don't have primary set */
+		if (!USES_PRIMARY(bond->params.mode) ||
+		    !bond->params.primary[0])
+			break;
+
+		if (slave == bond->primary_slave) {
+			/* slave's name changed - he's no longer primary */
+			bond->primary_slave = NULL;
+		} else if (!strcmp(slave_dev->name, bond->params.primary)) {
+			/* we have a new primary slave */
+			bond->primary_slave = slave;
+		} else { /* we didn't change primary - exit */
+			break;
+		}
+
+		pr_info("%s: Primary slave changed to %s, reselecting active slave.\n",
+			bond->dev->name, bond->primary_slave ? slave_dev->name :
+							       "none");
+		write_lock_bh(&bond->curr_slave_lock);
+		bond_select_active_slave(bond);
+		write_unlock_bh(&bond->curr_slave_lock);
 		break;
 	case NETDEV_FEAT_CHANGE:
 		bond_compute_features(bond);
Signature · 1 line
1.8.4
Acked-by on v4 1/1
#1 lore raw
Quoted 46 lines · Veaceslav Falico

Currently, if a slave's name change, we just pass it by. However, if the slave is a current primary_slave, then we end up with using a slave, whose name != params.primary, for primary_slave. And vice-versa, if we don't have a primary_slave but have params.primary set - we will not detected a new primary_slave.

Fix this by catching the NETDEV_CHANGENAME event and setting primary_slave accordingly. Also, if the primary_slave was changed, issue a reselection of the active slave, cause the priorities have changed.

CC Ding Tianhong <[email protected]>
CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>

---

Notes:

    v3->v4:
    Fix style issue.
    
    v2->v3:
    Reword the info message, per Jay's comment.
    
    v1->v2:
    Proper patch
 drivers/net/bonding/bond_main.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/net/bonding/bond_main.c +5 -3
index f2fe6cb..f00dd45 100644
@@ -2860,9 +2860,27 @@ static int bond_slave_netdev_event(unsigned long event,
 		 */
 		break;
 	case NETDEV_CHANGENAME:
-		/*
-		 * TODO: handle changing the primary's name
-		 */
+		/* we don't care if we don't have primary set */
+		if (!USES_PRIMARY(bond->params.mode) ||
+		    !bond->params.primary[0])
+			break;
+

drivers/net/bonding/bond_main.c static int bond_slave_netdev_event(unsigned long event, · line 2877

Quoted 10 lines
drivers/net/bonding/bond_main.c +10 -0
+		if (slave == bond->primary_slave) {
+			/* slave's name changed - he's no longer primary */
+			bond->primary_slave = NULL;
+		} else if (!strcmp(slave_dev->name, bond->params.primary)) {
+			/* we have a new primary slave */
+			bond->primary_slave = slave;
+		} else { /* we didn't change primary - exit */
+			break;
+		}
+

why not remove all the { } for the if else, there are only one line for each if.

but seems good for logic.

Quoted 10 lines
drivers/net/bonding/bond_main.c +6 -0
+		pr_info("%s: Primary slave changed to %s, reselecting active slave.\n",
+			bond->dev->name, bond->primary_slave ? slave_dev->name :
+							       "none");
+		write_lock_bh(&bond->curr_slave_lock);
+		bond_select_active_slave(bond);
+		write_unlock_bh(&bond->curr_slave_lock);
 		break;
 	case NETDEV_FEAT_CHANGE:
 		bond_compute_features(bond);
#2 lore raw
Quoted 50 lines · Ding Tianhong
Quoted 49 lines · Veaceslav Falico

Currently, if a slave's name change, we just pass it by. However, if the slave is a current primary_slave, then we end up with using a slave, whose name != params.primary, for primary_slave. And vice-versa, if we don't have a primary_slave but have params.primary set - we will not detected a new primary_slave.

Fix this by catching the NETDEV_CHANGENAME event and setting primary_slave accordingly. Also, if the primary_slave was changed, issue a reselection of the active slave, cause the priorities have changed.

CC Ding Tianhong <[email protected]>
CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>

---

Notes:

    v3->v4:
    Fix style issue.

    v2->v3:
    Reword the info message, per Jay's comment.

    v1->v2:
    Proper patch
 drivers/net/bonding/bond_main.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/net/bonding/bond_main.c +8 -3
index f2fe6cb..f00dd45 100644
@@ -2860,9 +2860,27 @@ static int bond_slave_netdev_event(unsigned long event,
 		 */
 		break;
 	case NETDEV_CHANGENAME:
-		/*
-		 * TODO: handle changing the primary's name
-		 */
+		/* we don't care if we don't have primary set */
+		if (!USES_PRIMARY(bond->params.mode) ||
+		    !bond->params.primary[0])
+			break;
+
+		if (slave == bond->primary_slave) {
+			/* slave's name changed - he's no longer primary */
+			bond->primary_slave = NULL;
Quoted 8 lines

drivers/net/bonding/bond_main.c static int bond_slave_netdev_event(unsigned long event, · line 2877

Quoted 7 lines
drivers/net/bonding/bond_main.c +7 -0
+		} else if (!strcmp(slave_dev->name, bond->params.primary)) {
+			/* we have a new primary slave */
+			bond->primary_slave = slave;
+		} else { /* we didn't change primary - exit */
+			break;
+		}
+

why not remove all the { } for the if else, there are only one line for each if.

It's written so in CodingStyles, as spotted by Sergei -
http://www.spinics.net/lists/netdev/msg266612.html .

Quoted 17 lines

but seems good for logic.

Quoted 10 lines
drivers/net/bonding/bond_main.c +6 -0
+		pr_info("%s: Primary slave changed to %s, reselecting active slave.\n",
+			bond->dev->name, bond->primary_slave ? slave_dev->name :
+							       "none");
+		write_lock_bh(&bond->curr_slave_lock);
+		bond_select_active_slave(bond);
+		write_unlock_bh(&bond->curr_slave_lock);
 		break;
 	case NETDEV_FEAT_CHANGE:
 		bond_compute_features(bond);
maintainer Applied
#3 lore raw
In reply to Veaceslav Falico

From: Veaceslav Falico <[email protected]>
Date: Thu, 16 Jan 2014 02:04:29 +0100

Quoted 10 lines

Currently, if a slave's name change, we just pass it by. However, if the slave is a current primary_slave, then we end up with using a slave, whose name != params.primary, for primary_slave. And vice-versa, if we don't have a primary_slave but have params.primary set - we will not detected a new primary_slave.

Fix this by catching the NETDEV_CHANGENAME event and setting primary_slave accordingly. Also, if the primary_slave was changed, issue a reselection of the active slave, cause the priorities have changed.

Quoted 5 lines
CC Ding Tianhong <[email protected]>
CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>

Applied, thanks.