netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 net-next] bonding: handle slave's name change with primary_slave logic
@ 2014-01-16  1:04 Veaceslav Falico
  2014-01-16  1:38 ` Ding Tianhong
  2014-01-17  1:27 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Veaceslav Falico @ 2014-01-16  1:04 UTC (permalink / raw)
  To: netdev; +Cc: Veaceslav Falico, Ding Tianhong, Jay Vosburgh, Andy Gospodarek

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.

Reported-by: Ding Tianhong <dingtianhong@huawei.com>
CC: Ding Tianhong <dingtianhong@huawei.com>
CC: Jay Vosburgh <fubar@us.ibm.com>
CC: Andy Gospodarek <andy@greyhouse.net>
Signed-off-by: Veaceslav Falico <vfalico@redhat.com>
---

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(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index f2fe6cb..f00dd45 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -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);
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 net-next] bonding: handle slave's name change with primary_slave logic
  2014-01-16  1:04 [PATCH v4 net-next] bonding: handle slave's name change with primary_slave logic Veaceslav Falico
@ 2014-01-16  1:38 ` Ding Tianhong
  2014-01-16  1:40   ` Veaceslav Falico
  2014-01-17  1:27 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Ding Tianhong @ 2014-01-16  1:38 UTC (permalink / raw)
  To: Veaceslav Falico, netdev; +Cc: Jay Vosburgh, Andy Gospodarek

On 2014/1/16 9:04, Veaceslav Falico wrote:
> 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.
> 
> Reported-by: Ding Tianhong <dingtianhong@huawei.com>
> CC: Ding Tianhong <dingtianhong@huawei.com>
> CC: Jay Vosburgh <fubar@us.ibm.com>
> CC: Andy Gospodarek <andy@greyhouse.net>
> Signed-off-by: Veaceslav Falico <vfalico@redhat.com>
> ---
> 
> 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(-)
> 
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index f2fe6cb..f00dd45 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -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;
> +		}
> +
why not remove all the { } for the if else, there are only one line for each if.

but seems good for logic.

Acked-by: Ding Tianhong <dingtianhong@huawei.com>

> +		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);
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 net-next] bonding: handle slave's name change with primary_slave logic
  2014-01-16  1:38 ` Ding Tianhong
@ 2014-01-16  1:40   ` Veaceslav Falico
  0 siblings, 0 replies; 4+ messages in thread
From: Veaceslav Falico @ 2014-01-16  1:40 UTC (permalink / raw)
  To: Ding Tianhong; +Cc: netdev, Jay Vosburgh, Andy Gospodarek

On Thu, Jan 16, 2014 at 09:38:50AM +0800, Ding Tianhong wrote:
>On 2014/1/16 9:04, Veaceslav Falico wrote:
>> 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.
>>
>> Reported-by: Ding Tianhong <dingtianhong@huawei.com>
>> CC: Ding Tianhong <dingtianhong@huawei.com>
>> CC: Jay Vosburgh <fubar@us.ibm.com>
>> CC: Andy Gospodarek <andy@greyhouse.net>
>> Signed-off-by: Veaceslav Falico <vfalico@redhat.com>
>> ---
>>
>> 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(-)
>>
>> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
>> index f2fe6cb..f00dd45 100644
>> --- a/drivers/net/bonding/bond_main.c
>> +++ b/drivers/net/bonding/bond_main.c
>> @@ -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;
>> +		}
>> +
>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 .

>
>but seems good for logic.
>
>Acked-by: Ding Tianhong <dingtianhong@huawei.com>
>
>> +		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);
>>
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 net-next] bonding: handle slave's name change with primary_slave logic
  2014-01-16  1:04 [PATCH v4 net-next] bonding: handle slave's name change with primary_slave logic Veaceslav Falico
  2014-01-16  1:38 ` Ding Tianhong
@ 2014-01-17  1:27 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2014-01-17  1:27 UTC (permalink / raw)
  To: vfalico; +Cc: netdev, dingtianhong, fubar, andy

From: Veaceslav Falico <vfalico@redhat.com>
Date: Thu, 16 Jan 2014 02:04:29 +0100

> 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.
> 
> Reported-by: Ding Tianhong <dingtianhong@huawei.com>
> CC: Ding Tianhong <dingtianhong@huawei.com>
> CC: Jay Vosburgh <fubar@us.ibm.com>
> CC: Andy Gospodarek <andy@greyhouse.net>
> Signed-off-by: Veaceslav Falico <vfalico@redhat.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-17  1:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-16  1:04 [PATCH v4 net-next] bonding: handle slave's name change with primary_slave logic Veaceslav Falico
2014-01-16  1:38 ` Ding Tianhong
2014-01-16  1:40   ` Veaceslav Falico
2014-01-17  1:27 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).