From: Daniel Lezcano <dlezcano@fr.ibm.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org
Subject: [net-2.6 patch 1/2][NETNS] fix device renaming for sysfs
Date: Wed, 30 Apr 2008 23:31:14 +0200 [thread overview]
Message-ID: <20080430213320.825349005@localhost.localdomain> (raw)
In-Reply-To: 20080430213113.410541118@localhost.localdomain
[-- Attachment #1: fix-kobject.patch --]
[-- Type: text/plain, Size: 3206 bytes --]
When a netdev is moved across namespaces with the 'dev_change_net_namespace'
function, the 'device_rename' function is used to fixup kobject and refresh
the sysfs tree. The device_rename function will call kobject_rename and this
one will check if there is an object with the same name and this is the case
because we are renaming the object with the same name.
The use of 'device_rename' seems for me wrong because we usually don't
rename it but just move it across namespaces. As we just want to do a
mini "netdev_[un]register", IMO the functions 'netdev_[un]register_kobject'
should be used instead, like an usual network device [un]registering.
This patch replace device_rename by netdev_unregister_kobject, followed by
netdev_register_kobject.
The netdev_register_kobject will call device_initialize and will raise a
warning indicating the device was already initialized. In order to fix that,
I split the device initialization into a separate function and use it together
with 'netdev_register_kobject' into register_netdevice. So we can safely call
'netdev_register_kobject' in 'dev_change_net_namespace'.
This fix will allow to properly use the sysfs per namespace which is coming
from -mm tree.
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Acked-by: Benjamin Thery <benjamin.thery@bull.net>
---
net/core/dev.c | 4 +++-
net/core/net-sysfs.c | 7 ++++++-
net/core/net-sysfs.h | 2 +-
3 files changed, 10 insertions(+), 3 deletions(-)
Index: net-2.6/net/core/dev.c
===================================================================
--- net-2.6.orig/net/core/dev.c
+++ net-2.6/net/core/dev.c
@@ -3776,6 +3776,7 @@ int register_netdevice(struct net_device
}
}
+ netdev_initialize_kobject(dev);
ret = netdev_register_kobject(dev);
if (ret)
goto err_uninit;
@@ -4208,7 +4209,8 @@ int dev_change_net_namespace(struct net_
}
/* Fixup kobjects */
- err = device_rename(&dev->dev, dev->name);
+ netdev_unregister_kobject(dev);
+ err = netdev_register_kobject(dev);
WARN_ON(err);
/* Add the device back in the hashes */
Index: net-2.6/net/core/net-sysfs.c
===================================================================
--- net-2.6.orig/net/core/net-sysfs.c
+++ net-2.6/net/core/net-sysfs.c
@@ -449,7 +449,6 @@ int netdev_register_kobject(struct net_d
struct device *dev = &(net->dev);
struct attribute_group **groups = net->sysfs_groups;
- device_initialize(dev);
dev->class = &net_class;
dev->platform_data = net;
dev->groups = groups;
@@ -470,6 +469,12 @@ int netdev_register_kobject(struct net_d
return device_add(dev);
}
+void netdev_initialize_kobject(struct net_device *net)
+{
+ struct device *device = &(net->dev);
+ device_initialize(device);
+}
+
int netdev_kobject_init(void)
{
return class_register(&net_class);
Index: net-2.6/net/core/net-sysfs.h
===================================================================
--- net-2.6.orig/net/core/net-sysfs.h
+++ net-2.6/net/core/net-sysfs.h
@@ -4,5 +4,5 @@
int netdev_kobject_init(void);
int netdev_register_kobject(struct net_device *);
void netdev_unregister_kobject(struct net_device *);
-
+void netdev_initialize_kobject(struct net_device *);
#endif
--
next prev parent reply other threads:[~2008-04-30 21:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-30 21:31 [net-2.6 patch 0/2][NETNS] netns fixes Daniel Lezcano
2008-04-30 21:31 ` Daniel Lezcano [this message]
2008-05-03 0:01 ` [net-2.6 patch 1/2][NETNS] fix device renaming for sysfs David Miller
2008-06-04 11:59 ` Eric W. Biederman
2008-06-04 13:50 ` Daniel Lezcano
2008-04-30 21:31 ` [net-2.6 patch 2/2][NETNS] Fix reassembly timer to use the right namespace Daniel Lezcano
2008-05-03 0:02 ` David Miller
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=20080430213320.825349005@localhost.localdomain \
--to=dlezcano@fr.ibm.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/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).