diff mbox

Broken link in /sys/class/net/ [was: [GIT] Networking]

Message ID m11utvytg4.fsf@fess.ebiederm.org
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

Eric W. Biederman Oct. 30, 2011, 4:49 a.m. UTC
Jiri Slaby <jslaby@suse.cz> writes:

> On 10/25/2011 03:13 PM, Greg KH wrote:
>> On Tue, Oct 25, 2011 at 01:46:11PM +0200, Linus Torvalds wrote:
>>> Anyway, after that rant about really bad practices, let me say that I
>>> did fix up the conflict and I think it's right. But I won't guarantee
>>> it, so please check the changes to fs/sysfs/dir.c.
>> 
>> I think it looks ok, I've booted the merge result, and am typing and
>> sending this from the new kernel, and it hasn't crashed yet :)
>
> Hi, maybe this was not caused by the merge, but the patch[1] causes this
> mess in /sys/class/net/ for me:
> l????????? ? ?    ?    ?             ? eth1
>
> This happens after one renames a net device -- the new name is eth1 here.
>
> [1] 4f72c0cab40 (sysfs: use rb-tree for name lookups)

This looks pretty fixable but today sysfs_rename does not do anything
with the to move a renamed entry to a different position in the rbtree.

If the directory itself changes sysfs_rename should be fine, and it
looks like a trivial patch to always apply the directory rename logic
in sysfs_rename. 

I think all we need is something like the untested patch below to fix
the network device rename problem.

Eric


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Jiri Slaby Oct. 30, 2011, 8:49 p.m. UTC | #1
On 10/30/2011 05:49 AM, Eric W. Biederman wrote:
> Jiri Slaby <jslaby@suse.cz> writes:
> 
>> On 10/25/2011 03:13 PM, Greg KH wrote:
>>> On Tue, Oct 25, 2011 at 01:46:11PM +0200, Linus Torvalds wrote:
>>>> Anyway, after that rant about really bad practices, let me say that I
>>>> did fix up the conflict and I think it's right. But I won't guarantee
>>>> it, so please check the changes to fs/sysfs/dir.c.
>>>
>>> I think it looks ok, I've booted the merge result, and am typing and
>>> sending this from the new kernel, and it hasn't crashed yet :)
>>
>> Hi, maybe this was not caused by the merge, but the patch[1] causes this
>> mess in /sys/class/net/ for me:
>> l????????? ? ?    ?    ?             ? eth1
>>
>> This happens after one renames a net device -- the new name is eth1 here.
>>
>> [1] 4f72c0cab40 (sysfs: use rb-tree for name lookups)
> 
> This looks pretty fixable but today sysfs_rename does not do anything
> with the to move a renamed entry to a different position in the rbtree.
> 
> If the directory itself changes sysfs_rename should be fine, and it
> looks like a trivial patch to always apply the directory rename logic
> in sysfs_rename. 
> 
> I think all we need is something like the untested patch below to fix
> the network device rename problem.

Looks like it works. Thanks.

> diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
> index 48ffbdf..a294068 100644
> --- a/fs/sysfs/dir.c
> +++ b/fs/sysfs/dir.c
> @@ -865,14 +865,13 @@ int sysfs_rename(struct sysfs_dirent *sd,
>  		sd->s_name = new_name;
>  	}
>  
> -	/* Remove from old parent's list and insert into new parent's list. */
> -	if (sd->s_parent != new_parent_sd) {
> -		sysfs_unlink_sibling(sd);
> -		sysfs_get(new_parent_sd);
> -		sysfs_put(sd->s_parent);
> -		sd->s_parent = new_parent_sd;
> -		sysfs_link_sibling(sd);
> -	}
> +	/* Move to the appropriate place in the appropriate directories rbtree. */
> +	sysfs_unlink_sibling(sd);
> +	sysfs_get(new_parent_sd);
> +	sysfs_put(sd->s_parent);
> +	sd->s_parent = new_parent_sd;
> +	sysfs_link_sibling(sd);
> +
>  	sd->s_ns = new_ns;
>  
>  	error = 0;
>
gregkh@suse.de Nov. 1, 2011, 9:19 p.m. UTC | #2
On Tue, Nov 01, 2011 at 07:06:17AM -0700, Eric W. Biederman wrote:
> 
> In sysfs_rename remove the optimization of not calling sysfs_unlink_sibling
> and sysfs_link_sibling if the renamed parent directory is not changing.
> This optimization is no longer valid now that sysfs dirents are stored in an
> rbtree sorted by name.
> 
> Move the assignment of s_ns before the call of sysfs_link_sibling.  With no
> sysfs_dirent fields changing after the call of sysfs_link_sibling this allows
> sysfs_link_sibling to take any of the directory entries into account when
> it builds the rbtrees, and s_ns looks like a prime canidate to be used
> in the rbtree in the future.
> 
> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>

Looks good, Linus, thanks for taking this in your tree already.

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 48ffbdf..a294068 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -865,14 +865,13 @@  int sysfs_rename(struct sysfs_dirent *sd,
 		sd->s_name = new_name;
 	}
 
-	/* Remove from old parent's list and insert into new parent's list. */
-	if (sd->s_parent != new_parent_sd) {
-		sysfs_unlink_sibling(sd);
-		sysfs_get(new_parent_sd);
-		sysfs_put(sd->s_parent);
-		sd->s_parent = new_parent_sd;
-		sysfs_link_sibling(sd);
-	}
+	/* Move to the appropriate place in the appropriate directories rbtree. */
+	sysfs_unlink_sibling(sd);
+	sysfs_get(new_parent_sd);
+	sysfs_put(sd->s_parent);
+	sd->s_parent = new_parent_sd;
+	sysfs_link_sibling(sd);
+
 	sd->s_ns = new_ns;
 
 	error = 0;