* [PATCH] net: make /proc/net/protocols namespace aware
@ 2008-11-17 10:50 Eric Dumazet
2008-11-17 10:53 ` Eric Dumazet
0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2008-11-17 10:50 UTC (permalink / raw)
To: David S. Miller; +Cc: Denis V. Lunev, Linux Netdev List
[-- Attachment #1: Type: text/plain, Size: 469 bytes --]
Converting /proc/net/protocols to be namespace aware is quite easy
and permits us to use sock_prot_inuse_get().
This provides seperate counters for each protocol. For example
we can really count TCPv6 sockets and TCPv4 sockets, while previously,
we had the same value, and this value was not namespace aware.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
---
net/core/sock.c | 27 +++++++++++++++++++++++----
1 files changed, 23 insertions(+), 4 deletions(-)
[-- Attachment #2: af_unix_inuse.patch --]
[-- Type: text/plain, Size: 679 bytes --]
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index a1eb596..36856ca 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -361,6 +361,7 @@ static void unix_sock_destructor(struct sock *sk)
unix_release_addr(u->addr);
atomic_dec(&unix_nr_socks);
+ sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
#ifdef UNIX_REFCNT_DEBUG
printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk,
atomic_read(&unix_nr_socks));
@@ -612,6 +613,9 @@ static struct sock *unix_create1(struct net *net, struct socket *sock)
out:
if (sk == NULL)
atomic_dec(&unix_nr_socks);
+ else
+ sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
+
return sk;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] net: make /proc/net/protocols namespace aware
2008-11-17 10:50 [PATCH] net: make /proc/net/protocols namespace aware Eric Dumazet
@ 2008-11-17 10:53 ` Eric Dumazet
2008-11-17 11:15 ` Alexey Dobriyan
0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2008-11-17 10:53 UTC (permalink / raw)
To: David S. Miller; +Cc: Denis V. Lunev, Linux Netdev List
[-- Attachment #1: Type: text/plain, Size: 1103 bytes --]
Eric Dumazet a écrit :
> Converting /proc/net/protocols to be namespace aware is quite easy
> and permits us to use sock_prot_inuse_get().
>
> This provides seperate counters for each protocol. For example
> we can really count TCPv6 sockets and TCPv4 sockets, while previously,
> we had the same value, and this value was not namespace aware.
>
> Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
> ---
> net/core/sock.c | 27 +++++++++++++++++++++++----
> 1 files changed, 23 insertions(+), 4 deletions(-)
>
Oops wrong attached file... sorry
[PATCH] net: make /proc/net/protocols namespace aware
Converting /proc/net/protocols to be namespace aware is quite easy
and permits us to use sock_prot_inuse_get().
This provides seperate counters for each protocol. For example
we can really count TCPv6 sockets and TCPv4 sockets, while previously,
we had the same value, and this value was not namespace aware.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
---
net/core/sock.c | 27 +++++++++++++++++++++++----
1 files changed, 23 insertions(+), 4 deletions(-)
[-- Attachment #2: protocols_pernet.patch --]
[-- Type: text/plain, Size: 1786 bytes --]
diff --git a/net/core/sock.c b/net/core/sock.c
index 38de9c3..566eb82 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2176,7 +2176,7 @@ static void proto_seq_printf(struct seq_file *seq, struct proto *proto)
"%2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c\n",
proto->name,
proto->obj_size,
- proto->sockets_allocated != NULL ? atomic_read(proto->sockets_allocated) : -1,
+ sock_prot_inuse_get(seq_file_net(seq), proto),
proto->memory_allocated != NULL ? atomic_read(proto->memory_allocated) : -1,
proto->memory_pressure != NULL ? *proto->memory_pressure ? "yes" : "no" : "NI",
proto->max_header,
@@ -2230,7 +2230,8 @@ static const struct seq_operations proto_seq_ops = {
static int proto_seq_open(struct inode *inode, struct file *file)
{
- return seq_open(file, &proto_seq_ops);
+ return seq_open_net(inode, file, &proto_seq_ops,
+ sizeof(struct seq_net_private));
}
static const struct file_operations proto_seq_fops = {
@@ -2241,10 +2242,28 @@ static const struct file_operations proto_seq_fops = {
.release = seq_release,
};
+static __net_init int proto_init_net(struct net *net)
+{
+ if (!proc_net_fops_create(net, "protocols", S_IRUGO, &proto_seq_fops))
+ return -ENOMEM;
+
+ return 0;
+}
+
+static __net_exit void proto_exit_net(struct net *net)
+{
+ proc_net_remove(net, "protocols");
+}
+
+
+static __net_initdata struct pernet_operations proto_net_ops = {
+ .init = proto_init_net,
+ .exit = proto_exit_net,
+};
+
static int __init proto_init(void)
{
- /* register /proc/net/protocols */
- return proc_net_fops_create(&init_net, "protocols", S_IRUGO, &proto_seq_fops) == NULL ? -ENOBUFS : 0;
+ return register_pernet_subsys(&proto_net_ops);
}
subsys_initcall(proto_init);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] net: make /proc/net/protocols namespace aware
2008-11-17 10:53 ` Eric Dumazet
@ 2008-11-17 11:15 ` Alexey Dobriyan
2008-11-17 11:27 ` Eric Dumazet
0 siblings, 1 reply; 5+ messages in thread
From: Alexey Dobriyan @ 2008-11-17 11:15 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David S. Miller, Denis V. Lunev, Linux Netdev List
On Mon, Nov 17, 2008 at 11:53:43AM +0100, Eric Dumazet wrote:
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -2230,7 +2230,8 @@ static const struct seq_operations proto_seq_ops = {
>
> static int proto_seq_open(struct inode *inode, struct file *file)
> {
> - return seq_open(file, &proto_seq_ops);
> + return seq_open_net(inode, file, &proto_seq_ops,
> + sizeof(struct seq_net_private));
You have to hook seq_release_net if you do this.
> }
>
> static const struct file_operations proto_seq_fops = {
> @@ -2241,10 +2242,28 @@ static const struct file_operations proto_seq_fops = {
> .release = seq_release,
+.release = seq_release_net,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: make /proc/net/protocols namespace aware
2008-11-17 11:15 ` Alexey Dobriyan
@ 2008-11-17 11:27 ` Eric Dumazet
2008-11-19 23:14 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2008-11-17 11:27 UTC (permalink / raw)
To: Alexey Dobriyan, David S. Miller; +Cc: Denis V. Lunev, Linux Netdev List
[-- Attachment #1: Type: text/plain, Size: 1366 bytes --]
Alexey Dobriyan a écrit :
> On Mon, Nov 17, 2008 at 11:53:43AM +0100, Eric Dumazet wrote:
>> --- a/net/core/sock.c
>> +++ b/net/core/sock.c
>
>> @@ -2230,7 +2230,8 @@ static const struct seq_operations proto_seq_ops = {
>>
>> static int proto_seq_open(struct inode *inode, struct file *file)
>> {
>> - return seq_open(file, &proto_seq_ops);
>> + return seq_open_net(inode, file, &proto_seq_ops,
>> + sizeof(struct seq_net_private));
>
> You have to hook seq_release_net if you do this.
>
>> }
>>
>> static const struct file_operations proto_seq_fops = {
>> @@ -2241,10 +2242,28 @@ static const struct file_operations proto_seq_fops = {
>> .release = seq_release,
> +.release = seq_release_net,
>
>
Good catch, thanks Alexey
[PATCH] net: make /proc/net/protocols namespace aware
Converting /proc/net/protocols to be namespace aware is quite easy
and permits us to use sock_prot_inuse_get().
This provides seperate counters for each protocol. For example
we can really count TCPv6 sockets and TCPv4 sockets, while previously,
we had the same value, and this value was not namespace aware.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
net/core/sock.c | 29 ++++++++++++++++++++++++-----
1 files changed, 24 insertions(+), 5 deletions(-)
[-- Attachment #2: protocols_pernet.patch --]
[-- Type: text/plain, Size: 1888 bytes --]
diff --git a/net/core/sock.c b/net/core/sock.c
index 38de9c3..244d8fb 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2176,7 +2176,7 @@ static void proto_seq_printf(struct seq_file *seq, struct proto *proto)
"%2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c\n",
proto->name,
proto->obj_size,
- proto->sockets_allocated != NULL ? atomic_read(proto->sockets_allocated) : -1,
+ sock_prot_inuse_get(seq_file_net(seq), proto),
proto->memory_allocated != NULL ? atomic_read(proto->memory_allocated) : -1,
proto->memory_pressure != NULL ? *proto->memory_pressure ? "yes" : "no" : "NI",
proto->max_header,
@@ -2230,7 +2230,8 @@ static const struct seq_operations proto_seq_ops = {
static int proto_seq_open(struct inode *inode, struct file *file)
{
- return seq_open(file, &proto_seq_ops);
+ return seq_open_net(inode, file, &proto_seq_ops,
+ sizeof(struct seq_net_private));
}
static const struct file_operations proto_seq_fops = {
@@ -2238,13 +2239,31 @@ static const struct file_operations proto_seq_fops = {
.open = proto_seq_open,
.read = seq_read,
.llseek = seq_lseek,
- .release = seq_release,
+ .release = seq_release_net,
+};
+
+static __net_init int proto_init_net(struct net *net)
+{
+ if (!proc_net_fops_create(net, "protocols", S_IRUGO, &proto_seq_fops))
+ return -ENOMEM;
+
+ return 0;
+}
+
+static __net_exit void proto_exit_net(struct net *net)
+{
+ proc_net_remove(net, "protocols");
+}
+
+
+static __net_initdata struct pernet_operations proto_net_ops = {
+ .init = proto_init_net,
+ .exit = proto_exit_net,
};
static int __init proto_init(void)
{
- /* register /proc/net/protocols */
- return proc_net_fops_create(&init_net, "protocols", S_IRUGO, &proto_seq_fops) == NULL ? -ENOBUFS : 0;
+ return register_pernet_subsys(&proto_net_ops);
}
subsys_initcall(proto_init);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] net: make /proc/net/protocols namespace aware
2008-11-17 11:27 ` Eric Dumazet
@ 2008-11-19 23:14 ` David Miller
0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2008-11-19 23:14 UTC (permalink / raw)
To: dada1; +Cc: adobriyan, den, netdev
From: Eric Dumazet <dada1@cosmosbay.com>
Date: Mon, 17 Nov 2008 12:27:23 +0100
> Good catch, thanks Alexey
>
> [PATCH] net: make /proc/net/protocols namespace aware
> Converting /proc/net/protocols to be namespace aware is quite easy
> and permits us to use sock_prot_inuse_get().
>
> This provides seperate counters for each protocol. For example
> we can really count TCPv6 sockets and TCPv4 sockets, while previously,
> we had the same value, and this value was not namespace aware.
>
> Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Applied to net-next-2.6, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-11-19 23:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-17 10:50 [PATCH] net: make /proc/net/protocols namespace aware Eric Dumazet
2008-11-17 10:53 ` Eric Dumazet
2008-11-17 11:15 ` Alexey Dobriyan
2008-11-17 11:27 ` Eric Dumazet
2008-11-19 23:14 ` 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).