[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <m11uzsxdty.fsf@fess.ebiederm.org>
Date: Sat, 21 May 2011 08:39:37 -0700
From: ebiederm@...ssion.com (Eric W. Biederman)
To: Alexey Dobriyan <adobriyan@...il.com>
Cc: davem@...emloft.net, netdev@...r.kernel.org, equinox@...c24.net
Subject: Re: [PATCH] netns: add /proc/*/net/id symlink
Alexey Dobriyan <adobriyan@...il.com> writes:
> David Lamparter pointed some real scenarios where knowing
> if two processes live in same netns is important,
> like "how do I kill _all_ processes in netns to shutdown it".
Currently today the way I do this is md5sum /proc/<pid>/mounts.
That works because it is usually necessary to have a separate mount
namespace with a separate set of mounts to accommodate sysfs.
> Currently only kernel knows if two netns are the same.
> Userspace maybe can look at different proc files to find a match
> indirectly sysconf-style but result will be ugly no matter what.
Somewhat.
Right now today without patches if we limit ourselves to the network
namespace there is a pretty valid way to do this.
stat /proc/<pid>/net/dev and compare the inode numbers.
Or any other file in /proc/*/net/. The inode numbers are the
same if you are in the same network namespace.
> Add /proc/*/net/id symlink which "points" to an integer.
>
> $ readlink /proc/net/id
> 0
>
> $ readlink /proc/2941/net/id
> 1
>
> "id" is not a file because 1 syscall is faster than 3 syscalls.
>
> The only rules and expectations for userspace are:
> [as if they will comply, ha-ha]
>
> * init_net always has id 0
> * two netns do not have same id
> * id is unsigned integer
I don't like this patch because we already have a proc interface
that already solves this in production kernels today.
- stat is a single syscall
- two netns do not have the same id
- id is an ino_t.
Now it probably needs to be better documented that /proc/*/net/*
have the same inode number if the network namespace is the
same, as everyone including myself overlooked this very handy
existing property.
Writing this it occurs to me there is a misfeature in my pending
namespace file descriptor code. Right now /proc/<pid>/ns/net
has a floating inode number and it would be good if I could make
that a inode number be the same for every file that refers to
the same network namespace. Ugh.
Eric
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists