bonding: "primary_reselect" with "failure" is not working properly
Subsystems (3)
PATCH v2 1/1 bonding: "primary_reselect" with "failure" is not working properly
When "primary_reselect" is set to "failure", primary interface should not become active until current active slave is up. But if we set first member of bond device as a "primary" interface and "primary_reselect" is set to "failure" then whenever primary interface's link get back(up) it become active slave even if current active slave is still up.
With this patch, "bond_find_best_slave" will not traverse members if primary interface is not candidate for failover/reselection and current active slave is still up.
---
v2: return "curr" instead of "bond->curr_active_slave".
drivers/net/bonding/bond_main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/bonding/bond_main.c +9 -1
@@ -715,7 +715,7 @@ static bool bond_should_change_active(struct bonding *bond)*/ static struct slave *bond_find_best_slave (struct bonding *bond) { -struct slave *slave, *bestslave =NULL , *primary; +struct slave *slave, *bestslave =NULL , *primary, *curr;struct list_head *iter;int mintime = bond->params.updelay;
@@ -724,6 +724,14 @@ static struct slave *bond_find_best_slave(struct bonding *bond) bond_should_change_active(bond))return primary; +/* We are here means primary interface is not candidate for +* reslection/failover. If currenet active slave is still up +* then there is no meaning to traverse members. +*/ + curr =rtnl_dereference (bond->curr_active_slave); +if (curr && curr->link ==BOND_LINK_UP ) +return curr; +bond_for_each_slave (bond, slave, iter) {if (slave->link ==BOND_LINK_UP )return slave;
Signature · 1 line
1.9.1
[ added netdev to cc ]
Quoted 2 lines · Mazhar Rana
When "
primary_reselect" is set to "failure", primary interface should not become active until current active slave is up. But if we set first
I think you mean "until current active slave is down" here, not
"up."
Quoted 35 lines
member of bond device as a "primary" interface and "
primary_reselect" is set to "failure" then whenever primary interface's link get back(up) it become active slave even if current active slave is still up.With this patch, "
bond_find_best_slave" will not traverse members if primary interface is not candidate for failover/reselection and current active slave is still up.Signed-off-by Mazhar Rana <[email protected]>Reviewed-by Sanket Shah <[email protected]>---
v2: return "curr" instead of "bond->curr_active_slave".
drivers/net/bonding/bond_main.c| 10 +++++++++-1 file changed, 9 insertions(+), 1 deletion(-)drivers/net/bonding/bond_main.c +2
-1@@ -715,7 +715,7 @@ static bool bond_should_change_active(struct bonding *bond)*/ static struct slave *bond_find_best_slave (struct bonding *bond) { -struct slave *slave, *bestslave =NULL , *primary; +struct slave *slave, *bestslave =NULL , *primary, *curr;struct list_head *iter;int mintime = bond->params.updelay;@@ -724,6 +724,14 @@ static struct slave *bond_find_best_slave(struct bonding *bond) bond_should_change_active(bond))return primary; +/* We are here means primary interface is not candidate for
drivers/net/bonding/bond_main.c static struct slave *bond_find_best_slave(struct bonding *bond) · line 737
Quoted 10 lines
drivers/net/bonding/bond_main.c +7
-0+* reslection/failover. If currenet active slave is still up +* then there is no meaning to traverse members. +*/ + curr =rtnl_dereference (bond->curr_active_slave); +if (curr && curr->link ==BOND_LINK_UP ) +return curr; +bond_for_each_slave (bond, slave, iter) {if (slave->link ==BOND_LINK_UP )return slave;
I believe the above patch will work, but I also think these
functions are kind of hacky, as bond_should_change_active() doesn't really give the answer its name implies, so we have to second guess here.
I think the following, while a bigger change, ends up with
clearer code. Compile tested only. Comments?
-J
drivers/net/bonding/bond_main.c +31 -17
@@ -689,40 +689,54 @@ out: } -static bool bond_should_change_active (struct bonding *bond) +static struct slave *bond_choose_primary_or_current (struct bonding *bond) {struct slave *prim =rtnl_dereference (bond->primary_slave);struct slave *curr =rtnl_dereference (bond->curr_active_slave); -if (!prim || !curr || curr->link !=BOND_LINK_UP ) -return true; +if (!prim || !prim->link ==BOND_LINK_UP ) +return curr; +if (bond->force_primary) { bond->force_primary = false; -return true; +return prim; + } + +if (!curr || curr->link !=BOND_LINK_UP ) +return prim; + +/* At this point, prim and curr are both up */ +switch (bond->params.primary_reselect) { +case BOND_PRI_RESELECT_ALWAYS : +return prim; +case BOND_PRI_RESELECT_BETTER : +if (prim->speed < curr->speed) +return curr; +if (prim->speed == curr->speed && prim->duplex <= curr->duplex) +return curr; +return prim; +case BOND_PRI_RESELECT_FAILURE : +return curr; +default : +netdev_err (bond->dev,"impossible primary_reselect %d\n" , + bond->params.primary_reselect); +return curr; } -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_BETTER && - (prim->speed < curr->speed || - (prim->speed == curr->speed && prim->duplex <= curr->duplex))) -return false; -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_FAILURE ) -return false; -return true; }/** -* find_best_interface - select the best available slave to be the active one +* bond_find_best_slave - select the best available slave to be the active one * @bond: our bonding struct */ static struct slave *bond_find_best_slave (struct bonding *bond) { -struct slave *slave, *bestslave =NULL , *primary; +struct slave *slave, *bestslave =NULL ;struct list_head *iter;int mintime = bond->params.updelay; - primary =rtnl_dereference (bond->primary_slave); -if (primary && primary->link ==BOND_LINK_UP && -bond_should_change_active (bond)) -return primary; + slave =bond_choose_primary_or_current (bond); +if (slave) +return slave;bond_for_each_slave (bond, slave, iter) {if (slave->link ==BOND_LINK_UP )
---
-Jay Vosburgh, [email protected]
Hi Jay,
Quoted 8 lines · Jay Vosburgh
[ added netdev to cc ]
Quoted 2 lines · Mazhar Rana
When "
primary_reselect" is set to "failure", primary interface should not become active until current active slave is up. But if we set firstI think you mean "until current active slave is down" here, not
"up."
Yes, It should be "up", grammatical mistake
Quoted 64 lines
Quoted 36 lines
member of bond device as a "primary" interface and "
primary_reselect" is set to "failure" then whenever primary interface's link get back(up) it become active slave even if current active slave is still up.With this patch, "
bond_find_best_slave" will not traverse members if primary interface is not candidate for failover/reselection and current active slave is still up.Signed-off-by Mazhar Rana <[email protected]>Reviewed-by Sanket Shah <[email protected]>---
v2: return "curr" instead of "bond->curr_active_slave".
drivers/net/bonding/bond_main.c| 10 +++++++++-1 file changed, 9 insertions(+), 1 deletion(-)drivers/net/bonding/bond_main.c +2
-1@@ -715,7 +715,7 @@ static bool bond_should_change_active(struct bonding *bond)*/ static struct slave *bond_find_best_slave (struct bonding *bond) { -struct slave *slave, *bestslave =NULL , *primary; +struct slave *slave, *bestslave =NULL , *primary, *curr;struct list_head *iter;int mintime = bond->params.updelay;@@ -724,6 +724,14 @@ static struct slave *bond_find_best_slave(struct bonding *bond) bond_should_change_active(bond))return primary; +/* We are here means primary interface is not candidate for drivers/net/bonding/bond_main.c static struct slave *bond_find_best_slave(struct bonding *bond) · line 737
Quoted 10 lines
drivers/net/bonding/bond_main.c +7
-0+* reslection/failover. If currenet active slave is still up +* then there is no meaning to traverse members. +*/ + curr =rtnl_dereference (bond->curr_active_slave); +if (curr && curr->link ==BOND_LINK_UP ) +return curr; +bond_for_each_slave (bond, slave, iter) {if (slave->link ==BOND_LINK_UP )return slave;I believe the above patch will work, but I also think these
functions are kind of hacky, asbond_should_change_active()doesn't really give the answer its name implies, so we have to second guess here.I think the following, while a bigger change, ends up with
clearer code. Compile tested only. Comments?-Jdrivers/net/bonding/bond_main.c +0
-0@@ -689,40 +689,54 @@ out: }
drivers/net/bonding/bond_main.c out: · line 698
Quoted 10 lines
drivers/net/bonding/bond_main.c +3
-3-static bool bond_should_change_active (struct bonding *bond) +static struct slave *bond_choose_primary_or_current (struct bonding *bond) {struct slave *prim =rtnl_dereference (bond->primary_slave);struct slave *curr =rtnl_dereference (bond->curr_active_slave); -if (!prim || !curr || curr->link !=BOND_LINK_UP ) -return true; +if (!prim || !prim->link ==BOND_LINK_UP ) +return curr;
This will not work when prim and curr both are pointing to same interface, e.g. bond0={eth0, eth1, eth2}, prim=eth0, curr=eth0, now if prim goes down then it will return curr which is again pointing to primary interface, so failover never happen.
Quoted 43 lines
drivers/net/bonding/bond_main.c +24
-9+if (bond->force_primary) { bond->force_primary = false; -return true; +return prim; + } + +if (!curr || curr->link !=BOND_LINK_UP ) +return prim; + +/* At this point, prim and curr are both up */ +switch (bond->params.primary_reselect) { +case BOND_PRI_RESELECT_ALWAYS : +return prim; +case BOND_PRI_RESELECT_BETTER : +if (prim->speed < curr->speed) +return curr; +if (prim->speed == curr->speed && prim->duplex <= curr->duplex) +return curr; +return prim; +case BOND_PRI_RESELECT_FAILURE : +return curr; +default : +netdev_err (bond->dev,"impossible primary_reselect %d\n" , + bond->params.primary_reselect); +return curr; } -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_BETTER && - (prim->speed < curr->speed || - (prim->speed == curr->speed && prim->duplex <= curr->duplex))) -return false; -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_FAILURE ) -return false; -return true; }/** -* find_best_interface - select the best available slave to be the active one +* bond_find_best_slave - select the best available slave to be the active one * @bond: our bonding struct */ static struct slave *bond_find_best_slave (struct bonding *bond) {
drivers/net/bonding/bond_main.c out: · line 737
Quoted 10 lines
drivers/net/bonding/bond_main.c +2
-5-struct slave *slave, *bestslave =NULL , *primary; +struct slave *slave, *bestslave =NULL ;struct list_head *iter;int mintime = bond->params.updelay; - primary =rtnl_dereference (bond->primary_slave); -if (primary && primary->link ==BOND_LINK_UP && -bond_should_change_active (bond)) -return primary; + slave =bond_choose_primary_or_current (bond);
primary_reselect policy only make sense when 'primary' interface is specified. And we should go for reselection only when primary link is up. So this function call should be conditional.
If we make this call conditional and remove first condition/check from "bond_choose_primary_or_current" then it will work fine.
Quoted 8 lines
drivers/net/bonding/bond_main.c +2
-1+if (slave) +return slave;bond_for_each_slave (bond, slave, iter) {if (slave->link ==BOND_LINK_UP ) ----Jay Vosburgh, [email protected]
Below is the updated version of your patch. Any Comments or suggestions ?
drivers/net/bonding/bond_main.c +30 -16
@@ -689,40 +689,54 @@ out: } -static bool bond_should_change_active (struct bonding *bond) +static struct slave *bond_choose_primary_or_current (struct bonding *bond) {struct slave *prim =rtnl_dereference (bond->primary_slave);struct slave *curr =rtnl_dereference (bond->curr_active_slave); -if (!prim || !curr || curr->link !=BOND_LINK_UP ) -return true;if (bond->force_primary) { bond->force_primary = false; -return true; +return prim; + } + +if (!curr || curr->link !=BOND_LINK_UP ) +return prim; + +/* At this point, prim and curr are both up */ +switch (bond->params.primary_reselect) { +case BOND_PRI_RESELECT_ALWAYS : +return prim; +case BOND_PRI_RESELECT_BETTER : +if (prim->speed < curr->speed) +return curr; +if (prim->speed == curr->speed && prim->duplex <= curr->duplex) +return curr; +return prim; +case BOND_PRI_RESELECT_FAILURE : +return curr; +default : +netdev_err (bond->dev,"impossible primary_reselect %d\n" , + bond->params.primary_reselect); +return curr; } -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_BETTER && - (prim->speed < curr->speed || - (prim->speed == curr->speed && prim->duplex <= curr->duplex))) -return false; -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_FAILURE ) -return false; -return true; }/** -* find_best_interface - select the best available slave to be the active one +* bond_find_best_slave - select the best available slave to be the active one * @bond: our bonding struct */ static struct slave *bond_find_best_slave (struct bonding *bond) { -struct slave *slave, *bestslave =NULL , *primary; +struct slave *slave =NULL , *bestslave =NULL , *primary;struct list_head *iter;int mintime = bond->params.updelay; primary =rtnl_dereference (bond->primary_slave); -if (primary && primary->link ==BOND_LINK_UP && -bond_should_change_active (bond)) -return primary; +if (primary && primary->link ==BOND_LINK_UP ) + slave =bond_choose_primary_or_current (bond); + +if (slave) +return slave;bond_for_each_slave (bond, slave, iter) {if (slave->link ==BOND_LINK_UP )
---
Regards,
Mazhar Rana
Quoted 6 lines · GMAIL
Hi Jay,
Quoted 2 lines · Jay Vosburgh
[ added netdev to cc ]
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines · Mazhar Rana
When "
primary_reselect" is set to "failure", primary interface should not become active until current active slave is up. But if we set firstI think you mean "until current active slave is down" here, not
"up."Yes, It should be "up", grammatical mistake
"down," right?
[...]
Quoted 1 line
Below is the updated version of your patch. Any Comments or suggestions ?
[...]
Quoted 15 lines
static struct slave *bond_find_best_slave(struct bonding *bond) {
(quoted diff) +1
-1- struct slave *slave, *bestslave = NULL, *primary; + struct slave *slave = NULL, *bestslave = NULL, *primary;struct list_head *iter; int mintime = bond->params.updelay; primary = rtnl_dereference(bond->primary_slave);(quoted diff) +5
-3- if (primary && primary->link == BOND_LINK_UP && - bond_should_change_active(bond)) - return primary; + if (primary && primary->link == BOND_LINK_UP) + slave = bond_choose_primary_or_current(bond); + + if (slave) + return slave;
Quoted 2 lines
bond_for_each_slave(bond, slave, iter) {
if (slave->link == BOND_LINK_UP) I think this will misbehave in the case that curr is up and
available, but primary is NULL (this can happen when the primary option is cleared). In this case, the above code will not call bond_choose_primary_or_current, and will then run the loop to find a new curr, which may select a different slave unnecessarily.
How does the following look? I prefer to make the call tochoose_primary_or_current unconditional, and have it decide if the search loop should be run. In this version, _choose_ tests curr if prim is not suitable. Compile tested only.
Thoughts? -J
drivers/net/bonding/bond_main.c +34 -17
@@ -689,40 +689,57 @@ out: } -static bool bond_should_change_active (struct bonding *bond) +static struct slave *bond_choose_primary_or_current (struct bonding *bond) {struct slave *prim =rtnl_dereference (bond->primary_slave);struct slave *curr =rtnl_dereference (bond->curr_active_slave); -if (!prim || !curr || curr->link !=BOND_LINK_UP ) -return true; +if (!prim || !prim->link ==BOND_LINK_UP ) { +if (!curr || !curr->link ==BOND_LINK_UP ) +return NULL ; +return curr; + } +if (bond->force_primary) { bond->force_primary = false; -return true; +return prim; + } + +if (!curr || curr->link !=BOND_LINK_UP ) +return prim; + +/* At this point, prim and curr are both up */ +switch (bond->params.primary_reselect) { +case BOND_PRI_RESELECT_ALWAYS : +return prim; +case BOND_PRI_RESELECT_BETTER : +if (prim->speed < curr->speed) +return curr; +if (prim->speed == curr->speed && prim->duplex <= curr->duplex) +return curr; +return prim; +case BOND_PRI_RESELECT_FAILURE : +return curr; +default : +netdev_err (bond->dev,"impossible primary_reselect %d\n" , + bond->params.primary_reselect); +return curr; } -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_BETTER && - (prim->speed < curr->speed || - (prim->speed == curr->speed && prim->duplex <= curr->duplex))) -return false; -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_FAILURE ) -return false; -return true; }/** -* find_best_interface - select the best available slave to be the active one +* bond_find_best_slave - select the best available slave to be the active one * @bond: our bonding struct */ static struct slave *bond_find_best_slave (struct bonding *bond) { -struct slave *slave, *bestslave =NULL , *primary; +struct slave *slave, *bestslave =NULL ;struct list_head *iter;int mintime = bond->params.updelay; - primary =rtnl_dereference (bond->primary_slave); -if (primary && primary->link ==BOND_LINK_UP && -bond_should_change_active (bond)) -return primary; + slave =bond_choose_primary_or_current (bond); +if (slave) +return slave;bond_for_each_slave (bond, slave, iter) {if (slave->link ==BOND_LINK_UP )
---
-Jay Vosburgh, [email protected]
Quoted 8 lines · Jay Vosburgh
Quoted 6 lines · GMAIL
Hi Jay,
Quoted 2 lines · Jay Vosburgh
[ added netdev to cc ]
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines · Mazhar Rana
When "
primary_reselect" is set to "failure", primary interface should not become active until current active slave is up. But if we set firstI think you mean "until current active slave is down" here, not
"up."Yes, It should be "up", grammatical mistake
"down," right?
Yes, "Down".
Quoted 117 lines
[...]
Quoted 1 line
Below is the updated version of your patch. Any Comments or suggestions ?
[...]
Quoted 15 lines
static struct slave *bond_find_best_slave(struct bonding *bond) {
(quoted diff) +1
-1- struct slave *slave, *bestslave = NULL, *primary; + struct slave *slave = NULL, *bestslave = NULL, *primary;struct list_head *iter; int mintime = bond->params.updelay; primary = rtnl_dereference(bond->primary_slave);(quoted diff) +5
-3- if (primary && primary->link == BOND_LINK_UP && - bond_should_change_active(bond)) - return primary; + if (primary && primary->link == BOND_LINK_UP) + slave = bond_choose_primary_or_current(bond); + + if (slave) + return slave;Quoted 2 lines
bond_for_each_slave(bond, slave, iter) { if (slave->link == BOND_LINK_UP)I think this will misbehave in the case that curr is up and
available, but primary is NULL (this can happen when the primary option is cleared). In this case, the above code will not callbond_choose_primary_or_current, and will then run the loop to find a new curr, which may select a different slave unnecessarily.How does the following look? I prefer to make the call to
choose_primary_or_currentunconditional, and have it decide if the search loop should be run. In this version, _choose_ tests curr if prim is not suitable. Compile tested only.Thoughts? -Jdrivers/net/bonding/bond_main.c +34
-18@@ -689,40 +689,57 @@ out: } -static bool bond_should_change_active (struct bonding *bond) +static struct slave *bond_choose_primary_or_current (struct bonding *bond) {struct slave *prim =rtnl_dereference (bond->primary_slave);struct slave *curr =rtnl_dereference (bond->curr_active_slave); -if (!prim || !curr || curr->link !=BOND_LINK_UP ) -return true; +if (!prim || !prim->link ==BOND_LINK_UP ) { +if (!curr || !curr->link ==BOND_LINK_UP ) +return NULL ; +return curr; + } +if (bond->force_primary) { bond->force_primary = false; -return true; +return prim; + } + +if (!curr || curr->link !=BOND_LINK_UP ) +return prim; + +/* At this point, prim and curr are both up */ +switch (bond->params.primary_reselect) { +case BOND_PRI_RESELECT_ALWAYS : +return prim; +case BOND_PRI_RESELECT_BETTER : +if (prim->speed < curr->speed) +return curr; +if (prim->speed == curr->speed && prim->duplex <= curr->duplex) +return curr; +return prim; +case BOND_PRI_RESELECT_FAILURE : +return curr; +default : +netdev_err (bond->dev,"impossible primary_reselect %d\n" , + bond->params.primary_reselect); +return curr; } -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_BETTER && - (prim->speed < curr->speed || - (prim->speed == curr->speed && prim->duplex <= curr->duplex))) -return false; -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_FAILURE ) -return false; -return true; }/** -* find_best_interface - select the best available slave to be the active one +* bond_find_best_slave - select the best available slave to be the active one * @bond: our bonding struct */ static struct slave *bond_find_best_slave (struct bonding *bond) { -struct slave *slave, *bestslave =NULL , *primary; +struct slave *slave, *bestslave =NULL ;struct list_head *iter;int mintime = bond->params.updelay; - primary =rtnl_dereference (bond->primary_slave); -if (primary && primary->link ==BOND_LINK_UP && -bond_should_change_active (bond)) -return primary; + slave =bond_choose_primary_or_current (bond); +if (slave) +return slave;bond_for_each_slave (bond, slave, iter) {if (slave->link ==BOND_LINK_UP ) ---
Quoted 1 line
-Jay Vosburgh, [email protected]
Looks good, added cosmetic changes for more readability, it might save some instructions :)
drivers/net/bonding/bond_main.c +34 -17
@@ -689,40 +689,57 @@ out: } -static bool bond_should_change_active (struct bonding *bond) +static struct slave *bond_choose_primary_or_current (struct bonding *bond) {struct slave *prim =rtnl_dereference (bond->primary_slave);struct slave *curr =rtnl_dereference (bond->curr_active_slave); -if (!prim || !curr || curr->link !=BOND_LINK_UP ) -return true; +if (!prim || prim->link !=BOND_LINK_UP ) { +if (!curr || curr->link !=BOND_LINK_UP ) +return NULL ; +return curr; + } +if (bond->force_primary) { bond->force_primary = false; -return true; +return prim; + } + +if (!curr || curr->link !=BOND_LINK_UP ) +return prim; + +/* At this point, prim and curr are both up */ +switch (bond->params.primary_reselect) { +case BOND_PRI_RESELECT_ALWAYS : +return prim; +case BOND_PRI_RESELECT_BETTER : +if (prim->speed < curr->speed) +return curr; +if (prim->speed == curr->speed && prim->duplex <= curr->duplex) +return curr; +return prim; +case BOND_PRI_RESELECT_FAILURE : +return curr; +default : +netdev_err (bond->dev,"impossible primary_reselect %d\n" , + bond->params.primary_reselect); +return curr; } -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_BETTER && - (prim->speed < curr->speed || - (prim->speed == curr->speed && prim->duplex <= curr->duplex))) -return false; -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_FAILURE ) -return false; -return true; }/** -* find_best_interface - select the best available slave to be the active one +* bond_find_best_slave - select the best available slave to be the active one * @bond: our bonding struct */ static struct slave *bond_find_best_slave (struct bonding *bond) { -struct slave *slave, *bestslave =NULL , *primary; +struct slave *slave, *bestslave =NULL ;struct list_head *iter;int mintime = bond->params.updelay; - primary =rtnl_dereference (bond->primary_slave); -if (primary && primary->link ==BOND_LINK_UP && -bond_should_change_active (bond)) -return primary; + slave =bond_choose_primary_or_current (bond); +if (slave) +return slave;bond_for_each_slave (bond, slave, iter) {if (slave->link ==BOND_LINK_UP )
---
Regards,
Mazhar Rana
Quoted 2 lines · GMAIL
Quoted 1 line · Jay Vosburgh
GMAIL <[email protected]> wrote:
[...]
Quoted 10 lines
Looks good, added cosmetic changes for more readability, it might save some instructions :)
drivers/net/bonding/bond_main.c +0
-0
drivers/net/bonding/bond_main.c out: · line 693
Quoted 6 lines
drivers/net/bonding/bond_main.c +1
-1@@ -689,40 +689,57 @@ out: } -static bool bond_should_change_active (struct bonding *bond) +static struct slave *bond_choose_primary_or_current (struct bonding *bond) {struct slave *prim =rtnl_dereference (bond->primary_slave);struct slave *curr =rtnl_dereference (bond->curr_active_slave);
Probably a good idea to add back a blank line here.
Otherwise this logic appears to be proper to resolve your issue and Jay's additions appear to handle the case where primary_slave is NULL.
Quoted 70 lines
drivers/net/bonding/bond_main.c +33
-17-if (!prim || !curr || curr->link !=BOND_LINK_UP ) -return true; +if (!prim || prim->link !=BOND_LINK_UP ) { +if (!curr || curr->link !=BOND_LINK_UP ) +return NULL ; +return curr; + } +if (bond->force_primary) { bond->force_primary = false; -return true; +return prim; + } + +if (!curr || curr->link !=BOND_LINK_UP ) +return prim; + +/* At this point, prim and curr are both up */ +switch (bond->params.primary_reselect) { +case BOND_PRI_RESELECT_ALWAYS : +return prim; +case BOND_PRI_RESELECT_BETTER : +if (prim->speed < curr->speed) +return curr; +if (prim->speed == curr->speed && prim->duplex <= curr->duplex) +return curr; +return prim; +case BOND_PRI_RESELECT_FAILURE : +return curr; +default : +netdev_err (bond->dev,"impossible primary_reselect %d\n" , + bond->params.primary_reselect); +return curr; } -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_BETTER && - (prim->speed < curr->speed || - (prim->speed == curr->speed && prim->duplex <= curr->duplex))) -return false; -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_FAILURE ) -return false; -return true; }/** -* find_best_interface - select the best available slave to be the active one +* bond_find_best_slave - select the best available slave to be the active one * @bond: our bonding struct */ static struct slave *bond_find_best_slave (struct bonding *bond) { -struct slave *slave, *bestslave =NULL , *primary; +struct slave *slave, *bestslave =NULL ;struct list_head *iter;int mintime = bond->params.updelay; - primary =rtnl_dereference (bond->primary_slave); -if (primary && primary->link ==BOND_LINK_UP && -bond_should_change_active (bond)) -return primary; + slave =bond_choose_primary_or_current (bond); +if (slave) +return slave;bond_for_each_slave (bond, slave, iter) {if (slave->link ==BOND_LINK_UP ) --- Regards,Mazhar Rana
Quoted 21 lines · Andy Gospodarek
Quoted 2 lines · GMAIL
Quoted 1 line · Jay Vosburgh
GMAIL<[email protected]> wrote:
[...]
Quoted 9 lines
Looks good, added cosmetic changes for more readability, it might save some instructions :)
drivers/net/bonding/bond_main.c +0
-0drivers/net/bonding/bond_main.c out: · line 693
Quoted 6 lines
drivers/net/bonding/bond_main.c +1
-1@@ -689,40 +689,57 @@ out: } -static bool bond_should_change_active (struct bonding *bond) +static struct slave *bond_choose_primary_or_current (struct bonding *bond) {struct slave *prim =rtnl_dereference (bond->primary_slave);struct slave *curr =rtnl_dereference (bond->curr_active_slave);Probably a good idea to add back a blank line here.
Quoted 2 lines
Otherwise this logic appears to be proper to resolve your issue and Jay's additions appear to handle the case where
primary_slaveis NULL.
It was there, I don't know, may be mail client issue.
Quoted 63 lines
Quoted 63 lines
drivers/net/bonding/bond_main.c +33
-16-if (!prim || !curr || curr->link !=BOND_LINK_UP ) -return true; +if (!prim || prim->link !=BOND_LINK_UP ) { +if (!curr || curr->link !=BOND_LINK_UP ) +return NULL ; +return curr; + } +if (bond->force_primary) { bond->force_primary = false; -return true; +return prim; + } + +if (!curr || curr->link !=BOND_LINK_UP ) +return prim; + +/* At this point, prim and curr are both up */ +switch (bond->params.primary_reselect) { +case BOND_PRI_RESELECT_ALWAYS : +return prim; +case BOND_PRI_RESELECT_BETTER : +if (prim->speed < curr->speed) +return curr; +if (prim->speed == curr->speed && prim->duplex <= curr->duplex) +return curr; +return prim; +case BOND_PRI_RESELECT_FAILURE : +return curr; +default : +netdev_err (bond->dev,"impossible primary_reselect %d\n" , + bond->params.primary_reselect); +return curr; } -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_BETTER && - (prim->speed < curr->speed || - (prim->speed == curr->speed && prim->duplex <= curr->duplex))) -return false; -if (bond->params.primary_reselect ==BOND_PRI_RESELECT_FAILURE ) -return false; -return true; }/** -* find_best_interface - select the best available slave to be the active one +* bond_find_best_slave - select the best available slave to be the active one * @bond: our bonding struct */ static struct slave *bond_find_best_slave (struct bonding *bond) { -struct slave *slave, *bestslave =NULL , *primary; +struct slave *slave, *bestslave =NULL ;struct list_head *iter;int mintime = bond->params.updelay; - primary =rtnl_dereference (bond->primary_slave); -if (primary && primary->link ==BOND_LINK_UP && -bond_should_change_active (bond)) -return primary; + slave =bond_choose_primary_or_current (bond); +if (slave) +return slave;
Quoted 7 lines
Quoted 7 lines
drivers/net/bonding/bond_main.c +0
-1bond_for_each_slave (bond, slave, iter) {if (slave->link ==BOND_LINK_UP ) --- Regards,Mazhar Rana
Sending updated version of patch(v3) separately which will accommodate my and Jay's changes.
Regards,
Mazhar Rana