Subject: Re: [PATCH net-next 1/2] bonding: add sysfs /slave dir for bond slave devices.

From: Veaceslav Falico <[email-masked]>
Date: Thu, 16 Jan 2014 19:40:30 +0100

On Thu, Jan 16, 2014 at 10:04:31AM -0800, Scott Feldman wrote:
>
>On Jan 16, 2014, at 7:31 AM, Veaceslav Falico <[email-masked]> wrote:
>
>> On Wed, Jan 15, 2014 at 09:54:34PM -0800, Scott Feldman wrote:
>>> Add sub-directory under /sys/class/net/<interface>/slave with
>>> read-only attributes for slave.  Directory only appears when
>>> <interface> is a slave.
>
>>> +static ssize_t state_show(struct slave *slave, char *buf)
>>> +{
>>> +	switch (bond_slave_state(slave)) {
>>> +	case BOND_STATE_ACTIVE:
>>> +		return sprintf(buf, "active\n");
>>> +	case BOND_STATE_BACKUP:
>>> +		return sprintf(buf, "backup\n");
>>> +	default:
>>> +		return sprintf(buf, "UNKONWN\n");
>>> +	}
>>> +}
>>> +static SLAVE_ATTR_RO(state);
>>
>> Am I missing something or does it really completely lacks any locking?
>>
>> What prevents the slave to be freed in between?
>
>Correct me if I’m wrong, but I think the equivalent question is: is there a race between sysfs_remove_file() and another CPU open on that file trying to read/write the file?  I believe the answer is no, but I’ll defer to the experts.
>
>The file removal call path is:
>
>	
>	bond_release (ndo_del_slave)
>		__bond_release_one
>			bond_sysfs_slave_del
>				sysfs_remove_file
>			<...continue freeing slave...>
>
>So slave is freed after sysfs_remove_file.  I would expect I/O on sysfs file to fail during sysfs_remove_file.
>
>Does this sound OK?  Am I missing anything else?

Yeah, totally, and as they're read-only there's no locking needed indeed.

>-scott