From 97577e38284f48ca773392e2d401af2f6c95dc08 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Sat, 1 Dec 2007 23:40:40 +1100 Subject: [UNIX]: Extend unix_sysctl_(un)register prototypes Add the struct net * argument to both of them to use in the future. Also make the register one return an error code. It is useless right now, but will make the future patches much simpler. Signed-off-by: Pavel Emelyanov Acked-by: Eric W. Biederman Signed-off-by: Herbert Xu Signed-off-by: David S. Miller --- net/unix/sysctl_net_unix.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'net/unix/sysctl_net_unix.c') diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c index eb0bd57ebada..b2e0407e1b7b 100644 --- a/net/unix/sysctl_net_unix.c +++ b/net/unix/sysctl_net_unix.c @@ -48,12 +48,13 @@ static ctl_table unix_root_table[] = { static struct ctl_table_header * unix_sysctl_header; -void unix_sysctl_register(void) +int unix_sysctl_register(struct net *net) { unix_sysctl_header = register_sysctl_table(unix_root_table); + return unix_sysctl_header == NULL ? -ENOMEM : 0; } -void unix_sysctl_unregister(void) +void unix_sysctl_unregister(struct net *net) { unregister_sysctl_table(unix_sysctl_header); } -- cgit v1.2.3 From d392e49756a99ba51577d265d6db83e3f01c6ac8 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Sat, 1 Dec 2007 23:44:15 +1100 Subject: [UNIX]: Move the sysctl_unix_max_dgram_qlen This will make all the sub-namespaces always use the default value (10) and leave the tuning via sysctl to the init namespace only. Per-namespace tuning is coming. Signed-off-by: Pavel Emelyanov Acked-by: Eric W. Biederman Signed-off-by: Herbert Xu Signed-off-by: David S. Miller --- include/net/net_namespace.h | 3 +++ net/unix/af_unix.c | 6 +++--- net/unix/sysctl_net_unix.c | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'net/unix/sysctl_net_unix.c') diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index 235214c4c231..b0cf07519b81 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -38,6 +38,9 @@ struct net { /* List of all packet sockets. */ rwlock_t packet_sklist_lock; struct hlist_head packet_sklist; + + /* unix sockets */ + int sysctl_unix_max_dgram_qlen; }; #ifdef CONFIG_NET diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index a0aa6d3c2c08..73620d61762b 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -117,8 +117,6 @@ #include #include -int sysctl_unix_max_dgram_qlen __read_mostly = 10; - static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1]; static DEFINE_SPINLOCK(unix_table_lock); static atomic_t unix_nr_socks = ATOMIC_INIT(0); @@ -594,7 +592,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock) &af_unix_sk_receive_queue_lock_key); sk->sk_write_space = unix_write_space; - sk->sk_max_ack_backlog = sysctl_unix_max_dgram_qlen; + sk->sk_max_ack_backlog = net->sysctl_unix_max_dgram_qlen; sk->sk_destruct = unix_sock_destructor; u = unix_sk(sk); u->dentry = NULL; @@ -2140,6 +2138,8 @@ static int unix_net_init(struct net *net) { int error = -ENOMEM; + net->sysctl_unix_max_dgram_qlen = 10; + #ifdef CONFIG_PROC_FS if (!proc_net_fops_create(net, "unix", 0, &unix_seq_fops)) goto out; diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c index b2e0407e1b7b..c46cec04d23f 100644 --- a/net/unix/sysctl_net_unix.c +++ b/net/unix/sysctl_net_unix.c @@ -18,7 +18,7 @@ static ctl_table unix_table[] = { { .ctl_name = NET_UNIX_MAX_DGRAM_QLEN, .procname = "max_dgram_qlen", - .data = &sysctl_unix_max_dgram_qlen, + .data = &init_net.sysctl_unix_max_dgram_qlen, .maxlen = sizeof(int), .mode = 0644, .proc_handler = &proc_dointvec -- cgit v1.2.3 From 1d430b913c2e6293a80a4a422406bc9489a476ad Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Sat, 1 Dec 2007 23:45:41 +1100 Subject: [UNIX]: Use ctl paths to register unix ctl tables Unlike previous ones, this patch is useful by its own, as it decreases the vmlinux size :) But it will be used later, when the per-namespace sysctl is added. Signed-off-by: Pavel Emelyanov Acked-by: Eric W. Biederman Signed-off-by: Herbert Xu Signed-off-by: David S. Miller --- net/unix/sysctl_net_unix.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'net/unix/sysctl_net_unix.c') diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c index c46cec04d23f..43dd356730fd 100644 --- a/net/unix/sysctl_net_unix.c +++ b/net/unix/sysctl_net_unix.c @@ -26,31 +26,17 @@ static ctl_table unix_table[] = { { .ctl_name = 0 } }; -static ctl_table unix_net_table[] = { - { - .ctl_name = NET_UNIX, - .procname = "unix", - .mode = 0555, - .child = unix_table - }, - { .ctl_name = 0 } -}; - -static ctl_table unix_root_table[] = { - { - .ctl_name = CTL_NET, - .procname = "net", - .mode = 0555, - .child = unix_net_table - }, - { .ctl_name = 0 } +static struct ctl_path unix_path[] = { + { .procname = "net", .ctl_name = CTL_NET, }, + { .procname = "unix", .ctl_name = NET_UNIX, }, + { }, }; static struct ctl_table_header * unix_sysctl_header; int unix_sysctl_register(struct net *net) { - unix_sysctl_header = register_sysctl_table(unix_root_table); + unix_sysctl_header = register_sysctl_paths(unix_path, unix_table); return unix_sysctl_header == NULL ? -ENOMEM : 0; } -- cgit v1.2.3 From 1597fbc0faf88c42edb3fe42e92e53b83c3f120e Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Sat, 1 Dec 2007 23:51:01 +1100 Subject: [UNIX]: Make the unix sysctl tables per-namespace This is the core. * add the ctl_table_header on the struct net; * make the unix_sysctl_register and _unregister clone the table; * moves calls to them into per-net init and exit callbacks; * move the .data pointer in the proper place. Signed-off-by: Pavel Emelyanov Acked-by: Eric W. Biederman Signed-off-by: Herbert Xu Signed-off-by: David S. Miller --- include/net/net_namespace.h | 3 +++ net/unix/af_unix.c | 9 ++++++--- net/unix/sysctl_net_unix.c | 27 ++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 8 deletions(-) (limited to 'net/unix/sysctl_net_unix.c') diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index b0cf07519b81..f97b2a4469ae 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -11,6 +11,8 @@ struct proc_dir_entry; struct net_device; struct sock; +struct ctl_table_header; + struct net { atomic_t count; /* To decided when the network * namespace should be freed. @@ -41,6 +43,7 @@ struct net { /* unix sockets */ int sysctl_unix_max_dgram_qlen; + struct ctl_table_header *unix_ctl; }; #ifdef CONFIG_NET diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 73620d61762b..b8a2189fb5c0 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2139,10 +2139,14 @@ static int unix_net_init(struct net *net) int error = -ENOMEM; net->sysctl_unix_max_dgram_qlen = 10; + if (unix_sysctl_register(net)) + goto out; #ifdef CONFIG_PROC_FS - if (!proc_net_fops_create(net, "unix", 0, &unix_seq_fops)) + if (!proc_net_fops_create(net, "unix", 0, &unix_seq_fops)) { + unix_sysctl_unregister(net); goto out; + } #endif error = 0; out: @@ -2151,6 +2155,7 @@ out: static void unix_net_exit(struct net *net) { + unix_sysctl_unregister(net); proc_net_remove(net, "unix"); } @@ -2175,7 +2180,6 @@ static int __init af_unix_init(void) sock_register(&unix_family_ops); register_pernet_subsys(&unix_net_ops); - unix_sysctl_register(&init_net); out: return rc; } @@ -2183,7 +2187,6 @@ out: static void __exit af_unix_exit(void) { sock_unregister(PF_UNIX); - unix_sysctl_unregister(&init_net); proto_unregister(&unix_proto); unregister_pernet_subsys(&unix_net_ops); } diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c index 43dd356730fd..553ef6a487d0 100644 --- a/net/unix/sysctl_net_unix.c +++ b/net/unix/sysctl_net_unix.c @@ -32,16 +32,33 @@ static struct ctl_path unix_path[] = { { }, }; -static struct ctl_table_header * unix_sysctl_header; - int unix_sysctl_register(struct net *net) { - unix_sysctl_header = register_sysctl_paths(unix_path, unix_table); - return unix_sysctl_header == NULL ? -ENOMEM : 0; + struct ctl_table *table; + + table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL); + if (table == NULL) + goto err_alloc; + + table[0].data = &net->sysctl_unix_max_dgram_qlen; + net->unix_ctl = register_net_sysctl_table(net, unix_path, table); + if (net->unix_ctl == NULL) + goto err_reg; + + return 0; + +err_reg: + kfree(table); +err_alloc: + return -ENOMEM; } void unix_sysctl_unregister(struct net *net) { - unregister_sysctl_table(unix_sysctl_header); + struct ctl_table *table; + + table = net->unix_ctl->ctl_table_arg; + unregister_sysctl_table(net->unix_ctl); + kfree(table); } -- cgit v1.2.3 From a0a53c8ba95451feef6c1975016f0a1eb3044ad4 Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Tue, 11 Dec 2007 04:19:17 -0800 Subject: [NETNS]: struct net content re-work (v3) Recently David Miller and Herbert Xu pointed out that struct net becomes overbloated and un-maintainable. There are two solutions: - provide a pointer to a network subsystem definition from struct net. This costs an additional dereferrence - place sub-system definition into the structure itself. This will speedup run-time access at the cost of recompilation time The second approach looks better for us. Other sub-systems will follow. Signed-off-by: Denis V. Lunev Acked-by: Daniel Lezcano Signed-off-by: David S. Miller --- include/net/net_namespace.h | 6 +++--- include/net/netns/unix.h | 13 +++++++++++++ net/unix/af_unix.c | 4 ++-- net/unix/sysctl_net_unix.c | 12 ++++++------ 4 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 include/net/netns/unix.h (limited to 'net/unix/sysctl_net_unix.c') diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index b62e31fca474..d943fd4eaba5 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -8,6 +8,8 @@ #include #include +#include + struct proc_dir_entry; struct net_device; struct sock; @@ -45,9 +47,7 @@ struct net { rwlock_t packet_sklist_lock; struct hlist_head packet_sklist; - /* unix sockets */ - int sysctl_unix_max_dgram_qlen; - struct ctl_table_header *unix_ctl; + struct netns_unix unx; }; #ifdef CONFIG_NET diff --git a/include/net/netns/unix.h b/include/net/netns/unix.h new file mode 100644 index 000000000000..284649d4dfb4 --- /dev/null +++ b/include/net/netns/unix.h @@ -0,0 +1,13 @@ +/* + * Unix network namespace + */ +#ifndef __NETNS_UNIX_H__ +#define __NETNS_UNIX_H__ + +struct ctl_table_header; +struct netns_unix { + int sysctl_max_dgram_qlen; + struct ctl_table_header *ctl; +}; + +#endif /* __NETNS_UNIX_H__ */ diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index b8a2189fb5c0..63a9239571a4 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -592,7 +592,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock) &af_unix_sk_receive_queue_lock_key); sk->sk_write_space = unix_write_space; - sk->sk_max_ack_backlog = net->sysctl_unix_max_dgram_qlen; + sk->sk_max_ack_backlog = net->unx.sysctl_max_dgram_qlen; sk->sk_destruct = unix_sock_destructor; u = unix_sk(sk); u->dentry = NULL; @@ -2138,7 +2138,7 @@ static int unix_net_init(struct net *net) { int error = -ENOMEM; - net->sysctl_unix_max_dgram_qlen = 10; + net->unx.sysctl_max_dgram_qlen = 10; if (unix_sysctl_register(net)) goto out; diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c index 553ef6a487d0..77513d7e35f2 100644 --- a/net/unix/sysctl_net_unix.c +++ b/net/unix/sysctl_net_unix.c @@ -18,7 +18,7 @@ static ctl_table unix_table[] = { { .ctl_name = NET_UNIX_MAX_DGRAM_QLEN, .procname = "max_dgram_qlen", - .data = &init_net.sysctl_unix_max_dgram_qlen, + .data = &init_net.unx.sysctl_max_dgram_qlen, .maxlen = sizeof(int), .mode = 0644, .proc_handler = &proc_dointvec @@ -40,9 +40,9 @@ int unix_sysctl_register(struct net *net) if (table == NULL) goto err_alloc; - table[0].data = &net->sysctl_unix_max_dgram_qlen; - net->unix_ctl = register_net_sysctl_table(net, unix_path, table); - if (net->unix_ctl == NULL) + table[0].data = &net->unx.sysctl_max_dgram_qlen; + net->unx.ctl = register_net_sysctl_table(net, unix_path, table); + if (net->unx.ctl == NULL) goto err_reg; return 0; @@ -57,8 +57,8 @@ void unix_sysctl_unregister(struct net *net) { struct ctl_table *table; - table = net->unix_ctl->ctl_table_arg; - unregister_sysctl_table(net->unix_ctl); + table = net->unx.ctl->ctl_table_arg; + unregister_sysctl_table(net->unx.ctl); kfree(table); } -- cgit v1.2.3