netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ding Tianhong <dingtianhong@huawei.com>
To: Veaceslav Falico <vfalico@redhat.com>
Cc: Jay Vosburgh <fubar@us.ibm.com>,
	Andy Gospodarek <andy@greyhouse.net>,
	"David S. Miller" <davem@davemloft.net>,
	Netdev <netdev@vger.kernel.org>
Subject: Re: [3/4] bonding: the calling of bond->slave_cnt need protection
Date: Mon, 22 Jul 2013 08:42:43 +0800	[thread overview]
Message-ID: <51EC8003.3040500@huawei.com> (raw)
In-Reply-To: <20130720104746.GC9149@redhat.com>

On 2013/7/20 18:47, Veaceslav Falico wrote:
> On Sat, Jul 20, 2013 at 03:23:57PM +0800, dingtianhong wrote:
>> The bonding_store_mode has rtnl protection, so no need to get read lock
>> for bond->slave_cnt, but the bonding_store_fail_over_mac need to protect
>> the bond->slave_cnt, so add read_lock().
>>
>> Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
>>
>> ---
>> drivers/net/bonding/bond_sysfs.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
>> index dc36a3d..d01a189 100644
>> --- a/drivers/net/bonding/bond_sysfs.c
>> +++ b/drivers/net/bonding/bond_sysfs.c
>> @@ -504,11 +504,14 @@ static ssize_t bonding_store_fail_over_mac(struct device *d,
>>     int new_value;
>>     struct bonding *bond = to_bond(d);
>>
>> +    read_lock(&bond->lock);
>>     if (bond->slave_cnt != 0) {
>>         pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
>>                bond->dev->name);
>> +        read_unlock(&bond->lock);
>>         return -EPERM;
>>     }
>> +    read_unlock(&bond->lock);
> 
> Maybe it's Saturday, but I really don't see *any* point in this locking.
> 
> I think you've meant that we need the rtnl protection while reading
> slave_cnt AND updating the .fail_over_mac, so that in between we won't add
> new slaves with outdated params.

yes, as you said, the rtnl lock is enough here, but I think rtnl lock is bigger than 
a readlock, so think about the performance, i choose the readlock to protect slave_cnt.

> 
> Something like this (untested):
> 
> diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
> index dc36a3d..8a5a6a3 100644
> --- a/drivers/net/bonding/bond_sysfs.c
> +++ b/drivers/net/bonding/bond_sysfs.c
> @@ -501,20 +501,25 @@ static ssize_t bonding_store_fail_over_mac(struct device *d,
>                         struct device_attribute *attr,
>                         const char *buf, size_t count)
>  {
> -    int new_value;
> +    int new_value, ret = count;
>      struct bonding *bond = to_bond(d);
>  
> +    if (!rtnl_trylock())
> +        return restart_syscall();
> +
>      if (bond->slave_cnt != 0) {
>          pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
>                 bond->dev->name);
> -        return -EPERM;
> +        ret = -EPERM;
> +        goto out;
>      }
>  
>      new_value = bond_parse_parm(buf, fail_over_mac_tbl);
>      if (new_value < 0) {
>          pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
>                 bond->dev->name, buf);
> -        return -EINVAL;
> +        ret = -EINVAL;
> +        goto out;
>      }
>  
>      bond->params.fail_over_mac = new_value;
> @@ -522,7 +527,9 @@ static ssize_t bonding_store_fail_over_mac(struct device *d,
>          bond->dev->name, fail_over_mac_tbl[new_value].modename,
>          new_value);
>  
> -    return count;
> +out:
> +    rtnl_unlock();
> +    return ret;
>  }
>  
>  static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
>>
>>     new_value = bond_parse_parm(buf, fail_over_mac_tbl);
>>     if (new_value < 0) {
> 
> .
> 

      parent reply	other threads:[~2013-07-22  0:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-20  7:23 [PATCH 3/4] bonding: the calling of bond->slave_cnt need protection Ding Tianhong
2013-07-20 10:47 ` [3/4] " Veaceslav Falico
2013-07-20 12:42   ` Nikolay Aleksandrov
2013-07-20 15:00     ` Veaceslav Falico
2013-07-22  0:47       ` Ding Tianhong
2013-07-22  0:42   ` Ding Tianhong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51EC8003.3040500@huawei.com \
    --to=dingtianhong@huawei.com \
    --cc=andy@greyhouse.net \
    --cc=davem@davemloft.net \
    --cc=fubar@us.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=vfalico@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).