netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: fix "queues" uevent between network namespaces
@ 2014-01-16  9:24 Chen Weilong
  2014-01-16 16:19 ` Greg KH
  2014-01-20  4:04 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Chen Weilong @ 2014-01-16  9:24 UTC (permalink / raw)
  To: davem, gregkh; +Cc: netdev

From: Weilong Chen <chenweilong@huawei.com>

When I create a new namespace with 'ip netns add net0', or add/remove
new links in a namespace with 'ip link add/delete type veth', rx/tx
queues events can be got in all namespaces. That is because rx/tx queue
ktypes do not have namespace support, and their kobj parents are setted to
NULL. This patch is to fix it.

Reported-by: Libo Chen <chenlibo@huawei.com>
Signed-off-by: Libo Chen <chenlibo@huawei.com>
Signed-off-by: Weilong Chen <chenweilong@huawei.com>
---
 lib/kobject_uevent.c | 10 ++++++++--
 net/core/net-sysfs.c | 26 ++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 52e5abb..5f72767 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -88,11 +88,17 @@ out:
 #ifdef CONFIG_NET
 static int kobj_bcast_filter(struct sock *dsk, struct sk_buff *skb, void *data)
 {
-	struct kobject *kobj = data;
+	struct kobject *kobj = data, *ksobj;
 	const struct kobj_ns_type_operations *ops;
 
 	ops = kobj_ns_ops(kobj);
-	if (ops) {
+	if (!ops && kobj->kset) {
+		ksobj = &kobj->kset->kobj;
+		if (ksobj->parent != NULL)
+			ops = kobj_ns_ops(ksobj->parent);
+	}
+
+	if (ops && ops->netlink_ns && kobj->ktype->namespace) {
 		const void *sock_ns, *ns;
 		ns = kobj->ktype->namespace(kobj);
 		sock_ns = ops->netlink_ns(dsk);
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 49843bf..0cabe7c 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -748,10 +748,23 @@ static void rx_queue_release(struct kobject *kobj)
 	dev_put(queue->dev);
 }
 
+static const void *rx_queue_namespace(struct kobject *kobj)
+{
+	struct netdev_rx_queue *queue = to_rx_queue(kobj);
+	struct device *dev = &queue->dev->dev;
+	const void *ns = NULL;
+
+	if (dev->class && dev->class->ns_type)
+		ns = dev->class->namespace(dev);
+
+	return ns;
+}
+
 static struct kobj_type rx_queue_ktype = {
 	.sysfs_ops = &rx_queue_sysfs_ops,
 	.release = rx_queue_release,
 	.default_attrs = rx_queue_default_attrs,
+	.namespace = rx_queue_namespace
 };
 
 static int rx_queue_add_kobject(struct net_device *net, int index)
@@ -1082,10 +1095,23 @@ static void netdev_queue_release(struct kobject *kobj)
 	dev_put(queue->dev);
 }
 
+static const void *netdev_queue_namespace(struct kobject *kobj)
+{
+	struct netdev_queue *queue = to_netdev_queue(kobj);
+	struct device *dev = &queue->dev->dev;
+	const void *ns = NULL;
+
+	if (dev->class && dev->class->ns_type)
+		ns = dev->class->namespace(dev);
+
+	return ns;
+}
+
 static struct kobj_type netdev_queue_ktype = {
 	.sysfs_ops = &netdev_queue_sysfs_ops,
 	.release = netdev_queue_release,
 	.default_attrs = netdev_queue_default_attrs,
+	.namespace = netdev_queue_namespace,
 };
 
 static int netdev_queue_add_kobject(struct net_device *net, int index)
-- 
1.7.12

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

* Re: [PATCH] net: fix "queues" uevent between network namespaces
  2014-01-16  9:24 [PATCH] net: fix "queues" uevent between network namespaces Chen Weilong
@ 2014-01-16 16:19 ` Greg KH
  2014-01-17  1:47   ` chenweilong
  2014-01-20  4:04 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Greg KH @ 2014-01-16 16:19 UTC (permalink / raw)
  To: Chen Weilong; +Cc: davem, netdev

On Thu, Jan 16, 2014 at 05:24:31PM +0800, Chen Weilong wrote:
> From: Weilong Chen <chenweilong@huawei.com>
> 
> When I create a new namespace with 'ip netns add net0', or add/remove
> new links in a namespace with 'ip link add/delete type veth', rx/tx
> queues events can be got in all namespaces. That is because rx/tx queue
> ktypes do not have namespace support, and their kobj parents are setted to
> NULL. This patch is to fix it.
> 
> Reported-by: Libo Chen <chenlibo@huawei.com>
> Signed-off-by: Libo Chen <chenlibo@huawei.com>
> Signed-off-by: Weilong Chen <chenweilong@huawei.com>
> ---
>  lib/kobject_uevent.c | 10 ++++++++--
>  net/core/net-sysfs.c | 26 ++++++++++++++++++++++++++
>  2 files changed, 34 insertions(+), 2 deletions(-)

I can't test this, but it looks good to me:

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

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

* Re: [PATCH] net: fix "queues" uevent between network namespaces
  2014-01-16 16:19 ` Greg KH
@ 2014-01-17  1:47   ` chenweilong
  0 siblings, 0 replies; 4+ messages in thread
From: chenweilong @ 2014-01-17  1:47 UTC (permalink / raw)
  To: Greg KH; +Cc: davem, netdev

On 2014/1/17 0:19, Greg KH wrote:
> On Thu, Jan 16, 2014 at 05:24:31PM +0800, Chen Weilong wrote:
>> From: Weilong Chen <chenweilong@huawei.com>
>>
>> When I create a new namespace with 'ip netns add net0', or add/remove
>> new links in a namespace with 'ip link add/delete type veth', rx/tx
>> queues events can be got in all namespaces. That is because rx/tx queue
>> ktypes do not have namespace support, and their kobj parents are setted to
>> NULL. This patch is to fix it.
>>
>> Reported-by: Libo Chen <chenlibo@huawei.com>
>> Signed-off-by: Libo Chen <chenlibo@huawei.com>
>> Signed-off-by: Weilong Chen <chenweilong@huawei.com>
>> ---
>>  lib/kobject_uevent.c | 10 ++++++++--
>>  net/core/net-sysfs.c | 26 ++++++++++++++++++++++++++
>>  2 files changed, 34 insertions(+), 2 deletions(-)
> 
> I can't test this, but it looks good to me:
> 
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> 

Hi,

Here's detail about the test, I hope it can be useful:
step1: create two netns
	suse11-sp3:~ # ip netns add net0
	suse11-sp3:~ # ip netns add net1
	suse11-sp3:~ # ip netns list
	net1
	net0
setp2: monitor udev events
	Term1:
	suse11-sp3:~ # ip netns exec net0 udevadm monitor
	Term2:
	suse11-sp3:~ # ip netns exec net1 udevadm monitor
setp3: add link to net0
	suse11-sp3:~ # ip netns exec net0 ip link add type veth

Then you'll see the below events in net0 and net1.
KERNEL[1389972662.984988] add      /devices/virtual/net/veth0/queues/rx-0 (queues)
KERNEL[1389972662.985008] add      /devices/virtual/net/veth0/queues/tx-0 (queues)
KERNEL[1389972662.985234] add      /devices/virtual/net/veth1/queues/rx-0 (queues)
KERNEL[1389972662.985247] add      /devices/virtual/net/veth1/queues/tx-0 (queues)

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

* Re: [PATCH] net: fix "queues" uevent between network namespaces
  2014-01-16  9:24 [PATCH] net: fix "queues" uevent between network namespaces Chen Weilong
  2014-01-16 16:19 ` Greg KH
@ 2014-01-20  4:04 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2014-01-20  4:04 UTC (permalink / raw)
  To: chenweilong; +Cc: gregkh, netdev

From: Chen Weilong <chenweilong@huawei.com>
Date: Thu, 16 Jan 2014 17:24:31 +0800

> From: Weilong Chen <chenweilong@huawei.com>
> 
> When I create a new namespace with 'ip netns add net0', or add/remove
> new links in a namespace with 'ip link add/delete type veth', rx/tx
> queues events can be got in all namespaces. That is because rx/tx queue
> ktypes do not have namespace support, and their kobj parents are setted to
> NULL. This patch is to fix it.
> 
> Reported-by: Libo Chen <chenlibo@huawei.com>
> Signed-off-by: Libo Chen <chenlibo@huawei.com>
> Signed-off-by: Weilong Chen <chenweilong@huawei.com>

Applied to net-next, thanks.

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

end of thread, other threads:[~2014-01-20  4:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-16  9:24 [PATCH] net: fix "queues" uevent between network namespaces Chen Weilong
2014-01-16 16:19 ` Greg KH
2014-01-17  1:47   ` chenweilong
2014-01-20  4:04 ` 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).